Scrapy

(last edited: 08/27/2019)

Overview

* When you craft TCP packets with Scapy, the underlying OS will not recognize the initial SYN packet and will reply with a RST packet. To mitigate this you need to set the following Iptables rule:

 iptables -A OUTPUT -p tcp --tcp-flags RST RST -j DROP 
from scapy.all import *   Imports all scapy libraries
ls()  List all available protocols
lsc()   List all scapy functions
conf  Show/set scapy config
IP(src=RandIP())  Generate random src IPs
Ether(src=RandMAC())  Generate random src MACs
ip=IP(src="1.1.1.1",dst="2.2.2.2")  Specify IP parameters
tcp=TCP(dport="443")  Specify TCP parameters
data="TCP data"   Specify data portion
packet=ip/tcp/data  Create IP()/TCP() packet
packet.show()   Display packet configuration
send(packet,count=1)  Send 1 packet @ layer 3
sendp(packet,count=2)   Send 2 packets @ layer 2
sendpfast(packet)   Send faster using tcpreply
sr(packet)  Send 1 packet & get replies
srl(packet)   Send only return 1st reply
for i in range(0,1000): send (packet)   Send (packet) 1000 times
sniff(count=100,iface=eth0)   Sniff 100 packets on eth0
Top - Home


SEND IPv6 IC:MP MSG

>> sr(IPv6(src="<ipv6>", dst="<ipv6>")/ICMP()) 
Top - Home


UDP PACKET TA7/ SPECIFIC PAYLOAD

>>> ip=IP(src="<ip>", dst="<ip>") 
>>> u=UDP(dport=1234, sport=5678)
>>> pay = "my UDP packet"
>>> packet=ip/u/pay 
>>> packet.show() 
>>> wrpcap ("out.pcap",packet) : write to pcap
>>> send(packet) 
Top - Home


NTP FUZZER

packet=IP(src="<ip>", 
dst="<ip>")/UDP(dport=123)/fuzz(NTP(version=4,mode=4)) 
Top - Home


SEND HTTP MESSAGE

from scapy.all import * 
# Add iptables rule to block attack box from sending RSTs 
# Create web.txt with entire GET/POST packet data 
fileweb = open("web.txt",'r')
data = fileweb.read() 
ip = IP(dst="<ip>") 
SYN=ip/TCP(rport=RandNum(6000,7000),dport=80,flags="S",seq=4) 
SYNACK = sr1(SYN) 
ACK=ip/TCP(sport=SYNACK.dport,dport=80,flags="A",seq=SYNACK.ack,ack=SYNACK.seq+1)/data 
reply,error = sr(ACK) 
print reply. show() 
Top - Home