-
Notifications
You must be signed in to change notification settings - Fork 4
/
metasploitable-connector.py
152 lines (60 loc) · 2.7 KB
/
metasploitable-connector.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import paramiko
from ftplib import FTP
import sys
# Replace these with your actual credentials
SSH_USERNAME = 'msfadmin' # replace with your SSH username
SSH_PASSWORD = 'msfadmin' # replace with your SSH password
FTP_USERNAME = 'msfadmin' # replace with your FTP username
FTP_PASSWORD = 'msfadmin' # replace with your FTP password
def ssh_connect(metasploitable_ip, port):
try:
# Create an SSH client
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Connect to the Metasploitable machine
client.connect(metasploitable_ip, username=SSH_USERNAME, password=SSH_PASSWORD, port=port)
print(f"Successfully connected to {metasploitable_ip} via SSH on port {port}.")
# Open an interactive shell
shell = client.invoke_shell()
while True:
command = input("Enter command to execute on Metasploitable (or 'exit' to quit): ")
if command.lower() == 'exit':
break
shell.send(command + '\n')
while shell.recv_ready():
output = shell.recv(1024).decode('utf-8')
print(output)
client.close()
except Exception as e:
print(f"SSH Connection failed: {e}")
def ftp_connect(metasploitable_ip, port):
try:
# Create an FTP client
ftp = FTP()
ftp.connect(metasploitable_ip, port)
ftp.login(user=FTP_USERNAME, passwd=FTP_PASSWORD)
print(f"Successfully connected to {metasploitable_ip} via FTP on port {port}.")
# List files in the current directory
print("Files in the current directory:")
ftp.retrlines('LIST')
# Example: Downloading a file
# ftp.retrbinary('RETR example.txt', open('example.txt', 'wb').write)
ftp.quit()
except Exception as e:
print(f"FTP Connection failed: {e}")
def main():
metasploitable_ip = input("Enter the IP address of the Metasploitable machine: ")
port = int(input("Enter the port number (default for SSH is 22, for FTP is 21): "))
print("Select connection type:")
print("1. SSH")
print("2. FTP")
choice = input("Enter your choice (1/2): ")
if choice == '1':
ssh_connect(metasploitable_ip, port)
elif choice == '2':
ftp_connect(metasploitable_ip, port)
else:
print("Invalid choice.")
if __name__ == "__main__":
main()
#Naveen_Wijesinghe