pentesting 0.24.2 → 0.24.3

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.
@@ -1,22 +1,221 @@
1
- # CTF Mode — Flag Tracking Active
1
+ # CTF Mode — Competitive Flag Hunting Protocol
2
2
 
3
- CTF mode enables **automatic flag detection and tracking** in all tool output.
3
+ CTF mode enables **automatic flag detection, time-aware strategy, and aggressive exploitation** optimized for competitive CTF environments.
4
4
 
5
- ## What CTF Mode Does
5
+ ## 🏁 Flag Detection (Auto-Active)
6
6
 
7
- - **Flag detection**: All tool output is scanned for known flag patterns
8
- (HTB, THM, picoCTF, DEF CON OOO, CSAW, Google CTF, and generic `FLAG{...}` formats)
9
- - **Auto-recording**: Detected flags are automatically saved via `add_loot`
10
- - **Multiple flags**: Some challenges have multiple flagskeep hunting after the first
7
+ - **All tool output** is scanned for known flag patterns (50+ formats)
8
+ - Detected flags are **auto-recorded** via `add_loot`
9
+ - **Decode suspicious strings**: base64, hex, rot13, URL encoding, binary
10
+ - Proof files (`user.txt`, `root.txt`) contain hex hashesthese ARE flags
11
+ - Multiple flags per challenge are common — **keep hunting after the first**
12
+ - **Environment variables** and **database entries** often contain flags
11
13
 
12
- ## Flag Submission
14
+ ## ⏱️ Time Management Protocol
13
15
 
