|
0 |
--- a/empire
|
|
1 |
+++ b/empire
|
|
2 |
@@ -9,6 +9,23 @@ import hashlib
|
|
3 |
from OpenSSL import SSL
|
|
4 |
import ssl
|
|
5 |
import ast
|
|
6 |
+import shutil
|
|
7 |
+
|
|
8 |
+# database old path
|
|
9 |
+DB_OLD_PATH = "/usr/share/powershell-empire/data"
|
|
10 |
+# database new path
|
|
11 |
+DB_PATH = os.path.expanduser("~/.powershell-empire")
|
|
12 |
+# Handle database creation / switch before import lib.common
|
|
13 |
+if not os.path.isfile(os.path.join(DB_PATH, "empire.db")):
|
|
14 |
+ if not os.path.exists(DB_PATH):
|
|
15 |
+ os.mkdir(DB_PATH)
|
|
16 |
+ if os.path.exists(os.path.join(DB_OLD_PATH, "empire.db")):
|
|
17 |
+ if os.getuid() == 0:
|
|
18 |
+ shutil.move((os.path.join(DB_OLD_PATH, "empire.db")), os.path.join(DB_PATH, "empire.db"))
|
|
19 |
+ else:
|
|
20 |
+ subprocess.run(["setup/setup_database.py"])
|
|
21 |
+ else:
|
|
22 |
+ subprocess.run(["setup/setup_database.py"])
|
|
23 |
|
|
24 |
# Empire imports
|
|
25 |
from lib.common import empire, helpers
|
|
26 |
@@ -45,7 +62,7 @@ def database_connect():
|
|
27 |
"""
|
|
28 |
try:
|
|
29 |
# set the database connectiont to autocommit w/ isolation level
|
|
30 |
- conn = sqlite3.connect('./data/empire.db', check_same_thread=False)
|
|
31 |
+ conn = sqlite3.connect(os.path.join(DB_PATH, 'empire.db'), check_same_thread=False)
|
|
32 |
conn.text_factory = str
|
|
33 |
conn.isolation_level = None
|
|
34 |
return conn
|
|
35 |
--- a/lib/common/__init__.py
|
|
36 |
+++ b/lib/common/__init__.py
|
|
37 |
@@ -6,6 +6,7 @@ from __future__ import absolute_import
|
|
38 |
|
|
39 |
import sys
|
|
40 |
import sqlite3
|
|
41 |
+import os
|
|
42 |
|
|
43 |
from . import helpers
|
|
44 |
|
|
45 |
@@ -13,7 +14,8 @@ from . import helpers
|
|
46 |
def connect_to_db():
|
|
47 |
try:
|
|
48 |
# set the database connectiont to autocommit w/ isolation level
|
|
49 |
- conn = sqlite3.connect('./data/empire.db', check_same_thread=False)
|
|
50 |
+ conn = sqlite3.connect(os.path.expanduser('~/.powershell-empire/empire.db'),
|
|
51 |
+ check_same_thread=False)
|
|
52 |
conn.text_factory = str
|
|
53 |
conn.isolation_level = None
|
|
54 |
return conn
|
|
55 |
--- a/lib/common/empire.py
|
|
56 |
+++ b/lib/common/empire.py
|
|
57 |
@@ -316,7 +316,8 @@ class MainMenu(cmd.Cmd):
|
|
58 |
"""
|
|
59 |
try:
|
|
60 |
# set the database connectiont to autocommit w/ isolation level
|
|
61 |
- self.conn = sqlite3.connect('./data/empire.db', check_same_thread=False)
|
|
62 |
+ self.conn = sqlite3.connect(os.path.expanduser('~/.powershell-empire/empire.db'),
|
|
63 |
+ check_same_thread=False)
|
|
64 |
self.conn.text_factory = str
|
|
65 |
self.conn.isolation_level = None
|
|
66 |
return self.conn
|
|
67 |
--- a/lib/common/helpers.py
|
|
68 |
+++ b/lib/common/helpers.py
|
|
69 |
@@ -594,7 +594,7 @@ def get_config(fields):
|
|
70 |
i.e. 'version,install_path'
|
|
71 |
"""
|
|
72 |
|
|
73 |
- conn = sqlite3.connect('./data/empire.db', check_same_thread=False)
|
|
74 |
+ conn = sqlite3.connect(os.path.expanduser('~/.powershell-empire/empire.db'), check_same_thread=False)
|
|
75 |
conn.isolation_level = None
|
|
76 |
|
|
77 |
cur = conn.cursor()
|
|
78 |
@@ -619,7 +619,7 @@ def get_listener_options(listenerName):
|
|
79 |
of the normal menu execution.
|
|
80 |
"""
|
|
81 |
try:
|
|
82 |
- conn = sqlite3.connect('./data/empire.db', check_same_thread=False)
|
|
83 |
+ conn = sqlite3.connect(os.path.expanduser('~/.powershell-empire/empire.db'), check_same_thread=False)
|
|
84 |
conn.isolation_level = None
|
|
85 |
conn.row_factory = dict_factory
|
|
86 |
cur = conn.cursor()
|
|
87 |
--- a/setup/setup_database.py
|
|
88 |
+++ b/setup/setup_database.py
|
|
89 |
@@ -62,7 +62,7 @@ OBFUSCATE_COMMAND = r'Token\All\1'
|
|
90 |
#
|
|
91 |
###################################################
|
|
92 |
|
|
93 |
-conn = sqlite3.connect('%s/data/empire.db'%INSTALL_PATH)
|
|
94 |
+conn = sqlite3.connect(os.path.expanduser('~/.powershell-empire/empire.db'))
|
|
95 |
|
|
96 |
c = conn.cursor()
|
|
97 |
|