Example #1
0
def nt_password_hash(passwd,pad_to_21_bytes=True):
    """
   NtPasswordHash(
   IN  0-to-256-unicode-char Password,
   OUT 16-octet              PasswordHash )
   {
      /*
       * Use the MD4 algorithm [5] to irreversibly hash Password
       * into PasswordHash.  Only the password is hashed without
       * including any terminating 0.
       */
    """

    # we have to have UNICODE password
    pw = utils.str2unicode(passwd)

    # do MD4 hash
    md4_context = md4.new()
    md4_context.update(pw)

    res = md4_context.digest()

    if pad_to_21_bytes:
        # addig zeros to get 21 bytes string
	res = res + '\000\000\000\000\000'

    return res
Example #2
0
def nt_password_hash(passwd, pad_to_21_bytes=True):
    """
   NtPasswordHash(
   IN  0-to-256-unicode-char Password,
   OUT 16-octet              PasswordHash )
   {
      /*
       * Use the MD4 algorithm [5] to irreversibly hash Password
       * into PasswordHash.  Only the password is hashed without
       * including any terminating 0.
       */
    """

    # we have to have UNICODE password
    pw = utils.str2unicode(passwd)

    # do MD4 hash
    md4_context = md4.new()
    md4_context.update(pw)

    res = md4_context.digest()

    if pad_to_21_bytes:
        # addig zeros to get 21 bytes string
        res = res + '\000\000\000\000\000'

    return res
 def _findmatch(self):
     "return a match tuple, or raise KeyError if there isn't one"
     # get the rollsum digest, calculating sig if needed
     try:
         sig=self.sig.digest()
     except AttributeError:
         self.sig=rollsum.new(buffer(self.data,self.pos,self.blocksize))
         sig=self.sig.digest()
     # get the matching offset, if it exists, otherwise raise KeyError
     sumtable=self.sigtable[sig]
     sum=md4.new(buffer(self.data,self.pos,self.blocksize))
     return sumtable[sum.digest()],self.sig.count
Example #4
0
 def _findmatch(self):
     "return a match tuple, or raise KeyError if there isn't one"
     # get the adler32 digest, calculating sig if needed
     try:
         sig = self.sig.digest()
     except AttributeError:
         self.sig = adler32.new(buffer(self.data, self.pos, self.blocksize))
         sig = self.sig.digest()
     # get the matching offset, if it exists, otherwise raise KeyError
     sumtable = self.sigtable[sig]
     sum = md4.new(buffer(self.data, self.pos, self.blocksize))
     return sumtable[sum.digest()], self.sig.count
def calcsig(oldfile,blocksize=BLOCK_SIZE):
    "Calculates and returns a signature"
    offset=0
    sigtable={}
    data=oldfile.read(blocksize)
    while data:
        sum=md4.new(data).digest()
        sig=rollsum.new(data).digest()
        try:
            sigtable[sig][sum]=offset
        except KeyError:
            sigtable[sig]={}
            sigtable[sig][sum]=offset
        offset=offset+len(data)
        data=oldfile.read(blocksize)
    return (offset,blocksize,sigtable)
Example #6
0
def create_NT_hashed_password(passwd):
    "create NT hashed password"

    # we have to have UNICODE password
    pw = utils.str2unicode(passwd)

    # do MD4 hash
    md4_context = md4.new()
    md4_context.update(pw)

    res = md4_context.digest()

    # addig zeros to get 21 bytes string
    res = res + '\000\000\000\000\000'

    return res
Example #7
0
def calcsig(oldfile, blocksize=BLOCK_SIZE):
    "Calculates and returns a signature"
    offset = 0
    sigtable = {}
    data = oldfile.read(blocksize)
    while data:
        sum = md4.new(data).digest()
        sig = adler32.new(data).digest()
        try:
            sigtable[sig][sum] = offset
        except KeyError:
            sigtable[sig] = {}
            sigtable[sig][sum] = offset
        offset = offset + len(data)
        data = oldfile.read(blocksize)
    return (offset, blocksize, sigtable)
Example #8
0
def create_NT_hashed_password(passwd):
    "create NT hashed password"

    # we have to have UNICODE password
    pw = ntlmutils.str2unicode(passwd)

    # do MD4 hash
    md4_context = md4.new()
    md4_context.update(pw)

    res = md4_context.digest()

    # addig zeros to get 21 bytes string
    res = res + '\000\000\000\000\000'

    return res
