Learning about packet crafting

This is a technique by which a hacker or pentester can create customized packets. By using a customized packet, a hacker can perform many tasks such as probing firewall rule sets, port scan, and the behavior of the operating system. Lots of tools are available for packet crafting, such as Hping, Colasoft packet builder, and so on. Packet crafting is a skill. You can perform it with no tools as you have Python.

First, we create Ethernet packets and then send them to the victim. Let's take a look at the entire code of eth.py and then understand it line by line:

import socket
s = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.ntohs(0x0800))
s.bind(("eth0",socket.htons(0x0800)))
sor = 'x00x0cx29x4fx8ex35'
des ='x00x0Cx29x2Ex84x7A'
code ='x08x00'
eth = des+sor+code
s.send(eth)

The s = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.ntohs(0x0800)) has already been seen by you in the packet sniffer. Now, decide on the network interface. We choose the eth0 interface to send the packet. The s.bind(("eth0",socket.htons(0x0800))) statement binds the interface eth0 with the protocol value. The next two lines define the source and destination MAC addresses. The code ='x08x00' statement shows the protocol of interest. This is the code of the IP protocol. The eth = des+sor+code statement is used to assemble the packet. The next line, s.send(eth), sends the packet.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.46.78