Need help with a Python script! - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Need help with a Python script! (/thread-3902.html) |
Need help with a Python script! - Kaos_Method - Jul-06-2017 Hey guys! I'm trying to get this script to work, but I can't seem to make that happen. I've tinkered with it quite a bit, but I keep getting kick backs. When I look it up online and ask buddies, I'm told it should function the way it is. Below is what I'm told is wrong. I understand it can't connect to the host (I had my information and such in there to make connecting possible). I just don't understand why it's saying specific lines are wrong. Could not establish connection to host [-] Error Connecting Traceback (most recent call last): File "/root/Documents/Python/Serpent.py", line 41, in <module> botnetCommand('ls -la') File "/root/Documents/Python/Serpent.py", line 30, in botnetCommand output = client.send_command(command) #To get output File "/root/Documents/Python/Serpent.py", line 24, in send_command self.session.sendline(cmd) AttributeError: 'NoneType' object has no attribute 'sendline' #!/usr/bin/python3.5 from pexpect import pxssh class Client: #Defining the class def __init__(self, host, user, password): #Create the initializer self.host = host self.user = user self.password = password self.session = self.connect() def connect(self):#connect method try: #incase connect fails x = pxssh.pxssh() #Set x as a variable for pxssh x.login(self.host, self.user, self.password) return x #If login is complete except Exception as e: #if fails print (e) print ('[-] Error Connecting') def send_command(self, cmd): self.session.sendline(cmd) self.session.prompt() return self.session.before def botnetCommand(command): #Function to send command(s) for client in botNet: output = client.send_command(command) #To get output print (' [*] Output from ' + client.host) #To get output print ('[+]' + output) def addClient (host, user, password): #Adding client to botnet client = Client(host, user, password) botNet.append(client) #Adding client session to botnet botNet = [] addClient() RE: Need help with a Python script! - Larz60+ - Jul-07-2017 It looks like session is not connected, or has no method named sendline Try adding some print statements (or run in debugger) that is a sure way to see that you are getting the results that you expect. Actually, looking at it a bit more, you're calling addClient with no arguments in your example code, but the error message doesn't match, it shows an 'ls -la' command please show code that matches error! |