14
- When a flag is detected:
15
- - Check if a scoreboard URL exists — submit if so
16
- - Flags may be encoded (base64, hex, rot13) — decode suspicious strings
17
- - Proof files (user.txt, root.txt) may contain hex hashes — these ARE flags
16
+ CTF = time-constrained. Every second counts. Follow this decision framework:
17
+
18
+ ```
19
+ FIRST 10 MINUTES (Survey Phase):
20
+ ├── Full port scan (-Pn -p- --min-rate=5000)
21
+ ├── Quick service version detection on open ports
22
+ ├── Identify challenge category (web/pwn/crypto/forensics/reversing/misc)
23
+ ├── Check for low-hanging fruit: default creds, exposed files, known CVEs
24
+ └── Record ALL findings → update_mission immediately
25
+
26
+ 10-30 MINUTES (Targeted Attack):
27
+ ├── Focus on highest-probability attack vector
28
+ ├── Version+service → web_search("{service} {version} exploit CVE") IMMEDIATELY
29
+ ├── Web: directory fuzzing + injection probes in parallel
30
+ ├── If stuck after 15 min on one vector → SWITCH to next
31
+ └── Background: hash cracking, brute force if applicable
32
+
33
+ 30-60 MINUTES (Deep Exploitation):
34
+ ├── Chain findings: LFI→RCE, SQLi→file write→shell, SSRF→internal
35
+ ├── Custom exploit development: write_file → run_cmd
36
+ ├── Source code analysis if .git, .bak, .swp found
37
+ └── Multiple attack paths simultaneously (background processes)
38
+
39
+ 60+ MINUTES (Pivot & Escalate):
40
+ ├── Privilege escalation: ALL categories systematically
41
+ ├── Lateral movement if internal network exists
42
+ ├── Creative hunting: unusual files, hidden services, config secrets
43
+ └── Re-examine ALL earlier findings with new context/access
44
+
45
+ FINAL 15 MINUTES:
46
+ ├── Submit any discovered flags NOT yet submitted
47
+ ├── Re-check flag search on all accessible systems
48
+ ├── Document proof of exploitation
49
+ └── Check for flags in non-obvious locations (env vars, DBs, binary strings)
50
+ ```
51
+
52
+ ### Time-Boxing Rule
53
+ **If stuck on ONE vector for more than 15 minutes → SWITCH.**
54
+ - Record what you tried in `update_mission`
55
+ - Move to next highest-probability vector
56
+ - Come back later with new information/tools
57
+ - **Never tunnel-vision on a single approach**
58
+
59
+ ## 🏆 Competition Type Strategies
60
+
61
+ ### Jeopardy-Style CTF (Most Common)
62
+ ```
63
+ Category priorities (by typical point efficiency):
64
+ 1. Web → Usually most familiar, quickest solves
65
+ 2. Misc/Scripting → Often simple but creative
66
+ 3. Forensics → Methodical, tools-driven
67
+ 4. Crypto → Formula-based, can be automated
68
+ 5. Pwn → Time-intensive, high points
69
+ 6. Reversing → Most time-intensive
70
+
71
+ Strategy:
72
+ ├── Solve ALL easy challenges first (100-200pt)
73
+ ├── Then attack medium challenges in strongest category
74
+ ├── Only attempt hard challenges if time remains
75
+ ├── Dynamic scoring: popular challenges = less points, rare = more
76
+ └── First bloods matter: speed on new challenges
77
+ ```
78
+
79
+ ### Attack-Defense CTF
80
+ ```
81
+ DUAL-MODE: Attack opponents while defending your own services
82
+ ├── DEFEND FIRST (10 min): patch obvious vulns in your services
83
+ │ ├── Identify service source code → read quickly
84
+ │ ├── Fix: SQLi, command injection, hardcoded creds, path traversal
85
+ │ ├── Don't break functionality (SLA checks!)
86
+ │ └── Set up traffic monitoring on your services
87
+ ├── ATTACK: exploit same vulns in other teams
88
+ │ ├── Your patches tell you WHAT the vulns are → exploit those in opponents
89
+ │ ├── Automate: write exploit scripts that run against all team IPs
90
+ │ ├── Flag submission API: automate submission after each round
91
+ │ └── Rotate exploits — teams will patch, need new vectors
92
+ └── MONITOR: watch for attacks against you
93
+ ├── tcpdump on service ports → detect incoming exploits
94
+ ├── Read opponent exploit traffic → learn new attack vectors
95
+ └── Patch what they're exploiting
96
+ ```
97
+
98
+ ### King-of-the-Hill (KOTH)
99
+ ```
100
+ ├── Speed is everything → fastest to root keeps the crown
101
+ ├── Persistence: SSH key, cron job, hidden web shell
102
+ ├── Monitor for other players resetting the box
103
+ ├── Multiple persistence mechanisms (they'll remove some)
104
+ └── OPSEC: don't leave obvious traces that show your method
105
+ ```
106
+
107
+ ### Infrastructure/Boot2Root (HTB/THM-style)
108
+ ```
109
+ ├── Linear path: Recon → Foothold → User → Root
110
+ ├── Usually ONE intended path (sometimes alternate)
111
+ ├── user.txt = user-level flag, root.txt = root-level flag
112
+ ├── Enumerate EVERYTHING before exploiting
113
+ └── If stuck → web_search("{box_name} walkthrough hints")
114
+ ```
115
+
116
+ ## 🧠 Challenge Type Quick-Start Protocols
117
+
118
+ ### Web Challenges
119
+ ```
120
+ 1. whatweb + curl headers → technology fingerprint
121
+ 2. Directory/file discovery (ffuf/gobuster with common.txt)
122
+ 3. Source code review (view-source, .js files, comments)
123
+ 4. Input point mapping → test ALL of: SQLi, SSTI, XSS, CMDi, SSRF, LFI, XXE
124
+ 5. robots.txt, .git/HEAD, .env, sitemap.xml, backup files
125
+ 6. Cookie/session analysis → JWT decode, session fixation
126
+ 7. API endpoints → parameter fuzzing, IDOR, mass assignment
127
+ ```
128
+
129
+ ### Pwn (Binary Exploitation) Challenges
130
+ ```
131
+ 1. file + checksec → identify protections (NX, PIE, Canary, RELRO)
132
+ 2. Run binary locally → understand normal behavior
133
+ 3. Decompile (Ghidra/r2) → find vulnerability
134
+ 4. Classify: buffer overflow / format string / heap / use-after-free
135
+ 5. Develop exploit with pwntools
136
+ 6. Remote: adapt offsets for remote libc (libc database lookup)
137
+ 7. Common patterns: ret2libc, ROP chain, ret2win, shellcode
138
+ ```
139
+
140
+ ### Crypto Challenges
141
+ ```
142
+ 1. Identify the cryptosystem (RSA, AES, XOR, custom)
143
+ 2. Check for known weaknesses:
144
+ ├── RSA: small e, shared factor, Wiener, Hastad, Franklin-Reiter
145
+ ├── AES: ECB mode detection, padding oracle, IV reuse, bit-flipping
146
+ ├── XOR: known-plaintext, frequency analysis, key length detection
147
+ ├── Hash: length extension, collision, rainbow table
148
+ └── Custom: analyze algorithm logic for mathematical weakness
149
+ 3. Use tools: SageMath, RsaCtfTool, PyCryptodome, hashcat
150
+ 4. web_search("{specific_crypto} CTF attack")
151
+ ```
152
+
153
+ ### Forensics Challenges
154
+ ```
155
+ 1. file command → identify file type
156
+ 2. binwalk → check for embedded files
157
+ 3. exiftool → metadata analysis
158
+ 4. strings / hexdump → look for flags or clues
159
+ 5. By file type:
160
+ ├── PCAP: Wireshark, tshark filters, follow TCP stream, HTTP objects
161
+ ├── Memory dump: volatility3 (pslist, filescan, dumpfiles, hashdump)
162
+ ├── Disk image: mount, autopsy, sleuthkit
163
+ ├── Image: steghide, zsteg, stegsolve, LSB analysis
164
+ ├── PDF: pdftotext, embedded JS, streams
165
+ └── Archive: nested archives, password brute-force (fcrackzip, john)
166
+ ```
167
+
168
+ ### Reversing Challenges
169
+ ```
170
+ 1. file → identify architecture and format
171
+ 2. strings → quick flag check, interesting strings
172
+ 3. ltrace/strace → runtime behavior analysis
173
+ 4. Ghidra/r2/IDA → decompile main function
174
+ 5. Identify check logic → extract/bypass:
175
+ ├── Simple comparison → extract expected value
176
+ ├── Transformation → reverse the algorithm
177
+ ├── Anti-debug → patch or bypass (ptrace check, timing)
178
+ ├── Obfuscated → de-obfuscate layer by layer
179
+ └── Constraint solving → angr or z3 for automatic solving
180
+ 6. web_search("{binary_behavior} CTF reverse engineering")
181
+ ```
182
+
183
+ ### Misc Challenges
184
+ ```
185
+ ├── Scripting: pyjail escape, restricted shell bypass, calc jail
186
+ │ ├── Python: __builtins__, __import__, eval, exec bypass
187
+ │ ├── Bash: restricted shell escape (vi, awk, find -exec)
188
+ │ └── PHP: disable_functions bypass
189
+ ├── OSINT: use dorking, wayback machine, social media
190
+ ├── Encoding: multi-layer decode (base64→hex→rot13→morse)
191
+ ├── Programming: automation scripts for brute-force/calculation
192
+ └── Network: unusual protocols, custom services, raw socket interaction
193
+ ```
194
+
195
+ ## 🔥 CTF-Specific Aggression Rules
196
+
197
+ 1. **No scope restrictions in CTF** — everything provided is fair game
198
+ 2. **Don't be gentle** — aggressive scanning, brute force, destructive testing OK
199
+ 3. **Speed over stealth** — no IDS/IPS concern in CTF
200
+ 4. **Tool everything** — `nmap -T5`, `ffuf -mc all`, `sqlmap --batch --level=5 --risk=3`
201
+ 5. **Custom scripting** — if a tool doesn't exist, write it (Python/Bash)
202
+ 6. **Read ALL source code** — comments often contain hints
203
+ 7. **Check EVERYTHING twice** — with different tools/perspectives
204
+ 8. **Parallel execution** — background processes for slow tasks, foreground for interactive
205
+
206
+ ## 📊 Score Optimization
207
+
208
+ ```
209
+ Point maximization strategy:
210
+ ├── Easy challenges (100-200pt): Solve in 5-15 min → HIGH ROI
211
+ ├── Medium challenges (300-500pt): Solve in 30-60 min → MEDIUM ROI
212
+ ├── Hard challenges (500-1000pt): Solve in 60-120 min → LOW ROI (but prestige)
213
+ ├── First blood bonus: Prioritize NEW challenges released during competition
214
+ ├── Hint system: Use hints if available — partial points > no points
215
+ └── Partial flags: Some challenges accept partial progress — submit what you have
216
+ ```
18
217
 
