fix for Bug #166 (Keyboard interrupt in Python threading)

This commit is contained in:
Miroslav Stampar 2010-03-11 11:14:20 +00:00
parent b344a70ba1
commit 2c053d5cfb
2 changed files with 33 additions and 16 deletions

View File

@ -960,6 +960,7 @@ def __setConfAttributes():
conf.seqLock = None conf.seqLock = None
conf.sessionFP = None conf.sessionFP = None
conf.start = True conf.start = True
conf.threadContinue = True
conf.threadException = False conf.threadException = False
conf.wFileType = None conf.wFileType = None

View File

@ -154,10 +154,11 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
idxlock = threading.Lock() idxlock = threading.Lock()
iolock = threading.Lock() iolock = threading.Lock()
conf.seqLock = threading.Lock() conf.seqLock = threading.Lock()
conf.threadContinue = True
def downloadThread(): def downloadThread():
try: try:
while True: while conf.threadContinue:
idxlock.acquire() idxlock.acquire()
if index[0] >= length: if index[0] >= length:
@ -169,21 +170,24 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
curidx = index[0] curidx = index[0]
idxlock.release() idxlock.release()
charStart = time.time() if conf.threadContinue:
val = getChar(curidx) charStart = time.time()
val = getChar(curidx)
if val is None: if val is None:
raise sqlmapValueException, "failed to get character at index %d (expected %d total)" % (curidx, length) raise sqlmapValueException, "failed to get character at index %d (expected %d total)" % (curidx, length)
else:
break
value[curidx-1] = val value[curidx-1] = val
if showEta: if conf.threadContinue:
etaProgressUpdate(time.time() - charStart, index[0]) if showEta:
elif conf.verbose >= 1: etaProgressUpdate(time.time() - charStart, index[0])
s = "".join([c or "_" for c in value]) elif conf.verbose >= 1:
iolock.acquire() s = "".join([c or "_" for c in value])
dataToStdout("\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), s)) iolock.acquire()
iolock.release() dataToStdout("\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), s))
iolock.release()
except (sqlmapConnectionException, sqlmapValueException), errMsg: except (sqlmapConnectionException, sqlmapValueException), errMsg:
conf.threadException = True conf.threadException = True
@ -215,9 +219,21 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
threads.append(thread) threads.append(thread)
# And wait for them to all finish # And wait for them to all finish
for thread in threads: #for thread in threads:
thread.join() # thread.join()
try:
alive = True
while alive:
alive = False
for thread in threads:
if thread.isAlive():
alive = True
thread.join(5)
except KeyboardInterrupt:
conf.threadContinue = False
raise
# If we have got one single character not correctly fetched it # If we have got one single character not correctly fetched it
# can mean that the connection to the target url was lost # can mean that the connection to the target url was lost
if None in value: if None in value: