Add sqlite database

This commit is contained in:
Marcel Schwarz 2021-01-09 18:18:36 +01:00
parent b7485ef2f3
commit b033814f55
8 changed files with 19802 additions and 5 deletions

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="scans" uuid="1439f70e-a609-450a-b3b0-e4f1ad5dd725">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
<jdbc-url>jdbc:sqlite:D:\Git-Repos\it-security-2\scan_output_parser\scans.db</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
<libraries>
<library>
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.31.1/sqlite-jdbc-3.31.1.jar</url>
</library>
</libraries>
</data-source>
</component>
</project>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/db_writer.py" dialect="GenericSQL" />
<file url="PROJECT" dialect="SQLite" />
</component>
</project>

19727
scan_output_parser/bla.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
import sqlite3
import json
DB_NAME = "scans.db"
def write_run_to_db(run):
conn = sqlite3.connect(DB_NAME)
run_data = (run.id, run.platform, run.system, run.version, run.path)
conn.execute("INSERT OR IGNORE INTO runs VALUES (?, ?, ?, ?, ?)", run_data)
for otseca_res in run.otseca_results:
data = (
run.id, otseca_res.run_nr, str(otseca_res.path),
*list(map(json.dumps, otseca_res.result['boxes'].values())),
*list(map(json.dumps, otseca_res.result['general'].values()))
)
conn.execute("INSERT OR IGNORE INTO otseca_results VALUES (" + "".join("?," * 13) + "?)", data)
for testssl_res in run.testssl_results:
data = (
run.id, testssl_res.run_nr, str(testssl_res.path),
*list(map(json.dumps, testssl_res.result.values()))
)
conn.execute("INSERT OR IGNORE INTO testssl_results VALUES (" + "".join("?," * 11) + "?)", data)
for lynis_res in run.lynis_results:
categories = list(lynis_res.result.values())[:31]
general = list(lynis_res.result.values())[31]
data = (
run.id, lynis_res.run_nr, str(lynis_res.path),
*list(map(json.dumps, categories)),
*general.values()
)
print(data)
conn.execute("INSERT OR IGNORE INTO lynis_results VALUES (" + "".join("?," * 37) + "?)", data)
conn.commit()

View File

@ -60,7 +60,12 @@ def lynis_get_base(path_to_log):
"white": len(re.findall(LYNIS_REGEX['white'], block_text)), "white": len(re.findall(LYNIS_REGEX['white'], block_text)),
} }
} }
interesting_blocks["GENERAL"] = {} interesting_blocks["GENERAL"] = {
"warningCount": None,
"suggestionCount": None,
"hardeningIndex": None,
"testsPerformed": None
}
if warning_count := re.findall(r".*Warnings.* \((\d+)\)", text): if warning_count := re.findall(r".*Warnings.* \((\d+)\)", text):
interesting_blocks["GENERAL"]["warningCount"] = int(warning_count[0]) interesting_blocks["GENERAL"]["warningCount"] = int(warning_count[0])

View File

@ -6,6 +6,7 @@ from typing import List
from dataclasses_json import dataclass_json from dataclasses_json import dataclass_json
from db_writer import write_run_to_db
from lynis import lynis_parse from lynis import lynis_parse
from otseca import otseca_parse from otseca import otseca_parse
from testssl import testssl_parse from testssl import testssl_parse
@ -57,6 +58,9 @@ def main():
with open("bla.json", "w") as handle: with open("bla.json", "w") as handle:
handle.write(Run.schema().dumps(list_of_all, many=True)) handle.write(Run.schema().dumps(list_of_all, many=True))
for run in list_of_all:
write_run_to_db(run)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -35,10 +35,10 @@ def otseca_distro_info(path_to_report):
return { return {
"pkgCount": pkg_count, "pkgCount": pkg_count,
"upgraded": upgrades_count[0], "upgraded": int(upgrades_count[0]),
"newlyInstalled": upgrades_count[1], "newlyInstalled": int(upgrades_count[1]),
"remove": upgrades_count[2], "remove": int(upgrades_count[2]),
"notUpgraded": upgrades_count[3] "notUpgraded": int(upgrades_count[3])
} }

BIN
scan_output_parser/scans.db Normal file

Binary file not shown.