mirror of
https://github.com/dbarzin/pandora-box.git
synced 2025-07-19 13:29:42 +02:00
work in progress
This commit is contained in:
parent
bf7a29d173
commit
d18a51dbe3
2 changed files with 27 additions and 17 deletions
|
@ -13,3 +13,9 @@ PANDORA_ROOT_URL = "http://127.0.0.1:6100"
|
||||||
; Set FAKE_SCAN to true to fake the scan process
|
; Set FAKE_SCAN to true to fake the scan process
|
||||||
FAKE_SCAN = True
|
FAKE_SCAN = True
|
||||||
|
|
||||||
|
; Set to true to copy infected files to the quarantine folder
|
||||||
|
; in the USB scanning station
|
||||||
|
QUARANTINE = True
|
||||||
|
|
||||||
|
; Set quarantine folder
|
||||||
|
QUARANTINE_FOLDER = /tmp
|
||||||
|
|
|
@ -13,6 +13,8 @@ import os
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
import configparser
|
import configparser
|
||||||
|
import shutil
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
# Config variables
|
# Config variables
|
||||||
|
@ -22,7 +24,7 @@ NO_SCAN = True
|
||||||
USB_AUTO_MOUNT = False
|
USB_AUTO_MOUNT = False
|
||||||
PANDORA_ROOT_URL = "http://127.0.0.1:6100"
|
PANDORA_ROOT_URL = "http://127.0.0.1:6100"
|
||||||
FAKE_SCAN = False
|
FAKE_SCAN = False
|
||||||
QUARANTINE =
|
QUARANTINE = False
|
||||||
|
|
||||||
""" read configuration file """
|
""" read configuration file """
|
||||||
def config():
|
def config():
|
||||||
|
@ -141,8 +143,7 @@ def update_bar(progress):
|
||||||
progress_win.refresh()
|
progress_win.refresh()
|
||||||
|
|
||||||
def init_log():
|
def init_log():
|
||||||
global log_win
|
global log_win, logging
|
||||||
global logging
|
|
||||||
log_win = curses.newwin(curses.LINES-20, curses.COLS, 20, 0)
|
log_win = curses.newwin(curses.LINES-20, curses.COLS, 20, 0)
|
||||||
log_win.border(0)
|
log_win.border(0)
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
|
@ -154,8 +155,7 @@ def init_log():
|
||||||
|
|
||||||
logs = []
|
logs = []
|
||||||
def log(str):
|
def log(str):
|
||||||
global log_win
|
global log_win, logging
|
||||||
global logging
|
|
||||||
logging.info(str)
|
logging.info(str)
|
||||||
logs.append(str)
|
logs.append(str)
|
||||||
if len(logs)>(curses.LINES-20):
|
if len(logs)>(curses.LINES-20):
|
||||||
|
@ -163,7 +163,7 @@ def log(str):
|
||||||
log_win.clear()
|
log_win.clear()
|
||||||
log_win.border(0)
|
log_win.border(0)
|
||||||
for i in range(min(curses.LINES-20,len(logs))):
|
for i in range(min(curses.LINES-20,len(logs))):
|
||||||
log_win.addstr(i+1,1,"%-80s"%logs[i],curses.color_pair(3))
|
log_win.addstr(i+1,1,logs[i][:curses.COLS-2],curses.color_pair(3))
|
||||||
log_win.refresh()
|
log_win.refresh()
|
||||||
|
|
||||||
"""Splash screen"""
|
"""Splash screen"""
|
||||||
|
@ -291,7 +291,7 @@ def device_loop():
|
||||||
try:
|
try:
|
||||||
statvfs=os.statvfs(mount_point)
|
statvfs=os.statvfs(mount_point)
|
||||||
except Exception as e :
|
except Exception as e :
|
||||||
log("Unexpected error1: %s" % e)
|
log("Unexpected error: %s" % e)
|
||||||
logging.exception("An exception was thrown!")
|
logging.exception("An exception was thrown!")
|
||||||
continue
|
continue
|
||||||
print_size(human_readable_size(statvfs.f_frsize * statvfs.f_blocks))
|
print_size(human_readable_size(statvfs.f_frsize * statvfs.f_blocks))
|
||||||
|
@ -325,7 +325,7 @@ def device_loop():
|
||||||
umount_device()
|
umount_device()
|
||||||
update_bar(0)
|
update_bar(0)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log("Unexpected error2: %s" % e )
|
log("Unexpected error: %s" % e )
|
||||||
logging.exception("An exception was thrown!")
|
logging.exception("An exception was thrown!")
|
||||||
finally:
|
finally:
|
||||||
log("Done.")
|
log("Done.")
|
||||||
|
@ -361,6 +361,8 @@ def scan(mount_point, used):
|
||||||
scanned = 0
|
scanned = 0
|
||||||
file_count = 0
|
file_count = 0
|
||||||
scan_start_time = time.time()
|
scan_start_time = time.time()
|
||||||
|
if QUARANTINE:
|
||||||
|
quanrantine_folder = os.path.join(QUARANTINE_FOLDER,datetime.now().strftime("%y%m%d-%H%M"))
|
||||||
if not FAKE_SCAN:
|
if not FAKE_SCAN:
|
||||||
pandora = pypandora.PyPandora(root_url=PANDORA_ROOT_URL)
|
pandora = pypandora.PyPandora(root_url=PANDORA_ROOT_URL)
|
||||||
for root, dirs, files in os.walk(mount_point):
|
for root, dirs, files in os.walk(mount_point):
|
||||||
|
@ -379,12 +381,19 @@ def scan(mount_point, used):
|
||||||
else:
|
else:
|
||||||
res = pandora.submit_from_disk(full_path)
|
res = pandora.submit_from_disk(full_path)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
while True:
|
loop = 0
|
||||||
|
while True and (loop < 60):
|
||||||
res = pandora.task_status(res["taskId"])
|
res = pandora.task_status(res["taskId"])
|
||||||
status = res["status"]
|
status = res["status"]
|
||||||
if status != "WAITING":
|
if status != "WAITING":
|
||||||
break
|
break
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
loop += 1
|
||||||
|
if status == "ALERT":
|
||||||
|
infected_files.append(full_path)
|
||||||
|
if QUARANTINE:
|
||||||
|
os.mkdir(quanrantine_folder)
|
||||||
|
shutil.copyfile(full_path, quanrantine_folder)
|
||||||
file_scan_end_time = time.time()
|
file_scan_end_time = time.time()
|
||||||
log("Scan %s [%s] -> %s (%ds)" % (
|
log("Scan %s [%s] -> %s (%ds)" % (
|
||||||
file,
|
file,
|
||||||
|
@ -395,17 +404,12 @@ def scan(mount_point, used):
|
||||||
file_count += 1
|
file_count += 1
|
||||||
update_bar(scanned * 100 // used)
|
update_bar(scanned * 100 // used)
|
||||||
except Exception as e :
|
except Exception as e :
|
||||||
log("Scan %s [%s] -> %s (%ds)" % (
|
|
||||||
file,
|
|
||||||
human_readable_size(file_size),
|
|
||||||
"ERROR", -1))
|
|
||||||
log("Unexpected error: %s" % e)
|
log("Unexpected error: %s" % e)
|
||||||
update_bar(100)
|
update_bar(100)
|
||||||
log("Scan done in %ds" % (time.time() - scan_start_time))
|
log("Scan done in %ds, %d files scanned, %d files infected" %
|
||||||
log("%d files scanned" % file_count)
|
((time.time() - scan_start_time),file_count,len(infected_files)))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue