Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,6 @@ malware-analysis.md
if you are given a **forensic image** of a device you can start **analyzing the partitions, file-system** used and **recovering** potentially **interesting files** (even deleted ones). Learn how in:


{{#ref}}
partitions-file-systems-carving/
{{#endref}}# Basic Forensic Methodology



## Creating and Mounting an Image


{{#ref}}
../../generic-methodologies-and-resources/basic-forensic-methodology/image-acquisition-and-mount.md
{{#endref}}

## Malware Analysis

This **isn't necessary the first step to perform once you have the image**. But you can use this malware analysis techniques independently if you have a file, a file-system image, memory image, pcap... so it's good to **keep these actions in mind**:


{{#ref}}
malware-analysis.md
{{#endref}}

## Inspecting an Image

if you are given a **forensic image** of a device you can start **analyzing the partitions, file-system** used and **recovering** potentially **interesting files** (even deleted ones). Learn how in:


{{#ref}}
partitions-file-systems-carving/
{{#endref}}
Expand Down Expand Up @@ -119,58 +92,8 @@ anti-forensic-techniques.md
## Threat Hunting


{{#ref}}
file-integrity-monitoring.md
{{#endref}}



## Deep inspection of specific file-types and Software

If you have very **suspicious** **file**, then **depending on the file-type and software** that created it several **tricks** may be useful.\
Read the following page to learn some interesting tricks:


{{#ref}}
specific-software-file-type-tricks/
{{#endref}}

I want to do a special mention to the page:


{{#ref}}
specific-software-file-type-tricks/browser-artifacts.md
{{#endref}}

## Memory Dump Inspection


{{#ref}}
memory-dump-analysis/
{{#endref}}

## Pcap Inspection


{{#ref}}
pcap-inspection/
{{#endref}}

## **Anti-Forensic Techniques**

Keep in mind the possible use of anti-forensic techniques:


{{#ref}}
anti-forensic-techniques.md
{{#endref}}

## Threat Hunting


{{#ref}}
file-integrity-monitoring.md
{{#endref}}

{{#include ../../banners/hacktricks-training.md}}

Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ See also stego tools and carving techniques:
## JS/VBS droppers → Base64 PowerShell staging
A recurring initial stage is a small, heavily‑obfuscated `.js` or `.vbs` delivered inside an archive. Its sole purpose is to decode an embedded Base64 string and launch PowerShell with `-nop -w hidden -ep bypass` to bootstrap the next stage over HTTPS.
A recurring initial stage is a small, heavily‑obfuscated `.js` or `.vbs` delivered inside an archive. Its sole purpose is to decode an embedded Base64 string and launch PowerShell with `-nop -w hidden -ep bypass` to bootstrap the next stage over HTTPS.<sup>[[5]](#references)</sup>
Skeleton logic (abstract):
- Read own file contents
Expand Down
3 changes: 0 additions & 3 deletions src/generic-methodologies-and-resources/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@
- [**Basic python syntax and libraries**](basic-python.md)

{{#include ../../banners/hacktricks-training.md}}



Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,6 @@ with zipfile.ZipFile("sample.zip") as zf:
## References

- [1] [Python tarfile docs](https://docs.python.org/3/library/tarfile.html)
- [2] [PEP 706 - Filter for tarfile.extractall](https://peps.python.org/pep-0706/)
- [2] [PEP 706 Filter for tarfile.extractall()](https://peps.python.org/pep-0706/)

{{#include ../../banners/hacktricks-training.md}}
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,3 @@ main()

{{#include ../../banners/hacktricks-training.md}}



Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{{#include ../../../banners/hacktricks-training.md}}

These are some tricks to bypass python sandbox protections and execute arbitrary commands.
These are some tricks to bypass python sandbox protections and execute arbitrary commands.<sup>[[1]](#references)[[2]](#references)</sup>

{{#ref}}
js2py-sandbox-escape-cve-2024-28397.md
Expand Down Expand Up @@ -75,7 +75,7 @@ class P(object):
print(base64.b64encode(pickle.dumps(P(), protocol=0)))
```

For more information about how pickle works check this: [https://checkoway.net/musings/pickle/](https://checkoway.net/musings/pickle/)
For more information about how pickle works check this: [https://checkoway.net/musings/pickle/](https://checkoway.net/musings/pickle/)<sup>[[16]](#references)</sup>

### Pip package

Expand Down Expand Up @@ -313,7 +313,7 @@ __ixor__ (k ^= 'import os; os.system("sh")')

#### Crating objects with [metaclasses](https://docs.python.org/3/reference/datamodel.html#metaclasses)

The key thing that metaclasses allow us to do is **make an instance of a class, without calling the constructor** directly, by creating a new class with the target class as a metaclass.
The key thing that metaclasses allow us to do is **make an instance of a class, without calling the constructor** directly, by creating a new class with the target class as a metaclass.<sup>[[15]](#references)</sup>

```python
# Code from https://ur4ndom.dev/posts/2022-07-04-gctf-treebox/ and fixed
Expand Down Expand Up @@ -404,7 +404,7 @@ __builtins__.__dict__['__import__']("os").system("ls")
### No Builtins

When you don't have `__builtins__` you are not going to be able to import anything nor even read or write files as **all the global functions** (like `open`, `import`, `print`...) **aren't loaded**.\
However, **by default python imports a lot of modules in memory**. These modules may seem benign, but some of them are **also importing dangerous** functionalities inside of them that can be accessed to gain even **arbitrary code execution**.
However, **by default python imports a lot of modules in memory**. These modules may seem benign, but some of them are **also importing dangerous** functionalities inside of them that can be accessed to gain even **arbitrary code execution**.<sup>[[4]](#references)[[5]](#references)</sup>

In the following examples you can observe how to **abuse** some of this "**benign**" modules loaded to **access** **dangerous** **functionalities** inside of them.

Expand Down Expand Up @@ -776,7 +776,7 @@ https://github.com/carlospolop/hacktricks/blob/master/generic-methodologies-and-

## Python Format String

If you **send** a **string** to python that is going to be **formatted**, you can use `{}` to access **python internal information.** You can use the previous examples to access globals or builtins for example.
If you **send** a **string** to python that is going to be **formatted**, you can use `{}` to access **python internal information.** You can use the previous examples to access globals or builtins for example.<sup>[[14]](#references)</sup>

```python
# Example from https://www.geeksforgeeks.org/vulnerability-in-str-format-in-python/
Expand Down Expand Up @@ -1064,7 +1064,7 @@ dis.dis('d\x01\x00}\x01\x00d\x02\x00}\x02\x00d\x03\x00d\x04\x00g\x02\x00}\x03\x0
## Compiling Python

Now, let us imagine that somehow you can **dump the information about a function that you cannot execute** but you **need** to **execute** it.\
Like in the following example, you **can access the code object** of that function, but just reading the disassemble you **don't know how to calculate the flag** (_imagine a more complex `calc_flag` function_)
Like in the following example, you **can access the code object** of that function, but just reading the disassemble you **don't know how to calculate the flag** (_imagine a more complex `calc_flag` function_)<sup>[[3]](#references)</sup>

```python
def get_flag(some_input):
Expand Down Expand Up @@ -1215,5 +1215,8 @@ will be bypassed
- [11] [SECCON CTF 2022 Quals: Author writeups (English)](https://blog.arkark.dev/2022/11/18/seccon-en/#misc-latexipy)
- [12] [Anatomy of an LLM RCE - CyberArk Threat Research Blog](https://www.cyberark.com/resources/threat-research-blog/anatomy-of-an-llm-rce)
- [13] [BuckeyeCTF 2024 Author Writeups](https://corgi.rip/posts/buckeye-writeups/)
- [14] [GeeksforGeeks – Vulnerability in str.format() in Python](https://www.geeksforgeeks.org/vulnerability-in-str-format-in-python/)
- [15] [ur4ndom – [GCTF 2022] Treebox](https://ur4ndom.dev/posts/2022-07-04-gctf-treebox/)
- [16] [checkoway.net - Musings - Pickle](https://checkoway.net/musings/pickle)

{{#include ../../../banners/hacktricks-training.md}}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ PY

## Operating against web sandboxes

- Any endpoint that feeds attacker-controlled JS into `js2py.eval_js` (for example, a Flask `/run_code` API) is immediately RCE if the process user has shell access.
- Any endpoint that feeds attacker-controlled JS into `js2py.eval_js` (for example, a Flask `/run_code` API) is immediately RCE if the process user has shell access.<sup>[[2]](#references)</sup>
- Returning `jsonify({'result': result})` will fail when `.communicate()` returns bytes; decode or direct output to DNS/ICMP to avoid serialization blockers.
- `disable_pyimport()` **does not** mitigate this chain; hard isolation (separate process/container) or removing Js2Py execution of untrusted code is required.<sup>[[2]](#references)</sup>
- `disable_pyimport()` **does not** mitigate this chain; hard isolation (separate process/container) or removing Js2Py execution of untrusted code is required.

## References

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,9 @@ Additional mitigation ideas
- Don’t allow arbitrary `CodeType.replace(...)` on untrusted input, or add strict structural checks on the resulting code object.
- Consider running untrusted code in a separate process with OS-level sandboxing (seccomp, job objects, containers) instead of relying on CPython semantics.



## References

- [1] [Splitline's HITCON CTF 2022 writeup "V O I D" (origin of this technique and high-level exploit chain)](https://blog.splitline.tw/hitcon-ctf-2022/)
- [2] [Python disassembler docs (indices semantics for LOAD_CONST/LOAD_NAME/etc., and 3.11+ `LOAD_ATTR`/`LOAD_GLOBAL` low-bit flags)](https://docs.python.org/3.13/library/dis.html)

{{#include ../../../banners/hacktricks-training.md}}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This page documents a practical sandbox escape and RCE primitive in ReportLab’
CVE-2023-33733 affects ReportLab versions up to and including 3.6.12.<sup>[[3]](#references)</sup> In certain attribute contexts (for example color), values wrapped in triple brackets [[[ ... ]]] are evaluated server-side by rl_safe_eval. By crafting a payload that pivots from a whitelisted builtin (pow) to its Python function globals, an attacker can reach the os module and execute commands.<sup>[[1]](#references)</sup>

Key points
- Trigger: inject [[[ ... ]]] into evaluated attributes such as <font color="..."> or any style path that eventually reaches `reportlab.lib.colors.toColor` within ReportLab/xhtml2pdf.
- Trigger: inject [[[ ... ]]] into evaluated attributes such as <font color="..."> or any style path that eventually reaches `reportlab.lib.colors.toColor` within ReportLab/xhtml2pdf.<sup>[[4]](#references)</sup>
- Sandbox: rl_safe_eval replaces dangerous builtins but evaluated functions still expose __globals__.
- Bypass: craft a transient class Word to bypass rl_safe_eval name checks and access the string "__globals__" while avoiding blocked dunder filtering.
- RCE: `getattr(pow, Word('__globals__'))['os'].system('<cmd>')`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ print(vars(emp)) #{'name': 'Ahemd', 'age': 23, 'manager': {'name': 'Sarah'}}

<details>

<summary>Creating class property default value to RCE (subprocess)</summary>
<summary>Creating class property default value to RCE (subprocess)</summary><sup>[[1]](#references)</sup>

```python
from os import popen
Expand Down Expand Up @@ -122,7 +122,7 @@ print(system_admin_emp.execute_command())

<details>

<summary>Polluting other classes and global vars through <code>globals</code></summary>
<summary>Polluting other classes and global vars through <code>globals</code></summary><sup>[[1]](#references)</sup>

```python
def merge(src, dst):
Expand Down Expand Up @@ -156,7 +156,7 @@ print(NotAccessibleClass) #> <class '__main__.PollutedClass'>

<details>

<summary>Arbitrary subprocess execution</summary>
<summary>Arbitrary subprocess execution</summary><sup>[[1]](#references)</sup>

```python
import subprocess, json
Expand Down Expand Up @@ -270,5 +270,3 @@ python-internal-read-gadgets.md
- [2] [CTFtime - idekCTF 2022: task manager writeup](https://ctftime.org/writeup/36082)

{{#include ../../banners/hacktricks-training.md}}


Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Notes:

Root cause:
- _retrieve_class_or_fn used unrestricted importlib.import_module() with attacker-controlled module strings from config.json.
- Impact: Arbitrary import of any installed module (or attacker-planted module on sys.path). Import-time code runs, then object construction occurs with attacker kwargs.<sup>[[1]](#references)[[4]](#references)</sup>
- Impact: Arbitrary import of any installed module (or attacker-planted module on sys.path). Import-time code runs, then object construction occurs with attacker kwargs.<sup>[[1]](#references)[[4]](#references)[[5]](#references)[[6]](#references)</sup>

Exploit idea:

Expand Down Expand Up @@ -151,9 +151,9 @@ Important limitation:

## ML pickle import allowlisting for AI/ML models (Fickling)

Many AI/ML model formats (PyTorch .pt/.pth/.ckpt, joblib/scikit-learn, older TensorFlow artifacts, etc.) embed Python pickle data. Attackers routinely abuse pickle GLOBAL imports and object constructors to achieve RCE or model swapping during load. Blacklist-based scanners often miss novel or unlisted dangerous imports.<sup>[[8]](#references)</sup>
Many AI/ML model formats (PyTorch .pt/.pth/.ckpt, joblib/scikit-learn, older TensorFlow artifacts, etc.) embed Python pickle data. Attackers routinely abuse pickle GLOBAL imports and object constructors to achieve RCE or model swapping during load. Blacklist-based scanners often miss novel or unlisted dangerous imports.<sup>[[8]](#references)[[14]](#references)</sup>

A practical fail-closed defense is to hook Python’s pickle deserializer and only allow a reviewed set of harmless ML-related imports during unpickling. Trail of Bits’ Fickling implements this policy and ships a curated ML import allowlist built from thousands of public Hugging Face pickles.<sup>[[8]](#references)</sup>
A practical fail-closed defense is to hook Python’s pickle deserializer and only allow a reviewed set of harmless ML-related imports during unpickling. Trail of Bits’ Fickling implements this policy and ships a curated ML import allowlist built from thousands of public Hugging Face pickles.<sup>[[8]](#references)[[13]](#references)</sup>

Security model for “safe” imports (intuitions distilled from research and practice): imported symbols used by a pickle must simultaneously:<sup>[[8]](#references)</sup>
- Not execute code or cause execution (no compiled/source code objects, shelling out, hooks, etc.)
Expand Down Expand Up @@ -192,9 +192,9 @@ fickling.hook.activate_safe_ml_environment(also_allow=[
- with fickling.check_safety(): for scoped enforcement
- fickling.load(path) / fickling.is_likely_safe(path) for one-off checks

- Prefer non-pickle model formats when possible (e.g., SafeTensors). If you must accept pickle, run loaders under least privilege without network egress and enforce the allowlist.
- Prefer non-pickle model formats when possible (e.g., SafeTensors).<sup>[[15]](#references)</sup> If you must accept pickle, run loaders under least privilege without network egress and enforce the allowlist.

This allowlist-first strategy demonstrably blocks common ML pickle exploit paths while keeping compatibility high. In ToB’s benchmark, Fickling flagged 100% of synthetic malicious files and allowed ~99% of clean files from top Hugging Face repos.<sup>[[8]](#references)</sup>
This allowlist-first strategy demonstrably blocks common ML pickle exploit paths while keeping compatibility high. In ToB’s benchmark, Fickling flagged 100% of synthetic malicious files and allowed ~99% of clean files from top Hugging Face repos.<sup>[[8]](#references)[[10]](#references)</sup>


## Researcher toolkit
Expand Down
5 changes: 3 additions & 2 deletions src/generic-methodologies-and-resources/python/pyscript.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PyScript is a new framework developed for integrating Python into HTML so, it ca

### Dumping / Retrieving files from the Emscripten virtual memory filesystem:

`CVE ID: CVE-2022-30286`\
`CVE ID: CVE-2022-30286`<sup>[[3]](#references)</sup>\
\
Code:

Expand All @@ -25,7 +25,7 @@ Result:

### [OOB Data Exfiltration of the Emscripten virtual memory filesystem (console monitoring)](https://github.com/s/jcd3T19P0M8QRnU1KRDk/~/changes/Wn2j4r8jnHsV8mBiqPk5/blogs/the-art-of-vulnerability-chaining-pyscript)

`CVE ID: CVE-2022-30286`\
`CVE ID: CVE-2022-30286`<sup>[[3]](#references)</sup>\
\
Code:

Expand Down Expand Up @@ -243,5 +243,6 @@ This behaviour was introduced in 2023 and is documented in the official Built-in

- [1] [NVD – CVE-2025-50182](https://nvd.nist.gov/vuln/detail/CVE-2025-50182)
- [2] [PyScript Built-ins documentation – `display` & `HTML`](https://docs.pyscript.net/2024.6.1/user-guide/builtins/)
- [3] [Cyber Guy - The Art of Vulnerability Chaining (PyScript)](https://cyber-guy.gitbook.io/cyber-guy/blogs/the-art-of-vulnerability-chaining-pyscript)

{{#include ../../banners/hacktricks-training.md}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

{{#include ../../banners/hacktricks-training.md}}


## Basic Information

Different vulnerabilities such as [**Python Format Strings**](bypass-python-sandboxes/index.html#python-format-string) or [**Class Pollution**](class-pollution-pythons-prototype-pollution.md) might allow you to **read python internal data but won't allow you to execute code**. Therefore, a pentester will need to make the most of these read permissions to **obtain sensitive privileges and escalate the vulnerability**.
Expand Down
2 changes: 0 additions & 2 deletions src/generic-methodologies-and-resources/python/venv.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,3 @@ inside the virtual environment

{{#include ../../banners/hacktricks-training.md}}



Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,3 @@ term.cmdloop()

{{#include ../../banners/hacktricks-training.md}}



Loading