Unit 3: Port Scanning 3.1 Port Scanning The TCP Three-Way Handshake

mac2022-06-30  19

>> Quick, how many things in life are guaranteed?No, not two.Three! Death, taxes, and, of course, TCP.At layer four, transmission control protocol establishes a connection between sourceand destination before any data is transferred, requires every messageto be acknowledge, and guarantees delivery.UDP, user datagram protocol, at layer four is connectionless,without acknowledgements, and doesn't guarantee anything.TCP would be like the return receipt you'd pay for at the post office,so you'd know when someone got your letter.UDP is like putting a stamp on an envelope and mailing it.If it gets there, it gets there.If it doesn't, it doesn't.The source doesn't know the destination didn't get it.The destination doesn't know that the source sent it.Email, HTTP, SSL/TLS, FTP, and SSH are the big protocols that use TCP at layer four because,in those cases, reliability and accuracy are more important than speed.DNS and DHCP are the big protocols that use UDP because speedand efficiency are more important in those cases.Remember that TCP segments and UDP datagrams are encapsulated in IP packets at layer threeand packets are encapsulated in frames at layer two.So how exactly does TCP establish a connection between source and destination?It's called the TCP three-way handshake.In nontechnical terms, the source says, hey, I want to talk to you.The destination says back, okay, you can talk to me.Can I talk to you?And the source says, sure.Let's rock.If you take a look at the TCP header fields,you'll notice that the first two fields contain the source and destination ports,indicating the program or service that the message comes from on the sourceand is headed for on the destination.Then comes two important fields, Sequence Number and Acknowledgement Number.To understand how these fields are used, let's look at the Flags section,which comes after the Offset field, representing the size of the TCP header,and the Reserved field, which is just three zero bits.Flags in the TCP header represent specific control information, metadata,conveyed to and from the connected machines.Like a flag on a mailbox, these flags could be raised or lowered.TCP flags, however, are not red.They're represented by a single big.Turning a flag on means setting that bit to a value of 1.Turning a flag off means setting that bit to a value of zero.There are nine flags in the TCP header -- six standard ones and three specialty ones.We're going to focus on two of them now and others later.In the first step of the TCP three-way handshake, the source sets the SYN,synchronized flag, on by placing a 1 in that bit position and also comesup with a pseudo randomly generated sequence number.That number is placed in the sequence number field.Let's say it's 9.The TCP header is placed in an IP packet, which is placed in a frame.And assuming remote communication, it's sent to the default gateway.When the TCP segment shows up on the actual destination, the destination says,roger that, by sending its own TCP segment.In step two of the TCP three-way handshake, the destination turns on the ACK, acknowledge flag,and increments the sequence number that the source sent by 1in the Acknowledgment Number field.If the source's initial sequence number was 9, the destination puts 9 plus 1, or 10,in the Acknowledgment Number field.In reality, both the sequence numberand acknowledgment number are four byte [phonetic] values.In the same TCP header, the destination also raises the SYN flag and comesup with its own pseudo randomly generated sequence number, let's say 2017,which it places in the Sequence Number field.This is the destination saying, can I talk to you too?This TCP segment is sent to the source.The source in step three responds to this by sending another TCP segmentwith the ACK flag on, incrementing the sequence number sent by the destination by 1in the Acknowledgement Number field.In our example, that would be 2017 plus 1, or 2018.At this point, the two systems are connected.The TCP segments in the three steps didn't have any data.It was just control messages in the TCP header.Now, when actual data's transmitted by either station, be it HTTP, SSL, TLS, SSH, FTP,or others, it's encapsulated inside the TCP headers.In fact, the sequence numbers now go up by the size of the data,Every bit sent is acknowledged.If not, it's resent.That's how TCP follows through on its guaranteed data delivery claim.

转载于:https://www.cnblogs.com/sec875/articles/10016015.html

最新回复(0)