Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kconfig integration #34

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "tools/checksec.sh"]
path = tools/checksec
url = https://github.com/slimm609/checksec.sh.git
[submodule "tools/kconfig-hardened-check"]
path = tools/kconfig-hardened-check
url = https://github.com/a13xp0p0v/kconfig-hardened-check.git
9 changes: 5 additions & 4 deletions hooks/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def guestfs_instance(self):
def guest_local_file(gfs, remote_file):
with NamedTemporaryFile() as temp:
gfs.download(remote_file, temp.name)
yield temp.name
yield remote_file, temp.name


class FilesystemHook(Hook):
Expand Down Expand Up @@ -147,8 +147,9 @@ def walk_capture(self, node):
self.context.trigger('filesystem_new_inode', inode=inode)
# download and execute trigger on local file
if InodeType(inode.inode_type) == InodeType.REG:
with guest_local_file(self.gfs, str(node)) as local_file:
self.context.trigger('filesystem_new_file', filepath=local_file, inode=inode)
with guest_local_file(self.gfs, str(node)) as (remote_file, local_file):
self.context.trigger('filesystem_new_file', guest_filepath=remote_file, local_filepath=local_file,
inode=inode)
# walk
if self.gfs.is_dir(str(node)):
entries = self.list_entries(node)
Expand All @@ -162,7 +163,7 @@ def walk_capture(self, node):
return inode

def process_new_file(self, event):
filepath = event.filepath
filepath = event.local_filepath
inode = event.inode
# determine MIME type
mime_type = subprocess.check_output(['file', '-bi', filepath]).decode().rstrip()
Expand Down
6 changes: 6 additions & 0 deletions hooks/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ChecksecFile:
class SecurityHook(Hook):

CHECKSEC_BIN = Path(__file__).parent.parent/"tools"/"checksec"/"checksec"
KCONFIG_BIN = Path(__file__).parent.parent/"tools"/"kconfig-hardened-check"/"kconfig-hardened-check.py"

def __init__(self, parameters):
super().__init__(parameters)
Expand All @@ -34,7 +35,12 @@ def __init__(self, parameters):
raise RuntimeError('Cannot find checksec, did you forget to init the submodule ?')
self.checksec = str(self.CHECKSEC_BIN)

if not self.KCONFIG_BIN.exists():
raise RuntimeError('Cannot find kconfig-hardened-check, did you forget to init the submodule ?')
self.kconfig = str(self.KCONFIG_BIN)

self.context.subscribe('filesystem_new_file_mime', self.check_file)
self.context.subscribe('filesystem_new_file', self.kconfig_check)

def check_file(self, event):
filepath = event.filepath
Expand Down
1 change: 1 addition & 0 deletions tools/kconfig-hardened-check
Submodule kconfig-hardened-check added at 3dc3f6