c++ program, which generates TCP packets.
-
I downloaded and installed crafter library on my debian machine. The installation is as easy as described
in
libcrafter.
The first example, which I tried, detects the computer's
IP and MAC address.
The second example generates
ARP packets.
-
In this case, I used a written example, which creates TCP packets. Some of the fields of the
packet , like check sum, are filled after sending. This is done by the function Send. Since
I don't want to send packet, but rather print them, I added a function that just "crafts"
the packet.
//Packet Craft
int Packet::FillPkt(const string& iface) {
/* Check the size of the stack */
if(Stack.size() == 0) {
PrintMessage(Crafter::PrintCodes::PrintWarning,
"Packet::FillPkt()",
"Not data in the packet. ");
return 0;
}
/* Craft the packet, so we fill all the information needed */
Craft();
return 1;
}
In the TCP program I used:
/* Write the packet on the wire */
tcp_packet.FillPkt();
cout << endl << "[@] Print after sending: " << endl;
tcp_packet.Print();
tcp_packet.RawString();
This is how the program output looks like:
[@] My IP address is : 192.168.0.180
[@] Print after sending:
< IP (20 bytes) :: Version = 4 , HeaderLength = 5 , DiffServicesCP = 0 , ExpCongestionNot = 0 , TotalLength = 56 , Identification = 0x0 , Flags = 2 , FragmentOffset = 0 , TTL = 64 , Protocol = 0x6 , CheckSum = 0x930b , SourceIP = 192.168.0.180 , DestinationIP = 212.179.17.165 , >
< TCP (20 bytes) :: SrcPort = 11 , DstPort = 80 , SeqNumber = 169354154 , AckNumber = 0 , DataOffset = 5 , Reserved = 0 , Flags = ( SYN ) , WindowsSize = 5840 , CheckSum = 0xa0d2 , UrgPointer = 0 , >
< RawLayer (16 bytes) :: Payload = ArbitraryPayload>
45 00 00 38 00 00 40 00 40 06 93 0b c0 a8 00 b4
d4 b3 11 a5 00 0b 00 50 0a 18 23 aa 00 00 00 00
50 02 16 d0 a0 d2 00 00 41 72 62 69 74 72 61 72
79 50 61 79 6c 6f 61 64
-
The next page combines the ARP and TCP to create the TCP layer on top of
the MAC layer.
link
|