mirror of
https://github.com/lgandx/Responder.git
synced 2025-08-22 06:13:39 -07:00
Fixed sqlite3 dependency. If sqlite3 module doesnt exist, logger will downgrade deduplication to file search.
This commit is contained in:
parent
15c8f53459
commit
a20452128c
1 changed files with 30 additions and 16 deletions
18
utils.py
18
utils.py
|
@ -45,8 +45,8 @@ def HTTPCurrentDate():
|
|||
try:
|
||||
import sqlite3
|
||||
except:
|
||||
print "[!] Please install python-sqlite3 extension."
|
||||
sys.exit(0)
|
||||
sqlite3 = False
|
||||
print "[!] Please install python-sqlite3 extension. Logging to database will be unavailable"
|
||||
|
||||
def color(txt, code = 1, modifier = 0):
|
||||
if txt.startswith('[*]'):
|
||||
|
@ -159,6 +159,7 @@ def DumpConfig(outfile, data):
|
|||
|
||||
def SaveToDb(result):
|
||||
# Creating the DB if it doesn't exist
|
||||
if sqlite3:
|
||||
if not os.path.exists(settings.Config.DatabaseFile):
|
||||
cursor = sqlite3.connect(settings.Config.DatabaseFile)
|
||||
cursor.execute('CREATE TABLE responder (timestamp varchar(32), module varchar(16), type varchar(16), client varchar(32), hostname varchar(32), user varchar(32), cleartext varchar(128), hash varchar(512), fullhash varchar(512))')
|
||||
|
@ -179,10 +180,20 @@ def SaveToDb(result):
|
|||
|
||||
logfile = os.path.join(settings.Config.ResponderPATH, 'logs', fname)
|
||||
|
||||
if sqlite3:
|
||||
cursor = sqlite3.connect(settings.Config.DatabaseFile)
|
||||
cursor.text_factory = sqlite3.Binary # We add a text factory to support different charsets
|
||||
res = cursor.execute("SELECT COUNT(*) AS count FROM responder WHERE module=? AND type=? AND client=? AND LOWER(user)=LOWER(?)", (result['module'], result['type'], result['client'], result['user']))
|
||||
(count,) = res.fetchone()
|
||||
else:
|
||||
logf = open(logfile, 'rb')
|
||||
data = logf.read()
|
||||
logf.close()
|
||||
|
||||
# What could possibly go wrong. Checking existence of hash in respective log file
|
||||
user_to_find = result['user'].encode('utf8', 'replace').split('\\', 1)
|
||||
user_to_find = '%s::%s' % (user_to_find[1], user_to_find[0]) # Username::domain
|
||||
count = len(re.findall('(?msi)^' + re.escape(user_to_find), data))
|
||||
|
||||
if not count:
|
||||
outf = open(logfile,"a")
|
||||
|
@ -192,6 +203,7 @@ def SaveToDb(result):
|
|||
outf.write(result['fullhash'].encode('utf8', 'replace') + '\n')
|
||||
outf.close()
|
||||
|
||||
if sqlite3:
|
||||
cursor.execute("INSERT INTO responder VALUES(datetime('now'), ?, ?, ?, ?, ?, ?, ?, ?)", (result['module'], result['type'], result['client'], result['hostname'], result['user'], result['cleartext'], result['hash'], result['fullhash']))
|
||||
cursor.commit()
|
||||
|
||||
|
@ -231,8 +243,10 @@ def SaveToDb(result):
|
|||
else:
|
||||
print color('[*] Skipping previously captured hash for %s' % result['user'], 3, 1)
|
||||
text('[*] Skipping previously captured hash for %s' % result['user'])
|
||||
if sqlite3:
|
||||
cursor.execute("UPDATE responder SET timestamp=datetime('now') WHERE user=? AND client=?", (result['user'], result['client']))
|
||||
cursor.commit()
|
||||
if sqlite3:
|
||||
cursor.close()
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue