diff --git a/lib/techniques/blind/inference.py b/lib/techniques/blind/inference.py index debfd8cfc..f336e92bc 100644 --- a/lib/techniques/blind/inference.py +++ b/lib/techniques/blind/inference.py @@ -147,9 +147,8 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None hintlock = threading.Lock() def tryHint(idx): - hintlock.acquire() - hintValue = kb.hintValue - hintlock.release() + with hintlock: + hintValue = kb.hintValue if hintValue is not None and len(hintValue) >= idx: if Backend.getIdentifiedDbms() in (DBMS.SQLITE, DBMS.ACCESS, DBMS.MAXDB, DBMS.DB2): @@ -164,9 +163,8 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None if result: return hintValue[idx-1] - hintlock.acquire() - kb.hintValue = None - hintlock.release() + with hintlock: + kb.hintValue = None return None @@ -373,10 +371,9 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None else: break - kb.locks.value.acquire() - threadData.shared.value[curidx - 1] = val - currentValue = list(threadData.shared.value) - kb.locks.value.release() + with kb.locks.value: + threadData.shared.value[curidx - 1] = val + currentValue = list(threadData.shared.value) if kb.threadContinue: if showEta: diff --git a/lib/techniques/error/use.py b/lib/techniques/error/use.py index 8a94c9b6b..af6a1ff9d 100644 --- a/lib/techniques/error/use.py +++ b/lib/techniques/error/use.py @@ -333,13 +333,11 @@ def errorUse(expression, expected=None, dump=False): threadData = getCurrentThreadData() while kb.threadContinue: - kb.locks.limits.acquire() - try: - num = threadData.shared.limits.next() - except StopIteration: - break - finally: - kb.locks.limits.release() + with kb.locks.limits: + try: + num = threadData.shared.limits.next() + except StopIteration: + break output = __errorFields(expression, expressionFields, expressionFieldsList, expected, num) @@ -349,9 +347,8 @@ def errorUse(expression, expected=None, dump=False): if output and isinstance(output, list) and len(output) == 1: output = output[0] - kb.locks.outputs.acquire() - threadData.shared.outputs.append(output) - kb.locks.outputs.release() + with kb.locks.outputs: + threadData.shared.outputs.append(output) runThreads(numThreads, errorThread) diff --git a/lib/techniques/union/use.py b/lib/techniques/union/use.py index 3fa3ffe4f..b376bf547 100644 --- a/lib/techniques/union/use.py +++ b/lib/techniques/union/use.py @@ -283,13 +283,11 @@ def unionUse(expression, unpack=True, dump=False): threadData = getCurrentThreadData() while kb.threadContinue: - kb.locks.limits.acquire() - try: - num = threadData.shared.limits.next() - except StopIteration: - break - finally: - kb.locks.limits.release() + with kb.locks.limits: + try: + num = threadData.shared.limits.next() + except StopIteration: + break if Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE): field = expressionFieldsList[0] @@ -309,10 +307,9 @@ def unionUse(expression, unpack=True, dump=False): items = parseUnionPage(output) if isNoneValue(items): continue - kb.locks.value.acquire() - for item in arrayizeValue(items): - threadData.shared.value.append(item) - kb.locks.value.release() + with kb.locks.value: + for item in arrayizeValue(items): + threadData.shared.value.append(item) else: items = output.replace(kb.chars.start, "").replace(kb.chars.stop, "").split(kb.chars.delimiter)