ineedcodes 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/skills/401-403-bypass-techniques/SKILL.md +348 -0
- package/skills/active-directory-acl-abuse/BLOODHOUND_PATHS.md +281 -0
- package/skills/active-directory-acl-abuse/SKILL.md +295 -0
- package/skills/active-directory-certificate-services/ADCS_ESC_MATRIX.md +197 -0
- package/skills/active-directory-certificate-services/SKILL.md +303 -0
- package/skills/active-directory-kerberos-attacks/KERBEROS_ATTACK_CHAINS.md +226 -0
- package/skills/active-directory-kerberos-attacks/SKILL.md +311 -0
- package/skills/ai-ml-security/SKILL.md +425 -0
- package/skills/android-pentesting-tricks/FRIDA_SCRIPTS.md +394 -0
- package/skills/android-pentesting-tricks/SKILL.md +369 -0
- package/skills/anti-debugging-techniques/ANTI_DEBUG_MATRIX.md +117 -0
- package/skills/anti-debugging-techniques/SKILL.md +407 -0
- package/skills/api-auth-and-jwt-abuse/SKILL.md +76 -0
- package/skills/api-authorization-and-bola/SKILL.md +48 -0
- package/skills/api-recon-and-docs/SKILL.md +61 -0
- package/skills/api-sec/SKILL.md +49 -0
- package/skills/arbitrary-write-to-rce/SKILL.md +361 -0
- package/skills/auth-sec/SKILL.md +41 -0
- package/skills/authbypass-authentication-flaws/SKILL.md +441 -0
- package/skills/bba-ad-attacker/SKILL.md +420 -0
- package/skills/bba-api-security/SKILL.md +95 -0
- package/skills/bba-attack-planner/SKILL.md +186 -0
- package/skills/bba-binary-exploit/SKILL.md +65 -0
- package/skills/bba-bizlogic-hunter/SKILL.md +304 -0
- package/skills/bba-bug-bounty/SKILL.md +245 -0
- package/skills/bba-cicd-redteam/SKILL.md +515 -0
- package/skills/bba-cloud-security/SKILL.md +97 -0
- package/skills/bba-container-escape/SKILL.md +161 -0
- package/skills/bba-credential-tester/SKILL.md +346 -0
- package/skills/bba-crypto-analyst/SKILL.md +54 -0
- package/skills/bba-ctf-solver/SKILL.md +166 -0
- package/skills/bba-detection-engineer/SKILL.md +93 -0
- package/skills/bba-engagement-planner/SKILL.md +68 -0
- package/skills/bba-exploit-chainer/SKILL.md +280 -0
- package/skills/bba-exploit-guide/SKILL.md +96 -0
- package/skills/bba-forensics-analyst/SKILL.md +512 -0
- package/skills/bba-graphql-hunter/SKILL.md +145 -0
- package/skills/bba-hardware-hacker/SKILL.md +57 -0
- package/skills/bba-jwt-cracker/SKILL.md +133 -0
- package/skills/bba-llm-redteam/SKILL.md +149 -0
- package/skills/bba-malware-analyst/SKILL.md +305 -0
- package/skills/bba-mobile-pentester/SKILL.md +350 -0
- package/skills/bba-osint-collector/SKILL.md +645 -0
- package/skills/bba-payload-crafter/SKILL.md +347 -0
- package/skills/bba-phishing-operator/SKILL.md +516 -0
- package/skills/bba-poc-validator/SKILL.md +249 -0
- package/skills/bba-privesc-advisor/SKILL.md +98 -0
- package/skills/bba-purple-team/SKILL.md +56 -0
- package/skills/bba-recon-advisor/SKILL.md +215 -0
- package/skills/bba-red-team-operator/SKILL.md +61 -0
- package/skills/bba-report-generator/SKILL.md +145 -0
- package/skills/bba-reverse-engineer/SKILL.md +298 -0
- package/skills/bba-social-engineer/SKILL.md +341 -0
- package/skills/bba-ssrf-hunter/SKILL.md +120 -0
- package/skills/bba-stig-analyst/SKILL.md +108 -0
- package/skills/bba-subdomain-takeover/SKILL.md +141 -0
- package/skills/bba-swarm-orchestrator/SKILL.md +351 -0
- package/skills/bba-threat-modeler/SKILL.md +574 -0
- package/skills/bba-vuln-scanner/SKILL.md +305 -0
- package/skills/bba-web-hunter/SKILL.md +285 -0
- package/skills/bba-wireless-pentester/SKILL.md +539 -0
- package/skills/binary-protection-bypass/PROTECTION_BYPASS_MATRIX.md +168 -0
- package/skills/binary-protection-bypass/SKILL.md +295 -0
- package/skills/browser-exploitation-v8/SKILL.md +334 -0
- package/skills/browser-exploitation-v8/V8_EXPLOITATION_PATTERNS.md +288 -0
- package/skills/business-logic-vuln/SKILL.md +33 -0
- package/skills/business-logic-vulnerabilities/CHECKLIST.md +375 -0
- package/skills/business-logic-vulnerabilities/METHODOLOGY.md +337 -0
- package/skills/business-logic-vulnerabilities/SCENARIOS.md +1095 -0
- package/skills/business-logic-vulnerabilities/SKILL.md +711 -0
- package/skills/classical-cipher-analysis/SKILL.md +663 -0
- package/skills/clickjacking/SKILL.md +163 -0
- package/skills/cmdi-command-injection/SKILL.md +687 -0
- package/skills/code-obfuscation-deobfuscation/SKILL.md +391 -0
- package/skills/container-escape-techniques/DOCKER_ESCAPE_CHAINS.md +296 -0
- package/skills/container-escape-techniques/SKILL.md +339 -0
- package/skills/cors-cross-origin-misconfiguration/SCENARIOS.md +152 -0
- package/skills/cors-cross-origin-misconfiguration/SKILL.md +270 -0
- package/skills/crlf-injection/SKILL.md +179 -0
- package/skills/csp-bypass-advanced/SKILL.md +259 -0
- package/skills/csrf-cross-site-request-forgery/SKILL.md +526 -0
- package/skills/csv-formula-injection/SKILL.md +144 -0
- package/skills/dangling-markup-injection/SKILL.md +321 -0
- package/skills/defi-attack-patterns/SKILL.md +355 -0
- package/skills/dependency-confusion/SKILL.md +178 -0
- package/skills/deserialization-insecure/JAVA_GADGET_CHAINS.md +511 -0
- package/skills/deserialization-insecure/SKILL.md +725 -0
- package/skills/dns-rebinding-attacks/SKILL.md +337 -0
- package/skills/email-header-injection/SKILL.md +349 -0
- package/skills/expression-language-injection/SKILL.md +243 -0
- package/skills/file-access-vuln/SKILL.md +33 -0
- package/skills/format-string-exploitation/SKILL.md +312 -0
- package/skills/ghost-bits-cast-attack/PAYLOAD_COOKBOOK.md +448 -0
- package/skills/ghost-bits-cast-attack/SKILL.md +799 -0
- package/skills/graphql-and-hidden-parameters/SKILL.md +50 -0
- package/skills/hack/SKILL.md +162 -0
- package/skills/hash-attack-techniques/SKILL.md +491 -0
- package/skills/heap-exploitation/HOUSE_OF_TECHNIQUES.md +244 -0
- package/skills/heap-exploitation/IO_FILE_EXPLOITATION.md +256 -0
- package/skills/heap-exploitation/SKILL.md +217 -0
- package/skills/http-host-header-attacks/SKILL.md +323 -0
- package/skills/http-parameter-pollution/SKILL.md +208 -0
- package/skills/http2-specific-attacks/SKILL.md +350 -0
- package/skills/idor-broken-object-authorization/SKILL.md +336 -0
- package/skills/injection-checking/EXTRA_INJECTION_TYPES.md +450 -0
- package/skills/injection-checking/SKILL.md +50 -0
- package/skills/insecure-source-code-management/SKILL.md +161 -0
- package/skills/ios-pentesting-tricks/IOS_RUNTIME_TRICKS.md +411 -0
- package/skills/ios-pentesting-tricks/SKILL.md +418 -0
- package/skills/jndi-injection/SKILL.md +265 -0
- package/skills/jwt-oauth-token-attacks/SKILL.md +301 -0
- package/skills/kernel-exploitation/KERNEL_HEAP_TECHNIQUES.md +293 -0
- package/skills/kernel-exploitation/KERNEL_MITIGATION_BYPASS.md +224 -0
- package/skills/kernel-exploitation/SKILL.md +307 -0
- package/skills/kubernetes-pentesting/SKILL.md +348 -0
- package/skills/lattice-crypto-attacks/SKILL.md +497 -0
- package/skills/linux-lateral-movement/SKILL.md +348 -0
- package/skills/linux-privilege-escalation/KERNEL_EXPLOITS_CHECKLIST.md +260 -0
- package/skills/linux-privilege-escalation/SKILL.md +346 -0
- package/skills/linux-privilege-escalation/SUID_CAPABILITIES_TRICKS.md +305 -0
- package/skills/linux-security-bypass/SKILL.md +345 -0
- package/skills/llm-prompt-injection/JAILBREAK_PATTERNS.md +306 -0
- package/skills/llm-prompt-injection/SKILL.md +357 -0
- package/skills/macos-process-injection/DYLIB_XPC_TECHNIQUES.md +373 -0
- package/skills/macos-process-injection/SKILL.md +384 -0
- package/skills/macos-security-bypass/SKILL.md +337 -0
- package/skills/macos-security-bypass/TCC_BYPASS_MATRIX.md +200 -0
- package/skills/memory-forensics-volatility/SKILL.md +323 -0
- package/skills/memory-forensics-volatility/VOLATILITY_CHEATSHEET.md +225 -0
- package/skills/mobile-ssl-pinning-bypass/SKILL.md +531 -0
- package/skills/network-protocol-attacks/NAME_RESOLUTION_POISONING.md +226 -0
- package/skills/network-protocol-attacks/SKILL.md +330 -0
- package/skills/nosql-injection/SKILL.md +341 -0
- package/skills/ntlm-relay-coercion/COERCION_METHODS.md +253 -0
- package/skills/ntlm-relay-coercion/SKILL.md +267 -0
- package/skills/oauth-oidc-misconfiguration/SKILL.md +46 -0
- package/skills/open-redirect/SKILL.md +380 -0
- package/skills/path-traversal-lfi/SKILL.md +802 -0
- package/skills/prototype-pollution/SKILL.md +190 -0
- package/skills/prototype-pollution-advanced/KNOWN_GADGETS.md +253 -0
- package/skills/prototype-pollution-advanced/SKILL.md +338 -0
- package/skills/race-condition/SKILL.md +526 -0
- package/skills/recon-and-methodology/SKILL.md +389 -0
- package/skills/recon-for-sec/SKILL.md +29 -0
- package/skills/request-smuggling/H2_SMUGGLING_VARIANTS.md +498 -0
- package/skills/request-smuggling/SKILL.md +314 -0
- package/skills/reverse-shell-techniques/SHELL_CHEATSHEET.md +196 -0
- package/skills/reverse-shell-techniques/SKILL.md +290 -0
- package/skills/rsa-attack-techniques/RSA_ATTACK_CATALOG.md +432 -0
- package/skills/rsa-attack-techniques/SKILL.md +437 -0
- package/skills/saml-sso-assertion-attacks/SKILL.md +41 -0
- package/skills/sandbox-escape-techniques/PYTHON_SANDBOX_ESCAPE.md +349 -0
- package/skills/sandbox-escape-techniques/SECCOMP_BYPASS.md +332 -0
- package/skills/sandbox-escape-techniques/SKILL.md +250 -0
- package/skills/smart-contract-vulnerabilities/SKILL.md +314 -0
- package/skills/smart-contract-vulnerabilities/SOLIDITY_VULN_PATTERNS.md +460 -0
- package/skills/sqli-sql-injection/SCENARIOS.md +575 -0
- package/skills/sqli-sql-injection/SKILL.md +489 -0
- package/skills/sqli-sql-injection/SQLMAP_ADVANCED.md +642 -0
- package/skills/ssrf-server-side-request-forgery/SCENARIOS.md +226 -0
- package/skills/ssrf-server-side-request-forgery/SKILL.md +323 -0
- package/skills/ssrf-server-side-request-forgery/URL_PARSER_TRICKS.md +650 -0
- package/skills/ssti-server-side-template-injection/ENGINE_PAYLOADS.md +456 -0
- package/skills/ssti-server-side-template-injection/SCENARIOS.md +319 -0
- package/skills/ssti-server-side-template-injection/SKILL.md +344 -0
- package/skills/stack-overflow-and-rop/ROP_ADVANCED_TECHNIQUES.md +249 -0
- package/skills/stack-overflow-and-rop/SKILL.md +304 -0
- package/skills/steganography-techniques/SKILL.md +348 -0
- package/skills/steganography-techniques/STEGO_TOOLS_GUIDE.md +335 -0
- package/skills/subdomain-takeover/SKILL.md +247 -0
- package/skills/symbolic-execution-tools/ANGR_COOKBOOK.md +437 -0
- package/skills/symbolic-execution-tools/SKILL.md +419 -0
- package/skills/symmetric-cipher-attacks/BLOCK_CIPHER_ATTACKS.md +364 -0
- package/skills/symmetric-cipher-attacks/SKILL.md +462 -0
- package/skills/traffic-analysis-pcap/SKILL.md +341 -0
- package/skills/tunneling-and-pivoting/SKILL.md +343 -0
- package/skills/type-juggling/SKILL.md +291 -0
- package/skills/unauthorized-access-common-services/PORT_SERVICE_MATRIX.md +340 -0
- package/skills/unauthorized-access-common-services/SKILL.md +388 -0
- package/skills/upload-insecure-files/SCENARIOS.md +158 -0
- package/skills/upload-insecure-files/SKILL.md +543 -0
- package/skills/vm-and-bytecode-reverse/SKILL.md +450 -0
- package/skills/vr-cheatsheet-authentication_bypass/SKILL.md +184 -0
- package/skills/vr-cheatsheet-dangerous_functions/SKILL.md +200 -0
- package/skills/vr-cheatsheet-linux_commands/SKILL.md +40 -0
- package/skills/vr-cheatsheet-rce/SKILL.md +177 -0
- package/skills/vr-cheatsheet-reverse_engineering/SKILL.md +144 -0
- package/skills/vr-cheatsheet-sqli/SKILL.md +270 -0
- package/skills/vr-cheatsheet-ssrf/SKILL.md +173 -0
- package/skills/vr-cheatsheet-xss/SKILL.md +177 -0
- package/skills/vr-methodology-mindset_and_tips/SKILL.md +51 -0
- package/skills/vr-template-vulnerability_report_template/SKILL.md +59 -0
- package/skills/vr-writeup-CVE-2026-9136/SKILL.md +171 -0
- package/skills/vr-writeup-ZVE-2026-3795/SKILL.md +350 -0
- package/skills/vr-writeup-api_key_leak/SKILL.md +103 -0
- package/skills/waf-bypass-techniques/SKILL.md +290 -0
- package/skills/waf-bypass-techniques/WAF_PRODUCT_MATRIX.md +202 -0
- package/skills/web-cache-deception/CACHE_POISONING_TECHNIQUES.md +637 -0
- package/skills/web-cache-deception/SKILL.md +222 -0
- package/skills/websocket-security/SKILL.md +454 -0
- package/skills/windows-av-evasion/AMSI_BYPASS_TECHNIQUES.md +289 -0
- package/skills/windows-av-evasion/SKILL.md +342 -0
- package/skills/windows-lateral-movement/CREDENTIAL_DUMPING.md +308 -0
- package/skills/windows-lateral-movement/SKILL.md +335 -0
- package/skills/windows-privilege-escalation/SKILL.md +328 -0
- package/skills/windows-privilege-escalation/TOKEN_POTATO_TRICKS.md +216 -0
- package/skills/windows-privilege-escalation/UAC_BYPASS_METHODS.md +225 -0
- package/skills/xslt-injection/SKILL.md +281 -0
- package/skills/xss-cross-site-scripting/ADVANCED_XSS_TRICKS.md +276 -0
- package/skills/xss-cross-site-scripting/SCENARIOS.md +278 -0
- package/skills/xss-cross-site-scripting/SKILL.md +379 -0
- package/skills/xxe-xml-external-entity/SCENARIOS.md +112 -0
- package/skills/xxe-xml-external-entity/SKILL.md +554 -0
- package/src/agent.js +1 -1
- package/src/session.js +47 -11
- package/src/skills.js +30 -6
- package/src/ui.js +1 -1
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: subdomain-takeover
|
|
3
|
+
description: >-
|
|
4
|
+
Subdomain takeover detection and exploitation playbook. Use when targets have
|
|
5
|
+
dangling CNAME/NS/MX records pointing to deprovisioned cloud resources, expired
|
|
6
|
+
third-party services, or unclaimed SaaS tenants that an attacker can register
|
|
7
|
+
to serve content under the victim's domain.gated: true
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# SKILL: Subdomain Takeover — Detection & Exploitation Playbook
|
|
11
|
+
|
|
12
|
+
> **AI LOAD INSTRUCTION**: Covers CNAME/NS/MX takeover, per-provider fingerprint matching, claim procedures, and defensive monitoring. Base models often confuse "CNAME exists" with "takeover possible" — the key is whether the *resource behind the CNAME is unclaimed and claimable*.
|
|
13
|
+
|
|
14
|
+
## 0. RELATED ROUTING
|
|
15
|
+
|
|
16
|
+
- [ssrf-server-side-request-forgery](../ssrf-server-side-request-forgery/SKILL.md) when a subdomain takeover is used to bypass SSRF allowlists trusting `*.target.com`
|
|
17
|
+
- [cors-cross-origin-misconfiguration](../cors-cross-origin-misconfiguration/SKILL.md) when CORS trusts `*.target.com` — takeover → full cross-origin read
|
|
18
|
+
- [xss-cross-site-scripting](../xss-cross-site-scripting/SKILL.md) takeover gives you script execution under target origin (cookie theft, OAuth redirect abuse)
|
|
19
|
+
- [http-host-header-attacks](../http-host-header-attacks/SKILL.md) when Host routing leads to subdomain-scoped cache or auth issues
|
|
20
|
+
- [web-cache-deception](../web-cache-deception/SKILL.md) when a taken-over subdomain shares cache with the main domain
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 1. CORE CONCEPT
|
|
25
|
+
|
|
26
|
+
Subdomain takeover occurs when:
|
|
27
|
+
|
|
28
|
+
1. `sub.target.com` has a DNS record (CNAME, NS, A) pointing to an external service
|
|
29
|
+
2. The external resource is **no longer provisioned** (deleted S3 bucket, removed Heroku app, etc.)
|
|
30
|
+
3. The attacker can **register/claim** that exact resource name on the provider
|
|
31
|
+
4. The attacker now controls content served under `sub.target.com`
|
|
32
|
+
|
|
33
|
+
**Impact**: cookie theft (parent domain cookies), OAuth token interception, phishing under trusted domain, CORS bypass, CSP bypass via whitelisted subdomain.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 2. DETECTION METHODOLOGY
|
|
38
|
+
|
|
39
|
+
### 2.1 CNAME Enumeration
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
1. Collect subdomains (amass, subfinder, assetfinder, crt.sh, SecurityTrails)
|
|
43
|
+
2. Resolve DNS for each:
|
|
44
|
+
dig CNAME sub.target.com +short
|
|
45
|
+
3. For each CNAME → check if the CNAME target returns NXDOMAIN or a provider error
|
|
46
|
+
4. Match error response against fingerprint table (Section 3)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 2.2 Key Signals
|
|
50
|
+
|
|
51
|
+
| Signal | Meaning |
|
|
52
|
+
|---|---|
|
|
53
|
+
| CNAME → `xxx.s3.amazonaws.com` + HTTP 404 "NoSuchBucket" | S3 bucket deleted, claimable |
|
|
54
|
+
| CNAME → `xxx.herokuapp.com` + "No such app" | Heroku app deleted |
|
|
55
|
+
| CNAME → `xxx.github.io` + 404 "There isn't a GitHub Pages site here" | GitHub Pages unclaimed |
|
|
56
|
+
| NXDOMAIN on the CNAME target domain itself | Target domain expired or never existed |
|
|
57
|
+
| CNAME → provider but HTTP 200 with default parking page | May or may not be claimable — verify |
|
|
58
|
+
|
|
59
|
+
### 2.3 Automated Tools
|
|
60
|
+
|
|
61
|
+
| Tool | Purpose |
|
|
62
|
+
|---|---|
|
|
63
|
+
| `subjack` | Automated CNAME takeover checking |
|
|
64
|
+
| `nuclei -t takeovers/` | Nuclei takeover detection templates |
|
|
65
|
+
| `can-i-take-over-xyz` (GitHub) | Reference for which services are vulnerable |
|
|
66
|
+
| `dnsreaper` | Multi-provider takeover scanner |
|
|
67
|
+
| `subzy` | Fast subdomain takeover verification |
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## 3. SERVICE PROVIDER FINGERPRINT TABLE
|
|
72
|
+
|
|
73
|
+
| Provider | CNAME Pattern | Fingerprint (HTTP Response) | Claimable? |
|
|
74
|
+
|---|---|---|---|
|
|
75
|
+
| **AWS S3** | `*.s3.amazonaws.com` / `*.s3-website-*.amazonaws.com` | `NoSuchBucket` (404) | Yes — create bucket with matching name |
|
|
76
|
+
| **GitHub Pages** | `*.github.io` | `There isn't a GitHub Pages site here` (404) | Yes — create repo + enable Pages |
|
|
77
|
+
| **Heroku** | `*.herokuapp.com` / `*.herokudns.com` | `No such app` | Yes — create app with matching name |
|
|
78
|
+
| **Azure** | `*.azurewebsites.net` / `*.cloudapp.azure.com` / `*.trafficmanager.net` | Various default pages, NXDOMAIN | Yes — register matching resource |
|
|
79
|
+
| **Shopify** | `*.myshopify.com` | `Sorry, this shop is currently unavailable` | Yes — create shop, add custom domain |
|
|
80
|
+
| **Fastly** | CNAME to Fastly edge | `Fastly error: unknown domain` | Yes — add domain to Fastly service |
|
|
81
|
+
| **Pantheon** | `*.pantheonsite.io` | `404 Site Not Found` with Pantheon branding | Yes |
|
|
82
|
+
| **Tumblr** | `*.tumblr.com` (custom domain CNAME) | `There's nothing here` / `Whatever you were looking for doesn't exist` | Yes |
|
|
83
|
+
| **WordPress.com** | CNAME to `*.wordpress.com` | `Do you want to register` | Yes — claim domain in WP.com |
|
|
84
|
+
| **Zendesk** | `*.zendesk.com` | `Help Center Closed` / Zendesk branding on error | Yes — create matching subdomain |
|
|
85
|
+
| **Unbounce** | `*.unbouncepages.com` | `The requested URL was not found` | Yes |
|
|
86
|
+
| **Ghost** | `*.ghost.io` | `404 Not Found` Ghost error | Yes |
|
|
87
|
+
| **Surge.sh** | `*.surge.sh` | `project not found` | Yes |
|
|
88
|
+
| **Fly.io** | CNAME to `*.fly.dev` | Fly.io default 404 | Yes |
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## 4. TAKEOVER PROCEDURE — COMMON PROVIDERS
|
|
93
|
+
|
|
94
|
+
### 4.1 AWS S3
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
1. Confirm: curl -s http://sub.target.com → "NoSuchBucket"
|
|
98
|
+
2. Extract bucket name from CNAME (e.g., sub.target.com.s3.amazonaws.com → bucket = "sub.target.com")
|
|
99
|
+
3. aws s3 mb s3://sub.target.com --region <region>
|
|
100
|
+
4. Upload index.html proving control
|
|
101
|
+
5. Enable static website hosting
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 4.2 GitHub Pages
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
1. Confirm: curl -s https://sub.target.com → "There isn't a GitHub Pages site here"
|
|
108
|
+
2. Create GitHub repo (any name)
|
|
109
|
+
3. Add CNAME file containing "sub.target.com"
|
|
110
|
+
4. Enable GitHub Pages in repo settings
|
|
111
|
+
5. Wait for DNS propagation (GitHub verifies CNAME match)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 4.3 Heroku
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
1. Confirm: curl -s http://sub.target.com → "No such app"
|
|
118
|
+
2. heroku create <app-name-from-cname>
|
|
119
|
+
3. heroku domains:add sub.target.com
|
|
120
|
+
4. Deploy proof-of-concept page
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## 5. NS TAKEOVER — HIGH SEVERITY
|
|
126
|
+
|
|
127
|
+
NS takeover is **far more dangerous** than CNAME takeover: you control **all DNS resolution** for the zone.
|
|
128
|
+
|
|
129
|
+
### How It Happens
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
target.com NS → ns1.expireddomain.com
|
|
133
|
+
↓
|
|
134
|
+
attacker registers expireddomain.com
|
|
135
|
+
↓
|
|
136
|
+
attacker now controls ALL DNS for target.com
|
|
137
|
+
(A records, MX records, TXT records — everything)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Detection
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
1. Enumerate NS records: dig NS target.com +short
|
|
144
|
+
2. Check each NS domain: whois ns1.example.com → is the domain expired or available?
|
|
145
|
+
3. Also check: dig A ns1.example.com → NXDOMAIN/SERVFAIL?
|
|
146
|
+
4. Subdelegated zones: check NS for sub.target.com specifically
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Impact
|
|
150
|
+
|
|
151
|
+
- Full domain takeover (serve any content, intercept email, issue TLS certs via DNS-01)
|
|
152
|
+
- Issue DV certificates from any CA using DNS challenge
|
|
153
|
+
- Modify SPF/DKIM/DMARC → send authenticated email as target
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## 6. MX TAKEOVER — EMAIL INTERCEPTION
|
|
158
|
+
|
|
159
|
+
When MX records point to deprovisioned mail services:
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
target.com MX → mail.deadservice.com (service discontinued)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
If attacker can claim `mail.deadservice.com` or the mail tenant:
|
|
166
|
+
- Receive password reset emails
|
|
167
|
+
- Intercept sensitive communications
|
|
168
|
+
- Potentially reset accounts that use email-based auth
|
|
169
|
+
|
|
170
|
+
### Common Scenario
|
|
171
|
+
|
|
172
|
+
Expired Google Workspace / Microsoft 365 tenant → MX still points to Google/Microsoft → attacker creates new tenant and claims the domain.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## 7. WILDCARD DNS RISKS
|
|
177
|
+
|
|
178
|
+
If `*.target.com` has a wildcard CNAME to a claimable service:
|
|
179
|
+
- **Every** undefined subdomain is vulnerable
|
|
180
|
+
- `anything.target.com` can be taken over
|
|
181
|
+
- Massively increases attack surface
|
|
182
|
+
|
|
183
|
+
Detection: `dig A random1234567.target.com` — if it resolves, wildcard exists.
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## 8. DETECTION & EXPLOITATION DECISION TREE
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
Subdomain discovered (sub.target.com)?
|
|
191
|
+
├── Resolve DNS records
|
|
192
|
+
│ ├── Has CNAME → external service?
|
|
193
|
+
│ │ ├── HTTP response matches known fingerprint? (Section 3)
|
|
194
|
+
│ │ │ ├── YES → Attempt claim on provider (Section 4)
|
|
195
|
+
│ │ │ │ ├── Claim successful → TAKEOVER CONFIRMED
|
|
196
|
+
│ │ │ │ └── Claim blocked (name reserved, region locked) → document, try variations
|
|
197
|
+
│ │ │ └── NO → Service active, no takeover
|
|
198
|
+
│ │ └── CNAME target NXDOMAIN?
|
|
199
|
+
│ │ ├── Target is a registrable domain? → Register it → full control
|
|
200
|
+
│ │ └── Target is a subdomain of active provider → check provider claim process
|
|
201
|
+
│ │
|
|
202
|
+
│ ├── Has NS records → external nameserver?
|
|
203
|
+
│ │ ├── NS domain expired/available? → Register → FULL ZONE TAKEOVER
|
|
204
|
+
│ │ └── NS domain active → no takeover
|
|
205
|
+
│ │
|
|
206
|
+
│ ├── Has MX → external mail service?
|
|
207
|
+
│ │ ├── Mail service deprovisioned/claimable? → Claim tenant → EMAIL INTERCEPTION
|
|
208
|
+
│ │ └── Active mail service → no takeover
|
|
209
|
+
│ │
|
|
210
|
+
│ └── Has A record → IP address?
|
|
211
|
+
│ ├── IP belongs to elastic cloud (AWS EIP, Azure, GCP)?
|
|
212
|
+
│ │ ├── IP unassigned? → Claim IP → serve content
|
|
213
|
+
│ │ └── IP assigned to another customer → no takeover
|
|
214
|
+
│ └── IP belongs to dedicated server → no takeover
|
|
215
|
+
│
|
|
216
|
+
└── Post-takeover impact assessment
|
|
217
|
+
├── Shared cookies with parent domain? → Session hijacking
|
|
218
|
+
├── CORS trusts *.target.com? → Cross-origin data theft
|
|
219
|
+
├── CSP whitelists *.target.com? → XSS via taken-over subdomain
|
|
220
|
+
├── OAuth redirect_uri allows sub.target.com? → Token theft
|
|
221
|
+
└── Can issue TLS cert for sub.target.com? → Full MITM
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## 9. DEFENSE & REMEDIATION
|
|
227
|
+
|
|
228
|
+
| Action | Priority |
|
|
229
|
+
|---|---|
|
|
230
|
+
| Remove DNS records when deprovisioning cloud resources | Critical |
|
|
231
|
+
| Monitor CNAME targets for NXDOMAIN responses | High |
|
|
232
|
+
| Use DNS monitoring tools (SecurityTrails, DNSHistory) | High |
|
|
233
|
+
| Claim/reserve resource names before deleting DNS records | High |
|
|
234
|
+
| Audit NS delegations — ensure NS domains are owned and renewed | Critical |
|
|
235
|
+
| Avoid wildcard CNAMEs to third-party services | Medium |
|
|
236
|
+
| Implement Certificate Transparency monitoring | Medium |
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## 10. TRICK NOTES — WHAT AI MODELS MISS
|
|
241
|
+
|
|
242
|
+
1. **CNAME ≠ takeover**: A CNAME to S3 that returns 403 (bucket exists, private) is NOT vulnerable. Only `NoSuchBucket` (404) is.
|
|
243
|
+
2. **Region matters for S3**: Bucket names are global, but website endpoints are regional. Try matching the region from the CNAME.
|
|
244
|
+
3. **GitHub Pages verification**: GitHub added domain verification — org-verified domains cannot be claimed by others. Check if target uses this.
|
|
245
|
+
4. **Edge cases**: Some providers (e.g., Cloudfront) require specific distribution configuration, not just domain claiming.
|
|
246
|
+
5. **Second-order takeover**: `sub.target.com CNAME → other.target.com CNAME → dead-service.com` — the chain must be followed fully.
|
|
247
|
+
6. **SPF subdomain takeover**: If SPF includes `include:sub.target.com` and you take over `sub.target.com`, you can modify its SPF TXT record to authorize your mail server → send spoofed email as `target.com`.
|
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
# angr Cookbook — Ready-to-Use Script Patterns for CTF Challenges
|
|
2
|
+
|
|
3
|
+
> **AI LOAD INSTRUCTION**: Load this when you need drop-in angr script templates for common CTF challenge patterns. Each recipe includes the scenario description, complete script, and adaptation notes. Assumes the main [SKILL.md](./SKILL.md) is already loaded for angr fundamentals.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Recipe 1: Basic find/avoid by Address
|
|
8
|
+
|
|
9
|
+
**Scenario**: Binary prints "Correct" at 0x401234, "Wrong" at 0x401300. Input via stdin.
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
import angr
|
|
13
|
+
|
|
14
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
15
|
+
state = proj.factory.entry_state()
|
|
16
|
+
simgr = proj.factory.simulation_manager(state)
|
|
17
|
+
|
|
18
|
+
simgr.explore(find=0x401234, avoid=[0x401300])
|
|
19
|
+
|
|
20
|
+
if simgr.found:
|
|
21
|
+
print(simgr.found[0].posix.dumps(0)) # fd 0 = stdin
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Recipe 2: Find by stdout Content
|
|
27
|
+
|
|
28
|
+
**Scenario**: Success/failure messages not at fixed addresses (PIE binary or indirect calls).
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import angr
|
|
32
|
+
|
|
33
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
34
|
+
state = proj.factory.entry_state()
|
|
35
|
+
simgr = proj.factory.simulation_manager(state)
|
|
36
|
+
|
|
37
|
+
simgr.explore(
|
|
38
|
+
find=lambda s: b"Correct" in s.posix.dumps(1),
|
|
39
|
+
avoid=lambda s: b"Wrong" in s.posix.dumps(1)
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
if simgr.found:
|
|
43
|
+
print(simgr.found[0].posix.dumps(0))
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Recipe 3: Symbolic stdin with Printable Constraint
|
|
49
|
+
|
|
50
|
+
**Scenario**: Flag is 32 printable characters read via scanf/fgets.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import angr
|
|
54
|
+
import claripy
|
|
55
|
+
|
|
56
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
57
|
+
|
|
58
|
+
FLAG_LEN = 32
|
|
59
|
+
flag = claripy.BVS("flag", 8 * FLAG_LEN)
|
|
60
|
+
|
|
61
|
+
state = proj.factory.entry_state(stdin=flag)
|
|
62
|
+
|
|
63
|
+
for i in range(FLAG_LEN):
|
|
64
|
+
byte = flag.get_byte(i)
|
|
65
|
+
state.solver.add(byte >= 0x20)
|
|
66
|
+
state.solver.add(byte <= 0x7e)
|
|
67
|
+
|
|
68
|
+
simgr = proj.factory.simulation_manager(state)
|
|
69
|
+
simgr.explore(find=0x401234, avoid=[0x401300])
|
|
70
|
+
|
|
71
|
+
if simgr.found:
|
|
72
|
+
solution = simgr.found[0].solver.eval(flag, cast_to=bytes)
|
|
73
|
+
print(f"Flag: {solution}")
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Recipe 4: Symbolic argv
|
|
79
|
+
|
|
80
|
+
**Scenario**: Binary takes flag as command-line argument `./challenge FLAG`.
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
import angr
|
|
84
|
+
import claripy
|
|
85
|
+
|
|
86
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
87
|
+
|
|
88
|
+
flag = claripy.BVS("flag", 8 * 32)
|
|
89
|
+
state = proj.factory.full_init_state(
|
|
90
|
+
args=['./challenge', flag],
|
|
91
|
+
add_options=angr.options.unicorn
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
for i in range(32):
|
|
95
|
+
b = flag.get_byte(i)
|
|
96
|
+
state.solver.add(b >= 0x20, b <= 0x7e)
|
|
97
|
+
|
|
98
|
+
simgr = proj.factory.simulation_manager(state)
|
|
99
|
+
simgr.explore(find=0x401234, avoid=[0x401300])
|
|
100
|
+
|
|
101
|
+
if simgr.found:
|
|
102
|
+
print(simgr.found[0].solver.eval(flag, cast_to=bytes))
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Recipe 5: Symbolic File Input
|
|
108
|
+
|
|
109
|
+
**Scenario**: Binary reads flag from a file.
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
import angr
|
|
113
|
+
import claripy
|
|
114
|
+
|
|
115
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
116
|
+
|
|
117
|
+
flag = claripy.BVS("flag", 8 * 64)
|
|
118
|
+
sim_file = angr.SimFile("flag.txt", content=flag)
|
|
119
|
+
|
|
120
|
+
state = proj.factory.entry_state(fs={'/tmp/flag.txt': sim_file})
|
|
121
|
+
|
|
122
|
+
simgr = proj.factory.simulation_manager(state)
|
|
123
|
+
simgr.explore(find=0x401234, avoid=[0x401300])
|
|
124
|
+
|
|
125
|
+
if simgr.found:
|
|
126
|
+
print(simgr.found[0].solver.eval(flag, cast_to=bytes))
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Recipe 6: Hook scanf
|
|
132
|
+
|
|
133
|
+
**Scenario**: Custom scanf that angr's default SimProcedure handles incorrectly.
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
import angr
|
|
137
|
+
import claripy
|
|
138
|
+
|
|
139
|
+
class MyScanf(angr.SimProcedure):
|
|
140
|
+
def run(self, fmt, ptr):
|
|
141
|
+
buf = claripy.BVS("scanf_input", 8 * 32)
|
|
142
|
+
self.state.memory.store(ptr, buf)
|
|
143
|
+
self.state.globals['scanf_buf'] = buf
|
|
144
|
+
return 1
|
|
145
|
+
|
|
146
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
147
|
+
proj.hook_symbol('__isoc99_scanf', MyScanf())
|
|
148
|
+
|
|
149
|
+
state = proj.factory.entry_state()
|
|
150
|
+
simgr = proj.factory.simulation_manager(state)
|
|
151
|
+
simgr.explore(find=0x401234, avoid=[0x401300])
|
|
152
|
+
|
|
153
|
+
if simgr.found:
|
|
154
|
+
found = simgr.found[0]
|
|
155
|
+
buf = found.globals['scanf_buf']
|
|
156
|
+
print(found.solver.eval(buf, cast_to=bytes))
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Recipe 7: Hook strcmp to Leak Expected Value
|
|
162
|
+
|
|
163
|
+
**Scenario**: Binary compares input against computed value. Hook strcmp to extract the expected string.
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
import angr
|
|
167
|
+
import claripy
|
|
168
|
+
|
|
169
|
+
class LeakStrcmp(angr.SimProcedure):
|
|
170
|
+
def run(self, s1, s2):
|
|
171
|
+
# Read both strings up to null
|
|
172
|
+
str1 = self.state.memory.load(s1, 64)
|
|
173
|
+
str2 = self.state.memory.load(s2, 64)
|
|
174
|
+
self.state.globals['cmp_s1'] = s1
|
|
175
|
+
self.state.globals['cmp_s2'] = s2
|
|
176
|
+
return claripy.If(str1 == str2, claripy.BVV(0, 32), claripy.BVV(1, 32))
|
|
177
|
+
|
|
178
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
179
|
+
proj.hook_symbol('strcmp', LeakStrcmp())
|
|
180
|
+
|
|
181
|
+
state = proj.factory.entry_state()
|
|
182
|
+
simgr = proj.factory.simulation_manager(state)
|
|
183
|
+
simgr.explore(find=0x401234)
|
|
184
|
+
|
|
185
|
+
if simgr.found:
|
|
186
|
+
found = simgr.found[0]
|
|
187
|
+
s2_addr = found.solver.eval(found.globals['cmp_s2'])
|
|
188
|
+
expected = found.memory.load(s2_addr, 32)
|
|
189
|
+
print(found.solver.eval(expected, cast_to=bytes))
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## Recipe 8: Start from Specific Function (skip initialization)
|
|
195
|
+
|
|
196
|
+
**Scenario**: Large binary, but the check function is known. Skip everything before it.
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
import angr
|
|
200
|
+
import claripy
|
|
201
|
+
|
|
202
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
203
|
+
|
|
204
|
+
CHECK_FUNC = 0x401500
|
|
205
|
+
BUF_ADDR = 0x600000
|
|
206
|
+
|
|
207
|
+
flag = claripy.BVS("flag", 8 * 32)
|
|
208
|
+
|
|
209
|
+
state = proj.factory.blank_state(addr=CHECK_FUNC)
|
|
210
|
+
state.memory.store(BUF_ADDR, flag)
|
|
211
|
+
state.regs.rdi = BUF_ADDR # first arg = buffer pointer (System V ABI)
|
|
212
|
+
state.regs.rsi = 32 # second arg = length
|
|
213
|
+
|
|
214
|
+
state.stack_push(0xDEADBEEF) # fake return address
|
|
215
|
+
|
|
216
|
+
simgr = proj.factory.simulation_manager(state)
|
|
217
|
+
simgr.explore(
|
|
218
|
+
find=lambda s: b"OK" in s.posix.dumps(1),
|
|
219
|
+
avoid=lambda s: b"FAIL" in s.posix.dumps(1)
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
if simgr.found:
|
|
223
|
+
print(simgr.found[0].solver.eval(flag, cast_to=bytes))
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Recipe 9: Veritesting (Merge Paths at Branches)
|
|
229
|
+
|
|
230
|
+
**Scenario**: Path explosion due to many conditional branches (e.g., per-character check).
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
import angr
|
|
234
|
+
|
|
235
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
236
|
+
state = proj.factory.entry_state()
|
|
237
|
+
simgr = proj.factory.simulation_manager(state)
|
|
238
|
+
|
|
239
|
+
simgr.use_technique(angr.exploration_techniques.Veritesting())
|
|
240
|
+
simgr.explore(find=0x401234, avoid=[0x401300])
|
|
241
|
+
|
|
242
|
+
if simgr.found:
|
|
243
|
+
print(simgr.found[0].posix.dumps(0))
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Recipe 10: Unicorn Concrete Execution Speedup
|
|
249
|
+
|
|
250
|
+
**Scenario**: Most code is concrete (no symbolic data), only small portion needs symbolic reasoning.
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
import angr
|
|
254
|
+
|
|
255
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
256
|
+
state = proj.factory.entry_state(
|
|
257
|
+
add_options=angr.options.unicorn # enable Unicorn backend
|
|
258
|
+
)
|
|
259
|
+
simgr = proj.factory.simulation_manager(state)
|
|
260
|
+
simgr.explore(find=0x401234, avoid=[0x401300])
|
|
261
|
+
|
|
262
|
+
if simgr.found:
|
|
263
|
+
print(simgr.found[0].posix.dumps(0))
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## Recipe 11: Multi-Stage Binary (Sequential Checks)
|
|
269
|
+
|
|
270
|
+
**Scenario**: Binary has multiple stages, each validating part of the flag.
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
import angr
|
|
274
|
+
import claripy
|
|
275
|
+
|
|
276
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
277
|
+
|
|
278
|
+
stages = [
|
|
279
|
+
{"find": 0x401100, "avoid": [0x401150]},
|
|
280
|
+
{"find": 0x401200, "avoid": [0x401250]},
|
|
281
|
+
{"find": 0x401300, "avoid": [0x401350]},
|
|
282
|
+
]
|
|
283
|
+
|
|
284
|
+
flag = claripy.BVS("flag", 8 * 48)
|
|
285
|
+
state = proj.factory.entry_state(stdin=flag)
|
|
286
|
+
|
|
287
|
+
for i, stage in enumerate(stages):
|
|
288
|
+
simgr = proj.factory.simulation_manager(state)
|
|
289
|
+
simgr.explore(find=stage["find"], avoid=stage["avoid"])
|
|
290
|
+
if simgr.found:
|
|
291
|
+
state = simgr.found[0]
|
|
292
|
+
partial = state.solver.eval(flag, cast_to=bytes)
|
|
293
|
+
print(f"Stage {i+1}: {partial}")
|
|
294
|
+
else:
|
|
295
|
+
print(f"Stage {i+1} failed")
|
|
296
|
+
break
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## Recipe 12: Constrain Flag Format (CTF{...})
|
|
302
|
+
|
|
303
|
+
**Scenario**: Flag format is known: `flag{...}` with alphanumeric content.
|
|
304
|
+
|
|
305
|
+
```python
|
|
306
|
+
import angr
|
|
307
|
+
import claripy
|
|
308
|
+
|
|
309
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
310
|
+
|
|
311
|
+
FLAG_LEN = 40
|
|
312
|
+
flag = claripy.BVS("flag", 8 * FLAG_LEN)
|
|
313
|
+
state = proj.factory.entry_state(stdin=flag)
|
|
314
|
+
|
|
315
|
+
prefix = b"flag{"
|
|
316
|
+
for i, c in enumerate(prefix):
|
|
317
|
+
state.solver.add(flag.get_byte(i) == c)
|
|
318
|
+
state.solver.add(flag.get_byte(FLAG_LEN - 1) == ord('}'))
|
|
319
|
+
|
|
320
|
+
for i in range(len(prefix), FLAG_LEN - 1):
|
|
321
|
+
b = flag.get_byte(i)
|
|
322
|
+
state.solver.add(
|
|
323
|
+
claripy.Or(
|
|
324
|
+
claripy.And(b >= ord('0'), b <= ord('9')),
|
|
325
|
+
claripy.And(b >= ord('a'), b <= ord('z')),
|
|
326
|
+
claripy.And(b >= ord('A'), b <= ord('Z')),
|
|
327
|
+
b == ord('_'), b == ord('-')
|
|
328
|
+
)
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
simgr = proj.factory.simulation_manager(state)
|
|
332
|
+
simgr.explore(find=0x401234, avoid=[0x401300])
|
|
333
|
+
|
|
334
|
+
if simgr.found:
|
|
335
|
+
print(simgr.found[0].solver.eval(flag, cast_to=bytes))
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## Recipe 13: Replace rand() with Concrete Value
|
|
341
|
+
|
|
342
|
+
**Scenario**: Binary uses `rand()` making execution non-deterministic.
|
|
343
|
+
|
|
344
|
+
```python
|
|
345
|
+
import angr
|
|
346
|
+
|
|
347
|
+
class ConcreteRand(angr.SimProcedure):
|
|
348
|
+
def run(self):
|
|
349
|
+
return 42 # deterministic
|
|
350
|
+
|
|
351
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
352
|
+
proj.hook_symbol('rand', ConcreteRand())
|
|
353
|
+
proj.hook_symbol('srand', angr.SIM_PROCEDURES['libc']['srand']())
|
|
354
|
+
|
|
355
|
+
state = proj.factory.entry_state()
|
|
356
|
+
simgr = proj.factory.simulation_manager(state)
|
|
357
|
+
simgr.explore(find=0x401234)
|
|
358
|
+
|
|
359
|
+
if simgr.found:
|
|
360
|
+
print(simgr.found[0].posix.dumps(0))
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
---
|
|
364
|
+
|
|
365
|
+
## Recipe 14: Timeout + DFS for Deep Binaries
|
|
366
|
+
|
|
367
|
+
**Scenario**: Binary has deep execution path, BFS runs out of memory.
|
|
368
|
+
|
|
369
|
+
```python
|
|
370
|
+
import angr
|
|
371
|
+
import signal
|
|
372
|
+
|
|
373
|
+
def timeout_handler(signum, frame):
|
|
374
|
+
raise TimeoutError("angr timed out")
|
|
375
|
+
|
|
376
|
+
signal.signal(signal.SIGALRM, timeout_handler)
|
|
377
|
+
signal.alarm(300) # 5-minute timeout
|
|
378
|
+
|
|
379
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
380
|
+
state = proj.factory.entry_state()
|
|
381
|
+
simgr = proj.factory.simulation_manager(state)
|
|
382
|
+
|
|
383
|
+
simgr.use_technique(angr.exploration_techniques.DFS())
|
|
384
|
+
|
|
385
|
+
try:
|
|
386
|
+
simgr.explore(find=0x401234, avoid=[0x401300])
|
|
387
|
+
if simgr.found:
|
|
388
|
+
print(simgr.found[0].posix.dumps(0))
|
|
389
|
+
except TimeoutError:
|
|
390
|
+
print("Timed out — try narrowing search space")
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
## Recipe 15: Symbolic Memory at Global Buffer
|
|
396
|
+
|
|
397
|
+
**Scenario**: Input is read into a global buffer at a known address, but through a complex path.
|
|
398
|
+
|
|
399
|
+
```python
|
|
400
|
+
import angr
|
|
401
|
+
import claripy
|
|
402
|
+
|
|
403
|
+
proj = angr.Project('./challenge', auto_load_libs=False)
|
|
404
|
+
|
|
405
|
+
GLOBAL_BUF = 0x604080
|
|
406
|
+
CHECK_START = 0x401200
|
|
407
|
+
FLAG_LEN = 24
|
|
408
|
+
|
|
409
|
+
flag = claripy.BVS("flag", 8 * FLAG_LEN)
|
|
410
|
+
state = proj.factory.blank_state(addr=CHECK_START)
|
|
411
|
+
state.memory.store(GLOBAL_BUF, flag)
|
|
412
|
+
|
|
413
|
+
for i in range(FLAG_LEN):
|
|
414
|
+
b = flag.get_byte(i)
|
|
415
|
+
state.solver.add(b >= 0x20, b <= 0x7e)
|
|
416
|
+
|
|
417
|
+
simgr = proj.factory.simulation_manager(state)
|
|
418
|
+
simgr.explore(find=0x401300, avoid=[0x401400])
|
|
419
|
+
|
|
420
|
+
if simgr.found:
|
|
421
|
+
print(simgr.found[0].solver.eval(flag, cast_to=bytes))
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
## Adaptation Checklist
|
|
427
|
+
|
|
428
|
+
When adapting any recipe to your specific challenge:
|
|
429
|
+
|
|
430
|
+
1. **Update addresses**: `find=`, `avoid=`, function addresses, buffer addresses
|
|
431
|
+
2. **Match input method**: stdin, argv, file, or memory — use the right recipe
|
|
432
|
+
3. **Set correct flag length**: Too short = can't find solution; too long = slow
|
|
433
|
+
4. **Add format constraints**: Known prefix, charset, null terminator
|
|
434
|
+
5. **Hook problematic functions**: Any function causing path explosion or crashes
|
|
435
|
+
6. **Choose exploration technique**: BFS (default) for short paths, DFS for deep, Veritesting for branchy
|
|
436
|
+
7. **Enable Unicorn**: `add_options=angr.options.unicorn` for speed on mostly-concrete paths
|
|
437
|
+
8. **Check architecture**: Ensure `auto_load_libs=False` doesn't break needed functionality
|