Last active
August 27, 2019 19:51
-
-
Save tg12/e7967017a8ccf99daaf0bf74dd4f5dbe to your computer and use it in GitHub Desktop.
Fast Multi-threaded FTP Scanner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
import time | |
import threading | |
########################### | |
from multiprocessing import Process | |
import random | |
########################### | |
import dns.resolver | |
import dns.reversename | |
import ftplib | |
import ipaddress | |
thread_list = [] | |
now = datetime.now() | |
logfile = now.strftime('mylogfile_%H_%M_%d_%m_%Y.log') | |
f = open(logfile, "a") | |
f.write("#####################################################\n") | |
f.write("#####################################################\n") | |
f.write("#This is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; \n#without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n") | |
f.write("#####################################################\n") | |
f.write("#####################################################\n") | |
f.write("#Last Modified:" + str(now.strftime("%Y-%m-%d %H:%M:%S")) + "\n") | |
f.write("#####################################################\n") | |
f.write("#####################################################\n") | |
f.close() | |
def debug_info(err_str): | |
# Standard debugging function, pass it a string | |
# print("-----------------DEBUG-----------------") | |
f.write(str(time.strftime("%H:%M:%S")) + | |
":!!!DEBUG!!!:\n" + str(err_str) + "\n") | |
# print("-----------------DEBUG-----------------") | |
def worker(thread_no): | |
f = open(logfile, "a") | |
ip = ".".join(map(str, (random.randint(0, 255) | |
for _ in range(4)))) | |
try: | |
n = dns.reversename.from_address(ip) | |
reverse_PTR = str(dns.resolver.query(n, "PTR")[0]) | |
except BaseException: | |
# woops, could not resolve PTR record!! | |
f.close() | |
return | |
print("trying...." + str(reverse_PTR)) | |
#f.write("trying...." + str(reverse_PTR) + "\n") | |
files = [] | |
try: | |
try: | |
ftp = ftplib.FTP(ip, timeout=3) | |
ftp.set_pasv(False) | |
ftp.login("anonymous", "") | |
except ftplib.error_perm as error: | |
f.close() | |
return | |
files = ftp.nlst() | |
except Exception as e: | |
f.close() | |
return | |
if len(files) > 0: | |
for file in files: | |
f.write(str(file) + "\n") | |
else: | |
f.write("No files in dir") | |
f.close() | |
return | |
f.write("##################################\n") | |
f.write("##################################\n") | |
f.write("##################################\n") | |
f.close() | |
while True: | |
for thread_no in range(1): | |
# thread = threading.Thread(target=worker, args=(thread_no,)) | |
# thread_list.append(thread) | |
# thread.start() | |
########################################################## | |
p = Process(target=worker, args=(thread_no,)) | |
p.start() | |
# p.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment