Skip to content

Instantly share code, notes, and snippets.

View thepacketgeek's full-sized avatar

Mat Wood thepacketgeek

View GitHub Profile
@thepacketgeek
thepacketgeek / 09-dns-spoofer.py
Last active March 29, 2020 23:37
Emulating PlexConnect DNS spoofer
from scapy.all import *
DNSServerIP = "172.16.20.40"
filter = "udp port 53 and ip dst " + DNSServerIP + " and not ip src " + DNSServerIP
def DNS_Responder(localIP):
def forwardDNS(orig_pkt):
print "Forwarding: " + orig_pkt[DNSQR].qname
response = sr1(IP(dst="8.8.8.8")/UDP(sport=orig_pkt[UDP].sport)/\
@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()
@thepacketgeek
thepacketgeek / 10-tcp-port-scan.py
Last active December 26, 2015 06:39
TCP port scanner, 1 host for an array of specified ports
from scapy.all import *
import random
# Define end host and TCP port range
host = "www.facebook.com"
portRange = [22,23,80,443,3389]
# Send SYN with random Src Port for each Dst port
for dstPort in portRange:
srcPort = random.randint(1025,65534)
resp = sr1(IP(dst=host)/TCP(sport=srcPort,dport=dstPort,flags="S"),timeout=1,verbose=0)
@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 / rand-packet-fields.py
Created October 23, 2013 00:01
Random packet field generators
## Returns a string of a random int between 1 and 254(default)
def randOct(end = 254):
return str(random.randint(1, end))
## Used for random size or TTL
def randTS(max = 256):
return str(random.randint(1, max/8) * 8)
## Returns a string of a hex number 4 digits long, with the preceding '0x' sliced off
def randHex(max = 65535):
from scapy.all import *
import netaddr
import random
# Define IP range to scan
network = "172.16.20.0/29"
# Define TCP port range
portRange = [22,23,80,443,449]
# make list of addresses out of network, set live host counter
#! /usr/bin/env python3
import random
from ipaddress import IPv4Network
from typing import List
from scapy.all import ICMP, IP, sr1, TCP
# Define IP range to scan
network = "192.168.40.0/30"
@thepacketgeek
thepacketgeek / valid_ip.py
Created December 4, 2013 22:01
Check for a valid IP address
def valid_ip(address):
try:
host_bytes = address.split('.')
valid = [int(b) for b in host_bytes]
valid = [b for b in valid if b >= 0 and b<=255]
return len(host_bytes) == 4 and len(valid) == 4
except:
return False
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
#!/usr/bin/env bash
# change to proper directory
cd /Applications/Google\ Drive.app/Contents/Resources/
# back up the files
sudo mkdir icon-backups
sudo cp mac-animate*.png icon-backups/
sudo cp mac-error*.png icon-backups/
sudo cp mac-inactive*.png icon-backups/