In this section, we will look at how to give a fake reply at the TCP layer. The program will give fake replies to open ports. For this code, we are going to use the scapy library because the TCP header is very complicated to make. The program name is tcp_trap.py:
- Use the following library and module:
import socket
import struct
import binascii
import Queue
from scapy.all import *
import threading
- A raw socket has been created to receive incoming packets as follows:
my_socket = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, 8)
Q = Queue.Queue()
- The following function receives the incoming TCP/IP packets. A lot of lines have already been discussed in Chapter 3, Sniffing and Penetration Testing. The if (D_port==445 or D_port==135 or D_port==80): syntax shows that we are only interested in ports 445, 135,...