Tags: rev
Rating:
```py
# https://github.com/crappycrypto/wincrypto/blob/master/wincrypto/native.py
from ctypes import FormatError, GetLastError
from ctypes import windll, c_void_p, byref, create_string_buffer, c_int
import struct
from wincrypto.constants import HP_ALGID, HP_HASHSIZE, KP_KEYLEN, KP_ALGID, CRYPT_EXPORTABLE
PROV_RSA_FULL = 1
PROV_RSA_AES = 24
CRYPT_NEWKEYSET = 8
NTE_BAD_KEYSET = 0x80090016
def assert_success(success):
if not success:
raise AssertionError(FormatError())
def CryptAcquireContext():
hprov = c_void_p()
success = windll.advapi32.CryptAcquireContextA(byref(hprov), 0, 0, PROV_RSA_AES, 0)
if not success and GetLastError() & 0xffffffff == NTE_BAD_KEYSET:
success = windll.advapi32.CryptAcquireContextA(byref(hprov), 0, 0, PROV_RSA_AES, CRYPT_NEWKEYSET)
assert_success(success)
return hprov
# def CryptReleaseContext(hprov):
# success = windll.advapi32.CryptReleaseContext(hprov, 0)
# assert_success(success)
# def CryptImportKey(hprov, keyblob, hPubKey=0):
# hkey = c_void_p()
# success = windll.advapi32.CryptImportKey(hprov, keyblob, len(keyblob), hPubKey, 0, byref(hkey))
# assert_success(success)
# return hkey
# def CryptExportKey(hkey, hexpkey, blobType):
# # determine output buffer length
# bdatalen = c_int(0)
# success = windll.advapi32.CryptExportKey(hkey, hexpkey, blobType, 0, 0, byref(bdatalen))
# assert_success(success)
# # export key
# bdata = create_string_buffer(b'', bdatalen.value)
# success = windll.advapi32.CryptExportKey(hkey, hexpkey, blobType, 0, bdata, byref(bdatalen))
# assert_success(success)
# return bdata.raw[:bdatalen.value]
# def CryptDestroyKey(hkey):
# success = windll.advapi32.CryptDestroyKey(hkey)
# assert_success(success)
# def CryptDecrypt(hkey, encrypted_data):
# bdata = create_string_buffer(encrypted_data)
# bdatalen = c_int(len(encrypted_data))
# success = windll.advapi32.CryptDecrypt(hkey, 0, 1, 0, bdata, byref(bdatalen))
# assert_success(success)
# return bdata.raw[:bdatalen.value]
# def CryptEncrypt(hkey, plain_data):
# # determine output buffer length
# bdatalen_test = c_int(len(plain_data))
# success = windll.advapi32.CryptEncrypt(hkey, 0, 1, 0, 0, byref(bdatalen_test), len(plain_data))
# assert_success(success)
# out_buf_len = bdatalen_test.value
# # encrypt data
# bdata = create_string_buffer(plain_data, out_buf_len)
# bdatalen = c_int(len(plain_data))
# success = windll.advapi32.CryptEncrypt(hkey, 0, 1, 0, bdata, byref(bdatalen), out_buf_len)
# assert_success(success)
# return bdata.raw[:bdatalen.value]
# def CryptGetKeyParam(hkey, dwparam):
# # determine output buffer length
# bdatalen = c_int(0)
# success = windll.advapi32.CryptGetKeyParam(hkey, dwparam, 0, byref(bdatalen), 0)
# assert_success(success)
# # get hash param
# bdata = create_string_buffer(b'', bdatalen.value)
# success = windll.advapi32.CryptGetKeyParam(hkey, dwparam, bdata, byref(bdatalen), 0)
# assert_success(success)
# result = bdata.raw[:bdatalen.value]
# if dwparam in [KP_KEYLEN, KP_ALGID]:
# result = struct.unpack('I', result)[0]
# return result
def CryptCreateHash(hProv, Algid):
hCryptHash = c_void_p()
success = windll.advapi32.CryptCreateHash(hProv, Algid, 0, None, byref(hCryptHash))
assert_success(success)
return hCryptHash
def CryptHashData(hHash, data):
bdata = create_string_buffer(data)
dwdatalen = c_int(len(data))
success = windll.advapi32.CryptHashData(hHash, bdata, dwdatalen, 0)
assert_success(success)
def CryptGetHashParam(hHash, dwParam):
# determine output buffer length
bdatalen = c_int(0)
success = windll.advapi32.CryptGetHashParam(hHash, dwParam, 0, byref(bdatalen), 0)
assert_success(success)
# get hash param
bdata = create_string_buffer(b'', bdatalen.value)
success = windll.advapi32.CryptGetHashParam(hHash, dwParam, bdata, byref(bdatalen), 0)
assert_success(success)
result = bdata.raw[:bdatalen.value]
if dwParam in [HP_ALGID, HP_HASHSIZE]:
result = struct.unpack('I', result)[0]
return result
def CryptDestroyHash(hCryptHash):
success = windll.advapi32.CryptDestroyHash(hCryptHash)
assert_success(success)
# def CryptDeriveKey(hProv, Algid, hBaseData):
# hkey = c_void_p()
# success = windll.advapi32.CryptDeriveKey(hProv, Algid, hBaseData, CRYPT_EXPORTABLE, byref(hkey))
# assert_success(success)
# return hkey
l = [ 0x33, 0x12, 0x95, 0x67, 0xE0, 0xBD, 0x78, 0x7E, 0xFB, 0x15, 0xA2, 0x63, 0x07, 0xE5, 0x31, 0x1E, 0x06, 0xBA, 0x66, 0xE3, 0xB8, 0xDB, 0xC2, 0x20, 0x6A, 0xD5, 0x9F, 0x99, 0x78, 0x0A, 0x4D, 0x78, 0xDD, 0x19, 0x16, 0x96, 0xE1, 0x5E, 0x2E, 0xE2, 0x93, 0x41, 0x0D, 0x02, 0x45, 0x4C, 0x5F, 0x94, 0x61, 0xA2, 0x24, 0x9D, 0xEE, 0x6D, 0x57, 0xC7, 0x5F, 0x26, 0x4E, 0xAE, 0xB8, 0x3A, 0x37, 0x82, 0xE7, 0x5B, 0x11, 0xDA, 0x69, 0x3D, 0x7B, 0xB5, 0x27, 0x39, 0x85, 0xDC, 0xF9, 0xF0, 0x27, 0x29, 0x45, 0x5D, 0xA7, 0xE7, 0xC8, 0x0E, 0x54, 0xA0, 0x61, 0x5E, 0x00, 0xEC, 0x2A, 0xE7, 0x6D, 0x8E, 0x04, 0x24, 0x9E, 0x0C, 0x25, 0x8E, 0x1A, 0x4E, 0x43, 0xCF, 0xDA, 0xE2, 0x91, 0xA8, 0x35, 0xCD, 0x15, 0x73, 0x5F, 0x65, 0x0B, 0xBB, 0xBA, 0x04, 0x65, 0xAD, 0xA1, 0xCD, 0x98, 0x46, 0x62, 0x2A, 0xE4, 0x22, 0x3E, 0xD2, 0x0D, 0x7E, 0xA5, 0x74, 0x0A, 0x32, 0x6E, 0x2B, 0x26, 0x8C, 0xA6, 0xDB, 0x91, 0xD0, 0x41, 0xCF, 0x51, 0x94, 0xF5, 0x77, 0xE3, 0x93, 0xA8, 0xBA, 0x3B, 0x85, 0xD8, 0xE9, 0x8B, 0x53, 0x63, 0x9F, 0x15, 0x2C, 0x8F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, 0xA2, 0x96, 0xD2, 0x24, 0xF2, 0x85, 0xC6, 0x7B, 0xEE, 0x93, 0xC3, 0x0F, 0x8A, 0x30, 0x91, 0x57, 0xF0, 0xDA, 0xA3, 0x5D, 0xC5, 0xB8, 0x7E, 0x41, 0x0B, 0x78, 0x63, 0x0A, 0x09, 0xCF, 0xC7, 0x96, 0xA2, 0x96, 0xD2, 0x24, 0xF2, 0x85, 0xC6, 0x7B, 0xEE, 0x93, 0xC3, 0x0F, 0x8A, 0x30, 0x91, 0x57, 0xF0, 0xDA, 0xA3, 0x5D, 0xC5, 0xB8, 0x7E, 0x41, 0x0B, 0x78, 0x63, 0x0A, 0x09, 0xCF, 0xC7, 0x96, 0xA2, 0x96, 0xD2, 0x24, 0xF2, 0x85, 0xC6, 0x7B, 0xEE, 0x93, 0xC3, 0x0F, 0x8A, 0x30, 0x91, 0x57, 0xF0, 0xDA, 0xA3, 0x5D, 0xC5, 0xB8, 0x7E, 0x41, 0x0B, 0x78, 0x63, 0x0A, 0x09, 0xCF, 0xC7, 0x96, 0xA2, 0x96, 0xD2, 0x24, 0xF2, 0x85, 0xC6, 0x7B, 0xEE, 0x93, 0xC3, 0x0F, 0x8A, 0x30, 0x91, 0x57, 0xF0, 0xDA, 0xA3, 0x5D, 0xC5, 0xB8, 0x7E, 0x41, 0x0B, 0x78, 0x63, 0x0A, 0x09, 0xCF, 0xC7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
x = 1
s = []
for i in range(32):
xx = []
for j in range(32):
xx.append(l[32*i+j])
s.append(xx)
hprov = CryptAcquireContext()
Algid = 0x0000800c
import string
import sys
w = ''
x = 0
while True:
for i in string.printable:
A = 0
for j in string.printable:
hHash = CryptCreateHash(hprov, Algid)
CryptHashData(hHash, f'{i}{j}'.encode())
dwParam = 2
r = CryptGetHashParam(hHash, dwParam)
if bytes(s[x]) == r:
w += f'{i}{j}'
A = 1
x += 1
CryptDestroyHash(hHash)
break
CryptDestroyHash(hHash)
if A:
break
print(w)
if '}' in w:
break
# zer0pts{m0d1fy1ng_PE_1mp0rts_1s_4n_34sy_0bfusc4t10n}
```