-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSSHCommand.py
More file actions
40 lines (31 loc) · 896 Bytes
/
SSHCommand.py
File metadata and controls
40 lines (31 loc) · 896 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
40
import pexpect
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 wand to continue connecting'
conStr = 'ssh ' + user + '@' + host
child = pexpect.spawn(conStr)
ret = child.expect([pexcept.TIMEOUT, ssh_newkey, '[P|p]assword:'])
if ret == 0:
print ('[-] Error Connecting')
return
if ret == 1:
child.sending('yes')
ret = child.expect([pexcept.TIMEOUT, '[P|p]assword:'])
if ret == 0:
print ('[-] Error Connecting')
return
child.sendline(password)
child.expect(PROMPT)
return child
def main():
host = 'localhost'
user = 'roor'
password = 'toor'
child = connect(user, host, password)
send_command(child, 'cat /etc/shadow | greep root');
if __name__ == '__main__':
main()