├── .config ├── ci │ ├── install.ps1 │ ├── install.sh │ ├── openldap │ │ ├── config.ldif │ │ ├── install.sh │ │ └── testdata.ldif │ ├── openssl.py │ ├── test.ps1 │ ├── test.sh │ ├── windows │ │ ├── InstallNpcap.ps1 │ │ └── InstallWindumpNpcap.ps1 │ └── zipapp.sh ├── codespell_ignore.txt └── mypy │ ├── mypy.ini │ ├── mypy_check.py │ ├── mypy_deployment_stats.py │ └── mypy_enabled.txt ├── .git-blame-ignore-revs ├── .gitattributes ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── BUGS.yml │ └── config.yml ├── PULL_REQUEST_TEMPLATE.md ├── codecov.yml └── workflows │ ├── cifuzz.yml │ └── unittests.yml ├── .gitignore ├── .packit.yml ├── .readthedocs.yml ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── MANIFEST.in ├── README.md ├── doc ├── LICENSE ├── notebooks │ ├── HTTP_2_Tuto.ipynb │ ├── Scapy in 15 minutes.ipynb │ ├── graphs-ipids.ipynb │ └── tls │ │ ├── images │ │ ├── handshake_tls12.png │ │ └── handshake_tls13.png │ │ ├── notebook1_x509.ipynb │ │ ├── notebook2_tls_protected.ipynb │ │ ├── notebook3_tls_compromised.ipynb │ │ ├── notebook4_tls13.ipynb │ │ └── raw_data │ │ ├── README.md │ │ ├── pki │ │ ├── ca_cert.der │ │ ├── ca_key.der │ │ ├── srv_cert.pem │ │ └── srv_key.pem │ │ ├── tls_nss_example.keys.txt │ │ ├── tls_nss_example.pcap │ │ ├── tls_session_13 │ │ ├── 01_cli.raw │ │ ├── 02_srv.raw │ │ ├── 03_srv.raw │ │ ├── 04_srv.raw │ │ ├── 05_srv.raw │ │ ├── 06_srv.raw │ │ ├── 07_cli.raw │ │ ├── 08_cli.raw │ │ ├── 09_srv.raw │ │ ├── cli_key.raw │ │ └── srv_key.raw │ │ ├── tls_session_compromised │ │ ├── 01_cli.raw │ │ ├── 02_srv.raw │ │ ├── 03_cli.raw │ │ ├── 04_srv.raw │ │ └── 05_cli.raw │ │ └── tls_session_protected │ │ ├── 01_cli.raw │ │ ├── 02_srv.raw │ │ ├── 03_srv.raw │ │ ├── 04_srv.raw │ │ ├── 05_cli.raw │ │ ├── 06_srv.raw │ │ └── 07_cli.raw ├── scapy.1 ├── scapy │ ├── Makefile │ ├── README │ ├── _ext │ │ ├── linkcode_res.py │ │ └── scapy_doc.py │ ├── _static │ │ └── _dummy │ ├── _templates │ │ ├── README.md │ │ ├── module.rst_t │ │ └── package.rst_t │ ├── advanced_usage.rst │ ├── backmatter.rst │ ├── build_dissect.rst │ ├── conf.py │ ├── development.rst │ ├── extending.rst │ ├── functions.rst │ ├── graphics │ │ ├── ATMT_HelloWorld.png │ │ ├── ATMT_TCP_client.svg │ │ ├── ATMT_TFTP_read.png │ │ ├── animations │ │ │ ├── animation-cansend.svg │ │ │ ├── animation-rdcandump.svg │ │ │ ├── animation-scapy-asyncsniffer.svg │ │ │ ├── animation-scapy-can.svg │ │ │ ├── animation-scapy-canframe.svg │ │ │ ├── animation-scapy-cansockets-mitm.svg │ │ │ ├── animation-scapy-cansockets-mitm2.svg │ │ │ ├── animation-scapy-cansockets-sniff.svg │ │ │ ├── animation-scapy-gmlan.svg │ │ │ ├── animation-scapy-isotpscan.svg │ │ │ ├── animation-scapy-native-cansocket.svg │ │ │ ├── animation-scapy-obd.svg │ │ │ ├── animation-scapy-rdcandump.svg │ │ │ ├── animation-scapy-rdpcap.svg │ │ │ ├── animation-scapy-uds.svg │ │ │ ├── animation-scapy-uds2.svg │ │ │ ├── animation-scapy-uds3.svg │ │ │ └── pipetool_demo.gif │ │ ├── automotive │ │ │ ├── CAN-full-frame.jpg │ │ │ ├── DC-ZGW-CAN-Bus-.png │ │ │ ├── Simple-CAN-Bus-.png │ │ │ ├── XCP_ReferenceBook.png │ │ │ ├── ZGW-CAN-Bus-.png │ │ │ ├── autosar1.png │ │ │ ├── autosar2.png │ │ │ ├── autosar3.png │ │ │ ├── autosar4.png │ │ │ ├── can-bus-states.png │ │ │ ├── can-frame-socket-can.png │ │ │ ├── diag-stack.png │ │ │ ├── isotp-flow.png │ │ │ └── isotp-frames.png │ │ ├── ble_eddystone_url.png │ │ ├── ble_ibeacon.png │ │ ├── command-ls.png │ │ ├── dcerpc │ │ │ ├── ndr_conformant_varying_array.png │ │ │ └── ndr_full_pointer.png │ │ ├── default-values-ip.pdf │ │ ├── default-values-ip.png │ │ ├── fieldsmanagement.pdf │ │ ├── fieldsmanagement.png │ │ ├── graph_traceroute.png │ │ ├── http_tcp.png │ │ ├── ipid.png │ │ ├── isakmp_dump.png │ │ ├── kerberos │ │ │ ├── as_req_fast.png │ │ │ ├── kerberos_atmt.png │ │ │ ├── ticketer.png │ │ │ └── wireshark_asreq.png │ │ ├── pipetool_demo.svg │ │ ├── pipetool_engine.png │ │ ├── scapy-concept.pdf │ │ ├── scapy-concept.png │ │ ├── scapy-win-screenshot1.png │ │ ├── scapy-win-screenshot2.png │ │ ├── scapy_logo.png │ │ ├── smb │ │ │ ├── smb_client.png │ │ │ └── smb_server.png │ │ ├── testing-taxonomy.png │ │ ├── trace3d_1.png │ │ ├── trace3d_2.png │ │ └── traceroute_worldplot.png │ ├── index.rst │ ├── installation.rst │ ├── introduction.rst │ ├── layers │ │ ├── automotive.rst │ │ ├── bluetooth.rst │ │ ├── dcerpc.rst │ │ ├── dotnet.rst │ │ ├── gssapi.rst │ │ ├── http.rst │ │ ├── index.rst │ │ ├── kerberos.rst │ │ ├── ldap.rst │ │ ├── netflow.rst │ │ ├── pnio.rst │ │ ├── sctp.rst │ │ ├── smb.rst │ │ ├── tcp.rst │ │ └── tuntap.rst │ ├── make.bat │ ├── routing.rst │ ├── troubleshooting.rst │ └── usage.rst ├── scapy_logo.png ├── syntax │ └── vim_uts_syntax │ │ ├── ftdetect │ │ ├── filetype.vim │ │ └── uts.vim │ │ ├── install.sh │ │ └── syntax │ │ └── uts.vim └── vagrant_ci │ ├── README.md │ ├── Vagrantfile │ ├── provision_freebsd.sh │ ├── provision_netbsd.sh │ └── provision_openbsd.sh ├── pyproject.toml ├── run_scapy ├── run_scapy.bat ├── scapy ├── __init__.py ├── __main__.py ├── all.py ├── ansmachine.py ├── arch │ ├── __init__.py │ ├── bpf │ │ ├── __init__.py │ │ ├── consts.py │ │ ├── core.py │ │ ├── pfroute.py │ │ └── supersocket.py │ ├── common.py │ ├── libpcap.py │ ├── linux │ │ ├── __init__.py │ │ └── rtnetlink.py │ ├── solaris.py │ ├── unix.py │ └── windows │ │ ├── __init__.py │ │ ├── native.py │ │ └── structures.py ├── as_resolvers.py ├── asn1 │ ├── __init__.py │ ├── asn1.py │ ├── ber.py │ └── mib.py ├── asn1fields.py ├── asn1packet.py ├── automaton.py ├── autorun.py ├── base_classes.py ├── compat.py ├── config.py ├── consts.py ├── contrib │ ├── __init__.py │ ├── altbeacon.py │ ├── aoe.py │ ├── automotive │ │ ├── __init__.py │ │ ├── autosar │ │ │ ├── __init__.py │ │ │ ├── pdu.py │ │ │ ├── secoc.py │ │ │ ├── secoc_canfd.py │ │ │ └── secoc_pdu.py │ │ ├── bmw │ │ │ ├── __init__.py │ │ │ ├── definitions.py │ │ │ ├── enumerator.py │ │ │ └── hsfz.py │ │ ├── ccp.py │ │ ├── doip.py │ │ ├── ecu.py │ │ ├── gm │ │ │ ├── __init__.py │ │ │ ├── gmlan.py │ │ │ ├── gmlan_ecu_states.py │ │ │ ├── gmlan_logging.py │ │ │ ├── gmlan_scanner.py │ │ │ └── gmlanutils.py │ │ ├── kwp.py │ │ ├── obd │ │ │ ├── __init__.py │ │ │ ├── iid │ │ │ │ ├── __init__.py │ │ │ │ └── iids.py │ │ │ ├── mid │ │ │ │ ├── __init__.py │ │ │ │ └── mids.py │ │ │ ├── obd.py │ │ │ ├── packet.py │ │ │ ├── pid │ │ │ │ ├── __init__.py │ │ │ │ ├── pids.py │ │ │ │ ├── pids_00_1F.py │ │ │ │ ├── pids_20_3F.py │ │ │ │ ├── pids_40_5F.py │ │ │ │ ├── pids_60_7F.py │ │ │ │ ├── pids_80_9F.py │ │ │ │ └── pids_A0_C0.py │ │ │ ├── scanner.py │ │ │ ├── services.py │ │ │ └── tid │ │ │ │ ├── __init__.py │ │ │ │ └── tids.py │ │ ├── scanner │ │ │ ├── __init__.py │ │ │ ├── configuration.py │ │ │ ├── enumerator.py │ │ │ ├── executor.py │ │ │ ├── graph.py │ │ │ ├── staged_test_case.py │ │ │ └── test_case.py │ │ ├── someip.py │ │ ├── uds.py │ │ ├── uds_ecu_states.py │ │ ├── uds_logging.py │ │ ├── uds_scan.py │ │ ├── volkswagen │ │ │ ├── __init__.py │ │ │ └── definitions.py │ │ └── xcp │ │ │ ├── __init__.py │ │ │ ├── cto_commands_master.py │ │ │ ├── cto_commands_slave.py │ │ │ ├── scanner.py │ │ │ ├── utils.py │ │ │ └── xcp.py │ ├── avs.py │ ├── bfd.py │ ├── bgp.py │ ├── bier.py │ ├── bp.py │ ├── cansocket.py │ ├── cansocket_native.py │ ├── cansocket_python_can.py │ ├── carp.py │ ├── cdp.py │ ├── chdlc.py │ ├── coap.py │ ├── concox.py │ ├── diameter.py │ ├── dtp.py │ ├── eddystone.py │ ├── eigrp.py │ ├── enipTCP.py │ ├── erspan.py │ ├── esmc.py │ ├── ethercat.py │ ├── etherip.py │ ├── exposure_notification.py │ ├── geneve.py │ ├── gtp.py │ ├── gtp_v2.py │ ├── gxrp.py │ ├── hicp.py │ ├── homeplugav.py │ ├── homepluggp.py │ ├── homeplugsg.py │ ├── http2.py │ ├── ibeacon.py │ ├── icmp_extensions.py │ ├── ife.py │ ├── igmp.py │ ├── igmpv3.py │ ├── ikev2.py │ ├── isis.py │ ├── isotp │ │ ├── __init__.py │ │ ├── isotp_native_socket.py │ │ ├── isotp_packet.py │ │ ├── isotp_scanner.py │ │ ├── isotp_soft_socket.py │ │ └── isotp_utils.py │ ├── knx.py │ ├── lacp.py │ ├── ldp.py │ ├── lldp.py │ ├── loraphy2wan.py │ ├── ltp.py │ ├── mac_control.py │ ├── macsec.py │ ├── metawatch.py │ ├── modbus.py │ ├── mount.py │ ├── mpls.py │ ├── mqtt.py │ ├── mqttsn.py │ ├── nfs.py │ ├── nlm.py │ ├── nrf_sniffer.py │ ├── nsh.py │ ├── oam.py │ ├── oncrpc.py │ ├── opc_da.py │ ├── openflow.py │ ├── openflow3.py │ ├── ospf.py │ ├── pfcp.py │ ├── pim.py │ ├── pnio.py │ ├── pnio_dcp.py │ ├── pnio_rpc.py │ ├── portmap.py │ ├── postgres.py │ ├── ppi_cace.py │ ├── ppi_geotag.py │ ├── psp.py │ ├── ripng.py │ ├── roce.py │ ├── rpl.py │ ├── rpl_metrics.py │ ├── rsvp.py │ ├── rtcp.py │ ├── rtps │ │ ├── __init__.py │ │ ├── common_types.py │ │ ├── pid_types.py │ │ └── rtps.py │ ├── rtr.py │ ├── rtsp.py │ ├── scada │ │ ├── __init__.py │ │ ├── iec104 │ │ │ ├── __init__.py │ │ │ ├── iec104_fields.py │ │ │ ├── iec104_information_elements.py │ │ │ └── iec104_information_objects.py │ │ └── pcom.py │ ├── sdnv.py │ ├── sebek.py │ ├── send.py │ ├── skinny.py │ ├── slowprot.py │ ├── socks.py │ ├── stamp.py │ ├── stun.py │ ├── tacacs.py │ ├── tcpao.py │ ├── tcpros.py │ ├── tzsp.py │ ├── vqp.py │ ├── vtp.py │ └── wireguard.py ├── dadict.py ├── data.py ├── error.py ├── fields.py ├── interfaces.py ├── layers │ ├── __init__.py │ ├── all.py │ ├── bluetooth.py │ ├── bluetooth4LE.py │ ├── can.py │ ├── clns.py │ ├── dcerpc.py │ ├── dhcp.py │ ├── dhcp6.py │ ├── dns.py │ ├── dot11.py │ ├── dot15d4.py │ ├── eap.py │ ├── gprs.py │ ├── gssapi.py │ ├── hsrp.py │ ├── http.py │ ├── inet.py │ ├── inet6.py │ ├── ipsec.py │ ├── ir.py │ ├── isakmp.py │ ├── kerberos.py │ ├── l2.py │ ├── l2tp.py │ ├── ldap.py │ ├── llmnr.py │ ├── lltd.py │ ├── mgcp.py │ ├── mobileip.py │ ├── ms_nrtp.py │ ├── msrpce │ │ ├── __init__.py │ │ ├── all.py │ │ ├── ept.py │ │ ├── msdcom.py │ │ ├── msdrsr.py │ │ ├── msnrpc.py │ │ ├── mspac.py │ │ ├── raw │ │ │ ├── README.md │ │ │ ├── __init__.py │ │ │ ├── ept.py │ │ │ ├── ms_dcom.py │ │ │ ├── ms_drsr.py │ │ │ ├── ms_nrpc.py │ │ │ ├── ms_samr.py │ │ │ ├── ms_srvs.py │ │ │ └── ms_wkst.py │ │ ├── rpcclient.py │ │ └── rpcserver.py │ ├── netbios.py │ ├── netflow.py │ ├── ntlm.py │ ├── ntp.py │ ├── pflog.py │ ├── ppi.py │ ├── ppp.py │ ├── pptp.py │ ├── quic.py │ ├── radius.py │ ├── rip.py │ ├── rtp.py │ ├── sctp.py │ ├── sixlowpan.py │ ├── skinny.py │ ├── smb.py │ ├── smb2.py │ ├── smbclient.py │ ├── smbserver.py │ ├── snmp.py │ ├── spnego.py │ ├── ssh.py │ ├── tftp.py │ ├── tls │ │ ├── __init__.py │ │ ├── all.py │ │ ├── automaton.py │ │ ├── automaton_cli.py │ │ ├── automaton_srv.py │ │ ├── basefields.py │ │ ├── cert.py │ │ ├── crypto │ │ │ ├── __init__.py │ │ │ ├── all.py │ │ │ ├── cipher_aead.py │ │ │ ├── cipher_block.py │ │ │ ├── cipher_stream.py │ │ │ ├── ciphers.py │ │ │ ├── common.py │ │ │ ├── compression.py │ │ │ ├── groups.py │ │ │ ├── h_mac.py │ │ │ ├── hash.py │ │ │ ├── hkdf.py │ │ │ ├── kx_algs.py │ │ │ ├── md4.py │ │ │ ├── pkcs1.py │ │ │ ├── prf.py │ │ │ └── suites.py │ │ ├── extensions.py │ │ ├── handshake.py │ │ ├── handshake_sslv2.py │ │ ├── keyexchange.py │ │ ├── keyexchange_tls13.py │ │ ├── quic.py │ │ ├── record.py │ │ ├── record_sslv2.py │ │ ├── record_tls13.py │ │ ├── session.py │ │ └── tools.py │ ├── tuntap.py │ ├── usb.py │ ├── vrrp.py │ ├── vxlan.py │ ├── x509.py │ └── zigbee.py ├── libs │ ├── __init__.py │ ├── ethertypes.py │ ├── extcap.py │ ├── manuf.py │ ├── matplot.py │ ├── rfc3961.py │ ├── structures.py │ ├── test_pyx.py │ └── winpcapy.py ├── main.py ├── modules │ ├── __init__.py │ ├── krack │ │ ├── __init__.py │ │ ├── automaton.py │ │ └── crypto.py │ ├── nmap.py │ ├── p0f.py │ ├── p0fv2.py │ ├── ticketer.py │ └── voip.py ├── packet.py ├── pipetool.py ├── plist.py ├── pton_ntop.py ├── py.typed ├── route.py ├── route6.py ├── scapypipes.py ├── sendrecv.py ├── sessions.py ├── supersocket.py ├── themes.py ├── tools │ ├── UTscapy.py │ ├── __init__.py │ ├── automotive │ │ ├── __init__.py │ │ ├── isotpscanner.py │ │ ├── obdscanner.py │ │ └── xcpscanner.py │ ├── check_asdis.py │ ├── check_spdx.sh │ ├── generate_ethertypes.py │ ├── generate_manuf.py │ └── scapy_pyannotate.py ├── utils.py ├── utils6.py └── volatile.py ├── setup.py ├── test ├── __init__.py ├── answering_machines.uts ├── benchmark │ ├── common.py │ ├── dissection_and_build.py │ └── latency_router.py ├── bpf.uts ├── configs │ ├── README.md │ ├── bsd.utsc │ ├── cryptography.utsc │ ├── linux.utsc │ ├── solaris.utsc │ ├── windows.utsc │ └── windows2.utsc ├── contrib │ ├── altbeacon.uts │ ├── aoe.uts │ ├── automotive │ │ ├── autosar │ │ │ ├── pdu.uts │ │ │ └── secoc.uts │ │ ├── bmw │ │ │ └── hsfz.uts │ │ ├── ccp.uts │ │ ├── doip.uts │ │ ├── ecu.uts │ │ ├── ecu_am.uts │ │ ├── gm │ │ │ ├── gmlan.uts │ │ │ ├── gmlanutils.uts │ │ │ └── scanner.uts │ │ ├── interface_mockup.py │ │ ├── kwp.uts │ │ ├── obd │ │ │ ├── obd.uts │ │ │ └── scanner.uts │ │ ├── scanner │ │ │ ├── configuration.uts │ │ │ ├── enumerator.uts │ │ │ ├── graph.uts │ │ │ ├── staged_test_case.uts │ │ │ ├── test_case.uts │ │ │ └── uds_scanner.uts │ │ ├── someip.uts │ │ ├── testsocket.uts │ │ ├── uds.uts │ │ └── xcp │ │ │ ├── xcp.uts │ │ │ └── xcp_comm.uts │ ├── avs.uts │ ├── bfd.uts │ ├── bgp.uts │ ├── bier.uts │ ├── bp.uts │ ├── canfdsocket_native.uts │ ├── canfdsocket_python_can.uts │ ├── cansocket.uts │ ├── cansocket_native.uts │ ├── cansocket_python_can.uts │ ├── carp.uts │ ├── cdp.uts │ ├── chdlc.uts │ ├── coap.uts │ ├── concox.uts │ ├── diameter.uts │ ├── dtp.uts │ ├── eddystone.uts │ ├── eigrp.uts │ ├── enipTCP.uts │ ├── erspan.uts │ ├── esmc.uts │ ├── ethercat.uts │ ├── etherip.uts │ ├── exposure_notification.uts │ ├── geneve.uts │ ├── gtp.uts │ ├── gtp_v2.uts │ ├── gxrp.uts │ ├── hicp.uts │ ├── homeplugav.uts │ ├── homepluggp.uts │ ├── homeplugsg.uts │ ├── http2.uts │ ├── ibeacon.uts │ ├── iec104.uts │ ├── ife.uts │ ├── igmp.uts │ ├── igmpv3.uts │ ├── ikev2.uts │ ├── isis.uts │ ├── isotp_message_builder.uts │ ├── isotp_native_socket.uts │ ├── isotp_packet.uts │ ├── isotp_soft_socket.uts │ ├── isotpscan.uts │ ├── knx.uts │ ├── lacp.uts │ ├── ldp.uts │ ├── lldp.uts │ ├── loraphy2wan.uts │ ├── ltp.uts │ ├── mac_control.uts │ ├── macsec.uts │ ├── metawatch.uts │ ├── modbus.uts │ ├── mount.uts │ ├── mpls.uts │ ├── mqtt.uts │ ├── mqttsn.uts │ ├── nfs.uts │ ├── nlm.uts │ ├── nsh.uts │ ├── oam.uts │ ├── oncrpc.uts │ ├── opc_da.uts │ ├── openflow.uts │ ├── openflow3.uts │ ├── ospf.uts │ ├── pcom.uts │ ├── pfcp.uts │ ├── pim.uts │ ├── pnio.uts │ ├── pnio_dcp.uts │ ├── pnio_rpc.uts │ ├── portmap.uts │ ├── postgres.uts │ ├── ppi_cace.uts │ ├── ppi_geotag.uts │ ├── psp.uts │ ├── ripng.uts │ ├── roce.uts │ ├── rpl.uts │ ├── rsvp.uts │ ├── rtcp.uts │ ├── rtps.uts │ ├── rtr.uts │ ├── rtsp.uts │ ├── sdnv.uts │ ├── sebek.uts │ ├── send.uts │ ├── socks.uts │ ├── stamp.uts │ ├── stun.uts │ ├── tacacs.uts │ ├── tcpao.uts │ ├── tcpros.uts │ ├── tzsp.uts │ ├── vqp.uts │ ├── vtp.uts │ └── wireguard.uts ├── fields.uts ├── imports.uts ├── linux.uts ├── nmap.uts ├── p0f.uts ├── p0fv2.uts ├── pcaps │ ├── bad_rsn_parsing_overrides_ssid.pcap │ ├── bgp_fragmented.pcap.gz │ ├── candump_gmlan_scanner.pcap.gz │ ├── candump_uds_scanner.pcap.gz │ ├── canfd.pcap.gz │ ├── dcerpc_msdrsr_cracknames.pcapng.gz │ ├── dcerpc_msnrpc.pcapng.gz │ ├── dcerpc_privacy_krb.pcapng.gz │ ├── dcerpc_privacy_ntlm.pcapng.gz │ ├── doip.pcap.gz │ ├── doip_ack.pcap │ ├── doip_functional_request.pcap.gz │ ├── ecu_trace.pcap.gz │ ├── gmlan_trace.pcap.gz │ ├── gvrp.pcapng.gz │ ├── http2_h2c.pcap │ ├── http_chunk.pcap.gz │ ├── http_compressed-brotli.pcap │ ├── http_compressed-zstd.pcap │ ├── http_compressed.pcap │ ├── http_content_length.pcap │ ├── http_head.pcapng.gz │ ├── http_tcp_psh.pcap.gz │ ├── ikev2_nat_t.pcapng │ ├── ikev2_notify_redirect.pcap │ ├── ipfix.pcap │ ├── macos.pcapng.gz │ ├── multiple_doip_layers.pcap.gz │ ├── netflowv9.pcap │ ├── pfcp.pcap │ ├── psp_v4_cleartext.pcap.gz │ ├── psp_v4_encrypt_transport_crypt_off_128.pcap.gz │ ├── psp_v4_encrypt_transport_crypt_off_128_vc.pcap.gz │ ├── psp_v4_encrypt_transport_crypt_off_256.pcap.gz │ ├── ssh_ed25519.pcap │ ├── tls_new-session-ticket.pcap │ ├── tls_tcp_frag.pcap.gz │ ├── tls_tcp_frag_withnss.pcap.gz │ ├── zigbee-join-authenticate.pcap │ └── zigbee-transport-key-skke_1.pcap ├── pipetool.uts ├── random.uts ├── regression.uts ├── run_tests ├── run_tests.bat ├── scapy │ ├── automaton.uts │ └── layers │ │ ├── asn1.uts │ │ ├── bluetooth.uts │ │ ├── bluetooth4LE.uts │ │ ├── can.uts │ │ ├── dcerpc.uts │ │ ├── dhcp.uts │ │ ├── dhcp6.uts │ │ ├── dns.uts │ │ ├── dns_dnssec.uts │ │ ├── dns_edns0.uts │ │ ├── dot11.uts │ │ ├── dot15d4.uts │ │ ├── eap.uts │ │ ├── hsrp.uts │ │ ├── http.uts │ │ ├── inet.uts │ │ ├── inet6.uts │ │ ├── ipsec.uts │ │ ├── isakmp.uts │ │ ├── kerberos.uts │ │ ├── l2.uts │ │ ├── l2tp.uts │ │ ├── ldap.uts │ │ ├── ldapopenldap.uts │ │ ├── llmnr.uts │ │ ├── lltd.uts │ │ ├── mgcp.uts │ │ ├── mobileip.uts │ │ ├── msdrsr.uts │ │ ├── msnrpc.uts │ │ ├── msnrtp.uts │ │ ├── netbios.uts │ │ ├── netflow.uts │ │ ├── ntlm.uts │ │ ├── ntp.uts │ │ ├── pflog.uts │ │ ├── ppp.uts │ │ ├── pptp.uts │ │ ├── quic.uts │ │ ├── radius.uts │ │ ├── rip.uts │ │ ├── rtp.uts │ │ ├── sctp.uts │ │ ├── skinny.uts │ │ ├── smb.uts │ │ ├── smb2.uts │ │ ├── smbclientserver.uts │ │ ├── snmp.uts │ │ ├── ssh.uts │ │ ├── tftp.uts │ │ ├── tls │ │ ├── __init__.py │ │ ├── cert.uts │ │ ├── example_client.py │ │ ├── example_server.py │ │ ├── pki │ │ │ ├── README.md │ │ │ ├── ca_cert.pem │ │ │ ├── ca_key.pem │ │ │ ├── cli_cert.pem │ │ │ ├── cli_key.pem │ │ │ ├── srv_cert.pem │ │ │ ├── srv_cert_ed25519.pem │ │ │ ├── srv_key.pem │ │ │ └── srv_key_ed25519.pem │ │ ├── sslv2.uts │ │ ├── tls.uts │ │ ├── tls13.uts │ │ └── tlsclientserver.uts │ │ ├── usb.uts │ │ ├── vrrp.uts │ │ ├── vxlan.uts │ │ └── x509.uts ├── sendsniff.uts ├── testsocket.py ├── tools │ ├── isotpscanner.uts │ ├── obdscanner.uts │ └── xcpscanner.uts ├── tuntap.uts └── windows.uts └── tox.ini /.config/ci/install.ps1: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | # Install packages needed for the CI on Windows 6 | 7 | # Install npcap and windump 8 | & "$PSScriptRoot\windows\InstallNpcap.ps1" 9 | & "$PSScriptRoot\windows\InstallWindumpNpcap.ps1" 10 | 11 | # Install wireshark 12 | choco install -y wireshark 13 | 14 | # Add to PATH 15 | echo "C:\Program Files\Wireshark;C:\Program Files\Windump" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append 16 | 17 | # Update pip & setuptools & wheel (tox uses those) 18 | python -m pip install --upgrade pip setuptools wheel --ignore-installed 19 | 20 | # Make sure tox is installed and up to date 21 | python -m pip install -U tox --ignore-installed 22 | -------------------------------------------------------------------------------- /.config/ci/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # SPDX-License-Identifier: GPL-2.0-only 4 | # This file is part of Scapy 5 | # See https://scapy.net/ for more information 6 | 7 | # Install packages needed for the CI on Linux/MacOS 8 | # Usage: 9 | # ./install.sh [install mode] 10 | 11 | # Detect install mode 12 | if [[ "${1}" == "libpcap" ]] 13 | then 14 | SCAPY_USE_LIBPCAP="yes" 15 | if [[ ! -z "$GITHUB_ACTIONS" ]] 16 | then 17 | echo "SCAPY_USE_LIBPCAP=yes" >> $GITHUB_ENV 18 | fi 19 | fi 20 | 21 | # Install on osx 22 | if [ "${OSTYPE:0:6}" = "darwin" ] 23 | then 24 | if [ ! -z $SCAPY_USE_LIBPCAP ] 25 | then 26 | brew update 27 | brew install libpcap 28 | fi 29 | fi 30 | 31 | CUR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 32 | 33 | # Install wireshark data, ifconfig, vcan, samba, openldap 34 | if [ "$OSTYPE" = "linux-gnu" ] 35 | then 36 | sudo apt-get update 37 | sudo apt-get -qy install tshark net-tools || exit 1 38 | sudo apt-get -qy install can-utils || exit 1 39 | sudo apt-get -qy install linux-modules-extra-$(uname -r) || exit 1 40 | sudo apt-get -qy install samba smbclient 41 | sudo bash $CUR/openldap/install.sh 42 | # Make sure libpcap is installed 43 | if [ ! -z $SCAPY_USE_LIBPCAP ] 44 | then 45 | sudo apt-get -qy install libpcap-dev || exit 1 46 | fi 47 | fi 48 | 49 | # Update pip & setuptools (tox uses those) 50 | python -m pip install --upgrade pip setuptools wheel --ignore-installed 51 | 52 | # Make sure tox is installed and up to date 53 | python -m pip install -U tox --ignore-installed 54 | 55 | # Dump Environment (so that we can check PATH, UT_FLAGS, etc.) 56 | set 57 | -------------------------------------------------------------------------------- /.config/ci/openldap/config.ldif: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | 4 | # Contains the configuration of our OpenLDAP test server 5 | 6 | # Configure LDAPS 7 | dn: cn=config 8 | changetype: modify 9 | add: olcTLSCACertificateFile 10 | olcTLSCACertificateFile: {{CAFILE}} 11 | 12 | dn: cn=config 13 | changetype: modify 14 | replace: olcTLSCertificateKeyFile 15 | olcTLSCertificateKeyFile: {{KEYFILE}} 16 | 17 | dn: cn=config 18 | changetype: modify 19 | replace: olcTLSCertificateFile 20 | olcTLSCertificateFile: {{CRTFILE}} 21 | 22 | dn: cn=config 23 | changetype: modify 24 | add: olcTLSVerifyClient 25 | olcTLSVerifyClient: never 26 | 27 | # Set channel bindings to 'tls-endpoint', like it would be on Windows 28 | dn: cn=config 29 | changetype: modify 30 | replace: olcSaslCbinding 31 | olcSaslCbinding: tls-endpoint 32 | -------------------------------------------------------------------------------- /.config/ci/openldap/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # SPDX-License-Identifier: GPL-2.0-only 4 | # This file is part of Scapy 5 | # See https://scapy.net/ for more information 6 | 7 | # Install an OpenLDAP test server 8 | 9 | # Pre-populate some setup questions 10 | sudo debconf-set-selections <<< 'slapd slapd/password2 password Bonjour1' 11 | sudo debconf-set-selections <<< 'slapd slapd/password1 password Bonjour1' 12 | sudo debconf-set-selections <<< 'slapd slapd/domain string scapy.net' 13 | 14 | # Run setup 15 | sudo apt-get -qy install slapd 16 | 17 | # Enable LDAPs 18 | echo "Enabling HTTPS on slapd..." 19 | sudo sed -i '/^SLAPD_SERVICES/ c\SLAPD_SERVICES="ldap:/// ldapi:/// ldaps://"' /etc/default/slapd 20 | sudo systemctl restart slapd 21 | 22 | # Calculate the paths we're going to need. 23 | CUR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 24 | PKIPATH=$(realpath "$CUR/../../../test/scapy/layers/tls/pki") 25 | OLDAPPATH=$(mktemp -d -t scapy_openldap_XXXX) 26 | 27 | # Copy certificates to temp path 28 | cp ${PKIPATH}/ca_cert.pem ${OLDAPPATH} 29 | cp ${PKIPATH}/srv_cert.pem ${OLDAPPATH} 30 | cp ${PKIPATH}/srv_key.pem ${OLDAPPATH} 31 | chmod a+rx -R ${OLDAPPATH} 32 | 33 | # Copy config template and replace variables. 34 | echo "Creating OpenLDAP config..." 35 | openldap_conf=${OLDAPPATH}/openldap_config.ldif 36 | cp $CUR/config.ldif $openldap_conf 37 | sed -i "s@{{CAFILE}}@${OLDAPPATH}/ca_cert.pem@g" $openldap_conf 38 | sed -i "s@{{CRTFILE}}@${OLDAPPATH}/srv_cert.pem@g" $openldap_conf 39 | sed -i "s@{{KEYFILE}}@${OLDAPPATH}/srv_key.pem@g" $openldap_conf 40 | 41 | echo "Applying OpenLDAP config..." 42 | sudo ldapmodify -Y EXTERNAL -H "ldapi:///" -w Bonjour1 -f $openldap_conf -c 43 | echo "Adding initial dummy data..." 44 | sudo ldapadd -D "cn=admin,dc=scapy,dc=net" -w Bonjour1 -H "ldapi:///" -f $CUR/testdata.ldif -c 45 | -------------------------------------------------------------------------------- /.config/ci/openldap/testdata.ldif: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: OLDAP-2.8 2 | # This file is based on https://git.openldap.org/openldap/openldap/-/blob/master/tests/data/ppolicy.ldif?ref_type=heads 3 | # (renamed to dc=scapy, dc=net) 4 | 5 | dn: dc=scapy, dc=net 6 | objectClass: top 7 | objectClass: organization 8 | objectClass: dcObject 9 | o: Scapy 10 | dc: scapy 11 | 12 | dn: ou=People, dc=scapy, dc=net 13 | objectClass: top 14 | objectClass: organizationalUnit 15 | ou: People 16 | 17 | dn: ou=Groups, dc=scapy, dc=net 18 | objectClass: organizationalUnit 19 | ou: Groups 20 | 21 | dn: cn=Policy Group, ou=Groups, dc=scapy, dc=net 22 | objectClass: groupOfNames 23 | cn: Policy Group 24 | member: uid=nd, ou=People, dc=scapy, dc=net 25 | owner: uid=ndadmin, ou=People, dc=scapy, dc=net 26 | 27 | dn: cn=Test Group, ou=Groups, dc=scapy, dc=net 28 | objectClass: groupOfNames 29 | cn: Policy Group 30 | member: uid=another, ou=People, dc=scapy, dc=net 31 | 32 | dn: ou=Policies, dc=scapy, dc=net 33 | objectClass: top 34 | objectClass: organizationalUnit 35 | ou: Policies 36 | 37 | dn: uid=nd, ou=People, dc=scapy, dc=net 38 | objectClass: top 39 | objectClass: person 40 | objectClass: inetOrgPerson 41 | cn: Neil Dunbar 42 | uid: nd 43 | sn: Dunbar 44 | givenName: Neil 45 | userPassword: testpassword 46 | 47 | dn: uid=ndadmin, ou=People, dc=scapy, dc=net 48 | objectClass: top 49 | objectClass: person 50 | objectClass: inetOrgPerson 51 | cn: Neil Dunbar (Admin) 52 | uid: ndadmin 53 | sn: Dunbar 54 | givenName: Neil 55 | userPassword: testpw 56 | 57 | dn: uid=another, ou=People, dc=scapy, dc=net 58 | objectClass: top 59 | objectClass: person 60 | objectClass: inetOrgPerson 61 | cn: Another Test 62 | uid: another 63 | sn: Test 64 | givenName: Another 65 | userPassword: testing 66 | 67 | -------------------------------------------------------------------------------- /.config/ci/openssl.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Gabriel Potter 5 | 6 | """ 7 | Create a duplicate of the OpenSSL config to be able to use TLS < 1.2 8 | This returns the path to this new config file. 9 | """ 10 | 11 | import os 12 | import re 13 | import subprocess 14 | import tempfile 15 | 16 | # Get OpenSSL config file 17 | OPENSSL_DIR = re.search( 18 | b"OPENSSLDIR: \"(.*)\"", 19 | subprocess.Popen( 20 | ["openssl", "version", "-d"], 21 | stdout=subprocess.PIPE 22 | ).communicate()[0] 23 | ).group(1).decode() 24 | OPENSSL_CONFIG = os.path.join(OPENSSL_DIR, 'openssl.cnf') 25 | 26 | # https://www.openssl.org/docs/manmaster/man5/config.html 27 | DATA = b""" 28 | openssl_conf = openssl_init 29 | 30 | [openssl_init] 31 | ssl_conf = ssl_configuration 32 | 33 | [ssl_configuration] 34 | system_default = tls_system_default 35 | 36 | [tls_system_default] 37 | MinProtocol = TLSv1 38 | CipherString = DEFAULT:@SECLEVEL=0 39 | Options = UnsafeLegacyRenegotiation 40 | """.strip() 41 | 42 | # Copy and edit 43 | with tempfile.NamedTemporaryFile(suffix=".cnf", delete=False) as fd: 44 | fd.write(DATA) 45 | print(fd.name) 46 | -------------------------------------------------------------------------------- /.config/ci/test.ps1: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | # test.ps1 6 | # Usage: 7 | # ./test.ps1 8 | # Examples: 9 | # ./test.sh 3.13 10 | 11 | if ($args.Count -eq 0) { 12 | Write-Host "Usage: .\test.ps1 " 13 | exit 14 | } 15 | 16 | # Set TOXENV 17 | $PY_VERSION = "py" + ($args[0] -replace '\.', '') 18 | $env:TOXENV = $PY_VERSION + "-windows-root" 19 | 20 | if ($env:GITHUB_ACTIONS) { 21 | # Due to a security policy, the firewall of the Azure runner 22 | # (Standard_DS2_v2) that runs Github Actions on Linux blocks ICMP. 23 | $env:UT_FLAGS += " -K icmp_firewall" 24 | } 25 | 26 | # Launch Scapy unit tests 27 | python -m tox -- @($env:UT_FLAGS.Trim() -split ' ') 28 | -------------------------------------------------------------------------------- /.config/ci/windows/InstallWindumpNpcap.ps1: -------------------------------------------------------------------------------- 1 | # Config 2 | $urlPath = "https://github.com/hsluoyz/WinDump/releases/download/v0.3/WinDump-for-Npcap-0.3.zip" 3 | $checksum = "4253cbc494416c4917920e1f2424cdf039af8bc39f839a47aa4337bd28f4eb7e" 4 | 5 | ############ 6 | ############ 7 | # Download the file 8 | Invoke-WebRequest $urlPath -UseBasicParsing -OutFile $PSScriptRoot"\npcap.zip" 9 | Add-Type -AssemblyName System.IO.Compression.FileSystem 10 | function Unzip 11 | { 12 | param([string]$zipfile, [string]$outpath) 13 | 14 | [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) 15 | } 16 | Unzip $PSScriptRoot"\npcap.zip" $PSScriptRoot"\npcap" 17 | Remove-Item $PSScriptRoot"\npcap.zip" 18 | # Now let's check its checksum 19 | $_chksum = $(CertUtil -hashfile $PSScriptRoot"\npcap\x64\WinDump.exe" SHA256)[1] -replace " ","" 20 | if ($_chksum -ne $checksum){ 21 | echo "Checksums does NOT match !" 22 | exit 23 | } else { 24 | echo "Checksums matches !" 25 | } 26 | # Finally, move it and remove tmp files 27 | New-Item -Path "C:\Program Files\Windump" -ItemType directory 28 | Move-Item -Force $PSScriptRoot"\npcap\x64\WinDump.exe" "C:\Program Files\Windump\windump.exe" 29 | Remove-Item $PSScriptRoot"\npcap" -recurse 30 | -------------------------------------------------------------------------------- /.config/codespell_ignore.txt: -------------------------------------------------------------------------------- 1 | abd 2 | aci 3 | ans 4 | applikation 5 | archtypes 6 | ba 7 | browseable 8 | byteorder 9 | cace 10 | cas 11 | ciph 12 | componet 13 | comversion 14 | cros 15 | delt 16 | doas 17 | doubleclick 18 | ether 19 | eventtypes 20 | fo 21 | funktion 22 | gost 23 | hart 24 | iff 25 | implementors 26 | inout 27 | interaktive 28 | joinin 29 | merchantibility 30 | microsof 31 | mitre 32 | nd 33 | negociate 34 | optiona 35 | ot 36 | potatoe 37 | referer 38 | requestor 39 | ro 40 | ser 41 | singl 42 | slac 43 | synching 44 | te 45 | temporaere 46 | tim 47 | ue 48 | uint 49 | vas 50 | wan 51 | wanna 52 | webp 53 | widgits 54 | -------------------------------------------------------------------------------- /.config/mypy/mypy.ini: -------------------------------------------------------------------------------- 1 | [mypy] 2 | 3 | # Internal Scapy modules that we ignore 4 | 5 | [mypy-scapy.libs.winpcapy] 6 | ignore_errors = True 7 | ignore_missing_imports = True 8 | 9 | [mypy-scapy.libs.rfc3961] 10 | warn_return_any = False 11 | 12 | # Layers specific config 13 | 14 | [mypy-scapy.arch.*] 15 | implicit_reexport = True 16 | 17 | [mypy-scapy.layers.*,scapy.contrib.*] 18 | warn_return_any = False 19 | 20 | # External libraries that we ignore 21 | 22 | [mypy-IPython] 23 | ignore_missing_imports = True 24 | 25 | [mypy-colorama] 26 | ignore_missing_imports = True 27 | 28 | [mypy-traitlets.config.loader] 29 | ignore_missing_imports = True 30 | 31 | [mypy-pyx] 32 | ignore_missing_imports = True 33 | 34 | [mypy-matplotlib.lines] 35 | ignore_missing_imports = True 36 | 37 | [mypy-prompt_toolkit.*] 38 | ignore_missing_imports = True 39 | -------------------------------------------------------------------------------- /.config/mypy/mypy_deployment_stats.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Gabriel Potter 5 | 6 | """ 7 | Generate MyPy deployment stats 8 | """ 9 | 10 | import os 11 | import io 12 | import glob 13 | from collections import defaultdict 14 | 15 | # Parse config file 16 | 17 | localdir = os.path.split(__file__)[0] 18 | rootpath = os.path.abspath(os.path.join(localdir, '../../')) 19 | 20 | with io.open(os.path.join(localdir, "mypy_enabled.txt")) as fd: 21 | FILES = [l.strip() for l in fd.readlines() if l.strip() and l[0] != "#"] 22 | 23 | # Scan Scapy 24 | 25 | ALL_FILES = [ 26 | "".join(x.partition("scapy/")[2:]) for x in 27 | glob.iglob(os.path.join(rootpath, 'scapy/**/*.py'), recursive=True) 28 | ] 29 | 30 | # Process 31 | 32 | REMAINING = defaultdict(list) 33 | MODULES = defaultdict(lambda: (0, 0, 0, 0)) 34 | 35 | for f in ALL_FILES: 36 | with open(os.path.join(rootpath, f)) as fd: 37 | lines = len(fd.read().split("\n")) 38 | parts = f.split("/") 39 | if len(parts) > 2: 40 | mod = parts[1] 41 | else: 42 | mod = "[core]" 43 | e, l, t, a = MODULES[mod] 44 | if f in FILES: 45 | e += lines 46 | t += 1 47 | else: 48 | REMAINING[mod].append(f) 49 | l += lines 50 | a += 1 51 | MODULES[mod] = (e, l, t, a) 52 | 53 | ENABLED = sum(x[0] for x in MODULES.values()) 54 | TOTAL = sum(x[1] for x in MODULES.values()) 55 | 56 | print("**MyPy Support: %.2f%%**" % (ENABLED / TOTAL * 100)) 57 | print("| Module | Typed code (lines) | Typed files |") 58 | print("| --- | --- | --- |") 59 | for mod, dat in MODULES.items(): 60 | print("|`%s` | %.2f%% | %s/%s |" % (mod, dat[0] / dat[1] * 100, dat[2], dat[3])) 61 | 62 | print() 63 | COREMODS = REMAINING["[core]"] 64 | if COREMODS: 65 | print("Core modules still untypes:") 66 | for mod in COREMODS: 67 | print("- `%s`" % mod) 68 | 69 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | scapy/__init__.py export-subst 2 | * text=auto 3 | *.bat text eol=crlf 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [gpotter2, guedou, p-l-, polybassa] 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | contact_links: 3 | - name: Ask a question 4 | url: https://gitter.im/secdev/scapy 5 | about: Please ask and answer questions on Gitter. 6 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | **Checklist:** 4 | 5 | - [ ] If you are new to Scapy: I have checked [CONTRIBUTING.md](https://github.com/secdev/scapy/blob/master/CONTRIBUTING.md) (esp. section submitting-pull-requests) 6 | - [ ] I squashed commits belonging together 7 | - [ ] I added unit tests or explained why they are not relevant 8 | - [ ] I executed the regression tests (using `cd test && ./run_tests` or `tox`) 9 | - [ ] If the PR is still not finished, please create a [Draft Pull Request](https://github.blog/2019-02-14-introducing-draft-pull-requests/) 10 | 11 | 12 | 13 | 16 | 17 | fixes #xxx 18 | -------------------------------------------------------------------------------- /.github/codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | notify: 3 | # Do not send notifications when CI fails 4 | require_ci_to_pass: true 5 | 6 | comment: 7 | # Define codevov comments behavior and content 8 | behavior: default 9 | layout: header, diff, tree 10 | require_changes: false 11 | 12 | coverage: 13 | # Define coverage range and precision 14 | precision: 2 15 | range: "70..100" 16 | round: down 17 | status: 18 | # Only consider changes to the whole project 19 | project: 20 | default: 21 | target: auto 22 | threshold: 0.5% 23 | base: auto 24 | patch: false 25 | changes: false 26 | 27 | parsers: 28 | gcov: 29 | branch_detection: 30 | conditional: true 31 | loop: true 32 | macro: false 33 | method: false 34 | javascript: 35 | enable_partials: yes 36 | -------------------------------------------------------------------------------- /.github/workflows/cifuzz.yml: -------------------------------------------------------------------------------- 1 | name: CIFuzz 2 | 3 | on: 4 | pull_request: 5 | branches: [master] 6 | 7 | permissions: 8 | contents: read 9 | 10 | jobs: 11 | Fuzzing: 12 | runs-on: ubuntu-latest 13 | if: github.repository == 'secdev/scapy' 14 | concurrency: 15 | group: ${{ github.workflow }}-${{ github.ref }} 16 | cancel-in-progress: true 17 | 18 | steps: 19 | - name: Build Fuzzers 20 | id: build 21 | uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master 22 | with: 23 | oss-fuzz-project-name: 'scapy' 24 | language: python 25 | dry-run: false 26 | allowed-broken-targets-percentage: 0 27 | - name: Run Fuzzers 28 | uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master 29 | with: 30 | oss-fuzz-project-name: 'scapy' 31 | language: python 32 | dry-run: false 33 | fuzz-seconds: 300 34 | - name: Upload Crash 35 | uses: actions/upload-artifact@v4 36 | if: failure() && steps.build.outcome == 'success' 37 | with: 38 | name: artifacts 39 | path: ./out/artifacts 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.pyo 3 | dist/ 4 | build/ 5 | MANIFEST 6 | *.egg-info/ 7 | test/*.html 8 | .coverage* 9 | coverage.xml 10 | .tox 11 | .ipynb_checkpoints 12 | .mypy_cache 13 | .vscode 14 | .DS_Store 15 | [.]venv/ 16 | __pycache__/ 17 | doc/scapy/_build 18 | doc/scapy/api 19 | .idea -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | # Readthedocs config file. 2 | 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html#supported-settings 4 | 5 | version: 2 6 | 7 | sphinx: 8 | configuration: doc/scapy/conf.py 9 | 10 | formats: 11 | - epub 12 | - pdf 13 | 14 | build: 15 | os: ubuntu-22.04 16 | tools: 17 | python: "3.12" 18 | # To show the correct Scapy version, we must unshallow 19 | # https://docs.readthedocs.io/en/stable/build-customization.html#unshallow-git-clone 20 | jobs: 21 | post_checkout: 22 | - git fetch --unshallow || true 23 | 24 | # https://docs.readthedocs.io/en/stable/config-file/v2.html#python 25 | python: 26 | install: 27 | - method: pip 28 | path: . 29 | extra_requirements: 30 | - doc 31 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | dist: bionic # OpenSSL 1.1.1 3 | cache: 4 | directories: 5 | - $HOME/.cache/pip 6 | - .tox 7 | 8 | jobs: 9 | include: 10 | # run custom root tests 11 | # isotp 12 | - os: linux 13 | python: 3.8 14 | env: 15 | - TOXENV=py38-isotp_kernel_module,codecov 16 | 17 | install: 18 | - bash .config/ci/install.sh 19 | - python -c "from scapy.all import conf; print(repr(conf))" 20 | 21 | script: bash .config/ci/test.sh 22 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include MANIFEST.in 2 | include LICENSE 3 | include run_scapy 4 | prune test 5 | -------------------------------------------------------------------------------- /doc/notebooks/tls/images/handshake_tls12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/images/handshake_tls12.png -------------------------------------------------------------------------------- /doc/notebooks/tls/images/handshake_tls13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/images/handshake_tls13.png -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/README.md: -------------------------------------------------------------------------------- 1 | This folder is used in the notebook and in some tests. 2 | 3 | Files in this folder are therefore cross licensed under both GPLv2 and CC-BY-NC-SA 2.5. 4 | -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/pki/ca_cert.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/pki/ca_cert.der -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/pki/ca_key.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/pki/ca_key.der -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/pki/srv_cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDnjCCAoagAwIBAgIJAP4EVw3HJ+n2MA0GCSqGSIb3DQEBCwUAMFQxCzAJBgNV 3 | BAYTAk1OMRQwEgYDVQQHDAtVbGFhbmJhYXRhcjEXMBUGA1UECwwOU2NhcHkgVGVz 4 | dCBQS0kxFjAUBgNVBAMMDVNjYXB5IFRlc3QgQ0EwHhcNMTYwOTE2MTAyODExWhcN 5 | MjYwOTE1MTAyODExWjBYMQswCQYDVQQGEwJNTjEUMBIGA1UEBwwLVWxhYW5iYWF0 6 | YXIxFzAVBgNVBAsMDlNjYXB5IFRlc3QgUEtJMRowGAYDVQQDDBFTY2FweSBUZXN0 7 | IFNlcnZlcjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMzx8ZtgLWCu 8 | 8pgNJynZwAlZTA9KMKhS3+WxIZ9Pwz1Wk91fxvez9lWL55Li3vKFSbShLPT9dqhn 9 | ygQgYBEYpvKptqYd2arl2duv5q9VV5//Uoll5oBigCGUvM+BG8tnwp21BXcEpseI 10 | GIB4aJU23pcbtmGHQhp1mEWC6z4yEcibhkI5jU0St1gbGfOdK6GYgsrXOyT7CTmw 11 | vMKVz4IpdRYpP0IgFytNQIxWbK26DzSFsX9AeXF4t6UEu5T3tUGV7nzrjQx5aFnv 12 | y7P6Pnge7mdMet3gme/a5++yCV2+gCAhBYMsRNtdKnYppbAjiHQHVCLWKXqS9W8t 13 | nuf4JiucWGUCAwEAAaNvMG0wCQYDVR0TBAIwADALBgNVHQ8EBAMCBeAwHQYDVR0O 14 | BBYEFKErIHDSa4DlZbzrAw+In3St3fYTMB8GA1UdIwQYMBaAFGZTlPQV0b1naLBR 15 | NzI14aSq3gd8MBMGA1UdJQQMMAoGCCsGAQUFBwMBMA0GCSqGSIb3DQEBCwUAA4IB 16 | AQCBiJJza5PnldbdQe6OHr2jSFinQTU/e33QN5gOuCyUd8hRNkCtWQkoyFbW6lus 17 | tNg/aLdmyuFWN6kAZepRyeyyaUld+ePA7WFUyRKfxrAKc1XoVTVg7xw28NrRkHdW 18 | BLirOO73CcWlmJAj6h/bFX8yKIGrm4UCS5XnN1F7G0gu+z5Sow20RqmSOhwf1woe 19 | WEr6LlGPKcYeuA4xDnPxJ4gXyshpDPqDzbN5DhSwuJsvOi0J4/wG8Dpu/TY7KxoJ 20 | KuirX4xA5IGyvPeDZxFuTpPqIq//o5p3V3bQCzis+IqUNY7X1GHMAf8ktI9hI7qI 21 | 11nk6boqTrUVD5zQ6gaR2d6r 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/pki/srv_key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDM8fGbYC1grvKY 3 | DScp2cAJWUwPSjCoUt/lsSGfT8M9VpPdX8b3s/ZVi+eS4t7yhUm0oSz0/XaoZ8oE 4 | IGARGKbyqbamHdmq5dnbr+avVVef/1KJZeaAYoAhlLzPgRvLZ8KdtQV3BKbHiBiA 5 | eGiVNt6XG7Zhh0IadZhFgus+MhHIm4ZCOY1NErdYGxnznSuhmILK1zsk+wk5sLzC 6 | lc+CKXUWKT9CIBcrTUCMVmytug80hbF/QHlxeLelBLuU97VBle58640MeWhZ78uz 7 | +j54Hu5nTHrd4Jnv2ufvsgldvoAgIQWDLETbXSp2KaWwI4h0B1Qi1il6kvVvLZ7n 8 | +CYrnFhlAgMBAAECggEAIPA9uZAimuhjOwbaJYLGt3nvnIF7AoKXU449biJeqawR 9 | hcHP852r2KHsrRHjbSz45JwG4rUd7gEIWdNuPTEuG9Ak99vSUQIyGnnR5JodxCw/ 10 | 8q869aVfHIaQNfV1JyLdB4XBhBhuSaFY9sTjYh/4dGbS0Cfx+titiXZ6InvfmdMD 11 | eLd/ZO35/BwtWN3J2ntRziTTREKLeEYFEe7FtXKGwDGIsvVn7egckefKMnflhMFA 12 | SuoPn2VvTqmhiwSuATdx1TP4XOVdVzuL2wT7brS7qHvabRDBKdVOfrNGOoMdnnua 13 | ursIQjQindNT8kVK8EGxws9eFr/dooYYFR72IusTfQKBgQDuQBzzKEtt86uRCbZX 14 | Y3lu0MJnR5OOodfGBBYF9Ue+W3OJTd9EvXLSgLBLvwirB7lsNXgXf8LHCTQOtF3H 15 | lnB8jE5OFSDGeSKWmUwZS+KVzq8vy7Qylp9i6x4pElwGUeba6AqeZZ+jUUn/HzdB 16 | s2pO8YWqyOp/Zo/m8P+vPZN4fwKBgQDcNqJ4Dutt/i60E9kaktGQVQODRNMhYCEq 17 | E5fhwJiZ0E9FBeuKPKjo7dGIux3KPQPBv3T0zjmB+M5QERVe5/ID8iytgbHGlnsg 18 | 916iTN9rvi1Gk518vyFPsYjX9pPiQIayRBQKOXSYIkY+6rj2384XPRlZrN8D9n3Q 19 | +An1JXfdGwKBgDs3YjqpnD3i35S4BkMoLUl2x6rl5m4AGeJUp6ipc0CD+G57FXA/ 20 | aieZ5rec7qmbzOFxVLz6e03/Ipo5CEoQQTsjoF7V74SFHSyzQ2/SJao4aeCGT+52 21 | 83yhlah9sLO9bZShMep2tbvg+3RWrOQ+lMC0VRXCxE4QDtpGsjY7Jsk/AoGAPstV 22 | iOa4O6U/rBn8zpcPKxkS51u42MuQqW7s4HMLENFVyVjm0YR6pfEqztKMrB6584Wk 23 | 1Cn6PBW2vx4f+fAqEvX7x340M2y1r7DaS22gSBjy0C1Hu0rFNPRrESo/AUVlI3BG 24 | RqQbm0YqwcYs+DjZi8bgc7HX5kljlzMjo8QLagECgYA1DHAWv4WVrHt4I8V4ZCth 25 | 9DZEtEOFpYjuoFh/xSIMZLsnvWRuyYVWcQwAqmK0Ew4m5opHFsQzABeGLVsK5aHX 26 | zmbYiRUuZGVpyc7c5XXomw50X8ajfQ+P21OPPc33h96cdHi2qbJIejZPia6A6ThU 27 | u13D93hAM6bzH6Ds5FPUQw== 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_nss_example.keys.txt: -------------------------------------------------------------------------------- 1 | # SSL/TLS secrets log file, generated by OpenSSL 2 | CLIENT_RANDOM c43c799f04ad31e397ee4fe14c8819a19bf5951bbc545cada407c6c7589e60ab b599798159244555ddd10d80b5552a37d327fd6e661f3520194c28ef6e8bb0af6e3fb4d4f9945a61e83a41f2345fa27a 3 | -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_nss_example.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_nss_example.pcap -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/01_cli.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_13/01_cli.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/02_srv.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_13/02_srv.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/03_srv.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_13/03_srv.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/04_srv.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_13/04_srv.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/05_srv.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_13/05_srv.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/06_srv.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_13/06_srv.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/07_cli.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_13/07_cli.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/08_cli.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_13/08_cli.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/09_srv.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_13/09_srv.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/cli_key.raw: -------------------------------------------------------------------------------- 1 | !"#$%&'()*+,-./0123456789:;<=>? -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/srv_key.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_13/srv_key.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_compromised/01_cli.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_compromised/01_cli.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_compromised/02_srv.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_compromised/02_srv.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_compromised/03_cli.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_compromised/03_cli.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_compromised/04_srv.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_compromised/04_srv.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_compromised/05_cli.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_compromised/05_cli.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_protected/01_cli.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_protected/01_cli.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_protected/02_srv.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_protected/02_srv.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_protected/03_srv.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_protected/03_srv.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_protected/04_srv.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_protected/04_srv.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_protected/05_cli.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_protected/05_cli.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_protected/06_srv.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_protected/06_srv.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_protected/07_cli.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/notebooks/tls/raw_data/tls_session_protected/07_cli.raw -------------------------------------------------------------------------------- /doc/scapy/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = Scapy 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /doc/scapy/README: -------------------------------------------------------------------------------- 1 | This folder includes source files (text and graphics) for Scapy's documentation, 2 | which is automatically built using Sphinx 3 | 4 | The *.rst files are written as reStructuredText and should be quite readable 5 | in your favourite text editor without any further formatting. 6 | 7 | To generate much nicer, searchable HTML docs, install Sphinx, open a command 8 | line, change to the directory where this README is placed, and type the 9 | following command: 10 | 11 | $ make html 12 | 13 | To generate a single PDF file (useful for printing) you need a working 14 | LaTeX installation (e.g. ). 15 | The following commands produce the file Scapy.pdf (>100 pages): 16 | 17 | $ make latex 18 | $ cd _build/latex 19 | $ make all-pdf 20 | -------------------------------------------------------------------------------- /doc/scapy/_static/_dummy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/_static/_dummy -------------------------------------------------------------------------------- /doc/scapy/_templates/README.md: -------------------------------------------------------------------------------- 1 | # Doc templates 2 | 3 | This folder contains templates used to generate Scapy's doc. It contains: 4 | 5 | - apidoc templates: inherited from 6 | https://github.com/sphinx-doc/sphinx/blob/master/sphinx/templates/apidoc/ 7 | -------------------------------------------------------------------------------- /doc/scapy/_templates/module.rst_t: -------------------------------------------------------------------------------- 1 | {%- if show_headings %} 2 | {{- basename | e | heading }} 3 | 4 | {% endif -%} 5 | .. automodule:: {{ qualname }} 6 | {%- for option in automodule_options %} 7 | :{{ option }}: 8 | {%- endfor %} 9 | 10 | -------------------------------------------------------------------------------- /doc/scapy/_templates/package.rst_t: -------------------------------------------------------------------------------- 1 | {%- macro automodule(modname, options) -%} 2 | .. automodule:: {{ modname }} 3 | {%- for option in options %} 4 | :{{ option }}: 5 | {%- endfor %} 6 | {%- endmacro %} 7 | 8 | {%- macro toctree(docnames) -%} 9 | .. toctree:: 10 | :maxdepth: {{ maxdepth }} 11 | :titlesonly: 12 | {% for docname in docnames %} 13 | {{ docname }} 14 | {%- endfor %} 15 | {%- endmacro %} 16 | 17 | {%- if is_namespace %} 18 | {{- [pkgname, "namespace"] | join(" ") | e | heading }} 19 | {% else %} 20 | {%- if pkgname == "scapy" %} 21 | {{- "Scapy API reference" | e | heading }} 22 | {% else %} 23 | {{- [pkgname, "package"] | join(" ") | e | heading }} 24 | {% endif %} 25 | {% endif %} 26 | 27 | {%- if modulefirst and not is_namespace %} 28 | {{ automodule(pkgname, automodule_options) }} 29 | {% endif %} 30 | 31 | {%- if subpackages %} 32 | Subpackages 33 | ----------- 34 | 35 | {{ toctree(subpackages) }} 36 | {% endif %} 37 | 38 | {%- if submodules %} 39 | Submodules 40 | ---------- 41 | {% if separatemodules %} 42 | {{ toctree(submodules) }} 43 | {%- else %} 44 | {%- for submodule in submodules %} 45 | {% if show_headings %} 46 | {{- [submodule, "module"] | join(" ") | e | heading(2) }} 47 | {% endif %} 48 | {{ automodule(submodule, automodule_options) }} 49 | {% endfor %} 50 | {%- endif %} 51 | {% endif %} 52 | 53 | {%- if not modulefirst and not is_namespace %} 54 | {{ automodule(pkgname, automodule_options) }} 55 | {% endif %} 56 | -------------------------------------------------------------------------------- /doc/scapy/backmatter.rst: -------------------------------------------------------------------------------- 1 | 2 | ********* 3 | Credits 4 | ********* 5 | 6 | - Philippe Biondi is Scapy's author. He has also written most of the documentation. 7 | - Pierre Lalet, Gabriel Potter, Guillaume Valadon, Nils Weiss are the current most active maintainers and contributors. 8 | - Fred Raynal wrote the chapter on building and dissecting packets. 9 | - Peter Kacherginsky contributed several tutorial sections, one-liners and recipes. 10 | - Dirk Loss integrated and restructured the existing docs to make this book. 11 | - Nils Weiss contributed automotive specific layers and utilities. 12 | -------------------------------------------------------------------------------- /doc/scapy/functions.rst: -------------------------------------------------------------------------------- 1 | *********************** 2 | Calling Scapy functions 3 | *********************** 4 | 5 | This section provides some examples that show how to benefit from Scapy 6 | functions in your own code. 7 | 8 | UDP checksum 9 | ============ 10 | 11 | The following example explains how to use the checksum() function to compute and 12 | UDP checksum manually. The following steps must be performed: 13 | 14 | 1. compute the UDP pseudo header as described in RFC768 15 | 2. build a UDP packet with Scapy with p[UDP].chksum=0 16 | 3. call checksum() with the pseudo header and the UDP packet 17 | 18 | :: 19 | 20 | from scapy.all import * 21 | 22 | # Get the UDP checksum computed by Scapy 23 | packet = IP(dst="10.11.12.13", src="10.11.12.14")/UDP()/DNS() 24 | packet = IP(raw(packet)) # Build packet (automatically done when sending) 25 | checksum_scapy = packet[UDP].chksum 26 | 27 | # Set the UDP checksum to 0 and compute the checksum 'manually' 28 | packet = IP(dst="10.11.12.13", src="10.11.12.14")/UDP(chksum=0)/DNS() 29 | packet_raw = raw(packet) 30 | udp_raw = packet_raw[20:] 31 | # in4_chksum is used to automatically build a pseudo-header 32 | chksum = in4_chksum(socket.IPPROTO_UDP, packet[IP], udp_raw) # For more infos, call "help(in4_chksum)" 33 | 34 | assert(checksum_scapy == chksum) 35 | -------------------------------------------------------------------------------- /doc/scapy/graphics/ATMT_HelloWorld.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/ATMT_HelloWorld.png -------------------------------------------------------------------------------- /doc/scapy/graphics/ATMT_TFTP_read.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/ATMT_TFTP_read.png -------------------------------------------------------------------------------- /doc/scapy/graphics/animations/pipetool_demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/animations/pipetool_demo.gif -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/CAN-full-frame.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/automotive/CAN-full-frame.jpg -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/DC-ZGW-CAN-Bus-.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/automotive/DC-ZGW-CAN-Bus-.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/Simple-CAN-Bus-.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/automotive/Simple-CAN-Bus-.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/XCP_ReferenceBook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/automotive/XCP_ReferenceBook.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/ZGW-CAN-Bus-.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/automotive/ZGW-CAN-Bus-.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/autosar1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/automotive/autosar1.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/autosar2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/automotive/autosar2.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/autosar3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/automotive/autosar3.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/autosar4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/automotive/autosar4.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/can-bus-states.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/automotive/can-bus-states.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/can-frame-socket-can.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/automotive/can-frame-socket-can.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/diag-stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/automotive/diag-stack.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/isotp-flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/automotive/isotp-flow.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/isotp-frames.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/automotive/isotp-frames.png -------------------------------------------------------------------------------- /doc/scapy/graphics/ble_eddystone_url.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/ble_eddystone_url.png -------------------------------------------------------------------------------- /doc/scapy/graphics/ble_ibeacon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/ble_ibeacon.png -------------------------------------------------------------------------------- /doc/scapy/graphics/command-ls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/command-ls.png -------------------------------------------------------------------------------- /doc/scapy/graphics/dcerpc/ndr_conformant_varying_array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/dcerpc/ndr_conformant_varying_array.png -------------------------------------------------------------------------------- /doc/scapy/graphics/dcerpc/ndr_full_pointer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/dcerpc/ndr_full_pointer.png -------------------------------------------------------------------------------- /doc/scapy/graphics/default-values-ip.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/default-values-ip.pdf -------------------------------------------------------------------------------- /doc/scapy/graphics/default-values-ip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/default-values-ip.png -------------------------------------------------------------------------------- /doc/scapy/graphics/fieldsmanagement.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/fieldsmanagement.pdf -------------------------------------------------------------------------------- /doc/scapy/graphics/fieldsmanagement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/fieldsmanagement.png -------------------------------------------------------------------------------- /doc/scapy/graphics/graph_traceroute.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/graph_traceroute.png -------------------------------------------------------------------------------- /doc/scapy/graphics/http_tcp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/http_tcp.png -------------------------------------------------------------------------------- /doc/scapy/graphics/ipid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/ipid.png -------------------------------------------------------------------------------- /doc/scapy/graphics/isakmp_dump.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/isakmp_dump.png -------------------------------------------------------------------------------- /doc/scapy/graphics/kerberos/as_req_fast.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/kerberos/as_req_fast.png -------------------------------------------------------------------------------- /doc/scapy/graphics/kerberos/kerberos_atmt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/kerberos/kerberos_atmt.png -------------------------------------------------------------------------------- /doc/scapy/graphics/kerberos/ticketer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/kerberos/ticketer.png -------------------------------------------------------------------------------- /doc/scapy/graphics/kerberos/wireshark_asreq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/kerberos/wireshark_asreq.png -------------------------------------------------------------------------------- /doc/scapy/graphics/pipetool_engine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/pipetool_engine.png -------------------------------------------------------------------------------- /doc/scapy/graphics/scapy-concept.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/scapy-concept.pdf -------------------------------------------------------------------------------- /doc/scapy/graphics/scapy-concept.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/scapy-concept.png -------------------------------------------------------------------------------- /doc/scapy/graphics/scapy-win-screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/scapy-win-screenshot1.png -------------------------------------------------------------------------------- /doc/scapy/graphics/scapy-win-screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/scapy-win-screenshot2.png -------------------------------------------------------------------------------- /doc/scapy/graphics/scapy_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/scapy_logo.png -------------------------------------------------------------------------------- /doc/scapy/graphics/smb/smb_client.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/smb/smb_client.png -------------------------------------------------------------------------------- /doc/scapy/graphics/smb/smb_server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/smb/smb_server.png -------------------------------------------------------------------------------- /doc/scapy/graphics/testing-taxonomy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/testing-taxonomy.png -------------------------------------------------------------------------------- /doc/scapy/graphics/trace3d_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/trace3d_1.png -------------------------------------------------------------------------------- /doc/scapy/graphics/trace3d_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/trace3d_2.png -------------------------------------------------------------------------------- /doc/scapy/graphics/traceroute_worldplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy/graphics/traceroute_worldplot.png -------------------------------------------------------------------------------- /doc/scapy/index.rst: -------------------------------------------------------------------------------- 1 | .. Scapy documentation master file, created by sphinx-quickstart on Mon Sep 8 19:37:39 2008. 2 | You can adapt this file completely to your liking, but it should at least 3 | contain the root `toctree` directive. 4 | 5 | Welcome to Scapy's documentation! 6 | ================================= 7 | 8 | .. image:: graphics/scapy_logo.png 9 | :scale: 20 10 | :align: center 11 | 12 | :Version: |version| 13 | :Release: |release| 14 | :Date: |today| 15 | 16 | Scapy's documentation is under a `Creative Commons Attribution - Non-Commercial 17 | - Share Alike 2.5 `_ license. 18 | 19 | .. toctree:: 20 | :maxdepth: 2 21 | :caption: General documentation 22 | 23 | introduction 24 | installation 25 | 26 | usage 27 | advanced_usage 28 | routing 29 | 30 | .. toctree:: 31 | :maxdepth: 2 32 | :caption: Extend scapy 33 | 34 | extending 35 | build_dissect 36 | functions 37 | 38 | .. toctree:: 39 | :maxdepth: 2 40 | :caption: Layer-specific documentation 41 | :glob: 42 | 43 | layers/index.rst 44 | 45 | .. toctree:: 46 | :maxdepth: 2 47 | :caption: About 48 | 49 | troubleshooting 50 | development 51 | backmatter 52 | 53 | .. only:: html 54 | 55 | .. toctree:: 56 | :maxdepth: 1 57 | :titlesonly: 58 | :caption: API Reference 59 | 60 | api/scapy.rst 61 | 62 | -------------------------------------------------------------------------------- /doc/scapy/layers/dotnet.rst: -------------------------------------------------------------------------------- 1 | .NET Protocols 2 | ============== 3 | 4 | Scapy implements a few .NET specific protocols. Those protocols are a bit uncommon, but it can be useful to try to understand what's sent by .NET applications, or for more offensive purposes (issues with .NET deserialization for instance). 5 | 6 | .NET Remoting 7 | ------------- 8 | 9 | Implemented under ``ms_nrtp``, you can load it using:: 10 | 11 | from scapy.layers.ms_nrtp import * 12 | 13 | This supports: 14 | 15 | - The .NET remote protocol: ``NRTP*`` classes 16 | - The .NET Binary Formatter: ``NRBF*`` classes 17 | 18 | For instance you can try to parse a .NET Remoting payload generated using ysoserial with the ``NRBF()`` to analyse what it's doing. 19 | -------------------------------------------------------------------------------- /doc/scapy/layers/index.rst: -------------------------------------------------------------------------------- 1 | .. Layer-specific documentation 2 | 3 | Layers 4 | ====== 5 | 6 | .. toctree:: 7 | :glob: 8 | :titlesonly: 9 | 10 | * -------------------------------------------------------------------------------- /doc/scapy/layers/sctp.rst: -------------------------------------------------------------------------------- 1 | **** 2 | SCTP 3 | **** 4 | 5 | SCTP is a relatively young transport-layer protocol combining both TCP and UDP characteristics. The `RFC 3286 `_ introduces it and its description lays in the `RFC 4960 `_. 6 | 7 | It is not broadly used, its mainly present in core networks operated by telecommunication companies, to support VoIP for instance. 8 | 9 | 10 | Enabling dynamic addressing reconfiguration and chunk authentication capabilities 11 | --------------------------------------------------------------------------------- 12 | 13 | If you are trying to discuss with SCTP servers, you may be interested in capabilities added in `RFC 4895 `_ which describe how to authenticated some SCTP chunks, and/or `RFC 5061 `_ to dynamically reconfigure the IP address of a SCTP association. 14 | 15 | These capabilities are not always enabled by default on Linux. Scapy does not need any modification on its end, but SCTP servers may need specific activation. 16 | 17 | To enable the RFC 4895 about authenticating chunks:: 18 | 19 | $ sudo echo 1 > /proc/sys/net/sctp/auth_enable 20 | 21 | To enable the RFC 5061 about dynamic address reconfiguration:: 22 | 23 | $ sudo echo 1 > /proc/sys/net/sctp/addip_enable 24 | 25 | You may also want to use the dynamic address reconfiguration without necessarily enabling the chunk authentication:: 26 | 27 | $ sudo echo 1 > /proc/sys/net/sctp/addip_noauth_enable -------------------------------------------------------------------------------- /doc/scapy/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | set SPHINXPROJ=Scapy 13 | 14 | if "%1" == "" goto help 15 | 16 | %SPHINXBUILD% >NUL 2>NUL 17 | if errorlevel 9009 ( 18 | echo. 19 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 20 | echo.installed, then set the SPHINXBUILD environment variable to point 21 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 22 | echo.may add the Sphinx directory to PATH. 23 | echo. 24 | echo.If you don't have Sphinx installed, grab it from 25 | echo.http://sphinx-doc.org/ 26 | exit /b 1 27 | ) 28 | 29 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 30 | goto end 31 | 32 | :help 33 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 34 | 35 | :end 36 | popd 37 | -------------------------------------------------------------------------------- /doc/scapy_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/doc/scapy_logo.png -------------------------------------------------------------------------------- /doc/syntax/vim_uts_syntax/ftdetect/filetype.vim: -------------------------------------------------------------------------------- 1 | au BufRead,BufNewFile *.uts setfiletype uts 2 | -------------------------------------------------------------------------------- /doc/syntax/vim_uts_syntax/ftdetect/uts.vim: -------------------------------------------------------------------------------- 1 | au BufRead,BufNewFile *.uts set filetype=uts 2 | -------------------------------------------------------------------------------- /doc/syntax/vim_uts_syntax/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $(pwd) != *"doc/syntax/vim_uts_syntax" ]] 4 | then 5 | echo "Wrong current directory. Please call this script if you are inside doc/syntax/vim_uts_syntax" 6 | exit -1 7 | fi 8 | 9 | if [ ! -d "$HOME/.vim" ]; then 10 | echo "$HOME/.vim doesn't exist" 11 | exit -1 12 | fi 13 | 14 | if [ -f "$HOME/.vim/ftdetect/filetype.vim" ]; then 15 | echo "$HOME/.vim/ftdetect/filetype.vim already exists. You may not want to overwrite this file." 16 | fi 17 | 18 | mkdir -p -v $HOME/.vim/ftdetect 19 | mkdir -p -v $HOME/.vim/syntax 20 | 21 | cp -i -v ftdetect/filetype.vim $HOME/.vim/ftdetect/filetype.vim 22 | cp -i -v ftdetect/uts.vim $HOME/.vim/ftdetect/uts.vim 23 | cp -i -v syntax/uts.vim $HOME/.vim/syntax/uts.vim 24 | 25 | echo "Installed" 26 | -------------------------------------------------------------------------------- /doc/vagrant_ci/README.md: -------------------------------------------------------------------------------- 1 | # Scapy Unit Tests 2 | 3 | This directory contains a Vagrant setup to ease starting `tox` based Scapy unit 4 | tests. 5 | -------------------------------------------------------------------------------- /doc/vagrant_ci/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # SPDX-License-Identifier: GPL-2.0-only 5 | # This file is part of Scapy 6 | # See https://scapy.net/ for more information 7 | # Copyright (C) Philippe Biondi 8 | 9 | Vagrant.configure("2") do |config| 10 | 11 | config.vm.provider "virtualbox" do |vb| 12 | vb.memory = 1024 13 | vb.cpus = 2 14 | end 15 | 16 | config.vm.define "openbsd" do |bsd| 17 | bsd.vm.box = "generic/openbsd7" 18 | bsd.vm.provision "shell", path: "provision_openbsd.sh" 19 | end 20 | 21 | config.vm.define "freebsd" do |bsd| 22 | bsd.vm.box = "freebsd/FreeBSD-14.0-RELEASE" 23 | bsd.vm.provision "shell", path: "provision_freebsd.sh" 24 | end 25 | 26 | config.vm.define "netbsd" do |bsd| 27 | bsd.vm.box = "generic/netbsd9" 28 | bsd.vm.provision "shell", path: "provision_netbsd.sh" 29 | end 30 | 31 | end 32 | -------------------------------------------------------------------------------- /doc/vagrant_ci/provision_freebsd.sh: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/bash 2 | 3 | # SPDX-License-Identifier: GPL-2.0-only 4 | # This file is part of Scapy 5 | # See https://scapy.net/ for more information 6 | # Copyright (C) Philippe Biondi 7 | 8 | PACKAGES="git python39 python311 py39-virtualenv py39-pip py39-sqlite3 py311-sqlite3 bash rust sudo" 9 | 10 | pkg update 11 | pkg install --yes $PACKAGES 12 | bash 13 | git clone https://github.com/secdev/scapy 14 | cd scapy 15 | export PATH=/usr/local/bin/:$PATH 16 | virtualenv-3.9 -p python3.9 venv 17 | source venv/bin/activate 18 | pip install tox 19 | chown -R vagrant:vagrant /home/vagrant/scapy 20 | -------------------------------------------------------------------------------- /doc/vagrant_ci/provision_netbsd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # SPDX-License-Identifier: GPL-2.0-only 4 | # This file is part of Scapy 5 | # See https://scapy.net/ for more information 6 | # Copyright (C) Philippe Biondi 7 | 8 | RELEASE="9.0_2022Q2" 9 | PACKAGES="git python27 python39 py39-virtualenv py27-sqlite3 py39-sqlite3 py39-expat rust mozilla-rootcerts-openssl" 10 | 11 | sudo -s 12 | unset PROMPT_COMMAND 13 | export PATH="/sbin:/usr/pkg/sbin:/usr/pkg/bin:$PATH" 14 | export PKG_PATH="http://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/${RELEASE}/All/" 15 | pkg_delete curl 16 | pkg_add -u $PACKAGES 17 | git clone https://github.com/secdev/scapy 18 | cd scapy 19 | virtualenv-3.9 venv 20 | . venv/bin/activate 21 | pip install tox 22 | chown -R vagrant:vagrant ../scapy/ 23 | -------------------------------------------------------------------------------- /doc/vagrant_ci/provision_openbsd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # SPDX-License-Identifier: GPL-2.0-only 4 | # This file is part of Scapy 5 | # See https://scapy.net/ for more information 6 | # Copyright (C) Philippe Biondi 7 | 8 | PACKAGES="git python3 py3-virtualenv py3-cryptography" 9 | 10 | sudo pkg_add $PACKAGES 11 | sudo mkdir -p /usr/local/test/ 12 | sudo chown -R vagrant:vagrant /usr/local/test/ 13 | cd /usr/local/test/ 14 | git clone https://github.com/secdev/scapy 15 | cd scapy 16 | virtualenv --system-site-packages venv 17 | source venv/bin/activate 18 | pip install tox 19 | sudo chown -R vagrant:vagrant /usr/local/test/ 20 | -------------------------------------------------------------------------------- /run_scapy: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | DIR=$(dirname "$0") 3 | if [ -z "$PYTHON" ] 4 | then 5 | PYTHON=${PYTHON:-python3} 6 | fi 7 | $PYTHON --version > /dev/null 2>&1 8 | if [ ! $? -eq 0 ] 9 | then 10 | echo "WARNING: '$PYTHON' not found, using 'python' instead." 11 | PYTHON=python 12 | fi 13 | PYTHONPATH=$DIR exec "$PYTHON" -m scapy $@ 14 | -------------------------------------------------------------------------------- /run_scapy.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | set PYTHONPATH=%~dp0 4 | REM shift will not work with %* 5 | set "_args=%*" 6 | IF "%PYTHON%" == "" set PYTHON=py 7 | WHERE %PYTHON% >nul 2>&1 8 | IF %ERRORLEVEL% NEQ 0 set PYTHON= 9 | IF "%1" == "-3" ( 10 | if "%PYTHON%" == "py" ( 11 | set "PYTHON=py -3" 12 | ) else ( 13 | set PYTHON=python3 14 | ) 15 | set "_args=%_args:~3%" 16 | ) else ( 17 | IF "%PYTHON%" == "" set PYTHON=python3 18 | WHERE %PYTHON% >nul 2>&1 19 | IF %ERRORLEVEL% NEQ 0 set PYTHON=python 20 | ) 21 | %PYTHON% -m scapy %_args% 22 | title Scapy - dead 23 | PAUSE -------------------------------------------------------------------------------- /scapy/__main__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | Scapy: create, send, sniff, dissect and manipulate network packets. 8 | 9 | Usable either from an interactive console or as a Python library. 10 | http://www.secdev.org/projects/scapy 11 | """ 12 | 13 | from scapy.main import interact 14 | 15 | interact() 16 | -------------------------------------------------------------------------------- /scapy/all.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | Aggregate top level objects from all Scapy modules. 8 | """ 9 | 10 | from scapy.base_classes import * 11 | from scapy.config import * 12 | from scapy.dadict import * 13 | from scapy.data import * 14 | from scapy.error import * 15 | from scapy.themes import * 16 | from scapy.arch import * 17 | from scapy.interfaces import * 18 | 19 | from scapy.plist import * 20 | from scapy.fields import * 21 | from scapy.packet import * 22 | from scapy.asn1fields import * 23 | from scapy.asn1packet import * 24 | 25 | from scapy.utils import * 26 | from scapy.route import * 27 | from scapy.sendrecv import * 28 | from scapy.sessions import * 29 | from scapy.supersocket import * 30 | from scapy.volatile import * 31 | from scapy.as_resolvers import * 32 | 33 | from scapy.automaton import * 34 | from scapy.autorun import * 35 | 36 | from scapy.main import * 37 | from scapy.consts import * 38 | from scapy.compat import raw # noqa: F401 39 | 40 | from scapy.layers.all import * 41 | 42 | from scapy.asn1.asn1 import * 43 | from scapy.asn1.ber import * 44 | from scapy.asn1.mib import * 45 | 46 | from scapy.pipetool import * 47 | from scapy.scapypipes import * 48 | 49 | if conf.ipv6_enabled: # noqa: F405 50 | from scapy.utils6 import * # noqa: F401 51 | from scapy.route6 import * # noqa: F401 52 | 53 | from scapy.ansmachine import * 54 | -------------------------------------------------------------------------------- /scapy/arch/bpf/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Guillaume Valadon 5 | 6 | """ 7 | Scapy BSD native support 8 | """ 9 | -------------------------------------------------------------------------------- /scapy/arch/bpf/consts.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Guillaume Valadon 5 | 6 | """ 7 | Scapy BSD native support - constants 8 | """ 9 | 10 | import ctypes 11 | 12 | from scapy.libs.structures import bpf_program 13 | from scapy.data import MTU 14 | 15 | # Type hints 16 | from typing import ( 17 | Any, 18 | Callable, 19 | ) 20 | 21 | SIOCGIFFLAGS = 0xc0206911 22 | BPF_BUFFER_LENGTH = MTU 23 | 24 | # From sys/ioccom.h 25 | 26 | IOCPARM_MASK = 0x1fff 27 | IOC_VOID = 0x20000000 28 | IOC_OUT = 0x40000000 29 | IOC_IN = 0x80000000 30 | IOC_INOUT = IOC_IN | IOC_OUT 31 | 32 | _th = lambda x: x if isinstance(x, int) else ctypes.sizeof(x) # type: Callable[[Any], int] # noqa: E501 33 | 34 | 35 | def _IOC(inout, group, num, len): 36 | # type: (int, str, int, Any) -> int 37 | return (inout | 38 | ((_th(len) & IOCPARM_MASK) << 16) | 39 | (ord(group) << 8) | (num)) 40 | 41 | 42 | _IO = lambda g, n: _IOC(IOC_VOID, g, n, 0) # type: Callable[[str, int], int] 43 | _IOR = lambda g, n, t: _IOC(IOC_OUT, g, n, t) # type: Callable[[str, int, Any], int] 44 | _IOW = lambda g, n, t: _IOC(IOC_IN, g, n, t) # type: Callable[[str, int, Any], int] 45 | _IOWR = lambda g, n, t: _IOC(IOC_INOUT, g, n, t) # type: Callable[[str, int, Any], int] 46 | 47 | # Length of some structures 48 | _bpf_stat = 8 49 | _ifreq = 32 50 | 51 | # From net/bpf.h 52 | BIOCGBLEN = _IOR('B', 102, ctypes.c_uint) 53 | BIOCSBLEN = _IOWR('B', 102, ctypes.c_uint) 54 | BIOCSETF = _IOW('B', 103, bpf_program) 55 | BIOCPROMISC = _IO('B', 105) 56 | BIOCGDLT = _IOR('B', 106, ctypes.c_uint) 57 | BIOCSETIF = _IOW('B', 108, 32) 58 | BIOCGSTATS = _IOR('B', 111, _bpf_stat) 59 | BIOCIMMEDIATE = _IOW('B', 112, ctypes.c_uint) 60 | BIOCSHDRCMPLT = _IOW('B', 117, ctypes.c_uint) 61 | BIOCSDLT = _IOW('B', 120, ctypes.c_uint) 62 | BIOCSTSTAMP = _IOW('B', 132, ctypes.c_uint) 63 | 64 | BPF_T_NANOTIME = 0x0001 65 | -------------------------------------------------------------------------------- /scapy/arch/solaris.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | Customization for the Solaris operation system. 8 | """ 9 | 10 | import socket 11 | 12 | from scapy.config import conf 13 | conf.use_pcap = True 14 | 15 | # IPPROTO_GRE is missing on Solaris 16 | socket.IPPROTO_GRE = 47 17 | 18 | # From sys/sockio.h and net/if.h 19 | SIOCGIFHWADDR = 0xc02069b9 # Get hardware address 20 | 21 | from scapy.arch.common import get_if_raw_addr # noqa: F401, F403, E402 22 | from scapy.arch.libpcap import * # noqa: F401, F403, E402 23 | from scapy.arch.unix import * # noqa: F401, F403, E402 24 | 25 | from scapy.interfaces import NetworkInterface # noqa: E402 26 | 27 | 28 | def get_working_if(): 29 | # type: () -> NetworkInterface 30 | """Return an interface that works""" 31 | try: 32 | # return the interface associated with the route with smallest 33 | # mask (route by default if it exists) 34 | iface = min(conf.route.routes, key=lambda x: x[1])[3] 35 | except ValueError: 36 | # no route 37 | iface = conf.loopback_name 38 | return conf.ifaces.dev_from_name(iface) 39 | -------------------------------------------------------------------------------- /scapy/asn1/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | Package holding ASN.1 related modules. 8 | """ 9 | -------------------------------------------------------------------------------- /scapy/asn1packet.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | ASN.1 Packet 8 | 9 | Packet holding data in Abstract Syntax Notation (ASN.1). 10 | """ 11 | 12 | from scapy.base_classes import Packet_metaclass 13 | from scapy.packet import Packet 14 | 15 | from typing import ( 16 | Any, 17 | Dict, 18 | Tuple, 19 | Type, 20 | cast, 21 | TYPE_CHECKING, 22 | ) 23 | 24 | if TYPE_CHECKING: 25 | from scapy.asn1fields import ASN1F_field # noqa: F401 26 | 27 | 28 | class ASN1Packet_metaclass(Packet_metaclass): 29 | def __new__(cls, 30 | name, # type: str 31 | bases, # type: Tuple[type, ...] 32 | dct # type: Dict[str, Any] 33 | ): 34 | # type: (...) -> Type[ASN1_Packet] 35 | if dct["ASN1_root"] is not None: 36 | dct["fields_desc"] = dct["ASN1_root"].get_fields_list() 37 | return cast( 38 | 'Type[ASN1_Packet]', 39 | super(ASN1Packet_metaclass, cls).__new__(cls, name, bases, dct), 40 | ) 41 | 42 | 43 | class ASN1_Packet(Packet, metaclass=ASN1Packet_metaclass): 44 | ASN1_root = cast('ASN1F_field[Any, Any]', None) 45 | ASN1_codec = None 46 | 47 | def self_build(self): 48 | # type: () -> bytes 49 | if self.raw_packet_cache is not None: 50 | return self.raw_packet_cache 51 | return self.ASN1_root.build(self) 52 | 53 | def do_dissect(self, x): 54 | # type: (bytes) -> bytes 55 | return self.ASN1_root.dissect(self, x) 56 | -------------------------------------------------------------------------------- /scapy/consts.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | This file contains constants 8 | """ 9 | 10 | from sys import byteorder, platform, maxsize 11 | import platform as platform_lib 12 | 13 | __all__ = [ 14 | "LINUX", 15 | "OPENBSD", 16 | "FREEBSD", 17 | "NETBSD", 18 | "DARWIN", 19 | "SOLARIS", 20 | "WINDOWS", 21 | "WINDOWS_XP", 22 | "BSD", 23 | "IS_64BITS", 24 | "BIG_ENDIAN", 25 | ] 26 | 27 | LINUX = platform.startswith("linux") 28 | OPENBSD = platform.startswith("openbsd") 29 | FREEBSD = "freebsd" in platform 30 | NETBSD = platform.startswith("netbsd") 31 | DARWIN = platform.startswith("darwin") 32 | SOLARIS = platform.startswith("sunos") 33 | WINDOWS = platform.startswith("win32") 34 | WINDOWS_XP = platform_lib.release() == "XP" 35 | BSD = DARWIN or FREEBSD or OPENBSD or NETBSD 36 | # See https://docs.python.org/3/library/platform.html#cross-platform 37 | IS_64BITS = maxsize > 2**32 38 | BIG_ENDIAN = byteorder == 'big' 39 | # LOOPBACK_NAME moved to conf.loopback_name 40 | -------------------------------------------------------------------------------- /scapy/contrib/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | Package of contrib modules that have to be loaded explicitly. 8 | """ 9 | 10 | # Make sure config is loaded 11 | import scapy.config # noqa: F401 12 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Nils Weiss 5 | 6 | # scapy.contrib.status = skip 7 | 8 | """ 9 | Package of contrib automotive modules that have to be loaded explicitly. 10 | """ 11 | 12 | import logging 13 | 14 | log_automotive = logging.getLogger("scapy.contrib.automotive") 15 | 16 | log_automotive.setLevel(logging.INFO) 17 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/autosar/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Damian Zaręba 5 | 6 | # scapy.contrib.status = skip 7 | 8 | """ 9 | Package of contrib automotive AUTOSAR modules 10 | that have to be loaded explicitly. 11 | """ 12 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/autosar/pdu.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | 3 | # SPDX-License-Identifier: GPL-2.0-only 4 | # This file is part of Scapy 5 | # See https://scapy.net/ for more information 6 | # Copyright (C) Damian Zaręba 7 | 8 | # scapy.contrib.description = AUTOSAR PDU packets handling package. 9 | # scapy.contrib.status = loads 10 | from typing import Tuple, Optional 11 | from scapy.layers.inet import UDP 12 | from scapy.fields import XIntField, PacketListField, LenField 13 | from scapy.packet import Packet, bind_bottom_up 14 | 15 | 16 | class PDU(Packet): 17 | """ 18 | Single PDU Packet inside PDUTransport list. 19 | Contains ID and payload length, and later - raw load. 20 | It's free to interpret using bind_layers/bind_bottom_up method 21 | 22 | Based off this document: 23 | 24 | https://www.autosar.org/fileadmin/standards/classic/22-11/AUTOSAR_SWS_IPDUMultiplexer.pdf # noqa: E501 25 | """ 26 | name = 'PDU' 27 | fields_desc = [ 28 | XIntField('pdu_id', 0), 29 | LenField('pdu_payload_len', None, fmt="I")] 30 | 31 | def extract_padding(self, s): 32 | # type: (bytes) -> Tuple[bytes, Optional[bytes]] 33 | return s[:self.pdu_payload_len], s[self.pdu_payload_len:] 34 | 35 | 36 | class PDUTransport(Packet): 37 | """ 38 | Packet representing PDUTransport containing multiple PDUs 39 | """ 40 | name = 'PDUTransport' 41 | fields_desc = [ 42 | PacketListField("pdus", [PDU()], PDU) 43 | ] 44 | 45 | 46 | bind_bottom_up(UDP, PDUTransport, dport=60000) 47 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/bmw/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Nils Weiss 5 | 6 | # scapy.contrib.status = skip 7 | 8 | """ 9 | Package of contrib automotive bmw specific modules 10 | that have to be loaded explicitly. 11 | """ 12 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/bmw/enumerator.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Nils Weiss 5 | 6 | # scapy.contrib.description = BMW specific enumerators 7 | # scapy.contrib.status = loads 8 | 9 | 10 | from scapy.packet import Packet 11 | from scapy.contrib.automotive.scanner.enumerator import _AutomotiveTestCaseScanResult # noqa: E501 12 | from scapy.contrib.automotive.uds import UDS 13 | from scapy.contrib.automotive.bmw.definitions import DEV_JOB 14 | from scapy.contrib.automotive.uds_scan import UDS_Enumerator 15 | 16 | from typing import ( 17 | Any, 18 | Iterable, 19 | ) 20 | 21 | 22 | class BMW_DevJobEnumerator(UDS_Enumerator): 23 | _description = "Available DevelopmentJobs by Identifier " \ 24 | "and negative response per state" 25 | 26 | def _get_initial_requests(self, **kwargs): 27 | # type: (Any) -> Iterable[Packet] 28 | scan_range = kwargs.pop("scan_range", range(0x10000)) 29 | return (UDS() / DEV_JOB(identifier=x) for x in scan_range) 30 | 31 | def _get_table_entry_y(self, tup): 32 | # type: (_AutomotiveTestCaseScanResult) -> str 33 | return "0x%04x: %s" % \ 34 | (tup[1].identifier, tup[1].sprintf("%DEV_JOB.identifier%")) 35 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/gm/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Nils Weiss 5 | 6 | # scapy.contrib.status = skip 7 | 8 | """ 9 | Package of contrib automotive gm specific modules 10 | that have to be loaded explicitly. 11 | """ 12 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/gm/gmlan_ecu_states.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Nils Weiss 5 | 6 | # scapy.contrib.description = GMLAN EcuState modifications 7 | # scapy.contrib.status = library 8 | from scapy.packet import Packet 9 | from scapy.contrib.automotive.ecu import EcuState 10 | from scapy.contrib.automotive.gm.gmlan import GMLAN, GMLAN_SAPR 11 | 12 | __all__ = ["GMLAN_modify_ecu_state", "GMLAN_SAPR_modify_ecu_state"] 13 | 14 | 15 | @EcuState.extend_pkt_with_modifier(GMLAN) 16 | def GMLAN_modify_ecu_state(self, req, state): 17 | # type: (Packet, Packet, EcuState) -> None 18 | if self.service == 0x50: 19 | state.session = 3 # type: ignore 20 | elif self.service == 0x60: 21 | state.reset() 22 | state.session = 1 # type: ignore 23 | elif self.service == 0x68: 24 | state.communication_control = 1 # type: ignore 25 | elif self.service == 0xe5: 26 | state.session = 2 # type: ignore 27 | elif self.service == 0x74 and len(req) > 3: 28 | state.request_download = 1 # type: ignore 29 | elif self.service == 0x7e: 30 | state.tp = 1 # type: ignore 31 | 32 | 33 | @EcuState.extend_pkt_with_modifier(GMLAN_SAPR) 34 | def GMLAN_SAPR_modify_ecu_state(self, req, state): 35 | # type: (Packet, Packet, EcuState) -> None 36 | if self.subfunction % 2 == 0 and self.subfunction > 0 and len(req) >= 3: 37 | state.security_level = self.subfunction # type: ignore 38 | elif self.subfunction % 2 == 1 and \ 39 | self.subfunction > 0 and \ 40 | len(req) >= 3 and not any(self.securitySeed): 41 | state.security_level = self.securityAccessType + 1 # type: ignore 42 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/obd/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Andreas Korb 5 | # Copyright (C) Nils Weiss 6 | 7 | # scapy.contrib.status = skip 8 | 9 | """ 10 | Package of contrib automotive obd specific modules 11 | that have to be loaded explicitly. 12 | """ 13 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/obd/iid/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Andreas Korb 5 | # Copyright (C) Nils Weiss 6 | 7 | # scapy.contrib.status = skip 8 | 9 | """ 10 | Package of contrib automotive obd specific modules 11 | that have to be loaded explicitly. 12 | """ 13 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/obd/mid/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Andreas Korb 5 | # Copyright (C) Nils Weiss 6 | 7 | # scapy.contrib.status = skip 8 | 9 | """ 10 | Package of contrib automotive obd specific modules 11 | that have to be loaded explicitly. 12 | """ 13 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/obd/packet.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Andreas Korb 5 | # Copyright (C) Nils Weiss 6 | 7 | # scapy.contrib.status = skip 8 | 9 | from scapy.packet import Packet 10 | 11 | 12 | class OBD_Packet(Packet): 13 | def extract_padding(self, s): 14 | return '', s 15 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/obd/pid/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Andreas Korb 5 | # Copyright (C) Nils Weiss 6 | 7 | # scapy.contrib.status = skip 8 | 9 | """ 10 | Package of contrib automotive obd specific modules 11 | that have to be loaded explicitly. 12 | """ 13 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/obd/tid/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Andreas Korb 5 | # Copyright (C) Nils Weiss 6 | 7 | # scapy.contrib.status = skip 8 | 9 | """ 10 | Package of contrib automotive obd specific modules 11 | that have to be loaded explicitly. 12 | """ 13 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/scanner/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Nils Weiss 5 | 6 | # scapy.contrib.description = Automotive Scanner Library 7 | # scapy.contrib.status = skip 8 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/volkswagen/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Nils Weiss 5 | 6 | # scapy.contrib.status = skip 7 | 8 | """ 9 | Package of contrib automotive bmw specific modules 10 | that have to be loaded explicitly. 11 | """ 12 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/xcp/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Tabea Spahn 5 | 6 | # scapy.contrib.status = skip 7 | 8 | """ 9 | Package of contrib automotive xcp specific modules 10 | that have to be loaded explicitly. 11 | """ 12 | -------------------------------------------------------------------------------- /scapy/contrib/bier.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | # scapy.contrib.description = Bit Index Explicit Replication (BIER) 6 | # scapy.contrib.status = loads 7 | 8 | from scapy.packet import Packet, bind_layers 9 | from scapy.fields import BitEnumField, BitField, BitFieldLenField, ByteField, \ 10 | ShortField, StrLenField 11 | from scapy.layers.inet import IP, UDP 12 | from scapy.layers.inet6 import IPv6 13 | 14 | 15 | class BIERLength: 16 | BIER_LEN_64 = 0 17 | BIER_LEN_128 = 1 18 | BIER_LEN_256 = 2 19 | BIER_LEN_512 = 3 20 | BIER_LEN_1024 = 4 21 | 22 | 23 | BIERnhcls = {1: "MPLS", 24 | 2: "MPLS", 25 | 4: "IPv4", 26 | 5: "IPv6"} 27 | 28 | 29 | class BIFT(Packet): 30 | name = "BIFT" 31 | fields_desc = [BitField("bsl", BIERLength.BIER_LEN_256, 4), 32 | BitField("sd", 0, 8), 33 | BitField("set", 0, 8), 34 | BitField("cos", 0, 3), 35 | BitField("s", 1, 1), 36 | ByteField("ttl", 0)] 37 | 38 | 39 | class BIER(Packet): 40 | name = "BIER" 41 | fields_desc = [BitField("id", 5, 4), 42 | BitField("version", 0, 4), 43 | BitFieldLenField("length", BIERLength.BIER_LEN_256, 4, 44 | length_of=lambda x:(x.BitString >> 8)), 45 | BitField("entropy", 0, 20), 46 | BitField("OAM", 0, 2), 47 | BitField("RSV", 0, 2), 48 | BitField("DSCP", 0, 6), 49 | BitEnumField("Proto", 2, 6, BIERnhcls), 50 | ShortField("BFRID", 0), 51 | StrLenField("BitString", 52 | "", 53 | length_from=lambda x:(8 << x.length))] 54 | 55 | 56 | bind_layers(BIER, IP, Proto=4) 57 | bind_layers(BIER, IPv6, Proto=5) 58 | bind_layers(UDP, BIFT, dport=8138) 59 | bind_layers(BIFT, BIER) 60 | -------------------------------------------------------------------------------- /scapy/contrib/cansocket.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Nils Weiss 5 | 6 | # scapy.contrib.description = CANSocket Utils 7 | # scapy.contrib.status = loads 8 | 9 | """ 10 | CANSocket. 11 | """ 12 | 13 | from scapy.error import log_loading 14 | from scapy.consts import LINUX 15 | from scapy.config import conf 16 | 17 | PYTHON_CAN = False 18 | 19 | try: 20 | if conf.contribs['CANSocket']['use-python-can']: 21 | from can import BusABC as can_BusABC # noqa: F401 22 | PYTHON_CAN = True 23 | except ImportError: 24 | log_loading.info("Can't import python-can.") 25 | except KeyError: 26 | log_loading.info("Configuration 'conf.contribs['CANSocket'] not found.") 27 | 28 | 29 | if PYTHON_CAN: 30 | log_loading.info("Using python-can CANSockets.\nSpecify 'conf.contribs['CANSocket'] = {'use-python-can': False}' to enable native CANSockets.") # noqa: E501 31 | from scapy.contrib.cansocket_python_can import (PythonCANSocket, CANSocket) # noqa: E501 F401 32 | 33 | elif LINUX and not conf.use_pypy: 34 | log_loading.info("Using native CANSockets.\nSpecify 'conf.contribs['CANSocket'] = {'use-python-can': True}' to enable python-can CANSockets.") # noqa: E501 35 | from scapy.contrib.cansocket_native import (NativeCANSocket, CANSocket) # noqa: E501 F401 36 | 37 | else: 38 | log_loading.info("No CAN support available. Install python-can or use Linux and python3.") # noqa: E501 39 | -------------------------------------------------------------------------------- /scapy/contrib/esmc.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | # scapy.contrib.description = Ethernet Synchronization Message Channel (ESMC) 6 | # scapy.contrib.status = loads 7 | 8 | from scapy.packet import Packet, bind_layers 9 | from scapy.fields import BitField, ByteField, XByteField, ShortField, XStrFixedLenField # noqa: E501 10 | from scapy.contrib.slowprot import SlowProtocol 11 | from scapy.compat import orb 12 | 13 | 14 | class ESMC(Packet): 15 | name = "ESMC" 16 | fields_desc = [ 17 | XStrFixedLenField("ituOui", b"\x00\x19\xa7", 3), 18 | ShortField("ituSubtype", 1), 19 | BitField("version", 1, 4), 20 | BitField("event", 0, 1), 21 | BitField("reserved1", 0, 3), 22 | XStrFixedLenField("reserved2", b"\x00" * 3, 3), 23 | ] 24 | 25 | def guess_payload_class(self, payload): 26 | if orb(payload[0]) == 1: 27 | return QLTLV 28 | if orb(payload[0]) == 2: 29 | return EQLTLV 30 | return Packet.guess_payload_class(self, payload) 31 | 32 | 33 | class QLTLV(ESMC): 34 | name = "QLTLV" 35 | fields_desc = [ 36 | ByteField("type", 1), 37 | ShortField("length", 4), 38 | XByteField("ssmCode", 0xf), 39 | ] 40 | 41 | 42 | class EQLTLV(ESMC): 43 | name = "EQLTLV" 44 | fields_desc = [ 45 | ByteField("type", 2), 46 | ShortField("length", 0x14), 47 | XByteField("enhancedSsmCode", 0xFF), 48 | XStrFixedLenField("clockIdentity", b"\x00" * 8, 8), 49 | ByteField("flag", 0), 50 | ByteField("cascaded_eEEcs", 1), 51 | ByteField("cascaded_EEcs", 0), 52 | XStrFixedLenField("reserved", b"\x00" * 5, 5), 53 | ] 54 | 55 | 56 | bind_layers(SlowProtocol, ESMC, subtype=10) 57 | -------------------------------------------------------------------------------- /scapy/contrib/etherip.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | # scapy.contrib.description = EtherIP 6 | # scapy.contrib.status = loads 7 | 8 | from scapy.fields import BitField 9 | from scapy.packet import Packet, bind_layers 10 | from scapy.layers.inet import IP 11 | from scapy.layers.l2 import Ether 12 | 13 | 14 | class EtherIP(Packet): 15 | name = "EtherIP / RFC 3378" 16 | fields_desc = [BitField("version", 3, 4), 17 | BitField("reserved", 0, 12)] 18 | 19 | 20 | bind_layers(IP, EtherIP, frag=0, proto=0x61) 21 | bind_layers(EtherIP, Ether) 22 | -------------------------------------------------------------------------------- /scapy/contrib/homeplugsg.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | # scapy.contrib.description = HomePlugSG Layer 6 | # scapy.contrib.status = loads 7 | 8 | 9 | from scapy.packet import Packet, bind_layers 10 | from scapy.fields import FieldLenField, StrFixedLenField, StrLenField 11 | 12 | # Extends HomePlug AV and GP layer 13 | from scapy.contrib.homeplugav import HomePlugAV, QualcommTypeList 14 | 15 | # 16 | # Copyright (C) HomePlugSG Layer for Scapy by FlUxIuS (Sebastien Dudek) 17 | # 18 | 19 | # HomePlug GP extension for SG 20 | 21 | 22 | HomePlugSGTypes = {0xA400: "VS_UART_CMD_Req", 23 | 0xA401: "VS_UART_CMD_Cnf"} 24 | 25 | 26 | QualcommTypeList.update(HomePlugSGTypes) 27 | 28 | # UART commands over HomePlugGP 29 | 30 | 31 | class VS_UART_CMD_REQ(Packet): 32 | name = "VS_UART_CMD_REQ" 33 | fields_desc = [FieldLenField("UDataLen", None, count_of="UData", fmt="H"), 34 | StrLenField("UData", "UartCommand\x00", 35 | length_from=lambda pkt: pkt.UDataLen)] 36 | 37 | 38 | class VS_UART_CMD_CNF(Packet): 39 | name = "VS_UART_CMD_CNF" 40 | fields_desc = [StrFixedLenField("reserved", b"\x00", 6), 41 | FieldLenField("UDataLen", None, count_of="UData", fmt="H"), 42 | StrLenField("UData", "UartCommand\x00", 43 | length_from=lambda pkt: pkt.UDataLen)] 44 | 45 | 46 | # END # 47 | 48 | bind_layers(HomePlugAV, VS_UART_CMD_REQ, HPtype=0xA400) 49 | bind_layers(HomePlugAV, VS_UART_CMD_CNF, HPtype=0xA401) 50 | -------------------------------------------------------------------------------- /scapy/contrib/icmp_extensions.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | # scapy.contrib.description = ICMP Extensions (deprecated) 6 | # scapy.contrib.status = deprecated 7 | 8 | __all__ = [ 9 | "ICMPExtensionObject", 10 | "ICMPExtensionHeader", 11 | "ICMPExtensionInterfaceInformation", 12 | "ICMPExtensionMPLS", 13 | ] 14 | 15 | import warnings 16 | 17 | from scapy.layers.inet import ( 18 | ICMPExtension_Object as ICMPExtensionObject, 19 | ICMPExtension_Header as ICMPExtensionHeader, 20 | ICMPExtension_InterfaceInformation as ICMPExtensionInterfaceInformation, 21 | ) 22 | from scapy.contrib.mpls import ( 23 | ICMPExtension_MPLS as ICMPExtensionMPLS, 24 | ) 25 | 26 | warnings.warn( 27 | "scapy.contrib.icmp_extensions is deprecated. Behavior has changed ! " 28 | "Use scapy.layers.inet", 29 | DeprecationWarning 30 | ) 31 | -------------------------------------------------------------------------------- /scapy/contrib/isotp/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Nils Weiss 5 | 6 | # scapy.contrib.description = ISO-TP (ISO 15765-2) 7 | # scapy.contrib.status = loads 8 | 9 | import logging 10 | 11 | from scapy.consts import LINUX 12 | from scapy.config import conf 13 | from scapy.error import log_loading 14 | 15 | from scapy.contrib.isotp.isotp_packet import ISOTP, ISOTPHeader, \ 16 | ISOTPHeaderEA, ISOTP_SF, ISOTP_FF, ISOTP_CF, ISOTP_FC, \ 17 | ISOTP_FF_FD, ISOTP_SF_FD, ISOTPHeaderEA_FD, ISOTPHeader_FD 18 | from scapy.contrib.isotp.isotp_utils import ISOTPSession, \ 19 | ISOTPMessageBuilder 20 | from scapy.contrib.isotp.isotp_soft_socket import ISOTPSoftSocket 21 | from scapy.contrib.isotp.isotp_scanner import isotp_scan 22 | 23 | __all__ = ["ISOTP", "ISOTPHeader", "ISOTPHeaderEA", "ISOTP_SF", "ISOTP_FF", 24 | "ISOTP_CF", "ISOTP_FC", "ISOTP_FF_FD", "ISOTP_SF_FD", 25 | "ISOTPSoftSocket", "ISOTPSession", "ISOTPHeader_FD", 26 | "ISOTPHeaderEA_FD", 27 | "ISOTPSocket", "ISOTPMessageBuilder", "isotp_scan", 28 | "USE_CAN_ISOTP_KERNEL_MODULE", "log_isotp"] 29 | 30 | USE_CAN_ISOTP_KERNEL_MODULE = False 31 | 32 | log_isotp = logging.getLogger("scapy.contrib.isotp") 33 | log_isotp.setLevel(logging.INFO) 34 | 35 | if LINUX: 36 | try: 37 | if conf.contribs['ISOTP']['use-can-isotp-kernel-module']: 38 | USE_CAN_ISOTP_KERNEL_MODULE = True 39 | except KeyError: 40 | log_loading.info( 41 | "Specify 'conf.contribs['ISOTP'] = {'use-can-isotp-kernel-module': True}' " # noqa: E501 42 | "to enable usage of can-isotp kernel module.") 43 | 44 | from scapy.contrib.isotp.isotp_native_socket import ISOTPNativeSocket 45 | __all__.append("ISOTPNativeSocket") 46 | 47 | if USE_CAN_ISOTP_KERNEL_MODULE: 48 | ISOTPSocket = ISOTPNativeSocket 49 | else: 50 | ISOTPSocket = ISOTPSoftSocket 51 | -------------------------------------------------------------------------------- /scapy/contrib/metawatch.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # Copyright (C) 2019 Brandon Ewing 4 | # 2019 Guillaume Valadon 5 | 6 | # scapy.contrib.description = Arista Metawatch 7 | # scapy.contrib.status = loads 8 | 9 | from scapy.layers.l2 import Ether 10 | from scapy.fields import ( 11 | ByteField, 12 | ShortField, 13 | FlagsField, 14 | SecondsIntField, 15 | TrailerField, 16 | UTCTimeField, 17 | ) 18 | 19 | 20 | class MetawatchEther(Ether): 21 | name = "Ethernet (with MetaWatch trailer)" 22 | match_subclass = True 23 | fields_desc = Ether.fields_desc + [ 24 | TrailerField(ByteField("metamako_portid", None)), 25 | TrailerField(ShortField("metamako_devid", None)), 26 | TrailerField(FlagsField("metamako_flags", 0x0, 8, "VX______")), 27 | TrailerField(SecondsIntField("metamako_nanos", 0, use_nano=True)), 28 | TrailerField(UTCTimeField("metamako_seconds", 0)), 29 | # TODO: Add TLV support 30 | ] 31 | -------------------------------------------------------------------------------- /scapy/contrib/ripng.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | # scapy.contrib.description = Routing Information Protocol next gen (RIPng) 6 | # scapy.contrib.status = loads 7 | 8 | from scapy.packet import Packet, bind_layers 9 | from scapy.fields import ByteEnumField, ByteField, IP6Field, ShortField 10 | from scapy.layers.inet import UDP 11 | 12 | 13 | class RIPng(Packet): 14 | name = "RIPng header" 15 | fields_desc = [ 16 | ByteEnumField("cmd", 1, {1: "req", 2: "resp"}), 17 | ByteField("ver", 1), 18 | ShortField("null", 0) 19 | ] 20 | 21 | 22 | class RIPngEntry(Packet): 23 | name = "RIPng entry" 24 | fields_desc = [ 25 | IP6Field("prefix_or_nh", "::"), 26 | ShortField("routetag", 0), 27 | ByteField("prefixlen", 0), 28 | ByteEnumField("metric", 1, {16: "Unreach", 29 | 255: "next-hop entry"}) 30 | ] 31 | 32 | 33 | bind_layers(UDP, RIPng, sport=521, dport=521) 34 | bind_layers(RIPng, RIPngEntry) 35 | bind_layers(RIPngEntry, RIPngEntry) 36 | -------------------------------------------------------------------------------- /scapy/contrib/rtps/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) 2021 Trend Micro Incorporated 5 | 6 | """ 7 | Real-Time Publish-Subscribe Protocol (RTPS) dissection 8 | """ 9 | 10 | # scapy.contrib.description = Real-Time Publish-Subscribe Protocol (RTPS) 11 | # scapy.contrib.status = loads 12 | # scapy.contrib.name = rtps 13 | 14 | from scapy.contrib.rtps.rtps import * # noqa F403,F401 15 | from scapy.contrib.rtps.pid_types import * # noqa F403,F401 16 | -------------------------------------------------------------------------------- /scapy/contrib/scada/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Thomas Tannhaeuser 5 | 6 | # scapy.contrib.status = skip 7 | 8 | 9 | # Package of contrib SCADA modules. 10 | 11 | 12 | """contains packages related to SCADA protocol layers.""" 13 | 14 | from scapy.contrib.scada.iec104 import * # noqa F403,F401 15 | -------------------------------------------------------------------------------- /scapy/contrib/slowprot.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | # scapy.contrib.description = Slow Protocol 6 | # scapy.contrib.status = loads 7 | 8 | from scapy.packet import Packet, bind_layers 9 | from scapy.fields import ByteEnumField 10 | from scapy.layers.l2 import Ether 11 | from scapy.data import ETHER_TYPES 12 | 13 | 14 | ETHER_TYPES[0x8809] = 'SlowProtocol' 15 | SLOW_SUB_TYPES = { 16 | 'Unused': 0, 17 | 'LACP': 1, 18 | 'Marker Protocol': 2, 19 | 'OAM': 3, 20 | 'OSSP': 10, 21 | } 22 | 23 | 24 | class SlowProtocol(Packet): 25 | name = "SlowProtocol" 26 | fields_desc = [ByteEnumField("subtype", 0, SLOW_SUB_TYPES)] 27 | 28 | 29 | bind_layers(Ether, SlowProtocol, type=0x8809, dst='01:80:c2:00:00:02') 30 | -------------------------------------------------------------------------------- /scapy/contrib/vqp.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | # scapy.contrib.description = VLAN Query Protocol 6 | # scapy.contrib.status = loads 7 | 8 | from scapy.packet import Packet, bind_layers, bind_bottom_up 9 | from scapy.fields import ( 10 | ByteEnumField, 11 | ByteField, 12 | FieldLenField, 13 | IPField, 14 | IntEnumField, 15 | IntField, 16 | MACField, 17 | MultipleTypeField, 18 | StrLenField, 19 | ) 20 | from scapy.layers.inet import UDP 21 | 22 | 23 | class VQP(Packet): 24 | name = "VQP" 25 | fields_desc = [ 26 | ByteField("const", 1), 27 | ByteEnumField("type", 1, { 28 | 1: "requestPort", 2: "responseVLAN", 29 | 3: "requestReconfirm", 4: "responseReconfirm" 30 | }), 31 | ByteEnumField("errorcodeaction", 0, { 32 | 0: "none", 3: "accessDenied", 33 | 4: "shutdownPort", 5: "wrongDomain" 34 | }), 35 | ByteEnumField("unknown", 2, { 36 | 2: "inGoodResponse", 6: "inRequests" 37 | }), 38 | IntField("seq", 0), 39 | ] 40 | 41 | 42 | class VQPEntry(Packet): 43 | name = "VQPEntry" 44 | fields_desc = [ 45 | IntEnumField("datatype", 0, { 46 | 3073: "clientIPAddress", 3074: "portName", 47 | 3075: "VLANName", 3076: "Domain", 3077: "ethernetPacket", 48 | 3078: "ReqMACAddress", 3079: "unknown", 49 | 3080: "ResMACAddress" 50 | }), 51 | FieldLenField("len", None, length_of="data", fmt="H"), 52 | MultipleTypeField( 53 | [ 54 | (IPField("data", "0.0.0.0"), 55 | lambda p: p.datatype == 3073), 56 | (MACField("data", "00:00:00:00:00:00"), 57 | lambda p: p.datatype in [3078, 3080]), 58 | ], 59 | StrLenField("data", None, length_from=lambda p: p.len) 60 | ) 61 | ] 62 | 63 | 64 | bind_bottom_up(UDP, VQP, sport=1589) 65 | bind_bottom_up(UDP, VQP, dport=1589) 66 | bind_layers(UDP, VQP, sport=1589, dport=1589) 67 | 68 | bind_layers(VQP, VQPEntry,) 69 | bind_layers(VQPEntry, VQPEntry,) 70 | -------------------------------------------------------------------------------- /scapy/layers/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | Layer package. 8 | """ 9 | 10 | # Make sure config is loaded 11 | import scapy.config # noqa: F401 12 | -------------------------------------------------------------------------------- /scapy/layers/all.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | All layers. Configurable with conf.load_layers. 8 | """ 9 | 10 | 11 | import builtins 12 | import logging 13 | 14 | # We import conf from arch to make sure arch specific layers are populated 15 | from scapy.arch import conf 16 | from scapy.error import log_loading 17 | from scapy.main import load_layer 18 | 19 | ignored = list(builtins.__dict__) + ["sys"] 20 | log = logging.getLogger("scapy.loading") 21 | 22 | __all__ = [] 23 | 24 | for _l in conf.load_layers: 25 | log_loading.debug("Loading layer %s", _l) 26 | try: 27 | load_layer(_l, globals_dict=globals(), symb_list=__all__) 28 | except Exception as e: 29 | log.warning("can't import layer %s: %s", _l, e) 30 | 31 | try: 32 | del _l 33 | except NameError: 34 | pass 35 | -------------------------------------------------------------------------------- /scapy/layers/gprs.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | GPRS (General Packet Radio Service) for mobile data communication. 8 | """ 9 | 10 | from scapy.fields import StrStopField 11 | from scapy.packet import Packet, bind_layers 12 | from scapy.layers.inet import IP 13 | 14 | 15 | class GPRS(Packet): 16 | name = "GPRSdummy" 17 | fields_desc = [ 18 | StrStopField("dummy", "", b"\x65\x00\x00", 1) 19 | ] 20 | 21 | 22 | bind_layers(GPRS, IP,) 23 | -------------------------------------------------------------------------------- /scapy/layers/ir.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | IrDA infrared data communication. 8 | """ 9 | 10 | from scapy.packet import Packet, bind_layers 11 | from scapy.fields import BitEnumField, ByteEnumField, StrField, XBitField, \ 12 | XByteField, XIntField, XShortField 13 | from scapy.layers.l2 import CookedLinux 14 | 15 | 16 | # IR 17 | 18 | class IrLAPHead(Packet): 19 | name = "IrDA Link Access Protocol Header" 20 | fields_desc = [XBitField("Address", 0x7f, 7), 21 | BitEnumField("Type", 1, 1, {"Response": 0, 22 | "Command": 1})] 23 | 24 | 25 | class IrLAPCommand(Packet): 26 | name = "IrDA Link Access Protocol Command" 27 | fields_desc = [XByteField("Control", 0), 28 | XByteField("Format_identifier", 0), 29 | XIntField("Source_address", 0), 30 | XIntField("Destination_address", 0xffffffff), 31 | XByteField("Discovery_flags", 0x1), 32 | ByteEnumField("Slot_number", 255, {"final": 255}), 33 | XByteField("Version", 0)] 34 | 35 | 36 | class IrLMP(Packet): 37 | name = "IrDA Link Management Protocol" 38 | fields_desc = [XShortField("Service_hints", 0), 39 | XByteField("Character_set", 0), 40 | StrField("Device_name", "")] 41 | 42 | 43 | bind_layers(CookedLinux, IrLAPHead, proto=23) 44 | bind_layers(IrLAPHead, IrLAPCommand, Type=1) 45 | bind_layers(IrLAPCommand, IrLMP,) 46 | -------------------------------------------------------------------------------- /scapy/layers/l2tp.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | L2TP (Layer 2 Tunneling Protocol) for VPNs. 8 | 9 | [RFC 2661] 10 | """ 11 | 12 | import struct 13 | 14 | from scapy.packet import Packet, bind_layers, bind_bottom_up 15 | from scapy.fields import BitEnumField, ConditionalField, FlagsField, \ 16 | PadField, ShortField 17 | from scapy.layers.inet import UDP 18 | from scapy.layers.ppp import PPP 19 | 20 | 21 | class L2TP(Packet): 22 | name = "L2TP" 23 | fields_desc = [ 24 | FlagsField("hdr", 0, 12, ['res00', 'res01', 'res02', 'res03', 'priority', 'offset', # noqa: E501 25 | 'res06', 'sequence', 'res08', 'res09', 'length', 'control']), # noqa: E501 26 | BitEnumField("version", 2, 4, {2: 'L2TPv2'}), 27 | 28 | ConditionalField(ShortField("len", None), 29 | lambda pkt: pkt.hdr & 'control+length'), 30 | ShortField("tunnel_id", 0), 31 | ShortField("session_id", 0), 32 | ConditionalField(ShortField("ns", 0), 33 | lambda pkt: pkt.hdr & 'sequence+control'), 34 | ConditionalField(ShortField("nr", 0), 35 | lambda pkt: pkt.hdr & 'sequence+control'), 36 | ConditionalField( 37 | PadField(ShortField("offset", 0), 4, b"\x00"), 38 | lambda pkt: not (pkt.hdr & 'control') and pkt.hdr & 'offset' 39 | ) 40 | ] 41 | 42 | def post_build(self, pkt, pay): 43 | if self.len is None and self.hdr & 'control+length': 44 | tmp_len = len(pkt) + len(pay) 45 | pkt = pkt[:2] + struct.pack("!H", tmp_len) + pkt[4:] 46 | return pkt + pay 47 | 48 | 49 | bind_bottom_up(UDP, L2TP, dport=1701) 50 | bind_bottom_up(UDP, L2TP, sport=1701) 51 | bind_layers(UDP, L2TP, dport=1701, sport=1701) 52 | bind_layers(L2TP, PPP,) 53 | -------------------------------------------------------------------------------- /scapy/layers/mgcp.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | MGCP (Media Gateway Control Protocol) 8 | 9 | [RFC 2805] 10 | """ 11 | 12 | from scapy.packet import Packet, bind_layers, bind_bottom_up 13 | from scapy.fields import StrFixedLenField, StrStopField 14 | from scapy.layers.inet import UDP 15 | 16 | 17 | class MGCP(Packet): 18 | name = "MGCP" 19 | longname = "Media Gateway Control Protocol" 20 | fields_desc = [StrStopField("verb", "AUEP", b" ", -1), 21 | StrFixedLenField("sep1", " ", 1), 22 | StrStopField("transaction_id", "1234567", b" ", -1), 23 | StrFixedLenField("sep2", " ", 1), 24 | StrStopField("endpoint", "dummy@dummy.net", b" ", -1), 25 | StrFixedLenField("sep3", " ", 1), 26 | StrStopField("version", "MGCP 1.0 NCS 1.0", b"\x0a", -1), 27 | StrFixedLenField("sep4", b"\x0a", 1), 28 | ] 29 | 30 | 31 | # class MGCP(Packet): 32 | # name = "MGCP" 33 | # longname = "Media Gateway Control Protocol" 34 | # fields_desc = [ ByteEnumField("type",0, ["request","response","others"]), 35 | # ByteField("code0",0), 36 | # ByteField("code1",0), 37 | # ByteField("code2",0), 38 | # ByteField("code3",0), 39 | # ByteField("code4",0), 40 | # IntField("trasid",0), 41 | # IntField("req_time",0), 42 | # ByteField("is_duplicate",0), 43 | # ByteField("req_available",0) ] 44 | # 45 | bind_bottom_up(UDP, MGCP, dport=2727) 46 | bind_bottom_up(UDP, MGCP, sport=2727) 47 | bind_layers(UDP, MGCP, sport=2727, dport=2727) 48 | -------------------------------------------------------------------------------- /scapy/layers/mobileip.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | Mobile IP. 8 | """ 9 | 10 | from scapy.fields import ByteEnumField, ByteField, IPField, LongField, \ 11 | ShortField, XByteField 12 | from scapy.packet import Packet, bind_layers, bind_bottom_up 13 | from scapy.layers.inet import IP, UDP 14 | 15 | 16 | class MobileIP(Packet): 17 | name = "Mobile IP (RFC3344)" 18 | fields_desc = [ByteEnumField("type", 1, {1: "RRQ", 3: "RRP"})] 19 | 20 | 21 | class MobileIPRRQ(Packet): 22 | name = "Mobile IP Registration Request (RFC3344)" 23 | fields_desc = [XByteField("flags", 0), 24 | ShortField("lifetime", 180), 25 | IPField("homeaddr", "0.0.0.0"), 26 | IPField("haaddr", "0.0.0.0"), 27 | IPField("coaddr", "0.0.0.0"), 28 | LongField("id", 0), ] 29 | 30 | 31 | class MobileIPRRP(Packet): 32 | name = "Mobile IP Registration Reply (RFC3344)" 33 | fields_desc = [ByteField("code", 0), 34 | ShortField("lifetime", 180), 35 | IPField("homeaddr", "0.0.0.0"), 36 | IPField("haaddr", "0.0.0.0"), 37 | LongField("id", 0), ] 38 | 39 | 40 | class MobileIPTunnelData(Packet): 41 | name = "Mobile IP Tunnel Data Message (RFC3519)" 42 | fields_desc = [ByteField("nexthdr", 4), 43 | ShortField("res", 0)] 44 | 45 | 46 | bind_bottom_up(UDP, MobileIP, dport=434) 47 | bind_bottom_up(UDP, MobileIP, sport=434) 48 | bind_layers(UDP, MobileIP, sport=434, dport=434) 49 | bind_layers(MobileIP, MobileIPRRQ, type=1) 50 | bind_layers(MobileIP, MobileIPRRP, type=3) 51 | bind_layers(MobileIP, MobileIPTunnelData, type=4) 52 | bind_layers(MobileIPTunnelData, IP, nexthdr=4) 53 | -------------------------------------------------------------------------------- /scapy/layers/msrpce/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Gabriel Potter 5 | 6 | """ 7 | [MS-RPCE] Remote Procedure Call Protocol Extensions 8 | 9 | This module contains toolery to interact with Microsoft's [MS-RPCE] 10 | (DCE/RPC) extensions. 11 | 12 | It contains the following modules: 13 | 14 | - ``scapy.layers.msrpce.rpcclient``: a MS-RPCE client 15 | - ``scapy.layers.msrpce.rpcserver``: a MS-RPCE server 16 | - ``scapy.layers.msrpce.ept``: DCE/RPC 1.1 endpoint mapper 17 | - ``scapy.layers.msrpce.mspac``: [MS-PAC], the PAC in Kerberos packets 18 | - ``scapy.layers.msrpce.msnrpc``: [MS-NRPC], a client and SSP 19 | - ``scapy.layers.msnpce.raw``: raw RPC classes 20 | """ 21 | -------------------------------------------------------------------------------- /scapy/layers/msrpce/raw/README.md: -------------------------------------------------------------------------------- 1 | # msrpce/raw 2 | 3 | This folder contains partial definitions of Windows IDLs. 4 | -------------------------------------------------------------------------------- /scapy/layers/msrpce/raw/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | """ 6 | 'Raw' definitions of DCE/RPC IDL interfaces 7 | """ 8 | -------------------------------------------------------------------------------- /scapy/layers/rtp.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | RTP (Real-time Transport Protocol). 8 | 9 | Remember to use:: 10 | 11 | bind_layers(UDP, RTP, dport=XXX) 12 | 13 | To register the port you are using 14 | """ 15 | 16 | from scapy.packet import Packet, bind_layers 17 | from scapy.fields import BitEnumField, BitField, BitFieldLenField, \ 18 | FieldLenField, FieldListField, IntField, ShortField 19 | 20 | _rtp_payload_types = { 21 | # http://www.iana.org/assignments/rtp-parameters 22 | 0: 'G.711 PCMU', 3: 'GSM', 23 | 4: 'G723', 5: 'DVI4', 24 | 6: 'DVI4', 7: 'LPC', 25 | 8: 'PCMA', 9: 'G722', 26 | 10: 'L16', 11: 'L16', 27 | 12: 'QCELP', 13: 'CN', 28 | 14: 'MPA', 15: 'G728', 29 | 16: 'DVI4', 17: 'DVI4', 30 | 18: 'G729', 25: 'CelB', 31 | 26: 'JPEG', 28: 'nv', 32 | 31: 'H261', 32: 'MPV', 33 | 33: 'MP2T', 34: 'H263'} 34 | 35 | 36 | class RTPExtension(Packet): 37 | name = "RTP extension" 38 | fields_desc = [ShortField("header_id", 0), 39 | FieldLenField("header_len", None, count_of="header", fmt="H"), # noqa: E501 40 | FieldListField('header', [], IntField("hdr", 0), count_from=lambda pkt: pkt.header_len)] # noqa: E501 41 | 42 | 43 | class RTP(Packet): 44 | name = "RTP" 45 | fields_desc = [BitField('version', 2, 2), 46 | BitField('padding', 0, 1), 47 | BitField('extension', 0, 1), 48 | BitFieldLenField('numsync', None, 4, count_of='sync'), 49 | BitField('marker', 0, 1), 50 | BitEnumField('payload_type', 0, 7, _rtp_payload_types), 51 | ShortField('sequence', 0), 52 | IntField('timestamp', 0), 53 | IntField('sourcesync', 0), 54 | FieldListField('sync', [], IntField("id", 0), count_from=lambda pkt:pkt.numsync)] # noqa: E501 55 | 56 | 57 | bind_layers(RTP, RTPExtension, extension=1) 58 | -------------------------------------------------------------------------------- /scapy/layers/tls/all.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) 2007, 2008, 2009 Arnaud Ebalard 5 | # 2015, 2016, 2017 Maxence Tury 6 | 7 | """ 8 | Aggregate top level objects from all TLS modules. 9 | """ 10 | 11 | from scapy.layers.tls.cert import * # noqa: F401 12 | 13 | from scapy.layers.tls.automaton_cli import * # noqa: F401 14 | from scapy.layers.tls.automaton_srv import * # noqa: F401 15 | from scapy.layers.tls.extensions import * # noqa: F401 16 | from scapy.layers.tls.handshake import * # noqa: F401 17 | from scapy.layers.tls.handshake_sslv2 import * # noqa: F401 18 | from scapy.layers.tls.keyexchange import * # noqa: F401 19 | from scapy.layers.tls.keyexchange_tls13 import * # noqa: F401 20 | from scapy.layers.tls.record import * # noqa: F401 21 | from scapy.layers.tls.record_sslv2 import * # noqa: F401 22 | from scapy.layers.tls.record_tls13 import * # noqa: F401 23 | from scapy.layers.tls.session import * # noqa: F401 24 | 25 | from scapy.layers.tls.crypto.all import * # noqa: F401 26 | -------------------------------------------------------------------------------- /scapy/layers/tls/crypto/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) 2007, 2008, 2009 Arnaud Ebalard 5 | # 2015, 2016 Maxence Tury 6 | 7 | """ 8 | Cryptographic capabilities for TLS. 9 | """ 10 | -------------------------------------------------------------------------------- /scapy/layers/tls/crypto/all.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) 2007, 2008, 2009 Arnaud Ebalard 5 | # 2015, 2016, 2017 Maxence Tury 6 | 7 | """ 8 | Aggregate some TLS crypto objects. 9 | """ 10 | 11 | from scapy.layers.tls.crypto.suites import * # noqa: F401 12 | -------------------------------------------------------------------------------- /scapy/layers/tls/crypto/ciphers.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) 2007, 2008, 2009 Arnaud Ebalard 5 | # 2015, 2016 Maxence Tury 6 | 7 | """ 8 | TLS ciphers. 9 | """ 10 | 11 | # in order to avoid circular dependencies. 12 | from scapy.layers.tls.crypto.cipher_aead import _tls_aead_cipher_algs 13 | from scapy.layers.tls.crypto.cipher_block import _tls_block_cipher_algs 14 | from scapy.layers.tls.crypto.cipher_stream import _tls_stream_cipher_algs 15 | 16 | _tls_cipher_algs = {} 17 | _tls_cipher_algs.update(_tls_block_cipher_algs) 18 | _tls_cipher_algs.update(_tls_stream_cipher_algs) 19 | _tls_cipher_algs.update(_tls_aead_cipher_algs) 20 | -------------------------------------------------------------------------------- /scapy/layers/tls/crypto/common.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | """ 6 | TLS ciphers. 7 | """ 8 | 9 | 10 | class CipherError(Exception): 11 | """ 12 | Raised when .decrypt() or .auth_decrypt() fails. 13 | """ 14 | pass 15 | -------------------------------------------------------------------------------- /scapy/layers/tls/crypto/hash.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) 2007, 2008, 2009 Arnaud Ebalard 5 | # 2015, 2016 Maxence Tury 6 | 7 | """ 8 | Hash classes. 9 | """ 10 | 11 | from hashlib import md5, sha1, sha224, sha256, sha384, sha512 12 | from scapy.layers.tls.crypto.md4 import MD4 as md4 13 | 14 | 15 | _tls_hash_algs = {} 16 | 17 | 18 | class _GenericHashMetaclass(type): 19 | """ 20 | Hash classes are automatically registered through this metaclass. 21 | Furthermore, their name attribute is extracted from their class name. 22 | """ 23 | def __new__(cls, hash_name, bases, dct): 24 | if hash_name != "_GenericHash": 25 | dct["name"] = hash_name[5:] # remove leading "Hash_" 26 | the_class = super(_GenericHashMetaclass, cls).__new__(cls, hash_name, 27 | bases, dct) 28 | if hash_name != "_GenericHash": 29 | _tls_hash_algs[hash_name[5:]] = the_class 30 | return the_class 31 | 32 | 33 | class _GenericHash(metaclass=_GenericHashMetaclass): 34 | def digest(self, tbd): 35 | return self.hash_cls(tbd).digest() 36 | 37 | 38 | class Hash_NULL(_GenericHash): 39 | hash_len = 0 40 | 41 | def digest(self, tbd): 42 | return b"" 43 | 44 | 45 | class Hash_MD4(_GenericHash): 46 | hash_cls = md4 47 | hash_len = 16 48 | 49 | 50 | class Hash_MD5(_GenericHash): 51 | hash_cls = md5 52 | hash_len = 16 53 | 54 | 55 | class Hash_SHA(_GenericHash): 56 | hash_cls = sha1 57 | hash_len = 20 58 | 59 | 60 | class Hash_SHA224(_GenericHash): 61 | hash_cls = sha224 62 | hash_len = 28 63 | 64 | 65 | class Hash_SHA256(_GenericHash): 66 | hash_cls = sha256 67 | hash_len = 32 68 | 69 | 70 | class Hash_SHA384(_GenericHash): 71 | hash_cls = sha384 72 | hash_len = 48 73 | 74 | 75 | class Hash_SHA512(_GenericHash): 76 | hash_cls = sha512 77 | hash_len = 64 78 | -------------------------------------------------------------------------------- /scapy/libs/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | """ 6 | Library bindings 7 | """ 8 | -------------------------------------------------------------------------------- /scapy/libs/matplot.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | External link to matplotlib 8 | """ 9 | 10 | from scapy.error import log_loading 11 | 12 | # Notice: this file must not be called before main.py, if started 13 | # in interactive mode, because it needs to be called after the 14 | # logger has been setup, to be able to print the warning messages 15 | 16 | __all__ = [ 17 | "Line2D", 18 | "MATPLOTLIB", 19 | "MATPLOTLIB_DEFAULT_PLOT_KARGS", 20 | "MATPLOTLIB_INLINED", 21 | "plt", 22 | ] 23 | 24 | # MATPLOTLIB 25 | 26 | try: 27 | from matplotlib import get_backend as matplotlib_get_backend 28 | from matplotlib import pyplot as plt 29 | from matplotlib.lines import Line2D 30 | MATPLOTLIB = 1 31 | if "inline" in matplotlib_get_backend(): 32 | MATPLOTLIB_INLINED = 1 33 | else: 34 | MATPLOTLIB_INLINED = 0 35 | MATPLOTLIB_DEFAULT_PLOT_KARGS = {"marker": "+"} 36 | # RuntimeError to catch gtk "Cannot open display" error 37 | except (ImportError, RuntimeError) as ex: 38 | plt = None 39 | Line2D = None 40 | MATPLOTLIB = 0 41 | MATPLOTLIB_INLINED = 0 42 | MATPLOTLIB_DEFAULT_PLOT_KARGS = dict() 43 | log_loading.info("Can't import matplotlib: %s. Won't be able to plot.", ex) 44 | -------------------------------------------------------------------------------- /scapy/libs/structures.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | """ 6 | Commonly used structures shared across Scapy 7 | """ 8 | 9 | import ctypes 10 | 11 | 12 | class bpf_insn(ctypes.Structure): 13 | """"The BPF instruction data structure""" 14 | _fields_ = [("code", ctypes.c_ushort), 15 | ("jt", ctypes.c_ubyte), 16 | ("jf", ctypes.c_ubyte), 17 | ("k", ctypes.c_int)] 18 | 19 | 20 | class bpf_program(ctypes.Structure): 21 | """"Structure for BIOCSETF""" 22 | _fields_ = [('bf_len', ctypes.c_int), 23 | ('bf_insns', ctypes.POINTER(bpf_insn))] 24 | 25 | 26 | class sock_fprog(ctypes.Structure): 27 | """"Structure for SO_ATTACH_FILTER""" 28 | _fields_ = [('len', ctypes.c_ushort), 29 | ('filter', ctypes.POINTER(bpf_insn))] 30 | -------------------------------------------------------------------------------- /scapy/libs/test_pyx.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | """ 6 | External link to pyx 7 | """ 8 | 9 | import os 10 | import subprocess 11 | from scapy.error import log_loading 12 | 13 | # Notice: this file must not be called before main.py, if started 14 | # in interactive mode, because it needs to be called after the 15 | # logger has been setup, to be able to print the warning messages 16 | 17 | __all__ = [ 18 | "PYX", 19 | ] 20 | 21 | # PYX 22 | 23 | 24 | def _test_pyx(): 25 | # type: () -> bool 26 | """Returns if PyX is correctly installed or not""" 27 | try: 28 | with open(os.devnull, 'wb') as devnull: 29 | r = subprocess.check_call(["pdflatex", "--version"], 30 | stdout=devnull, stderr=subprocess.STDOUT) 31 | except (subprocess.CalledProcessError, OSError): 32 | return False 33 | else: 34 | return r == 0 35 | 36 | 37 | try: 38 | import pyx # noqa: F401 39 | if _test_pyx(): 40 | PYX = 1 41 | else: 42 | log_loading.info("PyX dependencies are not installed ! Please install TexLive or MikTeX.") # noqa: E501 43 | PYX = 0 44 | except ImportError: 45 | log_loading.info("Can't import PyX. Won't be able to use psdump() or pdfdump().") # noqa: E501 46 | PYX = 0 47 | -------------------------------------------------------------------------------- /scapy/modules/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | Package of extension modules that have to be loaded explicitly. 8 | """ 9 | 10 | # Make sure config is loaded 11 | import scapy.config # noqa: F401 12 | -------------------------------------------------------------------------------- /scapy/modules/krack/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | """Module implementing Krack Attack on client, as a custom WPA Access Point 6 | 7 | Requires the python cryptography package v1.7+. See https://cryptography.io/ 8 | 9 | More details on the attack can be found on https://www.krackattacks.com/ 10 | 11 | Example of use (from the scapy shell): 12 | >>> load_module("krack") 13 | >>> KrackAP( 14 | iface="mon0", # A monitor interface 15 | ap_mac='11:22:33:44:55:66', # MAC (BSSID) to use 16 | ssid="TEST_KRACK", # SSID 17 | passphrase="testtest", # Associated passphrase 18 | ).run() 19 | 20 | Then, on the target device, connect to "TEST_KRACK" using "testtest" as the 21 | passphrase. 22 | The output logs will indicate if one of the vulnerability have been triggered. 23 | 24 | Outputs for vulnerable devices: 25 | - IV reuse!! Client seems to be vulnerable to handshake 3/4 replay 26 | (CVE-2017-13077) 27 | - Broadcast packet accepted twice!! (CVE-2017-13080) 28 | - Client has installed an all zero encryption key (TK)!! 29 | 30 | For patched devices: 31 | - Client is likely not vulnerable to CVE-2017-13080 32 | """ 33 | 34 | from scapy.config import conf 35 | 36 | if conf.crypto_valid: 37 | from scapy.modules.krack.automaton import KrackAP # noqa: F401 38 | else: 39 | raise ImportError("Cannot import Krack module due to missing dependency. " 40 | "Please install python{3}-cryptography v1.7+.") 41 | -------------------------------------------------------------------------------- /scapy/py.typed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/scapy/py.typed -------------------------------------------------------------------------------- /scapy/tools/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Philippe Biondi 5 | 6 | """ 7 | Additional tools to be run separately 8 | """ 9 | -------------------------------------------------------------------------------- /scapy/tools/automotive/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Nils Weiss 5 | 6 | """ 7 | Automotive related tools to be run separately 8 | """ 9 | -------------------------------------------------------------------------------- /scapy/tools/check_spdx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # SPDX-License-Identifier: GPL-2.0-only 4 | # This file is part of Scapy 5 | # See https://scapy.net/ for more information 6 | 7 | # Check that all Scapy files have a SPDX 8 | 9 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 10 | ROOT_DIR=$SCRIPT_DIR/../.. 11 | 12 | # http://mywiki.wooledge.org/BashFAQ/024 13 | # This documents an absolutely WTF behavior of bash. 14 | set +m 15 | shopt -s lastpipe 16 | 17 | function check_path() { 18 | cd $ROOT_DIR 19 | RCODE=0 20 | for ext in "${@:2}"; do 21 | find $1 -name "*.$ext" | while read f; do 22 | if [[ -z $(grep "SPDX" $f) ]]; then 23 | echo "$f" 24 | RCODE=1 25 | fi 26 | done 27 | done 28 | return $RCODE 29 | } 30 | 31 | check_path scapy py || exit $? 32 | -------------------------------------------------------------------------------- /scapy/tools/generate_manuf.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-or-later 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Gabriel Potter 5 | 6 | """ 7 | Generate the manuf.py file based on wireshark's manuf 8 | """ 9 | 10 | import gzip 11 | import urllib.request 12 | 13 | from base64 import b85encode 14 | 15 | URL = "https://www.wireshark.org/download/automated/data/manuf" 16 | 17 | with urllib.request.urlopen(URL) as stream: 18 | DATA = stream.read() 19 | 20 | COMPILED = "" 21 | 22 | for line in DATA.split(b"\n"): 23 | # We decode to strip any non-UTF8 characters. 24 | line = line.strip().decode("utf8", errors="backslashreplace") 25 | if not line or line.startswith("#"): 26 | continue 27 | COMPILED += line + "\n" 28 | 29 | # Compress properly 30 | COMPILED = gzip.compress(COMPILED.encode()) 31 | # Encode in Base85 32 | COMPILED = b85encode(COMPILED).decode() 33 | # Split 34 | COMPILED = "\n".join(COMPILED[i : i + 79] for i in range(0, len(COMPILED), 79)) + "\n" 35 | 36 | 37 | with open("../libs/manuf.py", "r") as inp: 38 | data = inp.read() 39 | 40 | with open("../libs/manuf.py", "w") as out: 41 | ini, sep, _ = data.partition("DATA = _d(\"\"\"") 42 | COMPILED = ini + sep + "\n" + COMPILED + "\"\"\")\n" 43 | print("Written: %s" % out.write(COMPILED)) 44 | -------------------------------------------------------------------------------- /scapy/tools/scapy_pyannotate.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | 5 | """ 6 | Wrap Scapy's shell in pyannotate. 7 | """ 8 | 9 | import os 10 | import sys 11 | sys.path.insert(0, os.path.abspath('../../')) 12 | 13 | from pyannotate_runtime import collect_types # noqa: E402 14 | from scapy.main import interact # noqa: E402 15 | 16 | collect_types.init_types_collection() 17 | with collect_types.collect(): 18 | interact() 19 | 20 | collect_types.dump_stats("pyannotate_results_main") 21 | -------------------------------------------------------------------------------- /test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/__init__.py -------------------------------------------------------------------------------- /test/benchmark/common.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Guillaume Valadon 5 | 6 | import os 7 | import sys 8 | 9 | scapy_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) 10 | sys.path.append(scapy_path) 11 | 12 | from scapy.all import * 13 | 14 | print("Scapy %s - Benchmarks" % VERSION) 15 | print("Python %s" % sys.version.replace("\n", "")) 16 | -------------------------------------------------------------------------------- /test/benchmark/dissection_and_build.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Guillaume Valadon 5 | 6 | from common import * 7 | import time 8 | 9 | N = 10000 10 | raw_packet = b'E\x00\x00(\x00\x01\x00\x00@\x11|\xc2\x7f\x00\x00\x01\x7f\x00\x00\x01\x005\x005\x00\x14\x00Z\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00' 11 | 12 | start = time.time() 13 | for i in range(N): 14 | p = IP(dst="127.0.0.1", src="127.0.0.1") / UDP() / DNS() 15 | assert raw(p) == raw_packet 16 | print("Build - %.2fs" % (time.time() - start)) 17 | 18 | start = time.time() 19 | for i in range(N): 20 | p = IP(raw_packet) 21 | assert DNS in p 22 | print("Dissect - %.2fs" % (time.time() - start)) 23 | 24 | start = time.time() 25 | for i in range(N): 26 | p = IP(dst="127.0.0.1", src="127.0.0.1") / UDP() / DNS() 27 | s = raw(p) 28 | assert s == raw_packet 29 | p = IP(s) 30 | assert DNS in p 31 | print("Build & dissect - %.2fs" % (time.time() - start)) 32 | -------------------------------------------------------------------------------- /test/benchmark/latency_router.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) Gabriel Potter 5 | 6 | 7 | # https://github.com/secdev/scapy/issues/1791 8 | 9 | from common import * 10 | 11 | # Router IP 12 | dest = conf.route.route("0.0.0.0")[2] 13 | 14 | send_tcp = True 15 | send_icmp = False 16 | 17 | pkts = [] 18 | for i in range(1,50): 19 | a = IP(dst=dest) / TCP(flags="S", seq=i, sport=65000, dport=55556) 20 | b = IP(dst=dest)/ICMP() 21 | if send_tcp: 22 | pkts.append(a) 23 | if send_icmp: 24 | pkts.append(b) 25 | 26 | ans, unans = sr(pkts, filter="host {0}".format(dest), inter=0, timeout=1, prebuild=True) 27 | 28 | print("scapy version: {}".format(conf.version)) 29 | 30 | average = 0 31 | 32 | for pkt in ans: 33 | sent = pkt[0] 34 | received = pkt[1] 35 | res = (received.time - sent.sent_time) 36 | average += res 37 | print("%s %s : %s" % (received.time, sent.sent_time, res)) 38 | 39 | print("AVERAGE RESPONSE TIME: %ss" % (average / len(ans))) 40 | -------------------------------------------------------------------------------- /test/configs/README.md: -------------------------------------------------------------------------------- 1 | ### UTscapy configs 2 | 3 | - OS specifics: bsd, linux, solaris, windows 4 | - Other: 5 | - cryptography -> used for downstream testing by pyca/cryptography 6 | -------------------------------------------------------------------------------- /test/configs/bsd.utsc: -------------------------------------------------------------------------------- 1 | { 2 | "testfiles": [ 3 | "test/*.uts", 4 | "test/scapy/layers/*.uts", 5 | "test/contrib/automotive/*.uts", 6 | "test/contrib/automotive/obd/*.uts", 7 | "test/contrib/automotive/scanner/*.uts", 8 | "test/contrib/automotive/gm/*.uts", 9 | "test/contrib/automotive/bmw/*.uts", 10 | "test/contrib/automotive/xcp/*.uts", 11 | "test/contrib/automotive/autosar/*.uts", 12 | "test/contrib/*.uts" 13 | ], 14 | "remove_testfiles": [ 15 | "test/linux.uts", 16 | "test/windows.uts", 17 | "test/contrib/automotive/ecu_am.uts", 18 | "test/contrib/automotive/gm/gmlanutils.uts", 19 | "test/contrib/isotp_packet.uts", 20 | "test/contrib/isotpscan.uts", 21 | "test/contrib/isotp_soft_socket.uts" 22 | ], 23 | "onlyfailed": true, 24 | "preexec": { 25 | "test/contrib/*.uts": "load_contrib(\"%name%\")", 26 | "test/cert.uts": "load_layer(\"tls\")", 27 | "test/sslv2.uts": "load_layer(\"tls\")", 28 | "test/tls*.uts": "load_layer(\"tls\")" 29 | }, 30 | "kw_ko": [ 31 | "linux", 32 | "windows", 33 | "ipv6", 34 | "vcan_socket", 35 | "tun", 36 | "tap" 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /test/configs/cryptography.utsc: -------------------------------------------------------------------------------- 1 | { 2 | "testfiles": [ 3 | "test/contrib/macsec.uts", 4 | "test/scapy/layers/dot11.uts", 5 | "test/scapy/layers/ipsec.uts", 6 | "test/scapy/layers/kerberos.uts", 7 | "test/scapy/layers/msnrpc.uts", 8 | "test/scapy/layers/tls/cert.uts", 9 | "test/scapy/layers/tls/tls*.uts" 10 | ], 11 | "breakfailed": true, 12 | "onlyfailed": true, 13 | "preexec": { 14 | "test/contrib/*.uts": "load_contrib(\"%name%\")", 15 | "test/scapy/layers/tls/*.uts": "load_layer(\"tls\")" 16 | }, 17 | "kw_ko": [ 18 | "mock", 19 | "needs_root" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /test/configs/linux.utsc: -------------------------------------------------------------------------------- 1 | { 2 | "testfiles": [ 3 | "test/*.uts", 4 | "test/scapy/layers/*.uts", 5 | "test/scapy/layers/tls/*.uts", 6 | "test/contrib/*.uts", 7 | "test/tools/*.uts", 8 | "test/contrib/automotive/*.uts", 9 | "test/contrib/automotive/obd/*.uts", 10 | "test/contrib/automotive/scanner/*.uts", 11 | "test/contrib/automotive/gm/*.uts", 12 | "test/contrib/automotive/bmw/*.uts", 13 | "test/contrib/automotive/xcp/*.uts", 14 | "test/contrib/automotive/autosar/*.uts" 15 | ], 16 | "remove_testfiles": [ 17 | "test/windows.uts", 18 | "test/bpf.uts" 19 | ], 20 | "breakfailed": true, 21 | "onlyfailed": true, 22 | "preexec": { 23 | "test/contrib/*.uts": "load_contrib(\"%name%\")", 24 | "test/scapy/layers/tls/*.uts": "load_layer(\"tls\")" 25 | }, 26 | "kw_ko": [ 27 | "osx", 28 | "windows", 29 | "ipv6" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /test/configs/solaris.utsc: -------------------------------------------------------------------------------- 1 | { 2 | "testfiles": [ 3 | "test/*.uts", 4 | "test/scapy/layers/*.uts", 5 | "test/contrib/automotive/*.uts", 6 | "test/contrib/automotive/obd/*.uts", 7 | "test/contrib/automotive/scanner/*.uts", 8 | "test/contrib/automotive/gm/*.uts", 9 | "test/contrib/automotive/bmw/*.uts", 10 | "test/contrib/automotive/xcp/*.uts", 11 | "test/contrib/automotive/autosar/*.uts", 12 | "test/contrib/*.uts" 13 | ], 14 | "remove_testfiles": [ 15 | "test/linux.uts", 16 | "test/bpf.uts", 17 | "test/windows.uts", 18 | "test/contrib/automotive/ecu_am.uts", 19 | "test/contrib/automotive/gm/gmlanutils.uts", 20 | "test/contrib/isotp.uts", 21 | "test/contrib/isotpscan.uts" 22 | ], 23 | "onlyfailed": true, 24 | "preexec": { 25 | "test/contrib/*.uts": "load_contrib(\"%name%\")", 26 | "test/cert.uts": "load_layer(\"tls\")", 27 | "test/sslv2.uts": "load_layer(\"tls\")", 28 | "test/tls*.uts": "load_layer(\"tls\")" 29 | }, 30 | "kw_ko": [ 31 | "osx", 32 | "linux", 33 | "windows", 34 | "crypto_advanced", 35 | "ipv6", 36 | "tap", 37 | "tun", 38 | "vcan_socket" 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /test/configs/windows.utsc: -------------------------------------------------------------------------------- 1 | { 2 | "testfiles": [ 3 | "test\\*.uts", 4 | "test\\scapy\\layers\\*.uts", 5 | "test\\scapy\\layers\\tls\\*.uts", 6 | "test\\contrib\\automotive\\obd\\*.uts", 7 | "test\\contrib\\automotive\\scanner\\*.uts", 8 | "test\\contrib\\automotive\\gm\\*.uts", 9 | "test\\contrib\\automotive\\bmw\\*.uts", 10 | "test\\contrib\\automotive\\xcp\\*.uts", 11 | "test\\contrib\\automotive\\*.uts", 12 | "test\\contrib\\automotive\\autosar\\*.uts", 13 | "test\\contrib\\*.uts" 14 | ], 15 | "remove_testfiles": [ 16 | "test\\bpf.uts", 17 | "test\\linux.uts" 18 | ], 19 | "breakfailed": true, 20 | "onlyfailed": true, 21 | "preexec": { 22 | "test\\contrib\\*.uts": "load_contrib(\"%name%\")", 23 | "test\\scapy\\layers\\tls\\*.uts": "load_layer(\"tls\")" 24 | }, 25 | "kw_ko": [ 26 | "as_resolvers", 27 | "brotli", 28 | "broken_windows", 29 | "ipv6", 30 | "linux", 31 | "native_tls13", 32 | "mock_read_routes_bsd", 33 | "open_ssl_client", 34 | "osx", 35 | "require_gui", 36 | "tap", 37 | "tun", 38 | "vcan_socket", 39 | "zstd" 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /test/configs/windows2.utsc: -------------------------------------------------------------------------------- 1 | { 2 | "testfiles": [ 3 | "*.uts", 4 | "scapy\\layers\\*.uts", 5 | "scapy\\layers\\tls\\*.uts", 6 | "contrib\\automotive\\obd\\*.uts", 7 | "contrib\\automotive\\gm\\*.uts", 8 | "contrib\\automotive\\bmw\\*.uts", 9 | "contrib\\automotive\\*.uts", 10 | "contrib\\automotive\\autosar\\*.uts", 11 | "contrib\\*.uts" 12 | ], 13 | "remove_testfiles": [ 14 | "bpf.uts", 15 | "linux.uts" 16 | ], 17 | "breakfailed": true, 18 | "onlyfailed": true, 19 | "preexec": { 20 | "contrib\\*.uts": "load_contrib(\"%name%\")", 21 | "scapy\\layers\\tls\\*.uts": "load_layer(\"tls\")" 22 | }, 23 | "format": "html", 24 | "kw_ko": [ 25 | "osx", 26 | "linux", 27 | "broken_windows", 28 | "crypto_advanced", 29 | "mock_read_routes_bsd", 30 | "ci_only", 31 | "open_ssl_client", 32 | "vcan_socket", 33 | "ipv6", 34 | "manufdb", 35 | "tcpdump", 36 | "tap", 37 | "tun", 38 | "tshark" 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /test/contrib/aoe.uts: -------------------------------------------------------------------------------- 1 | % Regression tests for aoe module 2 | ############ 3 | ############ 4 | + Basic tests 5 | 6 | = Build - Check Ethertype 7 | 8 | a = Ether(src="00:01:02:03:04:05") 9 | b = AOE() 10 | c = a / b 11 | assert c[Ether].type == 0x88a2 12 | 13 | = Build - Check default 14 | 15 | p = AOE() 16 | assert hasattr(p, "q_conf_info") 17 | 18 | = Build - Check Issue ATA command 19 | 20 | p = AOE() 21 | p.cmd = 0 22 | 23 | assert hasattr(p, "i_ata_cmd") 24 | 25 | = Build - Check Query Config Information 26 | 27 | p = AOE() 28 | p.cmd = 1 29 | 30 | assert hasattr(p, "q_conf_info") 31 | 32 | = Build - Check Mac Mask List 33 | 34 | p = AOE() 35 | p.cmd = 2 36 | 37 | assert hasattr(p, "mac_m_list") 38 | 39 | = Build - Check ReserveRelease 40 | 41 | p = AOE() 42 | p.cmd = 3 43 | 44 | assert hasattr(p, "res_rel") 45 | -------------------------------------------------------------------------------- /test/contrib/automotive/scanner/graph.uts: -------------------------------------------------------------------------------- 1 | % Regression tests for graph 2 | 3 | + Load general modules 4 | 5 | = Load contribution layer 6 | 7 | from scapy.contrib.automotive.scanner.graph import * 8 | import pickle 9 | import io 10 | 11 | + Graph tests 12 | 13 | = Basic test 14 | 15 | g = Graph() 16 | g.add_edge(("1", "1")) 17 | g.add_edge(("1", "2")) 18 | g.add_edge(("2", "3")) 19 | g.add_edge(("3", "4")) 20 | g.add_edge(("4", "4")) 21 | 22 | assert "1" in g.nodes 23 | assert "2" in g.nodes 24 | assert "3" in g.nodes 25 | assert "4" in g.nodes 26 | assert len(g.nodes) == 4 27 | assert g.dijkstra(g, "1", "4") == ["1", "2", "3", "4"] 28 | 29 | = Shortest path test 30 | 31 | g = Graph() 32 | g.add_edge(("1", "1")) 33 | g.add_edge(("1", "2")) 34 | g.add_edge(("2", "3")) 35 | g.add_edge(("3", "4")) 36 | g.add_edge(("4", "4")) 37 | 38 | assert g.dijkstra(g, "1", "4") == ["1", "2", "3", "4"] 39 | 40 | g.add_edge(("1", "4")) 41 | 42 | assert g.dijkstra(g, "1", "4") == ["1", "4"] 43 | 44 | g.add_edge(("3", "5")) 45 | g.add_edge(("5", "6")) 46 | 47 | print(g.dijkstra(g, "1", "6")) 48 | 49 | assert g.dijkstra(g, "1", "6") == ["1", "2", "3", "5", "6"] or \ 50 | g.dijkstra(g, "1", "6") == ['1', '4', '3', '5', '6'] 51 | 52 | g.add_edge(("2", "5")) 53 | 54 | print(g.dijkstra(g, "1", "6")) 55 | 56 | assert g.dijkstra(g, "1", "6") == ["1", "2", "5", "6"] 57 | 58 | = graph add transition function 59 | 60 | g.add_edge(("4", "6"), transition_function=(str, str)) 61 | 62 | assert g.dijkstra(g, "1", "6") == ["1", "4", "6"] 63 | 64 | = graph pickle 65 | 66 | f = io.BytesIO() 67 | 68 | pickle.dump(g, f) 69 | unp = pickle.loads(f.getvalue()) 70 | 71 | assert unp.dijkstra(g, "1", "6") == ["1", "4", "6"] 72 | 73 | f1, f2 = unp.get_transition_tuple_for_edge(("4", "6")) 74 | assert f1==f2 75 | assert "1" == f1(1) 76 | -------------------------------------------------------------------------------- /test/contrib/avs.uts: -------------------------------------------------------------------------------- 1 | % Regression tests for the avs module 2 | 3 | + Basic AVS test 4 | 5 | = Default build, storage and dissection 6 | 7 | pkt = AVSWLANHeader()/Dot11()/Dot11Auth() 8 | _filepath = get_temp_file(autoext=".pcap") 9 | wrpcap(_filepath, pkt) 10 | pkt1 = rdpcap(_filepath)[0] 11 | assert raw(pkt) == raw(pkt1) 12 | assert AVSWLANHeader in pkt 13 | assert Dot11 in pkt 14 | assert Dot11Auth in pkt 15 | 16 | try: 17 | os.remove(_filepath) 18 | except Exception: 19 | pass 20 | -------------------------------------------------------------------------------- /test/contrib/bier.uts: -------------------------------------------------------------------------------- 1 | # BIER unit tests 2 | # 3 | # Type the following command to launch start the tests: 4 | # $ test/run_tests -P "load_contrib('bier')" -P "load_contrib('mpls')" -t test/contrib/bier.uts 5 | 6 | + BIER tests 7 | 8 | = BIER - build/dissection 9 | 10 | from scapy.contrib.mpls import MPLS 11 | 12 | p1 = MPLS()/BIER(length=BIERLength.BIER_LEN_256)/IP()/UDP() 13 | assert p1[MPLS].s == 1 14 | p2 = BIFT()/BIER(length=BIERLength.BIER_LEN_64)/IP()/UDP() 15 | assert p2[BIFT].s == 1 16 | 17 | p1[MPLS] 18 | p1[BIER] 19 | p1[IP] 20 | p2[BIFT] 21 | p2[BIER] 22 | p2[IP] 23 | -------------------------------------------------------------------------------- /test/contrib/bp.uts: -------------------------------------------------------------------------------- 1 | % Bundle Protocol tests 2 | 3 | ############ 4 | ############ 5 | + Bundle Protocol (BP) basic tests 6 | 7 | #TODO: no pcap have been found on Internet. Check that scapy correctly decode those too 8 | 9 | = Build packets & dissect 10 | 11 | from scapy.contrib.ltp import LTPex 12 | 13 | pkt = Ether(src="aa:aa:aa:aa:aa:aa", dst="bb:bb:bb:bb:bb:bb")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP()/LTP(flags=7,\ 14 | SessionOriginator=2, 15 | SessionNumber=113, 16 | HeaderExtensions=[ 17 | LTPex(ExTag=1, ExData=b"\x00"), 18 | ], 19 | DATA_ClientServiceID=1, 20 | DATA_PayloadOffset=0, 21 | LTP_Payload=[ 22 | BP(ProcFlags=415)/\ 23 | BPBLOCK(ProcFlags=10, load="data") 24 | ]) 25 | 26 | pkt = Ether(raw(pkt)) 27 | assert LTP in pkt 28 | bp = pkt[LTP].LTP_Payload[0] 29 | assert BP in bp 30 | assert BPBLOCK in bp 31 | assert bp.load == b"data" 32 | 33 | bp.mysummary() 34 | -------------------------------------------------------------------------------- /test/contrib/carp.uts: -------------------------------------------------------------------------------- 1 | % Regression tests for the avs module 2 | 3 | + Basic CARP test 4 | 5 | = Build 6 | 7 | pkt = Ether()/IP()/CARP() 8 | pkt = Ether(raw(pkt)) 9 | assert CARP in pkt 10 | assert pkt[CARP].chksum 11 | assert pkt[CARP].build_hmac_sha1(ip4l=['192.168.0.111']) == b'\xbd\x82\xc7\x8f6\x1a\x0e\xff\xcfl\x14\xa2v\xedW;>ic\xa3' 12 | -------------------------------------------------------------------------------- /test/contrib/chdlc.uts: -------------------------------------------------------------------------------- 1 | % Regression tests for the avs module 2 | 3 | + Basic AVS test 4 | 5 | = Default build, storage and dissection 6 | 7 | pkt = CHDLC()/SLARP() 8 | _filepath = get_temp_file(autoext=".pcap") 9 | wrpcap(_filepath, pkt) 10 | pkt1 = rdpcap(_filepath)[0] 11 | assert raw(pkt) == raw(pkt1) 12 | assert CHDLC in pkt 13 | assert SLARP in pkt 14 | 15 | try: 16 | os.remove(_filepath) 17 | except Exception: 18 | pass 19 | 20 | = Build request 21 | 22 | pkt = CHDLC()/SLARP(type=0, address="192.168.0.131", mask="255.255.0.0") 23 | pkt = CHDLC(raw(pkt)) 24 | assert pkt[SLARP].address == "192.168.0.131" 25 | 26 | = Build keepalive 27 | 28 | pkt = CHDLC()/SLARP(type=2, mysequence=123, yoursequence=123456789, reliability=555) 29 | pkt = CHDLC(raw(pkt)) 30 | assert pkt[SLARP].yoursequence == 123456789 31 | -------------------------------------------------------------------------------- /test/contrib/concox.uts: -------------------------------------------------------------------------------- 1 | # Concox CRX1 unit tests 2 | # 3 | # Type the following command to launch start the tests: 4 | # $ test/run_tests -P "load_contrib('concox')" -t test/contrib/concox.uts 5 | 6 | + Concox CRX1 7 | 8 | = Basic tests 9 | 10 | r = raw(CRX1New(default_packet_length=5, default_packet_content=CRX1NewPacketContent())) 11 | assert r == b'xx\x05\x12\x00\x00\x00\x00\r\n' 12 | c = CRX1New(r) 13 | assert CRX1NewPacketContent in c 14 | 15 | r = raw(CRX1New(start_bit=0x7979, extended_packet_length=5, extended_packet_content=CRX1NewPacketContent())) 16 | assert r == b'yy\x00\x05\x12\x00\x00\x00\x00\r\n' 17 | c = CRX1New(r) 18 | assert CRX1NewPacketContent in c 19 | 20 | p = CRX1NewPacketContent(b'\x01\x41\x42\x43\x44\x45\x46\x47\x48\x02\x03\x04\x05') 21 | assert p.terminal_id == b'4142434445464748' 22 | 23 | p = CRX1NewPacketContent(b'\x12\x41\x42\x43\x44\x45\x46\x47\x48\x02\x03\x04\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04') 24 | assert p.crc == 0x304 and p.latitude 25 | -------------------------------------------------------------------------------- /test/contrib/dtp.uts: -------------------------------------------------------------------------------- 1 | + DTP Contrib tests 2 | 3 | = Basic DTP build 4 | 5 | pkt = DTP(tlvlist=[DTPNeighbor(neighbor='00:11:22:33:44:55'), DTPDomain(domain=b"\x01\x02\x03")]) 6 | assert raw(pkt) == b'\x01\x00\x04\x00\n\x00\x11"3DU\x00\x01\x00\x07\x01\x02\x03' 7 | 8 | = Basic DTP dissection 9 | 10 | pkt = Ether(b'\x01\x00\x0c\xcc\xcc\xcc\xd0P\x99V\xdd\xf9\x00"\xaa\xaa\x03\x00\x00\x0c \x04\x01\x00\x03\x00\x05\xa5\x00\x04\x00\n\xaa\xbb\xcc\xdd\xee\xff\x00\x01\x00\x05\x00\x00\x02\x00\x05\x03') 11 | assert DTP in pkt 12 | assert pkt[DTP].tlvlist[0].dtptype == b'\xa5' 13 | assert pkt[DTP].tlvlist[1].neighbor == 'aa:bb:cc:dd:ee:ff' 14 | assert pkt[DTP].tlvlist[2].domain == b'\x00' 15 | assert pkt[DTP].tlvlist[3].status == b'\x03' 16 | 17 | = Test negotiate_trunk 18 | 19 | from unittest import mock 20 | 21 | def test_pkt(pkt): 22 | pkt = Ether(raw(pkt)) 23 | assert DTP in pkt 24 | assert len(pkt[DTP].tlvlist) == 4 25 | print("Succeed") 26 | 27 | @mock.patch("scapy.contrib.dtp.sendp", side_effect=test_pkt) 28 | def _test_negotiate_trunk(m): 29 | negotiate_trunk() 30 | 31 | _test_negotiate_trunk() 32 | -------------------------------------------------------------------------------- /test/contrib/eddystone.uts: -------------------------------------------------------------------------------- 1 | # Eddystone unit tests 2 | # 3 | # Type the following command to launch start the tests: 4 | # $ test/run_tests -P "load_contrib('eddystone')" -t test/contrib/eddystone.uts 5 | 6 | + Eddystone tests 7 | 8 | = Setup 9 | 10 | def expect_exception(e, c): 11 | try: 12 | c() 13 | return False 14 | except e: 15 | return True 16 | 17 | = Eddystone URL (decode EIR) 18 | 19 | d = hex_bytes('0c16aafe10040373636170790a') 20 | p = EIR_Hdr(d) 21 | p.show() 22 | 23 | assert p[EIR_ServiceData16BitUUID].svc_uuid == 0xfeaa 24 | assert p[Eddystone_URL].to_url() == b'https://scapy.net' 25 | 26 | = Eddystone URL (decode LE Set Advertising Data) 27 | 28 | d = hex_bytes('01082020140201020303aafe0c16aafe10040373636170790a0000000000000000000000') 29 | p = HCI_Hdr(d) 30 | 31 | assert p[EIR_ServiceData16BitUUID].svc_uuid == 0xfeaa 32 | assert p[Eddystone_URL].to_url() == b'https://scapy.net' 33 | 34 | = Eddystone URL (encode frames) 35 | 36 | d = raw(Eddystone_URL.from_url('https://scapy.net')) 37 | assert d == hex_bytes('10000373636170790a') 38 | 39 | d = raw(Eddystone_URL.from_url('https://www.scapy.net')) 40 | assert d == hex_bytes('10000173636170790a') 41 | 42 | # Include some other .extensions in the path 43 | d = raw(Eddystone_URL.from_url('http://www.example.com/hello.info.html')) 44 | assert d == hex_bytes('1000006578616d706c650068656c6c6f0b2e68746d6c') 45 | 46 | = Eddystone URL (encode unsupported scheme) 47 | 48 | assert expect_exception(Exception, lambda: Eddystone_URL.from_url('gopher://example.com')) 49 | 50 | = Eddystone URL (encode advertising report) 51 | 52 | p = Eddystone_URL.from_url('https://scapy.net').build_advertising_report() 53 | assert raw(p[EIR_ServiceData16BitUUID]) == hex_bytes('aafe10000373636170790a') 54 | 55 | -------------------------------------------------------------------------------- /test/contrib/erspan.uts: -------------------------------------------------------------------------------- 1 | % ERSPAN 2 | 3 | + ERSPAN I 4 | = Build & dissect ERSPAN 1 5 | 6 | pkt = GRE()/ERSPAN_I()/Ether() 7 | pkt = GRE(bytes(pkt)) 8 | assert ERSPAN in pkt 9 | assert pkt.proto == 0x88be 10 | assert pkt.seqnum_present == 0 11 | 12 | + ERSPAN II 13 | = Build ERSPAN II 14 | 15 | pkt = GRE()/ERSPAN_II()/Ether(src="11:11:11:11:11:11", dst="ff:ff:ff:ff:ff:ff") 16 | b = bytes(pkt) 17 | assert b == b'\x10\x00\x88\xbe\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\x11\x11\x11\x11\x11\x11\x90\x00' 18 | 19 | = Dissect ERSPAN II 20 | 21 | pkt = GRE(b) 22 | assert pkt[GRE].proto == 0x88be 23 | assert pkt[GRE].seqnum_present == 1 24 | assert pkt[GRE][ERSPAN].ver == 1 25 | assert pkt[Ether].src == "11:11:11:11:11:11" 26 | 27 | + ERSPAN III 28 | = Build & dissect ERSPAN III with platform specific 29 | 30 | pkt = GRE()/ERSPAN_III()/ERSPAN_PlatformSpecific()/Ether() 31 | pkt = GRE(bytes(pkt)) 32 | assert pkt[GRE].proto == 0x22eb 33 | assert pkt[ERSPAN_III].o == 1 34 | assert ERSPAN_PlatformSpecific in pkt 35 | assert Ether in pkt 36 | 37 | = Build & dissect ERSPAN III without platform specific 38 | pkt = GRE()/ERSPAN_III()/Ether() 39 | pkt = GRE(bytes(pkt)) 40 | assert pkt[GRE].proto == 0x22eb 41 | assert pkt[ERSPAN_III].o == 0 42 | assert ERSPAN_PlatformSpecific not in pkt 43 | assert Ether in pkt 44 | 45 | -------------------------------------------------------------------------------- /test/contrib/esmc.uts: -------------------------------------------------------------------------------- 1 | % ESMC unit tests 2 | # 3 | # Type the following command to launch start the tests: 4 | # $ test/run_tests -P "load_contrib('esmc')" -t test/contrib/esmc.uts 5 | 6 | + ESMC 7 | 8 | = Build & dissect ESMC and QLTLV 9 | 10 | pkt = Ether(src="00:13:c4:12:0f:0d") / SlowProtocol() / ESMC(event=1) / QLTLV(ssmCode=0x2) 11 | pkt.show() 12 | s = raw(pkt) 13 | raw_pkt = b'\x01\x80\xc2\x00\x00\x02\x00\x13\xc4\x12\x0f\x0d\x88\x09\x0a\x00\x19\xa7\x00' \ 14 | b'\x01\x18\x00\x00\x00\x01\x00\x04\x02' 15 | assert s == raw_pkt 16 | 17 | p = Ether(s) 18 | assert SlowProtocol in p and ESMC in p and QLTLV in p 19 | assert raw(p) == raw_pkt 20 | 21 | = Build & dissect ESMC and EQLTLV 22 | 23 | pkt = pkt / EQLTLV(clockIdentity=b'\x11\x22\x33\x44\x55\x66\x77\x88') 24 | pkt.show() 25 | s = raw(pkt) 26 | raw_pkt = b'\x01\x80\xc2\x00\x00\x02\x00\x13\xc4\x12\x0f\x0d\x88\x09\x0a\x00\x19\xa7\x00' \ 27 | b'\x01\x18\x00\x00\x00\x01\x00\x04\x02\x02\x00\x14\xff\x11\x22\x33\x44\x55\x66' \ 28 | b'\x77\x88\x00\x01\x00\x00\x00\x00\x00\x00' 29 | assert s == raw_pkt 30 | 31 | p = Ether(s) 32 | assert SlowProtocol in p and ESMC in p and QLTLV in p and EQLTLV in p 33 | assert raw(p) == raw_pkt 34 | -------------------------------------------------------------------------------- /test/contrib/etherip.uts: -------------------------------------------------------------------------------- 1 | + EtherIP Contrib tests 2 | 3 | = Basic EtherIP test 4 | 5 | pkt = Ether(b'\x99\xc1o\xd2\xf5c\x9d\xb7\xd0\xc2\xe0\xd3\x08\x00E\x00\x00@\x00\x01\x00\x00@a,\xf3B\x83\x17\xc6\xad\xc2E^0\x00\xd5/\xf26\xab\xe2\x9f\xb4tD\xa4\x98\x08\x00E\x00\x00\x1c\x00\x01\x00\x00@\x01W-\xe7\x98H\xfa\xad\xc2E^\x08\x00\xf7\xff\x00\x00\x00\x00') 6 | assert ICMP in pkt 7 | assert EtherIP in pkt 8 | -------------------------------------------------------------------------------- /test/contrib/exposure_notification.uts: -------------------------------------------------------------------------------- 1 | % Exposure Notification System tests 2 | # 3 | # Type the following command to launch start the tests: 4 | # $ test/run_tests -P "load_contrib('exposure_notification')" -t test/contrib/exposure_notification.uts 5 | 6 | + ENS tests 7 | 8 | = Setup 9 | 10 | def next_eir(p): 11 | return EIR_Hdr(p[Padding].load) 12 | 13 | = Presence check 14 | 15 | Exposure_Notification_Frame 16 | 17 | = Raw payload copied from BluetoothExplorer.app 18 | 19 | d = hex_bytes('17df1d67405e3395470e62ca4fda6a9303687b31') 20 | p = Exposure_Notification_Frame(d) 21 | 22 | assert p.identifier == hex_bytes('17df1d67405e3395470e62ca4fda6a93') 23 | assert p.metadata == hex_bytes('03687b31') 24 | 25 | = Raw captured payload 26 | 27 | d = hex_bytes('02011a03036ffd17166ffde23f352fa09307a85d4194912443180d484dc151') 28 | p = EIR_Hdr(d) 29 | 30 | # First is a flags header 31 | assert EIR_Flags in p 32 | 33 | # Then the 16-bit Service Class ID 34 | p = next_eir(p) 35 | assert p[EIR_CompleteList16BitServiceUUIDs].svc_uuids == [ 36 | EXPOSURE_NOTIFICATION_UUID] 37 | 38 | # Then the ENS 39 | p = next_eir(p) 40 | assert p[EIR_ServiceData16BitUUID].svc_uuid == EXPOSURE_NOTIFICATION_UUID 41 | assert p[Exposure_Notification_Frame].identifier == hex_bytes( 42 | 'e23f352fa09307a85d4194912443180d') 43 | assert p[Exposure_Notification_Frame].metadata == hex_bytes('484dc151') 44 | 45 | # Rebuild the payload. 46 | p2 = p[Exposure_Notification_Frame].build_eir() 47 | 48 | # Our captured payload was from a mobile phone, but build_eir presumes that 49 | # we're broadcasting as an non-connectable, LE-only beacon. We need to adjust 50 | # these flags to match the captured packet. 51 | p2[0] = EIR_Hdr() / EIR_Flags(flags=[ 52 | 'general_disc_mode', 'simul_le_br_edr_ctrl', 'simul_le_br_edr_host']) 53 | 54 | # Ensure we didn't mutate LowEnergyBeaconHelper.base_eir just then. 55 | assert LowEnergyBeaconHelper.base_eir[0][EIR_Flags].flags == [ 56 | 'general_disc_mode', 'br_edr_not_supported'] 57 | 58 | # Assemble all packet bytes 59 | assert b''.join(map(raw, p2)) == d 60 | -------------------------------------------------------------------------------- /test/contrib/homeplugsg.uts: -------------------------------------------------------------------------------- 1 | % Regression tests for Scapy 2 | 3 | +Syntax check 4 | = Import the homepluggq layer 5 | 6 | from scapy.contrib.homeplugsg import * 7 | import binascii 8 | #from scapy.all import 9 | 10 | # HomePlugSG 11 | 12 | ############ 13 | ############ 14 | + Basic tests 15 | 16 | * Those test are here mainly to check nothing has been broken 17 | 18 | = Some important manipulations 19 | ~ field 20 | pkt=HomePlugAV(version=0x01)/VS_UART_CMD_REQ() 21 | pkt.UData = "AT+LOG?" 22 | assert raw(pkt) == b'\x01\x00\xa4\x00\x00\x00\x01AT+LOG?' 23 | -------------------------------------------------------------------------------- /test/contrib/ife.uts: -------------------------------------------------------------------------------- 1 | % IFE test campaign 2 | 3 | # 4 | # execute test: 5 | # > test/run_tests -P "load_contrib('ife')" -t test/contrib/ife.uts 6 | # 7 | 8 | + Basic layer handling 9 | = build basic IFE frames 10 | 11 | frm = Ether()/IFE(tlvs=[IFESKBMark(value=3), IFETCIndex(value=5)]) 12 | 13 | frm = Ether(bytes(frm)) 14 | 15 | assert IFE in frm 16 | assert frm[IFE].tlvs[0].type == 1 17 | assert frm[IFE].tlvs[0].length == 8 18 | assert frm[IFE].tlvs[0].value == 3 19 | assert frm[IFE].tlvs[1].type == 5 20 | assert frm[IFE].tlvs[1].length == 6 21 | assert frm[IFE].tlvs[1].value == 5 22 | 23 | = add padding if required 24 | 25 | frm = Ether()/IFE(tlvs=[IFETCIndex()]) 26 | assert len(raw(frm)) == 24 27 | 28 | frm = Ether()/IFE(tlvs=[IFESKBMark(), IFETCIndex()]) 29 | assert len(raw(frm)) == 32 30 | 31 | = variable payload 32 | 33 | frm = Ether(src="aa:aa:aa:aa:aa:aa", dst="bb:bb:bb:bb:bb:bb")/IFE(tlvs=[IFETlvStr(b"testsr")]) 34 | assert bytes(frm) == b'\xbb\xbb\xbb\xbb\xbb\xbb\xaa\xaa\xaa\xaa\xaa\xaa\xed>\x00\x08testsr' 35 | -------------------------------------------------------------------------------- /test/contrib/igmp.uts: -------------------------------------------------------------------------------- 1 | ############ 2 | % IGMP tests 3 | ############ 4 | 5 | + Basic IGMP tests 6 | 7 | = Build IGMP - Basic 8 | 9 | a=Ether(src="00:01:02:03:04:05") 10 | b=IP(src="1.2.3.4") 11 | c=IGMP(gaddr="0.0.0.0") 12 | x = a/b/c 13 | x[IGMP].igmpize() 14 | assert x.mrcode == 20 15 | assert x[IP].dst == "224.0.0.1" 16 | 17 | = Build IGMP - Custom membership 18 | 19 | a=Ether(src="00:01:02:03:04:05") 20 | b=IP(src="1.2.3.4") 21 | c=IGMP(gaddr="224.0.1.2") 22 | x = a/b/c 23 | x[IGMP].igmpize() 24 | assert x.mrcode == 20 25 | assert x[IP].dst == "224.0.1.2" 26 | 27 | = Build IGMP - LG 28 | 29 | a=Ether(src="00:01:02:03:04:05") 30 | b=IP(src="1.2.3.4") 31 | c=IGMP(type=0x17, gaddr="224.2.3.4") 32 | x = a/b/c 33 | x[IGMP].igmpize() 34 | assert x.dst == "01:00:5e:00:00:02" 35 | assert x.mrcode == 0 36 | assert x[IP].dst == "224.0.0.2" 37 | 38 | = Change IGMP params 39 | 40 | x = Ether(src="00:01:02:03:04:05")/IP()/IGMP() 41 | x[IGMP].igmpize() 42 | assert x.mrcode == 20 43 | assert x[IP].dst == "224.0.0.1" 44 | 45 | x = Ether(src="00:01:02:03:04:05")/IP()/IGMP(gaddr="224.2.3.4", type=0x12) 46 | x.mrcode = 1 47 | x[IGMP].igmpize() 48 | x = Ether(raw(x)) 49 | assert x.mrcode == 0 50 | 51 | x.gaddr = "224.3.2.4" 52 | x[IGMP].igmpize() 53 | assert x.dst == "01:00:5e:03:02:04" 54 | 55 | x.ttl = 64 56 | x[IGMP].igmpize() 57 | assert x.ttl == 1 58 | 59 | = Test mysummary 60 | 61 | x = Ether(src="00:01:02:03:04:05")/IP(src="192.168.0.1")/IGMP(gaddr="224.0.0.2", type=0x17) 62 | x[IGMP].igmpize() 63 | assert x[IGMP].mysummary() == "IGMP: 192.168.0.1 > 224.0.0.2 Leave Group 224.0.0.2" 64 | 65 | assert IGMP().mysummary() == "IGMP Group Membership Query 0.0.0.0" 66 | 67 | = IGMP - misc 68 | ~ netaccess 69 | 70 | x = Ether(src="00:01:02:03:04:05")/IP(dst="192.168.0.1")/IGMP(gaddr="www.google.fr", type=0x11) 71 | x = Ether(raw(x)) 72 | assert not x[IGMP].igmpize() 73 | assert x[IP].dst == "192.168.0.1" 74 | 75 | x = Ether(src="00:01:02:03:04:05")/IP(dst="192.168.0.1")/IGMP(gaddr="124.0.2.1", type=0x00) 76 | assert not x[IGMP].igmpize() 77 | assert x[IP].dst == "192.168.0.1" -------------------------------------------------------------------------------- /test/contrib/lacp.uts: -------------------------------------------------------------------------------- 1 | % LACP unit tests 2 | # 3 | # Type the following command to launch start the tests: 4 | # $ test/run_tests -P "load_contrib('lacp')" -t test/contrib/lacp.uts 5 | 6 | + LACP 7 | 8 | = Build & dissect LACP 9 | 10 | # 1 0.000000 CiscoInc_12:0f:0d Slow-Protocols LACP 124 Link Aggregation Control ProtocolVersion 1. Actor Port = 22 Partner Port = 25 11 | params = dict( 12 | actor_system_priority=32768, 13 | actor_system='00:13:c4:12:0f:00', 14 | actor_key=13, 15 | actor_port_priority=32768, 16 | actor_port_number=22, 17 | actor_state=0x85, 18 | partner_system_priority=32768, 19 | partner_system='00:0e:83:16:f5:00', 20 | partner_key=13, 21 | partner_port_priority=32768, 22 | partner_port_number=25, 23 | partner_state=0x36, 24 | collector_max_delay=32768, 25 | ) 26 | pkt = Ether(src="00:13:c4:12:0f:0d") / SlowProtocol() / LACP(**params) 27 | s = raw(pkt) 28 | raw_pkt = b'\x01\x80\xc2\x00\x00\x02\x00\x13\xc4\x12\x0f\x0d\x88\x09\x01\x01\x01\x14\x80' \ 29 | b'\x00\x00\x13\xc4\x12\x0f\x00\x00\x0d\x80\x00\x00\x16\x85\x00\x00\x00\x02\x14' \ 30 | b'\x80\x00\x00\x0e\x83\x16\xf5\x00\x00\x0d\x80\x00\x00\x19\x36\x00\x00\x00\x03' \ 31 | b'\x10\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \ 32 | b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \ 33 | b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \ 34 | b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' 35 | assert s == raw_pkt 36 | 37 | p = Ether(s) 38 | assert SlowProtocol in p and LACP in p 39 | assert raw(p) == raw_pkt 40 | 41 | = Marker sanity 42 | 43 | pkt = Ether(src="00:13:c4:12:0f:0d") / SlowProtocol() / MarkerProtocol() 44 | pkt.show() 45 | s = raw(pkt) 46 | p = Ether(s) 47 | assert SlowProtocol in p and MarkerProtocol in p 48 | assert raw(p) == s 49 | -------------------------------------------------------------------------------- /test/contrib/loraphy2wan.uts: -------------------------------------------------------------------------------- 1 | % Regression tests for Scapy 2 | 3 | +Syntax check 4 | = Import the loraphy2wan layer 5 | 6 | from scapy.contrib.loraphy2wan import * 7 | from scapy.compat import raw 8 | 9 | # LoRa PHY to WAN 10 | 11 | ############ 12 | ############ 13 | + Basic tests 14 | 15 | * Those test are here mainly to check nothing has been broken 16 | 17 | = Packet decoding 18 | ~ field 19 | 20 | p = b'\x00\x00\x00\x00lovecafemeeetoo\x00iiS\x02LI' 21 | pkt = LoRa(p) 22 | assert pkt.Join_Request_Field[0].DevEUI == b'meeetoo\x00' 23 | assert pkt.Join_Request_Field[0].DevNonce == 26985 24 | 25 | p = b'\x0f0P@\xad\x15\x00`\x80\x06\x00\t\xca\xfe\x0c\x1d\x8d\x04\\\xb5' 26 | pkt = LoRa(p) 27 | assert pkt.MType == 2 28 | assert pkt.DataPayload == b'\xca\xfe' 29 | assert pkt.FCnt == 6 30 | assert pkt.FPort == 9 31 | assert pkt.FCtrl[0].ADR == 1 32 | assert pkt.DevAddr[0].NwkID == 0xad 33 | assert pkt.DevAddr[0].NwkAddr == 0x600015 34 | 35 | p = b'\x0f0P\x80\xad\x15\x00`\x00\x01\x00\t\xca\xfe:\x98\x89|\x8f\xd4' 36 | pkt = LoRa(p) 37 | assert pkt.MType == 4 38 | 39 | = Decoding an encrypted JA packet 40 | 41 | LoRa.encrypted = True 42 | p = b'\x00\x00\x00 \x086\xe2\x87\xa9\x80\\\xb7\xee\x9e_\xff|\x9e\xe9z' 43 | pkt = LoRa(p) 44 | assert pkt.Join_Accept_Encrypted == b'\x086\xe2\x87\xa9\x80\\\xb7\xee\x9e_\xff|\x9e\xe9z' 45 | 46 | = Packet crafting: generating an unencrypted JA frame 47 | 48 | ja = Join_Accept() 49 | ja.JoinAppNonce=0x6fe14a 50 | ja.NetID = 0x10203 51 | ja.DevAddr = 0x68e8cb1 52 | assert raw(ja) == b'J\xe1o\x03\x02\x01\xb1\x8c\x8e\x06\x00\x00' 53 | 54 | = Generating an unencrypted LoRa JA packet 55 | 56 | LoRa.encrypted = False 57 | pkt = LoRa(MType=0b001) 58 | pkt.Join_Accept_Field = [ja] 59 | assert raw(pkt) == b'\x00\x00\x00 J\xe1o\x03\x02\x01\xb1\x8c\x8e\x06\x00\x00\x00\x00\x00\x00' 60 | 61 | = Parsing Piggy back commands 62 | 63 | p = b'\r0\xc0\x80\xad\x15\x00`\x01\x01\x00\x02\xc0\xe3N\xb7\xc7\xae' 64 | pkt = LoRa(p) 65 | assert pkt.FOpts_up[0].CID == 2 66 | -------------------------------------------------------------------------------- /test/contrib/ltp.uts: -------------------------------------------------------------------------------- 1 | % Licklider Transmission Protocol tests 2 | 3 | ############ 4 | ############ 5 | + Licklider Transmission Protocol (LTP) basic tests 6 | 7 | ~ TODO: no pcap have been found on Internet. Check that scapy correctly decode those too 8 | 9 | = Build packets & dissect 10 | 11 | load_contrib("ltp") 12 | pkt = Ether(src="aa:aa:aa:aa:aa:aa", dst="bb:bb:bb:bb:bb:bb")/IP(src="192.168.0.1", dst="192.168.0.2")/UDP()/LTP(flags=8,\ 13 | SessionOriginator=2, 14 | SessionNumber=113, 15 | ReportCheckpointSerialNo=12, 16 | ReportUpperBound=0, 17 | ReportLowerBound=5, 18 | ReportReceptionClaims=[ 19 | LTPReceptionClaim(ReceptionClaimOffset=1, ReceptionClaimLength=4), 20 | LTPReceptionClaim(ReceptionClaimOffset=2, ReceptionClaimLength=3), 21 | ], 22 | HeaderExtensions=[ 23 | LTPex(ExTag=1, ExData=b"\x00"), 24 | ], 25 | TrailerExtensions=[ 26 | LTPex(ExTag=0, ExData=b"\x01"), 27 | LTPex(ExTag=1, ExData=b"\x02"), 28 | ]) 29 | 30 | pkt = Ether(raw(pkt)) 31 | assert LTP in pkt 32 | assert pkt[LTP].ReportLowerBound == 5 33 | assert pkt[LTP].ReportCheckpointSerialNo == 12 34 | assert pkt[LTP].ReportReceptionClaims[0].ReceptionClaimLength == 4 35 | assert pkt[LTP].ReportReceptionClaims[1].ReceptionClaimOffset == 2 36 | assert pkt[LTP].HeaderExtensions[0].ExTag == 1 37 | assert pkt[LTP].HeaderExtensions[0].ExData == b"\x00" 38 | 39 | s = pkt.summary() 40 | s 41 | assert s.replace("ltp_deepspace", "1113") == 'Ether / IP / UDP 192.168.0.1:1113 > 192.168.0.2:1113 / LTP 113' -------------------------------------------------------------------------------- /test/contrib/metawatch.uts: -------------------------------------------------------------------------------- 1 | # Arista Metawatch unit tests 2 | # 3 | # Type the following command to launch start the tests: 4 | # $ test/run_tests -P "load_contrib('metawatch')" -t test/contrib/metawatch.uts 5 | 6 | + Metawatch 7 | 8 | = MetawatchEther, basic instantiation 9 | 10 | m = MetawatchEther() 11 | assert m.type == 0x9000 12 | 13 | = MetawatchEther, build & dissect 14 | 15 | r = raw(MetawatchEther(dst="00:01:02:03:04:05", src="06:07:08:09:10:11")) 16 | assert r == b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\x10\x11\x90\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' 17 | 18 | m = MetawatchEther(r) 19 | assert m.dst == "00:01:02:03:04:05" and m.src == "06:07:08:09:10:11" and m.type == 0x9000 20 | -------------------------------------------------------------------------------- /test/contrib/mount.uts: -------------------------------------------------------------------------------- 1 | % Test mount layer 2 | #################### 3 | #################### 4 | 5 | + Packet Creation Tests 6 | 7 | = Create subpackets 8 | Path() 9 | File_Object() 10 | 11 | = Create Mount Calls 12 | NULL_Call() 13 | MOUNT_Call() 14 | UNMOUNT_Call() 15 | 16 | = Create Successful Mount Replies 17 | MOUNT_Reply(status=0) 18 | 19 | = Create Failed Mount Replies 20 | MOUNT_Reply(status=1) 21 | 22 | + RPC Layer bindings tests 23 | 24 | = Layer Bindings for Mount Calls 25 | from scapy.contrib.oncrpc import * 26 | pkt = RPC()/RPC_Call()/NULL_Call() 27 | assert (pkt.mtype, pkt.program, pkt.pversion, pkt.procedure) == (0, 100005, 3, 0) 28 | pkt = RPC()/RPC_Call()/MOUNT_Call() 29 | assert (pkt.mtype, pkt.program, pkt.pversion, pkt.procedure) == (0, 100005, 3, 1) 30 | pkt = RPC()/RPC_Call()/UNMOUNT_Call() 31 | assert (pkt.mtype, pkt.program, pkt.pversion, pkt.procedure) == (0, 100005, 3, 3) 32 | 33 | = Layer Bindings for Mount Replies 34 | from scapy.contrib.oncrpc import * 35 | pkt = RPC()/RPC_Reply()/NULL_Reply() 36 | assert pkt.mtype == 1 37 | pkt = RPC()/RPC_Reply()/MOUNT_Reply() 38 | assert pkt.mtype == 1 39 | pkt = RPC()/RPC_Reply()/UNMOUNT_Reply() 40 | assert pkt.mtype == 1 41 | 42 | + Test Built Packets vs Raw Strings 43 | 44 | = Mount calls vs Raw strings 45 | pkt = MOUNT_Call( 46 | path=Path( 47 | length=4, 48 | path='path' 49 | ) 50 | ) 51 | assert bytes(pkt) == b'\x00\x00\x00\x04path' 52 | 53 | pkt = UNMOUNT_Call( 54 | path=Path( 55 | length=4, 56 | path='path' 57 | ) 58 | ) 59 | assert bytes(pkt) == b'\x00\x00\x00\x04path' 60 | 61 | = Mount replies vs Raw Strings 62 | pkt = MOUNT_Reply( 63 | status=0, 64 | filehandle=File_Object( 65 | length=4, 66 | fh='file' 67 | ), 68 | flavors=3, 69 | flavor=[ 70 | 0,0,0 71 | ] 72 | ) 73 | assert bytes(pkt) == b'\x00\x00\x00\x00\x00\x00\x00\x04file\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' 74 | -------------------------------------------------------------------------------- /test/contrib/mpls.uts: -------------------------------------------------------------------------------- 1 | # MPLS unit tests 2 | # 3 | # Type the following command to launch start the tests: 4 | # $ test/run_tests -P "load_contrib('mpls')" -t test/contrib/mpls.uts 5 | 6 | + MPLS 7 | 8 | = Build & dissect - IPv4 9 | 10 | s = raw(Ether(src="00:01:02:04:05")/MPLS()/IP()) 11 | assert s == b'\xff\xff\xff\xff\xff\xff\x00\x01\x02\x04\x05\x00\x88G\x00\x00\x01\x00E\x00\x00\x14\x00\x01\x00\x00@\x00|\xe7\x7f\x00\x00\x01\x7f\x00\x00\x01' 12 | 13 | p = Ether(s) 14 | assert MPLS in p and IP in p 15 | 16 | 17 | = Build & dissect - IPv6 18 | s = raw(Ether(src="00:01:02:04:05")/MPLS(s=0)/MPLS()/IPv6()) 19 | assert s == b'\xff\xff\xff\xff\xff\xff\x00\x01\x02\x04\x05\x00\x88G\x00\x000\x00\x00\x00!\x00`\x00\x00\x00\x00\x00;@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01' 20 | 21 | p = Ether(s) 22 | assert IPv6 in p and isinstance(p[MPLS].payload, MPLS) 23 | 24 | = Association on IP and IPv6 25 | p = IP()/MPLS() 26 | p = IP(raw(p)) 27 | assert p[IP].proto == 137 28 | 29 | p2 = IPv6()/MPLS() 30 | p2 = IPv6(raw(p2)) 31 | assert p2[IPv6].nh == 137 32 | -------------------------------------------------------------------------------- /test/contrib/portmap.uts: -------------------------------------------------------------------------------- 1 | % Tests for portmap module 2 | ############ 3 | ############ 4 | + Packet Creation Tests 5 | 6 | = Create subpackets 7 | Map_Entry() 8 | 9 | = Create Portmap Packets 10 | NULL_Call() 11 | NULL_Reply() 12 | DUMP_Call() 13 | DUMP_Reply() 14 | GETPORT_Call() 15 | GETPORT_Reply() 16 | 17 | + Test Layer bindings 18 | 19 | = RPC Layer Bindings for Portmap calls 20 | from scapy.contrib.oncrpc import * 21 | pkt = RPC()/RPC_Call()/NULL_Call() 22 | assert (pkt.mtype, pkt.program, pkt.pversion, pkt.procedure) == (0, 100000, 2, 0) 23 | pkt = RPC()/RPC_Call()/GETPORT_Call() 24 | assert (pkt.mtype, pkt.program, pkt.pversion, pkt.procedure) == (0, 100000, 2, 3) 25 | pkt = RPC()/RPC_Call()/DUMP_Call() 26 | assert (pkt.mtype, pkt.program, pkt.pversion, pkt.procedure) == (0, 100000, 2, 4) 27 | 28 | = RPC Layer Bindings for Portmap replies 29 | from scapy.contrib.oncrpc import * 30 | pkt = RPC()/RPC_Reply()/NULL_Reply() 31 | assert pkt.mtype == 1 32 | pkt = RPC()/RPC_Reply()/GETPORT_Reply() 33 | assert pkt.mtype == 1 34 | pkt = RPC()/RPC_Reply()/DUMP_Reply() 35 | assert pkt.mtype == 1 36 | 37 | + Test Built Packets vs Raw Strings 38 | 39 | = Portmap calls vs Raw Strings 40 | pkt = GETPORT_Call( 41 | prog=100003, 42 | vers=3, 43 | prot=6, 44 | port=0 45 | ) 46 | assert bytes(pkt) == b'\x00\x01\x86\xa3\x00\x00\x00\x03\x00\x00\x00\x06\x00\x00\x00\x00' 47 | 48 | = Portmap replies vs Raw Strings 49 | pkt = GETPORT_Reply( 50 | port=2049 51 | ) 52 | assert bytes(pkt) == b'\x00\x00\x08\x01' 53 | 54 | pkt = DUMP_Reply(value_follows=1, 55 | mappings=[Map_Entry(prog=1, vers=2, prot=3, port=4, value_follows=1), 56 | Map_Entry(prog=5, vers=6, prot=7, port=8, value_follows=0), 57 | ] 58 | ) 59 | assert bytes(pkt) == b'\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x00' 60 | -------------------------------------------------------------------------------- /test/contrib/ppi_geotag.uts: -------------------------------------------------------------------------------- 1 | # PPI_Geotag tests 2 | 3 | ############ 4 | ############ 5 | + PPI Geotags tests 6 | 7 | = Import PPI Geotag 8 | 9 | from scapy.contrib.ppi_geotag import * 10 | 11 | = Test GPS dissection 12 | 13 | assert raw(PPI_Hdr()/PPI_Geotag_GPS()) == b'2u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00' 14 | 15 | = Test Vector dissection 16 | 17 | assert raw(PPI_Hdr()/PPI_Geotag_Vector()) == b'3u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00' 18 | 19 | = Test Sensor dissection 20 | 21 | assert raw(PPI_Hdr()/PPI_Geotag_Sensor()) == b'4u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00' 22 | 23 | = Test Antenna dissection 24 | 25 | assert raw(PPI_Hdr()/PPI_Geotag_Antenna()) == b'5u\x08\x00\x02\x00\x08\x00\x00\x00\x00\x00' 26 | 27 | = Test GPSTime_Field time handling 28 | 29 | assert GPSTime_Field("GPSTime", None).delta == 0.0 30 | 31 | -------------------------------------------------------------------------------- /test/contrib/ripng.uts: -------------------------------------------------------------------------------- 1 | + RIPng Contrib tests 2 | 3 | = Basic RIPng build 4 | 5 | pkt = Ether()/IP()/UDP()/RIPng()/RIPngEntry(prefix_or_nh='8c07:9bc5:fdf6:996:117e:08c0:dd84:549e', metric=255)/RIPngEntry(prefix_or_nh='afb6:5b1b:c518:a147:312a:0c32:f40c:3771') 6 | pkt = Ether(raw(pkt)) 7 | assert RIPngEntry in pkt 8 | assert pkt[RIPngEntry].prefix_or_nh == '8c07:9bc5:fdf6:996:117e:8c0:dd84:549e' 9 | assert pkt[RIPngEntry].payload.prefix_or_nh == 'afb6:5b1b:c518:a147:312a:c32:f40c:3771' 10 | -------------------------------------------------------------------------------- /test/contrib/rsvp.uts: -------------------------------------------------------------------------------- 1 | % Regression tests for the rsvp module 2 | 3 | + Basic RSVP test 4 | 5 | = Default build 6 | 7 | pkt = Ether()/IP()/RSVP()/RSVP_Object()/RSVP_SessionAttrb(Name="test") 8 | pkt = Ether(raw(pkt)) 9 | assert RSVP_SessionAttrb in pkt 10 | assert pkt.Name == b"test" 11 | 12 | = Master dissection 13 | 14 | pkt = Ether(b"\x00\x90\x92\x9d\x94\x01\x00\xd0c\xc3\xb8G\x08\x00E\x00\x00\x80\x8ad\x00\x00\xff.\x8c\xe7\xd2\x00\x00\x02\xd2\x00\x00\x01\x10\x02\xeb\xfa\xff\x00\x00l\x00\x10\x01\x07\x10\x02\x02\x02\x00\x00\x00\x01\x11\x03\x03\x03\x00\x0c\x03\x01\xd2\x00\x00\x02\x00\x00\x00\x00\x00\x08\x05\x01\x00\x00u0\x00\x08\x08\x01\x00\x00\x00\x12\x00$\t\x02\x00\x00\x00\x07\x05\x00\x00\x06\x7f\x00\x00\x05I\x18\x96\x80Dz\x00\x00\x7f\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0c\n\x07\x11\x03\x03\x03\x00\x00'\x11\x00\x08\x10\x01\x00\x00\x00\x10\x03\x06-\xad") 15 | assert RSVP_Time in pkt 16 | assert pkt[RSVP_Time].refresh == 30000 17 | -------------------------------------------------------------------------------- /test/contrib/sdnv.uts: -------------------------------------------------------------------------------- 1 | % SDNV library tests 2 | 3 | ############ 4 | ############ 5 | + Test SDNV encoding/decoding 6 | 7 | = Load SDNVUtil 8 | 9 | # Explicit to load SDNVUtil 10 | load_contrib("sdnv") 11 | 12 | = Define utils 13 | 14 | def doTestVector(vec): 15 | # Test numbers individually 16 | for n in vec: 17 | ba = SDNVUtil.encode(n) 18 | (num, sdnvLen) = SDNVUtil.decode(ba, 0) 19 | if num != n: 20 | print("Error encoding/decoding", n) 21 | return False 22 | # Encode them all in a bunch 23 | ba = bytearray() 24 | for n in vec: 25 | temp = SDNVUtil.encode(n) 26 | ba = ba + temp 27 | offset = 0 28 | outNums = [] 29 | for n in vec: 30 | (num, sdnvLen) = SDNVUtil.decode(ba, offset) 31 | outNums.append(num) 32 | offset += sdnvLen 33 | if outNums != vec: 34 | print("Failed on multi-number encode/decode") 35 | return False 36 | return True 37 | 38 | = Vector tests: small ints 39 | 40 | ba = bytearray() 41 | theNums = [0, 1, 2, 5, 126, 127, 128, 129, 42 | 130, 150, 190, 220, 254, 255, 256] 43 | assert doTestVector(theNums) 44 | 45 | = Vector tests: big ints 46 | 47 | theNums = [0, 1, 0, 1, 0, 128, 32765, 48 | SDNVUtil.maxValue - 10, 4, 32766, 32767, 32768, 32769] 49 | assert doTestVector(theNums) 50 | 51 | = 100 random vector tests 52 | 53 | import random 54 | 55 | def doRandomTestVector(howMany): 56 | vec = [] 57 | for i in range(0, howMany): 58 | vec.append(random.randint(0, SDNVUtil.maxValue)) 59 | result = doTestVector(vec) 60 | return result 61 | 62 | assert doRandomTestVector(100) 63 | 64 | = SDVN tests 65 | 66 | # Tests using the SDNV class 67 | s = SDNV(30) 68 | b = s.encode(17) 69 | theNums = [0, 4, 20, 29, 30, 31, 33] 70 | not_enc = [] 71 | for n in theNums: 72 | try: 73 | b = s.encode(n) 74 | except SDNVValueError as e: 75 | print("Could not encode", n, "-- maximum value is:", e.maxValue) 76 | not_enc.append(n) 77 | 78 | not_enc.sort() 79 | assert not_enc == [31, 33] -------------------------------------------------------------------------------- /test/contrib/sebek.uts: -------------------------------------------------------------------------------- 1 | # Sebek layer unit tests 2 | # 3 | # Type the following command to launch start the tests: 4 | # $ test/run_tests -P "load_contrib('sebek')" -t test/contrib/sebek.uts 5 | 6 | + Sebek protocol 7 | 8 | = Layer binding 1 9 | pkt = IP() / UDP() / SebekHead() / SebekV1(cmd="diepotato") 10 | assert pkt.sport == pkt.dport == 1101 and pkt[SebekHead].version == 1 11 | assert pkt.summary() == "IP / UDP / SebekHead / Sebek v1 read (b'diepotato')" 12 | 13 | = Packet dissection 1 14 | pkt = IP(raw(pkt)) 15 | pkt.sport == pkt.dport == 1101 and pkt[SebekHead].version == 1 16 | 17 | = Layer binding 2 18 | pkt = IP() / UDP() / SebekHead() / SebekV2Sock(cmd="diepotato") 19 | assert pkt.sport == pkt.dport == 1101 and pkt[SebekHead].version == 2 and pkt[SebekHead].type ==2 20 | assert pkt.summary() == "IP / UDP / SebekHead / Sebek v2 socket (b'diepotato')" 21 | 22 | = Packet dissection 2 23 | pkt = IP(raw(pkt)) 24 | pkt.sport == pkt.dport == 1101 and pkt[SebekHead].version == 2 and pkt[SebekHead].type ==2 25 | 26 | = Layer binding 3 27 | pkt = IPv6()/UDP()/SebekHead()/SebekV3() 28 | assert pkt.sport == pkt.dport == 1101 and pkt[SebekHead].version == 3 29 | assert pkt.summary() == "IPv6 / UDP / SebekHead / Sebek v3 read (b'')" 30 | 31 | = Packet dissection 3 32 | pkt = IPv6(raw(pkt)) 33 | pkt.sport == pkt.dport == 1101 and pkt[SebekHead].version == 3 34 | 35 | = Nonsense summaries 36 | 37 | assert SebekHead(version=2).summary() == "Sebek Header v2 read" 38 | assert SebekV1(cmd="diepotato").summary() == "Sebek v1 (b'diepotato')" 39 | assert SebekV2(cmd="diepotato").summary() == "Sebek v2 (b'diepotato')" 40 | assert (SebekHead()/SebekV2(cmd="nottoday")).summary() == "SebekHead / Sebek v2 read (b'nottoday')" 41 | assert SebekV3(cmd="diepotato").summary() == "Sebek v3 (b'diepotato')" 42 | assert (SebekHead()/SebekV3(cmd="nottoday")).summary() == "SebekHead / Sebek v3 read (b'nottoday')" 43 | assert SebekV3Sock(cmd="diepotato").summary() == "Sebek v3 socket (b'diepotato')" 44 | assert (SebekHead()/SebekV3Sock(cmd="nottoday")).summary() == "SebekHead / Sebek v3 socket (b'nottoday')" 45 | assert SebekV2Sock(cmd="diepotato").summary() == "Sebek v2 socket (b'diepotato')" 46 | assert (SebekHead()/SebekV2Sock(cmd="nottoday")).summary() == "SebekHead / Sebek v2 socket (b'nottoday')" 47 | -------------------------------------------------------------------------------- /test/contrib/send.uts: -------------------------------------------------------------------------------- 1 | + SEND (IPv6) tests 2 | 3 | = ICMPv6NDOptRsaSig build and dissection 4 | 5 | pkt = Ether()/IPv6()/ICMPv6ND_NS()/ICMPv6NDOptRsaSig(signature_pad = b"\x01" * 12) 6 | pkt = Ether(raw(pkt)) 7 | 8 | assert ICMPv6NDOptRsaSig in pkt 9 | assert pkt[ICMPv6NDOptRsaSig].signature_pad == b"\x01" * 12 10 | 11 | = ICMPv6NDOptCGA build and dissection 12 | 13 | pkt = Ether()/IPv6()/ICMPv6ND_NS()/ICMPv6NDOptCGA(CGA_PARAMS=CGA_Params()) 14 | pkt = Ether(raw(pkt)) 15 | 16 | assert ICMPv6NDOptCGA in pkt 17 | assert isinstance(pkt[ICMPv6NDOptCGA].CGA_PARAMS.pubkey, X509_SubjectPublicKeyInfo) 18 | assert len(pkt) == 142 19 | 20 | = ICMPv6NDOptTmstp build and dissection 21 | 22 | pkt = Ether()/IPv6()/ICMPv6ND_NS()/ICMPv6NDOptTmstp(timestamp=int(time.mktime(time.gmtime()))) 23 | pkt = Ether(raw(pkt)) 24 | pkt.show() 25 | 26 | assert ICMPv6NDOptTmstp in pkt 27 | assert pkt[ICMPv6NDOptTmstp].len == 2 28 | 29 | = ICMPv6NDOptNonce build and dissection 30 | 31 | pkt = Ether()/IPv6()/ICMPv6ND_NS()/ICMPv6NDOptNonce(nonce=b"\x31\x32\x33\x34\x35\x36") 32 | pkt = Ether(raw(pkt)) 33 | 34 | assert ICMPv6NDOptNonce in pkt 35 | assert raw(ICMPv6NDOptNonce(nonce=b"\x31\x32\x33\x34\x35\x36")) == b'\x0e\x01123456' 36 | -------------------------------------------------------------------------------- /test/contrib/socks.uts: -------------------------------------------------------------------------------- 1 | + SOCKS 4/5 tests 2 | 3 | = Basic build and dissection - test version dispatch 4 | 5 | p1 = Ether(raw(Ether()/IP()/TCP()/SOCKS()/SOCKS5Request())) 6 | p2 = Ether(raw(Ether()/IP()/TCP()/SOCKS()/SOCKS5Reply())) 7 | p3 = Ether(raw(Ether()/IP()/TCP()/SOCKS()/SOCKS4Request())) 8 | p4 = Ether(raw(Ether()/IP()/TCP()/SOCKS()/SOCKS4Reply())) 9 | 10 | assert p1[TCP].dport == 1080 11 | assert p1[SOCKS].vn == 0x5 12 | assert SOCKS5Request in p1 13 | 14 | assert p2[TCP].sport == 1080 15 | assert p2[SOCKS].vn == 0x5 16 | assert SOCKS5Reply in p2 17 | 18 | assert p3[TCP].dport == 1080 19 | assert p3[SOCKS].vn == 0x4 20 | assert SOCKS4Request in p3 21 | 22 | assert p4[TCP].sport == 1080 23 | assert p4[SOCKS].vn == 0x0 24 | assert SOCKS4Reply in p4 25 | 26 | = SOCKS5Request build and dissection 27 | 28 | pkt = IP(dst="127.0.0.1", src="127.0.0.1")/TCP(sport=123)/SOCKS()/SOCKS5Request(atyp=0x3, addr="scapy.net") 29 | assert raw(pkt) == b'E\x00\x009\x00\x01\x00\x00@\x06|\xbc\x7f\x00\x00\x01\x7f\x00\x00\x01\x049\x048\x00\x00\x00\x00\x00\x00\x00\x00P\x02 \x00\xf2*\x00\x00\x05\x00\x00\x03\x05scapy\x03net\x00\x00P' 30 | pkt = IP(raw(pkt)) 31 | 32 | assert SOCKS5Request in pkt 33 | assert pkt[SOCKS5Request].addr == b'scapy.net.' 34 | 35 | = Test SOCKSv5 over UDP 36 | 37 | pkt = Ether()/IP()/UDP()/SOCKS5UDP(port=53)/DNS() 38 | pkt = Ether(raw(pkt)) 39 | assert DNS in pkt 40 | -------------------------------------------------------------------------------- /test/contrib/vqp.uts: -------------------------------------------------------------------------------- 1 | % VQP tests 2 | 3 | + Basic VQP tests 4 | 5 | = Build VQP 6 | 7 | pkt = UDP()/VQP(type=2, 8 | seq=15)/VQPEntry(datatype=3073,data="1.2.3.4")/VQPEntry(datatype=3078, 9 | data="AA:AA:AA:AA:AA:AA") 10 | 11 | assert bytes(pkt) == b'\x065\x065\x00&\x00\x00\x01\x02\x00\x02\x00\x00\x00\x0f\x00\x00\x0c\x01\x00\x04\x01\x02\x03\x04\x00\x00\x0c\x06\x00\x06\xaa\xaa\xaa\xaa\xaa\xaa' 12 | 13 | = Dissect VQP 14 | 15 | pkt = UDP(b'\x065\x065\x00&\x00\x00\x01\x02\x00\x02\x00\x00\x00\x0f\x00\x00\x0c\x01\x00\x04\x01\x02\x03\x04\x00\x00\x0c\x06\x00\x06\xaa\xaa\xaa\xaa\xaa\xaa') 16 | 17 | assert pkt[VQP].sprintf("%type%") == "responseVLAN" 18 | assert pkt.getlayer(VQPEntry, 1).len == 4 19 | assert pkt.getlayer(VQPEntry, 1).sprintf("%datatype%") == "clientIPAddress" 20 | assert pkt.getlayer(VQPEntry, 2).len == 6 21 | assert pkt.getlayer(VQPEntry, 2).sprintf("%datatype%") == "ReqMACAddress" 22 | -------------------------------------------------------------------------------- /test/contrib/vtp.uts: -------------------------------------------------------------------------------- 1 | # VP unit tests 2 | # 3 | # Type the following command to launch start the tests: 4 | # $ test/run_tests -P "load_contrib('vtp')" -t test/contrib/vtp.uts 5 | 6 | 7 | + VTP 8 | 9 | = VTP, basic instantiation 10 | pkt = VTP(vlaninfo=[VTPVlanInfo()]) 11 | assert len(pkt) == 72 12 | -------------------------------------------------------------------------------- /test/pcaps/bad_rsn_parsing_overrides_ssid.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/bad_rsn_parsing_overrides_ssid.pcap -------------------------------------------------------------------------------- /test/pcaps/bgp_fragmented.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/bgp_fragmented.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/candump_gmlan_scanner.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/candump_gmlan_scanner.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/candump_uds_scanner.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/candump_uds_scanner.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/canfd.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/canfd.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/dcerpc_msdrsr_cracknames.pcapng.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/dcerpc_msdrsr_cracknames.pcapng.gz -------------------------------------------------------------------------------- /test/pcaps/dcerpc_msnrpc.pcapng.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/dcerpc_msnrpc.pcapng.gz -------------------------------------------------------------------------------- /test/pcaps/dcerpc_privacy_krb.pcapng.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/dcerpc_privacy_krb.pcapng.gz -------------------------------------------------------------------------------- /test/pcaps/dcerpc_privacy_ntlm.pcapng.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/dcerpc_privacy_ntlm.pcapng.gz -------------------------------------------------------------------------------- /test/pcaps/doip.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/doip.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/doip_ack.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/doip_ack.pcap -------------------------------------------------------------------------------- /test/pcaps/doip_functional_request.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/doip_functional_request.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/ecu_trace.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/ecu_trace.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/gmlan_trace.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/gmlan_trace.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/gvrp.pcapng.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/gvrp.pcapng.gz -------------------------------------------------------------------------------- /test/pcaps/http2_h2c.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/http2_h2c.pcap -------------------------------------------------------------------------------- /test/pcaps/http_chunk.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/http_chunk.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/http_compressed-brotli.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/http_compressed-brotli.pcap -------------------------------------------------------------------------------- /test/pcaps/http_compressed-zstd.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/http_compressed-zstd.pcap -------------------------------------------------------------------------------- /test/pcaps/http_compressed.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/http_compressed.pcap -------------------------------------------------------------------------------- /test/pcaps/http_content_length.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/http_content_length.pcap -------------------------------------------------------------------------------- /test/pcaps/http_head.pcapng.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/http_head.pcapng.gz -------------------------------------------------------------------------------- /test/pcaps/http_tcp_psh.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/http_tcp_psh.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/ikev2_nat_t.pcapng: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/ikev2_nat_t.pcapng -------------------------------------------------------------------------------- /test/pcaps/ikev2_notify_redirect.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/ikev2_notify_redirect.pcap -------------------------------------------------------------------------------- /test/pcaps/ipfix.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/ipfix.pcap -------------------------------------------------------------------------------- /test/pcaps/macos.pcapng.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/macos.pcapng.gz -------------------------------------------------------------------------------- /test/pcaps/multiple_doip_layers.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/multiple_doip_layers.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/netflowv9.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/netflowv9.pcap -------------------------------------------------------------------------------- /test/pcaps/pfcp.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/pfcp.pcap -------------------------------------------------------------------------------- /test/pcaps/psp_v4_cleartext.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/psp_v4_cleartext.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/psp_v4_encrypt_transport_crypt_off_128.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/psp_v4_encrypt_transport_crypt_off_128.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/psp_v4_encrypt_transport_crypt_off_128_vc.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/psp_v4_encrypt_transport_crypt_off_128_vc.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/psp_v4_encrypt_transport_crypt_off_256.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/psp_v4_encrypt_transport_crypt_off_256.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/ssh_ed25519.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/ssh_ed25519.pcap -------------------------------------------------------------------------------- /test/pcaps/tls_new-session-ticket.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/tls_new-session-ticket.pcap -------------------------------------------------------------------------------- /test/pcaps/tls_tcp_frag.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/tls_tcp_frag.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/tls_tcp_frag_withnss.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/tls_tcp_frag_withnss.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/zigbee-join-authenticate.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/zigbee-join-authenticate.pcap -------------------------------------------------------------------------------- /test/pcaps/zigbee-transport-key-skke_1.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/secdev/scapy/56de4f4363088c533d6c8753080f1a31c90115ee/test/pcaps/zigbee-transport-key-skke_1.pcap -------------------------------------------------------------------------------- /test/run_tests: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # Run Scapy test suite. 4 | # 5 | # If ran with no arguments: 6 | # ./run_tests 7 | # this util will run the test suite using tox, with options that should work 8 | # regardless of the platform or the dependencies. The only dependency for this 9 | # to work are python3 (or python) and tox. 10 | # 11 | # If ran with arguments, this will call UTscapy.py 12 | # 13 | # ATTENTION PACKAGE MAINTAINERS: 14 | # If you do need to run Scapy tests, calling ./run_tests should be enough. 15 | # 16 | DIR=$(dirname "$0")/.. 17 | if [ -z "$PYTHON" ] 18 | then 19 | ARGS="" 20 | for arg in "$@" 21 | do 22 | case $arg 23 | in 24 | -3) PYTHON=python3;; 25 | -W) PYTHONWARNINGS="-W error";; 26 | *) ARGS="$ARGS $arg";; 27 | esac 28 | done 29 | PYTHON=${PYTHON:-python3} 30 | else 31 | ARGS="$@" 32 | fi 33 | $PYTHON --version > /dev/null 2>&1 34 | if [ ! $? -eq 0 ] 35 | then 36 | echo "WARNING: '$PYTHON' not found, using 'python' instead." 37 | PYTHON=python 38 | fi 39 | 40 | if [ -z "$ARGS" ] 41 | then 42 | # No arguments specified: use tox 43 | # We use flags to disable tests that use external non tox-installed 44 | # software. 45 | 46 | # Check tox 47 | tox --version >/dev/null 2>/dev/null 48 | if [ ! $? -eq 0 ] 49 | then 50 | echo "ERROR: tox is not installed." 51 | echo "You can still run ./run_tests with arguments: see ./run_tests -h" 52 | echo "e.g. ./run_tests -t tls.uts -F" 53 | exit 1 54 | fi 55 | 56 | # Run tox 57 | export UT_FLAGS="-K tcpdump -K wireshark -K tshark -K ci_only -K vcan_socket -K automotive_comm -K imports -K scanner" 58 | export SIMPLE_TESTS="true" 59 | export PYTHON 60 | export DISABLE_COVERAGE=" " 61 | PYVER=$($PYTHON -c "import sys; print('.'.join(sys.version.split('.')[:2]))") 62 | bash ${DIR}/.config/ci/test.sh $PYVER non_root 63 | exit $? 64 | fi 65 | PYTHONPATH=$DIR exec "$PYTHON" $PYTHONWARNINGS ${DIR}/scapy/tools/UTscapy.py $ARGS 66 | -------------------------------------------------------------------------------- /test/run_tests.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set MYDIR=%~dp0.. 3 | set PWD=%MYDIR% 4 | set PYTHONPATH=%MYDIR% 5 | REM Note: shift will not work with %* 6 | REM ### Get args, Handle Python version ### 7 | set "_args=%*" 8 | IF "%1" == "-3" ( 9 | set PYTHON=python3 10 | set "_args=%_args:~3%" 11 | ) 12 | IF "%PYTHON%" == "" set PYTHON=python3 13 | WHERE %PYTHON% >nul 2>&1 14 | IF %ERRORLEVEL% NEQ 0 set PYTHON=python 15 | REM Reset Error level 16 | VERIFY > nul 17 | echo ##### Starting Unit tests ##### 18 | REM ### Check no-argument mode ### 19 | IF "%_args%" == "" ( 20 | REM Check for tox 21 | %PYTHON% -m tox --version >nul 2>&1 22 | IF %ERRORLEVEL% NEQ 0 ( 23 | echo Tox not installed ! 24 | pause 25 | exit 1 26 | ) 27 | REM Run tox 28 | %PYTHON% -m tox -- -K tcpdump -K manufdb -K wireshark -K ci_only -K automotive_comm 29 | pause 30 | exit 0 31 | ) 32 | REM ### Start UTScapy normally ### 33 | %PYTHON% "%MYDIR%\scapy\tools\UTscapy.py" %_args% 34 | PAUSE 35 | -------------------------------------------------------------------------------- /test/scapy/layers/hsrp.uts: -------------------------------------------------------------------------------- 1 | % HSRP regression tests for Scapy 2 | 3 | 4 | ############ 5 | ############ 6 | + HSRP tests 7 | 8 | = HSRP - build & dissection 9 | defaddr = conf.route.route('0.0.0.0')[1] 10 | pkt = IP(raw(IP()/UDP(dport=1985, sport=1985)/HSRP()/HSRPmd5())) 11 | assert pkt[IP].dst == "224.0.0.2" and pkt[UDP].sport == pkt[UDP].dport == 1985 12 | assert pkt[HSRP].opcode == 0 and pkt[HSRP].state == 16 13 | assert pkt[HSRPmd5].type == 4 and pkt[HSRPmd5].sourceip == defaddr 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/scapy/layers/l2tp.uts: -------------------------------------------------------------------------------- 1 | % L2TP regression tests for Scapy 2 | 3 | ############ 4 | ############ 5 | + L2TP tests 6 | 7 | = L2TP - build 8 | s = raw(IP(src="127.0.0.1", dst="127.0.0.1")/UDP()/L2TP()) 9 | s == b'E\x00\x00"\x00\x01\x00\x00@\x11|\xc8\x7f\x00\x00\x01\x7f\x00\x00\x01\x06\xa5\x06\xa5\x00\x0e\xf4\x83\x00\x02\x00\x00\x00\x00' 10 | 11 | = L2TP - build with computed length 12 | assert bytes(L2TP(hdr="control+length", tunnel_id=1, session_id=2)) == b'\xc0\x02\x00\x0c\x00\x01\x00\x02\x00\x00\x00\x00' 13 | 14 | = L2TP - dissection 15 | p = IP(s) 16 | L2TP in p and len(p[L2TP]) == 6 and p.tunnel_id == 0 and p.session_id == 0 and p[UDP].chksum == 0xf483 17 | -------------------------------------------------------------------------------- /test/scapy/layers/ldapopenldap.uts: -------------------------------------------------------------------------------- 1 | % Tests that need a local instance of OpenLDAP to run 2 | 3 | + Functional test against OpenLDAP 4 | ~ linux ci_only 5 | 6 | = (OpenLDAP) connect to server, bind 7 | 8 | cli = LDAP_Client() 9 | cli.connect("127.0.0.1") 10 | cli.bind(LDAP_BIND_MECHS.SIMPLE, simple_username="cn=admin,dc=scapy,dc=net", simple_password="Bonjour1") 11 | cli.close() 12 | 13 | = (OpenLDAP) connect to server, bind, search 14 | 15 | cli = LDAP_Client() 16 | cli.connect("127.0.0.1") 17 | cli.bind(LDAP_BIND_MECHS.SIMPLE, simple_username="cn=admin,dc=scapy,dc=net", simple_password="Bonjour1") 18 | res = cli.search("dc=scapy,dc=net", "(&(givenName=Another)(sn=Test))", scope=2) 19 | cli.close() 20 | 21 | assert res == { 22 | 'uid=another,ou=People,dc=scapy,dc=net': { 23 | 'objectClass': ['top', 24 | 'person', 25 | 'inetOrgPerson'], 26 | 'cn': ['Another Test'], 27 | 'uid': ['another'], 28 | 'sn': ['Test'], 29 | 'givenName': ['Another'], 30 | 'userPassword': ['testing'] 31 | } 32 | } 33 | 34 | = (OpenLDAP) connect to server using SSL 35 | ~ disabled 36 | 37 | # We need a version of OpenLDAP that is more recent. Let's wait. 38 | 39 | cli = LDAP_Client() 40 | cli.connect("127.0.0.1", use_ssl=True, no_check_certificate=True) 41 | cli.bind(LDAP_BIND_MECHS.SIMPLE, simple_username="cn=admin,dc=scapy,dc=net", simple_password="Bonjour1") 42 | cli.close() 43 | -------------------------------------------------------------------------------- /test/scapy/layers/mgcp.uts: -------------------------------------------------------------------------------- 1 | % MGCP regression tests for Scapy 2 | 3 | ############ 4 | ############ 5 | + MGCP tests 6 | 7 | = MGCP - build 8 | s = raw(IP(src="127.0.0.1")/UDP()/MGCP(endpoint="scapy@secdev.org", transaction_id="04523")) 9 | s == b'E\x00\x00I\x00\x01\x00\x00@\x11|\xa1\x7f\x00\x00\x01\x7f\x00\x00\x01\n\xa7\n\xa7\x005\xf8\xaeAUEP 04523 scapy@secdev.org MGCP 1.0 NCS 1.0\n' 10 | 11 | = MGCP - dissect 12 | pkt = Ether(b'\x1b\x81\xb8\xa8J5\xe3\xebn\x90q\xb8\x08\x00E\x00\x00E\x00\x01\x00\x00@\x11\xf7\xde\xc0\xa8\x00\xff\xc0\xa8\x00y\n\xa7\n\xa7\x001\x05\xb5AUEP 155 god@heaven.com MGCP 1.0 NCS 1.0\n') 13 | assert pkt[MGCP].endpoint == b'god@heaven.com' 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/scapy/layers/mobileip.uts: -------------------------------------------------------------------------------- 1 | % Mobile IP regression tests for Scapy 2 | 3 | 4 | ############ 5 | ############ 6 | + MobileIP tests 7 | 8 | = MobileIP - build 9 | s = raw(IP(src="127.0.0.1")/UDP()/MobileIP()/MobileIPRRP(homeaddr='156.133.50.141', haaddr='95.83.86.216')) 10 | s == b'E\x00\x000\x00\x01\x00\x00@\x11|\xba\x7f\x00\x00\x01\x7f\x00\x00\x01\x01\xb2\x01\xb2\x00\x1cu]\x03\x00\x00\xb4\x9c\x852\x8d_SV\xd8\x00\x00\x00\x00\x00\x00\x00\x00' 11 | 12 | = MobileIP - dissect 13 | pkt = IP(s) 14 | assert pkt[MobileIP][MobileIPRRP].haaddr == '95.83.86.216' 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/scapy/layers/rip.uts: -------------------------------------------------------------------------------- 1 | % RIP regression tests for Scapy 2 | 3 | ############ 4 | ############ 5 | + RIP tests 6 | 7 | = RIP - build 8 | s = raw(IP()/UDP(sport=520)/RIP()/RIPEntry()/RIPAuth(authtype=2, password="scapy")) 9 | s == b'E\x00\x00H\x00\x01\x00\x00@\x11|\xa2\x7f\x00\x00\x01\x7f\x00\x00\x01\x02\x08\x02\x08\x004\xae\x99\x01\x01\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xff\xff\x00\x02scapy\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' 10 | 11 | = RIP - UDP bindings 12 | w = IP(raw(IP()/UDP()/RIP()/RIPEntry()/RIPAuth(authtype=2, password="scapy"))) 13 | assert RIPAuth in w 14 | assert w[RIPAuth].password.startswith(b"scapy") 15 | 16 | = RIP - dissection 17 | p = IP(s) 18 | RIPEntry in p and RIPAuth in p and p[RIPAuth].password.startswith(b"scapy") 19 | -------------------------------------------------------------------------------- /test/scapy/layers/rtp.uts: -------------------------------------------------------------------------------- 1 | % RTP regression tests for Scapy 2 | 3 | # More information at http://www.secdev.org/projects/UTscapy/ 4 | 5 | ############ 6 | # RTP 7 | ############ 8 | 9 | + RTP tests 10 | 11 | = test rtp with extension header 12 | ~ rtp 13 | 14 | data = b'\x90o\x14~YY\xf5h\xcc#\xd7\xcfUH\x00\x03\x167116621 \x000\x00' 15 | pkt = RTP(data) 16 | assert "RTP" in pkt 17 | parsed = pkt["RTP"] 18 | assert parsed.version == 2 19 | assert parsed.extension 20 | assert parsed.numsync == 0 21 | assert not parsed.marker 22 | assert parsed.payload_type == 111 23 | assert parsed.sequence == 5246 24 | assert parsed.timestamp == 1499067752 25 | assert parsed.sourcesync == 0xcc23d7cf 26 | assert "RTPExtension" in parsed, parsed.show() 27 | assert parsed["RTPExtension"].header_id == 0x5548 28 | assert parsed["RTPExtension"].header == [0x16373131,0x36363231,0x20003000] 29 | 30 | = test layer creation 31 | 32 | created = RTP(extension=True, payload_type="PCMA", sequence=0x1234, timestamp=12345678, sourcesync=0xabcdef01) 33 | created /= RTPExtension(header_id=0x4321, header=[0x11223344]) 34 | assert raw(created) == b'\x90\x08\x124\x00\xbcaN\xab\xcd\xef\x01C!\x00\x01\x11"3D' 35 | parsed = RTP(raw(created)) 36 | assert parsed.payload_type == 8 37 | assert "RTPExtension" in parsed, parsed.show() 38 | assert parsed["RTPExtension"].header == [0x11223344] 39 | 40 | = test RTP without extension 41 | 42 | created = RTP(extension=False, payload_type="DVI4", sequence=0x1234, timestamp=12345678, sourcesync=0xabcdef01) 43 | assert raw(created) == b'\x80\x11\x124\x00\xbcaN\xab\xcd\xef\x01' 44 | parsed = RTP(raw(created)) 45 | assert parsed.sourcesync == 0xabcdef01 46 | assert "RTPExtension" not in parsed 47 | 48 | -------------------------------------------------------------------------------- /test/scapy/layers/skinny.uts: -------------------------------------------------------------------------------- 1 | % Skinny regression tests for Scapy 2 | 3 | # More information at http://www.secdev.org/projects/UTscapy/ 4 | 5 | ############ 6 | ############ 7 | + Skinny tests 8 | 9 | = Skinny - build & dissection 10 | p = raw(IP(src="127.0.0.1")/TCP()/Skinny(msg="ServiceURLStatMessage")) 11 | assert p == b'E\x00\x004\x00\x01\x00\x00@\x06|\xc1\x7f\x00\x00\x01\x7f\x00\x00\x01\x07\xd0\x07\xd0\x00\x00\x00\x00\x00\x00\x00\x00P\x02 \x00S3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/\x01\x00\x00' 12 | assert IP(p)[Skinny].msg == 303 13 | -------------------------------------------------------------------------------- /test/scapy/layers/tls/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: GPL-2.0-only 2 | # This file is part of Scapy 3 | # See https://scapy.net/ for more information 4 | # Copyright (C) 2016 Maxence Tury 5 | 6 | """ 7 | Examples and test PKI for the TLS module. 8 | """ 9 | 10 | -------------------------------------------------------------------------------- /test/scapy/layers/tls/pki/README.md: -------------------------------------------------------------------------------- 1 | # Notes on how to generate the PKI 2 | 3 | ``` 4 | openssl genpkey -algorithm ED25519 -out srv_key_ed25519.pem 5 | openssl req -new -key srv_key_ed25519.pem -out srv_cert_ed25519.csr -addext basicConstraints=critical,CA:FALSE,pathlen:1 -addext "extendedKeyUsage = serverAuth" -subj "/C=MN/L=Ulaanbaatar/OU=Scapy Test PKI/CN=Scapy Test Server" 6 | openssl x509 -req -days 3653 -in srv_cert_ed25519.csr -CA ca_cert.pem -CAkey ca_key.pem -out srv_cert_ed25519.pem -copy_extensions copyall 7 | rm srv_cert_ed25519.csr 8 | openssl x509 -in srv_cert_ed25519.pem -text -noout 9 | ``` 10 | -------------------------------------------------------------------------------- /test/scapy/layers/tls/pki/ca_cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDiDCCAnCgAwIBAgIJALpa+1bjqpmeMA0GCSqGSIb3DQEBCwUAMFQxCzAJBgNV 3 | BAYTAk1OMRQwEgYDVQQHDAtVbGFhbmJhYXRhcjEXMBUGA1UECwwOU2NhcHkgVGVz 4 | dCBQS0kxFjAUBgNVBAMMDVNjYXB5IFRlc3QgQ0EwHhcNMTYwOTE2MTAyNjQ1WhcN 5 | MjYwOTE2MTAyNjQ1WjBUMQswCQYDVQQGEwJNTjEUMBIGA1UEBwwLVWxhYW5iYWF0 6 | YXIxFzAVBgNVBAsMDlNjYXB5IFRlc3QgUEtJMRYwFAYDVQQDDA1TY2FweSBUZXN0 7 | IENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0Gy5LahBQAwiGUrP 8 | ZLrBUIEZAlnsOkCd7Al+wJwaPFhMLy+nga0ubMuUBo4P9DQv729jpiRnu6Q1ScO3 9 | PcRX5FNdEKxV9fLOWUJp5MIMz5k6snJ5+kEMouNXj/umUN+qHHyvgbDVEw7RroTN 10 | mLqnWs2Al5Rd0NAxp4lLoYdVUclXrlOGY7Ldkq4WAgdlJZQ6PiZyeoz6YNeoRNmR 11 | h4RGKDmzoSEKqsAUlozEg3seC1EbU0TtY9r3O09tEGegQUARIxXV3qpWjFxakax+ 12 | XzzldwuoIWMO7x8RqH9X3Y+ktcLOxiPhKmGqcR3kNyMcARatdIjdV0b3jAeH68of 13 | DVxXoQIDAQABo10wWzAdBgNVHQ4EFgQUZlOU9BXRvWdosFE3MjXhpKreB3wwHwYD 14 | VR0jBBgwFoAUZlOU9BXRvWdosFE3MjXhpKreB3wwDAYDVR0TBAUwAwEB/zALBgNV 15 | HQ8EBAMCAgQwDQYJKoZIhvcNAQELBQADggEBAJNnhilPvSXjGFSUNp5XG81i44lI 16 | wqsYcWl7cuNjFS8tqciMb1Q8Lr768+CPFYlf3OjwX43SCe621oKtRZV0O3bizSZd 17 | 5xuCAEsCe1jkk4d7Nxk13/AB2z6YKvWeud/vLAQpYIwzV/qExAOv+ZLAj46t6S/E 18 | h/A/kNEXqBE5e+yysTUVNz+moI7P8Sw91yXuiPMSWJ4rla+nmfFWaKTP9vjEmEHt 19 | a+LA8VUiR2dEeLcRnVCgVJc0+AS6EjG662AKyNYP4AcmUaFvBKRiJpEgZwNmmOen 20 | PjNAbNxzEk7bJMG8GUmwYJ9cYznBFBOzAJNyMkG8wSmMYN3NgdnD4KYHYVE= 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /test/scapy/layers/tls/pki/ca_key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDQbLktqEFADCIZ 3 | Ss9kusFQgRkCWew6QJ3sCX7AnBo8WEwvL6eBrS5sy5QGjg/0NC/vb2OmJGe7pDVJ 4 | w7c9xFfkU10QrFX18s5ZQmnkwgzPmTqycnn6QQyi41eP+6ZQ36ocfK+BsNUTDtGu 5 | hM2YuqdazYCXlF3Q0DGniUuhh1VRyVeuU4Zjst2SrhYCB2UllDo+JnJ6jPpg16hE 6 | 2ZGHhEYoObOhIQqqwBSWjMSDex4LURtTRO1j2vc7T20QZ6BBQBEjFdXeqlaMXFqR 7 | rH5fPOV3C6ghYw7vHxGof1fdj6S1ws7GI+EqYapxHeQ3IxwBFq10iN1XRveMB4fr 8 | yh8NXFehAgMBAAECggEAXSPpEO0604tYhaL30VTf5MD8Ux+qQFH2ALAxk5Nu6f6v 9 | dPq/yWSB9Z54NQGxQXk83qwRhQKJ1MHKCn/K2HBwsplKYpQRCgsKibrzJYZOQUuB 10 | fpNHzTzaj8Q2siJMLaH2HCrgJ33FinG55Fp2okTvWtWxHIvx7MnNFsh1IuceiqA3 11 | 5tVSR7+kMraJgJ9auRNRQbH273LzntVOzAt339Xd38izsQ7CvYERAQGabTwo6BEC 12 | nDFfhWXPaxRt5JcJWcJNYSxYKigMmDh4oGXSb+mZeuojcXYcaHzyAToAjZ6x2hXU 13 | Vjxo7JMK+gvhJvlOpY2tjMNIkRh1P7gLrBSP8XcxjQKBgQDtSIr8qooaswEQ9H8W 14 | Tkr5ciLU4u6Wfhp26+M6oHPv57bbJI7qN68Z3l+cbtLxSqj0bcop1V+xvQjWOD+/ 15 | ckNPm4aEmoIMP3a0oQARtJeR9uaos64uudc+1gpz9g7w+sO+khy9yAFdY1+9gsEi 16 | WqqbtVQ2e3RABoolr14Pcc222wKBgQDg3XAjcXupfsrDhQP5R45kY/eVFWUk7PMB 17 | jpPl6+ZfoB/vqUuCZBX3UYrFDe4O+n0R6oF9ACXLRsVuaG/IZYDFczsBvEr8WpOG 18 | 78lpTbgUwudKlnzSBl01aUZu7zpJ3oFhX1DgZspr72UfHl9+/NwezV4gFd0ZKGLO 19 | s/aLsh3eMwKBgDm3TH9a6A7IfbjnD8aYMqpsNca8kDYw5DUK+ZF4F9tB7HtvcAfO 20 | lZvgODdvyYWBmIkj72mvigBMr8qTkgX6QB8sAFNe1cUu5qvXAZJM8BVEDiT416Rr 21 | 9cxF+fLs5gN9q4E+Pxl2fcZ+dno9RMcbcKZBPAOokcVFEfNKrcFp+BTDAoGBAL42 22 | 0ztILgFs/fxysq/V9f+6CJ8WIB8iSVXR1A40hQXzH9DN9s/v9hzl32tdozkMb2wO 23 | YUbqLw5LaYtB0P1Fz643EX0gWJYr0IvenxPy6Hq3fIu9zQyk0Yfy69+/giEmlW9W 24 | /8UzbpvrQDEYslNrdpCfzLV7iTJU1XBhD3eQTm+9AoGAf1EX07Jk7357Y7+l/vB4 25 | Cd0g+k4yRadDM7tCrdYnZcdwhFoKtCC9y/ChBgHRkayMizJRYC218ou9muP3qYLD 26 | Wd+Sqtxg7LlDRa+m8db0SI40a0AMb0fGKXzy4AxD1EJrBLt8rdaDrqoGF/Vwadjh 27 | sxUMjCPGDmiV+ucqbJR9/NE= 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /test/scapy/layers/tls/pki/cli_cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDnjCCAoagAwIBAgIJAP4EVw3HJ+n4MA0GCSqGSIb3DQEBCwUAMFQxCzAJBgNV 3 | BAYTAk1OMRQwEgYDVQQHDAtVbGFhbmJhYXRhcjEXMBUGA1UECwwOU2NhcHkgVGVz 4 | dCBQS0kxFjAUBgNVBAMMDVNjYXB5IFRlc3QgQ0EwHhcNMTYwOTE2MTAzMDUyWhcN 5 | MjYwOTE1MTAzMDUyWjBYMQswCQYDVQQGEwJNTjEUMBIGA1UEBwwLVWxhYW5iYWF0 6 | YXIxFzAVBgNVBAsMDlNjYXB5IFRlc3QgUEtJMRowGAYDVQQDDBFTY2FweSBUZXN0 7 | IENsaWVudDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMMJN5ioDSgj 8 | OufUeWJI7Ali5QPySoD8neeSXkzGlm48SGDNzoKQs0v75gmlOs/mditKsPfu9HQA 9 | Ohd97oor8HQLhEMqF6OpiGyjOo7i3+/X8bPhJJsn6pYmJ5PH8HjduHuGFGt9Or2t 10 | wpQCd1t5ZN3KSZpnEk9K3HS3GJHHsO69UvuIWsksjjetAtD7HpvdeMGrMRmTEgI3 11 | EFVUigfP1y8uaoq648TPG31MFx8cpxfKhNtstmRPZNpyl2NpzoZQFXskbMO8pVYc 12 | QxTwA6/AgDBYoaYRdV4hq5MSfcGloy5OIsR/8toamJ0EjbypulnC0+F78goP/Puw 13 | isuHi2YYJxUCAwEAAaNvMG0wCQYDVR0TBAIwADALBgNVHQ8EBAMCBeAwHQYDVR0O 14 | BBYEFAPVvKSOtt3Hj63JN8ZtzEGSZZ5IMB8GA1UdIwQYMBaAFGZTlPQV0b1naLBR 15 | NzI14aSq3gd8MBMGA1UdJQQMMAoGCCsGAQUFBwMCMA0GCSqGSIb3DQEBCwUAA4IB 16 | AQAhzb8LBydZ+ulSyIiF4/PgTh7/sQOC1LroP0GhVsOLNZ07qvw8teXJO9HwsAqm 17 | 14GeLJh5XWhoL4tkq9RMcwuZL2vuVl9FB9inLerA1FU/ErJJOIIC3drIORTTQ2ot 18 | lUkbKOAQFzZfP0d+iuCFi0r0Kcu7BAZETTeG4cAoIoIIhh2AZ8DfT3E6xP7OKUMA 19 | 3m1gA4M1hwiAhFvj4iBaG20Sb0RXpDuTToHEfCEnuQdoex3F8gmn88yt22FNakqe 20 | cr9ooif+id4ErdKLozgG1i0PFYCFRj2/fUPTQw3BSgfo+XNcAjA04CowuhPAjsL8 21 | ybC+9OE5YPSxfOqOPB4sK/w2 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /test/scapy/layers/tls/pki/cli_key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDDCTeYqA0oIzrn 3 | 1HliSOwJYuUD8kqA/J3nkl5MxpZuPEhgzc6CkLNL++YJpTrP5nYrSrD37vR0ADoX 4 | fe6KK/B0C4RDKhejqYhsozqO4t/v1/Gz4SSbJ+qWJieTx/B43bh7hhRrfTq9rcKU 5 | AndbeWTdykmaZxJPStx0txiRx7DuvVL7iFrJLI43rQLQ+x6b3XjBqzEZkxICNxBV 6 | VIoHz9cvLmqKuuPEzxt9TBcfHKcXyoTbbLZkT2Tacpdjac6GUBV7JGzDvKVWHEMU 7 | 8AOvwIAwWKGmEXVeIauTEn3BpaMuTiLEf/LaGpidBI28qbpZwtPhe/IKD/z7sIrL 8 | h4tmGCcVAgMBAAECggEBAJU951ocNj0hgEDH+L55uIySLVawv8wmAhqiiSBM0e22 9 | mVfiBIUqftjE/8kfs3pFCuWjuPlv04U0az9wsOjwKIZUDbhrbD1jTC59VSDjgKKC 10 | ZsTTonRLvhl5Rs2xsFR8rV9wQQ3jfOCKJxulK3pG0SVaVqoc9wjP6xQwy086NCzq 11 | QLnM2BESEED9cfbO7zVE7bJzLmAH9v4eF5hpuQ3SQZGE6oib0uPPnAyl5iOZZHnu 12 | 4DTxVHYIYKCegL47VpeL3h80Yzu8bAuqoSsLxbBcAoYB9e9ZMVi8o1NaVM9eT0/m 13 | HSb+rkN39YrrtXDkXxqmwsh8B7R9gRBxMFIzsI83XN0CgYEA+KSoQ3zpEjjFioB+ 14 | 006JcATCslLERgDuuaVqVlnt5a983i/3nwvICxfsGrFaQJ4TkhXEYuZro4Zovdc1 15 | 9IAj8DEQRNh7H7mZoWtQnFC32VOdAUVZVpopL6009xKs/II9pRKg4Vm6mpb47xfl 16 | Yk/upy5yV4gHThkMLccJ8PqmIosCgYEAyM6Da1vflkzoKMu7HmJNmi59hnk5N15V 17 | C8BcYNaodiHucrcyzOexaVnIQJ7+CgVen+RF9wwcIQxUsw8Vcs0AZ4ipLDOFZXNk 18 | k0oGjr5oeCIHJvA9W1BSXmcJ5Beo4ASr0GmIQpfsFohFuHXn7ezQWqA6Me8HwFGF 19 | l8goN3VyMN8CgYBJ5u7YOE0yDEuykeSgO6yf7dpMlEsgH3DVHvRPPCV4akNr6sfn 20 | ruHDYlXbzTDtGc7pUazwVFpT3UROgKPZyyhjYMHcJJfb4xdlofbwrxEl+DMnSIx4 21 | MBPjxtCCSzu9RZy67qGAuWG8RvkwX2LfaLCfYi+8EoNRVCKJjKpIxMcSZwKBgC9E 22 | xZTJDKmxstiflI2DcGcB2JSGBpzs/LIGdvhor0EXnaytSS0IwS9ebhAgHQa42txi 23 | fMG5vQlegLWhsFfUv+qfNcts2VLXRe6R91c0pRzaTbqxxI+xKaKFOMPTefI5x0QJ 24 | A4VBg9aN/3N7dbwBCc67dtd4P+faiMsA186uO9IbAoGAVvh9bC5zoCfenexRe9si 25 | c/baEsOlPjMnM/QKz6Ue/65YTzpJYQ1hVlGqP2DsN28f5yJetHLcUINaPxlegKdL 26 | Ifhmdg5HO7v35NHVghXq+/M8xYRzKD6nqRqB8wEdGb+XOo5QHXsLp3wBQ7QXL4UI 27 | mrJFWi1wtyQOdIO4GJC8Bc0= 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /test/scapy/layers/tls/pki/srv_cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDnjCCAoagAwIBAgIJAP4EVw3HJ+n2MA0GCSqGSIb3DQEBCwUAMFQxCzAJBgNV 3 | BAYTAk1OMRQwEgYDVQQHDAtVbGFhbmJhYXRhcjEXMBUGA1UECwwOU2NhcHkgVGVz 4 | dCBQS0kxFjAUBgNVBAMMDVNjYXB5IFRlc3QgQ0EwHhcNMTYwOTE2MTAyODExWhcN 5 | MjYwOTE1MTAyODExWjBYMQswCQYDVQQGEwJNTjEUMBIGA1UEBwwLVWxhYW5iYWF0 6 | YXIxFzAVBgNVBAsMDlNjYXB5IFRlc3QgUEtJMRowGAYDVQQDDBFTY2FweSBUZXN0 7 | IFNlcnZlcjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMzx8ZtgLWCu 8 | 8pgNJynZwAlZTA9KMKhS3+WxIZ9Pwz1Wk91fxvez9lWL55Li3vKFSbShLPT9dqhn 9 | ygQgYBEYpvKptqYd2arl2duv5q9VV5//Uoll5oBigCGUvM+BG8tnwp21BXcEpseI 10 | GIB4aJU23pcbtmGHQhp1mEWC6z4yEcibhkI5jU0St1gbGfOdK6GYgsrXOyT7CTmw 11 | vMKVz4IpdRYpP0IgFytNQIxWbK26DzSFsX9AeXF4t6UEu5T3tUGV7nzrjQx5aFnv 12 | y7P6Pnge7mdMet3gme/a5++yCV2+gCAhBYMsRNtdKnYppbAjiHQHVCLWKXqS9W8t 13 | nuf4JiucWGUCAwEAAaNvMG0wCQYDVR0TBAIwADALBgNVHQ8EBAMCBeAwHQYDVR0O 14 | BBYEFKErIHDSa4DlZbzrAw+In3St3fYTMB8GA1UdIwQYMBaAFGZTlPQV0b1naLBR 15 | NzI14aSq3gd8MBMGA1UdJQQMMAoGCCsGAQUFBwMBMA0GCSqGSIb3DQEBCwUAA4IB 16 | AQCBiJJza5PnldbdQe6OHr2jSFinQTU/e33QN5gOuCyUd8hRNkCtWQkoyFbW6lus 17 | tNg/aLdmyuFWN6kAZepRyeyyaUld+ePA7WFUyRKfxrAKc1XoVTVg7xw28NrRkHdW 18 | BLirOO73CcWlmJAj6h/bFX8yKIGrm4UCS5XnN1F7G0gu+z5Sow20RqmSOhwf1woe 19 | WEr6LlGPKcYeuA4xDnPxJ4gXyshpDPqDzbN5DhSwuJsvOi0J4/wG8Dpu/TY7KxoJ 20 | KuirX4xA5IGyvPeDZxFuTpPqIq//o5p3V3bQCzis+IqUNY7X1GHMAf8ktI9hI7qI 21 | 11nk6boqTrUVD5zQ6gaR2d6r 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /test/scapy/layers/tls/pki/srv_cert_ed25519.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICqDCCAZCgAwIBAgIUYYDvh160/Q32Q/MuCGSfIYxTwwEwDQYJKoZIhvcNAQEL 3 | BQAwVDELMAkGA1UEBhMCTU4xFDASBgNVBAcMC1VsYWFuYmFhdGFyMRcwFQYDVQQL 4 | DA5TY2FweSBUZXN0IFBLSTEWMBQGA1UEAwwNU2NhcHkgVGVzdCBDQTAeFw0yNDA3 5 | MTQxOTU4MzNaFw0zNDA3MTUxOTU4MzNaMFgxCzAJBgNVBAYTAk1OMRQwEgYDVQQH 6 | DAtVbGFhbmJhYXRhcjEXMBUGA1UECwwOU2NhcHkgVGVzdCBQS0kxGjAYBgNVBAMM 7 | EVNjYXB5IFRlc3QgU2VydmVyMCowBQYDK2VwAyEAB8exZcGWUFeio0aPES732u5l 8 | GXRUuaktLmSIQB8PoPejaDBmMA8GA1UdEwEB/wQFMAMCAQEwEwYDVR0lBAwwCgYI 9 | KwYBBQUHAwEwHQYDVR0OBBYEFJOzQR0udLrz7IiLP3q+FehLxijkMB8GA1UdIwQY 10 | MBaAFGZTlPQV0b1naLBRNzI14aSq3gd8MA0GCSqGSIb3DQEBCwUAA4IBAQCRk6TP 11 | XKfSy2fwodsYe1bedhL9mlm9xDDOu6ILkDZtCpbOwrjeSf+U7VQYvdlI8QCeQyEK 12 | ZE/S3S5UzOjEv7fQpyqfG9aJJbH7OQwG25ShiX86Kt/RAkgtjyCmKevhT6uSs5fa 13 | BsdYWnS9WHWH5ZkWkjZt1K2xYJP4Lqg9VpHy/YNz4b5swXEWf+MdayVSgzPxoviG 14 | zXnsTrxiTcGvelGFm/lYc42u6cSqrHoLtfniyaGNvPwrfBsiY/cypN4GZLNgEk80 15 | /tcAg2TeUGNbMbT4Rko1OMLxMT9zRzgJyjd/XyW/5fCE/Xm0q7VYo1EF1ScywU1B 16 | XwZH9DJ6Ud0s8/j+ 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /test/scapy/layers/tls/pki/srv_key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDM8fGbYC1grvKY 3 | DScp2cAJWUwPSjCoUt/lsSGfT8M9VpPdX8b3s/ZVi+eS4t7yhUm0oSz0/XaoZ8oE 4 | IGARGKbyqbamHdmq5dnbr+avVVef/1KJZeaAYoAhlLzPgRvLZ8KdtQV3BKbHiBiA 5 | eGiVNt6XG7Zhh0IadZhFgus+MhHIm4ZCOY1NErdYGxnznSuhmILK1zsk+wk5sLzC 6 | lc+CKXUWKT9CIBcrTUCMVmytug80hbF/QHlxeLelBLuU97VBle58640MeWhZ78uz 7 | +j54Hu5nTHrd4Jnv2ufvsgldvoAgIQWDLETbXSp2KaWwI4h0B1Qi1il6kvVvLZ7n 8 | +CYrnFhlAgMBAAECggEAIPA9uZAimuhjOwbaJYLGt3nvnIF7AoKXU449biJeqawR 9 | hcHP852r2KHsrRHjbSz45JwG4rUd7gEIWdNuPTEuG9Ak99vSUQIyGnnR5JodxCw/ 10 | 8q869aVfHIaQNfV1JyLdB4XBhBhuSaFY9sTjYh/4dGbS0Cfx+titiXZ6InvfmdMD 11 | eLd/ZO35/BwtWN3J2ntRziTTREKLeEYFEe7FtXKGwDGIsvVn7egckefKMnflhMFA 12 | SuoPn2VvTqmhiwSuATdx1TP4XOVdVzuL2wT7brS7qHvabRDBKdVOfrNGOoMdnnua 13 | ursIQjQindNT8kVK8EGxws9eFr/dooYYFR72IusTfQKBgQDuQBzzKEtt86uRCbZX 14 | Y3lu0MJnR5OOodfGBBYF9Ue+W3OJTd9EvXLSgLBLvwirB7lsNXgXf8LHCTQOtF3H 15 | lnB8jE5OFSDGeSKWmUwZS+KVzq8vy7Qylp9i6x4pElwGUeba6AqeZZ+jUUn/HzdB 16 | s2pO8YWqyOp/Zo/m8P+vPZN4fwKBgQDcNqJ4Dutt/i60E9kaktGQVQODRNMhYCEq 17 | E5fhwJiZ0E9FBeuKPKjo7dGIux3KPQPBv3T0zjmB+M5QERVe5/ID8iytgbHGlnsg 18 | 916iTN9rvi1Gk518vyFPsYjX9pPiQIayRBQKOXSYIkY+6rj2384XPRlZrN8D9n3Q 19 | +An1JXfdGwKBgDs3YjqpnD3i35S4BkMoLUl2x6rl5m4AGeJUp6ipc0CD+G57FXA/ 20 | aieZ5rec7qmbzOFxVLz6e03/Ipo5CEoQQTsjoF7V74SFHSyzQ2/SJao4aeCGT+52 21 | 83yhlah9sLO9bZShMep2tbvg+3RWrOQ+lMC0VRXCxE4QDtpGsjY7Jsk/AoGAPstV 22 | iOa4O6U/rBn8zpcPKxkS51u42MuQqW7s4HMLENFVyVjm0YR6pfEqztKMrB6584Wk 23 | 1Cn6PBW2vx4f+fAqEvX7x340M2y1r7DaS22gSBjy0C1Hu0rFNPRrESo/AUVlI3BG 24 | RqQbm0YqwcYs+DjZi8bgc7HX5kljlzMjo8QLagECgYA1DHAWv4WVrHt4I8V4ZCth 25 | 9DZEtEOFpYjuoFh/xSIMZLsnvWRuyYVWcQwAqmK0Ew4m5opHFsQzABeGLVsK5aHX 26 | zmbYiRUuZGVpyc7c5XXomw50X8ajfQ+P21OPPc33h96cdHi2qbJIejZPia6A6ThU 27 | u13D93hAM6bzH6Ds5FPUQw== 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /test/scapy/layers/tls/pki/srv_key_ed25519.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MC4CAQAwBQYDK2VwBCIEIGu36oadjA6raCmwtImfAWI/DSCENM/uQCsUaClVoUTZ 3 | -----END PRIVATE KEY----- 4 | -------------------------------------------------------------------------------- /test/scapy/layers/vrrp.uts: -------------------------------------------------------------------------------- 1 | % VRRP regression tests for Scapy 2 | 3 | # More information at http://www.secdev.org/projects/UTscapy/ 4 | 5 | 6 | ############ 7 | ############ 8 | + VRRP tests 9 | 10 | = VRRP - build 11 | s = raw(IP()/VRRP()) 12 | s == b'E\x00\x00$\x00\x01\x00\x00@p|g\x7f\x00\x00\x01\x7f\x00\x00\x01!\x01d\x00\x00\x01z\xfd\x00\x00\x00\x00\x00\x00\x00\x00' 13 | 14 | = VRRP - dissection 15 | p = IP(s) 16 | VRRP in p and p[VRRP].chksum == 0x7afd 17 | 18 | = VRRP IPv6 - build 19 | s6 = raw(IPv6()/VRRPv3()) 20 | s6 == b'`\x00\x00\x00\x00\x08p@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x011\x01d\x01\x00dj\x1f' 21 | 22 | = VRRP IPv6 - dissection 23 | p6 = IPv6(s6) 24 | VRRPv3 in p6 and p6[VRRPv3].chksum == 0x6a1f 25 | 26 | = VRRP - chksums 27 | # VRRPv3 28 | p = Ether(src="00:00:5e:00:02:02",dst="01:00:5e:00:00:12")/IP(src="20.0.0.3", dst="224.0.0.18",ttl=255)/VRRPv3(priority=254,vrid=2,version=3,adv=1,addrlist=["20.0.1.2","20.0.1.3"]) 29 | a = Ether(raw(p)) 30 | assert a[VRRPv3].chksum == 0xb25e 31 | # VRRPv1 32 | p = Ether(src="00:00:5e:00:02:02",dst="01:00:5e:00:00:12")/IP(src="20.0.0.3", dst="224.0.0.18",ttl=255)/VRRP(priority=254,vrid=2,version=1,adv=1,addrlist=["20.0.1.2","20.0.1.3"]) 33 | b = Ether(raw(p)) 34 | assert b[VRRP].chksum == 0xc6f4 35 | 36 | = VRRP IPv6 - chksums 37 | # VRRPv3 IPv6 38 | p = Ether(src="00:00:5e:00:02:02",dst="33:33:00:00:00:12")/IPv6(src="2001:db8::1", dst="ff02::12",hlim=255)/VRRPv3(priority=254,vrid=2,version=3,adv=1,ipcount=2,addrlist=["2001:db8::2","2001:db8::3"]) 39 | c = Ether(raw(p)) 40 | assert c[VRRPv3].chksum == 0x481b 41 | --------------------------------------------------------------------------------