10

How can I calculate NTLM hash of a passowrd in python? Is there any library or sample code?

I want it for writing a NTLM brute force tools with python (Like Cain & Abel )

SuB
  • 2,250
  • 3
  • 22
  • 37

2 Answers2

13

It is actually very quite simple use hashlib here

import hashlib,binascii
hash = hashlib.new('md4', "password".encode('utf-16le')).digest()
print binascii.hexlify(hash)

Or you can additionally use the python-ntlm library here

  • 9
    A slightly more simpler form - `import hashlib print(hashlib.new('md4', "password".encode('utf-16le')).hexdigest())` – user1720897 Dec 25 '15 at 09:05
6

You can make use of the hashlib and binascii modules to compute your NTLM hash:

import binascii, hashlib
input_str = "SOMETHING_AS_INPUT_TO_HASH"
ntlm_hash = binascii.hexlify(hashlib.new('md4', input_str.encode('utf-16le')).digest())
print ntlm_hash
Tuxdude
  • 47,485
  • 15
  • 109
  • 110
  • why not this? http://pythonhosted.org/passlib/lib/passlib.hash.nthash.html not familiar with NTLM hash at already. – CppLearner Mar 24 '13 at 20:50
  • 1
    `passlib` is a separate python package, but `binascii` and `hashlib` are part of the standard python library. Not saying you should not use `passlib`, it is upto the author's preference. There are other libraries as well like [`python-ntlm`](https://pypi.python.org/pypi/python-ntlm). – Tuxdude Mar 24 '13 at 20:57
  • Thanks. interesting how OP checked the other guy. He just copy and paste from an online source code and you being the first one didn't get checked. – CppLearner Mar 25 '13 at 04:35