module - Global variable not defined after separating functions to separate Python file -


continuing write dictionary attack script project.

my script calls upon 2 functions perform actual dictionary attack on ssh. first declared global variable in get_args() function in main.py, following main() function

def get_args():     # stuff parsing blah blah       global service, username, wordlist, address, port, delay      service = args.service     username = args.username     wordlist = args.password     address = args.address     port = args.port     delay = args.delay      return service, username, wordlist, address   def main():      service, username, wordlist, address = get_args()      # output , stuff      # ssh bruteforce     if service == 'ssh':         if address none:             print r + "[!] need provide ssh address cracking! [!]" + w     else:         print c + "[*] address: %s" % address + w         sleep(0.5)         global port         if port none:             print o + "[?] port not set. automatically set 22 [?]" + w             port = 22          print c + "[*] port: %s "  % port + w         sleep(1)         print p + "[*] starting dictionary attack! [*]" + w         print "using %s seconds of delay. default 1 second" % delay         sshbruteforce(address, username, wordlist) 

the line sshbruteforce(address, username, wordlist) references function include in seperate file module, import

from module1 import * 

inside module1.py:

# ssh_connect() def ssh_connect(password, code=0):     ssh = paramiko.sshclient()     ssh.set_missing_host_key_policy(paramiko.autoaddpolicy())     paramiko.util.log_to_file("filename.log")      try:         ssh.connect(address, port=port, username=username, password=password)   def sshbruteforce(address, username, wordlist):     wordlist = open(wordlist, 'r')      in wordlist.readlines():         password = i.strip("\n")         try:             response = ssh_connect(password)             # actual bruteforcing here. above line references ssh_connect()             # function, problem actual occurs 

the line, ssh.connect(address, port=port, username=username, password=password) problem occurs. let's execute script so:

python main.py -u root -w wordlist.txt -s ssh -p 22 -a 192.168.1.3  

this stores string "root" within variable username, , etc. however, once main.py program executes sshbruteforce() function, occurs:

global name 'address' not defined 

i know occurs within ssh_connect() function, line ssh.connect(address, port=port, username=username, password=password), meaning variable address not have stored in it. not know why occurring.

including from __main__ import * within module1.py not change anything. have seen many these questions asked, none similar situation.

the concept of global defining means should define outside of function, try init globals outside fuction none or , see if problem resolved


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -