Skip to content

Instantly share code, notes, and snippets.

View thepacketgeek's full-sized avatar

Mat Wood thepacketgeek

View GitHub Profile
@thepacketgeek
thepacketgeek / python-post-json.py
Last active July 7, 2021 06:51
POST JSON from Python with Requests
import requests
url = "http://localhost:8080"
data = {'sender': 'Alice', 'receiver': 'Bob', 'message': 'We did it!'}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post(url, data=json.dumps(data), headers=headers)
@thepacketgeek
thepacketgeek / cleanScapyPacket.py
Created October 4, 2013 16:34
Clean up a scapy packet summary
def cleanPayload(p):
p = str(p)
# Clean up packet payload from scapy output
return p.split('Raw')[0].split("Padding")[0].replace('|','\n').strip('<')\
.strip('bound method Ether.show of ').replace('>','').replace('[<','[')\
.replace('\n<','<').replace('<','\n');

Create a Meteor app and put the client_/server_ files in a client/server directories. Also, create a public dir to save the uploaded files.

@thepacketgeek
thepacketgeek / scapy-CustomAction.py
Last active December 24, 2015 22:59
Run a custom function on every packet sniffed with scapy
## Import Scapy module
from scapy.all import *
## Create a Packet Count var
packetCount = 0
## Define our Custom Action function
def customAction(packet):
global packetCount
packetCount += 1
@thepacketgeek
thepacketgeek / scapy-multiple-arguments.py
Created October 7, 2013 23:19
Using the scapy 'prn' argument, pass multiple arguments along with packet in a sniff(), s(), or sr() function.
# define API options
url = "http://hosted.app/api/packets"
token = "supersecretusertoken"
# create parent function with passed in arguments
def customAction(url,token):
# uploadPacket function has access to the url & token parameters because they are 'closed' in the nested function
def uploadPacket(packet):
# upload packet, using passed arguments
headers = {'content-type': 'application/json'}
@thepacketgeek
thepacketgeek / scapy-single-object-argument.py
Created October 7, 2013 23:20
Using the scapy 'prn' argument, pass an object along with packet in a sniff(), s(), or sr() function.
# define API options
options = {"url": "http://hosted.app/api/packets", "token": "supersecretusertoken"}
# create parent function with passed in arguments
def customAction(options):
# uploadPacket function has access to the options object because they are 'closed' in the nested function
def uploadPacket(packet):
# upload packet, using passed arguments
headers = {'content-type': 'application/json'}
r = requests.post(options["url"], data=json.dumps(packet,options["token"]), headers=headers)
@thepacketgeek
thepacketgeek / 07-arp_monitor.py
Last active May 31, 2018 20:32
Scapy - Monitor ARP traffic on network with custom console output
from scapy.all import *
def arp_display(pkt):
if pkt[ARP].op == 1: #who-has (request)
return "Request: " + pkt[ARP].psrc + " is asking about " + pkt[ARP].pdst
if pkt[ARP].op == 2: #is-at (response)
return "*Response: " + pkt[ARP].hwsrc + " has address " + pkt[ARP].psrc
print sniff(prn=arp_display, filter="arp", store=0, count=10)
@thepacketgeek
thepacketgeek / 08-xmas-tree-packet.py
Last active September 22, 2023 15:35
Scapy - Creating a TCP Christmas Tree Packet
from scapy.all import *
from random import randint
# Create the skeleton of our packet
template = IP(dst="172.16.20.10")/TCP()
# Start lighting up those bits!
template[TCP].flags = "UFP"
# Create a list with a large number of packets to send
@thepacketgeek
thepacketgeek / 07-sniff-arp.py
Last active December 25, 2015 04:49
Scapy - Basic ARP sniff
from scapy.all import *
print sniff(filter="arp",count=10).summary()
@thepacketgeek
thepacketgeek / 07-print-ping.py
Last active December 25, 2015 04:49
Ping an IP and print out the summary of the response packets
from scapy.all import *
print sr1(IP(dst="4.2.2.1")/ICMP()).summary()