19
218
  ## Everything Else
20
219
 
21
- Strategy, speed, aggression, proof collection, clue detection, time management
220
+ Strategy, speed, aggression, proof collection, clue detection —
22
221
  these are **always active** regardless of CTF mode. See `strategy.md`.
@@ -372,3 +372,54 @@ When JWT tokens are discovered:
372
372
  ├── Brute force secret: hashcat -m 16500 jwt.txt rockyou.txt
373
373
  └── web_search("JWT attack techniques {year}")
374
374
  ```
375
+
376
+ ## ⚙️ Context Digest — "Raw Output Is Data. Digested Output Is Intelligence."
377
+
378
+ ### Core Philosophy
379
+ ```
380
+ Long tool output is the #1 threat to agent effectiveness.
381
+ A 200KB nmap scan where 199KB is noise and 1KB is critical findings
382
+ will drown your context window and make you FORGET earlier discoveries.
383
+
384
+ THE SOLUTION: 3-Layer Context Digest
385
+ ─────────────────────────────────────
386
+ Layer 1 — Pattern Extraction (cost: 0ms)
387
+ Regex-based. Knows nmap, linpeas, enum4linux, gobuster, sqlmap, hashes.
388
+ Extracts open ports, CVEs, credentials, SUID binaries, discovered paths.
389
+
390
+ Layer 2 — Structural Reduction (cost: ~1ms)
391
+ Strips ANSI escapes, progress bars, duplicate lines.
392
+ 1000x "404 Not Found" → "[1000 similar lines collapsed]"
393
+ Signal lines (errors, credentials, CVEs, flags) are NEVER removed.
394
+
395
+ Layer 3 — Semantic Digest (cost: ~2-5s, separate LLM call)
396
+ Only fires for truly massive outputs (>50K after Layer 1+2).
397
+ Produces a focused 30-line intelligence summary.
398
+ Full output is ALWAYS saved to ~/.pentesting/outputs/ for reference.
399
+ ```
400
+
401
+ ### Agent Behavioral Rules for Output Handling
402
+ ```
403
+ 1. TRUST THE DIGEST — The intelligence summary at the top of tool output
404
+ contains the critical findings. Start your analysis there.
405
+
406
+ 2. READ THE FULL OUTPUT WHEN:
407
+ - The summary says "No actionable findings" but you expected results
408
+ - You need exact values (full hash, exact file content, raw headers)
409
+ - The summary mentions something you want to verify
410
+ → Use read_file on the saved output path shown at the bottom
411
+
412
+ 3. NEVER re-run a tool just because the output was compressed.
413
+ The full output is SAVED. Read the file instead.
414
+
415
+ 4. When output is truncated, the TAIL may be missing.
416
+ Check the saved file for anything that was cut off.
417
+
418
+ 5. Signal lines are ALWAYS preserved through compression:
419
+ - Error messages, warnings
420
+ - Credentials, hashes, tokens, keys
421
+ - CVE references
422
+ - Open ports, interesting paths
423
+ - CTF flags
424
+ ```
425
+
@@ -155,3 +155,142 @@ Side-channel (rare but appears at DEF CON):
155
155
  └── Cache timing: Flush+Reload on shared libraries
156
156
  ```
