Scapy: Sending and Receiving Crafted Packets

Hi 

So you are now able to move forward in you packet manipulation tutorials with Scapy.
In previous tutorials we learnt how to create a simple packet and after that how to add more values to it since Scapy uses default values if they are not added there.

So in this tutorial we will learn about how to send and receive packets using Scapy.
In Scapy we use three functions for sending and receiving packets. these are 

sr(): This is used for layer 3 protocols by using this function we can send packets and receive their answers. this returns a couple of packet their answers and unanswered packets.

sr1(): By using this function it it returns only one packet that answered the sent packet.

srp(): this function does the same which sr() and sr1() do but for layer 2 packets.

So now lets sends a simple packet.
>>>packet=sr(IP(dst="192.168.XX.XX")/TCP())

Begin emission:
.Finished to send 1 packets.
*

Received 2 packets, got 1 answers, remaining 0 packets


here I want to elaborate some more info like i told you in the previous post if you have a crafted packet before you can send the same using this command

>>>response=sr(packet_name) or 
>>>response=sr1(packet_name)

Now if you use sr1() function I told you above it will show you the first answered packet.

Now if you want to look at your packet simply type
>>>packet.show

here "packet" is name of packet we given to the crafted packet.


So now lets try to add more to packet and sending that using our own payload


>>>packet=sr(IP(dst="192.168.XX.XX")/TCP()/"hello admin")

here packet is the name of packet

so you can add your own payload and sent the packet to its destination.

and now lets try specifying the port number to the destination IP address so lets do it

>>>packet=sr(IP(dst="192.168.XX.XX")/TCP(dport=80)/"hello admin")

so here I specified the port number on the destination IP which this it will be received.

lets try specifying Source IP address

>>>packet=sr(IP(dst="192.168.XX.XX", src="192.168.XX.XX")/TCP()/"hello admin")

here I specified the source IP address with src fuction. It will add the source IP to the crafted packet

Now lets specify the TTL (time to live) value in the packet

>>>packet=sr(IP(dst="192.168.XX.XX", src="192.168.XX.XX",ttl="128")/TCP()/"hello admin")




Thats all for this post.

In this post You have learnt how to send and receive packets and also sending some complimated crafted packet.
So in next post we will learn about how we can add more values to our packet and can make it more complicated packets like specifying source port adding and how to specify port ranges ( this is how a port scanner works)

Stay tuned

Regards
Jitendra & Sooraj Shekhar (Team Computer Korner) 

Special Thanks Gurpreet Singh


Feel Free To Leave A Comment If Our Article has Helped You, Support Us By Making A Small Contribution, Thank You!

0 comments: