openhack 0.1.0__py3-none-any.whl

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.
Files changed (113) hide show
  1. openhack/__init__.py +2 -0
  2. openhack/__main__.py +225 -0
  3. openhack/agents/__init__.py +30 -0
  4. openhack/agents/base.py +230 -0
  5. openhack/agents/browser_verifier.py +679 -0
  6. openhack/agents/browser_verifier_swarm.py +256 -0
  7. openhack/agents/checkpoint.py +89 -0
  8. openhack/agents/context_manager.py +356 -0
  9. openhack/agents/coordinator.py +1105 -0
  10. openhack/agents/endpoint_analyst.py +307 -0
  11. openhack/agents/feature_hunter.py +93 -0
  12. openhack/agents/hunter.py +481 -0
  13. openhack/agents/hunter_swarm.py +385 -0
  14. openhack/agents/llm.py +334 -0
  15. openhack/agents/recon.py +19 -0
  16. openhack/agents/sandbox_verifier.py +396 -0
  17. openhack/agents/sandbox_verifier_swarm.py +250 -0
  18. openhack/agents/session.py +286 -0
  19. openhack/agents/validator.py +217 -0
  20. openhack/agents/validator_swarm.py +106 -0
  21. openhack/auth.py +175 -0
  22. openhack/browser/__init__.py +12 -0
  23. openhack/browser/runner.py +385 -0
  24. openhack/categories.py +130 -0
  25. openhack/config.py +201 -0
  26. openhack/deterministic_recon.py +464 -0
  27. openhack/entry_points.py +745 -0
  28. openhack/framework_classifier.py +515 -0
  29. openhack/framework_detection.py +269 -0
  30. openhack/headless_scan.py +179 -0
  31. openhack/prompts/__init__.py +108 -0
  32. openhack/prompts/browser_verifier.py +171 -0
  33. openhack/prompts/coordinator.py +31 -0
  34. openhack/prompts/django/__init__.py +32 -0
  35. openhack/prompts/django/auth_bypass.py +76 -0
  36. openhack/prompts/django/csrf.py +62 -0
  37. openhack/prompts/django/data_exposure.py +67 -0
  38. openhack/prompts/django/idor.py +74 -0
  39. openhack/prompts/django/injection.py +67 -0
  40. openhack/prompts/django/misconfiguration.py +70 -0
  41. openhack/prompts/django/ssrf.py +64 -0
  42. openhack/prompts/endpoint_analyst.py +122 -0
  43. openhack/prompts/express/__init__.py +29 -0
  44. openhack/prompts/express/auth_bypass.py +71 -0
  45. openhack/prompts/express/data_exposure.py +77 -0
  46. openhack/prompts/express/idor.py +69 -0
  47. openhack/prompts/express/injection.py +75 -0
  48. openhack/prompts/express/misconfiguration.py +72 -0
  49. openhack/prompts/express/ssrf.py +63 -0
  50. openhack/prompts/feature_hunter.py +140 -0
  51. openhack/prompts/flask/__init__.py +29 -0
  52. openhack/prompts/flask/auth_bypass.py +86 -0
  53. openhack/prompts/flask/data_exposure.py +78 -0
  54. openhack/prompts/flask/idor.py +83 -0
  55. openhack/prompts/flask/injection.py +77 -0
  56. openhack/prompts/flask/misconfiguration.py +73 -0
  57. openhack/prompts/flask/ssrf.py +65 -0
  58. openhack/prompts/hunter.py +362 -0
  59. openhack/prompts/hunter_continuation_loop.py +12 -0
  60. openhack/prompts/hunter_continuation_no_findings.py +19 -0
  61. openhack/prompts/hunter_continuation_no_progress.py +22 -0
  62. openhack/prompts/hunter_tool_instructions.py +55 -0
  63. openhack/prompts/nextjs/__init__.py +42 -0
  64. openhack/prompts/nextjs/auth_bypass.py +80 -0
  65. openhack/prompts/nextjs/csrf.py +71 -0
  66. openhack/prompts/nextjs/data_exposure.py +88 -0
  67. openhack/prompts/nextjs/idor.py +64 -0
  68. openhack/prompts/nextjs/injection.py +65 -0
  69. openhack/prompts/nextjs/middleware_bypass.py +75 -0
  70. openhack/prompts/nextjs/misconfiguration.py +92 -0
  71. openhack/prompts/nextjs/server_actions.py +97 -0
  72. openhack/prompts/nextjs/ssrf.py +66 -0
  73. openhack/prompts/nextjs/xss.py +69 -0
  74. openhack/prompts/pr_analysis_system.py +80 -0
  75. openhack/prompts/pr_analysis_user.py +11 -0
  76. openhack/prompts/project_context.py +89 -0
  77. openhack/prompts/recon.py +199 -0
  78. openhack/prompts/reporter.py +88 -0
  79. openhack/prompts/researchers.py +434 -0
  80. openhack/prompts/sandbox_verifier.py +128 -0
  81. openhack/prompts/supabase/__init__.py +39 -0
  82. openhack/prompts/supabase/auth_tokens.py +131 -0
  83. openhack/prompts/supabase/edge_functions.py +150 -0
  84. openhack/prompts/supabase/graphql.py +102 -0
  85. openhack/prompts/supabase/postgrest.py +99 -0
  86. openhack/prompts/supabase/realtime.py +93 -0
  87. openhack/prompts/supabase/rls.py +110 -0
  88. openhack/prompts/supabase/rpc_functions.py +127 -0
  89. openhack/prompts/supabase/storage.py +110 -0
  90. openhack/prompts/supabase/tenant_isolation.py +118 -0
  91. openhack/prompts/validator.py +319 -0
  92. openhack/prompts/validator_continuation_incomplete.py +12 -0
  93. openhack/prompts/validator_tool_instructions.py +29 -0
  94. openhack/quality.py +231 -0
  95. openhack/sandbox/__init__.py +12 -0
  96. openhack/sandbox/orchestrator.py +517 -0
  97. openhack/sandbox/runner.py +177 -0
  98. openhack/scan_session.py +245 -0
  99. openhack/setup.py +452 -0
  100. openhack/static_validator.py +612 -0
  101. openhack/tools/__init__.py +1 -0
  102. openhack/tools/ast_tools.py +307 -0
  103. openhack/tools/coverage.py +1078 -0
  104. openhack/tools/filesystem.py +404 -0
  105. openhack/tools/nextjs.py +258 -0
  106. openhack/tools/registry.py +52 -0
  107. openhack/tui.py +3450 -0
  108. openhack/updates.py +170 -0
  109. openhack-0.1.0.dist-info/METADATA +189 -0
  110. openhack-0.1.0.dist-info/RECORD +113 -0
  111. openhack-0.1.0.dist-info/WHEEL +4 -0
  112. openhack-0.1.0.dist-info/entry_points.txt +2 -0
  113. openhack-0.1.0.dist-info/licenses/LICENSE +661 -0
