mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-05-08 01:33:48 +03:00
optimizing a bit pyDes module used in Oracle hash cracking
This commit is contained in:
parent
08071f42d0
commit
068ff92dc4
|
@ -1,8 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
#Copyright (c) 2010, Miroslav Stampar <miroslav.stampar@gmail.com>
|
|
||||||
#Added formatXML method
|
|
||||||
|
|
||||||
#Copyright (c) 2010, Chris Hall <chris.hall@mod10.net>
|
#Copyright (c) 2010, Chris Hall <chris.hall@mod10.net>
|
||||||
#All rights reserved.
|
#All rights reserved.
|
||||||
|
|
||||||
|
|
|
@ -419,32 +419,37 @@ class des(_baseDes):
|
||||||
# Turn the strings into integers. Python 3 uses a bytes
|
# Turn the strings into integers. Python 3 uses a bytes
|
||||||
# class, which already has this behaviour.
|
# class, which already has this behaviour.
|
||||||
data = [ord(c) for c in data]
|
data = [ord(c) for c in data]
|
||||||
l = len(data) * 8
|
|
||||||
result = [0] * l
|
result = [False] * len(data) * 8
|
||||||
pos = 0
|
pos = 0
|
||||||
for ch in data:
|
for ch in data:
|
||||||
i = 7
|
result[pos + 0] = (ch & (1 << 7) != 0)
|
||||||
while i >= 0:
|
result[pos + 1] = (ch & (1 << 6) != 0)
|
||||||
if ch & (1 << i) != 0:
|
result[pos + 2] = (ch & (1 << 5) != 0)
|
||||||
result[pos] = 1
|
result[pos + 3] = (ch & (1 << 4) != 0)
|
||||||
else:
|
result[pos + 4] = (ch & (1 << 3) != 0)
|
||||||
result[pos] = 0
|
result[pos + 5] = (ch & (1 << 2) != 0)
|
||||||
pos += 1
|
result[pos + 6] = (ch & (1 << 1) != 0)
|
||||||
i -= 1
|
result[pos + 7] = (ch & (1 << 0) != 0)
|
||||||
|
pos += 8
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def __BitList_to_String(self, data):
|
def __BitList_to_String(self, data):
|
||||||
"""Turn the list of bits -> data, into a string"""
|
"""Turn the list of bits -> data, into a string"""
|
||||||
result = []
|
result = [0] * (len(data) >> 3)
|
||||||
pos = 0
|
pos = 0
|
||||||
c = 0
|
|
||||||
while pos < len(data):
|
while pos < len(data):
|
||||||
c += data[pos] << (7 - (pos % 8))
|
c = data[pos + 0] << (7 - 0)
|
||||||
if (pos % 8) == 7:
|
c += data[pos + 1] << (7 - 1)
|
||||||
result.append(c)
|
c += data[pos + 2] << (7 - 2)
|
||||||
c = 0
|
c += data[pos + 3] << (7 - 3)
|
||||||
pos += 1
|
c += data[pos + 4] << (7 - 4)
|
||||||
|
c += data[pos + 5] << (7 - 5)
|
||||||
|
c += data[pos + 6] << (7 - 6)
|
||||||
|
c += data[pos + 7] << (7 - 7)
|
||||||
|
result[pos >> 3] = c
|
||||||
|
pos += 8
|
||||||
|
|
||||||
if _pythonMajorVersion < 3:
|
if _pythonMajorVersion < 3:
|
||||||
return ''.join([ chr(c) for c in result ])
|
return ''.join([ chr(c) for c in result ])
|
||||||
|
@ -453,7 +458,8 @@ class des(_baseDes):
|
||||||
|
|
||||||
def __permutate(self, table, block):
|
def __permutate(self, table, block):
|
||||||
"""Permutate this block with the specified table"""
|
"""Permutate this block with the specified table"""
|
||||||
return list(map(lambda x: block[x], table))
|
#return map(lambda x: block[x], table)
|
||||||
|
return list(block[x] for x in table)
|
||||||
|
|
||||||
# Transform the secret key, so that it is ready for data processing
|
# Transform the secret key, so that it is ready for data processing
|
||||||
# Create the 16 subkeys, K[1] - K[16]
|
# Create the 16 subkeys, K[1] - K[16]
|
||||||
|
@ -506,7 +512,7 @@ class des(_baseDes):
|
||||||
self.R = self.__permutate(des.__expansion_table, self.R)
|
self.R = self.__permutate(des.__expansion_table, self.R)
|
||||||
|
|
||||||
# Exclusive or R[i - 1] with K[i], create B[1] to B[8] whilst here
|
# Exclusive or R[i - 1] with K[i], create B[1] to B[8] whilst here
|
||||||
self.R = list(map(lambda x, y: x ^ y, self.R, self.Kn[iteration]))
|
self.R = map(lambda x, y: x ^ y, self.R, self.Kn[iteration])
|
||||||
B = [self.R[:6], self.R[6:12], self.R[12:18], self.R[18:24], self.R[24:30], self.R[30:36], self.R[36:42], self.R[42:]]
|
B = [self.R[:6], self.R[6:12], self.R[12:18], self.R[18:24], self.R[24:30], self.R[30:36], self.R[36:42], self.R[42:]]
|
||||||
# Optimization: Replaced below commented code with above
|
# Optimization: Replaced below commented code with above
|
||||||
#j = 0
|
#j = 0
|
||||||
|
@ -542,7 +548,7 @@ class des(_baseDes):
|
||||||
self.R = self.__permutate(des.__p, Bn)
|
self.R = self.__permutate(des.__p, Bn)
|
||||||
|
|
||||||
# Xor with L[i - 1]
|
# Xor with L[i - 1]
|
||||||
self.R = list(map(lambda x, y: x ^ y, self.R, self.L))
|
self.R = map(lambda x, y: x ^ y, self.R, self.L)
|
||||||
# Optimization: This now replaces the below commented code
|
# Optimization: This now replaces the below commented code
|
||||||
#j = 0
|
#j = 0
|
||||||
#while j < len(self.R):
|
#while j < len(self.R):
|
||||||
|
@ -603,7 +609,7 @@ class des(_baseDes):
|
||||||
# Xor with IV if using CBC mode
|
# Xor with IV if using CBC mode
|
||||||
if self.getMode() == CBC:
|
if self.getMode() == CBC:
|
||||||
if crypt_type == des.ENCRYPT:
|
if crypt_type == des.ENCRYPT:
|
||||||
block = list(map(lambda x, y: x ^ y, block, iv))
|
block = map(lambda x, y: x ^ y, block, iv)
|
||||||
#j = 0
|
#j = 0
|
||||||
#while j < len(block):
|
#while j < len(block):
|
||||||
# block[j] = block[j] ^ iv[j]
|
# block[j] = block[j] ^ iv[j]
|
||||||
|
@ -612,7 +618,7 @@ class des(_baseDes):
|
||||||
processed_block = self.__des_crypt(block, crypt_type)
|
processed_block = self.__des_crypt(block, crypt_type)
|
||||||
|
|
||||||
if crypt_type == des.DECRYPT:
|
if crypt_type == des.DECRYPT:
|
||||||
processed_block = list(map(lambda x, y: x ^ y, processed_block, iv))
|
processed_block = map(lambda x, y: x ^ y, processed_block, iv)
|
||||||
#j = 0
|
#j = 0
|
||||||
#while j < len(processed_block):
|
#while j < len(processed_block):
|
||||||
# processed_block[j] = processed_block[j] ^ iv[j]
|
# processed_block[j] = processed_block[j] ^ iv[j]
|
||||||
|
|
|
@ -188,7 +188,7 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
|
||||||
kb.threadContinue = True
|
kb.threadContinue = True
|
||||||
kb.threadException = False
|
kb.threadException = False
|
||||||
|
|
||||||
if conf.get('hashDB', None):
|
if conf.get("hashDB", None):
|
||||||
conf.hashDB.flush(True)
|
conf.hashDB.flush(True)
|
||||||
|
|
||||||
if cleanupFunction:
|
if cleanupFunction:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user