Example #9
0
def hash_nt_password_hash(password_hash):
    """
   HashNtPasswordHash(
   IN  16-octet PasswordHash,
   OUT 16-octet PasswordHashHash )
   {
      /*
       * Use the MD4 algorithm [5] to irreversibly hash
       * PasswordHash into PasswordHashHash.
       */
   }
    """
    md4_context = md4.new()
    md4_context.update(password_hash)

    res = md4_context.digest()
    return res
Example #10
0
def hash_nt_password_hash(password_hash):
    """
   HashNtPasswordHash(
   IN  16-octet PasswordHash,
   OUT 16-octet PasswordHashHash )
   {
      /*
       * Use the MD4 algorithm [5] to irreversibly hash
       * PasswordHash into PasswordHashHash.
       */
   }
    """
    md4_context = md4.new()
    md4_context.update(password_hash)

    res = md4_context.digest()
    return res
Example #11
0
def md4_hash(pw):
    md4_context = md4.new()
    md4_context.update(pw)
    res = md4_context.digest()
    return res
Example #12
0
def hash_nt_password_hash(password_hash):
    """HashNtPasswordHash"""
    md4_context = md4.new()
    md4_context.update(password_hash)
    return md4_context.digest()
Example #13
0
def nt_password_hash(passwd):
    """NtPasswordHash"""
    pw = utils.str2unicode(passwd)
    md4_context = md4.new()
    md4_context.update(pw)
    return md4_context.digest()
Example #14
0
import base64
import re
try:
    import hashlib
    hash_md4 = hashlib.new("md4")
    hash_md5 = hashlib.md5()
except ImportError:
    # for Python << 2.5
    import md4
    import md5
    hash_md4 = md4.new()
    hash_md5 = md5.new()

# Import SOCKS module if it exists, else standard socket module socket
try:
    import SOCKS
    socket = SOCKS
    del SOCKS  # import SOCKS as socket
    from socket import getfqdn
    socket.getfqdn = getfqdn
    del getfqdn
except ImportError:
    import socket
from socket import _GLOBAL_DEFAULT_TIMEOUT

__all__ = ["rsync"]

# The standard rsync server control port
RSYNC_PORT = 873
# The sizehint parameter passed to readline() calls
MAXLINE = 8192
Example #15
0
import socket
from printers import printPink,printRed,printGreen
from multiprocessing.dummy import Pool
socket.setdefaulttimeout(10)
import re
import time
import base64
try:
    import hashlib
    hash_md4 = hashlib.new("md4")
    hash_md5 = hashlib.md5()
except ImportError:
    # for Python << 2.5
    import md4
    import md5
    hash_md4 = md4.new()
    hash_md5 = md5.new()

# Import SOCKS module if it exists, else standard socket module socket
try:
    import SOCKS; socket = SOCKS; del SOCKS # import SOCKS as socket
    from socket import getfqdn; socket.getfqdn = getfqdn; del getfqdn
except ImportError:
    import socket
from socket import _GLOBAL_DEFAULT_TIMEOUT

__all__ = ["rsync"]



# The standard rsync server control port
Example #16
0
def hash_nt_password_hash(password_hash):
    """HashNtPasswordHash"""
    md4_context = md4.new()
    md4_context.update(password_hash)
    return md4_context.digest()
Example #17
0
def nt_password_hash(passwd):
    """NtPasswordHash"""
    pw = utils.str2unicode(passwd)
    md4_context = md4.new()
    md4_context.update(pw)
    return md4_context.digest()
Example #18
0
    import md4
except ImportError:
    print 'MD4 module not available'
else:
    print 'MD4:'
    try:
        import data
    except ImportError:
        print '  Test suite data not available'
    else:
        print '  Verifying against test suite...'
        for text, hash in data.md4:
            HashCompare(md4, text, hash)
        print '  Completed'
        import time
        obj = md4.new()
        start = time.time()
        s = obj.update(teststr)
        end = time.time()
        print '  Benchmark for 128K: ', 128 / (end - start), 'K/sec'
        del obj

# Test/benchmark MD5 hash algorithm ; the test data is taken from
# RFC1321, "The MD5 Message-Digest Algorithm"
try:
    import md5
except ImportError:
    print 'MD5 module not available'
else:
    print 'MD5:'
    try: