Skip to content

Instantly share code, notes, and snippets.

View thepacketgeek's full-sized avatar

Mat Wood thepacketgeek

View GitHub Profile
@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 / 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 / 10-dns-query.py
Last active July 7, 2023 11:43
Simple DNS Query with Scapy
from scapy.all import *
answer = sr1(IP(dst="8.8.8.8")/UDP(dport=53)/DNS(rd=1,qd=DNSQR(qname="www.thepacketgeek.com")),verbose=0)
print answer[DNS].summary()

Diving into Rust

If you're wanting to get involved with Rust projects and see what the magic is all about, here are some great starting points!

Read

  • A Gentle Introduction
    • A little more focused on the main concepts, only takes an hour or so
  • The Book
    • This is the first and foremost (albiet most time consuming) way to get familiar
  • Py2Rs
@thepacketgeek
thepacketgeek / 10-ping-sweep.py
Created October 22, 2013 23:14
Ping sweep using Python's netaddr
from scapy.all import *
import netaddr
# Define IP range to ping
network = "172.16.20.0/24"
# make list of addresses out of network, set live host counter
addresses = netaddr.IPNetwork(network)
liveCounter = 0
@thepacketgeek
thepacketgeek / .zshrc
Created January 6, 2022 18:20
Git checkout branch w/ fzf
gch() {
git checkout $(git for-each-ref refs/heads/ --format='%(refname:short)' | fzf)
}
gchr() {
git checkout --track $(git branch --remotes | fzf)
}
@thepacketgeek
thepacketgeek / host-cargo-docs.sh
Created January 4, 2022 22:00
Host `cargo doc` in HTTP server
#!/bin/bash
set -o errexit
pushd `BROWSER=echo cargo doc --open | sed "s/\/doc\/.*/\/doc\//"` && python -m http.server; popd
#!/usr/bin/env python
"""
Very simple HTTP server in python.
Usage::
./dummy-web-server.py [<port>]
Send a GET request::
curl http://localhost
@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 / gist:6f00c7d2e2d9e4ba8df20b9adf214067
Created June 25, 2021 17:59
Telegraf Syslog with "source" tag
./telegraf --test --config /etc/telegraf/telegraf.conf --input-filter syslog --test-wait 15
2021-06-25T17:55:06Z I! Starting Telegraf
> syslog,appname=docker-compose,facility=daemon,host=bb8,hostname=droplet,location=home,severity=info,source=10.0.0.12 facility_code=3i,message="<redacted>",severity_code=6i,timestamp=1624643706396113000i,version=1i 1624643706400667198
> syslog,appname=tailscaled,facility=daemon,host=bb8,hostname=dev,location=home,severity=info,source=10.0.0.15 facility_code=3i,message="<redacted>",severity_code=6i,timestamp=1624643706403394000i,version=1i 1624643706407850408
> syslog,appname=docker-compose,facility=daemon,host=bb8,hostname=droplet,location=home,severity=info,source=10.0.0.12 facility_code=3i,message="<redacted>",severity_code=6i,timestamp=1624643706675853000i,version=1i 1624643706679251683
> syslog,appname=multipathd,facility=daemon,host=bb8,hostname=droplet,location=home,severity=info,source=10.0.0.12 facility_code=3i,message="<redacted>",severity_code=6i,timestamp=162464370