示例#1
0
def add_file_to_quarantine():
    global li
    global terminations

    file = askopenfilename()
    file = file.replace("/", "\\")
    quarantaene.encode_base64(file, file_to_quarantine)
    text_box.insert(END, "[ + ] Moved to quarantine:\n" + file + "\n",
                    "positive")
    text_box.tag_config("positive", foreground="green")
    text_box.see(END)
    text_box.update()
    li.update()

    k = 0
    while True:
        tmp = len(li.get(k))
        if tmp == 0:
            break
        else:
            li.delete(0, tmp)
            k += 1
    li.update()

    terminations = glob.glob(quarantine_folder)
    for i in terminations:
        li.insert(END, i)
        li.update()
示例#2
0
def scan():
    global text_box

    match = False
    file = askopenfilename()
    start = time.time()
    text_box.insert(END, "[ * ] Scanning " + file + "\n")
    text_box.see(END)
    text_box.update()
    try:
        f = open(file, "rb")
        content = f.read()
        f.close()
        content = create_md5(content)
        text_box.insert(END, "MD5-Hash: " + content.decode("utf-8") + "\n")
        text_box.see(END)
        text_box.update()
    except MemoryError:
        text_box.insert(
            END, "[ - ] Unable to create MD5-Hash:\n----->MemoryError!\n",
            'negative')
        text_box.insert(END, "[ ! ] Only select files under 1 GB\n",
                        "negative")
        text_box.tag_config('negative', foreground="red")
        text_box.see(END)
        text_box.update()
        return None
    except Exception as e:
        text_box.insert(
            END,
            "[ ! ] Unable to handle problem\n[ ! ] Try again/file might be corrupted\n",
            "negative")
        text_box.tag_config('negative', foreground="red")
        text_box.see(END)
        text_box.update()
        return None

    signatures = open(large_signatures, "rb")
    #runtime of a scan varies from system to system(time on the systems tested: 1s <= t <= 20s)
    try:
        if content in signatures.read():  #fastest solution
            signatures.close()
            match = True
        else:
            match = False
            signatures.close()
    except MemoryError:
        try:
            signatures.close()
            signatures = open(large_signatures, "rb")
            if content in signatures.readlines(
            ):  #again fast, but around 4 times slower than the fastest
                f.close()
                match = True
            else:
                signatures.close()
                match = False
        except MemoryError:
            signatures.close()
            signatures = open(large_signatures, "rb")
            while True:  #slowest solution, but can read files sized over 2 GB
                tmp = signatures.readline()
                if tmp == b"":
                    signatures.close()
                    break
                if tmp == content:
                    match = True
                    signatures.close()
    except:
        text_box.insert(
            END, "[ - ] Something bad happened while performing the task\n",
            "negative")
        text_box.tag_config("negative", foreground="red")
        text_box.see(END)
        text_box.update()
        return None

    text_box.insert(
        END, "[ * ] Scan duration: {0}\n".format(round(time.time() - start,
                                                       2)))
    text_box.see(END)
    text_box.update()
    if match:
        quarantaene.encode_base64(file, file_to_quarantine)
        text_box.insert(
            END,
            "[ ! ] Threat found: {0}\n[ ! ] File was moved into quarantine",
            "important")
        text_box.tag_config("important", foreground="red")
        text_box.see(END)
        text_box.update()
    if not match:
        text_box.insert(END, "[ + ] No threat was found\n", "positive")
        text_box.tag_config("positive", foreground="green")
        text_box.see(END)
        text_box.update()
def full_scan(part):
    global directori
    global files
    global text_box
    global e
    global full_scan
    global files_len
    global lock
    global t_time
    global counter

    if part == 1:  #Thread-1
        i = int(len(files) * 0.125)
        tmp = 0
    if part == 2:  #Thread-2
        i = int(len(files) * 0.25)
        tmp = int(len(files) * 0.125)
    if part == 3:  #Thread-3
        i = int(len(files) * 0.375)
        tmp = int(len(files) * 0.25)
    if part == 4:  #Thread-4
        i = int(len(files) * 0.5)
        tmp = int(len(files) * 0.375)
    if part == 5:  #Thread-5
        i = int(len(files) * 0.625)
        tmp = int(len(files) * 0.5)
    if part == 6:  #Thread-6
        i = int(len(files) * 0.75)
        tmp = int(len(files) * 0.625)
    if part == 7:  #Thread-7
        i = int(len(files) * 0.875)
        tmp = int(len(files) * 0.75)
    if part == 8:  #Thread-8
        i = int(len(files))
        tmp = int(len(files) * 0.875)

    if len(files) == 0:
        return ScanSystemFiles()

    text_box.tag_config('positive', foreground="green")
    text_box.see(END)
    text_box.update()
    counter = 0
    st = 0
    while i >= tmp:
        try:
            f = open(files[i], "rb")
            file_content = f.read()
            f.close()
        except:
            continue
        ret = scan_auto(files[i])
        if ret == True:
            text_box.insert(
                END, "[ ! ] Program: " + files[i] + " might be dangerous\n",
                "important")
            text_box.tag_config("important", foreground="red")
            text_box.see(END)
            text_box.update()
            quarantaene.encode_base64(files[i])
        files_len -= 1
        i -= 1
    runtime = int(time.time() - start)
    text_box.insert(
        END, "[ + ] Scan ended after\n " + str(runtime / 60) + " minutes.\n",
        "positive")
    text_box.tag_config("positive", foreground="green")
    if files_len == 0:
        full_scan["state"] = "normal"
    if len(terminations) == 0:
        text_box.insert(END, "[ +++ ] Your PC is safe" + "\n", 'important')
    else:
        text_box.insert(
            END,
            "[ !!! ] Found {0} Threats on your PC\n".format(len(terminations)))
    text_box.tag_config("important", background="red")
    text_box.see(END)
    text_box.update()