Guest User

Untitled

a guest
Mar 23rd, 2018
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 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. def connect(user, host, password):
  8. ssh_newkey = 'Are you sure you want to continue connecting'
  9. connStr = 'ssh ' + user + '@' + host
  10. child = pexpect.spawn(connStr)
  11. ret = child.expect([pexpect.TIMEOUT, ssh_newkey, \
  12. '[P|p]assword:'])
  13. if ret == 0:
  14. print '[-] Error Connecting'
  15. return
  16. if ret == 1:
  17. child.sendline('yes')
  18. ret = child.expect([pexpect.TIMEOUT, \
  19. '[P|p]assword:'])
  20. if ret == 0:
  21. print '[-] Error Connecting'
  22. return
  23. child.sendline(password)
  24. child.expect(PROMPT)
  25. return child
  26. def main():
  27. host = 'localhost'
  28. user = 'root'
  29. password = 'toor'
  30. child = connect(user, host, password)
  31. send_command(child, 'cat /etc/shadow | grep root')
  32. if __name__ == '__main__':
  33. main()
Add Comment
Please, Sign In to add comment