26.07.2018 Views

hacking-the-art-of-exploitation

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

0 1 2 3<br />

0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1<br />

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />

| Source Port | Destination Port |<br />

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />

| Sequence Number |<br />

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />

| Acknowledgment Number |<br />

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />

| Data | |U|A|P|R|S|F| |<br />

| Offset| Reserved |R|C|S|S|Y|I| Window |<br />

| | |G|K|H|T|N|N| |<br />

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />

| Checksum | Urgent Pointer |<br />

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />

| Options | Padding |<br />

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />

| data |<br />

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<br />

TCP Header Format<br />

Note that one tick mark represents one bit position.<br />

Figure 3.<br />

The sequence number and acknowledgment number are used to maintain<br />

state. The SYN and ACK flags are used toge<strong>the</strong>r to open connections in a<br />

three-step handshaking process. When a client wants to open a connection<br />

with a server, a packet with <strong>the</strong> SYN flag on, but <strong>the</strong> ACK flag <strong>of</strong>f, is sent to<br />

<strong>the</strong> server. The server <strong>the</strong>n responds with a packet that has both <strong>the</strong> SYN and<br />

ACK flags turned on. To complete <strong>the</strong> connection, <strong>the</strong> client sends back a<br />

packet with <strong>the</strong> SYN flag <strong>of</strong>f but <strong>the</strong> ACK flag on. After that, every packet in<br />

<strong>the</strong> connection will have <strong>the</strong> ACK flag turned on and <strong>the</strong> SYN flag turned <strong>of</strong>f.<br />

Only <strong>the</strong> first two packets <strong>of</strong> <strong>the</strong> connection have <strong>the</strong> SYN flag on, since those<br />

packets are used to synchronize sequence numbers.<br />

SYN packet<br />

SYN on ACK <strong>of</strong>f<br />

seq # = 324808530<br />

ack # = 0<br />

Client<br />

SYN/ACK packet<br />

SYN on ACK on<br />

seq # = 288666267<br />

ack # = 324808531<br />

Server<br />

ACK packet<br />

SYN <strong>of</strong>f ACK on<br />

seq # = 324808531<br />

ack # = 288666268<br />

Networking 223

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!