Python Forum
Need help with a Python script!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with a Python script!
#1
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()
Reply
#2
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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,452 Jun-29-2023, 11:57 AM
Last Post: gologica
  How to kill a bash script running as root from a python script? jc_lafleur 4 6,003 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,347 May-28-2020, 05:27 PM
Last Post: micseydel
  Package python script which has different libraries as a single executable or script tej7gandhi 1 2,661 May-11-2019, 08:12 PM
Last Post: keames
  How to run python script which has dependent python script in another folder? PrateekG 1 3,190 May-23-2018, 04:50 PM
Last Post: snippsat
  How to call one python script and use its output in another python script lravikumarvsp 3 32,496 May-16-2018, 02:08 AM
Last Post: lravikumarvsp
  Check Python version from inside script? Run Pythons script in v2 compatibility mode? pstein 2 9,888 Jul-07-2017, 08:59 AM
Last Post: snippsat
  Cant pass corect variables to python script in bash script neradp 3 6,265 Nov-05-2016, 01:26 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020