12 June, 2013

About Scapy

Scapy is a packet manipulation tool than can craft, send, capture and sniff network datagrams (segments, packets and frames)

Rune Scapy 

root@bt:~# scapy
Welcome to Scapy (2.0.1)
>>>

To Exit From Scapy Use Ctrl + D

Send Simple ICMP Packet

>>> send(IP(src="192.168.1.33",dst="192.168.1.1")/ICMP()/"I-LOVE-YOU")

If You Capture Trafic You Can See It.


Make Some Variables:

root@bt:~# scapy

>>> L2=Ether()
>>> L3=IP()
>>> L4=TCP()

Just Verify

>>> L2
<Ether  |>
>>> L3
<IP  |>
>>> L4
<TCP  |>

To See Default Configuration Inside Scapy 

>>> L2.show()

###[ Ethernet ]###
  dst= ff:ff:ff:ff:ff:ff
  src= 00:00:00:00:00:00
  type= 0x0

>>> L3.show()

###[ IP ]###
  version= 4
  ihl= None
  tos= 0x0
  len= None
  id= 1
  flags=
  frag= 0
  ttl= 64
  proto= ip
  chksum= 0x0
  src= 127.0.0.1
  dst= 127.0.0.1
  options= ''

>>> L4.show()

###[ TCP ]###
  sport= ftp_data
  dport= www
  seq= 0
  ack= 0
  dataofs= None
  reserved= 0
  flags= S
  window= 8192
  chksum= 0x0
  urgptr= 0
  options= {}

We Can Manually Change Any Settings.

Change L2 Source MAC Address 

>>> L2=Ether(src="11:11:11:AA:AA:AA")
>>> L2.show()

###[ Ethernet ]###
  dst= ff:ff:ff:ff:ff:ff
  src= 11:11:11:AA:AA:AA    <---
  type= 0x0

Change L3 Source And Destination Addresses

>>> L3=IP(ttl=99, dst="192.168.1.25", src="192.168.1.22")
>>> L3.show()

###[ IP ]###
  version= 4
  ihl= None
  tos= 0x0
  len= None
  id= 1
  flags=
  frag= 0
  ttl= 64
  proto= ip
  chksum= 0x0
  src= 192.168.1.22    <---
  dst= 192.168.1.25    <---
  options= ''

Make Quick Change 

>>> del(L3.dst)             (Delete Destination Address)

>>> L3.dst="192.168.1.26"   (Add New Destination Address)

Change L4 Options 

>>> L4=TCP(sport=7777, dport=22, flags="A")
>>> L4.show()



###[ TCP ]###
  sport= 7777    <---
  dport= ssh     <---
  seq= 0
  ack= 0
  dataofs= None
  reserved= 0
  flags= A       <---
  window8192
  chksum= 0x0
  urgptr= 0
  options= {}

When Type L2, L3 And L4 Its Shows You Changed Options 

>>> L2
<Ether  src=11:11:11:AA:AA:AA |>
>>> L3
<IP  ttl=99 src=192.168.1.22 dst=192.168.1.25 |>
>>> L4
<TCP  sport=7777 dport=ssh flags=A |>

Now We Can Send 1 Packet And Verify It


>>> send=sendp(L2/L3/L4)

.

Sent 1 packets.

Now Verify In WireShark 


##########################################################################################################