Skip to content

Commit d09f5de

Browse files
authored
Merge pull request #65 from idnahacks/dev
Allow the sql-path arg to be a dir or file
2 parents 89892b8 + 92d46c4 commit d09f5de

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

goodhound/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def arguments():
2525
parsegroupschema.add_argument("--patch41", help="A temporary option to patch a bug in Bloodhound 4.1 relating to the highvalue attribute.", action="store_true")
2626
parsegroupsql = argparser.add_argument_group('SQLite Database')
2727
parsegroupsql.add_argument("--db-skip", help="Skips the logging of attack paths to a local SQLite Database", action="store_true")
28-
parsegroupsql.add_argument("-sqlpath", "--sql-path", default=getcwd(), help="Sets the file path of the SQLite Database file goodhound.db", type=str)
28+
parsegroupsql.add_argument("-sqlpath", "--sql-path", default=getcwd(), help="Sets the file path of the GoodHound Database file", type=str)
2929
args = argparser.parse_args()
3030
return args
3131

goodhound/ghutils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,16 @@ def checkoutdir(path):
3434
logging.error('Selected output path is not a directory')
3535
exit(1)
3636
else:
37-
os.makedirs(path, exist_ok=True)
37+
os.makedirs(path, exist_ok=True)
38+
39+
def checkdbfileexists(sqlpath):
40+
"""Looks at the provided sql-path argument and determines whether to create a new db or update an existing one."""
41+
if Path(sqlpath).exists():
42+
if Path(sqlpath).is_file():
43+
dbfile = sqlpath
44+
else:
45+
dbfile = sqlpath + os.sep + "goodhound.db"
46+
else:
47+
os.makedirs(sqlpath, exist_ok=True)
48+
dbfile = sqlpath + os.sep + "goodhound.db"
49+
return dbfile

goodhound/sqldb.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from goodhound import neodb
1+
from goodhound import neodb, ghutils
22
from sqlite3.dbapi2 import Error
33
import sqlite3
44
from pathlib import Path
@@ -20,9 +20,9 @@ def db(results, graph, args):
2020
first_seen INTEGER NOT NULL,
2121
last_seen INTEGER NOT NULL);"""
2222
conn = None
23+
dbpath = ghutils.checkdbfileexists(args.sql_path)
2324
try:
24-
db = str(Path(args.sql_path)) + os.sep + 'goodhound.db'
25-
conn = sqlite3.connect(db)
25+
conn = sqlite3.connect(dbpath)
2626
c = conn.cursor()
2727
c.execute(table_sql)
2828
scandate, scandatenice = neodb.getscandate(graph)

0 commit comments

Comments
 (0)