forked from EONRaider/violent-python3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh_command.py
More file actions
39 lines (29 loc) · 957 Bytes
/
Copy pathssh_command.py
File metadata and controls
39 lines (29 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import pexpect
PROMPT = ['# ', '>>> ', '> ', '\$ ']
def send_command(child, cmd):
child.sendline(cmd)
child.expect(PROMPT)
print(child.before.decode('utf-8'))
def connect(host, user, password):
ssh_newkey = 'Are you sure you want to continue connecting'
conn_str = f'ssh {user}@{host}'
child = pexpect.spawn(conn_str)
ret = child.expect([pexpect.TIMEOUT, ssh_newkey, '[P|p]assword:'])
if not ret:
print('[-] Error Connecting')
return
else:
child.sendline('yes')
ret = child.expect([pexpect.TIMEOUT, '[P|p]assword:'])
if not ret:
print('[-] Error Connecting')
return
child.sendline(password)
child.expect(PROMPT)
return child
if __name__ == '__main__':
tgt_host = 'localhost'
tgt_user = 'root'
tgt_passwd = 'toor'
conn = connect(tgt_host, tgt_user, tgt_passwd)
send_command(conn, 'sudo cat /etc/shadow | grep root')