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

Database migration #821

Merged
merged 302 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
302 commits
Select commit Hold shift + click to select a range
714e29a
switch DB routes to postgres
jstucke Jan 10, 2022
0cdb577
used lazy uwsgi config to fix forking auth bug
jstucke Jan 10, 2022
32ce6dd
Merge branch 'master' into postgresql
jstucke Jan 10, 2022
fd1b52f
removed unused file
jstucke Jan 10, 2022
59a2aee
switch IO routes to postgres
jstucke Jan 10, 2022
c0bceb4
switch REST routes to postgres
jstucke Jan 10, 2022
bf0b734
migrated backend to postgres
jstucke Jan 11, 2022
a74dfef
migrated plugins to postgres
jstucke Jan 11, 2022
fea97dc
fix nice list hid for FW
jstucke Jan 11, 2022
e60f2fc
delete file type fix
jstucke Jan 12, 2022
1e337ba
rest base class fix
jstucke Jan 12, 2022
c85d82d
added missing test for comparison_exists
jstucke Jan 12, 2022
bfa1a3c
delete file interface type fix
jstucke Jan 12, 2022
60b9ca1
analysis_is_up_to_date bugfix + version comparison deprecation fix
jstucke Jan 12, 2022
0f17f3c
migrated work load stats to postgres
jstucke Jan 12, 2022
db1e14d
fixed scheduler integration tests
jstucke Jan 12, 2022
a3dbc16
fixed REST integration tests
jstucke Jan 12, 2022
a739fdc
added unpacking lock manager class
jstucke Jan 13, 2022
3e59fe6
fixed unit tests except web interface
jstucke Jan 13, 2022
cc15b1b
improved dependency graph performance
jstucke Jan 14, 2022
81db5b8
web interface unit tests WIP + refactoring
jstucke Jan 14, 2022
941b730
fixed remaining web interface unit tests + refactoring
jstucke Jan 18, 2022
6bedbcc
fixed remaining unit tests + refactoring
jstucke Jan 18, 2022
f1636dd
converted test client base to class method
jstucke Jan 18, 2022
57485e7
route bugfixes
jstucke Jan 18, 2022
15fa1e2
fixed delete file integration tests
jstucke Jan 18, 2022
575f91b
refactored frontend with dependency injection to fix mocking problems…
jstucke Jan 19, 2022
b074c02
removed side effects from intercom delete file test
jstucke Jan 19, 2022
825401a
fix integration tests ... again
jstucke Jan 19, 2022
5dca5de
removed old db integration tests and replaced them with the (existing…
jstucke Jan 19, 2022
db433f2
fix plugin routes + tests
jstucke Jan 19, 2022
dcd4f50
added dedicated DB read-only, read-write and admin users
jstucke Jan 20, 2022
7daed19
live stats bugfix
jstucke Jan 20, 2022
30326b0
replace session.close with invalidate to fix problem with availabe DB…
jstucke Jan 20, 2022
e475fbf
added postgres init script
jstucke Jan 20, 2022
4738f2d
added database and table creation to postgres init script
jstucke Jan 20, 2022
2f8ad36
fixed acceptance base class
jstucke Jan 20, 2022
91e75be
fixed advanced search acceptance test
jstucke Jan 20, 2022
2e8c284
fixed binary search + acceptance test
jstucke Jan 20, 2022
962a140
fixed meta entry for browse db
jstucke Jan 21, 2022
50dab21
removed unused function
jstucke Jan 21, 2022
ada577e
fixed missing analyses search
jstucke Jan 21, 2022
47e17a3
extended search options (also mostly fixes basic search)
jstucke Jan 21, 2022
872f13e
analysis scheduler analysis retrieval bugfix
jstucke Jan 21, 2022
8679d01
stats updater bugfix
jstucke Jan 21, 2022
a496ee1
refactoring: removed internal db class from get_analysis
jstucke Jan 24, 2022
04750fe
replaced still existing mongo db interfaces with postgres ones
jstucke Jan 24, 2022
bb69f43
fixed comparison acceptance test + comparison search limit
jstucke Jan 24, 2022
fb9ce1a
fixed more acceptance tests
jstucke Jan 24, 2022
ebf3987
ensure backend process termination
jstucke Jan 24, 2022
2375d40
add nested analysis result search
jstucke Jan 24, 2022
ce008ed
fixed delete firmware timing
jstucke Jan 25, 2022
e434d8e
fixed stats click search + extended search options
jstucke Jan 25, 2022
113ae64
fixed more acceptance tests
jstucke Jan 25, 2022
203ab34
generalized firmware search
jstucke Jan 25, 2022
2fcc13c
fixed rest acceptance tests
jstucke Jan 25, 2022
4ebd7a1
fixed incomplete analysis result in case of fail
jstucke Jan 26, 2022
abf47af
fixed bytes in plugin results
jstucke Jan 26, 2022
1dc27f9
fixed plugin tests + unified config + simplified init
jstucke Jan 27, 2022
7b984dd
added postgres installation
jstucke Jan 27, 2022
fe8ea3d
postgres import bugfix
jstucke Jan 27, 2022
509a73a
postgres install fix + f-string <python3.8 compat fixes
jstucke Jan 27, 2022
be7d5af
another postgres intall fix
jstucke Jan 27, 2022
b996138
switch to psycopg2 binary package
jstucke Jan 27, 2022
193651e
added missing sha256 fields to migration script
jstucke Jan 27, 2022
2f4dbd7
fixed missing pre-selected plugins for FW update
jstucke Jan 27, 2022
4047d0b
introduced or search option + fixed quick search
jstucke Jan 28, 2022
80a5ebf
introduced substring search option
jstucke Jan 28, 2022
7447dc8
fixed file tree bug for objects with missing type analysis
jstucke Jan 28, 2022
7481a6b
added session recycling
jstucke Jan 28, 2022
38da552
fixed wrong import
jstucke Jan 31, 2022
ebc623c
Merge remote-tracking branch 'origin/master' into postgresql
jstucke Jan 31, 2022
8848fde
fixed dep graph test
jstucke Jan 31, 2022
abc9f50
replaced mongo in intercom with redis + completely removed mongo
jstucke Feb 2, 2022
854da60
fixed missing fo binary for update
jstucke Feb 2, 2022
f34a061
fixed missing file_path in redo unpacking
jstucke Feb 2, 2022
fc8a2f4
don't try to install postgres if it is installed
jstucke Feb 4, 2022
8710495
changed file_object.size column type to bigint
jstucke Feb 4, 2022
0f3fd48
replaced tqdm progress bar with rich
jstucke Feb 4, 2022
29b37b8
fixed advanced search example
jstucke Feb 4, 2022
5cd47ce
updated advanced search examples and description
jstucke Feb 4, 2022
ff5034b
Merge branch 'postgresql' into postgres-redis-intercom
jstucke Feb 4, 2022
d052eb3
Merge remote-tracking branch 'origin/database-migration' into postgresql
jstucke Feb 4, 2022
10b25c2
fixed postgres init script import error
jstucke Feb 7, 2022
39b8662
ignore sqlalchemy-induced PEP8 errors
jstucke Feb 7, 2022
1babbe5
added error logging for postgres installation
jstucke Feb 7, 2022
a548924
changed migration progress bar time to elapsed
jstucke Feb 8, 2022
9c2ce47
removed lazy import
jstucke Feb 8, 2022
cffa73c
refactored postgres initialization to use sqlalchemy instead of psql …
jstucke Feb 8, 2022
54abef3
moved postgres init script
jstucke Feb 9, 2022
226c4d1
path bugfix
jstucke Feb 9, 2022
b325aec
jenkins user bugfix
jstucke Feb 9, 2022
831cb83
jenkins user bugfix -- 2nd try
jstucke Feb 9, 2022
e15752b
ip and uri finder refactoring
jstucke Feb 9, 2022
57492bd
acceptance test base bugfix + refactoring
jstucke Feb 9, 2022
7f98cb8
file size stats Decimal bugfix
jstucke Feb 10, 2022
4459ec1
Merge branch 'postgresql' into postgres-redis-intercom
jstucke Feb 10, 2022
9c85844
test summary order bugfix
jstucke Feb 10, 2022
4e01d10
delete firmware duplicate file bugfix
jstucke Feb 10, 2022
2bb8cd0
cherry pick fixes to VFP update from redis postgres branch
jstucke Feb 10, 2022
c4749dd
file object update bugfix + removed some ToDos/FixMes
jstucke Feb 10, 2022
0559f20
postgres ppa arch bugfix
jstucke Feb 10, 2022
e8cf9eb
requested review changes + refactoring
jstucke Feb 10, 2022
e3c729e
allow postgres json column query on other types than str
jstucke Feb 11, 2022
14caada
fixed ordering of rest_get_firmware_uids
jstucke Feb 18, 2022
c84c4bf
kernel config hardening check version incompatibility bugfix
jstucke Feb 16, 2022
6c9a707
fixed error in show_analysis caused by missing root_uid
jstucke Feb 18, 2022
22a8918
refactoring
jstucke Feb 18, 2022
22bb650
Merge branch 'database-migration' into postgresql
jstucke Feb 22, 2022
c5d1726
Merge branch 'postgresql' into postgres-redis-intercom
jstucke Feb 22, 2022
a2822e4
requested changes from 2nd review + refactoring
jstucke Mar 1, 2022
a054639
Merge pull request #735 from fkie-cad/postgresql
jstucke Mar 2, 2022
ee295ba
increase test timeout
jstucke Feb 21, 2022
4cfb4f1
Merge branch 'database-migration' into postgres-redis-intercom
jstucke Mar 2, 2022
253af4e
arbitrary sized value support for redis intercom
jstucke Mar 3, 2022
15414da
added missing redis interface
jstucke Mar 3, 2022
6210033
requested review changes + refactoring
jstucke Mar 4, 2022
fc93a90
fixed tags + refactoring
jstucke Mar 4, 2022
51d52c4
added missing tag template
jstucke Mar 4, 2022
ce9e90d
fixed tests + analysis tag color fix + pylint fixes
jstucke Mar 4, 2022
03d015f
fix spacing between fw and analysis tags
jstucke Mar 4, 2022
064521d
added max connections fix to installation
jstucke Mar 4, 2022
c0bcd18
requested review changes
jstucke Apr 1, 2022
8d8a4cf
improved optional test skipping
jstucke Apr 1, 2022
3cf5359
Merge remote-tracking branch 'origin/master' into database-migration
jstucke Apr 6, 2022
297db97
added missing docker base dir creation in acceptance base class
jstucke Apr 7, 2022
d7d57dd
fix filters and multi tag search + new overlap search operator
jstucke Apr 7, 2022
b9e2d48
Merge branch 'database-migration' into postgres-redis-intercom
jstucke Apr 7, 2022
815fc16
removed common_helper_process from postgres installation
jstucke Apr 8, 2022
007cb26
Merge pull request #745 from fkie-cad/postgres-redis-intercom
dorpvom Apr 28, 2022
548fc78
Merge branch 'master' into database-migration
jstucke Apr 28, 2022
aee8a35
added missing doc files and docs for FACT 4 upgrade
jstucke Apr 29, 2022
ebf6670
added checks for failing gracefully when FACT is not installed or upg…
jstucke Apr 29, 2022
48c4b3e
added check for psycopg2 library
jstucke Apr 29, 2022
9e9eb57
Unify config key and section names
maringuu Feb 8, 2022
fe4f3ad
fixed bug with null bytes in analysis result crashing psycopg2
jstucke May 2, 2022
4254fab
fixed comparison basked bug triggered by lazy uwsgi config
jstucke May 2, 2022
86c70bb
illegible fw analysis progress bar bugfix
jstucke May 2, 2022
230f166
Update docsrc/migration.rst
jstucke May 4, 2022
257d72f
requested review changes
jstucke May 4, 2022
4271d3e
Merge pull request #767 from fkie-cad/graceful-start-fail
dorpvom May 4, 2022
c612381
improve test stability
jstucke May 5, 2022
3fbb7d3
added new network component software signatures
jstucke May 5, 2022
e5fe6f1
improved nullbyte sanitization
jstucke May 6, 2022
5014ae5
Fix tests
maringuu May 9, 2022
fe92cbe
fixed bug with crypto material search from analysis view
jstucke May 9, 2022
820e848
test bugfix
jstucke May 9, 2022
066459f
fixed bug with rubocop linter installation in older systems + pylint …
jstucke May 9, 2022
f58e188
removed unused code + pylint fixes
jstucke May 11, 2022
77f9d5e
fix flaky test (hopefully)
jstucke May 11, 2022
9bda6c6
Merge remote-tracking branch 'origin/master' into database-migration
jstucke May 12, 2022
5eddfb8
Merge branch 'database-migration' into rename_config_keys
jstucke May 12, 2022
8f33b11
Merge pull request #768 from fkie-cad/rename_config_keys
jstucke May 12, 2022
d1e919a
improved kernel config detection
jstucke May 13, 2022
3a81024
added missing test file
jstucke May 16, 2022
28e7d6f
added NetUSB software signature
jstucke May 16, 2022
240a3dd
added no_text_file condition to new signature
jstucke May 16, 2022
72565d3
Merge branch 'database-migration' into new-software-signatures
jstucke May 16, 2022
52cc9ff
install.py: Make common install selectable
maringuu May 2, 2022
e28e81a
strip leading zeroes from matched software version
jstucke May 16, 2022
9a7223d
Merge branch 'database-migration' into postgres-bugfixes
jstucke May 16, 2022
21aa1a9
Merge pull request #780 from fkie-cad/improved_kconfig_detection
rhelmke May 17, 2022
b091914
use packaging module instead of pkg_resources
jstucke May 17, 2022
df6f2e4
fix flaky test with more robust events
jstucke May 17, 2022
0f30e20
Merge remote-tracking branch 'origin/database-migration' into simplif…
jstucke May 17, 2022
335b14f
Merge pull request #776 from fkie-cad/simplify_installer
jstucke May 17, 2022
fe3b7f5
added additional crypto hints signatures
jstucke May 17, 2022
b602dac
revert import change to fix ImportError
jstucke May 18, 2022
d475ce1
test wait event wrong fo count fix
jstucke May 18, 2022
79fc9c4
Merge pull request #769 from fkie-cad/postgres-bugfixes
jstucke May 18, 2022
3b8d841
Merge pull request #771 from fkie-cad/new-software-signatures
dorpvom May 19, 2022
3b2938b
added ghidra script for detecting CVE-2021-45608
May 19, 2022
7a3ed01
added error handling for missing parent in DB
jstucke May 25, 2022
a2433cc
text file diff html file comparison bugfix
jstucke May 25, 2022
43c9354
requested review changes
jstucke May 25, 2022
5026bf9
Merge pull request #784 from fkie-cad/crypto_hints_signatures
rhelmke May 30, 2022
22ede9c
updated migration docs
jstucke May 30, 2022
514c6ff
added missing migration config files
jstucke May 30, 2022
29a3192
improved migration user feedback
jstucke May 30, 2022
5b61504
added per page dropdown menu to browse page
jstucke May 31, 2022
9b24d7f
init_postgres.py: Add shebang
maringuu May 9, 2022
6b0704b
init_postgres.py: Connect to correct host and port
maringuu May 9, 2022
0e403a7
Merge pull request #789 from fkie-cad/revised-migration
dorpvom Jun 7, 2022
ae222b6
Merge pull request #790 from fkie-cad/browse-per-page
rhelmke Jun 8, 2022
65adf63
moved john installation to docker container
jstucke Jun 13, 2022
4b2d6a4
select.select big fp count bugfix
jstucke Jun 13, 2022
4464ad0
updated distribution codenames
jstucke Jun 13, 2022
e2ec999
updated docker installation
jstucke Jun 13, 2022
6da19d4
jammy unsupported hash functions bugfix
jstucke Jun 13, 2022
bbdacb3
pre_install codename bugfix
jstucke Jun 13, 2022
c6c6929
pre_install outdated package sources bugfix
jstucke Jun 13, 2022
228b8c5
changed html escaping
jstucke Jun 13, 2022
678cdb5
add john pot file to installation
jstucke Jun 14, 2022
208bfe3
made docker entry script executable
jstucke Jun 14, 2022
fb4c6e6
Merge pull request #787 from fkie-cad/refactoring_and_test_coverage
rhelmke Jun 14, 2022
71ec429
Merge branch 'jammy2' into refactoring_and_test_coverage
jstucke Jun 14, 2022
7f360ee
increased installation error logging verbosity
jstucke Jun 3, 2022
bc752a6
removed ubuntu 14.04 codenames from pre_install.sh
jstucke Jun 14, 2022
267d4b3
plugin installation refactoring
jstucke Jun 14, 2022
04b4164
removed WebFrontEnd from manage_users and replaced it with new app mo…
jstucke Jun 14, 2022
c09c8a0
Merge pull request #800 from fkie-cad/jammy2
jstucke Jun 14, 2022
e4c277e
Merge remote-tracking branch 'origin/database-migration' into refacto…
jstucke Jun 14, 2022
b41b756
bytes in users_and_pw results bugfix
jstucke Jun 14, 2022
41de620
db serialization error logging bugfix
jstucke Jun 14, 2022
16fc96f
Merge pull request #802 from fkie-cad/manage-users-dependency-rework
rhelmke Jun 14, 2022
d98f6d5
Merge remote-tracking branch 'origin/master' into database-migration
jstucke Jun 27, 2022
81db54c
Merge remote-tracking branch 'origin/database-migration' into refacto…
jstucke Jun 27, 2022
23d6e80
master merge bugfix: removed _get_docker_build_args function
jstucke Jun 27, 2022
ae39649
Merge pull request #775 from fkie-cad/better_database_init
jstucke Jun 27, 2022
78c1223
Merge remote-tracking branch 'origin/database-migration' into refacto…
jstucke Jun 27, 2022
ab745bc
Replace .format calls with f-strings
maringuu Jun 27, 2022
d202b94
Replace some double quotes with single quotes
maringuu Jun 27, 2022
4c6c684
Merge pull request #722 from fkie-cad/f-strings
jstucke Jun 28, 2022
baa4928
adjusted script to detect other fixes, added evaluation
Jun 30, 2022
6a31296
added JSON output, corrected evaluation
Jul 4, 2022
046ad2e
edit JSON path
Jul 4, 2022
e8275b0
Merge pull request #803 from fkie-cad/users-and-pw-bytes-bugfix
dorpvom Jul 6, 2022
f2e9ccd
Merge pull request #801 from fkie-cad/refactoring_and_test_coverage
dorpvom Jul 6, 2022
061ba71
Merge remote-tracking branch 'origin/master' into database-migration
jstucke Jul 6, 2022
a9f4301
removed md5 hashes from quick search (didn't work anyway)
jstucke Jul 7, 2022
ee85dd1
updated quick search placeholder string
jstucke Jul 7, 2022
4b3397a
added unit tests for quick search
jstucke Jul 7, 2022
8d259f1
requested review changes
jstucke Jul 8, 2022
9fcb43b
Merge pull request #815 from fkie-cad/md5-quick-search-bugfix
dorpvom Jul 8, 2022
20f45e1
moved db engine to own class so that db interface instances are not s…
jstucke Jul 8, 2022
a048871
fixed tests
jstucke Jul 8, 2022
eb9331b
init postgres fix
jstucke Jul 8, 2022
94895ad
pip package installation error handling bugfix
jstucke Jul 8, 2022
b12e147
bumped version and updated changelog
jstucke Jul 8, 2022
8ae90c8
made changelog link clickable
jstucke Jul 8, 2022
12aabd7
Merge pull request #817 from fkie-cad/refactoring_and_test_coverage
rhelmke Jul 8, 2022
24b48e6
Merge remote-tracking branch 'origin/database-migration' into CVE-202…
jstucke Jul 11, 2022
5c42a95
revised ghidra script
jstucke Jul 11, 2022
8940c9d
updated software_components Dockerfile to use the same base image as …
jstucke Jul 11, 2022
2205d85
added known_vulnerabilities Dockerfile and installation
jstucke Jul 11, 2022
600dbf0
rulebook typo fixes
jstucke Jul 11, 2022
d44ee9b
added NetUSB check to known_vulnerabilities plugin
jstucke Jul 11, 2022
43b9999
added tests
jstucke Jul 11, 2022
90deca8
updated known_vulnerabilities template to display additional data
jstucke Jul 11, 2022
9db9031
requested review changes
jstucke Jul 12, 2022
2dc4bac
added session recycling to plugins
jstucke Jul 12, 2022
81b6780
fix naming in ajax_routes
jstucke Jul 14, 2022
598cc8e
fix naming in rest_compare
jstucke Jul 14, 2022
20f2408
more naming fixes in rest_compare
jstucke Jul 14, 2022
d3dcd1f
Merge pull request #819 from fkie-cad/CVE-2021-45608-detection
rhelmke Jul 14, 2022
5b83979
renaming bugfix
jstucke Jul 14, 2022
5b553ee
Merge pull request #816 from fkie-cad/fix-session-recycling
rhelmke Jul 15, 2022
9ef0668
Update README.md
dorpvom Jul 20, 2022
7991fa1
Merge pull request #818 from fkie-cad/version-bump
dorpvom Jul 20, 2022
a17a6f1
added missing mock import for docs
jstucke Jul 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ save some time when you already have the images.
The three components db, backend and frontend can be installed independently to create a distributed installation.

The two worker components (frontend, backend) communicate exclusively through the database. The database in turn does not needed any knowledge of its place in the network, other than on which **ip:port** combination the database server has to be hosted.
The main.cfg on the frontend system has to be altered so that the values of `data_storage.mongo_server` and `data_storage.mongo_port` match the **ip:port** for the database.
The same has to be done for the backend. In addition, since the raw firmware and file binaries are stored in the backend, the `data_storage.firmware_file_storage_directory` has to be created (by default `/media/data/fact_fw_data`).
The main.cfg on the frontend system has to be altered so that the values of `data-storage.mongo-server` and `data-storage.mongo-port` match the **ip:port** for the database.
The same has to be done for the backend. In addition, since the raw firmware and file binaries are stored in the backend, the `data-storage.firmware-file-storage-directory` has to be created (by default `/media/data/fact_fw_data`).
On the database system, the `mongod.conf` has to be given the correct `net.bindIp` and `net.port`. In addition the path in `storage.dbPath` of the `mongod.conf` has to be created.

## Installation with Nginx (**--nginx**)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Minimal | Recommended | Software
It is possible to install FACT on any Linux distribution, but the installer is limited to
- Ubuntu 18.04 (with Python >3.6)
- Ubuntu 20.04 (stable)
- Ubuntu 22.04 (stable)
- Debian 10 (stable)
- Kali (experimental)

Expand Down
1 change: 1 addition & 0 deletions docsrc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
'pymongo',
'requests',
'si_prefix',
'sqlalchemy',
'ssdeep',
'tlsh',
'werkzeug',
Expand Down
1 change: 1 addition & 0 deletions docsrc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Contents
:maxdepth: 1

main
migration


.. toctree::
Expand Down
22 changes: 22 additions & 0 deletions docsrc/migration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Upgrading FACT from 3 to 4
==========================

With the release of FACT 4.0, the database was switched from MongoDB to PostgreSQL.
To install all dependencies, simply rerun the installation::

$ python3 src/install.py

Existing analysis and comparison results from your old FACT installation have to be migrated to the new database.
First you need to start the database::

$ mongod --config config/mongod.conf

Then you can start the migration script::

$ python3 src/migrate_db_to_postgresql.py

After this, you should be able to start FACT normally and should find your old data in the new database.
When the migration is complete, FACT does not use MongoDB anymore and you may want to uninstall it::

$ python3 -m pip uninstall pymongo
$ sudo apt remove mongodb # or mongodb-org depending on which version is installed
7 changes: 7 additions & 0 deletions docsrc/modules/helperFunctions.data_conversion.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
helperFunctions.data_conversion module
======================================

.. automodule:: helperFunctions.data_conversion
:members:
:undoc-members:
:show-inheritance:
7 changes: 0 additions & 7 deletions docsrc/modules/helperFunctions.mongo_config_parser.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docsrc/modules/helperFunctions.object_storage.rst

This file was deleted.

6 changes: 3 additions & 3 deletions docsrc/modules/helperFunctions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ helperFunctions

helperFunctions.compare_sets
helperFunctions.config
helperFunctions.data_conversion
helperFunctions.database
helperFunctions.docker
helperFunctions.fileSystem
helperFunctions.hash
helperFunctions.install
helperFunctions.logging
helperFunctions.merge_generators
helperFunctions.mongo_config_parser
helperFunctions.mongo_task_conversion
helperFunctions.object_conversion
helperFunctions.object_storage
helperFunctions.pdf
helperFunctions.plugin
helperFunctions.process
helperFunctions.program_setup
helperFunctions.tag
helperFunctions.task_conversion
helperFunctions.uid
helperFunctions.virtual_file_path
helperFunctions.web_interface
helperFunctions.yara_binary_search

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
helperFunctions.mongo_task_conversion module
helperFunctions.task_conversion module
============================================

.. automodule:: helperFunctions.mongo_task_conversion
.. automodule:: helperFunctions.task_conversion
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docsrc/modules/helperFunctions.virtual_file_path.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
helperFunctions.virtual_file_path module
========================================

.. automodule:: helperFunctions.virtual_file_path
:members:
:undoc-members:
:show-inheritance:
63 changes: 40 additions & 23 deletions src/analysis/PluginBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from time import time

from helperFunctions.process import (
ExceptionSafeProcess, check_worker_exceptions, start_single_worker, terminate_process_and_children
ExceptionSafeProcess, check_worker_exceptions, start_single_worker, stop_processes, terminate_process_and_children
)
from helperFunctions.tag import TagColor
from objects.file import FileObject
Expand All @@ -20,32 +20,50 @@ def __init__(self, *args, plugin=None):
class AnalysisBasePlugin(BasePlugin): # pylint: disable=too-many-instance-attributes
'''
This is the base plugin. All plugins should be subclass of this.
recursive flag: If True (default) recursively analyze included files
'''
VERSION = 'not set'
SYSTEM_VERSION = None

timeout = None
# must be set by the plugin:
FILE = None
NAME = None
DESCRIPTION = None
VERSION = None

# can be set by the plugin:
RECURSIVE = True # If `True` (default) recursively analyze included files
TIMEOUT = 300
SYSTEM_VERSION = None
MIME_BLACKLIST = []
MIME_WHITELIST = []

def __init__(self, plugin_administrator, config=None, recursive=True, no_multithread=False, timeout=300, offline_testing=False, plugin_path=None): # pylint: disable=too-many-arguments
super().__init__(plugin_administrator, config=config, plugin_path=plugin_path)
def __init__(self, plugin_administrator, config=None, no_multithread=False, offline_testing=False, view_updater=None):
super().__init__(plugin_administrator, config=config, plugin_path=self.FILE, view_updater=view_updater)
self._check_plugin_attributes()
self.check_config(no_multithread)
self.recursive = recursive
self.additional_setup()
self.in_queue = Queue()
self.out_queue = Queue()
self.stop_condition = Value('i', 0)
self.workers = []
self.thread_count = int(self.config[self.NAME]['threads'])
self.active = [Value('i', 0) for _ in range(self.thread_count)]
if self.timeout is None:
self.timeout = timeout
self.register_plugin()
if not offline_testing:
self.start_worker()

def additional_setup(self):
'''
This function can be implemented by the plugin to do initialization
'''
pass

def _check_plugin_attributes(self):
for attribute in ['FILE', 'NAME', 'VERSION']:
if getattr(self, attribute, None) is None:
raise PluginInitException(f'Plugin {self.NAME} is missing {attribute} in configuration')

def add_job(self, fw_object: FileObject):
if self._dependencies_are_unfulfilled(fw_object):
logging.error('{}: dependencies of plugin {} not fulfilled'.format(fw_object.uid, self.NAME))
logging.error(f'{fw_object.uid}: dependencies of plugin {self.NAME} not fulfilled')
elif self._analysis_depth_not_reached_yet(fw_object):
self.in_queue.put(fw_object)
return
Expand All @@ -57,7 +75,7 @@ def _dependencies_are_unfulfilled(self, fw_object: FileObject):
return any(dep not in fw_object.processed_analysis for dep in self.DEPENDENCIES)

def _analysis_depth_not_reached_yet(self, fo):
return self.recursive or fo.depth == 0
return self.RECURSIVE or fo.depth == 0

def process_object(self, file_object): # pylint: disable=no-self-use
'''
Expand All @@ -76,12 +94,11 @@ def _add_plugin_version_and_timestamp_to_analysis_result(self, fo): # pylint: d

def shutdown(self):
'''
This function can be called to shutdown all working threads
This function can be called to shut down all working threads
'''
logging.debug('Shutting down...')
self.stop_condition.value = 1
for process in self.workers:
process.join()
stop_processes(self.workers)
self.in_queue.close()
self.out_queue.close()

Expand Down Expand Up @@ -116,7 +133,7 @@ def check_config(self, no_multithread):
def start_worker(self):
for process_index in range(self.thread_count):
self.workers.append(start_single_worker(process_index, 'Analysis', self.worker))
logging.debug('{}: {} worker threads started'.format(self.NAME, len(self.workers)))
logging.debug(f'{self.NAME}: {len(self.workers)} worker threads started')

def process_next_object(self, task, result):
task.processed_analysis.update({self.NAME: {}})
Expand All @@ -132,34 +149,34 @@ def worker_processing_with_timeout(self, worker_id, next_task):
result = manager.list()
process = ExceptionSafeProcess(target=self.process_next_object, args=(next_task, result))
process.start()
process.join(timeout=self.timeout)
process.join(timeout=self.TIMEOUT)
if self.timeout_happened(process):
self._handle_failed_analysis(next_task, process, worker_id, 'Timeout')
elif process.exception:
self._handle_failed_analysis(next_task, process, worker_id, 'Exception')
else:
self.out_queue.put(result.pop())
logging.debug('Worker {}: Finished {} analysis on {}'.format(worker_id, self.NAME, next_task.uid))
logging.debug(f'Worker {worker_id}: Finished {self.NAME} analysis on {next_task.uid}')

def _handle_failed_analysis(self, fw_object, process, worker_id, cause: str):
terminate_process_and_children(process)
fw_object.analysis_exception = (self.NAME, '{} occurred during analysis'.format(cause))
logging.error('Worker {}: {} during analysis {} on {}'.format(worker_id, cause, self.NAME, fw_object.uid))
fw_object.analysis_exception = (self.NAME, f'{cause} occurred during analysis')
logging.error(f'Worker {worker_id}: {cause} during analysis {self.NAME} on {fw_object.uid}')
self.out_queue.put(fw_object)

def worker(self, worker_id):
while self.stop_condition.value == 0:
try:
next_task = self.in_queue.get(timeout=float(self.config['ExpertSettings']['block_delay']))
logging.debug('Worker {}: Begin {} analysis on {}'.format(worker_id, self.NAME, next_task.uid))
next_task = self.in_queue.get(timeout=float(self.config['expert-settings']['block-delay']))
logging.debug(f'Worker {worker_id}: Begin {self.NAME} analysis on {next_task.uid}')
except Empty:
self.active[worker_id].value = 0
else:
self.active[worker_id].value = 1
next_task.processed_analysis.update({self.NAME: {}})
self.worker_processing_with_timeout(worker_id, next_task)

logging.debug('worker {} stopped'.format(worker_id))
logging.debug(f'worker {worker_id} stopped')

def check_exceptions(self):
return check_worker_exceptions(self.workers, 'Analysis', self.config, self.worker)
23 changes: 10 additions & 13 deletions src/analysis/YaraPluginBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import subprocess
from pathlib import Path
from typing import Dict

from analysis.PluginBase import AnalysisBasePlugin, PluginInitException
from helperFunctions.fileSystem import get_src_dir
Expand All @@ -15,19 +16,20 @@ class YaraBasePlugin(AnalysisBasePlugin):
NAME = 'Yara_Base_Plugin'
DESCRIPTION = 'this is a Yara plugin'
VERSION = '0.0'
FILE = None

def __init__(self, plugin_administrator, config=None, recursive=True, plugin_path=None):
def __init__(self, plugin_administrator, config=None, view_updater=None):
'''
recursive flag: If True recursively analyze included files
propagate flag: If True add analysis result of child to parent object
'''
self.config = config
self.signature_path = self._get_signature_file(plugin_path) if plugin_path else None
self.signature_path = self._get_signature_file(self.FILE) if self.FILE else None
if self.signature_path and not Path(self.signature_path).exists():
logging.error(f'Signature file {self.signature_path} not found. Did you run "compile_yara_signatures.py"?')
raise PluginInitException(plugin=self)
self.SYSTEM_VERSION = self.get_yara_system_version() # pylint: disable=invalid-name
super().__init__(plugin_administrator, config=config, recursive=recursive, plugin_path=plugin_path)
super().__init__(plugin_administrator, config=config, view_updater=view_updater)

def get_yara_system_version(self):
with subprocess.Popen(['yara', '--version'], stdout=subprocess.PIPE) as process:
Expand Down Expand Up @@ -62,7 +64,7 @@ def _get_signature_file(self, plugin_path):

@staticmethod
def _parse_yara_output(output):
resulting_matches = dict()
resulting_matches = {}

match_blocks, rules = _split_output_in_rules_and_matches(output)

Expand All @@ -88,23 +90,18 @@ def _split_output_in_rules_and_matches(output):
return match_blocks, rules


def _append_match_to_result(match, resulting_matches, rule):
def _append_match_to_result(match, resulting_matches: Dict[str, dict], rule):
rule_name, meta_string, _, _ = rule
_, offset, matched_tag, matched_string = match

meta_dict = _parse_meta_data(meta_string)

this_match = resulting_matches[rule_name] if rule_name in resulting_matches else dict(rule=rule_name, matches=True, strings=list(), meta=meta_dict)

this_match['strings'].append((int(offset, 16), matched_tag, matched_string.encode()))
resulting_matches[rule_name] = this_match
resulting_matches.setdefault(rule_name, dict(rule=rule_name, matches=True, strings=[], meta=_parse_meta_data(meta_string)))
resulting_matches[rule_name]['strings'].append((int(offset, 16), matched_tag, matched_string))


def _parse_meta_data(meta_data_string):
'''
Will be of form 'item0=lowercaseboolean0,item1="value1",item2=value2,..'
'''
meta_data = dict()
meta_data = {}
for item in meta_data_string.split(','):
if '=' in item:
key, value = item.split('=', maxsplit=1)
Expand Down
6 changes: 3 additions & 3 deletions src/check_signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@


def _setup_argparser():
parser = argparse.ArgumentParser(description='{} - {}'.format(PROGRAM_NAME, PROGRAM_DESCRIPTION))
parser = argparse.ArgumentParser(description=f'{PROGRAM_NAME} - {PROGRAM_DESCRIPTION}')
parser.add_argument('-V', '--version', action='version',
version='{} {}'.format(PROGRAM_NAME, PROGRAM_VERSION))
version=f'{PROGRAM_NAME} {PROGRAM_VERSION}')
parser.add_argument('test_file', help='File containing the list of signatures')
parser.add_argument('--yara_path', help='File or Folder containing yara signatures (Extension .yara mandatory)', default='software_signatures/')
return parser.parse_args()
Expand All @@ -54,6 +54,6 @@ def _setup_logging():
sig_tester = SignatureTesting()
diff = sig_tester.check(args.yara_path, args.test_file)
if diff:
logging.error('Missing yara signatures for: {}'.format(diff))
logging.error(f'Missing yara signatures for: {diff}')
else:
logging.info('Found all strings')
9 changes: 6 additions & 3 deletions src/compare/PluginBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ class CompareBasePlugin(BasePlugin):
This is the compare plug-in base class. All compare plug-ins should be derived from this class.
'''

def __init__(self, plugin_administrator, config=None, db_interface=None, plugin_path=None):
super().__init__(plugin_administrator, config=config, plugin_path=plugin_path)
# must be set by the plugin:
FILE = None

def __init__(self, plugin_administrator, config=None, db_interface=None, view_updater=None):
super().__init__(plugin_administrator, config=config, plugin_path=self.FILE, view_updater=view_updater)
self.database = db_interface
self.register_plugin()

Expand All @@ -30,7 +33,7 @@ def compare(self, fo_list):
'''
missing_deps = _get_unmatched_dependencies(fo_list, self.DEPENDENCIES)
if len(missing_deps) > 0:
return {'Compare Skipped': {'all': 'Required analysis not present: {}'.format(', '.join(missing_deps))}}
return {'Compare Skipped': {'all': f"Required analysis not present: {', '.join(missing_deps)}"}}
return self.compare_function(fo_list)


Expand Down
Loading