Skip to content

Instantly share code, notes, and snippets.

View dwallraff's full-sized avatar

Dave Wallraff dwallraff

View GitHub Profile
@dwallraff
dwallraff / tmp_ram_disk.sh
Created September 10, 2016 16:49
Mount a temporary RAM disk
mount -t tmpfs tmpfs /mnt -o size=1024m
@dwallraff
dwallraff / inspect_ram.sh
Created September 10, 2016 16:51
Look at what's in RAM (linux)
sudo strings /dev/mem
@dwallraff
dwallraff / nc_udp.sh
Created September 10, 2016 16:54
Test UDP with netcat
netcat -u host port
# netcat -z -v domain.com 1-1000
# -z just checks connection
@dwallraff
dwallraff / python_tcpdump.py
Last active September 14, 2016 17:10
Use python to tcpump (outputs PCAP)
#!/usr/bin/env python
import sys,socket,struct,time
sys.stdout.write(struct.pack('!IHHIIII',0xa1b2c3d4,2,4,0,0,65535,1))
s=socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.htons(0x3))
while True:
t,p=time.time(),s.recvfrom(65535)
ts=int(t)
tu=int((t-ts)*1000000)
sys.stdout.write(struct.pack('!IIII',ts,tu,len(p[0]),len(p[0]))+p[0])
@dwallraff
dwallraff / read-only.sh
Created September 10, 2016 16:56
Set Linux filesystem to read-only
echo u > /proc/sysrq-trigger
@dwallraff
dwallraff / git_list_commiters.sh
Created September 10, 2016 16:56
Git command to list users and e-mails from a git repo
git log --format="%an %ae" | sort | uniq
@dwallraff
dwallraff / ssh_config_proxy_command.md
Created September 10, 2016 16:59
SSH config ProxyCommand
Host internal-*.example.net
  ProxyCommand ssh -T external.example.net 'nc %h %p'

Used to ssh internal-dev.example.net

@dwallraff
dwallraff / port_forwarding.md
Last active March 16, 2025 10:40
Add port forwarding to running SSH sessions

Use SSH's escape sequence <enter>~<shift>+c

user@sshhost $ ~C
ssh> L8080:localhost:8080
Forwarding port.
user@sshhost $ ~C
ssh&gt; KL8080
@dwallraff
dwallraff / bash_exit_trap.sh
Created September 13, 2016 16:53
Trap EXIT in a bash script
#!/bin/bash
# Do some stuff
function finish {
# Your cleanup code here
}
trap finish EXIT
@dwallraff
dwallraff / sample_color_output.sh
Created September 13, 2016 17:06
Use `tput` to modify output in bash scripts
NORMAL=$(tput sgr0)
GREEN=$(tput setaf 2; tput bold)
YELLOW=$(tput setaf 3)
RED=$(tput setaf 1)
function red() {
echo -e "$RED$*$NORMAL"
}
function green() {