├── .appveyor.yml ├── .config ├── appveyor │ ├── InstallNpcap.ps1 │ └── InstallWindumpNpcap.ps1 ├── ci │ ├── install.sh │ ├── openssl.py │ └── test.sh ├── codespell_ignore.txt └── mypy │ ├── mypy.ini │ ├── mypy_check.py │ ├── mypy_deployment_stats.py │ └── mypy_enabled.txt ├── .gitattributes ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── BUGS.yml │ └── config.yml ├── PULL_REQUEST_TEMPLATE.md ├── codecov.yml └── workflows │ └── unittests.yml ├── .gitignore ├── .readthedocs.yml ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── MANIFEST.in ├── README ├── README.md ├── doc ├── 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 │ │ ├── pki │ │ ├── ca_cert.der │ │ ├── ca_key.der │ │ ├── srv_cert.pem │ │ └── srv_key.pem │ │ ├── tls_session_13 │ │ ├── 01_cli.raw │ │ ├── 02_srv.raw │ │ ├── 03_cli.raw │ │ ├── 04_srv.raw │ │ ├── 05_srv.raw │ │ ├── 06_cli.raw │ │ ├── 07_srv.raw │ │ ├── 08_cli.raw │ │ └── cli_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-demo.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-themes-demo.gif │ │ │ ├── animation-scapy-uds.svg │ │ │ ├── animation-scapy-uds2.svg │ │ │ └── animation-scapy-uds3.svg │ │ ├── automotive │ │ │ ├── CAN-full-frame.jpg │ │ │ ├── DC-ZGW-CAN-Bus-.png │ │ │ ├── Simple-CAN-Bus-.png │ │ │ ├── XCP_ReferenceBook.png │ │ │ ├── ZGW-CAN-Bus-.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 │ │ ├── default-values-ip.pdf │ │ ├── default-values-ip.png │ │ ├── fieldsmanagement.pdf │ │ ├── fieldsmanagement.png │ │ ├── graph_traceroute.png │ │ ├── http_tcp.png │ │ ├── ipid.png │ │ ├── isakmp_dump.png │ │ ├── pipetool_demo.svg │ │ ├── pipetool_engine.png │ │ ├── scapy-concept.pdf │ │ ├── scapy-concept.png │ │ ├── scapy-win-screenshot1.png │ │ ├── scapy-win-screenshot2.png │ │ ├── scapy_logo.png │ │ ├── testing-taxonomy.png │ │ ├── trace3d_1.png │ │ ├── trace3d_2.png │ │ └── traceroute_worldplot.png │ ├── index.rst │ ├── installation.rst │ ├── introduction.rst │ ├── layers │ │ ├── automotive.rst │ │ ├── bluetooth.rst │ │ ├── http.rst │ │ ├── index.rst │ │ ├── netflow.rst │ │ ├── pnio.rst │ │ ├── sctp.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 ├── run_scapy ├── run_scapy.bat ├── scapy ├── __init__.py ├── __main__.py ├── all.py ├── ansmachine.py ├── arch │ ├── __init__.py │ ├── bpf │ │ ├── __init__.py │ │ ├── consts.py │ │ ├── core.py │ │ └── supersocket.py │ ├── common.py │ ├── libpcap.py │ ├── linux.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 │ │ ├── bmw │ │ │ ├── __init__.py │ │ │ ├── definitions.py │ │ │ └── hsfz.py │ │ ├── ccp.py │ │ ├── doip.py │ │ ├── ecu.py │ │ ├── enumerator.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 │ │ ├── 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 │ ├── dce_rpc.py │ ├── diameter.py │ ├── dtp.py │ ├── eddystone.py │ ├── eigrp.py │ ├── enipTCP.py │ ├── erspan.py │ ├── ethercat.py │ ├── etherip.py │ ├── exposure_notification.py │ ├── geneve.py │ ├── gtp.py │ ├── gtp_v2.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 │ ├── modbus.py │ ├── mount.py │ ├── mpls.py │ ├── mqtt.py │ ├── mqttsn.py │ ├── nfs.py │ ├── nlm.py │ ├── nsh.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 │ ├── ppi_cace.py │ ├── ppi_geotag.py │ ├── ripng.py │ ├── roce.py │ ├── rpl.py │ ├── rpl_metrics.py │ ├── rsvp.py │ ├── rtr.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 │ ├── socks.py │ ├── spbm.py │ ├── tacacs.py │ ├── tzsp.py │ ├── ubberlogger.py │ ├── vqp.py │ ├── vtp.py │ ├── wireguard.py │ └── wpa_eapol.py ├── dadict.py ├── data.py ├── error.py ├── extlib.py ├── fields.py ├── interfaces.py ├── layers │ ├── __init__.py │ ├── all.py │ ├── bluetooth.py │ ├── bluetooth4LE.py │ ├── can.py │ ├── clns.py │ ├── dhcp.py │ ├── dhcp6.py │ ├── dns.py │ ├── dot11.py │ ├── dot15d4.py │ ├── eap.py │ ├── gprs.py │ ├── hsrp.py │ ├── http.py │ ├── inet.py │ ├── inet6.py │ ├── ipsec.py │ ├── ir.py │ ├── isakmp.py │ ├── l2.py │ ├── l2tp.py │ ├── llmnr.py │ ├── lltd.py │ ├── mgcp.py │ ├── mobileip.py │ ├── netbios.py │ ├── netflow.py │ ├── ntp.py │ ├── pflog.py │ ├── ppi.py │ ├── ppp.py │ ├── pptp.py │ ├── radius.py │ ├── rip.py │ ├── rtp.py │ ├── sctp.py │ ├── sixlowpan.py │ ├── skinny.py │ ├── smb.py │ ├── smb2.py │ ├── snmp.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 │ │ │ ├── pkcs1.py │ │ │ ├── prf.py │ │ │ └── suites.py │ │ ├── extensions.py │ │ ├── handshake.py │ │ ├── handshake_sslv2.py │ │ ├── keyexchange.py │ │ ├── keyexchange_tls13.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 │ ├── structures.py │ └── winpcapy.py ├── main.py ├── modules │ ├── __init__.py │ ├── krack │ │ ├── __init__.py │ │ ├── automaton.py │ │ └── crypto.py │ ├── nmap.py │ ├── p0f.py │ ├── p0fv2.py │ ├── six.py │ └── voip.py ├── packet.py ├── pipetool.py ├── plist.py ├── pton_ntop.py ├── 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 │ ├── generate_ethertypes.py │ └── scapy_pyannotate.py ├── utils.py ├── utils6.py └── volatile.py ├── setup.cfg ├── setup.py ├── test ├── answering_machines.uts ├── benchmark │ ├── common.py │ ├── dissection_and_build.py │ └── latency_router.py ├── bpf.uts ├── cert.uts ├── configs │ ├── bsd.utsc │ ├── linux.utsc │ ├── solaris.utsc │ ├── windows.utsc │ └── windows2.utsc ├── contrib │ ├── altbeacon.uts │ ├── aoe.uts │ ├── automotive │ │ ├── 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 │ │ ├── someip.uts │ │ ├── uds.uts │ │ ├── uds_utils.uts │ │ └── xcp │ │ │ ├── xcp.uts │ │ │ └── xcp_comm.uts │ ├── avs.uts │ ├── bfd.uts │ ├── bgp.uts │ ├── bier.uts │ ├── bp.uts │ ├── cansocket.uts │ ├── cansocket_native.uts │ ├── cansocket_python_can.uts │ ├── carp.uts │ ├── cdp.uts │ ├── chdlc.uts │ ├── coap.uts │ ├── concox.uts │ ├── dce_rpc.uts │ ├── diameter.uts │ ├── dtp.uts │ ├── eddystone.uts │ ├── eigrp.uts │ ├── enipTCP.uts │ ├── erspan.uts │ ├── ethercat.uts │ ├── etherip.uts │ ├── exposure_notification.uts │ ├── geneve.uts │ ├── gtp.uts │ ├── gtp_v2.uts │ ├── homeplugav.uts │ ├── homepluggp.uts │ ├── homeplugsg.uts │ ├── http2.uts │ ├── ibeacon.uts │ ├── icmp_extensions.uts │ ├── iec104.uts │ ├── ife.uts │ ├── igmp.uts │ ├── igmpv3.uts │ ├── ikev2.uts │ ├── isis.uts │ ├── isotp.uts │ ├── isotpscan.uts │ ├── knx.uts │ ├── lacp.uts │ ├── ldp.uts │ ├── lldp.uts │ ├── loraphy2wan.uts │ ├── ltp.uts │ ├── mac_control.uts │ ├── macsec.uts │ ├── modbus.uts │ ├── mount.uts │ ├── mpls.uts │ ├── mqtt.uts │ ├── mqttsn.uts │ ├── nfs.uts │ ├── nlm.uts │ ├── nsh.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 │ ├── ppi_cace.uts │ ├── ppi_geotag.uts │ ├── ripng.uts │ ├── roce.uts │ ├── rpl.uts │ ├── rsvp.uts │ ├── rtr.uts │ ├── sdnv.uts │ ├── sebek.uts │ ├── send.uts │ ├── socks.uts │ ├── spbm.uts │ ├── tacacs.uts │ ├── tzsp.uts │ ├── vqp.uts │ ├── vtp.uts │ └── wireguard.uts ├── fields.uts ├── imports.uts ├── linux.uts ├── nmap.uts ├── p0f.uts ├── p0fv2.uts ├── packet.uts ├── pcaps │ ├── bad_rsn_parsing_overrides_ssid.pcap │ ├── candump_gmlan_scanner.log.gz │ ├── doip.pcap.gz │ ├── ecu_trace.pcap.gz │ ├── gmlan_trace.candump.gz │ ├── http2_h2c.pcap │ ├── http_chunk.pcap.gz │ ├── http_compressed-brotli.pcap │ ├── http_compressed-zstd.pcap │ ├── http_compressed.pcap │ ├── http_content_length.pcap │ ├── http_tcp_psh.pcap.gz │ ├── ipfix.pcap │ ├── macos.pcapng.gz │ ├── netflowv9.pcap │ ├── pfcp.pcap │ ├── tls_new-session-ticket.pcap │ ├── tls_tcp_frag.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 │ │ ├── bluetooth.uts │ │ ├── bluetooth4LE.uts │ │ ├── can.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 │ │ ├── l2.uts │ │ ├── l2tp.uts │ │ ├── llmnr.uts │ │ ├── lltd.uts │ │ ├── mgcp.uts │ │ ├── mobileip.uts │ │ ├── netbios.uts │ │ ├── netflow.uts │ │ ├── ntp.uts │ │ ├── ppp.uts │ │ ├── pptp.uts │ │ ├── radius.uts │ │ ├── rip.uts │ │ ├── rtp.uts │ │ ├── sctp.uts │ │ ├── skinny.uts │ │ ├── smb.uts │ │ ├── smb2.uts │ │ ├── snmp.uts │ │ ├── tftp.uts │ │ ├── usb.uts │ │ ├── vrrp.uts │ │ ├── vxlan.uts │ │ └── x509.uts ├── sendsniff.uts ├── sslv2.uts ├── tftp.uts ├── tls.uts ├── tls │ ├── __init__.py │ ├── example_client.py │ ├── example_server.py │ ├── pki │ │ ├── ca_cert.pem │ │ ├── ca_key.pem │ │ ├── cli_cert.pem │ │ ├── cli_key.pem │ │ ├── srv_cert.pem │ │ └── srv_key.pem │ └── tests_tls_netaccess.uts ├── tls13.uts ├── tools │ ├── isotpscanner.uts │ ├── obdscanner.uts │ └── xcpscanner.uts ├── tuntap.uts └── windows.uts └── tox.ini /.config/appveyor/InstallNpcap.ps1: -------------------------------------------------------------------------------- 1 | # Install Npcap on the machine. 2 | 3 | # Config: 4 | $npcap_oem_file = "npcap-1.31-oem.exe" 5 | 6 | # Note: because we need the /S option (silent), this script has two cases: 7 | # - The script is runned from a master build, then use the secure variable 'npcap_oem_key' which will be available 8 | # to decode the very recent npcap install oem file and use it 9 | # - The script is runned from a PR, then use the provided archived 0.96 version, which is the last public one to 10 | # provide support for the /S option 11 | 12 | if (Test-Path Env:npcap_oem_key){ # Key is here: on master 13 | echo "Using Npcap OEM version" 14 | # Unpack the key 15 | $user, $pass = (Get-ChildItem Env:npcap_oem_key).Value.replace("`"", "").split(",") 16 | if(!$user -Or !$pass){ 17 | Throw (New-Object System.Exception) 18 | } 19 | $file = $PSScriptRoot+"\"+$npcap_oem_file 20 | # Download oem file using (super) secret credentials 21 | $pair = "${user}:${pass}" 22 | $encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair)) 23 | $basicAuthValue = "Basic $encodedCreds" 24 | $headers = @{ Authorization = $basicAuthValue } 25 | $secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force 26 | $credential = New-Object System.Management.Automation.PSCredential($user, $secpasswd) 27 | Invoke-WebRequest -uri (-join("https://nmap.org/npcap/oem/dist/",$npcap_oem_file)) -OutFile $file -Headers $headers -Credential $credential 28 | } else { # No key: PRs 29 | echo "Using backup 0.96" 30 | $file = $PSScriptRoot+"\npcap-0.96.exe" 31 | # Download the 0.96 file from nmap servers 32 | wget "https://nmap.org/npcap/dist/npcap-0.96.exe" -UseBasicParsing -OutFile $file 33 | # Now let's check its checksum 34 | $_chksum = $(CertUtil -hashfile $file SHA256)[1] -replace " ","" 35 | if ($_chksum -ne "83667e1306fdcf7f9967c10277b36b87e50ee8812e1ee2bb9443bdd065dc04a1"){ 36 | echo "Checksums does NOT match !" 37 | exit 38 | } else { 39 | echo "Checksums matches !" 40 | } 41 | } 42 | echo ('Installing: ' + $file) 43 | 44 | # Run installer 45 | Start-Process $file -ArgumentList "/loopback_support=yes /S" -wait 46 | if($?) { 47 | echo "Npcap installation completed" 48 | } 49 | -------------------------------------------------------------------------------- /.config/appveyor/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 | wget $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/ci/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Usage: 4 | # ./install.sh [install mode] 5 | 6 | # Detect install mode 7 | if [[ "${1}" == "libpcap" ]]; then 8 | SCAPY_USE_LIBPCAP="yes" 9 | if [[ ! -z "$GITHUB_ACTIONS" ]]; then 10 | echo "SCAPY_USE_LIBPCAP=yes" >> $GITHUB_ENV 11 | fi 12 | fi 13 | 14 | # Install on osx 15 | if [ "$OSTYPE" = "darwin"* ] || [ "$TRAVIS_OS_NAME" = "osx" ] 16 | then 17 | if [ ! -z $SCAPY_USE_LIBPCAP ] 18 | then 19 | brew update 20 | brew install libpcap 21 | fi 22 | fi 23 | 24 | # Install wireshark data, ifconfig & vcan 25 | if [ "$OSTYPE" = "linux-gnu" ] || [ "$TRAVIS_OS_NAME" = "linux" ] 26 | then 27 | sudo apt-get update 28 | sudo apt-get -qy install tshark net-tools || exit 1 29 | sudo apt-get -qy install can-utils build-essential linux-headers-$(uname -r) linux-modules-extra-$(uname -r) || exit 1 30 | fi 31 | 32 | # Make sure libpcap is installed 33 | if [ ! -z $SCAPY_USE_LIBPCAP ] 34 | then 35 | sudo apt-get -qy install libpcap-dev || exit 1 36 | fi 37 | 38 | # On Travis, "osx" dependencies are installed in .travis.yml 39 | if [ "$TRAVIS_OS_NAME" != "osx" ] 40 | then 41 | # Update pip & setuptools (tox uses those) 42 | python -m pip install --upgrade pip setuptools --ignore-installed 43 | 44 | # Make sure tox is installed and up to date 45 | python -m pip install -U tox --ignore-installed 46 | fi 47 | 48 | # Dump Environment (so that we can check PATH, UT_FLAGS, etc.) 49 | openssl version 50 | set 51 | -------------------------------------------------------------------------------- /.config/ci/openssl.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # Copyright (C) Gabriel Potter 3 | 4 | """ 5 | Create a duplicate of the OpenSSL config to be able to use TLS < 1.2 6 | This returns the path to this new config file. 7 | """ 8 | 9 | import os 10 | import re 11 | import subprocess 12 | import tempfile 13 | 14 | # Get OpenSSL config file 15 | OPENSSL_DIR = re.search( 16 | b"OPENSSLDIR: \"(.*)\"", 17 | subprocess.Popen( 18 | ["openssl", "version", "-d"], 19 | stdout=subprocess.PIPE 20 | ).communicate()[0] 21 | ).group(1).decode() 22 | OPENSSL_CONFIG = os.path.join(OPENSSL_DIR, 'openssl.cnf') 23 | 24 | # https://askubuntu.com/a/1233456 25 | HEADER = b"openssl_conf = default_conf\n" 26 | FOOTER = b""" 27 | [ default_conf ] 28 | 29 | ssl_conf = ssl_sect 30 | 31 | [ssl_sect] 32 | 33 | system_default = system_default_sect 34 | 35 | [system_default_sect] 36 | MinProtocol = TLSv1.2 37 | CipherString = DEFAULT:@SECLEVEL=1 38 | """ 39 | 40 | # Copy and edit 41 | with open(OPENSSL_CONFIG, 'rb') as fd: 42 | DATA = fd.read() 43 | 44 | DATA = HEADER + DATA + FOOTER 45 | 46 | with tempfile.NamedTemporaryFile(suffix=".cnf", delete=False) as fd: 47 | fd.write(DATA) 48 | print(fd.name) 49 | -------------------------------------------------------------------------------- /.config/codespell_ignore.txt: -------------------------------------------------------------------------------- 1 | aci 2 | ans 3 | archtypes 4 | ba 5 | byteorder 6 | cace 7 | cas 8 | cros 9 | doas 10 | doubleclick 11 | eventtypes 12 | fo 13 | gost 14 | iff 15 | inout 16 | microsof 17 | mitre 18 | nd 19 | negociate 20 | ot 21 | referer 22 | ser 23 | te 24 | tim 25 | ue 26 | uint 27 | vas 28 | wan 29 | wanna 30 | webp 31 | Ether 32 | ether 33 | -------------------------------------------------------------------------------- /.config/mypy/mypy.ini: -------------------------------------------------------------------------------- 1 | [mypy] 2 | 3 | # Internal Scapy modules that we ignore 4 | 5 | [mypy-scapy.modules.six,scapy.modules.six.moves,scapy.libs.winpcapy] 6 | ignore_errors = True 7 | ignore_missing_imports = True 8 | 9 | # Layers specific config 10 | 11 | [mypy-scapy.layers.*,scapy.contrib.*] 12 | warn_return_any = False 13 | 14 | # External libraries that we ignore 15 | 16 | [mypy-IPython] 17 | ignore_missing_imports = True 18 | 19 | [mypy-colorama] 20 | ignore_missing_imports = True 21 | 22 | [mypy-traitlets.config.loader] 23 | ignore_missing_imports = True 24 | 25 | [mypy-pyx] 26 | ignore_missing_imports = True 27 | 28 | [mypy-matplotlib.lines] 29 | ignore_missing_imports = True 30 | 31 | [mypy-prompt_toolkit.*] 32 | ignore_missing_imports = True 33 | -------------------------------------------------------------------------------- /.config/mypy/mypy_check.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Gabriel Potter 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | Performs Static typing checks over Scapy's codebase 8 | """ 9 | 10 | # IMPORTANT NOTE 11 | # 12 | # Because we are rolling out mypy tests progressively, 13 | # we currently use --follow-imports=skip. This means that 14 | # mypy doesn't check consistency between the imports (different files). 15 | # 16 | # Once each file has been processed individually, we'll remove that to 17 | # check the inconsistencies across the files 18 | 19 | import io 20 | import os 21 | import sys 22 | 23 | from mypy.main import main as mypy_main 24 | 25 | # Load files 26 | 27 | localdir = os.path.split(__file__)[0] 28 | 29 | with io.open(os.path.join(localdir, "mypy_enabled.txt")) as fd: 30 | FILES = [l.strip() for l in fd.readlines() if l.strip() and l[0] != "#"] 31 | 32 | if not FILES: 33 | print("No files specified. Arborting") 34 | sys.exit(0) 35 | 36 | # Generate mypy arguments 37 | 38 | ARGS = [ 39 | # strictness: same as --strict minus --disallow-subclassing-any 40 | "--warn-unused-configs", 41 | "--disallow-any-generics", 42 | "--disallow-untyped-calls", 43 | "--disallow-untyped-defs", 44 | "--disallow-incomplete-defs", 45 | "--check-untyped-defs", 46 | "--disallow-untyped-decorators", 47 | "--no-implicit-optional", 48 | "--warn-redundant-casts", 49 | "--warn-unused-ignores", 50 | "--warn-return-any", 51 | "--no-implicit-reexport", 52 | "--strict-equality", 53 | "--ignore-missing-imports", 54 | # config 55 | "--follow-imports=skip", # Remove eventually 56 | "--config-file=" + os.path.abspath( 57 | os.path.join( 58 | localdir, 59 | "mypy.ini" 60 | ) 61 | ), 62 | "--show-traceback", 63 | ] + [os.path.abspath(f) for f in FILES] 64 | 65 | # Run mypy over the files 66 | 67 | mypy_main(None, sys.stdout, sys.stderr, ARGS) 68 | -------------------------------------------------------------------------------- /.config/mypy/mypy_deployment_stats.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See https://scapy.net for more information 3 | # Copyright (C) Gabriel Potter 4 | # This program is published under a GPLv2 license 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)) 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 = MODULES[mod] 44 | if f in FILES: 45 | e += lines 46 | else: 47 | REMAINING[mod].append(f) 48 | l += lines 49 | MODULES[mod] = (e, l) 50 | 51 | ENABLED = sum(x[0] for x in MODULES.values()) 52 | TOTAL = sum(x[1] for x in MODULES.values()) 53 | 54 | print("*The numbers correspond to the amount of lines per files processed*") 55 | print("**MyPy Support: %.2f%%**" % (ENABLED / TOTAL * 100)) 56 | for mod, dat in MODULES.items(): 57 | print("- `%s`: %.2f%%" % (mod, dat[0] / dat[1] * 100)) 58 | 59 | print() 60 | COREMODS = REMAINING["[core]"] 61 | if COREMODS: 62 | print("Core modules still untypes:") 63 | for mod in COREMODS: 64 | print("- `%s`" % mod) 65 | 66 | -------------------------------------------------------------------------------- /.config/mypy/mypy_enabled.txt: -------------------------------------------------------------------------------- 1 | # This file registers all files that have already been processed as part of 2 | # https://github.com/secdev/scapy/issues/2158, and therefore will be enforced 3 | # with unit tests in future development. 4 | 5 | # Style cheet: https://mypy.readthedocs.io/en/latest/cheat_sheet.html 6 | 7 | # CORE 8 | scapy/__init__.py 9 | scapy/__main__.py 10 | scapy/all.py 11 | scapy/ansmachine.py 12 | scapy/arch/__init__.py 13 | scapy/arch/common.py 14 | scapy/arch/linux.py 15 | scapy/arch/unix.py 16 | scapy/asn1/asn1.py 17 | scapy/asn1/ber.py 18 | scapy/asn1/mib.py 19 | scapy/asn1fields.py 20 | scapy/asn1packet.py 21 | scapy/base_classes.py 22 | scapy/compat.py 23 | scapy/config.py 24 | scapy/consts.py 25 | scapy/dadict.py 26 | scapy/data.py 27 | scapy/error.py 28 | scapy/extlib.py 29 | scapy/fields.py 30 | scapy/interfaces.py 31 | scapy/main.py 32 | scapy/packet.py 33 | scapy/plist.py 34 | scapy/pton_ntop.py 35 | scapy/route.py 36 | scapy/route6.py 37 | scapy/sendrecv.py 38 | scapy/sessions.py 39 | scapy/supersocket.py 40 | scapy/themes.py 41 | scapy/utils.py 42 | scapy/utils6.py 43 | 44 | # LAYERS 45 | scapy/layers/can.py 46 | scapy/layers/l2.py 47 | 48 | # CONTRIB 49 | scapy/contrib/automotive/bmw/hsfz.py 50 | scapy/contrib/automotive/doip.py 51 | scapy/contrib/automotive/ecu.py 52 | scapy/contrib/automotive/gm/gmlan_ecu_states.py 53 | scapy/contrib/automotive/gm/gmlan_logging.py 54 | scapy/contrib/automotive/gm/gmlan_scanner.py 55 | scapy/contrib/automotive/gm/gmlanutils.py 56 | scapy/contrib/automotive/kwp.py 57 | scapy/contrib/automotive/obd/scanner.py 58 | scapy/contrib/automotive/scanner/configuration.py 59 | scapy/contrib/automotive/scanner/enumerator.py 60 | scapy/contrib/automotive/scanner/executor.py 61 | scapy/contrib/automotive/scanner/graph.py 62 | scapy/contrib/automotive/scanner/staged_test_case.py 63 | scapy/contrib/automotive/scanner/test_case.py 64 | scapy/contrib/automotive/uds_ecu_states.py 65 | scapy/contrib/automotive/uds_logging.py 66 | scapy/contrib/cansocket_native.py 67 | scapy/contrib/cansocket_python_can.py 68 | #scapy/contrib/http2.py # needs to be fixed 69 | scapy/contrib/isotp/isotp_native_socket.py 70 | scapy/contrib/isotp/isotp_packet.py 71 | scapy/contrib/isotp/isotp_scanner.py 72 | scapy/contrib/isotp/isotp_soft_socket.py 73 | scapy/contrib/isotp/isotp_utils.py 74 | scapy/contrib/roce.py 75 | -------------------------------------------------------------------------------- /.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-] 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 for Python2 and Python3 (using `tox` or, `cd test && ./run_tests_py2, cd test && ./run_tests_py3`) 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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.pyo 3 | dist/ 4 | build/ 5 | MANIFEST 6 | *.egg-info/ 7 | scapy/VERSION 8 | test/*.html 9 | .coverage* 10 | .tox 11 | .ipynb_checkpoints 12 | .mypy_cache 13 | .vscode 14 | doc/scapy/_build 15 | doc/scapy/api 16 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | # Readthedocs config file. 2 | 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html#supported-settings 4 | # Copied from https://github.com/pycontribs/jira/blob/master/.readthedocs.yml 5 | 6 | version: 2 7 | 8 | formats: 9 | - epub 10 | - pdf 11 | 12 | build: 13 | image: latest 14 | 15 | python: 16 | version: 3.7 17 | install: 18 | - method: pip 19 | path: . 20 | extra_requirements: 21 | - docs 22 | -------------------------------------------------------------------------------- /.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 | include scapy/VERSION 5 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | README.md -------------------------------------------------------------------------------- /doc/notebooks/tls/images/handshake_tls12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/notebooks/tls/images/handshake_tls12.png -------------------------------------------------------------------------------- /doc/notebooks/tls/images/handshake_tls13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/notebooks/tls/images/handshake_tls13.png -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/pki/ca_cert.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/notebooks/tls/raw_data/pki/ca_cert.der -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/pki/ca_key.der: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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_session_13/01_cli.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/notebooks/tls/raw_data/tls_session_13/01_cli.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/02_srv.raw: -------------------------------------------------------------------------------- 1 |  2 | ( -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/03_cli.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/notebooks/tls/raw_data/tls_session_13/03_cli.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/04_srv.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/notebooks/tls/raw_data/tls_session_13/05_srv.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/06_cli.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/notebooks/tls/raw_data/tls_session_13/06_cli.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/07_srv.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/notebooks/tls/raw_data/tls_session_13/07_srv.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/08_cli.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/notebooks/tls/raw_data/tls_session_13/08_cli.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_13/cli_key.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/notebooks/tls/raw_data/tls_session_13/cli_key.raw -------------------------------------------------------------------------------- /doc/notebooks/tls/raw_data/tls_session_compromised/01_cli.raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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 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/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/ATMT_HelloWorld.png -------------------------------------------------------------------------------- /doc/scapy/graphics/ATMT_TFTP_read.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/ATMT_TFTP_read.png -------------------------------------------------------------------------------- /doc/scapy/graphics/animations/animation-scapy-themes-demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/animations/animation-scapy-themes-demo.gif -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/CAN-full-frame.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/automotive/CAN-full-frame.jpg -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/DC-ZGW-CAN-Bus-.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/automotive/DC-ZGW-CAN-Bus-.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/Simple-CAN-Bus-.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/automotive/Simple-CAN-Bus-.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/XCP_ReferenceBook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/automotive/XCP_ReferenceBook.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/ZGW-CAN-Bus-.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/automotive/ZGW-CAN-Bus-.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/can-bus-states.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/automotive/can-bus-states.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/can-frame-socket-can.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/automotive/can-frame-socket-can.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/diag-stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/automotive/diag-stack.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/isotp-flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/automotive/isotp-flow.png -------------------------------------------------------------------------------- /doc/scapy/graphics/automotive/isotp-frames.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/automotive/isotp-frames.png -------------------------------------------------------------------------------- /doc/scapy/graphics/ble_eddystone_url.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/ble_eddystone_url.png -------------------------------------------------------------------------------- /doc/scapy/graphics/ble_ibeacon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/ble_ibeacon.png -------------------------------------------------------------------------------- /doc/scapy/graphics/command-ls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/command-ls.png -------------------------------------------------------------------------------- /doc/scapy/graphics/default-values-ip.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/default-values-ip.pdf -------------------------------------------------------------------------------- /doc/scapy/graphics/default-values-ip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/default-values-ip.png -------------------------------------------------------------------------------- /doc/scapy/graphics/fieldsmanagement.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/fieldsmanagement.pdf -------------------------------------------------------------------------------- /doc/scapy/graphics/fieldsmanagement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/fieldsmanagement.png -------------------------------------------------------------------------------- /doc/scapy/graphics/graph_traceroute.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/graph_traceroute.png -------------------------------------------------------------------------------- /doc/scapy/graphics/http_tcp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/http_tcp.png -------------------------------------------------------------------------------- /doc/scapy/graphics/ipid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/ipid.png -------------------------------------------------------------------------------- /doc/scapy/graphics/isakmp_dump.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/isakmp_dump.png -------------------------------------------------------------------------------- /doc/scapy/graphics/pipetool_demo.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | pipe 11 | 12 | 13 | 14 | 2518161510704 15 | 16 | TransformDrain 17 | 18 | 19 | 20 | 2518161510896 21 | 22 | WiresharkSink 23 | 24 | 25 | 26 | 2518161510704->2518161510896 27 | 28 | 29 | 30 | 31 | 32 | 2518161510992 33 | 34 | SniffSource 35 | 36 | 37 | 38 | 2518161510992->2518161510704 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /doc/scapy/graphics/pipetool_engine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/pipetool_engine.png -------------------------------------------------------------------------------- /doc/scapy/graphics/scapy-concept.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/scapy-concept.pdf -------------------------------------------------------------------------------- /doc/scapy/graphics/scapy-concept.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/scapy-concept.png -------------------------------------------------------------------------------- /doc/scapy/graphics/scapy-win-screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/scapy-win-screenshot1.png -------------------------------------------------------------------------------- /doc/scapy/graphics/scapy-win-screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/scapy-win-screenshot2.png -------------------------------------------------------------------------------- /doc/scapy/graphics/scapy_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/scapy_logo.png -------------------------------------------------------------------------------- /doc/scapy/graphics/testing-taxonomy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/testing-taxonomy.png -------------------------------------------------------------------------------- /doc/scapy/graphics/trace3d_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/trace3d_1.png -------------------------------------------------------------------------------- /doc/scapy/graphics/trace3d_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/doc/scapy/graphics/trace3d_2.png -------------------------------------------------------------------------------- /doc/scapy/graphics/traceroute_worldplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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 | This document 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/index.rst: -------------------------------------------------------------------------------- 1 | .. Layer-specific documentation 2 | 3 | .. toctree:: 4 | :glob: 5 | 6 | * -------------------------------------------------------------------------------- /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/layers/tcp.rst: -------------------------------------------------------------------------------- 1 | TCP 2 | === 3 | 4 | Scapy is based on a stimulus/response model. This model does not work 5 | well for a TCP stack. On the other hand, quite often, the TCP stream is 6 | used as a tube to exchange messages that are stimulus/response-based. 7 | 8 | Also, Scapy provides a way to describe network automata that can be 9 | used to create a TCP stack automaton. 10 | 11 | There are many ways to use TCP with Scapy 12 | 13 | Using the kernel's TCP stack 14 | ---------------------------- 15 | 16 | Scapy provides a ``StreamSocket`` object that can transform a simple 17 | socket into a Scapy supersocket suitable for use with ``sr()`` command 18 | family. 19 | 20 | .. code:: 21 | 22 | >>> s=socket.socket() 23 | >>> s.connect(("www.test.com",80)) 24 | >>> ss=StreamSocket(s,Raw) 25 | >>> ss.sr1(Raw("GET /\r\n")) 26 | Begin emission: 27 | Finished to send 1 packets. 28 | * 29 | Received 1 packets, got 1 answers, remaining 0 packets 30 | >> s = TCP_client.tcplink(Raw, "www.test.com", 80) 51 | >>> s.send("GET /\r\n") 52 | 7 53 | >>> s.recv() 54 | 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/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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 | # This file is part of Scapy 5 | # See http://www.secdev.org/projects/scapy for more information 6 | # Copyright (C) Philippe Biondi 7 | # This program is published under a GPLv2 license 8 | 9 | Vagrant.configure("2") do |config| 10 | 11 | config.vm.define "openbsd" do |bsd| 12 | bsd.vm.box = "generic/openbsd6" 13 | bsd.vm.provision "shell", path: "provision_openbsd.sh" 14 | end 15 | 16 | config.vm.define "freebsd" do |bsd| 17 | bsd.vm.box = "freebsd/FreeBSD-13.0-RELEASE" 18 | bsd.vm.provision "shell", path: "provision_freebsd.sh" 19 | end 20 | 21 | config.vm.define "netbsd" do |bsd| 22 | bsd.vm.box = "generic/netbsd9" 23 | bsd.vm.provision "shell", path: "provision_netbsd.sh" 24 | end 25 | 26 | end 27 | -------------------------------------------------------------------------------- /doc/vagrant_ci/provision_freebsd.sh: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/bash 2 | 3 | # This file is part of Scapy 4 | # See http://www.secdev.org/projects/scapy for more information 5 | # Copyright (C) Philippe Biondi 6 | # This program is published under a GPLv2 license 7 | 8 | pkg update 9 | pkg install --yes git python2 python3 py37-virtualenv py27-sqlite3 py37-sqlite3 bash rust 10 | bash 11 | git clone https://github.com/secdev/scapy 12 | cd scapy 13 | export PATH=/usr/local/bin/:$PATH 14 | virtualenv-3.7 -p python3.7 venv 15 | source venv/bin/activate 16 | pip install tox 17 | chown -R vagrant:vagrant /home/vagrant/scapy 18 | -------------------------------------------------------------------------------- /doc/vagrant_ci/provision_netbsd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This file is part of Scapy 4 | # See http://www.secdev.org/projects/scapy for more information 5 | # Copyright (C) Philippe Biondi 6 | # This program is published under a GPLv2 license 7 | 8 | RELEASE="9.0_2020Q4" 9 | 10 | sudo -s 11 | unset PROMPT_COMMAND 12 | export PATH="/sbin:/usr/pkg/sbin:/usr/pkg/bin:$PATH" 13 | export PKG_PATH="http://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/${RELEASE}/All/" 14 | pkg_delete curl 15 | pkg_add git python27 python38 py38-virtualenv py27-sqlite3 py38-sqlite3 py38-expat rust mozilla-rootcerts-openssl 16 | git clone https://github.com/secdev/scapy 17 | cd scapy 18 | virtualenv-3.8 venv 19 | . venv/bin/activate 20 | pip install tox 21 | chown -R vagrant:vagrant ../scapy/ 22 | -------------------------------------------------------------------------------- /doc/vagrant_ci/provision_openbsd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This file is part of Scapy 4 | # See http://www.secdev.org/projects/scapy for more information 5 | # Copyright (C) Philippe Biondi 6 | # This program is published under a GPLv2 license 7 | 8 | sudo pkg_add git python-2.7.18p0 python3 py-virtualenv 9 | sudo mkdir -p /usr/local/test/ 10 | sudo chown -R vagrant:vagrant /usr/local/test/ 11 | cd /usr/local/test/ 12 | git clone https://github.com/secdev/scapy 13 | cd scapy 14 | virtualenv venv 15 | source venv/bin/activate 16 | pip install tox 17 | sudo chown -R vagrant:vagrant /usr/local/test/ 18 | -------------------------------------------------------------------------------- /run_scapy: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | DIR=$(dirname "$0") 3 | if [ -z "$PYTHON" ] 4 | then 5 | ARGS="" 6 | for arg in "$@" 7 | do 8 | case $arg 9 | in 10 | -2) PYTHON=python2;; 11 | -3) PYTHON=python3;; 12 | *) ARGS="$ARGS $arg";; 13 | esac 14 | done 15 | PYTHON=${PYTHON:-python3} 16 | fi 17 | $PYTHON --version > /dev/null 2>&1 18 | if [ ! $? -eq 0 ] 19 | then 20 | echo "WARNING: '$PYTHON' not found, using 'python' instead." 21 | PYTHON=python 22 | fi 23 | PYTHONPATH=$DIR exec "$PYTHON" -m scapy $ARGS 24 | -------------------------------------------------------------------------------- /run_scapy.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set PYTHONPATH=%~dp0 3 | REM shift will not work with %* 4 | set "_args=%*" 5 | IF "%1" == "-2" ( 6 | set PYTHON=python 7 | set "_args=%_args:~3%" 8 | ) ELSE 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 | %PYTHON% -m scapy %_args% 16 | title Scapy - dead 17 | PAUSE -------------------------------------------------------------------------------- /scapy/__main__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 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 | # Guillaume Valadon 2 | 3 | """ 4 | Scapy BSD native support 5 | """ 6 | -------------------------------------------------------------------------------- /scapy/arch/bpf/consts.py: -------------------------------------------------------------------------------- 1 | # Guillaume Valadon 2 | 3 | """ 4 | Scapy BSD native support - constants 5 | """ 6 | 7 | from ctypes import sizeof 8 | 9 | from scapy.libs.structures import bpf_program 10 | from scapy.data import MTU 11 | 12 | 13 | SIOCGIFFLAGS = 0xc0206911 14 | BPF_BUFFER_LENGTH = MTU 15 | 16 | # From net/bpf.h 17 | BIOCIMMEDIATE = 0x80044270 18 | BIOCGSTATS = 0x4008426f 19 | BIOCPROMISC = 0x20004269 20 | BIOCSETIF = 0x8020426c 21 | BIOCSBLEN = 0xc0044266 22 | BIOCGBLEN = 0x40044266 23 | BIOCSETF = 0x80004267 | ((sizeof(bpf_program) & 0x1fff) << 16) 24 | BIOCSDLT = 0x80044278 25 | BIOCSHDRCMPLT = 0x80044275 26 | BIOCGDLT = 0x4004426a 27 | DLT_IEEE802_11_RADIO = 127 28 | -------------------------------------------------------------------------------- /scapy/arch/solaris.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 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.libpcap import * # noqa: F401, F403, E402 22 | from scapy.arch.unix import * # noqa: F401, F403, E402 23 | from scapy.arch.common import get_if_raw_hwaddr # noqa: F401, F403, E402 24 | 25 | 26 | def get_working_if(): 27 | """Return an interface that works""" 28 | try: 29 | # return the interface associated with the route with smallest 30 | # mask (route by default if it exists) 31 | iface = min(conf.route.routes, key=lambda x: x[1])[3] 32 | except ValueError: 33 | # no route 34 | iface = conf.loopback_name 35 | return iface 36 | -------------------------------------------------------------------------------- /scapy/asn1/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | Package holding ASN.1 related modules. 8 | """ 9 | -------------------------------------------------------------------------------- /scapy/asn1packet.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | ASN.1 Packet 8 | 9 | Packet holding data in Abstract Syntax Notation (ASN.1). 10 | """ 11 | 12 | from __future__ import absolute_import 13 | from scapy.base_classes import Packet_metaclass 14 | from scapy.packet import Packet 15 | import scapy.modules.six as six 16 | 17 | from scapy.compat import ( 18 | Any, 19 | Dict, 20 | Tuple, 21 | Type, 22 | cast, 23 | TYPE_CHECKING, 24 | ) 25 | 26 | if TYPE_CHECKING: 27 | from scapy.asn1fields import ASN1F_field # noqa: F401 28 | 29 | 30 | class ASN1Packet_metaclass(Packet_metaclass): 31 | def __new__(cls, # type: ignore 32 | name, # type: str 33 | bases, # type: Tuple[type, ...] 34 | dct # type: Dict[str, Any] 35 | ): 36 | # type: (...) -> Type[ASN1_Packet] 37 | if dct["ASN1_root"] is not None: 38 | dct["fields_desc"] = dct["ASN1_root"].get_fields_list() 39 | return super(ASN1Packet_metaclass, cls).__new__(cls, name, bases, dct) 40 | 41 | 42 | @six.add_metaclass(ASN1Packet_metaclass) 43 | class ASN1_Packet(Packet): 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | This file contains constants 8 | """ 9 | 10 | from sys import byteorder, platform, maxsize 11 | import platform as platform_lib 12 | 13 | LINUX = platform.startswith("linux") 14 | OPENBSD = platform.startswith("openbsd") 15 | FREEBSD = "freebsd" in platform 16 | NETBSD = platform.startswith("netbsd") 17 | DARWIN = platform.startswith("darwin") 18 | SOLARIS = platform.startswith("sunos") 19 | WINDOWS = platform.startswith("win32") 20 | WINDOWS_XP = platform_lib.release() == "XP" 21 | BSD = DARWIN or FREEBSD or OPENBSD or NETBSD 22 | # See https://docs.python.org/3/library/platform.html#cross-platform 23 | IS_64BITS = maxsize > 2**32 24 | BIG_ENDIAN = byteorder == 'big' 25 | # LOOPBACK_NAME moved to conf.loopback_name 26 | -------------------------------------------------------------------------------- /scapy/contrib/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | Package of contrib modules that have to be loaded explicitly. 8 | """ 9 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Nils Weiss 4 | # This program is published under a GPLv2 license 5 | 6 | # scapy.contrib.status = skip 7 | 8 | """ 9 | Package of contrib automotive modules that have to be loaded explicitly. 10 | """ 11 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/bmw/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Nils Weiss 4 | # This program is published under a GPLv2 license 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/gm/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Nils Weiss 4 | # This program is published under a GPLv2 license 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Nils Weiss 4 | # This program is published under a GPLv2 license 5 | 6 | # scapy.contrib.description = GMLAN EcuState modifications 7 | # scapy.contrib.status = library 8 | 9 | from scapy.packet import Packet 10 | from scapy.contrib.automotive.ecu import EcuState 11 | from scapy.contrib.automotive.gm.gmlan import GMLAN, GMLAN_SAPR 12 | 13 | __all__ = ["GMLAN_modify_ecu_state", "GMLAN_SAPR_modify_ecu_state"] 14 | 15 | 16 | @EcuState.extend_pkt_with_modifier(GMLAN) 17 | def GMLAN_modify_ecu_state(self, req, state): 18 | # type: (Packet, Packet, EcuState) -> None 19 | if self.service == 0x50: 20 | state.session = 3 # type: ignore 21 | elif self.service == 0x60: 22 | state.reset() 23 | state.session = 1 # type: ignore 24 | elif self.service == 0x68: 25 | state.communication_control = 1 # type: ignore 26 | elif self.service == 0xe5: 27 | state.session = 2 # type: ignore 28 | elif self.service == 0x74 and len(req) > 3: 29 | state.request_download = 1 # type: ignore 30 | elif self.service == 0x7e: 31 | state.tp = 1 # type: ignore 32 | 33 | 34 | @EcuState.extend_pkt_with_modifier(GMLAN_SAPR) 35 | def GMLAN_SAPR_modify_ecu_state(self, req, state): 36 | # type: (Packet, Packet, EcuState) -> None 37 | if self.subfunction % 2 == 0 and self.subfunction > 0 and len(req) >= 3: 38 | state.security_level = self.subfunction # type: ignore 39 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/obd/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Andreas Korb 4 | # Copyright (C) Nils Weiss 5 | # This program is published under a GPLv2 license 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Andreas Korb 4 | # Copyright (C) Nils Weiss 5 | # This program is published under a GPLv2 license 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Andreas Korb 4 | # Copyright (C) Nils Weiss 5 | # This program is published under a GPLv2 license 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Andreas Korb 4 | # Copyright (C) Nils Weiss 5 | # This program is published under a GPLv2 license 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Andreas Korb 4 | # Copyright (C) Nils Weiss 5 | # This program is published under a GPLv2 license 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Andreas Korb 4 | # Copyright (C) Nils Weiss 5 | # This program is published under a GPLv2 license 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Nils Weiss 4 | # This program is published under a GPLv2 license 5 | 6 | # scapy.contrib.description = Automotive Scanner Library 7 | # scapy.contrib.status = skip 8 | -------------------------------------------------------------------------------- /scapy/contrib/automotive/volkswagen/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Nils Weiss 4 | # This program is published under a GPLv2 license 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Tabea Spahn 4 | # This program is published under a GPLv2 license 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/bfd.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Parag Bhide 4 | # This program is published under GPLv2 license 5 | 6 | """ 7 | BFD - Bidirectional Forwarding Detection - RFC 5880, 5881, 7130, 7881 8 | """ 9 | 10 | # scapy.contrib.description = BFD 11 | # scapy.contrib.status = loads 12 | 13 | from scapy.packet import Packet, bind_layers, bind_bottom_up 14 | from scapy.fields import BitField, BitEnumField, FlagsField, ByteField 15 | from scapy.layers.inet import UDP 16 | 17 | _sta_names = {0: "AdminDown", 18 | 1: "Down", 19 | 2: "Init", 20 | 3: "Up", 21 | } 22 | 23 | # https://www.iana.org/assignments/bfd-parameters/bfd-parameters.xhtml 24 | _diagnostics = { 25 | 0: "No Diagnostic", 26 | 1: "Control Detection Time Expired", 27 | 2: "Echo Function Failed", 28 | 3: "Neighbor Signaled Session Down", 29 | 4: "Forwarding Plane Reset", 30 | 5: "Path Down", 31 | 6: "Concatenated Path Down", 32 | 7: "Administratively Down", 33 | 8: "Reverse Concatenated Path Down", 34 | 9: "Mis-Connectivity Defect", 35 | } 36 | 37 | 38 | class BFD(Packet): 39 | name = "BFD" 40 | fields_desc = [ 41 | BitField("version", 1, 3), 42 | BitEnumField("diag", 0, 5, _diagnostics), 43 | BitEnumField("sta", 3, 2, _sta_names), 44 | FlagsField("flags", 0x00, 6, "MDACFP"), 45 | ByteField("detect_mult", 3), 46 | ByteField("len", 24), 47 | BitField("my_discriminator", 0x11111111, 32), 48 | BitField("your_discriminator", 0x22222222, 32), 49 | BitField("min_tx_interval", 1000000000, 32), 50 | BitField("min_rx_interval", 1000000000, 32), 51 | BitField("echo_rx_interval", 1000000000, 32)] 52 | 53 | def mysummary(self): 54 | return self.sprintf( 55 | "BFD (my_disc=%BFD.my_discriminator%," 56 | "your_disc=%BFD.your_discriminator%," 57 | "state=%BFD.sta%)" 58 | ) 59 | 60 | 61 | for _bfd_port in [3784, # single-hop BFD 62 | 4784, # multi-hop BFD 63 | 6784, # BFD for LAG a.k.a micro-BFD 64 | 7784]: # seamless BFD 65 | bind_bottom_up(UDP, BFD, dport=_bfd_port) 66 | bind_bottom_up(UDP, BFD, sport=_bfd_port) 67 | bind_layers(UDP, BFD, dport=_bfd_port, sport=_bfd_port) 68 | -------------------------------------------------------------------------------- /scapy/contrib/cansocket.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Nils Weiss 4 | # This program is published under a GPLv2 license 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 | import scapy.modules.six as six 17 | 18 | PYTHON_CAN = False 19 | 20 | try: 21 | if conf.contribs['CANSocket']['use-python-can']: 22 | from can import BusABC as can_BusABC # noqa: F401 23 | PYTHON_CAN = True 24 | except ImportError: 25 | log_loading.info("Can't import python-can.") 26 | except KeyError: 27 | log_loading.info("Configuration 'conf.contribs['CANSocket'] not found.") 28 | 29 | 30 | if PYTHON_CAN: 31 | log_loading.info("Using python-can CANSockets.\nSpecify 'conf.contribs['CANSocket'] = {'use-python-can': False}' to enable native CANSockets.") # noqa: E501 32 | from scapy.contrib.cansocket_python_can import (PythonCANSocket, CANSocket) # noqa: E501 F401 33 | 34 | elif LINUX and six.PY3 and not conf.use_pypy: 35 | log_loading.info("Using native CANSockets.\nSpecify 'conf.contribs['CANSocket'] = {'use-python-can': True}' to enable python-can CANSockets.") # noqa: E501 36 | from scapy.contrib.cansocket_native import (NativeCANSocket, CANSocket) # noqa: E501 F401 37 | 38 | else: 39 | log_loading.info("No CAN support available. Install python-can or use Linux and python3.") # noqa: E501 40 | -------------------------------------------------------------------------------- /scapy/contrib/etherip.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # Scapy is free software: you can redistribute it and/or modify 3 | # it under the terms of the GNU General Public License as published by 4 | # the Free Software Foundation, either version 2 of the License, or 5 | # any later version. 6 | # 7 | # Scapy is distributed in the hope that it will be useful, 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | # GNU General Public License for more details. 11 | # 12 | # You should have received a copy of the GNU General Public License 13 | # along with Scapy. If not, see . 14 | 15 | # scapy.contrib.description = EtherIP 16 | # scapy.contrib.status = loads 17 | 18 | from scapy.fields import BitField 19 | from scapy.packet import Packet, bind_layers 20 | from scapy.layers.inet import IP 21 | from scapy.layers.l2 import Ether 22 | 23 | 24 | class EtherIP(Packet): 25 | name = "EtherIP / RFC 3378" 26 | fields_desc = [BitField("version", 3, 4), 27 | BitField("reserved", 0, 12)] 28 | 29 | 30 | bind_layers(IP, EtherIP, frag=0, proto=0x61) 31 | bind_layers(EtherIP, Ether) 32 | -------------------------------------------------------------------------------- /scapy/contrib/homeplugsg.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | 3 | # This file is part of Scapy 4 | # Scapy is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 2 of the License, or 7 | # any later version. 8 | # 9 | # Scapy is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with Scapy. If not, see . 16 | 17 | # scapy.contrib.description = HomePlugSG Layer 18 | # scapy.contrib.status = loads 19 | 20 | from __future__ import absolute_import 21 | 22 | from scapy.packet import Packet, bind_layers 23 | from scapy.fields import FieldLenField, StrFixedLenField, StrLenField 24 | 25 | # Extends HomePlug AV and GP layer 26 | from scapy.contrib.homeplugav import HomePlugAV, QualcommTypeList 27 | 28 | # 29 | # Copyright (C) HomePlugSG Layer for Scapy by FlUxIuS (Sebastien Dudek) 30 | # 31 | 32 | # HomePlug GP extension for SG 33 | 34 | 35 | HomePlugSGTypes = {0xA400: "VS_UART_CMD_Req", 36 | 0xA401: "VS_UART_CMD_Cnf"} 37 | 38 | 39 | QualcommTypeList.update(HomePlugSGTypes) 40 | 41 | # UART commands over HomePlugGP 42 | 43 | 44 | class VS_UART_CMD_REQ(Packet): 45 | name = "VS_UART_CMD_REQ" 46 | fields_desc = [FieldLenField("UDataLen", None, count_of="UData", fmt="H"), 47 | StrLenField("UData", "UartCommand\x00", 48 | length_from=lambda pkt: pkt.UDataLen)] 49 | 50 | 51 | class VS_UART_CMD_CNF(Packet): 52 | name = "VS_UART_CMD_CNF" 53 | fields_desc = [StrFixedLenField("reserved", b"\x00", 6), 54 | FieldLenField("UDataLen", None, count_of="UData", fmt="H"), 55 | StrLenField("UData", "UartCommand\x00", 56 | length_from=lambda pkt: pkt.UDataLen)] 57 | 58 | 59 | # END # 60 | 61 | bind_layers(HomePlugAV, VS_UART_CMD_REQ, HPtype=0xA400) 62 | bind_layers(HomePlugAV, VS_UART_CMD_CNF, HPtype=0xA401) 63 | -------------------------------------------------------------------------------- /scapy/contrib/isotp/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Nils Weiss 4 | # This program is published under a GPLv2 license 5 | 6 | # scapy.contrib.description = ISO-TP (ISO 15765-2) 7 | # scapy.contrib.status = loads 8 | 9 | from scapy.consts import LINUX 10 | import scapy.modules.six as six 11 | from scapy.config import conf 12 | from scapy.error import log_loading 13 | 14 | from scapy.contrib.isotp.isotp_packet import ISOTP, ISOTPHeader, \ 15 | ISOTPHeaderEA, ISOTP_SF, ISOTP_FF, ISOTP_CF, ISOTP_FC 16 | from scapy.contrib.isotp.isotp_utils import ISOTPSession, \ 17 | ISOTPMessageBuilder 18 | from scapy.contrib.isotp.isotp_soft_socket import ISOTPSoftSocket 19 | from scapy.contrib.isotp.isotp_scanner import isotp_scan 20 | 21 | __all__ = ["ISOTP", "ISOTPHeader", "ISOTPHeaderEA", "ISOTP_SF", "ISOTP_FF", 22 | "ISOTP_CF", "ISOTP_FC", "ISOTPSoftSocket", "ISOTPSession", 23 | "ISOTPSocket", "ISOTPMessageBuilder", "isotp_scan", 24 | "USE_CAN_ISOTP_KERNEL_MODULE"] 25 | 26 | USE_CAN_ISOTP_KERNEL_MODULE = False 27 | 28 | if six.PY3 and LINUX: 29 | try: 30 | if conf.contribs['ISOTP']['use-can-isotp-kernel-module']: 31 | USE_CAN_ISOTP_KERNEL_MODULE = True 32 | except KeyError: 33 | log_loading.info( 34 | "Specify 'conf.contribs['ISOTP'] = {'use-can-isotp-kernel-module': True}' " # noqa: E501 35 | "to enable usage of can-isotp kernel module.") 36 | 37 | from scapy.contrib.isotp.isotp_native_socket import ISOTPNativeSocket 38 | __all__.append("ISOTPNativeSocket") 39 | 40 | if USE_CAN_ISOTP_KERNEL_MODULE: 41 | ISOTPSocket = ISOTPNativeSocket 42 | else: 43 | ISOTPSocket = ISOTPSoftSocket 44 | -------------------------------------------------------------------------------- /scapy/contrib/portmap.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Lucas Preston 4 | # This program is published under a GPLv2 license 5 | 6 | # scapy.contrib.description = Portmapper v2 7 | # scapy.contrib.status = loads 8 | 9 | from scapy.packet import Packet, bind_layers 10 | from scapy.fields import IntField, PacketListField 11 | from scapy.contrib.oncrpc import RPC, RPC_Call 12 | 13 | 14 | class GETPORT_Call(Packet): 15 | name = 'GETPORT Call' 16 | fields_desc = [ 17 | IntField('prog', 0), 18 | IntField('vers', 0), 19 | IntField('prot', 0), 20 | IntField('port', 0) 21 | ] 22 | 23 | 24 | class GETPORT_Reply(Packet): 25 | name = 'GETPORT Reply' 26 | fields_desc = [ 27 | IntField('port', 0) 28 | ] 29 | 30 | 31 | bind_layers(RPC, GETPORT_Call, mtype=0) 32 | bind_layers(RPC, GETPORT_Reply, mtype=1) 33 | bind_layers( 34 | RPC_Call, GETPORT_Call, program=100000, pversion=2, procedure=3 35 | ) 36 | 37 | 38 | class NULL_Call(Packet): 39 | name = 'PORTMAP NULL Call' 40 | fields_desc = [] 41 | 42 | 43 | class NULL_Reply(Packet): 44 | name = 'PORTMAP NULL Reply' 45 | fields_desc = [] 46 | 47 | 48 | bind_layers(RPC, NULL_Call, mtype=0) 49 | bind_layers(RPC, NULL_Reply, mtype=1) 50 | bind_layers(RPC_Call, NULL_Call, program=100000, pversion=2, procedure=0) 51 | 52 | 53 | class Map_Entry(Packet): 54 | name = 'PORTMAP Map Entry' 55 | fields_desc = [ 56 | IntField('prog', 0), 57 | IntField('vers', 0), 58 | IntField('prot', 0), 59 | IntField('port', 0), 60 | IntField('value_follows', 0) 61 | ] 62 | 63 | def extract_padding(self, s): 64 | return '', s 65 | 66 | 67 | class DUMP_Call(Packet): 68 | name = 'PORTMAP DUMP Call' 69 | fields_desc = [] 70 | 71 | 72 | class DUMP_Reply(Packet): 73 | name = 'PORTMAP DUMP Reply' 74 | fields_desc = [ 75 | IntField('value_follows', 0), 76 | PacketListField('mappings', [], Map_Entry, 77 | next_cls_cb=lambda pkt, lst, cur, remain: 78 | Map_Entry if pkt.value_follows == 1 and 79 | (len(lst) == 0 or cur.value_follows == 1) and 80 | len(remain) > 4 else None) 81 | ] 82 | 83 | 84 | bind_layers(RPC, DUMP_Call, mtype=0) 85 | bind_layers(RPC, DUMP_Reply, mtype=1) 86 | bind_layers(RPC_Call, DUMP_Call, program=100000, pversion=2, procedure=4) 87 | -------------------------------------------------------------------------------- /scapy/contrib/ripng.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # Scapy is free software: you can redistribute it and/or modify 3 | # it under the terms of the GNU General Public License as published by 4 | # the Free Software Foundation, either version 2 of the License, or 5 | # any later version. 6 | # 7 | # Scapy is distributed in the hope that it will be useful, 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | # GNU General Public License for more details. 11 | # 12 | # You should have received a copy of the GNU General Public License 13 | # along with Scapy. If not, see . 14 | 15 | # scapy.contrib.description = Routing Information Protocol next gen (RIPng) 16 | # scapy.contrib.status = loads 17 | 18 | from scapy.packet import Packet, bind_layers 19 | from scapy.fields import ByteEnumField, ByteField, IP6Field, ShortField 20 | from scapy.layers.inet import UDP 21 | 22 | 23 | class RIPng(Packet): 24 | name = "RIPng header" 25 | fields_desc = [ 26 | ByteEnumField("cmd", 1, {1: "req", 2: "resp"}), 27 | ByteField("ver", 1), 28 | ShortField("null", 0) 29 | ] 30 | 31 | 32 | class RIPngEntry(Packet): 33 | name = "RIPng entry" 34 | fields_desc = [ 35 | IP6Field("prefix_or_nh", "::"), 36 | ShortField("routetag", 0), 37 | ByteField("prefixlen", 0), 38 | ByteEnumField("metric", 1, {16: "Unreach", 39 | 255: "next-hop entry"}) 40 | ] 41 | 42 | 43 | bind_layers(UDP, RIPng, sport=521, dport=521) 44 | bind_layers(RIPng, RIPngEntry) 45 | bind_layers(RIPngEntry, RIPngEntry) 46 | -------------------------------------------------------------------------------- /scapy/contrib/scada/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Thomas Tannhaeuser 4 | # This program is published under a GPLv2 license 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/wpa_eapol.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # Scapy is free software: you can redistribute it and/or modify 3 | # it under the terms of the GNU General Public License as published by 4 | # the Free Software Foundation, either version 2 of the License, or 5 | # any later version. 6 | # 7 | # Scapy is distributed in the hope that it will be useful, 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | # GNU General Public License for more details. 11 | # 12 | # You should have received a copy of the GNU General Public License 13 | # along with Scapy. If not, see . 14 | 15 | # scapy.contrib.description = WPA EAPOL-KEY 16 | # scapy.contrib.status = loads 17 | 18 | from scapy.packet import Packet, bind_layers 19 | from scapy.fields import ByteField, LenField, ShortField, StrFixedLenField, \ 20 | StrLenField 21 | from scapy.layers.eap import EAPOL 22 | 23 | 24 | class WPA_key(Packet): 25 | name = "WPA_key" 26 | fields_desc = [ByteField("descriptor_type", 1), 27 | ShortField("key_info", 0), 28 | LenField("len", None, "H"), 29 | StrFixedLenField("replay_counter", "", 8), 30 | StrFixedLenField("nonce", "", 32), 31 | StrFixedLenField("key_iv", "", 16), 32 | StrFixedLenField("wpa_key_rsc", "", 8), 33 | StrFixedLenField("wpa_key_id", "", 8), 34 | StrFixedLenField("wpa_key_mic", "", 16), 35 | LenField("wpa_key_length", None, "H"), 36 | StrLenField("wpa_key", "", length_from=lambda pkt:pkt.wpa_key_length)] # noqa: E501 37 | 38 | def extract_padding(self, s): 39 | tmp_len = self.len 40 | return s[:tmp_len], s[tmp_len:] 41 | 42 | def hashret(self): 43 | return chr(self.type) + self.payload.hashret() 44 | 45 | def answers(self, other): 46 | if isinstance(other, WPA_key): 47 | return 1 48 | return 0 49 | 50 | 51 | bind_layers(EAPOL, WPA_key, type=3) 52 | -------------------------------------------------------------------------------- /scapy/extlib.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | External link to programs 8 | """ 9 | 10 | import os 11 | import subprocess 12 | from scapy.error import log_loading 13 | 14 | # Notice: this file must not be called before main.py, if started 15 | # in interactive mode, because it needs to be called after the 16 | # logger has been setup, to be able to print the warning messages 17 | 18 | # MATPLOTLIB 19 | 20 | try: 21 | from matplotlib import get_backend as matplotlib_get_backend 22 | from matplotlib import pyplot as plt 23 | from matplotlib.lines import Line2D 24 | MATPLOTLIB = 1 25 | if "inline" in matplotlib_get_backend(): 26 | MATPLOTLIB_INLINED = 1 27 | else: 28 | MATPLOTLIB_INLINED = 0 29 | MATPLOTLIB_DEFAULT_PLOT_KARGS = {"marker": "+"} 30 | # RuntimeError to catch gtk "Cannot open display" error 31 | except (ImportError, RuntimeError): 32 | plt = None 33 | Line2D = None 34 | MATPLOTLIB = 0 35 | MATPLOTLIB_INLINED = 0 36 | MATPLOTLIB_DEFAULT_PLOT_KARGS = dict() 37 | log_loading.info("Can't import matplotlib. Won't be able to plot.") 38 | 39 | # PYX 40 | 41 | 42 | def _test_pyx(): 43 | # type: () -> bool 44 | """Returns if PyX is correctly installed or not""" 45 | try: 46 | with open(os.devnull, 'wb') as devnull: 47 | r = subprocess.check_call(["pdflatex", "--version"], 48 | stdout=devnull, stderr=subprocess.STDOUT) 49 | except (subprocess.CalledProcessError, OSError): 50 | return False 51 | else: 52 | return r == 0 53 | 54 | 55 | try: 56 | import pyx # noqa: F401 57 | if _test_pyx(): 58 | PYX = 1 59 | else: 60 | log_loading.info("PyX dependencies are not installed ! Please install TexLive or MikTeX.") # noqa: E501 61 | PYX = 0 62 | except ImportError: 63 | log_loading.info("Can't import PyX. Won't be able to use psdump() or pdfdump().") # noqa: E501 64 | PYX = 0 65 | -------------------------------------------------------------------------------- /scapy/layers/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | Layer package. 8 | """ 9 | -------------------------------------------------------------------------------- /scapy/layers/all.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | All layers. Configurable with conf.load_layers. 8 | """ 9 | 10 | from __future__ import absolute_import 11 | 12 | # We import conf from arch to make sure arch specific layers are populated 13 | from scapy.arch import conf 14 | from scapy.error import log_loading 15 | from scapy.main import load_layer 16 | 17 | import logging 18 | import scapy.modules.six as six 19 | 20 | ignored = list(six.moves.builtins.__dict__) + ["sys"] 21 | log = logging.getLogger("scapy.loading") 22 | 23 | __all__ = [] 24 | 25 | for _l in conf.load_layers: 26 | log_loading.debug("Loading layer %s", _l) 27 | try: 28 | load_layer(_l, globals_dict=globals(), symb_list=__all__) 29 | except Exception as e: 30 | log.warning("can't import layer %s: %s", _l, e) 31 | 32 | try: 33 | del _l 34 | except NameError: 35 | pass 36 | -------------------------------------------------------------------------------- /scapy/layers/gprs.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 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", 0), 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 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/rtp.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 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 | # This file is part of Scapy 2 | # Copyright (C) 2007, 2008, 2009 Arnaud Ebalard 3 | # 2015, 2016, 2017 Maxence Tury 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | Aggregate top level objects from all TLS modules. 8 | """ 9 | 10 | from scapy.layers.tls.cert import * # noqa: F401 11 | 12 | from scapy.layers.tls.automaton_cli import * # noqa: F401 13 | from scapy.layers.tls.automaton_srv import * # noqa: F401 14 | from scapy.layers.tls.extensions import * # noqa: F401 15 | from scapy.layers.tls.handshake import * # noqa: F401 16 | from scapy.layers.tls.handshake_sslv2 import * # noqa: F401 17 | from scapy.layers.tls.keyexchange import * # noqa: F401 18 | from scapy.layers.tls.keyexchange_tls13 import * # noqa: F401 19 | from scapy.layers.tls.record import * # noqa: F401 20 | from scapy.layers.tls.record_sslv2 import * # noqa: F401 21 | from scapy.layers.tls.record_tls13 import * # noqa: F401 22 | from scapy.layers.tls.session import * # noqa: F401 23 | 24 | from scapy.layers.tls.crypto.all import * # noqa: F401 25 | -------------------------------------------------------------------------------- /scapy/layers/tls/crypto/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # Copyright (C) 2007, 2008, 2009 Arnaud Ebalard 3 | # 2015, 2016 Maxence Tury 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | Cryptographic capabilities for TLS. 8 | """ 9 | -------------------------------------------------------------------------------- /scapy/layers/tls/crypto/all.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # Copyright (C) 2007, 2008, 2009 Arnaud Ebalard 3 | # 2015, 2016, 2017 Maxence Tury 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | Aggregate some TLS crypto objects. 8 | """ 9 | 10 | from scapy.layers.tls.crypto.suites import * # noqa: F401 11 | -------------------------------------------------------------------------------- /scapy/layers/tls/crypto/ciphers.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # Copyright (C) 2007, 2008, 2009 Arnaud Ebalard 3 | # 2015, 2016 Maxence Tury 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | TLS ciphers. 8 | """ 9 | 10 | # in order to avoid circular dependencies. 11 | from scapy.layers.tls.crypto.cipher_aead import _tls_aead_cipher_algs 12 | from scapy.layers.tls.crypto.cipher_block import _tls_block_cipher_algs 13 | from scapy.layers.tls.crypto.cipher_stream import _tls_stream_cipher_algs 14 | 15 | _tls_cipher_algs = {} 16 | _tls_cipher_algs.update(_tls_block_cipher_algs) 17 | _tls_cipher_algs.update(_tls_stream_cipher_algs) 18 | _tls_cipher_algs.update(_tls_aead_cipher_algs) 19 | -------------------------------------------------------------------------------- /scapy/layers/tls/crypto/common.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # Copyright (C) Philippe Biondi 3 | # This program is published under a GPLv2 license 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/compression.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # Copyright (C) 2007, 2008, 2009 Arnaud Ebalard 3 | # 2015, 2016 Maxence Tury 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | TLS compression. 8 | """ 9 | 10 | from __future__ import absolute_import 11 | import zlib 12 | 13 | from scapy.error import warning 14 | import scapy.modules.six as six 15 | 16 | 17 | _tls_compression_algs = {} 18 | _tls_compression_algs_cls = {} 19 | 20 | 21 | class _GenericCompMetaclass(type): 22 | """ 23 | Compression classes are automatically registered through this metaclass. 24 | """ 25 | def __new__(cls, name, bases, dct): 26 | the_class = super(_GenericCompMetaclass, cls).__new__(cls, name, 27 | bases, dct) 28 | comp_name = dct.get("name") 29 | val = dct.get("val") 30 | if comp_name: 31 | _tls_compression_algs[val] = comp_name 32 | _tls_compression_algs_cls[val] = the_class 33 | return the_class 34 | 35 | 36 | class _GenericComp(six.with_metaclass(_GenericCompMetaclass, object)): 37 | pass 38 | 39 | 40 | class Comp_NULL(_GenericComp): 41 | """ 42 | The default and advised compression method for TLS: doing nothing. 43 | """ 44 | name = "null" 45 | val = 0 46 | 47 | def compress(self, s): 48 | return s 49 | 50 | def decompress(self, s): 51 | return s 52 | 53 | 54 | class Comp_Deflate(_GenericComp): 55 | """ 56 | DEFLATE algorithm, specified for TLS by RFC 3749. 57 | """ 58 | name = "deflate" 59 | val = 1 60 | 61 | def compress(self, s): 62 | tmp = self.compress_state.compress(s) 63 | tmp += self.compress_state.flush(zlib.Z_FULL_FLUSH) 64 | return tmp 65 | 66 | def decompress(self, s): 67 | return self.decompress_state.decompress(s) 68 | 69 | def __init__(self): 70 | self.compress_state = zlib.compressobj() 71 | self.decompress_state = zlib.decompressobj() 72 | 73 | 74 | class Comp_LZS(_GenericComp): 75 | """ 76 | Lempel-Zic-Stac (LZS) algorithm, specified for TLS by RFC 3943. 77 | XXX No support for now. 78 | """ 79 | name = "LZS" 80 | val = 64 81 | 82 | def compress(self, s): 83 | warning("LZS Compression algorithm is not implemented yet") 84 | return s 85 | 86 | def decompress(self, s): 87 | warning("LZS Compression algorithm is not implemented yet") 88 | return s 89 | -------------------------------------------------------------------------------- /scapy/layers/tls/crypto/hash.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # Copyright (C) 2007, 2008, 2009 Arnaud Ebalard 3 | # 2015, 2016 Maxence Tury 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | Hash classes. 8 | """ 9 | 10 | from __future__ import absolute_import 11 | from hashlib import md5, sha1, sha224, sha256, sha384, sha512 12 | import scapy.modules.six as six 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(six.with_metaclass(_GenericHashMetaclass, object)): 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_MD5(_GenericHash): 46 | hash_cls = md5 47 | hash_len = 16 48 | 49 | 50 | class Hash_SHA(_GenericHash): 51 | hash_cls = sha1 52 | hash_len = 20 53 | 54 | 55 | class Hash_SHA224(_GenericHash): 56 | hash_cls = sha224 57 | hash_len = 28 58 | 59 | 60 | class Hash_SHA256(_GenericHash): 61 | hash_cls = sha256 62 | hash_len = 32 63 | 64 | 65 | class Hash_SHA384(_GenericHash): 66 | hash_cls = sha384 67 | hash_len = 48 68 | 69 | 70 | class Hash_SHA512(_GenericHash): 71 | hash_cls = sha512 72 | hash_len = 64 73 | -------------------------------------------------------------------------------- /scapy/layers/tls/crypto/hkdf.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # Copyright (C) 2017 Maxence Tury 3 | # This program is published under a GPLv2 license 4 | 5 | """ 6 | Stateless HKDF for TLS 1.3. 7 | """ 8 | 9 | import struct 10 | 11 | from scapy.config import conf 12 | from scapy.layers.tls.crypto.pkcs1 import _get_hash 13 | 14 | if conf.crypto_valid: 15 | from cryptography.hazmat.backends import default_backend 16 | from cryptography.hazmat.primitives.kdf.hkdf import HKDF, HKDFExpand 17 | from cryptography.hazmat.primitives.hashes import Hash 18 | from cryptography.hazmat.primitives.hmac import HMAC 19 | 20 | 21 | class TLS13_HKDF(object): 22 | def __init__(self, hash_name="sha256"): 23 | self.hash = _get_hash(hash_name) 24 | 25 | def extract(self, salt, ikm): 26 | h = self.hash 27 | hkdf = HKDF(h, h.digest_size, salt, None, default_backend()) 28 | if ikm is None: 29 | ikm = b"\x00" * h.digest_size 30 | return hkdf._extract(ikm) 31 | 32 | def expand(self, prk, info, L): 33 | h = self.hash 34 | hkdf = HKDFExpand(h, L, info, default_backend()) 35 | return hkdf.derive(prk) 36 | 37 | def expand_label(self, secret, label, hash_value, length): 38 | hkdf_label = struct.pack("!H", length) 39 | hkdf_label += struct.pack("B", 6 + len(label)) 40 | hkdf_label += b"tls13 " 41 | hkdf_label += label 42 | hkdf_label += struct.pack("B", len(hash_value)) 43 | hkdf_label += hash_value 44 | return self.expand(secret, hkdf_label, length) 45 | 46 | def derive_secret(self, secret, label, messages): 47 | h = Hash(self.hash, backend=default_backend()) 48 | h.update(messages) 49 | hash_messages = h.finalize() 50 | hash_len = self.hash.digest_size 51 | return self.expand_label(secret, label, hash_messages, hash_len) 52 | 53 | def compute_verify_data(self, basekey, handshake_context): 54 | hash_len = self.hash.digest_size 55 | finished_key = self.expand_label(basekey, b"finished", b"", hash_len) 56 | 57 | h = Hash(self.hash, backend=default_backend()) 58 | h.update(handshake_context) 59 | hash_value = h.finalize() 60 | 61 | hm = HMAC(finished_key, self.hash, default_backend()) 62 | hm.update(hash_value) 63 | return hm.finalize() 64 | -------------------------------------------------------------------------------- /scapy/libs/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # This program is published under a GPLv2 license 4 | 5 | """ 6 | Library bindings 7 | """ 8 | -------------------------------------------------------------------------------- /scapy/libs/structures.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # This program is published under a GPLv2 license 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/modules/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | Package of extension modules that have to be loaded explicitly. 8 | """ 9 | -------------------------------------------------------------------------------- /scapy/modules/krack/__init__.py: -------------------------------------------------------------------------------- 1 | """Module implementing Krack Attack on client, as a custom WPA Access Point 2 | 3 | Requires the python cryptography package v1.7+. See https://cryptography.io/ 4 | 5 | More details on the attack can be found on https://www.krackattacks.com/ 6 | 7 | Example of use (from the scapy shell): 8 | >>> load_module("krack") 9 | >>> KrackAP( 10 | iface="mon0", # A monitor interface 11 | ap_mac='11:22:33:44:55:66', # MAC (BSSID) to use 12 | ssid="TEST_KRACK", # SSID 13 | passphrase="testtest", # Associated passphrase 14 | ).run() 15 | 16 | Then, on the target device, connect to "TEST_KRACK" using "testtest" as the 17 | passphrase. 18 | The output logs will indicate if one of the vulnerability have been triggered. 19 | 20 | Outputs for vulnerable devices: 21 | - IV re-use!! Client seems to be vulnerable to handshake 3/4 replay 22 | (CVE-2017-13077) 23 | - Broadcast packet accepted twice!! (CVE-2017-13080) 24 | - Client has installed an all zero encryption key (TK)!! 25 | 26 | For patched devices: 27 | - Client is likely not vulnerable to CVE-2017-13080 28 | """ 29 | 30 | from scapy.config import conf 31 | 32 | if conf.crypto_valid: 33 | from scapy.modules.krack.automaton import KrackAP # noqa: F401 34 | else: 35 | raise ImportError("Cannot import Krack module due to missing dependency. " 36 | "Please install python{3}-cryptography v1.7+.") 37 | -------------------------------------------------------------------------------- /scapy/tools/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | Additional tools to be run separately 8 | """ 9 | -------------------------------------------------------------------------------- /scapy/tools/automotive/__init__.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Nils Weiss 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | Automotive related tools to be run separately 8 | """ 9 | -------------------------------------------------------------------------------- /scapy/tools/generate_ethertypes.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # Copyright (C) Gabriel Potter 5 | # This program is published under a GPLv2 license 6 | 7 | """Generate the ethertypes file (/etc/ethertypes) based on the OpenBSD source 8 | https://github.com/openbsd/src/blob/master/sys/net/ethertypes.h 9 | 10 | It allows to have a file with the format of 11 | http://git.netfilter.org/ebtables/plain/ethertypes 12 | but up-to-date. 13 | """ 14 | 15 | import re 16 | import urllib.request 17 | 18 | URL = "https://raw.githubusercontent.com/openbsd/src/master/sys/net/ethertypes.h" # noqa: E501 19 | 20 | with urllib.request.urlopen(URL) as stream: 21 | DATA = stream.read() 22 | 23 | reg = br".*ETHERTYPE_([^\s]+)\s.0x([0-9A-Fa-f]+).*\/\*(.*)\*\/" 24 | COMPILED = b"""# 25 | # Ethernet frame types 26 | # This file describes some of the various Ethernet 27 | # protocol types that are used on Ethernet networks. 28 | # 29 | # This list could be found on: 30 | # http://www.iana.org/assignments/ethernet-numbers 31 | # http://www.iana.org/assignments/ieee-802-numbers 32 | # 33 | # ... #Comment 34 | # 35 | """ 36 | ALIASES = { 37 | b"IP": b"IPv4", 38 | b"IPV6": b"IPv6" 39 | } 40 | 41 | for line in DATA.split(b"\n"): 42 | match = re.match(reg, line) 43 | if match: 44 | name = match.group(1) 45 | name = ALIASES.get(name, name).ljust(16) 46 | number = match.group(2).upper() 47 | comment = match.group(3).strip() 48 | compiled_line = (b"%b%b" + b" " * 25 + b"# %b\n") % ( 49 | name, number, comment 50 | ) 51 | COMPILED += compiled_line 52 | 53 | with open("../libs/ethertypes.py", "rb") as inp: 54 | data = inp.read() 55 | 56 | with open("../libs/ethertypes.py", "wb") as out: 57 | ini, sep, _ = data.partition(b"DATA = b\"\"\"") 58 | COMPILED = ini + sep + b"\n" + COMPILED + b"\"\"\"\n" 59 | print("Written: %s" % out.write(COMPILED)) 60 | -------------------------------------------------------------------------------- /scapy/tools/scapy_pyannotate.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Philippe Biondi 4 | # This program is published under a GPLv2 license 5 | 6 | """ 7 | Wrap Scapy's shell in pyannotate. 8 | """ 9 | 10 | import os 11 | import sys 12 | sys.path.insert(0, os.path.abspath('../../')) 13 | 14 | from pyannotate_runtime import collect_types # noqa: E402 15 | from scapy.main import interact # noqa: E402 16 | 17 | collect_types.init_types_collection() 18 | with collect_types.collect(): 19 | interact() 20 | 21 | collect_types.dump_stats("pyannotate_results_main") 22 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal = 1 3 | 4 | [metadata] 5 | description-file = README.md 6 | license_file = LICENSE 7 | 8 | [sdist] 9 | formats=gztar 10 | owner=root 11 | group=root 12 | 13 | [coverage:run] 14 | concurrency = multiprocessing 15 | omit = 16 | # Scapy specific paths 17 | scapy/tools/UTscapy.py 18 | test/* 19 | # Scapy external modules 20 | scapy/modules/six.py 21 | scapy/libs/winpcapy.py 22 | scapy/libs/ethertypes.py 23 | # .tox specific path 24 | .tox/* 25 | # OS specific paths 26 | /private/* 27 | -------------------------------------------------------------------------------- /test/benchmark/common.py: -------------------------------------------------------------------------------- 1 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Guillaume Valadon 4 | # This program is published under a GPLv2 license 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Guillaume Valadon 4 | # This program is published under a GPLv2 license 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 | # This file is part of Scapy 2 | # See http://www.secdev.org/projects/scapy for more information 3 | # Copyright (C) Gabriel Potter 4 | # This program is published under a GPLv2 license 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/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/*.uts" 12 | ], 13 | "remove_testfiles": [ 14 | "test/linux.uts", 15 | "test/windows.uts", 16 | "test/contrib/automotive/ecu_am.uts", 17 | "test/contrib/automotive/gm/gmlanutils.uts", 18 | "test/contrib/isotpscan.uts" 19 | ], 20 | "onlyfailed": true, 21 | "preexec": { 22 | "test/contrib/*.uts": "load_contrib(\"%name%\")", 23 | "test/cert.uts": "load_layer(\"tls\")", 24 | "test/sslv2.uts": "load_layer(\"tls\")", 25 | "test/tls*.uts": "load_layer(\"tls\")" 26 | }, 27 | "kw_ko": [ 28 | "linux", 29 | "windows", 30 | "crypto_advanced", 31 | "ipv6", 32 | "vcan_socket" 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /test/configs/linux.utsc: -------------------------------------------------------------------------------- 1 | { 2 | "testfiles": [ 3 | "test/*.uts", 4 | "test/scapy/layers/*.uts", 5 | "test/contrib/*.uts", 6 | "test/tools/*.uts", 7 | "test/contrib/automotive/*.uts", 8 | "test/contrib/automotive/obd/*.uts", 9 | "test/contrib/automotive/scanner/*.uts", 10 | "test/contrib/automotive/gm/*.uts", 11 | "test/contrib/automotive/bmw/*.uts", 12 | "test/contrib/automotive/xcp/*.uts", 13 | "test/tls/tests_tls_netaccess.uts" 14 | ], 15 | "remove_testfiles": [ 16 | "test/windows.uts", 17 | "test/bpf.uts" 18 | ], 19 | "breakfailed": true, 20 | "onlyfailed": true, 21 | "preexec": { 22 | "test/contrib/*.uts": "load_contrib(\"%name%\")", 23 | "test/cert.uts": "load_layer(\"tls\")", 24 | "test/sslv2.uts": "load_layer(\"tls\")", 25 | "test/tls*.uts": "load_layer(\"tls\")" 26 | }, 27 | "kw_ko": [ 28 | "osx", 29 | "windows", 30 | "crypto_advanced", 31 | "ipv6" 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /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/*.uts" 12 | ], 13 | "remove_testfiles": [ 14 | "test/linux.uts", 15 | "test/bpf.uts", 16 | "test/windows.uts", 17 | "test/contrib/automotive/ecu_am.uts", 18 | "test/contrib/automotive/gm/gmlanutils.uts", 19 | "test/contrib/isotp.uts", 20 | "test/contrib/isotpscan.uts" 21 | ], 22 | "onlyfailed": true, 23 | "preexec": { 24 | "test/contrib/*.uts": "load_contrib(\"%name%\")", 25 | "test/cert.uts": "load_layer(\"tls\")", 26 | "test/sslv2.uts": "load_layer(\"tls\")", 27 | "test/tls*.uts": "load_layer(\"tls\")" 28 | }, 29 | "kw_ko": [ 30 | "osx", 31 | "linux", 32 | "windows", 33 | "crypto_advanced", 34 | "ipv6", 35 | "tap", 36 | "tun", 37 | "vcan_socket" 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /test/configs/windows.utsc: -------------------------------------------------------------------------------- 1 | { 2 | "testfiles": [ 3 | "test\\*.uts", 4 | "test\\scapy\\layers\\*.uts", 5 | "test\\tls\\tests_tls_netaccess.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\\*.uts" 13 | ], 14 | "remove_testfiles": [ 15 | "test\\bpf.uts", 16 | "test\\linux.uts" 17 | ], 18 | "breakfailed": true, 19 | "onlyfailed": true, 20 | "preexec": { 21 | "test\\contrib\\*.uts": "load_contrib(\"%name%\")", 22 | "test\\cert.uts": "load_layer(\"tls\")", 23 | "test\\sslv2.uts": "load_layer(\"tls\")", 24 | "test\\tls*.uts": "load_layer(\"tls\")" 25 | }, 26 | "kw_ko": [ 27 | "brotli", 28 | "crypto_advanced", 29 | "ipv6", 30 | "linux", 31 | "mock_read_routes_bsd", 32 | "open_ssl_client", 33 | "osx", 34 | "require_gui", 35 | "tap", 36 | "tun", 37 | "vcan_socket", 38 | "zstd" 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /test/configs/windows2.utsc: -------------------------------------------------------------------------------- 1 | { 2 | "testfiles": [ 3 | "*.uts", 4 | "scapy\\layers\\*.uts", 5 | "test\\contrib\\automotive\\obd\\*.uts", 6 | "test\\contrib\\automotive\\gm\\*.uts", 7 | "test\\contrib\\automotive\\bmw\\*.uts", 8 | "test\\contrib\\automotive\\*.uts", 9 | "tls\\tests_tls_netaccess.uts", 10 | "contrib\\*.uts" 11 | ], 12 | "remove_testfiles": [ 13 | "bpf.uts", 14 | "linux.uts" 15 | ], 16 | "breakfailed": true, 17 | "onlyfailed": true, 18 | "preexec": { 19 | "contrib\\*.uts": "load_contrib(\"%name%\")", 20 | "cert.uts": "load_layer(\"tls\")", 21 | "sslv2.uts": "load_layer(\"tls\")", 22 | "tls*.uts": "load_layer(\"tls\")" 23 | }, 24 | "format": "html", 25 | "kw_ko": [ 26 | "osx", 27 | "linux", 28 | "crypto_advanced", 29 | "mock_read_routes_bsd", 30 | "appveyor_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/bmw/hsfz.uts: -------------------------------------------------------------------------------- 1 | % Regression tests for the HSFZ layer 2 | 3 | # More information at http://www.secdev.org/projects/UTscapy/ 4 | 5 | 6 | ############ 7 | ############ 8 | 9 | + HSFZ Contrib tests 10 | 11 | = Load Contrib Layer 12 | load_contrib("automotive.bmw.hsfz", globals_dict=globals()) 13 | 14 | = Basic Test 1 15 | 16 | pkt = HSFZ(type=1, src=0xf4, dst=0x10)/Raw(b'\x11\x22\x33') 17 | assert bytes(pkt) == b'\x00\x00\x00\x05\x00\x01\xf4\x10\x11"3' 18 | 19 | = Basic Test 2 20 | 21 | pkt = HSFZ(type=1, src=0xf4, dst=0x10)/Raw(b'\x11\x22\x33\x11\x11\x11\x11\x11') 22 | assert bytes(pkt) == b'\x00\x00\x00\x0a\x00\x01\xf4\x10\x11"3\x11\x11\x11\x11\x11' 23 | 24 | = Basic Dissect Test 25 | 26 | pkt = HSFZ(b'\x00\x00\x00\x0a\x00\x01\xf4\x10\x11"3\x11\x11\x11\x11\x11') 27 | assert pkt.length == 10 28 | assert pkt.src == 0xf4 29 | assert pkt.dst == 0x10 30 | assert pkt.type == 1 31 | assert pkt[1].service == 17 32 | assert pkt[2].resetType == 34 33 | 34 | = Build Test 35 | 36 | pkt = HSFZ(src=0xf4, dst=0x10)/Raw(b"0" * 20) 37 | assert bytes(pkt) == b'\x00\x00\x00\x16\x00\x01\xf4\x10' + b"0" * 20 38 | 39 | = Dissect Test 40 | 41 | pkt = HSFZ(b'\x00\x00\x00\x18\x00\x01\xf4\x10\x67\x01' + b"0" * 20) 42 | assert pkt.length == 24 43 | assert pkt.src == 0xf4 44 | assert pkt.dst == 0x10 45 | assert pkt.type == 1 46 | assert pkt.securitySeed == b"0" * 20 47 | assert len(pkt[1]) == pkt.length - 2 48 | 49 | = Dissect Test with padding 50 | 51 | pkt = HSFZ(b'\x00\x00\x00\x18\x00\x01\xf4\x10\x67\x01' + b"0" * 20 + b"p" * 100) 52 | assert pkt.length == 24 53 | assert pkt.src == 0xf4 54 | assert pkt.dst == 0x10 55 | assert pkt.type == 1 56 | assert pkt.securitySeed == b"0" * 20 57 | assert pkt.load == b'p' * 100 58 | 59 | = Dissect Test to short packet 60 | 61 | pkt = HSFZ(b'\x00\x00\x00\x18\x00\x01\xf4\x10\x67\x01' + b"0" * 19) 62 | assert pkt.length == 24 63 | assert pkt.src == 0xf4 64 | assert pkt.dst == 0x10 65 | assert pkt.type == 1 66 | assert pkt.securitySeed == b"0" * 19 67 | 68 | = Dissect Test very long packet 69 | 70 | pkt = HSFZ(b'\x00\x0f\xff\x04\x00\x01\xf4\x10\x67\x01' + b"0" * 0xfff00) 71 | assert pkt.length == 0xfff04 72 | assert pkt.src == 0xf4 73 | assert pkt.dst == 0x10 74 | assert pkt.type == 1 75 | assert pkt.securitySeed == b"0" * 0xfff00 76 | 77 | -------------------------------------------------------------------------------- /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/automotive/scanner/test_case.uts: -------------------------------------------------------------------------------- 1 | % Regression tests for automotive scanner test_case 2 | 3 | + Load general modules 4 | 5 | = Load contribution layer 6 | 7 | from scapy.contrib.automotive.scanner.test_case import AutomotiveTestCase 8 | from scapy.contrib.automotive.ecu import EcuState 9 | 10 | + Basic checks 11 | 12 | = Definition of Test class 13 | 14 | class MyTestCase(AutomotiveTestCase): 15 | _description = "MyTestCase" 16 | def supported_responses(self): 17 | return [] 18 | 19 | = Create instance of test class 20 | 21 | mt = MyTestCase() 22 | 23 | mt._state_completed[EcuState(session=1)] = True 24 | mt._state_completed[EcuState(session=2)] = True 25 | mt._state_completed[EcuState(session=3)] = False 26 | 27 | = Tests of has_completed 28 | 29 | assert mt.completed is False 30 | assert mt.has_completed(EcuState(session=1)) 31 | assert mt.has_completed(EcuState(session=3)) is False 32 | 33 | assert len(mt.scanned_states) == 3 34 | 35 | = Tests of has_completed with new state 36 | 37 | assert mt.completed is False 38 | assert mt.has_completed(EcuState(session=4)) is False 39 | assert mt.has_completed(EcuState(session=3)) is False 40 | 41 | assert len(mt.scanned_states) == 4 42 | 43 | = Tests of completed 44 | 45 | mt._state_completed[EcuState(session=3)] = True 46 | mt._state_completed[EcuState(session=4)] = True 47 | 48 | assert mt.completed 49 | 50 | = Test of show 51 | 52 | header = mt._show_header(dump=True) 53 | 54 | assert "MyTestCase" in header 55 | 56 | state_info = mt._show_state_information(dump=True) 57 | 58 | assert "session" in state_info 59 | assert "False" not in state_info 60 | assert "True" in state_info 61 | 62 | mt._state_completed[EcuState(session=3)] = False 63 | state_info = mt._show_state_information(dump=True) 64 | 65 | assert "session" in state_info 66 | assert "False" in state_info 67 | assert "True" in state_info 68 | 69 | dump = mt.show(dump=True, verbose=True) 70 | 71 | assert "session" in dump 72 | assert "MyTestCase" in dump 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /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/bfd.uts: -------------------------------------------------------------------------------- 1 | + BFD 2 | 3 | = BFD, basic instantiation 4 | 5 | from scapy.contrib.bfd import BFD 6 | a = UDP(sport=3784, dport=3784)/BFD() 7 | assert raw(a) == b'\x0e\xc8\x0e\xc8\x00 \x00\x00 \xc0\x03\x18\x11\x11\x11\x11"""";\x9a\xca\x00;\x9a\xca\x00;\x9a\xca\x00' 8 | 9 | = BFD - dissection 10 | 11 | assert BFD in UDP(raw(a)) 12 | -------------------------------------------------------------------------------- /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 | 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\x00\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 == 0 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/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/icmp_extensions.uts: -------------------------------------------------------------------------------- 1 | + ICMP Extensions tests 2 | 3 | = Basic build 4 | 5 | p = IP(src="192.0.2.1", dst="192.0.2.2")/ICMP()/ICMPExtensionHeader(version = 2)/ICMPExtensionMPLS(classnum = 1, classtype = 1) 6 | print(raw(p)) 7 | b = b'E\x00\x00$\x00\x01\x00\x00@\x01\xf6\xd4\xc0\x00\x02\x01\xc0\x00\x02\x02\x08\x00\xf6\xfa\x00\x00\x00\x00 \x00\xdf\xff\x00\x04\x01\x01' 8 | assert raw(p) == b 9 | -------------------------------------------------------------------------------- /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/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/nsh.uts: -------------------------------------------------------------------------------- 1 | + Basic Layer Tests 2 | 3 | = Build a NSH over NSH packet with SPI=42, and SI=1 4 | raw(NSH(spi=42, si=1)/NSH()) == b'\x0f\xc6\x01\x04\x00\x00*\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\xc6\x01\x03\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' 5 | 6 | = Build a NSH with Fixed context headers 7 | raw(NSH(ttl=25, spi=55, si=34, context_header=b"\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\xff\xff\xff\xff")) == b'\x06F\x01\x03\x00\x007"\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\xff\xff\xff\xff' 8 | 9 | = Build a Ethernet over NSH over Ethernet packet (NSH over Ethernet encapsulating the original packet) and verify Ethernet Bindings 10 | raw(Ether(src="00:00:00:00:00:01", dst="00:00:00:00:00:02")/NSH()/Ether(src="00:00:00:00:00:03", dst="00:00:00:00:00:04")/ARP(psrc="10.0.0.1", hwsrc="00:00:00:00:00:01")) == b'\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x01\x89O\x0f\xc6\x01\x03\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x03\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\x00\x00\x00\x00\x00\x01\n\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' 11 | 12 | = Build a NSH over GRE packet, and verify GRE Bindings 13 | raw(Ether(src="00:00:00:00:00:01", dst="00:00:00:00:00:02")/IP(src="1.1.1.1", dst="2.2.2.2")/GRE()/NSH()/Ether(src="00:00:00:00:00:03", dst="00:00:00:00:00:04")/ARP(psrc="10.0.0.1", hwsrc="00:00:00:00:00:01")) == b'\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x01\x08\x00E\x00\x00Z\x00\x01\x00\x00@/to\x01\x01\x01\x01\x02\x02\x02\x02\x00\x00\x89O\x0f\xc6\x01\x03\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x03\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\x00\x00\x00\x00\x00\x01\n\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' 14 | 15 | = 0 length variable length context header NSH 16 | raw(NSH(mdtype=2, spi=0xF0F0F0, si=0xFF)) == b'\x0f\xc2\x02\x03\xf0\xf0\xf0\xff' 17 | -------------------------------------------------------------------------------- /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 UTCTimeField with time values 32 | 33 | # Always use ``time.gmtime`` and ``calendar.timegm``, not ``time.localtime`` 34 | # and ``time.mktime``. 35 | 36 | local_time = time.gmtime() 37 | utc_time = UTCTimeField("Test", None, epoch=local_time) 38 | assert time.gmtime(utc_time.epoch) == local_time 39 | assert calendar.timegm(time.gmtime(utc_time.delta)) == calendar.timegm(local_time) 40 | strft_time = time.strftime("%a, %d %b %Y %H:%M:%S %z", local_time) 41 | 42 | # Backup: also test summer time bug 43 | expected = "{} ({:d})".format(strft_time, utc_time.delta) 44 | result = utc_time.i2repr(None, None) 45 | result 46 | expected 47 | assert result == expected 48 | 49 | = Test LETimeField with time values 50 | 51 | local_time = time.gmtime() 52 | lme_time = LETimeField("Test", None, epoch=local_time) 53 | assert time.gmtime(lme_time.epoch) == local_time 54 | assert calendar.timegm(time.gmtime(lme_time.delta)) == calendar.timegm(local_time) 55 | strft_time = time.strftime("%a, %d %b %Y %H:%M:%S %z", local_time) 56 | 57 | # Backup: also test summer time bug 58 | expected = "{} ({:d})".format(strft_time, lme_time.delta) 59 | result = lme_time.i2repr(None, None) 60 | result 61 | expected 62 | assert result == expected 63 | -------------------------------------------------------------------------------- /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 ('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 ('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 ('')" 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 ('diepotato')" 39 | assert SebekV2(cmd="diepotato").summary() == "Sebek v2 ('diepotato')" 40 | assert (SebekHead()/SebekV2(cmd="nottoday")).summary() == "SebekHead / Sebek v2 read ('nottoday')" 41 | assert SebekV3(cmd="diepotato").summary() == "Sebek v3 ('diepotato')" 42 | assert (SebekHead()/SebekV3(cmd="nottoday")).summary() == "SebekHead / Sebek v3 read ('nottoday')" 43 | assert SebekV3Sock(cmd="diepotato").summary() == "Sebek v3 socket ('diepotato')" 44 | assert (SebekHead()/SebekV3Sock(cmd="nottoday")).summary() == "SebekHead / Sebek v3 socket ('nottoday')" 45 | assert SebekV2Sock(cmd="diepotato").summary() == "Sebek v2 socket ('diepotato')" 46 | assert (SebekHead()/SebekV2Sock(cmd="nottoday")).summary() == "SebekHead / Sebek v2 socket ('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/spbm.uts: -------------------------------------------------------------------------------- 1 | % Regression tests for the spbm module 2 | 3 | + Basic SPBM test 4 | 5 | = Test build and dissection 6 | 7 | backboneEther = Ether(dst='00:bb:00:00:90:00', src='00:bb:00:00:40:00', type=0x8100) 8 | backboneDot1Q = Dot1Q(vlan=4051,type=0x88e7) 9 | backboneServiceID = SPBM(prio=1,isid=20011) 10 | customerEther = Ether(dst='00:1b:4f:5e:ca:00',src='00:00:00:00:00:01',type=0x8100) 11 | customerDot1Q = Dot1Q(prio=1,vlan=11,type=0x0800) 12 | customerIP = IP(src='10.100.11.10',dst='10.100.12.10',id=0x0629,len=106) 13 | customerUDP = UDP(sport=1024,dport=1025,chksum=0,len=86) 14 | 15 | pkt = backboneEther/backboneDot1Q/backboneServiceID/customerEther/customerDot1Q/customerIP/customerUDP/"Payload" 16 | pkt = Ether(raw(pkt)) 17 | assert SPBM in pkt 18 | assert pkt[SPBM].payload.payload.payload.src == '10.100.11.10' 19 | -------------------------------------------------------------------------------- /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/nmap.uts: -------------------------------------------------------------------------------- 1 | % Regression tests for Scapy Nmap module 2 | 3 | ~ nmap 4 | 5 | ############ 6 | ############ 7 | + Basic Nmap OS fingerprints tests 8 | 9 | = Module loading 10 | load_module('nmap') 11 | 12 | = Test functions 13 | 14 | d = nmap_udppacket_sig(IP()/UDP(), IP(raw(IP()/ICMP(type=3, code=2)/IPerror()/UDPerror()))) 15 | assert len(d) == 9 16 | 17 | d = nmap_tcppacket_sig(IP()/TCP()) 18 | assert len(d) == 5 19 | 20 | = Fetch database 21 | ~ netaccess 22 | 23 | from __future__ import print_function 24 | try: 25 | from urllib.request import urlopen 26 | except ImportError: 27 | from urllib2 import urlopen 28 | 29 | def _test(): 30 | with open('nmap-os-fingerprints', 'wb') as fd: 31 | fd.write(urlopen('https://raw.githubusercontent.com/nmap/nmap/9efe1892/nmap-os-fingerprints').read()) 32 | 33 | retry_test(_test) 34 | 35 | conf.nmap_base = 'nmap-os-fingerprints' 36 | 37 | = Database loading 38 | ~ netaccess 39 | 40 | print(conf.nmap_kdb.base, conf.nmap_kdb.filename, len(conf.nmap_kdb.get_base())) 41 | assert len(conf.nmap_kdb.get_base()) > 100 42 | 43 | = fingerprint test: www.secdev.org 44 | ~ netaccess 45 | score, fprint = nmap_fp('www.secdev.org') 46 | print(score, fprint) 47 | assert score > 0.5 48 | assert fprint 49 | 50 | = fingerprint test: gateway 51 | ~ netaccess 52 | score, fprint = nmap_fp(conf.route.route('0.0.0.0')[2]) 53 | print(score, fprint) 54 | assert score > 0.5 55 | assert fprint 56 | 57 | = fingerprint test: to text 58 | ~ netaccess 59 | 60 | import re as re_ 61 | 62 | a = nmap_sig("www.secdev.org", 80, 81) 63 | a 64 | for x in nmap_sig2txt(a).split("\n"): 65 | assert re_.match(r"\w{2,4}\(.*\)", x) 66 | 67 | = nmap_udppacket_sig test: www.google.com 68 | ~ netaccess 69 | 70 | a = nmap_sig("www.google.com", ucport=80) 71 | assert len(a) > 3 72 | assert len(a["PU"]) > 0 73 | 74 | + Nmap errors triggering 75 | 76 | = Nmap base not available 77 | 78 | conf.nmap_kdb.filename = "invalid" 79 | conf.nmap_kdb.reload() 80 | assert conf.nmap_kdb.filename == None 81 | 82 | = Clear temp files 83 | try: 84 | os.remove('nmap-os-fingerprints') 85 | except: 86 | pass 87 | 88 | -------------------------------------------------------------------------------- /test/pcaps/bad_rsn_parsing_overrides_ssid.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/bad_rsn_parsing_overrides_ssid.pcap -------------------------------------------------------------------------------- /test/pcaps/candump_gmlan_scanner.log.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/candump_gmlan_scanner.log.gz -------------------------------------------------------------------------------- /test/pcaps/doip.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/doip.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/ecu_trace.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/ecu_trace.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/gmlan_trace.candump.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/gmlan_trace.candump.gz -------------------------------------------------------------------------------- /test/pcaps/http2_h2c.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/http2_h2c.pcap -------------------------------------------------------------------------------- /test/pcaps/http_chunk.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/http_chunk.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/http_compressed-brotli.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/http_compressed-brotli.pcap -------------------------------------------------------------------------------- /test/pcaps/http_compressed-zstd.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/http_compressed-zstd.pcap -------------------------------------------------------------------------------- /test/pcaps/http_compressed.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/http_compressed.pcap -------------------------------------------------------------------------------- /test/pcaps/http_content_length.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/http_content_length.pcap -------------------------------------------------------------------------------- /test/pcaps/http_tcp_psh.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/http_tcp_psh.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/ipfix.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/ipfix.pcap -------------------------------------------------------------------------------- /test/pcaps/macos.pcapng.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/macos.pcapng.gz -------------------------------------------------------------------------------- /test/pcaps/netflowv9.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/netflowv9.pcap -------------------------------------------------------------------------------- /test/pcaps/pfcp.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/pfcp.pcap -------------------------------------------------------------------------------- /test/pcaps/tls_new-session-ticket.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/tls_new-session-ticket.pcap -------------------------------------------------------------------------------- /test/pcaps/tls_tcp_frag.pcap.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/tls_tcp_frag.pcap.gz -------------------------------------------------------------------------------- /test/pcaps/zigbee-join-authenticate.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/test/pcaps/zigbee-join-authenticate.pcap -------------------------------------------------------------------------------- /test/pcaps/zigbee-transport-key-skke_1.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/scapy/059a37182743476ed5a53733865e6cf47b1477c9/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 | -2) PYTHON=python2;; 25 | -3) PYTHON=python3;; 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 manufdb -K wireshark -K ci_only -K vcan_socket -K automotive_comm" 58 | export SIMPLE_TESTS="true" 59 | PYVER=$($PYTHON -c "import sys; print('.'.join(sys.version.split('.')[:2]))") 60 | ${DIR}/.config/ci/test.sh $PYVER non_root 61 | exit $? 62 | fi 63 | PYTHONPATH=$DIR exec "$PYTHON" ${DIR}/scapy/tools/UTscapy.py $ARGS 64 | -------------------------------------------------------------------------------- /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" == "-2" ( 9 | set PYTHON=python 10 | set "_args=%_args:~3%" 11 | ) ELSE IF "%1" == "-3" ( 12 | set PYTHON=python3 13 | set "_args=%_args:~3%" 14 | ) 15 | IF "%PYTHON%" == "" set PYTHON=python3 16 | WHERE %PYTHON% >nul 2>&1 17 | IF %ERRORLEVEL% NEQ 0 set PYTHON=python 18 | REM Reset Error level 19 | VERIFY > nul 20 | echo ##### Starting Unit tests ##### 21 | REM ### Check no-argument mode ### 22 | IF "%_args%" == "" ( 23 | REM Check for tox 24 | %PYTHON% -m tox --version >nul 2>&1 25 | IF %ERRORLEVEL% NEQ 0 ( 26 | echo Tox not installed ! 27 | pause 28 | exit 1 29 | ) 30 | REM Run tox 31 | %PYTHON% -m tox -- -K tcpdump -K manufdb -K wireshark -K ci_only -K automotive_comm 32 | pause 33 | exit 0 34 | ) 35 | REM ### Start UTScapy normally ### 36 | %PYTHON% "%MYDIR%\scapy\tools\UTscapy.py" %_args% 37 | PAUSE 38 | -------------------------------------------------------------------------------- /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/isakmp.uts: -------------------------------------------------------------------------------- 1 | % Scapy ISAKMP layer tests 2 | 3 | 4 | ############ 5 | ############ 6 | + ISAKMP tests 7 | 8 | = ISAKMP creation 9 | ~ IP UDP ISAKMP 10 | p=IP(src='192.168.8.14',dst='10.0.0.1')/UDP()/ISAKMP()/ISAKMP_payload_SA(prop=ISAKMP_payload_Proposal(trans=ISAKMP_payload_Transform(transforms=[('Encryption', 'AES-CBC'), ('Hash', 'MD5'), ('Authentication', 'PSK'), ('GroupDesc', '1536MODPgr'), ('KeyLength', 256), ('LifeType', 'Seconds'), ('LifeDuration', 86400)])/ISAKMP_payload_Transform(res2=12345,transforms=[('Encryption', '3DES-CBC'), ('Hash', 'SHA'), ('Authentication', 'PSK'), ('GroupDesc', '1024MODPgr'), ('LifeType', 'Seconds'), ('LifeDuration', 86400)]))) 11 | p.show() 12 | p 13 | 14 | 15 | = ISAKMP manipulation 16 | ~ ISAKMP 17 | r = p[ISAKMP_payload_Transform:2] 18 | r 19 | r.res2 == 12345 20 | 21 | = ISAKMP assembly 22 | ~ ISAKMP 23 | hexdump(p) 24 | raw(p) == b"E\x00\x00\x96\x00\x01\x00\x00@\x11\xa7\x9f\xc0\xa8\x08\x0e\n\x00\x00\x01\x01\xf4\x01\xf4\x00\x82\xbf\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00z\x00\x00\x00^\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00R\x01\x01\x00\x00\x03\x00\x00'\x00\x01\x00\x00\x80\x01\x00\x07\x80\x02\x00\x01\x80\x03\x00\x01\x80\x04\x00\x05\x80\x0e\x01\x00\x80\x0b\x00\x01\x00\x0c\x00\x03\x01Q\x80\x00\x00\x00#\x00\x0109\x80\x01\x00\x05\x80\x02\x00\x02\x80\x03\x00\x01\x80\x04\x00\x02\x80\x0b\x00\x01\x00\x0c\x00\x03\x01Q\x80" 25 | 26 | 27 | = ISAKMP disassembly 28 | ~ ISAKMP 29 | q=IP(raw(p)) 30 | q.show() 31 | r = q[ISAKMP_payload_Transform:2] 32 | r 33 | r.res2 == 12345 34 | 35 | 36 | -------------------------------------------------------------------------------- /test/scapy/layers/l2.uts: -------------------------------------------------------------------------------- 1 | % Layer 2 regression tests for Scapy 2 | 3 | # More information at http://www.secdev.org/projects/UTscapy/ 4 | 5 | 6 | ############ 7 | ############ 8 | + Layer 2 Unit Tests 9 | 10 | = Arping 11 | ~ netaccess tcpdump 12 | * This test assumes the local network is a /24. This is bad. 13 | def _test(): 14 | ip_address = conf.route.route("0.0.0.0")[2] 15 | ip_address 16 | arping(ip_address+"/24") 17 | 18 | retry_test(_test) 19 | 20 | = Test ARPingResult output 21 | ~ manufdb 22 | 23 | ar = ARPingResult([(None, Ether(src='70:ee:50:50:ee:70')/ARP(psrc='192.168.0.1'))]) 24 | with ContextManagerCaptureOutput() as cmco: 25 | ar.show() 26 | result_ar = cmco.get_output() 27 | 28 | assert result_ar.startswith(" 70:ee:50:50:ee:70 Netatmo 192.168.0.1") 29 | 30 | 31 | ############ 32 | ############ 33 | + STP tests 34 | 35 | = STP - Basic Instantiation 36 | assert raw(STP()) == b'\x00\x00\x00\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\x14\x00\x02\x00\x0f\x00' 37 | 38 | = STP - Basic Dissection 39 | 40 | s = STP(b'\x00\x00\x00\x00\x00\x00\x00\x12\x13\x14\x15\x16\x17\x00\x00\x00\x00\x00\x00\xaa\xaa\xaa\xaa\xaa\xaa\x00\x00\x01\x00\x14\x00\x05\x00\x0f\x00') 41 | assert s.rootmac == "12:13:14:15:16:17" 42 | assert s.bridgemac == "aa:aa:aa:aa:aa:aa" 43 | assert s.hellotime == 5 44 | 45 | 46 | ############ 47 | ############ 48 | + ARP 49 | 50 | = Simple Ether() / ARP() show 51 | (Ether() / ARP()).show() 52 | 53 | = ARP for IPv4 54 | 55 | p = raw(ARP()) 56 | assert p == raw(ARP(ptype=0x0800)) 57 | p = ARP(p) 58 | assert p.ptype == 0x0800 59 | assert valid_ip(p.pdst) 60 | assert valid_ip(p.psrc) 61 | assert isinstance(p.payload, NoPayload) 62 | 63 | = ARP for IPv6 64 | 65 | p = ARP(raw(ARP(ptype=0x86dd))) 66 | assert p.ptype == 0x86dd 67 | assert valid_ip6(p.pdst) 68 | assert valid_ip6(p.psrc) 69 | assert isinstance(p.payload, NoPayload) 70 | 71 | = Dummy ARP 72 | 73 | p = ARP(raw(ARP(plen=2, hwlen=1, hwdst="x", hwsrc="y", pdst="aa", psrc="bb"))) 74 | assert p.hwdst == b"x" 75 | assert p.hwsrc == b"y" 76 | assert p.pdst == b"aa" 77 | assert p.psrc == b"bb" 78 | assert isinstance(p.payload, NoPayload) 79 | 80 | p = ARP(raw(ARP(plen=1, hwlen=1))) 81 | assert p.hwdst == p.hwsrc == p.pdst == p.psrc == b"\x00" 82 | assert isinstance(p.payload, NoPayload) 83 | 84 | p = ARP(pdst='192.168.178.0/24') 85 | assert "Net" in repr(p) 86 | -------------------------------------------------------------------------------- /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 - dissection 12 | p = IP(s) 13 | L2TP in p and len(p[L2TP]) == 6 and p.tunnel_id == 0 and p.session_id == 0 and p[UDP].chksum == 0xf483 14 | -------------------------------------------------------------------------------- /test/scapy/layers/llmnr.uts: -------------------------------------------------------------------------------- 1 | % LLMNR regression tests for Scapy 2 | 3 | ############ 4 | ############ 5 | + LLMNR protocol 6 | 7 | = Simple packet dissection 8 | pkt = Ether(b'\x11\x11\x11\x11\x11\x11\x99\x99\x99\x99\x99\x99\x08\x00E\x00\x00(\x00\x01\x00\x00@\x11:\xa4\xc0\xa8\x00w\x7f\x00\x00\x01\x14\xeb\x14\xeb\x00\x14\x95\xcf\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') 9 | assert pkt.sport == 5355 10 | assert pkt.dport == 5355 11 | assert pkt[LLMNRQuery].opcode == 0 12 | 13 | = Packet build / dissection 14 | pkt = UDP(raw(UDP()/LLMNRResponse())) 15 | assert LLMNRResponse in pkt 16 | assert pkt.qr == 1 17 | assert pkt.c == 0 18 | assert pkt.tc == 0 19 | assert pkt.z == 0 20 | assert pkt.rcode == 0 21 | assert pkt.qdcount == 0 22 | assert pkt.arcount == 0 23 | assert pkt.nscount == 0 24 | assert pkt.ancount == 0 25 | 26 | = Answers - building 27 | a = UDP()/LLMNRResponse(id=12) 28 | b = UDP()/LLMNRQuery(id=12) 29 | assert a.answers(b) 30 | assert not b.answers(a) 31 | assert b.hashret() == b'\x00\x0c' 32 | 33 | = Answers - dissecting 34 | a = Ether(b'\xd0P\x99V\xdd\xf9\x14\x0cv\x8f\xfe(\x08\x00E\x00\x00(\x00\x01\x00\x00@\x11:\xa4\x7f\x00\x00\x01\xc0\xa8\x00w\x14\xeb\x14\xeb\x00\x14\x95\xcf\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') 35 | b = Ether(b'\x14\x0cv\x8f\xfe(\xd0P\x99V\xdd\xf9\x08\x00E\x00\x00(\x00\x01\x00\x00@\x11:\xa4\xc0\xa8\x00w\x7f\x00\x00\x01\x14\xeb\x14\xeb\x00\x14\x15\xcf\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00') 36 | assert b.answers(a) 37 | assert not a.answers(b) 38 | 39 | -------------------------------------------------------------------------------- /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/netbios.uts: -------------------------------------------------------------------------------- 1 | % NETBIOS regression tests for Scapy 2 | 3 | # More information at http://www.secdev.org/projects/UTscapy/ 4 | 5 | ############ 6 | ############ 7 | + Netbios tests 8 | 9 | = NBNSQueryRequest - build 10 | 11 | z = NBNSQueryRequest(SUFFIX="file server service", QUESTION_NAME='TEST1', QUESTION_TYPE='NB') 12 | 13 | assert raw(z) == b'\x00\x00\x01\x10\x00\x01\x00\x00\x00\x00\x00\x00 FEEFFDFEDBCACACACACACACACACACACA\x00\x00 \x00\x01' 14 | 15 | pkt = IP(dst='192.168.0.255')/UDP(sport=137, dport='netbios_ns')/z 16 | pkt = IP(raw(pkt)) 17 | assert pkt.QUESTION_NAME == b'TEST1 ' -------------------------------------------------------------------------------- /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/smb.uts: -------------------------------------------------------------------------------- 1 | ############ 2 | ############ 3 | + SMB 4 | 5 | = test SMB Negociate Header - dissect 6 | 7 | # OK test 8 | rawpkt = b'\x45\x00\x00\x5b\x69\x10\x40\x00\x73\x06\xca\x85\x7a\xa0\x9a\xb6\xc0\xa8\xfe\x07\xeb\xec\x01\xbd\xaf\x97\x2e\xb7\x78\x60\x84\x6c\x50\x18\x40\x29\xd5\x36\x00\x00\x00\x00\x00\x2f\xff\x53\x4d\x42\x72\x00\x00\x00\x00\x18\x01\x48\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x20\x18\x00\x00\x00\x00\x00\x0c\x00\x02\x4e\x54\x20\x4c\x4d\x20\x30\x2e\x31\x32\x00' 9 | pkt = IP(rawpkt) 10 | # Check layers 11 | assert TCP in pkt 12 | assert NBTSession in pkt 13 | assert pkt[NBTSession].LENGTH == 47 14 | assert SMBNegociate_Protocol_Request_Header in pkt 15 | smb = pkt[SMBNegociate_Protocol_Request_Header] 16 | # Check header values 17 | print(smb.show()) 18 | assert smb.Start == b'\xffSMB' 19 | assert smb.Command == 0x72 # SMB_COM_NEGOCIATE 20 | 21 | # KO test 22 | rawpkt = b'\x45\x00\x00\x5b\x69\x10\x40\x00\x73\x06\xca\x85\x7a\xa0\x9a\xb6\xc0\xa8\xfe\x07\xeb\xec\x01\xbd\xaf\x97\x2e\xb7\x78\x60\x84\x6c\x50\x18\x40\x29\xd5\x36\x00\x00\x00\x00\x00\x2f\xf0\x53\x4d\x42\x72\x00\x00\x00\x00\x18\x01\x48\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x20\x18\x00\x00\x00\x00\x00\x0c\x00\x02\x4e\x54\x20\x4c\x4d\x20\x30\x2e\x31\x32\x00' 23 | pkt = IP(rawpkt) 24 | # Check layers 25 | assert TCP in pkt 26 | assert NBTSession in pkt 27 | assert pkt[NBTSession].LENGTH == 47 28 | assert SMBNegociate_Protocol_Request_Header_Generic in pkt 29 | # Should not have a proper SMBNegociate header as magic is \xf0SMB, not \xffSMB 30 | assert SMBNegociate_Protocol_Request_Header not in pkt 31 | 32 | 33 | = test SMB Negociate Header - assemble 34 | 35 | pkt = IP() / TCP() / NBTSession() / SMBNegociate_Protocol_Request_Header() 36 | assert pkt[NBTSession].TYPE == 0x00 # session message 37 | smb = pkt[SMBNegociate_Protocol_Request_Header] 38 | assert smb.Start == b'\xffSMB' 39 | -------------------------------------------------------------------------------- /test/scapy/layers/tftp.uts: -------------------------------------------------------------------------------- 1 | % TFTP regression tests for Scapy 2 | 3 | # More information at http://www.secdev.org/projects/UTscapy/ 4 | 5 | 6 | ############ 7 | ############ 8 | + TFTP tests 9 | 10 | = TFTP Options 11 | x=IP()/UDP(sport=12345)/TFTP()/TFTP_RRQ(filename="fname")/TFTP_Options(options=[TFTP_Option(oname="blksize", value="8192"),TFTP_Option(oname="other", value="othervalue")]) 12 | assert( raw(x) == b'E\x00\x00H\x00\x01\x00\x00@\x11|\xa2\x7f\x00\x00\x01\x7f\x00\x00\x0109\x00E\x004B6\x00\x01fname\x00octet\x00blksize\x008192\x00other\x00othervalue\x00' ) 13 | y=IP(raw(x)) 14 | y[TFTP_Option].oname 15 | y[TFTP_Option:2].oname 16 | assert(len(y[TFTP_Options].options) == 2 and y[TFTP_Option].oname == b"blksize") 17 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /test/tls/__init__.py: -------------------------------------------------------------------------------- 1 | ## This file is part of Scapy 2 | ## Copyright (C) 2016 Maxence Tury 3 | ## This program is published under a GPLv2 license 4 | 5 | """ 6 | Examples and test PKI for the TLS module. 7 | """ 8 | 9 | -------------------------------------------------------------------------------- /test/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/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/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/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/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/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 | --------------------------------------------------------------------------------