Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
helviojunior committed Aug 1, 2024
1 parent 4252b57 commit 41d777c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
14 changes: 11 additions & 3 deletions knowsmore/cmd/bloodhound.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,13 @@ def get_all_owned(self) -> list:
return session.execute_read(self._get_owned)

def set_owned(self, source_filter_type: str, source_label: str, source:str, owned: bool = True):
with self.driver.session(database=self.database) as session:
return session.execute_write(self._set_owned, source_filter_type, source_label, source, owned)

if self.version.major >= 5:
with self.driver.session(database=self.database) as session:
session.execute_write(self._set_owned, source_filter_type, source_label, source, owned)
else:
with self.driver.session(database=self.database) as session:
session.write_transaction(self._set_owned, source_filter_type, source_label, source, owned)

def get_session(self) -> Session:
return self.driver.session(database=self.database)
Expand Down Expand Up @@ -544,7 +549,7 @@ def mark_owned(self):
'on c.password_id = p.password_id '
'inner join domains as d '
'on c.domain_id = d.domain_id '
'where p.length > 0',
'where p.password <> ""',
args=[]
)

Expand Down Expand Up @@ -579,6 +584,9 @@ def mark_owned(self):
bar.hide = True
Tools.clear_line()

else:
Color.pl('{!} {O}Has none owned objects{W}')

def run(self):

# Disable warning logs of neo4j driver
Expand Down
7 changes: 7 additions & 0 deletions knowsmore/cmd/userpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def run(self):
args=[credential_id]
)

pwd = self.db.select_first('passwords', ntlm_hash=self.password.ntlm_hash)

pdata = {}

if len(Configuration.company) > 0:
Expand All @@ -112,6 +114,11 @@ def run(self):
)

self.db.insert_password_manually(self.password, **pdata)
if pwd is None:
pwd = self.db.select('passwords', ntlm_hash=self.password.ntlm_hash)

self.db.update('credentials', filter_data=dict(credential_id=credential_id), password_id=pwd['password_id'])

Logger.pl('{+} {C}Password inserted/updated{W}')

print(' ')
Expand Down
10 changes: 9 additions & 1 deletion knowsmore/util/knowsmoredb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import hashlib
from sqlite3 import Connection, OperationalError, IntegrityError, ProgrammingError

from knowsmore.util.tools import Tools

from .color import Color
from .database import Database
from ..password import Password
Expand Down Expand Up @@ -57,6 +59,11 @@ def insert_group(self, domain: int, object_identifier: str, name: str, dn: str =
membership=membership
)

def pe(self, error):
from knowsmore.config import Configuration
if Configuration.verbose >= 3:
Tools.print_error(error)

def update_password(self, password: Password, **kwargs):

filter_data = {
Expand Down Expand Up @@ -226,11 +233,12 @@ def insert_or_update_credential(self, domain: int, username: str, ntlm_hash: str
ex += [str(x) for x in exclude_on_update]

self.insert_update_one_exclude('credentials',
exclude_on_update=exclude_on_update,
exclude_on_update=ex,
**data)

except Exception as e:
Color.pl('{!} {R}Error inserting credential data:{O} %s{W}' % str(e))
self.pe(e)
pass

def insert_or_get_domain(self, domain: str, dn: str = '', object_identifier: str = '') -> int:
Expand Down
15 changes: 15 additions & 0 deletions knowsmore/util/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,18 @@ def escape_ansi(text):

pattern = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')
return pattern.sub('', text)

@staticmethod
def print_error(error: Exception, force: bool = False):
from knowsmore.config import Configuration
Color.pl('\n{!} {R}Error:{O} %s{W}' % str(error))

if Configuration.verbose >= 2 or force:
Color.pl('\n{!} {O}Full stack trace below')
from traceback import format_exc
Color.p('\n{!} ')
err = format_exc().strip()
err = err.replace('\n', '\n{W}{!} {W} ')
err = err.replace(' File', '{W}{D}File')
err = err.replace(' Exception: ', '{R}Exception: {O}')
Color.pl(err + '{W}')

0 comments on commit 41d777c

Please sign in to comment.