Azorult Parser
язык: python
ридми:
Simple azorult parser coded by bluemagic, to run program, on linux place script in same folder as azorult logs .zip file and run, command line from the same directory.
язык: python
ридми:
Simple azorult parser coded by bluemagic, to run program, on linux place script in same folder as azorult logs .zip file and run, command line from the same directory.
У вас должно быть более 5 сообщений для просмотра скрытого контента.
Код:
#! Python3
##Simple azorult parser coded by bluemagic, to run program, on linux place script in same folder as azorult logs .zip file
# and run, command line from the same directory.
import os, zipfile, platform, send2trash, sys, threading, Queue,time,random,string
from glob import glob
from distutils.dir_util import copy_tree
from multiprocessing import Process, Queue, Pool
#specify name of the file containing passwords. default is 'PasswordList.txt'
passwords_file = 'PasswordsList.txt'
#generate random directory where arhcives will be extracted
temp_dir = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
global azorult
#keep count of how many threads have finish running
complete = 0
#Create a class object name Log that contains all methods required to work on a single archive of logs
#downloaded from your azorult panel in .zip format
class Log(object):
#first initiate the class using archive name
def __init__(self, file_name):
if file_name is '': #abort if archive name is empty
print('Error: specify archive file name.')
return
#full path of archive = current working directory + archive_name
self.archives_path = os.path.join(os.getcwd(),file_name)
#open zipfile object while passing the archive path as argument
self.archive = zipfile.ZipFile(self.archives_path)
if os.path.exists(self.archives_path) is False:
print('Error: Logs Archive not found. Try again')
return
#get a list of log archive names
def extract_archive_list(self):
return self.archive.namelist()
#extract one log at a time, so each thread handles extraction of a single log.
#expected argument: log archive name
def extract_archive(self):
print('entered process')
extracted = []
tmp = os.path.join(os.getcwd(), temp_dir)
for log in self.archive.namelist():
self.archive.extract(log, tmp)
print('extracted: '+log)
extracted.append(log)
return extracted
#close main archive after extracting all logs
def close_main_archive(self):
self.archive.close()
#using glob() to get absolute path for all non-empty logs, return result as list
@staticmethod
def arrange_result():
_list = glob(os.path.join(os.getcwd(),temp_dir, "*", "*", ""))
return _list
#this function extracts all the content of single log archive then deletes the original archive
#it takes a single argument which is the name of the archive.
#full path of log archive = current working directory + global temp directory + log archive name
@staticmethod
def extract_archive_child(archive_name):
#full path of archive: working directory + extraction directory + archive name
log = os.path.join(os.getcwd(),temp_dir,archive_name)
# open a zipFile object
log = zipfile.ZipFile(log)
#extract all contents of log file archive
log.extractall( os.path.join(os.getcwd(),temp_dir,archive_name)[:-4])
#delete original archive file
send2trash.send2trash(os.path.join(os.getcwd(),temp_dir,archive_name))
#remove the whole folder if passwordList.txt doesn't exist
if not os.path.exists(os.path.join(os.getcwd(),temp_dir, archive_name[:-4],passwords_file)):
send2trash.send2trash(os.path.join(os.getcwd(),temp_dir,archive_name[:-4]))
# use the sort method to search for specific string of text in the logs
def sort(self, query, logs):
#if query string is empty, abort
if query == '':
print('Search query can not be empty')
return
matches = []
#search all the logs Password txt file for query string
for log_name in logs:
print(log_name)
#open Password file
try:
with open(os.path.join(log_name,passwords_file), 'r') as searchfile: #loop thru the lines, checking if each line contains the query string
for line in searchfile:
if query in line: #if query string is found and it doesn't exist in matches records already, add the path to matches records
path = os.path.join(log_name,passwords_file)
if path not in matches:
matches.append(log_name)
except:
pass
return matches #return matches
def echo(self,val):
print val
#run routine that determines how the program runs
def run(self):
logs_list = self.extract_archive_list()
self.extract_archive()
#specify number of threads to use
numThreads = 10
#total number of logs in record
numLogs = len(logs_list)
print('Total Records: '+str(numLogs))
#pool = Pool(10)
#pool.apply(self.echo, (logs_list[0],))
ok = raw_input('works?')
return logs_list
#thread class to handle extraction of big archive
class azo_extractThread(threading.Thread):
global azorult
ok = raw_input('thread started')
#def __init to define expected parameters
#which are
#start: index number of starting log
#end: index number of ending log
#logs: list containing names of logs names
def __init__(self, logs, name):
global start_
threading.Thread.__init__(self)
self.name = str(name)
self.logs = logs
def run(self):
print('')
print(len(self.logs))
global complete
#for log in self.logs:
# azorult.extract_archive(log)
for log in self.logs:
try:
azorult.extract_archive_child(log)
print('('+self.name+')extracting: '+log+'\n')
except:
print('extraction failed: '+log)
complete += 1
if __name__ == '__main__':
print(':::::::::::: Azorult log Parser ::::::::::::\n\n')
print('Place script in the same directory as this file and input name below')
file_name = raw_input('File name: ')
azorult = Log(file_name)
logs_list = azorult.run()
#get a list of logs archives
print(logs_list)
#logs per thread
numLogs = len(logs_list)
numThreads = 10
LogsPerThread = (numLogs/numThreads)
ok = raw_input('ok?')
azo_threads = []
count = 0
for log_pos in range(0,LogsPerThread*numThreads, LogsPerThread):
azo_thread = azo_extractThread(logs_list[log_pos:log_pos+LogsPerThread], "Thread-"+str(count))
print('################################### starting '+str(azo_thread))
azo_threads.append(azo_thread)
azo_thread.start()
count += 1
omited = numLogs - LogsPerThread*numThreads
processed = LogsPerThread*numThreads
while complete is not numThreads:
pass
#process remainder archives using final_thread
final_thread = azo_extractThread(logs_list[LogsPerThread*numThreads:numLogs], "Thread-"+str(count))
print('################################### starting '+str(final_thread))
azo_threads.append(final_thread)
final_thread.start()
for azo_thread in azo_threads:
azo_thread.join()
results = azorult.arrange_result()
print(results)
while True:
find = raw_input('Input your search: ')
res = azorult.sort(find,results)
if len(res)>0:
i = 1
for r in res:
copy_tree(r, os.path.join(os.getcwd(),'results('+find+')', str(i)))
i = i+1