@@ -0,0 +1,434 @@
1
+ """
2
+ Hardcoded researcher task prompts.
3
+
4
+ Each researcher encodes a proven security analysis pattern that works across
5
+ any codebase. These are the "how to look" instructions, not "what to find."
6
+ """
7
+
8
+ OUTBOUND_REQUESTS_RESEARCHER = (
9
+ "You are a security researcher. Focus on OUTBOUND REQUESTS and NETWORK FEATURES.\n\n"
10
+ "Start by reading the route definitions and auth config to understand the app.\n\n"
11
+ "Then do this analysis:\n"
12
+ "1. Find EVERY place the server makes outbound HTTP requests on behalf of users: "
13
+ "webhooks, notifications, URL fetching, favicon downloads, RSS imports, link previews, "
14
+ "URL scraping, image proxying, OAuth callbacks, payment callbacks.\n"
15
+ "2. For EACH one, check: is the URL validated? Is there an IP blocklist for internal addresses? "
16
+ "Can the user specify arbitrary protocols/schemas?\n"
17
+ "3. Compare URL validation across ALL outbound request features. If one validates with isUrl "
18
+ "but another accepts raw strings — that's an SSRF inconsistency.\n"
19
+ "4. If there's a blocklist/allowlist, check completeness. What schemas/IPs are NOT blocked?\n"
20
+ "5. Check if any outbound request feature reads the response and returns it to the user "
21
+ "(full SSRF vs blind SSRF).\n\n"
22
+ "DO NOT spend time on file uploads or auth — other researchers cover those."
23
+ )
24
+
25
+ FILE_HANDLING_RESEARCHER = (
26
+ "You are a security researcher. Focus on FILE HANDLING and CONTENT SERVING.\n\n"
27
+ "Start by reading the route definitions and auth config to understand the app.\n\n"
28
+ "CRITICAL ANALYSIS — you MUST do ALL of these:\n"
29
+ "1. Find the file UPLOAD handler. Read it completely. Note what properties it sets on the "
30
+ "stored file record (mimeType, image, encoding, size, etc.)\n"
31
+ "2. Find the file DOWNLOAD/SERVE handler. Read it completely. Note how it decides "
32
+ "Content-Type and Content-Disposition headers. Does it use any properties from step 1?\n"
33
+ "3. Compare: if a user uploads an SVG file (mimeType: image/svg+xml), what properties get "
34
+ "set during upload? When that SVG is downloaded, does it get Content-Disposition: attachment "
35
+ "(forced download, safe) or is it served inline (XSS via embedded JavaScript)?\n"
36
+ "4. Check the same for HTML, XML, and other dangerous content types.\n"
37
+ "5. Check if filenames are sanitized. Can path traversal characters (../) appear in "
38
+ "stored filenames?\n"
39
+ "6. Check if there are Content-Security-Policy or X-Content-Type-Options headers on "
40
+ "file serving responses.\n\n"
41
+ "The KEY PATTERN: a property set during UPLOAD that changes behavior during DOWNLOAD. "
42
+ "For example, if the upload handler marks SVGs as 'image: true' and the download handler "
43
+ "skips Content-Disposition: attachment for images, then SVGs with JavaScript will execute "
44
+ "in the browser — that's stored XSS.\n\n"
45
+ "DO NOT spend time on webhooks or notification services — another researcher covers that."
46
+ )
47
+
48
+ AUTH_RESEARCHER = (
49
+ "You are a security researcher. Focus on AUTHENTICATION and AUTHORIZATION.\n\n"
50
+ "Start by reading the route definitions, auth middleware, and policy config.\n\n"
51
+ "Then do this analysis:\n"
52
+ "1. Map every endpoint and its required auth level (public, authenticated, admin).\n"
53
+ "2. Find endpoints that SKIP auth — check for patterns like AUTHENTICATE=false, "
54
+ "csrf_exempt, skip_before_action, publicProcedure, or routes missing auth middleware.\n"
55
+ "3. Check authorization consistency: when an endpoint loads an object by ID, does it "
56
+ "verify the current user owns/has access to that object? Compare across all CRUD endpoints.\n"
57
+ "4. Check for privilege escalation: can a regular user set admin flags via mass assignment? "
58
+ "Can a non-admin access admin-only endpoints by guessing the URL?\n"
59
+ "5. Check password reset and token flows: are tokens predictable? Can they be reused? "
60
+ "Is there a timing side-channel in token comparison?\n"
61
+ "6. Check for missing await/async bugs in auth checks — if an auth middleware uses async "
62
+ "but the caller doesn't await it, the check returns a Promise (truthy) instead of the "
63
+ "actual result, so auth always passes.\n\n"
64
+ "DO NOT spend time on file uploads or webhooks — other researchers cover those."
65
+ )
66
+
67
+ INPUT_RENDERING_RESEARCHER = (
68
+ "You are a security researcher. Focus on USER INPUT RENDERING and TEMPLATE INJECTION.\n\n"
69
+ "Start by reading the route definitions to find where user content is displayed.\n\n"
70
+ "Then do this analysis:\n"
71
+ "1. Find every place user-provided content is rendered as HTML: markdown rendering, "
72
+ "template engines, rich text editors, comment systems, description fields.\n"
73
+ "2. For each one, check the sanitization pipeline: what library is used? What's the "
74
+ "sanitizer configuration? Are there custom renderer rules that bypass default escaping?\n"
75
+ "3. Check for dangerouslySetInnerHTML, v-html, innerHTML, or equivalent patterns. "
76
+ "Trace what content reaches them — is it sanitized first?\n"
77
+ "4. Check if user content can include links/URLs — are they validated to prevent "
78
+ "javascript: protocol XSS?\n"
79
+ "5. Look for server-side template injection: is user input ever passed to template "
80
+ "engines (Jinja2, EJS, Pug, Handlebars) without escaping?\n\n"
81
+ "DO NOT spend time on file uploads or webhooks — other researchers cover those."
82
+ )
83
+
84
+ MEMORY_SAFETY_RESEARCHER = (
85
+ "You are a security researcher. Focus on MEMORY SAFETY vulnerabilities in C/C++ code.\n\n"
86
+ "Start by reading the main source directories to understand the codebase structure.\n\n"
87
+ "CRITICAL ANALYSIS — check ALL of these:\n"
88
+ "1. **Buffer overflows**: Find every call to memcpy, memmove, strcpy, strncpy, strcat, strncat, "
89
+ "sprintf, snprintf, gets, fgets, read, recv. For EACH one, check: is the destination buffer "
90
+ "large enough? Is the size parameter validated against the buffer size? Can user input control "
91
+ "the size or content?\n"
92
+ "2. **Heap overflows**: Find malloc/calloc/realloc calls. Check if the size calculation can "
93
+ "integer-overflow (e.g., `malloc(n * sizeof(x))` where n is user-controlled). Check if the "
94
+ "allocated buffer is used with a larger size later.\n"
95
+ "3. **Stack buffer overflows**: Find fixed-size local arrays (char buf[256]). Check if data is "
96
+ "written to them without bounds checking.\n"
97
+ "4. **Off-by-one errors**: Check loop boundaries, string null terminator handling, fence-post "
98
+ "errors in buffer size calculations.\n"
99
+ "5. **Format string vulnerabilities**: Find printf, fprintf, sprintf, syslog, snprintf calls "
100
+ "where the format string comes from user input (not a literal).\n\n"
101
+ "For each finding: show the exact code, the buffer sizes involved, and how an attacker controls "
102
+ "the input. A buffer overflow is only real if attacker-controlled data reaches the vulnerable "
103
+ "function.\n\n"
104
+ "CRITICAL: Before reporting, check the file path. Only report vulnerabilities in production "
105
+ "code — the library/server core. DO NOT report issues in test files, demo servers, example "
106
+ "code, CLI tools, debug utilities, or benchmark code. A buffer overflow in a demo program "
107
+ "is NOT a CVE. A buffer overflow in the TLS parser IS."
108
+ )
109
+
110
+ USE_AFTER_FREE_RESEARCHER = (
111
+ "You are a security researcher. Focus on USE-AFTER-FREE and DOUBLE-FREE vulnerabilities in C/C++ code.\n\n"
112
+ "Start by reading the main source directories to understand memory management patterns.\n\n"
113
+ "CRITICAL ANALYSIS:\n"
114
+ "1. **Use-after-free**: Find every free() call. Trace the pointer after free — is it used again "
115
+ "before being reassigned? Check error handling paths where cleanup frees memory but the caller "
116
+ "continues to use the pointer. Check callback functions that may fire after the owning object "
117
+ "is freed.\n"
118
+ "2. **Double-free**: Find code paths where the same pointer can be freed twice — especially in "
119
+ "error handling where both the error path and the normal cleanup path free the same memory.\n"
120
+ "3. **Reference counting bugs**: If the codebase uses reference counting (ref/unref patterns), "
121
+ "check for missing increments or extra decrements that lead to premature free.\n"
122
+ "4. **Dangling pointers in data structures**: When an item is removed from a linked list, hash "
123
+ "table, or tree, check if other references to it are cleaned up.\n"
124
+ "5. **Lifetime mismatches**: Check if stack-allocated data is stored in a structure that outlives "
125
+ "the stack frame. Check if data from a temporary buffer is referenced after the buffer is reused.\n\n"
126
+ "Focus on code paths reachable from network input — parsing functions, protocol handlers, "
127
+ "connection management. Internal-only code paths are lower priority.\n\n"
128
+ "CRITICAL: Before reporting, check the file path. Only report vulnerabilities in code that "
129
+ "ships in production — the library/server itself. DO NOT report issues in test files, demo "
130
+ "servers, example code, CLI tools, debug utilities, or benchmark code. Use your judgment: "
131
+ "does this code run in a real deployment?"
132
+ )
133
+
134
+ INTEGER_OVERFLOW_RESEARCHER = (
135
+ "You are a security researcher. Focus on INTEGER OVERFLOW and TYPE CONFUSION in C/C++ code.\n\n"
136
+ "CRITICAL ANALYSIS:\n"
137
+ "1. **Integer overflow in size calculations**: Find arithmetic used to compute buffer sizes, "
138
+ "especially multiplication (`n * m`), addition (`a + b`), and left shifts (`x << n`). Check if "
139
+ "the result can wrap around to a small value, leading to undersized allocation followed by "
140
+ "buffer overflow.\n"
141
+ "2. **Signed/unsigned confusion**: Find places where signed integers are used as sizes or "
142
+ "indices. A negative signed value cast to unsigned becomes a very large number. Check casts "
143
+ "between int/size_t/ssize_t/uint32_t.\n"
144
+ "3. **Truncation**: Check if a 64-bit size is truncated to 32-bit (e.g., assigning size_t to "
145
+ "int or uint32_t). On 64-bit systems, a large allocation size truncated to 32 bits becomes "
146
+ "small.\n"
147
+ "4. **Length validation bypass**: Find length checks like `if (len > MAX)` where len is signed — "
148
+ "a negative len passes the check but wraps to large when used as unsigned.\n"
149
+ "5. **Arithmetic in protocol parsing**: Network protocols often have length fields. Check if "
150
+ "the length field from a packet is used in arithmetic without overflow checking before "
151
+ "allocation or memcpy.\n\n"
152
+ "Focus on network-facing code: TLS parsing, protocol handlers, certificate processing, "
153
+ "HTTP parsing, data serialization/deserialization.\n\n"
154
+ "CRITICAL: Before reporting, check the file path. Only report vulnerabilities in production "
155
+ "code — the library/server core. DO NOT report issues in test files, demo code, examples, "
156
+ "CLI tools, debug utilities, or platform-specific code that's compiled out. Use your judgment."
157
+ )
158
+
159
+ CRYPTO_RESEARCHER = (
160
+ "You are a security researcher. Focus on CRYPTOGRAPHIC vulnerabilities.\n\n"
161
+ "CRITICAL ANALYSIS:\n"
162
+ "1. **Weak random number generation**: Find uses of rand(), srand(), random() for security "
163
+ "purposes (key generation, nonce creation, token generation). These are NOT cryptographically "
164
+ "secure. Check if RAND_bytes(), /dev/urandom, or getrandom() is used instead.\n"
165
+ "2. **Hardcoded keys/IVs**: Find hardcoded encryption keys, initialization vectors, or salts "
166
+ "in the source code.\n"
167
+ "3. **Timing side-channels**: Find memcmp() or strcmp() used to compare secrets (MACs, tokens, "
168
+ "passwords). These are vulnerable to timing attacks. Should use constant-time comparison "
169
+ "(CRYPTO_memcmp, timingsafe_bcmp, etc).\n"
170
+ "4. **Deprecated algorithms**: Find uses of MD5, SHA1, DES, RC4, or other broken algorithms "
171
+ "for security purposes (not for checksums/hashing where collision resistance doesn't matter).\n"
172
+ "5. **Certificate validation**: Check if X.509 certificate validation can be bypassed — "
173
+ "hostname verification, chain validation, expiry checking, revocation checking.\n"
174
+ "6. **Nonce reuse**: Check if encryption nonces/IVs are generated fresh for each operation "
175
+ "or if they can be reused (especially for AES-GCM where nonce reuse is catastrophic).\n\n"
176
+ "Focus on code that handles TLS, certificates, key exchange, password hashing, token generation, "
177
+ "and encrypted storage.\n\n"
178
+ "DO NOT report deprecated algorithms used only in backward-compatibility code paths that are "
179
+ "disabled by default.\n\n"
180
+ "CRITICAL: Before reporting, check the file path. Only report vulnerabilities in production "
181
+ "code. DO NOT report issues in test files, demo code, examples, CLI tools, or debug utilities."
182
+ )
183
+
184
+ # ============================================================
185
+ # Framework-specific researchers
186
+ # ============================================================
187
+
188
+ GRAPHQL_RESEARCHER = (
189
+ "You are a security researcher. Focus on GRAPHQL API SECURITY.\n\n"
190
+ "CRITICAL ANALYSIS:\n"
191
+ "1. **Introspection**: Is introspection enabled on the public endpoint? Query `{ __schema { queryType { fields { name } } } }`. "
192
+ "If it works without auth, the entire API schema is exposed.\n"
193
+ "2. **Authorization on resolvers**: For each query and mutation, check if it requires authentication. "
194
+ "Compare the public schema (*.graphql) vs admin schema (*.admin.graphql or similar). "
195
+ "Are there queries that should be admin-only but are in the public schema?\n"
196
+ "3. **IDOR via GraphQL**: Can a user query another user's data by providing their ID? "
197
+ "Check if resolvers filter by the current user or accept arbitrary IDs.\n"
198
+ "4. **Nested query depth**: Is there a query depth limit? Deep nested queries can DoS the server. "
199
+ "Try: `{ users { posts { comments { author { posts { comments { author { id } } } } } } } }`\n"
200
+ "5. **Mutations without auth**: Check all mutations — can unauthenticated users create, update, or delete resources?\n"
201
+ "6. **Batching attacks**: Can the attacker send multiple queries in one request to bypass rate limiting?\n\n"
202
+ "DO NOT spend time on REST endpoints — other researchers cover those.\n\n"
203
+ "CRITICAL: Before reporting, check the file path. Only report vulnerabilities in production code."
204
+ )
205
+
206
+ OAUTH_OIDC_RESEARCHER = (
207
+ "You are a security researcher. Focus on OAUTH2 and OIDC SECURITY.\n\n"
208
+ "CRITICAL ANALYSIS:\n"
209
+ "1. **State parameter validation**: Is the OAuth state parameter cryptographically signed/bound to the session? "
210
+ "Or is it plain JSON/base64 that can be forged? Check `parseState()` or equivalent.\n"
211
+ "2. **ID token signature verification**: When receiving id_tokens (especially from Apple, Google, Azure), "
212
+ "does the app verify the JWT signature? Or does it just base64-decode the payload? "
213
+ "Look for `jwt.decode()` without `verify=True`, or manual `explode('.')` / `split('.')` on the JWT.\n"
214
+ "3. **PKCE support**: Does the OAuth2 implementation use PKCE (Proof Key for Code Exchange)? "
215
+ "Without PKCE, authorization code interception is possible on mobile/SPA flows.\n"
216
+ "4. **Redirect URI validation**: Is the redirect_uri validated against a whitelist? "
217
+ "Can an attacker register `https://evil.com` as a redirect and steal auth codes?\n"
218
+ "5. **email_verified check**: After OAuth login, does the app check if the email is verified? "
219
+ "Unverified emails can be used for account linking attacks.\n"
220
+ "6. **Token storage**: Are OAuth tokens stored securely? Check for tokens in localStorage, "
221
+ "URL parameters, or unencrypted cookies.\n\n"
222
+ "DO NOT spend time on file uploads or webhooks — other researchers cover those.\n\n"
223
+ "CRITICAL: Before reporting, check the file path. Only report vulnerabilities in production code."
224
+ )
225
+
226
+ WEBSOCKET_RESEARCHER = (
227
+ "You are a security researcher. Focus on WEBSOCKET and REAL-TIME SECURITY.\n\n"
228
+ "CRITICAL ANALYSIS:\n"
229
+ "1. **Authentication on WebSocket upgrade**: Is the WebSocket handshake authenticated? "
230
+ "Check if the upgrade request validates JWT/session before accepting the connection.\n"
231
+ "2. **Authorization on messages**: After connection, are individual message types authorized? "
232
+ "Can a regular user send admin-only message types?\n"
233
+ "3. **Cross-origin WebSocket hijacking**: Is the Origin header validated on upgrade? "
234
+ "Without origin checking, a malicious website can establish WebSocket connections using the victim's session.\n"
235
+ "4. **Message injection**: Can a user inject messages that appear to come from other users "
236
+ "or the system? Check if sender identity is validated server-side.\n"
237
+ "5. **Room/channel authorization**: In chat-style apps, can a user join rooms/channels they don't have access to?\n"
238
+ "6. **Rate limiting**: Is there rate limiting on WebSocket messages? Unbounded message sending can DoS.\n\n"
239
+ "DO NOT spend time on REST endpoints or file uploads — other researchers cover those.\n\n"
240
+ "CRITICAL: Before reporting, check the file path. Only report vulnerabilities in production code."
241
+ )
242
+
243
+ GRPC_RESEARCHER = (
244
+ "You are a security researcher. Focus on gRPC and PROTOBUF API SECURITY.\n\n"
245
+ "CRITICAL ANALYSIS:\n"
246
+ "1. **Authentication interceptors**: Are gRPC services protected by auth interceptors? "
247
+ "Check if any service methods skip the auth middleware.\n"
248
+ "2. **Reflection API**: Is gRPC server reflection enabled? Like GraphQL introspection, "
249
+ "it reveals all available services and methods.\n"
250
+ "3. **Input validation**: Are protobuf message fields validated beyond type checking? "
251
+ "A field defined as `string` accepts arbitrary length. Check for size limits.\n"
252
+ "4. **Authorization per method**: Are different RPC methods protected with different permission levels? "
253
+ "Or does one auth check cover all methods?\n"
254
+ "5. **Streaming abuse**: For server-streaming or bidirectional RPCs, can a client open unlimited streams?\n\n"
255
+ "CRITICAL: Before reporting, check the file path. Only report vulnerabilities in production code."
256
+ )
257
+
258
+ # ============================================================
259
+ # Language-specific researchers
260
+ # ============================================================
261
+
262
+ JAVA_RESEARCHER = (
263
+ "You are a security researcher. Focus on JAVA/SPRING SECURITY vulnerabilities.\n\n"
264
+ "CRITICAL ANALYSIS:\n"
265
+ "1. **Deserialization**: Find uses of `ObjectInputStream.readObject()`, `XMLDecoder`, "
266
+ "`XStream.fromXML()`, `SnakeYAML.load()`, or `Jackson` with `enableDefaultTyping()`. "
267
+ "Any deserialization of untrusted input is potential RCE.\n"
268
+ "2. **Spring Expression Language (SpEL) injection**: Find `@Value('#{...}')`, "
269
+ "`ExpressionParser.parseExpression()`, or `StandardEvaluationContext` with user input. SpEL injection is RCE.\n"
270
+ "3. **SQL injection via JPA/Hibernate**: Find `@Query` with string concatenation instead of `:param` placeholders, "
271
+ "`createNativeQuery()` with concatenation, or `Criteria` API with unsanitized input.\n"
272
+ "4. **Spring Security misconfig**: Check `SecurityFilterChain` — are endpoints excluded with `permitAll()` "
273
+ "that should require auth? Is CSRF disabled globally with `csrf().disable()`? "
274
+ "Is method security (`@PreAuthorize`) applied consistently?\n"
275
+ "5. **JNDI injection**: Find `InitialContext.lookup()`, `JndiTemplate.lookup()`, or any JNDI lookup "
276
+ "with user-controlled input. This is the Log4Shell pattern.\n"
277
+ "6. **Path traversal**: Find `new File(userInput)`, `Paths.get(userInput)`, or `ResourceUtils.getFile()` "
278
+ "where the path isn't validated against a base directory.\n"
279
+ "7. **Mass assignment**: Find `@ModelAttribute` or `BeanUtils.copyProperties()` where user input "
280
+ "maps directly to entity fields including sensitive ones (role, admin, password).\n\n"
281
+ "CRITICAL: Before reporting, check the file path. Only report vulnerabilities in production code. "
282
+ "DO NOT report issues in test files, demo code, or examples."
283
+ )
284
+
285
+ DOTNET_RESEARCHER = (
286
+ "You are a security researcher. Focus on C#/.NET SECURITY vulnerabilities.\n\n"
287
+ "CRITICAL ANALYSIS:\n"
288
+ "1. **Deserialization**: Find `BinaryFormatter.Deserialize()`, `JsonConvert.DeserializeObject()` with "
289
+ "`TypeNameHandling.Auto/All`, `XmlSerializer` with untrusted types, or `DataContractSerializer` "
290
+ "with user-controlled type info. All are potential RCE.\n"
291
+ "2. **SQL injection**: Find `SqlCommand` with string concatenation, `FromSqlRaw()` with interpolation, "
292
+ "or `ExecuteSqlRaw()` without parameterization.\n"
293
+ "3. **SSRF**: Find `HttpClient.GetAsync()`, `WebClient.DownloadString()`, or `HttpWebRequest.Create()` "
294
+ "with user-controlled URLs.\n"
295
+ "4. **Auth bypass**: Check `[AllowAnonymous]` attributes on controllers/actions that should require auth. "
296
+ "Check if `[Authorize]` is applied at the controller level and not accidentally overridden.\n"
297
+ "5. **Path traversal**: Find `Path.Combine()` with user input — .NET's Path.Combine behaves like "
298
+ "Python's joinpath and replaces the base with absolute paths.\n"
299
+ "6. **CSRF**: Is `[ValidateAntiForgeryToken]` applied to all POST/PUT/DELETE actions?\n\n"
300
+ "CRITICAL: Before reporting, check the file path. Only report vulnerabilities in production code."
301
+ )
302
+
303
+ RUST_RESEARCHER = (
304
+ "You are a security researcher. Focus on RUST SECURITY vulnerabilities.\n\n"
305
+ "Rust prevents memory safety bugs at compile time, so focus on logic bugs instead:\n\n"
306
+ "1. **Unsafe blocks**: Find every `unsafe { }` block. These opt out of Rust's safety guarantees. "
307
+ "Check for buffer overflows, use-after-free, and data races inside unsafe blocks.\n"
308
+ "2. **SQL injection**: Even in Rust, raw SQL queries with format! or string concatenation are injectable. "
309
+ "Find `sqlx::query()` with `format!()` instead of `sqlx::query!()` macro.\n"
310
+ "3. **Command injection**: Find `std::process::Command::new()` with user input in arguments. "
311
+ "Check if arguments are properly separated or concatenated into a shell string.\n"
312
+ "4. **SSRF**: Find `reqwest::get()`, `hyper::Client::get()`, or `ureq::get()` with user-controlled URLs.\n"
313
+ "5. **Auth/authz logic**: Missing permission checks, IDOR, and auth bypass are language-agnostic.\n"
314
+ "6. **Panic-based DoS**: Find `.unwrap()` on network input that could cause the server to crash.\n\n"
315
+ "CRITICAL: Before reporting, check the file path. Only report vulnerabilities in production code."
316
+ )
317
+
318
+ # ============================================================
319
+ # All researcher registries
320
+ # ============================================================
321
+
322
+ # Web application researchers (universal)
323
+ HARDCODED_RESEARCHERS: dict[str, str] = {
324
+ "outbound_requests": OUTBOUND_REQUESTS_RESEARCHER,
325
+ "file_handling": FILE_HANDLING_RESEARCHER,
326
+ "auth": AUTH_RESEARCHER,
327
+ "input_rendering": INPUT_RENDERING_RESEARCHER,
328
+ "graphql": GRAPHQL_RESEARCHER,
329
+ "oauth_oidc": OAUTH_OIDC_RESEARCHER,
330
+ }
331
+
332
+ # C/C++ researchers
333
+ C_RESEARCHERS: dict[str, str] = {
334
+ "memory_safety": MEMORY_SAFETY_RESEARCHER,
335
+ "use_after_free": USE_AFTER_FREE_RESEARCHER,
336
+ "integer_overflow": INTEGER_OVERFLOW_RESEARCHER,
337
+ "crypto": CRYPTO_RESEARCHER,
338
+ }
339
+
340
+ # Java/Spring researchers
341
+ JAVA_RESEARCHERS: dict[str, str] = {
342
+ "java": JAVA_RESEARCHER,
343
+ "auth": AUTH_RESEARCHER,
344
+ "outbound_requests": OUTBOUND_REQUESTS_RESEARCHER,
345
+ "file_handling": FILE_HANDLING_RESEARCHER,
346
+ "oauth_oidc": OAUTH_OIDC_RESEARCHER,
347
+ }
348
+
349
+ # .NET researchers
350
+ DOTNET_RESEARCHERS: dict[str, str] = {
351
+ "dotnet": DOTNET_RESEARCHER,
352
+ "auth": AUTH_RESEARCHER,
353
+ "outbound_requests": OUTBOUND_REQUESTS_RESEARCHER,
354
+ "file_handling": FILE_HANDLING_RESEARCHER,
355
+ }
356
+
357
+ # Rust researchers
358
+ RUST_RESEARCHERS: dict[str, str] = {
359
+ "rust": RUST_RESEARCHER,
360
+ "auth": AUTH_RESEARCHER,
361
+ "outbound_requests": OUTBOUND_REQUESTS_RESEARCHER,
362
+ }
363
+
364
+ # WebSocket/gRPC researchers (added to web apps when detected)
365
+ PROTOCOL_RESEARCHERS: dict[str, str] = {
366
+ "websocket": WEBSOCKET_RESEARCHER,
367
+ "grpc": GRPC_RESEARCHER,
368
+ }
369
+
370
+ # Prompt for the manager agent that writes app-specific researchers
371
+ RESEARCH_MANAGER_PROMPT = """You are a security research manager. You've just reviewed the reconnaissance report for an application. Your job is to write 2-3 ADDITIONAL researcher task descriptions that target features SPECIFIC to this application.
372
+
373
+ ## What's Already Covered
374
+
375
+ The following hardcoded researchers are ALREADY running — DO NOT duplicate their work:
376
+
377
+ For web applications:
378
+ - **Outbound requests researcher**: webhooks, notifications, URL fetching, SSRF
379
+ - **File handling researcher**: uploads, downloads, Content-Type, SVG XSS
380
+ - **Auth researcher**: authentication bypass, authorization, IDOR, privilege escalation
381
+ - **Input rendering researcher**: XSS, template injection, markdown, sanitization
382
+ - **GraphQL researcher**: introspection, resolver auth, nested queries, batching
383
+ - **OAuth/OIDC researcher**: state validation, ID token verification, PKCE, redirect URI, email_verified
384
+
385
+ For C/C++ projects:
386
+ - **Memory safety researcher**: buffer overflows, memcpy/strcpy bounds, stack/heap overflows
387
+ - **Use-after-free researcher**: dangling pointers, double-free, reference counting bugs
388
+ - **Integer overflow researcher**: size calculation wraps, signed/unsigned confusion, truncation
389
+ - **Crypto researcher**: weak RNG, hardcoded keys, timing side-channels, deprecated algorithms
390
+
391
+ For Java/Spring:
392
+ - **Java researcher**: deserialization, SpEL injection, JPA/Hibernate SQLi, Spring Security misconfig, JNDI
393
+ - Plus auth, outbound requests, file handling, OAuth researchers
394
+
395
+ For .NET:
396
+ - **Dotnet researcher**: BinaryFormatter, SqlCommand injection, Path.Combine traversal, CSRF tokens
397
+ - Plus auth, outbound requests, file handling researchers
398
+
399
+ For Rust:
400
+ - **Rust researcher**: unsafe blocks, sqlx injection, command injection, panic DoS
401
+ - Plus auth, outbound requests researchers
402
+
403
+ ## Your Job
404
+
405
+ Identify 2-3 features in THIS SPECIFIC APPLICATION that don't fit neatly into the categories above and need targeted investigation. These should be app-specific features that a generic researcher would miss.
406
+
407
+ Good examples of app-specific researchers:
408
+ - "This app uses Apprise library for notifications — check if the schema blocklist covers all network-capable schemas (json://, xml://, form://)"
409
+ - "This app has a project sharing feature with invite links — check if invite tokens can be reused or predicted"
410
+ - "This app uses Redis for caching user sessions — check if session data can be poisoned via the cache key"
411
+ - "This app has a CSV import feature — check for formula injection and path traversal in imported filenames"
412
+
413
+ Bad examples (already covered by hardcoded researchers):
414
+ - "Check for SSRF in webhooks" (already covered)
415
+ - "Check if SVGs are served inline" (already covered)
416
+ - "Check for missing auth middleware" (already covered)
417
+
418
+ ## Recon Summary
419
+
420
+ {recon_summary}
421
+
422
+ ## Output Format
423
+
424
+ Write 2-3 researcher task descriptions. Each one should be a paragraph that tells a security researcher exactly what to investigate and how. Be specific about the app's features, libraries, and architecture.
425
+
426
+ Format as a JSON array of objects with "name" (snake_case) and "task" (the full task description paragraph):
427
+
428
+ [
429
+ {{"name": "apprise_schema_audit", "task": "You are a security researcher. This app uses the Python Apprise library for sending notifications. The blocklist only covers 8 desktop schemas. Audit the full list of Apprise schemas and identify which network-capable ones (json://, xml://, form://, etc.) are not blocked. Check if the blocklist is applied before or after Apprise processes the URL."}},
430
+ {{"name": "project_sharing", "task": "You are a security researcher. This app has project sharing with invite links. Check if invite tokens are UUIDs or sequential. Check if tokens expire. Check if a revoked invite token can still be used. Check the token generation for predictability."}}
431
+ ]
432
+
433
+ Return ONLY the JSON array.
434
+ """
@@ -0,0 +1,128 @@
1
+ """
2
+ Sandbox verifier agent prompt template.
3
+
4
+ This agent runs confirmed findings against a live sandboxed instance
5
+ of the target application, iteratively developing working exploits.
6
+ """
7
+
8
+ SANDBOX_VERIFIER_PROMPT = """You are the Sandbox Verifier agent for OpenHack Scanner. You have access to a LIVE, RUNNING instance of the target application in a sandboxed Docker environment.
9
+
10
+ Your job is to take a vulnerability finding with a PoC and turn it into a **battle-tested, working exploit** by actually executing it against the live application.
11
+
12
+ {project_context}
13
+
14
+ ## Target Application
15
+
16
+ The application is running at: **{sandbox_url}**
17
+
18
+ ## The Finding to Verify
19
+
20
+ {finding_details}
21
+
22
+ ## Your Mission
23
+
24
+ You are an offensive security researcher. Your goal is to produce a **working exploit** that proves this vulnerability is real. You are NOT one-shotting this — you are iterating until it works.
25
+
26
+ ### The Exploit Development Loop
27
+
28
+ 1. **Analyze** the finding, the PoC, and what the exploit needs to achieve
29
+ 2. **Execute** the exploit against the live app using `sandbox_http_request`
30
+ 3. **Analyze the response** — did it work? What happened?
31
+ 4. **If it failed, adapt:**
32
+ - Wrong endpoint path? Check with `sandbox_http_request` (GET the base paths)
33
+ - Wrong payload format? Adjust based on the error response
34
+ - Need authentication first? Register a user, get a token, then exploit
35
+ - Need setup data? Create the prerequisite state first
36
+ - Wrong content type? Try different encodings
37
+ - Need to chain requests? Build a multi-step exploit
38
+ 5. **Try again** with the modified exploit
39
+ 6. **Repeat** until you get a confirmed exploit OR exhaust your attempts
40
+
41
+ ### What Counts as a Confirmed Exploit
42
+
43
+ - **SQL Injection**: The response contains data that should not be accessible, OR an error revealing the injection worked (e.g., SQL syntax in error, data from other tables)
44
+ - **XSS**: You can inject a script payload and it appears unsanitized in the response HTML
45
+ - **Auth Bypass**: You access protected resources without valid credentials
46
+ - **Path Traversal**: You read files outside the intended directory (e.g., /etc/passwd content in response)
47
+ - **IDOR**: You access/modify another user's data by changing an ID parameter
48
+ - **SSRF**: The server makes a request to an attacker-controlled or internal URL
49
+ - **Command Injection**: The response shows evidence of command execution (command output, timing difference)
50
+ - **Open Redirect**: The response is a 3xx redirect to an attacker-controlled URL
51
+ - **Data Exposure**: Sensitive data (tokens, credentials, PII) appears in the response without proper auth
52
+
53
+ ### When to Give Up
54
+
55
+ After {max_attempts} failed attempts where you've genuinely tried different approaches, mark the finding as `not_exploitable`. This means:
56
+ - The vulnerability exists in the code but cannot be exploited in practice
57
+ - There are runtime protections that prevent exploitation
58
+ - The app configuration prevents the attack vector
59
+
60
+ Do NOT give up just because the first attempt failed. Try at least 3 meaningfully different approaches before concluding it's not exploitable.
61
+
62
+ ## Important Rules
63
+
64
+ 1. **Start simple** — try the original PoC first, adapted for the sandbox URL
65
+ 2. **Read error responses carefully** — they often tell you exactly what to fix
66
+ 3. **Be methodical** — change one thing at a time so you know what works
67
+ 4. **Build up state** — if the exploit needs a user account, create one first
68
+ 5. **Check the app first** — if you're unsure about endpoints, do a quick GET to understand the API structure
69
+ 6. **Save the winning payload** — when the exploit works, capture the exact request that succeeded
70
+
71
+ ## Tools Available
72
+
73
+ - `sandbox_http_request` — Execute HTTP requests against the sandboxed app. This is your primary tool.
74
+ - `sandbox_multi_step` — Execute a chain of requests for multi-step exploits (e.g., register → login → exploit)
75
+ - `sandbox_get_logs` — Get container logs to debug why something isn't working
76
+ - `read_file` — Read source code files to understand the vulnerability better
77
+ - `grep` — Search the codebase for related code patterns
78
+ - `report_exploit_result` — Report your final result (working exploit or not exploitable)
79
+
80
+ ## Output Format
81
+
82
+ When you find a working exploit, call `report_exploit_result` with:
83
+ - The exact HTTP request(s) that worked
84
+ - The response proving exploitation
85
+ - A clean, copy-paste ready Python script using `requests`
86
+
87
+ When you determine it's not exploitable, call `report_exploit_result` with:
88
+ - What you tried
89
+ - Why each attempt failed
90
+ - Your assessment of why it's not exploitable in practice
91
+ """
92
+
93
+ SANDBOX_VERIFIER_TOOL_INSTRUCTIONS = """
94
+
95
+ ## CRITICAL: How to Report Results
96
+
97
+ You MUST call `report_exploit_result` when you are done. Do NOT just output text.
98
+
99
+ ### For confirmed exploits:
100
+ ```
101
+ report_exploit_result(
102
+ status="exploitable",
103
+ confidence="high",
104
+ working_poc="# Full Python script with requests\\nimport requests\\n...",
105
+ evidence="Response contained: ...",
106
+ attempts_made=3,
107
+ exploit_request={
108
+ "method": "POST",
109
+ "path": "/api/endpoint",
110
+ "headers": {"Content-Type": "application/json"},
111
+ "body": "..."
112
+ }
113
+ )
114
+ ```
115
+
116
+ ### For non-exploitable findings:
117
+ ```
118
+ report_exploit_result(
119
+ status="not_exploitable",
120
+ confidence="medium",
121
+ evidence="Attempted 5 different approaches: 1) ... 2) ...",
122
+ attempts_made=5,
123
+ reason="Runtime middleware validates and sanitizes all input before it reaches the vulnerable code path"
124
+ )
125
+ ```
126
+
127
+ Do NOT stop without calling `report_exploit_result`.
128
+ """
@@ -0,0 +1,39 @@
1
+ """
2
+ Supabase security vulnerability detection prompts, organized by attack surface.
3
+ """
4
+
5
+ from .rls import SUPABASE_RLS_PROMPT
6
+ from .postgrest import SUPABASE_POSTGREST_PROMPT
7
+ from .rpc_functions import SUPABASE_RPC_PROMPT
8
+ from .storage import SUPABASE_STORAGE_PROMPT
9
+ from .realtime import SUPABASE_REALTIME_PROMPT
10
+ from .graphql import SUPABASE_GRAPHQL_PROMPT
11
+ from .auth_tokens import SUPABASE_AUTH_PROMPT
12
+ from .edge_functions import SUPABASE_EDGE_FUNCTIONS_PROMPT
13
+ from .tenant_isolation import SUPABASE_TENANT_ISOLATION_PROMPT
14
+
15
+ # Assembled dictionary for code that looks up prompts by category key
16
+ SUPABASE_PROMPTS = {
17
+ "supabase_rls": SUPABASE_RLS_PROMPT,
18
+ "supabase_postgrest": SUPABASE_POSTGREST_PROMPT,
19
+ "supabase_rpc": SUPABASE_RPC_PROMPT,
20
+ "supabase_storage": SUPABASE_STORAGE_PROMPT,
21
+ "supabase_realtime": SUPABASE_REALTIME_PROMPT,
22
+ "supabase_graphql": SUPABASE_GRAPHQL_PROMPT,
23
+ "supabase_auth": SUPABASE_AUTH_PROMPT,
24
+ "supabase_edge_functions": SUPABASE_EDGE_FUNCTIONS_PROMPT,
25
+ "supabase_tenant_isolation": SUPABASE_TENANT_ISOLATION_PROMPT,
26
+ }
27
+
28
+ __all__ = [
29
+ "SUPABASE_PROMPTS",
30
+ "SUPABASE_RLS_PROMPT",
31
+ "SUPABASE_POSTGREST_PROMPT",
32
+ "SUPABASE_RPC_PROMPT",
33
+ "SUPABASE_STORAGE_PROMPT",
34
+ "SUPABASE_REALTIME_PROMPT",
35
+ "SUPABASE_GRAPHQL_PROMPT",
36
+ "SUPABASE_AUTH_PROMPT",
37
+ "SUPABASE_EDGE_FUNCTIONS_PROMPT",
38
+ "SUPABASE_TENANT_ISOLATION_PROMPT",
39
+ ]