-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparamiko1.py
More file actions
65 lines (43 loc) · 1.59 KB
/
Copy pathparamiko1.py
File metadata and controls
65 lines (43 loc) · 1.59 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#we add paramiko library
import paramiko
#we describe function for execute command
def execute_command():
# receive input from the user
command = input('>> ')
#we create loop and if input is "Quit,quit, QUIT" function will end
while command.lower().strip() != 'quit' :
#remote server execute command, stdin->send to data, stdout->command output, stderr->error message
stdin, stdout, stderr = ssh.exec_command(command)
#read for output
output = stdout.read()
error = stderr.read()
#print output and output was encoded and we are decoding
print(output.decode())
print(error.decode())
#again receive input from the user
command = input('>> ')
#function end
return 0
#create a object and this name is ssh
ssh = paramiko.SSHClient()
#if we didn't set AutoAddPolicy we will receive error message and this message is include "Unknown Server"
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
#Metasploit ip address maybe your ip addresses different check it
ip = '192.168.1.101'
#ssh port
port = 22
#Create try except for wrong username or password
try:
#we need to Metasploit default username and password
username = input("Username: ")
password = input("Password: ")
#connect to metasploit and we add ip, port, username, password
ssh.connect(ip, port = port, username = username, password = password)
#we call function
execute_command()
#if we have error this method catch and print error
except Exception as e:
print("incorrect password or username and Error is: ",e)
#Server end
finally:
ssh.close()