The TCP port scan

The first step for any potential hackers is almost always try to learn which service is open on the network, so they can concentrate their effort on the attack. Of course, we need to open certain ports in order to service our customer, but we should also close any open port that is not necessary to decrease the risk. We can use Scapy to do a simple open port scan.

We can send a SYN packet and see whether the server will return with SYN-ACK:

>>> p = sr1(IP(dst="10.0.0.14")/TCP(sport=666,dport=23,flags="S"))>>> p.show()###[ IP ]### version= 4L ihl= 5L tos= 0x0 len= 40 id= 25373 flags= DF frag= 0L ttl= 62 proto= tcp chksum= 0xc59b src= 10.0.0.14 dst= 10.0.0.10 options###[ TCP ]### sport= telnet dport= 666 seq= 0 ack= 1 dataofs= ...

Get Mastering Python Networking now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.