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
46
utils.py
46
utils.py
|
@ -45,8 +45,8 @@ def HTTPCurrentDate():
|
||||||
try:
|
try:
|
||||||
import sqlite3
|
import sqlite3
|
||||||
except:
|
except:
|
||||||
print "[!] Please install python-sqlite3 extension."
|
sqlite3 = False
|
||||||
sys.exit(0)
|
print "[!] Please install python-sqlite3 extension. Logging to database will be unavailable"
|
||||||
|
|
||||||
def color(txt, code = 1, modifier = 0):
|
def color(txt, code = 1, modifier = 0):
|
||||||
if txt.startswith('[*]'):
|
if txt.startswith('[*]'):
|
||||||
|
@ -159,11 +159,12 @@ def DumpConfig(outfile, data):
|
||||||
|
|
||||||
def SaveToDb(result):
|
def SaveToDb(result):
|
||||||
# Creating the DB if it doesn't exist
|
# Creating the DB if it doesn't exist
|
||||||
if not os.path.exists(settings.Config.DatabaseFile):
|
if sqlite3:
|
||||||
cursor = sqlite3.connect(settings.Config.DatabaseFile)
|
if not os.path.exists(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))')
|
cursor = sqlite3.connect(settings.Config.DatabaseFile)
|
||||||
cursor.commit()
|
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))')
|
||||||
cursor.close()
|
cursor.commit()
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
for k in [ 'module', 'type', 'client', 'hostname', 'user', 'cleartext', 'hash', 'fullhash' ]:
|
for k in [ 'module', 'type', 'client', 'hostname', 'user', 'cleartext', 'hash', 'fullhash' ]:
|
||||||
if not k in result:
|
if not k in result:
|
||||||
|
@ -179,10 +180,20 @@ def SaveToDb(result):
|
||||||
|
|
||||||
logfile = os.path.join(settings.Config.ResponderPATH, 'logs', fname)
|
logfile = os.path.join(settings.Config.ResponderPATH, 'logs', fname)
|
||||||
|
|
||||||
cursor = sqlite3.connect(settings.Config.DatabaseFile)
|
if sqlite3:
|
||||||
cursor.text_factory = sqlite3.Binary # We add a text factory to support different charsets
|
cursor = sqlite3.connect(settings.Config.DatabaseFile)
|
||||||
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']))
|
cursor.text_factory = sqlite3.Binary # We add a text factory to support different charsets
|
||||||
(count,) = res.fetchone()
|
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:
|
if not count:
|
||||||
outf = open(logfile,"a")
|
outf = open(logfile,"a")
|
||||||
|
@ -192,8 +203,9 @@ def SaveToDb(result):
|
||||||
outf.write(result['fullhash'].encode('utf8', 'replace') + '\n')
|
outf.write(result['fullhash'].encode('utf8', 'replace') + '\n')
|
||||||
outf.close()
|
outf.close()
|
||||||
|
|
||||||
cursor.execute("INSERT INTO responder VALUES(datetime('now'), ?, ?, ?, ?, ?, ?, ?, ?)", (result['module'], result['type'], result['client'], result['hostname'], result['user'], result['cleartext'], result['hash'], result['fullhash']))
|
if sqlite3:
|
||||||
cursor.commit()
|
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()
|
||||||
|
|
||||||
if settings.Config.CaptureMultipleHashFromSameHost:
|
if settings.Config.CaptureMultipleHashFromSameHost:
|
||||||
outf = open(logfile,"a")
|
outf = open(logfile,"a")
|
||||||
|
@ -231,9 +243,11 @@ def SaveToDb(result):
|
||||||
else:
|
else:
|
||||||
print color('[*] Skipping previously captured hash for %s' % result['user'], 3, 1)
|
print color('[*] Skipping previously captured hash for %s' % result['user'], 3, 1)
|
||||||
text('[*] Skipping previously captured hash for %s' % result['user'])
|
text('[*] Skipping previously captured hash for %s' % result['user'])
|
||||||
cursor.execute("UPDATE responder SET timestamp=datetime('now') WHERE user=? AND client=?", (result['user'], result['client']))
|
if sqlite3:
|
||||||
cursor.commit()
|
cursor.execute("UPDATE responder SET timestamp=datetime('now') WHERE user=? AND client=?", (result['user'], result['client']))
|
||||||
cursor.close()
|
cursor.commit()
|
||||||
|
if sqlite3:
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
|
||||||
def Parse_IPV6_Addr(data):
|
def Parse_IPV6_Addr(data):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue