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: Upload Insecure Files/README.md
+26Lines changed: 26 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -279,6 +279,31 @@ Alternatively you may be able to upload a JSON file with a custom scripts, try t
279
279
}
280
280
```
281
281
282
+
#### Python Path File
283
+
284
+
When a `.pth` file is placed in a directory like `site-packages` or `dist-packages`, Python's `site` initialization logic processes it during interpreter startup.
285
+
286
+
> An executable line in a .pth file is run at every Python startup, regardless of whether a particular module is actually going to be used. - [Site-specific configuration hook](https://docs.python.org/3/library/site.html)
287
+
288
+
Dropping a malicious `.pth` file into a globally loaded package directory can give an attacker repeated code execution without modifying the target application's source code. Any Python program that starts in that environment may trigger the payload.
289
+
290
+
Default locations for globally loaded package directories can be extracted using `python3 -m site`. Typical locations include:
291
+
292
+
```py
293
+
/usr/lib/pythonX.Y/site-packages/
294
+
/usr/local/lib/pythonX.Y/dist-packages/
295
+
296
+
# home location
297
+
/root
298
+
/home/$USER
299
+
```
300
+
301
+
Example of malicious use, this will create a reverse shell that will connect back to the attacker's machine every time a Python process starts in that environment.:
If the backend is using ImageMagick to resize/convert user images, you can try to exploit well-known vulnerabilities such as ImageTragik.
@@ -368,6 +393,7 @@ More payloads in the folder `CVE FFmpeg HLS/`.
368
393
## References
369
394
370
395
* [A New Vector For “Dirty” Arbitrary File Write to RCE - Doyensec - Maxence Schmitt and Lorenzo Stella - 28 Feb 2023](https://web.archive.org/web/20230228140105/https://blog.doyensec.com/2023/02/28/new-vector-for-dirty-arbitrary-file-write-2-rce.html)
396
+
* [Analysis of Python's .pth files as a persistence mechanism - @malmoeb - January 14, 2025](https://dfir.ch/posts/publish_python_pth_extension/)
371
397
* [Arbitrary File Upload Tricks In Java - pyn3rd -2022-05-07](https://web.archive.org/web/20220601101409/https://pyn3rd.github.io/2022/05/07/Arbitrary-File-Upload-Tricks-In-Java/)
372
398
* [Attacking Webservers Via .htaccess- Eldar Marcussen - May 17, 2011](https://web.archive.org/web/20200203171034/https://www.justanotherhacker.com:80/2011/05/htaccess-based-attacks.html)
373
399
* [BookFresh Tricky File Upload Bypass to RCE- Ahmed Aboul-Ela - November 29, 2014](http://web.archive.org/web/20141231210005/https://secgeek.net/bookfresh-vulnerability/)
0 commit comments