157
157
 
158
+ ## Hash Attacks (Beyond Cracking)
159
+
160
+ ```
161
+ Length Extension Attack:
162
+ ├── Vulnerable: MD5, SHA1, SHA256 (Merkle-Damgård construction)
163
+ ├── NOT vulnerable: SHA3, HMAC, truncated hashes
164
+ ├── Tool: hash_extender or HashPump
165
+ │ hash_extender --data "known" --secret-len 16 --append "admin=true" --signature <hash>
166
+ ├── When to use: MAC = H(secret || user_data) → append data without knowing secret
167
+ └── Result: valid MAC for extended message
168
+
169
+ Collision Attack:
170
+ ├── MD5: Generate two files with same MD5 hash
171
+ │ Tool: fastcoll or HashClash
172
+ │ Use: bypass file comparison, forge certificates
173
+ ├── SHA1: SHAttered (practical collision exists)
174
+ └── When: "if md5(file1) == md5(file2)" type checks
175
+
176
+ Rainbow Table:
177
+ ├── CrackStation: crackstation.net for quick lookups
178
+ ├── hashes.org: community hash lookup
179
+ ├── For custom charsets: rtgen from RainbowCrack project
180
+ └── Limited to unsalted hashes
181
+ ```
182
+
183
+ ## RSA — Extended Attack Catalog
184
+
185
+ ```
186
+ ═══════════════════════════════════════
187
+ Franklin-Reiter Related Message:
188
+ ═══════════════════════════════════════
189
+ ├── Two messages with known relationship: m2 = a*m1 + b
190
+ ├── Same RSA key → gcd of polynomials → recover both messages
191
+ ├── Common: m2 = m1 + padding_difference
192
+ └── SageMath: gcd of (x^e - c1) and ((a*x+b)^e - c2) in Z_n[x]
193
+
194
+ ═══════════════════════════════════════
195
+ Boneh-Durfee:
196
+ ═══════════════════════════════════════
197
+ ├── Small private exponent (d < n^0.292)
198
+ ├── Stronger than Wiener's (which requires d < n^0.25)
199
+ ├── Lattice-based: construct lattice → LLL → factor n
200
+ └── Tool: web_search("boneh durfee RSA CTF implementation")
201
+
202
+ ═══════════════════════════════════════
203
+ Multi-prime RSA:
204
+ ═══════════════════════════════════════
205
+ ├── n = p * q * r (or more primes)
206
+ ├── phi = (p-1)(q-1)(r-1)
207
+ ├── Each extra prime → easier to factor
208
+ ├── factordb.com often factors multi-prime n
209
+ └── Lambda function: lcm(p-1, q-1, r-1) — may be needed for d
210
+
211
+ ═══════════════════════════════════════
212
+ Chinese Remainder Theorem (CRT):
213
+ ═══════════════════════════════════════
214
+ ├── When: m^e < n (small message, large modulus)
215
+ │ Direct e-th root: m = iroot(c, e) (integer root)
216
+ ├── Hastad improved with CRT:
217
+ │ Multiple (n_i, c_i) with same e → CRT → then e-th root
218
+ ├── When: same message encrypted with different moduli
219
+ └── SageMath: CRT_list(remainders, moduli)
220
+
221
+ ═══════════════════════════════════════
222
+ RSA with known bits:
223
+ ═══════════════════════════════════════
224
+ ├── Partial p/q known → Coppersmith small_roots
225
+ ├── Partial d known → Coppersmith on d
226
+ ├── Example: "p starts with AAAA..." → known MSB → Coppersmith
227
+ └── SageMath: f.small_roots(X=2^unknown_bits, beta=0.5)
228
+ ```
229
+
230
+ ## Automated Crypto Solving Strategy
231
+
232
+ ```
233
+ CTF crypto decision tree:
234
+ 1. Check: is it a KNOWN cipher? (RSA, AES, XOR, custom)
235
+ 2. Extract all parameters from challenge
236
+ 3. For RSA:
237
+ ├── Try RsaCtfTool first (covers 40+ attacks automatically!)
238
+ │ python3 RsaCtfTool.py -n <n> -e <e> --uncipher <c> --attack all
239
+ ├── Try factordb.com for n
240
+ ├── Check e: small e → Hastad/cube root, large e → Wiener/Boneh-Durfee
241
+ ├── Multiple ciphertexts? → CRT / Franklin-Reiter
242
+ └── Weird parameters? → web_search("RSA CTF <description>")
243
+ 4. For AES:
244
+ ├── ECB? → byte-at-a-time or ECB penguin
245
+ ├── CBC? → padding oracle or bit-flip
246
+ ├── CTR? → nonce reuse → XOR
247
+ └── Custom mode? → analyze and find weakness
248
+ 5. For custom cipher:
249
+ ├── Read the code CAREFULLY
250
+ ├── Look for: weak randomness, reused key, algebraic weakness
251
+ ├── Z3 solver for constraint problems
252
+ └── Brute-force if keyspace < 2^32
253
+ 6. For encoding puzzles:
254
+ ├── CyberChef Magic (auto-detect)
255
+ ├── Multi-layer decode: base64 → hex → XOR → rot13
256
+ └── dcode.fr for classical ciphers
257
+
258
+ Essential tools:
259
+ ├── RsaCtfTool: github.com/RsaCtfTool/RsaCtfTool
260
+ ├── SageMath: for all mathematical crypto
261
+ ├── CyberChef: gchq.github.io/CyberChef
262
+ ├── PyCryptodome: python crypto library
263
+ ├── z3-solver: constraint solving
264
+ ├── factordb.com: integer factorization
265
+ └── dcode.fr: classical cipher solver
266
+ ```
267
+
268
+ ## SageMath Essential Patterns
269
+
270
+ ```python
271
+ # RSA decryption
272
+ n, e, c = ...
273
+ p, q = factor(n) # or from factordb
274
+ phi = (p-1)*(q-1)
275
+ d = inverse_mod(e, phi)
276
+ m = pow(c, d, n)
277
+ bytes.fromhex(hex(m)[2:])
278
+
279
+ # Coppersmith (small roots)
280
+ P.<x> = PolynomialRing(Zmod(n))
281
+ f = x + known_prefix
282
+ roots = f.small_roots(X=2^64, beta=0.5)
283
+
284
+ # Lattice reduction (LLL)
285
+ M = matrix(ZZ, [...])
286
+ M_reduced = M.LLL()
287
+
288
+ # ECC discrete log
289
+ E = EllipticCurve(GF(p), [a, b])
290
+ G = E(Gx, Gy)
291
+ P = E(Px, Py)
292
+ d = discrete_log(P, G, G.order(), operation='+')
293
+
294
+ # CRT
295
+ x = crt([r1, r2, r3], [m1, m2, m3])
296
+ ```