Advertisement
rfmonk

brutessh1.py

Nov 25th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. #! /usr/bin/env python
  2.  
  3. import pexpect
  4. PROMPT = ['# ', '>>> ', '> ', '\$ ']
  5. def send_command(child, cmd):
  6.     child.sendline(cmd)
  7.     child.expect(PROMPT)
  8.     print child.before
  9. def connect(user, host, password):
  10.     ssh_newkey = 'Are you sure you want to continue connecting'
  11.     connStr = 'ssh ' + user + '@' + host
  12.     child = pexpect.spawn(connStr)
  13.     ret = child.expect([pexpect.TIMEOUT, ssh_newkey, \
  14.         '[P|p]assword:'])
  15.     if ret == 0:
  16.         print '[-] Error Connecting'
  17.         return
  18.     if ret == 1:
  19.         child.sendline('yes')
  20.         ret = child.expect([pexpect.TIMEOUT, \
  21.             '[P|p]assword:'])
  22.         if ret == 0:
  23.             print '[-] Error Connecting'
  24.                 return
  25.             child.sendline(password)
  26.             child.expect(PROMPT)
  27.             return child
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement