diff --git a/src/compile_custom_magic.py b/src/compile_custom_magic.py new file mode 100755 index 000000000..3fb5fa7e7 --- /dev/null +++ b/src/compile_custom_magic.py @@ -0,0 +1,38 @@ +#! /usr/bin/env python3 +''' + Firmware Analysis and Comparison Tool (FACT) + Copyright (C) 2015-2019 Fraunhofer FKIE + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +''' +from pathlib import Path + +from common_helper_process import execute_shell_command_get_return_code +from helperFunctions.install import OperateInDirectory + +MIME_DIR = Path(Path(__file__).parent, 'mime') + + +def main(): + with OperateInDirectory(str(MIME_DIR)): + cat_output, cat_code = execute_shell_command_get_return_code('cat custom_* > custommime') + file_output, file_code = execute_shell_command_get_return_code('file -C -m custommime') + mv_output, mv_code = execute_shell_command_get_return_code('mv -f custommime.mgc ../bin/') + if any(code != 0 for code in (cat_code, file_code, mv_code)): + exit('Failed to properly compile magic file\n{}'.format('\n'.join((cat_output, file_output, mv_output)))) + Path('custommime').unlink() + + +if __name__ == '__main__': + exit(main()) diff --git a/src/install/backend.py b/src/install/backend.py index 163820eab..c3f105d77 100644 --- a/src/install/backend.py +++ b/src/install/backend.py @@ -4,10 +4,13 @@ from pathlib import Path from common_helper_process import execute_shell_command_get_return_code - from compile_yara_signatures import main as compile_signatures -from helperFunctions.install import apt_remove_packages, apt_install_packages, InstallationError, pip3_install_packages, \ - install_github_project, pip2_install_packages, pip2_remove_packages, check_string_in_command, OperateInDirectory, load_main_config +from helperFunctions.install import ( + InstallationError, OperateInDirectory, apt_install_packages, + apt_remove_packages, check_string_in_command, install_github_project, + load_main_config, pip2_install_packages, pip2_remove_packages, + pip3_install_packages +) def main(distribution): @@ -39,13 +42,9 @@ def main(distribution): _install_plugins() # compile custom magic file - with OperateInDirectory('../mime'): - cat_output, cat_code = execute_shell_command_get_return_code('cat custom_* > custommime') - file_output, file_code = execute_shell_command_get_return_code('file -C -m custommime') - mv_output, mv_code = execute_shell_command_get_return_code('mv -f custommime.mgc ../bin/') - if any(code != 0 for code in (cat_code, file_code, mv_code)): - raise InstallationError('Failed to properly compile magic file\n{}'.format('\n'.join((cat_output, file_output, mv_output)))) - Path('custommime').unlink() + mime_output, mime_rc = execute_shell_command_get_return_code('../compile_custom_magic.py') + if mime_rc != 0: + raise InstallationError(mime_output) # configure environment _edit_sudoers() @@ -79,7 +78,9 @@ def _edit_environment(): def _edit_sudoers(): logging.info('add rules to sudo...') username = os.environ['USER'] - sudoers_content = '\n'.join(('{}\tALL=NOPASSWD: {}'.format(username, command) for command in ('/bin/mount', '/bin/umount', '/bin/mknod', '/usr/local/bin/sasquatch', '/bin/rm', '/bin/cp', '/bin/dd', '/bin/chown'))) + sudoers_content = '\n'.join(('{}\tALL=NOPASSWD: {}'.format(username, command) for command in ( + '/bin/mount', '/bin/umount', '/bin/mknod', '/usr/local/bin/sasquatch', '/bin/rm', '/bin/cp', '/bin/dd', '/bin/chown' + ))) Path('/tmp/fact_overrides').write_text('{}\n'.format(sudoers_content)) chown_output, chown_code = execute_shell_command_get_return_code('sudo chown root:root /tmp/fact_overrides') mv_output, mv_code = execute_shell_command_get_return_code('sudo mv /tmp/fact_overrides /etc/sudoers.d/fact_overrides')