diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2e0bb3b..6d5b456 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,15 +2,15 @@ - - - - - - - - - + + + + + + + + + @@ -24,7 +24,7 @@ - + @@ -536,58 +561,76 @@ - + - - + + - + - - + + - + - - + + - + + + + + + + + + - - + + - - + + - + - - + + + + + + + + + + + + - + - - + + diff --git a/__pycache__/module.cpython-34.pyc b/__pycache__/module.cpython-34.pyc index 637b63c..2564529 100644 --- a/__pycache__/module.cpython-34.pyc +++ b/__pycache__/module.cpython-34.pyc diff --git a/__pycache__/modulevar.cpython-34.pyc b/__pycache__/modulevar.cpython-34.pyc index eab07dc..3500a72 100644 --- a/__pycache__/modulevar.cpython-34.pyc +++ b/__pycache__/modulevar.cpython-34.pyc diff --git a/__pycache__/runcmd.cpython-34.pyc b/__pycache__/runcmd.cpython-34.pyc new file mode 100644 index 0000000..488d527 --- /dev/null +++ b/__pycache__/runcmd.cpython-34.pyc diff --git a/digger.py b/digger.py index b88a818..48e399a 100644 --- a/digger.py +++ b/digger.py @@ -10,8 +10,6 @@ import subprocess as sp sys.path.append('modules') sys.path.append('vars') -vars = {} - def getModules(): choiceList = [] modules = [] @@ -22,7 +20,7 @@ def getModules(): for modname in modules: try: module = __import__(modname) - instance = module.getInstance(vars) + instance = module.getInstance() choiceList.append((instance.name,instance.description,False)) del instance del module @@ -34,13 +32,13 @@ def getModules(): return choiceList def prepareModule(moduleName): - module = __import__(moduleName).getInstance(vars) + module = __import__(moduleName).getInstance() module.getVars() return module locale.setlocale(locale.LC_ALL, '') d = Dialog(dialog="dialog",autowidgetsize=True) -d.set_background_title("My little program") +d.set_background_title("Gravedigger") moduleList = getModules() code, tags = d.checklist("Select modules to execute", @@ -48,18 +46,24 @@ code, tags = d.checklist("Select modules to execute", title="Module selection") if code == d.OK: runlist = [] - if "All" in tags: - for module in moduleList: - runlist.append(prepareModule(module)) - else: - for tag in tags: - runlist.append(prepareModule(tag)) + try: + if "All" in tags: + for module in moduleList: + runlist.append(prepareModule(module)) + else: + for tag in tags: + runlist.append(prepareModule(tag)) + + sp.call('clear', shell=True) + + for module in runlist: + print("Running " + module.name + "...") + try: + module.run() + except Exception as e: + print("Exception raised while running " + module.name + ": " + str(e)) + + except Exception as e: + print("Exception raised while preparing module: " + str(e)) - sp.call('clear', shell=True) - for module in runlist: - print("Running " + module.name + "...") - try: - module.run() - except Exception as e: - print("Exception raised while running " + module.name + ": " + str(e)) diff --git a/module.py b/module.py index b1737ef..de3d073 100644 --- a/module.py +++ b/module.py @@ -3,19 +3,17 @@ from abc import ABCMeta, abstractmethod class Module(object): __metaclass__ = ABCMeta - sharedVars = {} name = "" description = "" - vars = [] + vars = {} + requiredVars = [] @abstractmethod def run(self): pass def getVars(self): - for var in self.vars: - if var in self.sharedVars: - continue - modvar = __import__(var).getInstance() + for var in self.requiredVars: + modvar = __import__(var).getInstance(self.name) modvar.query() - self.sharedVars[modvar.name] = modvar \ No newline at end of file + self.vars[modvar.name] = modvar \ No newline at end of file diff --git a/modules/__pycache__/mft.cpython-34.pyc b/modules/__pycache__/mft.cpython-34.pyc index d8f8de0..4ebbb03 100644 --- a/modules/__pycache__/mft.cpython-34.pyc +++ b/modules/__pycache__/mft.cpython-34.pyc diff --git a/modules/mft.py b/modules/mft.py index db8e6a0..dd42588 100644 --- a/modules/mft.py +++ b/modules/mft.py @@ -1,16 +1,17 @@ from module import Module -def getInstance(vars): - return MFTModule(vars) +def getInstance(): + return MFTModule() class MFTModule(Module): - def __init__(self,vars): - self.sharedVars = vars + def __init__(self): self.name = "mft" self.description = "Extracts NTFS MFT" - self.vars = ["ntfsvol"] + self.requiredVars = ["ntfsvol"] + self.vars = {} def run(self): - pass + for x in self.vars: + print(x + ": " + str(self.vars[x].value)) diff --git a/modulevar.py b/modulevar.py index 2b30870..d63f5d7 100644 --- a/modulevar.py +++ b/modulevar.py @@ -4,6 +4,7 @@ class Modulevar(object): __metaclass__ = ABCMeta name = "" + parentModule = "" description = "" value = None diff --git a/runcmd.py b/runcmd.py new file mode 100644 index 0000000..652eb31 --- /dev/null +++ b/runcmd.py @@ -0,0 +1,5 @@ +import subprocess + +def runProcess(cmd): + out = subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE) + return out.communicate()[0], out.returncode \ No newline at end of file diff --git a/scripts/digger.sh b/scripts/digger.sh old mode 100644 new mode 100755 index 7ee8ca9..1795cf0 --- a/scripts/digger.sh +++ b/scripts/digger.sh @@ -5,4 +5,6 @@ GD_PATH="/opt/gravedigger" #set tty /bin/stty -echoprt -/usr/bin/env python3 $GD_PATH/digger.py \ No newline at end of file +pushd $GD_PATH > /dev/null +/usr/bin/env python3 digger.py +popd \ No newline at end of file diff --git a/scripts/list_ntfs.sh b/scripts/list_ntfs.sh new file mode 100755 index 0000000..504aa8e --- /dev/null +++ b/scripts/list_ntfs.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Outputs, separated by newlines, the list of NTFS volumes present on this computer + +for disk in $(cat /proc/partitions | awk -F " " '{print $NF}' | tail -n+3); do + HEADER=$(dd if="/dev/$disk" bs=1 skip=3 count=4 2> /dev/null) + if [[ $HEADER == "NTFS" ]]; then + echo $disk + fi +done \ No newline at end of file diff --git a/vars/__pycache__/ntfsvol.cpython-34.pyc b/vars/__pycache__/ntfsvol.cpython-34.pyc index 977e840..e54105b 100644 --- a/vars/__pycache__/ntfsvol.cpython-34.pyc +++ b/vars/__pycache__/ntfsvol.cpython-34.pyc diff --git a/vars/ntfsvol.py b/vars/ntfsvol.py index 0dda38f..e0715c3 100644 --- a/vars/ntfsvol.py +++ b/vars/ntfsvol.py @@ -1,14 +1,35 @@ from modulevar import Modulevar +from dialog import Dialog +from runcmd import runProcess -def getInstance(): - return NTFSVol() +def getInstance(modname): + return NTFSVol(modname) class NTFSVol(Modulevar): - def __init__(self): + def __init__(self,modname): self.name = "ntfsvol" + self.parentModule = modname self.description = "NTFS Volume" self.value = None + def getNTFSVolumes(self): + result = runProcess("scripts/list_ntfs.sh") + volumes = result[0].decode("utf-8").splitlines() + print(volumes) + choices = [] + for vol in volumes: + choices.append((vol,"",False)) + return choices + def query(self): - print("WHAT IS VAR " + self.name) \ No newline at end of file + d = Dialog(dialog="dialog", autowidgetsize=True) + d.set_background_title("[" + self.parentModule + "] Setting variable: ntfsvol") + volumeList = self.getNTFSVolumes() + code, vols = d.checklist("Select NTFS volumes to extract the MFT", + choices=volumeList, + title="Module selection") + if code == d.OK: + self.value = vols + else: + raise Exception("[" + self.name + "] Operation Cancelled") \ No newline at end of file