scapy

How to extract Raw of TCP packet using Scapy

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 19:16:58
问题 I use the sniff function of scapy module. My filter and prn function are doing a great job. But now, I would like to extract the Raw of the TCP packet and handle it using hexadecimal or binary format. Here is the documentation of Packet Class in scapy. How can I do that ? I tried print packet[Raw] but it seems to be converted as ASCII or something like that. I want to keep it in hexadecimal or binary. 回答1: You can get the raw bytes of the packet via str(packet) . For printing them to the

Python Ethical Hacking - MODIFYING DATA IN HTTP LAYER(3)

我怕爱的太早我们不能终老 提交于 2019-11-29 12:04:53
Refactoring and Housekeeping: #!/usr/bin/env python import re from netfilterqueue import NetfilterQueue from scapy.layers.inet import TCP, IP from scapy.packet import Raw def set_load(packet, load): packet[Raw].load = load del packet[IP].len del packet[IP].chksum del packet[TCP].chksum return packet def process_packet(packet): scapy_packet = IP(packet.get_payload()) if scapy_packet.haslayer(Raw) and scapy_packet.haslayer(TCP): load = scapy_packet[Raw].load if scapy_packet[TCP].dport == 80: print("[+] Request") load = re.sub(b"Accept-Encoding:.*?\\r\\n", b"", load) elif scapy_packet[TCP].sport

how to add http headers to a packet sniffed using scapy

隐身守侯 提交于 2019-11-29 11:05:13
I am trying to sniff an out going http packet using scapy, add a few new http headers in it and send it ahead. The intention here is to only insert new headers while keeping the packet intact. At max any checksum recalculation should be done if needed. Have been through almost all questions on SO but didn't exactly get a solution. Following is what i have done. def parse(pkt): if pkt.haslayer(TCP) and pkt.getlayer(TCP).dport == 80 and pkt.haslayer(Raw): pkt = pkt / "New Header:value\r\n\r\n" # OR i tried this #pkt = pkt.getlayer(Raw).load / Raw.load(load="New Header:value\r\n\r\n") #pkt

3 way handshake in Scapy

我怕爱的太早我们不能终老 提交于 2019-11-29 10:31:55
Im trying to build a 3 way handshake in Scapy. Using the following code, #!/usr/local/bin/python from scapy.all import * sport = random.randint(1024,65535) # SYN ip=IP(src='172.16.120.5',dst='172.16.100.101') SYN=TCP(sport=sport,dport=443,flags='S',seq=1000) SYNACK=sr1(ip/SYN) # ACK my_ack = SYNACK.seq + 1 ACK=TCP(sport=sport, dport=443, flags='A', seq=1001, ack=my_ack) send(ip/ACK) However on the server I see only SYN_RECV even though the return SYN-ACK is sent and the ACK is sent in return. Here is a capture from the server (172.16.100.101), 08:10:19.455038 IP 172.16.120.5.58972 > 172.16.100

Pinging an IP range with Scapy

冷暖自知 提交于 2019-11-29 10:31:27
I'm attempting to write a Python script which uses the Scapy module to ping an internal IP range to determine which IP's are online. I've got this so far: #!/usr/bin/python from scapy.all import * conf.verb = 0 for ip in range(0, 256): packet = IP(dst="192.168.0." + str(ip), ttl=20)/ICMP() reply = sr1(packet) if "192.168." in reply.src: print reply.src, "is online" And the program will sit for a while doing nothing, and then if I kill it with CTRL+C I get an error message: Traceback (most recent call last): File "sweep.py", line 7, in <module> if "192.168." in reply.src: AttributeError:

Python Ethical Hacking - DNS Spoofing

心已入冬 提交于 2019-11-29 03:25:39
What is DNS Spoofing Sniff the DNSRR packet and show on the terminal. #!/usr/bin/env python from netfilterqueue import NetfilterQueue from scapy.layers.dns import DNSRR,IP def process_packet(packet): scapy_packet = IP(packet.get_payload()) if scapy_packet.haslayer(DNSRR): print(scapy_packet.show()) packet.accept() queue = NetfilterQueue() queue.bind(0, process_packet) try: queue.run() except KeyboardInterrupt: print('') Analyze the following DNSRR records. ###[ IP ]### version = 4 ihl = 5 tos = 0x0 len = 218 id = 0 flags = DF frag = 0 ttl = 64 proto = udp chksum = 0x25e8 src = 10.0.0.1 dst =

Importing python modules in jython

馋奶兔 提交于 2019-11-29 01:56:22
I'm having some issues importing scapy under jython. I've been doing java forever, but python for only a day or two. The simple case to reproduce the problem is: $jython >>> import sys >>> sys.path ['', '/usr/share/jython/Lib', '/usr/lib/site-python', '__classpath__'] >>> from scapy.all import * Traceback (innermost last): File "<console>", line 1, in ? ImportError: no module named scapy If I do these exact same steps under python , everything works. How do I tell jython to use scapy? If it helps, I'm running ubuntu 10.04 and installed jython and scapy via apt-get install You've done the right

Get TCP Flags with Scapy

泪湿孤枕 提交于 2019-11-29 01:46:17
I'm parsing a PCAP file and I need to extract TCP flags (SYN, ACK, PSH, URG, ...). I'm using the packet['TCP'].flags value to obtain all the flags at once. pkts = PcapReader(infile) for p in pkts: F = bin(p['TCP'].flags) print F, bin(F), p.summary() # manual flags extraction from F Is there a way to obtain a single TCP flag without manually extract it from packet['TCP'].flags value? Normally, the usual way to handle FLAGS is with a bitmap and bitwise operators. If your Packet class doesn't have specific method to test for flags, the best thing you can do IMHO is to: FIN = 0x01 SYN = 0x02 RST =

Change TCP Payload with nfqueue/scapy

爷,独闯天下 提交于 2019-11-29 00:23:52
Hello I am using nfqueue and scapy and I my goal is to recieve packets at my NFQUEUE, change the payload and resend them. I can change fields like the TTL without any kind of problem, but when it comes to change the payload, I am encoutering problems. When I change the payload, I sniff the packet with wireshark and apparently I send the packet with the payload modified, but the server doesn't answer. This is my code: #!/usr/bin/env python import nfqueue from scapy.all import * def callback(payload): data = payload.get_data() pkt = IP(data) pkt[TCP].payload = str(pkt[TCP].payload).replace("ABC"

Scapy installation fails on osx with dnet import error

一个人想着一个人 提交于 2019-11-28 20:22:22
问题 Having trouble installing Scapy and it's required dependancies. I have spent some time Googling for a solution but all 'solutions' seem to affect older versions of Python, or simply do not work. Script: #!/usr/bin/python import threading import Queue import time from scapy.all import * class WorkerThread(threading.Thread) : def __init__(self, queue, tid) : threading.Thread.__init__(self) self.queue = queue self.tid = tid print 'Worker: %d' %self.tid def run(self) : total_ports = 0 while True