Created
April 18, 2016 14:44
-
-
Save mgeeky/6ddd94ce4ee9cf4bb8fa3de9246c40f3 to your computer and use it in GitHub Desktop.
sshcommand.py - ripped out from Violent Python - by TJ O'Connor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment