scapy

How to create HTTP GET request Scapy?

橙三吉。 提交于 2019-11-28 14:02:48
I need to create HTTP GET request and save the data response. I tried to use this: syn = IP(dst=URL) / TCP(dport=80, flags='S') syn_ack = sr1(syn) getStr = 'GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n' request = IP(dst='www.google.com') / TCP(dport=80, sport=syn_ack[TCP].dport, seq=syn_ack[TCP].ack, ack=syn_ack[TCP].seq + 1, flags='A') / getStr reply = sr1(request) print reply.show() But when I print reply I don't see any data response. In addition, when I checked in 'Wireshark' I got SYN, SYN/ACK but I didn't get an ACK. Image: Edit: I try to do that now: # Import scapy from scapy.all

Network bridge using Scapy and Python

白昼怎懂夜的黑 提交于 2019-11-28 11:32:36
I am creating a network bridge that connects two ethernet cards on the same machine. One of the cards is connected to the LAN and the other is connected to a network device. It looks something like this, I am sniffing packets on both the interfaces and then sending them to the other using sendp(x,iface='eth0') for a packet that I sniffed on eth1 and vice versa. I verified the packets at both the interfaces and found them to be correct, but somehow I am unable to get an IP for the device. Below is a piece of my code, I create two threads, one for each interface: from scapy.all import* **THREAD1

Scapy fails to sniff packets when using multiple threads

主宰稳场 提交于 2019-11-28 10:14:07
I'll try to demonstrate my problem with a simplified example. Following is a very simple (single threaded) packet sniffer (ICMP): from scapy.all import * m_iface = "wlan0" m_dst = "192.168.0.1" def print_summary(pkt): print pkt.summary() def plain_sniff(): sniff(iface = m_iface, count = 10, filter = "icmp and src {0}".format(m_dst), prn = print_summary) This sniffer works just fine and I get the output: WARNING: No route found for IPv6 destination :: (no default route?) Ether / IP / ICMP 192.168.0.1 > 192.168.0.9 echo-reply 0 / Raw Ether / IP / ICMP 192.168.0.1 > 192.168.0.9 echo-reply 0 / Raw

So since Scapy has been renamed to Kamene, how would I import and use base64_bytes?

时间秒杀一切 提交于 2019-11-28 09:37:13
问题 So I used to be able to import scapy's base64_bytes by using from scapy.all import base64_bytes . However, I get this error when I do that: PIP package scapy-python3 used to provide scapy3k, which was a fork from scapy implementing python3 compatibility since 2016. This package was included in some of the Linux distros under name of python3-scapy. Starting from scapy version 2.4 (released in March, 2018) mainstream scapy supports python3. To reduce any confusion scapy3k was renamed to kamene.

Extract received data in a tcp socket in Python

女生的网名这么多〃 提交于 2019-11-28 07:11:54
问题 I have a client sending a packet with a custom layer "Reservation" created with Scapy Client.py #!/usr/bin/env python import socket from scapy.all import * class Reservation(Packet): name = "ReservationPacket" fields_desc=[ ShortField("id", 0), BitField("type",None, 0), X3BytesField("update", 0), ByteField("rssiap", 0)] pkt = IP(len=16384, src='192.168.240.5', dst='192.168.240.198', id=RandShort(), ttl=2)/TCP(sport=5005, dport=5005, flags="S", window=200, options=[('MSS', 1460), ('WScale', 2)

compile libdnet for python 2.7

三世轮回 提交于 2019-11-28 05:44:35
问题 I'm trying to use scapy on win32 python2.7 I've manage to compile all the other dependencies expect this one can some help in the goal of reaching this executable ? "dnet-1.12.win32-py2.7.exe" (I promise to update the this question too and the scapy manual, Running Scapy on Windows with Python 2.7) Update: I've managed to compile it with mingw32 I'm using vs2005, and I have to make some fixes to libdnet to actually work (look like last time they compiled it on windows it was with vs6.0 I'll

how to add http headers to a packet sniffed using scapy

孤人 提交于 2019-11-28 04:55:37
问题 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"

Fetch source address and port number of packet - Scapy script

会有一股神秘感。 提交于 2019-11-28 04:44:45
问题 I am doing a sniffing of the network and trying to get ip address and port number on every tcp packet. I used scapy with python and could successfully sniff packets and in a callback function could even print the packet summary. But I would want to do more, like fetching only the IP address of the source and its port number. How can i accomplish it? Below is my code: #!/usr/bin/evn python from scapy.all.import.* def print_summary(pkt): packet = pkt.summary() print packet sniff(filter="tcp"

3 way handshake in Scapy

有些话、适合烂在心里 提交于 2019-11-28 03:47:32
问题 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.

How to calculate a packet checksum without sending it?

烂漫一生 提交于 2019-11-27 21:18:31
I'm using scapy, and I want to create a packet and calculate its' checksum without sending it. Is there a way to do it? Thanks. You need to delete the .chksum value from the packet after you create it; then call .show2() >>> from scapy.layers.inet import IP >>> from scapy.layers.inet import ICMP >>> from scapy.layers.inet import TCP >>> target = "10.9.8.7" >>> ttl = 64 >>> id = 32711 >>> sport = 2927 >>> dport = 80 >>> pak = IP(dst=target, src = "100.99.98.97", ttl=ttl, flags="DF", id=id, len=1200, chksum = 0)/TCP(flags="S", sport=sport, dport=int(dport), options=[('Timestamp',(0,0))], chksum