Skip to content

Commit

Permalink
dcrack: solved problem saving data when script is aborted
Browse files Browse the repository at this point in the history
  • Loading branch information
Pepelux committed Jul 17, 2024
1 parent f15f862 commit 9017d17
Showing 1 changed file with 55 additions and 27 deletions.
82 changes: 55 additions & 27 deletions src/sippts/sipdigestcrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
__copyright__ = "Copyright (C) 2015-2024, SIPPTS"
__email__ = "[email protected]"

from threading import Lock
import signal
from concurrent.futures import ThreadPoolExecutor
import threading
Expand Down Expand Up @@ -41,7 +42,11 @@ def __init__(self):

self.totaltime = 0
self.found = []
self.saved = False
self.saved = []

self.lock = None

self.backupfile = "sipdigestcrack.res"

self.c = Color()

Expand All @@ -50,6 +55,8 @@ def __init__(self):
signal.signal(signal.SIGINT, self.signal_handler)

def start(self):
self.lock = Lock()

if not os.path.isfile(self.file):
print(f"{self.c.RED}[-] File {self.file} not found")
print(self.c.WHITE)
Expand Down Expand Up @@ -136,6 +143,8 @@ def start(self):

self.found.sort()
self.print()

self.save_file()

def signal_handler(self, sig, frame):
self.stop()
Expand Down Expand Up @@ -176,9 +185,11 @@ def read_data(
f"{self.c.BYELLOW}[+] Trying to crack hash {response} of the user {username} ...{self.c.WHITE}".ljust(100)
)

found = "false"
word_start = ""
try:
with io.open(
"sipdigestcrack.res",
self.backupfile,
"r",
newline=None,
encoding="latin-1",
Expand Down Expand Up @@ -281,11 +292,11 @@ def read_data(
else:
if self.run == False:
if self.bruteforce == "True":
self.save_file(
self.save_data(
self.charset, username, self.pwdvalue, "false"
)
else:
self.save_file(
self.save_data(
self.wordlist, username, self.pwdvalue, "false"
)
print(
Expand All @@ -306,21 +317,17 @@ def check_value(self, password, chars):
value += (pos**i) * chars.index(c)
return value

def save_file(self, wl, usr, pwd, status):
if self.saved == True:
return

self.saved = True
lines = []
def save_data(self, wl, usr, pwd, status):
found = 0

b64pwd = base64.b64encode(bytes(pwd, "utf-8")).decode()

print(f"{self.c.WHITE}\nSaving restore data ...")
if pwd == '' or b64pwd == '':
return

try:
with io.open(
"sipdigestcrack.res", "r", newline=None, encoding="latin-1"
self.backupfile, "r", newline=None, encoding="latin-1"
) as fd:
for pline in fd:
try:
Expand Down Expand Up @@ -360,7 +367,8 @@ def save_file(self, wl, usr, pwd, status):
status,
)
found = 1
lines.append(pl)
if pl not in self.saved:
self.saved.append(pl)
except:
fd.close()
return ""
Expand All @@ -374,6 +382,7 @@ def save_file(self, wl, usr, pwd, status):
self.suffix,
usr,
b64pwd,
status,
)
else:
pl = "bf:%s:%s:%s:%s:%s" % (
Expand All @@ -385,7 +394,8 @@ def save_file(self, wl, usr, pwd, status):
status,
)
found = 1
lines.append(pl)
if pl not in self.saved:
self.saved.append(pl)

if found == 0:
if self.bruteforce != "True":
Expand All @@ -406,13 +416,31 @@ def save_file(self, wl, usr, pwd, status):
b64pwd,
status,
)
lines.append(pl)

with open("sipdigestcrack.res", "w+") as f:
for l in lines:
f.write(l + "\n")
if pl not in self.saved:
self.saved.append(pl)

f.close()
def save_file(self):
self.saved.sort()
aux = []
aux2 = []

for line in reversed(self.saved):
values = line.split(":")

tmp = f"{values[0]}:{values[1]}:{values[2]}:{values[3]}:{values[4]}:"
if tmp not in aux:
aux2.append(line)

aux.append(tmp)

aux2.sort()

f = open(self.backupfile, 'w+')

for line in aux2:
f.write(line + "\n")

f.close()

def crack(
self,
Expand Down Expand Up @@ -474,10 +502,10 @@ def crack(
self.verbose,
"",
):
self.save_file(self.charset, username, pwd, "true")
self.save_data(self.charset, username, pwd, "true")
return pwd
except KeyboardInterrupt:
self.save_file(self.charset, username, pwd, "false")
self.save_data(self.charset, username, pwd, "false")
self.stop()
return ""
except:
Expand All @@ -487,7 +515,7 @@ def crack(
for pwd in fd:
# if not self.run_event.is_set():
# # fd.close()
# self.save_file(self.wordlist, username, pwd, "false")
# self.save_data(self.wordlist, username, pwd, "false")
# self.stop()
# break

Expand All @@ -508,7 +536,7 @@ def crack(

if not self.run_event.is_set():
fd.close()
self.save_file(self.wordlist, username, pwd, "false")
self.save_data(self.wordlist, username, pwd, "false")
self.stop()
break

Expand All @@ -530,18 +558,18 @@ def crack(
"",
):
fd.close()
self.save_file(self.wordlist, username, pwd, "true")
self.save_data(self.wordlist, username, pwd, "true")
return pwd
except KeyboardInterrupt:
fd.close()
self.save_file(self.wordlist, username, pwd, "false")
self.save_data(self.wordlist, username, pwd, "false")
self.stop()
return ""
except:
pwd = ""
pass

self.save_file(self.wordlist, username, pwd, "false")
self.save_data(self.wordlist, username, pwd, "false")
fd.close()
return ""

Expand Down

0 comments on commit 9017d17

Please sign in to comment.