You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/generic-methodologies-and-resources/python/python-internal-read-gadgets.md
+51-1Lines changed: 51 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,57 @@ Use this payload to **change `app.secret_key`** (the name in your app might be d
41
41
42
42
If the vulnerability is in a different python file, check the previous Flask trick to access the objects from the main python file.
43
43
44
-
{{#include ../../banners/hacktricks-training.md}}
44
+
### Django - SECRET_KEY and settings module
45
+
46
+
The Django settings object is cached in `sys.modules` once the application starts. With only read primitives you can leak the **`SECRET_KEY`**, database credentials or signing salts:
Once the key is known you can forge Django signed cookies or tokens in a similar way to Flask.
64
+
65
+
### Environment variables / cloud creds via loaded modules
46
66
67
+
Many jails still import `os` or `sys` somewhere. You can abuse any reachable function `__init__.__globals__` to pivot to the already-imported `os` module and dump **environment variables** containing API tokens, cloud keys or flags:
68
+
69
+
```python
70
+
# Classic os._wrap_close subclass index may change per version
71
+
cls= [c for c inobject.__subclasses__() if'os._wrap_close'instr(c)][0]
Environment variables are frequently the only secrets needed to move from read to full compromise (cloud IAM keys, database URLs, signing keys, etc.).
82
+
83
+
### Django-Unicorn class pollution (CVE-2025-24370)
84
+
85
+
`django-unicorn` (<0.62.0) allowed **class pollution** via crafted component requests. Setting a property path such as `__init__.__globals__` let an attacker reach the component module globals and any imported modules (e.g. `settings`, `os`, `sys`). From there you can leak `SECRET_KEY`, `DATABASES` or service credentials without code execution. The exploit chain is purely read-based and uses the same dunder-gadget patterns as above.
86
+
87
+
### Gadget collections for chaining
88
+
89
+
Recent CTFs (e.g. jailCTF 2025) show reliable read chains built only with attribute access and subclass enumeration. Community-maintained lists such as [**pyjailbreaker**](https://github.com/jailctf/pyjailbreaker) catalog hundreds of minimal gadgets you can combine to traverse from objects to `__globals__`, `sys.modules` and finally sensitive data. Use them to quickly adapt when indices or class names differ between Python minor versions.
90
+
91
+
92
+
93
+
## References
94
+
95
+
-[Wiz analysis of django-unicorn class pollution (CVE-2025-24370)](https://www.wiz.io/vulnerability-database/cve/cve-2025-24370)
0 commit comments