Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c053d5

Browse files
committed
fix for Bug #166 (Keyboard interrupt in Python threading)
1 parent b344a70 commit 2c053d5

2 files changed

Lines changed: 33 additions & 16 deletions

File tree

lib/core/option.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ def __setConfAttributes():
960960
conf.seqLock = None
961961
conf.sessionFP = None
962962
conf.start = True
963+
conf.threadContinue = True
963964
conf.threadException = False
964965
conf.wFileType = None
965966

lib/techniques/blind/inference.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,11 @@ def etaProgressUpdate(charTime, index):
154154
idxlock = threading.Lock()
155155
iolock = threading.Lock()
156156
conf.seqLock = threading.Lock()
157+
conf.threadContinue = True
157158

158159
def downloadThread():
159160
try:
160-
while True:
161+
while conf.threadContinue:
161162
idxlock.acquire()
162163

163164
if index[0] >= length:
@@ -169,21 +170,24 @@ def downloadThread():
169170
curidx = index[0]
170171
idxlock.release()
171172

172-
charStart = time.time()
173-
val = getChar(curidx)
174-
175-
if val is None:
176-
raise sqlmapValueException, "failed to get character at index %d (expected %d total)" % (curidx, length)
173+
if conf.threadContinue:
174+
charStart = time.time()
175+
val = getChar(curidx)
176+
if val is None:
177+
raise sqlmapValueException, "failed to get character at index %d (expected %d total)" % (curidx, length)
178+
else:
179+
break
177180

178181
value[curidx-1] = val
179182

180-
if showEta:
181-
etaProgressUpdate(time.time() - charStart, index[0])
182-
elif conf.verbose >= 1:
183-
s = "".join([c or "_" for c in value])
184-
iolock.acquire()
185-
dataToStdout("\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), s))
186-
iolock.release()
183+
if conf.threadContinue:
184+
if showEta:
185+
etaProgressUpdate(time.time() - charStart, index[0])
186+
elif conf.verbose >= 1:
187+
s = "".join([c or "_" for c in value])
188+
iolock.acquire()
189+
dataToStdout("\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), s))
190+
iolock.release()
187191

188192
except (sqlmapConnectionException, sqlmapValueException), errMsg:
189193
conf.threadException = True
@@ -215,9 +219,21 @@ def downloadThread():
215219
threads.append(thread)
216220

217221
# And wait for them to all finish
218-
for thread in threads:
219-
thread.join()
220-
222+
#for thread in threads:
223+
# thread.join()
224+
225+
try:
226+
alive = True
227+
while alive:
228+
alive = False
229+
for thread in threads:
230+
if thread.isAlive():
231+
alive = True
232+
thread.join(5)
233+
except KeyboardInterrupt:
234+
conf.threadContinue = False
235+
raise
236+
221237
# If we have got one single character not correctly fetched it
222238
# can mean that the connection to the target url was lost
223239
if None in value:

0 commit comments

Comments
 (0)