scapy

Get all the layers in a packet

百般思念 提交于 2019-12-04 05:40:55
How can I get a list of all the layers in scapy? Eg: Ether/IP/UDP/DNS or Ether/IP/TCP/HTTP . The only thing I can think of is to do a packet.summary() and parse the output, which seems very crude. I think there should be a method built-in, but cannot find any in the documentation. Any suggestions? What I am trying to do is to iterate over all the fields of a specific protocol given by a user and display its values. Update: What I am looking for exactly can be seen in wireshark: Open any capture, select a packet, and in the 'Frame' menu, one can see Protocols in frame: eth:ip:udp:data This is

Scapy BPF filter not working

心不动则不痛 提交于 2019-12-04 03:49:32
I am using Scapy and would like to filter based on the destination mac address. However, I am getting packets displayed where the destination MAC address is not the address specified in the filter. Here is a code snippit: from scapy.all import * sniff(iface="eth1", filter="ether dst host 91:e0:f0:01:00:00", count=3, prn=lambda x: x.show()) I am running Scapy 2.2.0 Any ideas on the issue here? Scapy requires numerous dependencies for many different systems. It is quiet possible that you don't have the required dependency for BPF filters to work. http://www.secdev.org/projects/scapy/portability

Filter options for sniff function in scapy

时光总嘲笑我的痴心妄想 提交于 2019-12-04 03:39:33
I'm working on a scapy based tool where at a point I need to sniff a packet based on protocol and the ip address of the destination I'd like to know about the ways in which filter option in sniff() function can be used. I tried using format in documentation but most of the times it results in problems like this. the filter of sniff function in scapy does not work properly . The one which I used was a=sniff(filter="host 172.16.18.69 and tcp port 80",prn = comp_pkt,count = 1) Thanks in advance! Jeff Bencteux sniff() uses Berkeley Packet Filter (BPF) syntax (the same one as tcpdump ), here are

Adding payload in packet

青春壹個敷衍的年華 提交于 2019-12-04 02:38:09
Can I insert image or document (in MBs) as a data in packet using scapy? This is what I did to send data. data = "University of texas at San Antonio" a = IP(dst="129.132.2.21")/TCP()/data send(a) Yes, you can send raw data like this. In this example, data will be ASCII encoded. >>> data = 'University of Texas at San Antonio' >>> a = IP(dst='129.132.2.21') / TCP() / Raw(load=data) >>> sendp(a) 来源: https://stackoverflow.com/questions/6605118/adding-payload-in-packet

Scapy and Python 3.2

别说谁变了你拦得住时间么 提交于 2019-12-04 01:51:41
Will Scapy be compatible with Python 3.2? I've been trying to find some info on how it performs, since the Scapy website has rather scarce (if any) info on Python 3.X compatibility, and I didn't come up with anything informative. Has anyone tried using it on Python 3.X and how did it perform? m01 Intrusive edit: Many answers below are outdated. Scapy now supports Python 3. See https://github.com/secdev/scapy Python 3 compatibility for parts of Scapy seems to have been attempted . It's perhaps worth filing a ticket on their bug tracker if there isn't one already (I tried searching and didn't

suppress scapy warning message when importing the module

扶醉桌前 提交于 2019-12-04 00:17:38
I'm writing a small script, that gathers some information using scapy and then returns some xml code, that I'll pass on to the xmlrpc interface of metasploit. I'd like it that my script only returns xml, and no additional warnings etc. I can suppress most scapy output, with adding the option verbose=0 to my sr1 command. What I still get before every output, and I assume it returns this warning when I'm loading the module, is: WARNING: No route found for IPv6 destination :: (no default route?) I can easily redirect that output, by calling my script like this: ./myscript 2> /dev/null but I'd

HTTP GET packet sniffer in Scapy

血红的双手。 提交于 2019-12-03 15:00:56
I am trying to code a simple sniffer in Scapy, which only prints HTTP packets with GET method only. Here's the code: #!/usr/bin/python from scapy.all import * def http_header(packet): http_packet=str(packet) if http_packet.find('GET'): print GET_print(packet) print packet def GET_print(packet1): print "***************************************GET PACKET****************************************************" print packet1 print "*****************************************************************************************************" sniff(iface='eth0',prn=http_header) Here is the output: *************

python中安装下载超时,下载不了安装包

本秂侑毒 提交于 2019-12-03 14:29:21
python3 -m pip install scapy 执行上面命令报错,下载超时,下载不了安装包 Collecting scapy WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. (read timeout=15)")': /packages/52/e7/464079606a9cf97ad04936c52a5324d14dae36215f9319bf3faa46a7907d/scapy-2.4.3.tar.gz WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at

Raw sockets and sendto in python

眉间皱痕 提交于 2019-12-03 11:55:21
问题 I am working on integrating scapy with twisted, but I ran into this very weird bug on OSX that I can't seem to figure out. Basically I am unable to send a valid TCP packet (inclusive of IP headers) via a raw socket. This is what I am doing: import socket from scapy.all import IP, TCP pkt = IP(src='0.0.0.0', dst='127.0.0.1')/TCP() spkt1 = str(pkt) outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW) outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1) outs.sendto(spkt1, (

Scapy installation fails due to invalid token

你。 提交于 2019-12-03 10:25:53
I have recently taken up learning networks, and I want to install scapy. I have downloaded the latest version (2.2.0), and have two versions of python on my computer- 2.6.1 and 3.3.2. My OS is windows 7 64 bit. After extracting scapy and navigating to the correct folder in the terminal, I was instructed to run "python setup.py install". I get the following error- File "setup.py", line 35 os.chmod(fname,0755) ................................^ ......................invalid token (dots for alignment) How do I solve this problem? galath Update: scapy-python3 is deprecated (2018) and will no longer