Skip to content

Commit cd76f88

Browse files
committed
Speeding up oracle_old_passwd if PyCrypto available
1 parent 5b2c0f0 commit cd76f88

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from thirdparty.six import unichr as _unichr
2121

2222
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
23-
VERSION = "1.6.4.0"
23+
VERSION = "1.6.4.1"
2424
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2525
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2626
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

lib/utils/hash.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
except: # removed ImportError because of https://github.com/sqlmapproject/sqlmap/issues/3171
1313
from thirdparty.fcrypt.fcrypt import crypt
1414

15+
try:
16+
from Crypto.Cipher.DES import MODE_CBC as CBC
17+
from Crypto.Cipher.DES import new as des
18+
except:
19+
from thirdparty.pydes.pyDes import CBC
20+
from thirdparty.pydes.pyDes import des
21+
1522
_multiprocessing = None
1623

1724
import base64
@@ -80,8 +87,6 @@
8087
from lib.core.wordlist import Wordlist
8188
from thirdparty import six
8289
from thirdparty.colorama.initialise import init as coloramainit
83-
from thirdparty.pydes.pyDes import CBC
84-
from thirdparty.pydes.pyDes import des
8590
from thirdparty.six.moves import queue as _queue
8691

8792
def mysql_passwd(password, uppercase=True):
@@ -219,14 +224,21 @@ def oracle_old_passwd(password, username, uppercase=True): # prior to version '
219224
'F894844C34402B67'
220225
"""
221226

222-
IV, pad = "\0" * 8, "\0"
227+
IV, pad = b"\0" * 8, b"\0"
223228

224229
unistr = b"".join((b"\0" + _.encode(UNICODE_ENCODING)) if ord(_) < 256 else _.encode(UNICODE_ENCODING) for _ in (username + password).upper())
225230

226-
cipher = des(decodeHex("0123456789ABCDEF"), CBC, IV, pad)
227-
encrypted = cipher.encrypt(unistr)
228-
cipher = des(encrypted[-8:], CBC, IV, pad)
229-
encrypted = cipher.encrypt(unistr)
231+
if des.__module__ == "Crypto.Cipher.DES":
232+
unistr += b"\0" * ((8 - len(unistr) % 8) & 7)
233+
cipher = des(decodeHex("0123456789ABCDEF"), CBC, iv=IV)
234+
encrypted = cipher.encrypt(unistr)
235+
cipher = des(encrypted[-8:], CBC, iv=IV)
236+
encrypted = cipher.encrypt(unistr)
237+
else:
238+
cipher = des(decodeHex("0123456789ABCDEF"), CBC, IV, pad)
239+
encrypted = cipher.encrypt(unistr)
240+
cipher = des(encrypted[-8:], CBC, IV, pad)
241+
encrypted = cipher.encrypt(unistr)
230242

231243
retVal = encodeHex(encrypted[-8:], binary=False)
232244

0 commit comments

Comments
 (0)