From 4ac221710b8e44c84cbec858fa303f8db0c5db4d Mon Sep 17 00:00:00 2001 From: Omar Santos Date: Sun, 31 Mar 2019 13:34:48 -0400 Subject: [PATCH] Update python_cool_tricks.md --- python_ruby_and_bash/python_cool_tricks.md | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/python_ruby_and_bash/python_cool_tricks.md b/python_ruby_and_bash/python_cool_tricks.md index 1c79935..b5a6aea 100644 --- a/python_ruby_and_bash/python_cool_tricks.md +++ b/python_ruby_and_bash/python_cool_tricks.md @@ -3,24 +3,35 @@ ## Starting a quick web server to serve some files (useful for post exploitation) ### In Python 2.x -`python -m SimpleHTTPServer 1337` +``` +python -m SimpleHTTPServer 1337 +``` ### In Python 3.x -`python3 -m http.server 1337` +``` +python3 -m http.server 1337 +``` ---- ## Pythonic Web Client ### In Python 2.x -`python -c 'import urllib2; print urllib2.urlopen("http://h4cker.org/web").read()' | tee /tmp/file.html` +``` +python -c 'import urllib2; print urllib2.urlopen("http://h4cker.org/web").read()' | tee /tmp/file.html +``` + ### In Python 3.x -`python3 -c 'import urllib.request; urllib.request.urlretrieve ("http://h4cker.org/web","/tmp/h4cker.html")'` +``` +python3 -c 'import urllib.request; urllib.request.urlretrieve ("http://h4cker.org/web","/tmp/h4cker.html")' +``` ---- ## Python Debugger This imports a Python file and runs the debugger automatically. This is useful for debugging Python-based malware and for post-exploitation. -`python -m pdb ` +``` +python -m pdb +``` Refer to this [Python Debugger cheatsheet](https://kapeli.com/cheat_sheets/Python_Debugger.docset/Contents/Resources/Documents/index) if you are not familiar with the Python Debugger. @@ -29,7 +40,9 @@ Refer to this [Python Debugger cheatsheet](https://kapeli.com/cheat_sheets/Pytho ## Shell to Terminal This is useful after exploitation and getting a shell. It allows you to use Linux commands that require a terminal session (e.g., su, sudo, vi, etc.) -`python -c 'import pty; pty.spawn("/bin/bash")'` +``` +python -c 'import pty; pty.spawn("/bin/bash")' +``` ----