Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Import a couple of modules
- import paramiko # For High level networking
- import os # Basic shell usage
- import getpass # Allows user input without echoing
- import sys # Allows basic system commands
- import time # Works with local time
- # Initialise the class as an object. Create a couple of functions inside.
- # __init__ is present in every class, Instantiation which occurs before any function is called
- # Even if __init__ properties arent specified, it still exists.
- class startUP(object):
- def __init__(self):
- execComm = execCommand()
- class execCommand(object):
- # Set a couple of global class variables and clear the shell
- os.system(['clear', 'cls'][os.name == 'nt'])
- _host = raw_input("\n\n[!] Please Enter Remote IP: ")
- _port = raw_input("[!] Please Enter Target Port: ")
- _port = int(_port)
- _uname = raw_input("[!] Please Enter Target Username: ")
- _passwd = getpass.getpass("[!] Please Enter Target Password: ")
- # Example of multi line printing
- def __init__(self):
- print('''
- __ __
- ( ) _ - _ ( )
- ~~ ~~
- ( 0 0 )
- --------ooO----( )----Ooo--------
- """ ( ) """
- ( )
- \ /
- ~~O~~
- \n''')
- # Print a few options to screen, pairing data structures together with the zip function creating a menu
- print('\n\nJoin me in the sewers...\nIt may be time to search for RATs\n\n')
- self._Item = ['Menu', '1', '2', '0']
- self._Desc = ['Job List\n\n', 'Bad Samaritan', 'Retrieval Job\n', 'Great Escape\n']
- for q, a in zip(self._Item, self._Desc):
- print('{0}: The {1}'.format(q, a))
- # Ask for user input and set the received value as an integer.
- self._Choice = raw_input('Tell Me What To Do..: ')
- self._Choice = int(self._Choice)
- # Function Variables
- self._List = str('')
- self. _Str = str(self._List)
- self._UI = str('')
- # Basic if, else if and else sequence. Various different functions are called depending on response
- try:
- if self._Choice == 1:
- execCommand.paraMiko(self)
- elif self._Choice == 2:
- execCommand.SFTP(self)
- # System Exit exits the script
- else:
- paramiko.SFTPClient().close()
- paramiko.SSHClient().close()
- raise SystemExit
- except Exception, e:
- print e
- def paraMiko(self):
- # Save time by defining the paramiko client. Set logging file local host side.
- # Append host keys to known_host file using paramikos auto add policy.
- # Connect to the host using the specified global class variables.
- # If system allows it, call for a pseudo terminal. Grab banner from the server.
- # Start bash string with a parenthases. Start the loop function.
- # Setting a timeout of 2 seconds to allow buffer to fill (Banner grab)
- try:
- self.ssh = paramiko.SSHClient()
- paramiko.util.log_to_file('/tmp/parakito.log')
- self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- self.ssh.connect(execCommand._host, execCommand._port, username=execCommand._uname,
- password=execCommand._passwd, timeout=2)
- self._Chan = self.ssh.invoke_shell()
- print ('\n[+] Connected\n')
- self._Data = self._Chan.recv(2014)
- print '[+] Host Message Of The Day\n' + str(self._Data)
- self._Str += '('
- execCommand.loop(self)
- except Exception, e:
- print e
- finally:
- self.ssh.close()
- def loop(self):
- # Question loop starts here, within its own function.
- try:
- self._UI = raw_input("SSH > ")
- execCommand.Verify(self)
- except ValueError:
- print("Apologies, I Wasnt Expecting That. Try Again...")
- execCommand.loop(self)
- def Verify(self):
- # This function loops the question, adding each input to the string (self._str)
- # If Disconnect is present in the return, we print the concatenated string output
- # It then asks us if we are ready to proceed, if so it will execute the bash string
- # To the server. '> /home/notalog.txt' is a way of saying, save all output to this file.
- try:
- if self._UI == str('Disconnect'):
- self._Str += 'uptime) > /home/notalog.txt'
- print('\n\n'+self._Str)
- self._Req = raw_input('\n[!] Fingers Trembling, Ready To Send? [Execute/Stop]: ')
- if self._Req == str("Execute"):
- print('\n[+] Issuing Commands To Server..\n')
- execCommand.Push(self)
- else:
- execCommand.loop(self)
- else:
- self._Str += str((self._UI))+ '; '
- execCommand.loop(self)
- except Exception, e:
- print e
- def Push(self):
- # Standard (input, output, error) are declared as result of the execute command function
- # In paramiko. Executing the class variable self._Str as the command to be executed.
- # Wait for user input, then go to main menu.
- try:
- self._stdin, self._stdout, self._stderr = self.ssh.exec_command(self._Str)
- raw_input('\nShall We Proceed?..')
- execCommand()
- except Exception, e:
- print e
- self.ssh.close()
- def SFTP(self):
- # Using the transport function from paramiko using the global class variables host, port
- # Connecting using the global class variables uname and password
- # Setting the local and remote paths. SFTP.get takes two arguments, a send and a receive
- # This sequence can be reversed when using the SFTP.put method to upload a file instead of download.
- # The prog bar calculates transfer time and displays this in the interpreter
- def progBar(transferred, toBeTransferred):
- print("\n[+] Transferred: {0}\tOut Of: {1}".format(transferred, toBeTransferred))
- try:
- self._T = paramiko.Transport((execCommand._host, execCommand._port))
- self._T.connect(username=execCommand._uname, password = execCommand._passwd)
- self._SFTP = paramiko.SFTPClient.from_transport(self._T)
- self._remotepath='/home/notalog.txt'
- self._localpath='/home/Spawn/Desktop/SFTP/notalog.txt'
- self._SFTP.get(self._remotepath,self._localpath, callback=progBar)
- print('\n[+] File Successfully Sent')
- raw_input("\n[!] Ready To Proceed?")
- self._SFTP.close()
- startUP()
- except Exception, e:
- print e
- try:
- # Classes are initialised by defining their name within a function
- s = startUP()
- except KeyboardInterrupt:
- # Keyboard interrupt; Control - C.
- # Using the time module to implement delays in messages
- # Raw input at the end waiting for enter press
- paramiko.SSHClient().close()
- print('\n\n[+] Connection Terminated By User, Closing SSH Connection..')
- time.sleep(0.5)
- print('\n[+] SSH Connection Terminated Successfully..')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement