Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'Zakkq'
- # Firestorm - Fight fire with fire
- import binascii
- import sys
- import os
- import time
- if sys.version_info < (3,0):
- import Tkinter as tkinter
- import tkMessageBox as mbox
- else:
- import tkinter
- import tkinter.messagebox as mbox
- mfs = raw_input('Max file size you want to scan? in Mega Bytes eg "5": ')
- sd = raw_input('Starting Directory, Standard is "C:\\": ')
- c = 0
- string = []
- # Getting the HEX Signatues
- with open("signatures.txt", 'rb') as s:
- content = s.read()
- # Formatting the HEX Signatues
- contentbuffer = content.rstrip().split('\n')
- i = 0
- while i < len(contentbuffer):
- string.append(contentbuffer[i].split('=', 1)[1])
- i = i + 1
- # Setting starting Dir
- if sd == "":
- directories = ["C:\\"]
- else:
- directories =[sd]
- # Choosing files not to scan
- safeFiles = ["signatures.txt"]
- while True:
- if len(directories) == 0:
- window = tkinter.Tk()
- window.wm_withdraw()
- mbox.showinfo('Virus Detector','DONE ' + str(c) + " Scanned Objects -" + " " + str(filename))
- break
- folder = directories[0]
- del directories[0]
- print folder
- try:
- filename = os.listdir(folder)
- except Exception as e:
- print "Error reading dir:", folder
- continue
- i = 0
- filename2 = []
- if len(directories) > 1000 or len(filename) > 10000:
- print "Breaking because of too much stuff"
- break
- for cur_file in filename:
- abs_path = os.path.join(folder, cur_file)
- if os.path.isfile(abs_path):
- #print "FILE:", cur_file
- filename2.append(abs_path)
- elif os.path.isdir(abs_path):
- #print "DIR:", cur_file
- directories.append(abs_path)
- else:
- print "IGNORING:", cur_file
- filename = filename2
- i = 0
- while i < len(string):
- string[i] = " ".join(string[i][g:g+2] for g in range(0, len(string[i]), 2))
- string[i]=string[i].replace(" ",",")
- i = i + 1
- i = 0
- print str(filename) + "\n"
- try:
- for cur_file in filename:
- t0 = time.clock()
- base_name = os.path.basename(cur_file)
- #print base_name
- if os.path.getsize(cur_file) > (mfs * 1024 * 1024):
- print "Large file ignored", cur_file
- continue
- try:
- if cur_file in safeFiles:
- print "file in SafeFiles ignored:"
- continue
- else:
- with open(cur_file, 'rb') as f:
- content = f.read()
- c = c + 1
- except IOError as err:
- print "Unable to read:", cur_file
- continue
- hex = str(binascii.hexlify(content))
- formatted_hex = ','.join(hex[i:i+2] for i in range(0, len(hex), 2))
- i = 0
- while i < len(string):
- if string[i] in formatted_hex:
- window = tkinter.Tk()
- window.wm_withdraw()
- mbox.showinfo('Virus Detector','VIRUS AT ' + cur_file + " The virus signature number is " + string[i])
- else:
- i = i + 1
- pass
- a = time.clock() - t0
- astring = str(a)
- print base_name + " Has been Scanned it took: " + astring[:3] + " :seconds to scan the element"
- except Exception as e:
- exc_type, exc_obj, exc_tb = sys.exc_info()
- fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
- print(exc_type, fname, exc_tb.tb_lineno)
- print time.clock() - t0
- raw_input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement