mirror of
https://github.com/dbarzin/pandora-box.git
synced 2025-07-28 09:49:41 +02:00
work in progress
This commit is contained in:
parent
d18a51dbe3
commit
49e00d9875
2 changed files with 34 additions and 33 deletions
|
@ -3,15 +3,12 @@
|
||||||
; Set USB_AUTO_MOUNT to true is if the OS mount automaticaly mount USB keys
|
; Set USB_AUTO_MOUNT to true is if the OS mount automaticaly mount USB keys
|
||||||
USB_AUTO_MOUNT = True
|
USB_AUTO_MOUNT = True
|
||||||
|
|
||||||
; Set NO_SCAN to true to skip the scan process
|
|
||||||
NO_SCAN = True
|
|
||||||
|
|
||||||
; Set PANDORA_ROOT_URL to the URL of the Pandora server
|
; Set PANDORA_ROOT_URL to the URL of the Pandora server
|
||||||
; the default value is "http://127.0.0.1:6100"
|
; the default value is "http://127.0.0.1:6100"
|
||||||
PANDORA_ROOT_URL = "http://127.0.0.1:6100"
|
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 = False
|
||||||
|
|
||||||
; Set to true to copy infected files to the quarantine folder
|
; Set to true to copy infected files to the quarantine folder
|
||||||
; in the USB scanning station
|
; in the USB scanning station
|
||||||
|
|
|
@ -20,7 +20,6 @@ from datetime import datetime
|
||||||
# Config variables
|
# Config variables
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
|
|
||||||
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
|
||||||
|
@ -28,14 +27,13 @@ QUARANTINE = False
|
||||||
|
|
||||||
""" read configuration file """
|
""" read configuration file """
|
||||||
def config():
|
def config():
|
||||||
global NO_SCAN, USB_AUTO_MOUNT, PANDORA_ROOT_URL
|
global USB_AUTO_MOUNT, PANDORA_ROOT_URL
|
||||||
global FAKE_SCAN, QUARANTINE, QUARANTINE_FOLDER
|
global FAKE_SCAN, QUARANTINE, QUARANTINE_FOLDER
|
||||||
# intantiate a ConfirParser
|
# intantiate a ConfirParser
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
# read the config file
|
# read the config file
|
||||||
config.read('pandorabox.ini')
|
config.read('pandorabox.ini')
|
||||||
# set values
|
# set values
|
||||||
NO_SCAN=config['DEFAULT']['NO_SCAN'].lower()=="true"
|
|
||||||
FAKE_SCAN=config['DEFAULT']['FAKE_SCAN'].lower()=="true"
|
FAKE_SCAN=config['DEFAULT']['FAKE_SCAN'].lower()=="true"
|
||||||
USB_AUTO_MOUNT=config['DEFAULT']['USB_AUTO_MOUNT'].lower()=="true"
|
USB_AUTO_MOUNT=config['DEFAULT']['USB_AUTO_MOUNT'].lower()=="true"
|
||||||
PANDORA_ROOT_URL=config['DEFAULT']['PANDORA_ROOT_URL']
|
PANDORA_ROOT_URL=config['DEFAULT']['PANDORA_ROOT_URL']
|
||||||
|
@ -158,11 +156,11 @@ def log(str):
|
||||||
global log_win, logging
|
global log_win, logging
|
||||||
logging.info(str)
|
logging.info(str)
|
||||||
logs.append(str)
|
logs.append(str)
|
||||||
if len(logs)>(curses.LINES-20):
|
if len(logs)>(curses.LINES-22):
|
||||||
logs.pop(0)
|
logs.pop(0)
|
||||||
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-22,len(logs))):
|
||||||
log_win.addstr(i+1,1,logs[i][:curses.COLS-2],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()
|
||||||
|
|
||||||
|
@ -286,30 +284,33 @@ def device_loop():
|
||||||
# Mount device
|
# Mount device
|
||||||
mount_point = mount_device(device)
|
mount_point = mount_device(device)
|
||||||
if mount_point == None:
|
if mount_point == None:
|
||||||
# no partition (?)
|
# no partition
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
statvfs=os.statvfs(mount_point)
|
statvfs=os.statvfs(mount_point)
|
||||||
except Exception as e :
|
except Exception as e :
|
||||||
log("Unexpected error: %s" % e)
|
log("Unexpected error: %s" % e)
|
||||||
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))
|
||||||
print_used(human_readable_size(statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree)))
|
print_used(human_readable_size(statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree)))
|
||||||
|
|
||||||
|
# Scan files
|
||||||
log("Scan started...........")
|
log("Scan started...........")
|
||||||
# fake scan
|
infected_files = scan(mount_point, statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree))
|
||||||
if False:
|
|
||||||
loading = 0
|
# Clean files
|
||||||
while loading < 100:
|
if len(infected_files) > 0:
|
||||||
loading += 1
|
log('%d infected files found !' % len(infected_files))
|
||||||
time.sleep(0.03)
|
log('PRESS KEY TO CLEAN')
|
||||||
update_bar(loading)
|
screen.getch()
|
||||||
else:
|
# Remove infected files
|
||||||
res = scan(mount_point, statvfs.f_frsize * (statvfs.f_blocks - statvfs.f_bfree))
|
for file in infected_files:
|
||||||
if res:
|
try :
|
||||||
log("Scan done.")
|
os.remove(file)
|
||||||
else:
|
log('%s removed' % file)
|
||||||
log("Scan failed !")
|
except Exception as e :
|
||||||
|
log("Unexpected error: %s" % str(e))
|
||||||
|
log("Clean done.")
|
||||||
|
|
||||||
if device.action == "remove":
|
if device.action == "remove":
|
||||||
log("Device removed")
|
log("Device removed")
|
||||||
|
@ -325,8 +326,7 @@ def device_loop():
|
||||||
umount_device()
|
umount_device()
|
||||||
update_bar(0)
|
update_bar(0)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log("Unexpected error: %s" % e )
|
log("Unexpected error: %s" % str(e) )
|
||||||
logging.exception("An exception was thrown!")
|
|
||||||
finally:
|
finally:
|
||||||
log("Done.")
|
log("Done.")
|
||||||
|
|
||||||
|
@ -368,6 +368,7 @@ def scan(mount_point, used):
|
||||||
for root, dirs, files in os.walk(mount_point):
|
for root, dirs, files in os.walk(mount_point):
|
||||||
for file in files:
|
for file in files:
|
||||||
try :
|
try :
|
||||||
|
status = None
|
||||||
full_path = os.path.join(root,file)
|
full_path = os.path.join(root,file)
|
||||||
file_size = os.path.getsize(full_path)
|
file_size = os.path.getsize(full_path)
|
||||||
# log("Check %s [%s]" % (file, human_readable_size(file_size)))
|
# log("Check %s [%s]" % (file, human_readable_size(file_size)))
|
||||||
|
@ -375,6 +376,7 @@ def scan(mount_point, used):
|
||||||
if FAKE_SCAN :
|
if FAKE_SCAN :
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
status = "SKIPPED"
|
status = "SKIPPED"
|
||||||
|
# status = "ALERT"
|
||||||
else:
|
else:
|
||||||
if file_size > (1024*1024*1024):
|
if file_size > (1024*1024*1024):
|
||||||
status = "TOO BIG"
|
status = "TOO BIG"
|
||||||
|
@ -389,11 +391,6 @@ def scan(mount_point, used):
|
||||||
break
|
break
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
loop += 1
|
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,
|
||||||
|
@ -403,12 +400,20 @@ def scan(mount_point, used):
|
||||||
scanned += os.path.getsize(full_path)
|
scanned += os.path.getsize(full_path)
|
||||||
file_count += 1
|
file_count += 1
|
||||||
update_bar(scanned * 100 // used)
|
update_bar(scanned * 100 // used)
|
||||||
|
|
||||||
|
if status == "ALERT":
|
||||||
|
infected_files.append(full_path)
|
||||||
|
if QUARANTINE:
|
||||||
|
if not os.path.isdir(quanrantine_folder) :
|
||||||
|
os.mkdir(quanrantine_folder)
|
||||||
|
shutil.copyfile(full_path, os.path.join(quanrantine_folder,file))
|
||||||
|
|
||||||
except Exception as e :
|
except Exception as e :
|
||||||
log("Unexpected error: %s" % e)
|
log("Unexpected error: %s" % e)
|
||||||
update_bar(100)
|
update_bar(100)
|
||||||
log("Scan done in %ds, %d files scanned, %d files infected" %
|
log("Scan done in %ds, %d files scanned, %d files infected" %
|
||||||
((time.time() - scan_start_time),file_count,len(infected_files)))
|
((time.time() - scan_start_time),file_count,len(infected_files)))
|
||||||
return True
|
return infected_files
|
||||||
|
|
||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
|
|
||||||
|
@ -425,7 +430,6 @@ def main(stdscr):
|
||||||
except Exception as e :
|
except Exception as e :
|
||||||
end_curses()
|
end_curses()
|
||||||
print("Unexpected error: ", e)
|
print("Unexpected error: ", e)
|
||||||
logging.error("Unexpected error: ", e)
|
|
||||||
finally:
|
finally:
|
||||||
end_curses()
|
end_curses()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue