Durante la hora del almuerzo estuve mirando otro reto de los que dejo Ricardo, esta vez fue el Dark-Puzzle_KeygenMe y este me parece que estaba mucho mas fácil, asi que el post no sera muy extenso, solo presento el codigo comentado, el resumen del proceso y el keygen.
Se trata de una aplicación de consola que presenta ese MessageBox al inicio (aqui se reporta otro nombre para el keygenme, pero lo seguire llamando darkpuzzle). Valida de cierto modo el email, pero finalmente no lo usa para calcular el serial.
Desde IDA Free, entramos directamente en el start() y no necesitaremos nada mas... Por comodidad marque como input() y print() algunas funciones que precan obvias, y cambie la representacion de algunas variables para que aparezcan como chars:
.text:00401000 ; Attributes: noreturn
.text:00401000
.text:00401000 public start
.text:00401000 start proc near
.text:00401000 push 0 ; uType
.text:00401002 push offset Caption ; "ItSecurity.ma KeygenMe (RESTRICTED PATC"...
.text:00401007 push offset Text ; "Itsecurity.ma KeygenME Coded by Souhail"...
.text:0040100C push 0 ; hWnd
.text:0040100E call MessageBoxA
.text:00401013 push offset aPleaseTypeYour ; "Please type your e-mail: "
.text:00401018 call print
.text:0040101D push 0C8h ; nNumberOfBytesToRead
.text:00401022 push offset email ; lpBuffer
.text:00401027 call input
.text:0040102C lea eax, email
.text:00401032 xor edx, edx
.text:00401034 xor ecx, ecx
.text:00401036
.text:00401036 loc_401036: ; CODE XREF: start+47 j
.text:00401036 mov bl, [eax]
.text:00401038 cmp bl, 40h
.text:0040103B jz short loc_401049
.text:0040103D cmp bl, dl
.text:0040103F jz loc_4011EB
.text:00401045 inc ecx
.text:00401046 inc eax
.text:00401047 jmp short loc_401036
.text:00401049 ; ---------------------------------------------------------------------------
.text:00401049
.text:00401049 loc_401049: ; CODE XREF: start+3B j
.text:00401049 cmp cl, 3
.text:0040104C jle loc_40120B
.text:00401052 push offset aPleaseEnterAVa ; "Please Enter a valid serial: "
.text:00401057 call print
.text:0040105C push 0C8h ; nNumberOfBytesToRead
.text:00401061 push offset serial ; lpBuffer
.text:00401066 call input
.text:0040106B push offset serial ; lpString
.text:00401070 call lstrlenA
.text:00401075 cmp eax, 17h
.text:00401078 jnz mala
.text:0040107E lea eax, serial
.text:00401084 xor ebx, ebx
.text:00401086 mov ebx, [eax]
.text:00401088 cmp ebx, '-STI' ; primer bloque
.text:0040108E jnz mala
.text:00401094 add eax, 8
.text:00401097 cmp byte ptr [eax], '-' ; separa el bloque
.text:0040109A jnz mala
.text:004010A0 xor ecx, ecx
.text:004010A2 xor edx, edx
.text:004010A4 mov cl, 3
.text:004010A6 mov dl, 5
.text:004010A8
.text:004010A8 loc_4010A8: ; CODE XREF: start+AF j
.text:004010A8 add eax, edx
.text:004010AA dec cl
.text:004010AC cmp byte ptr [eax], 2Dh ; ITS-????-????-????-????
.text:004010AF jz short loc_4010A8
.text:004010B1 cmp cl, 0
.text:004010B4 jnz mala
.text:004010BA lea eax, serial
.text:004010C0 add eax, 4 ; posicion 4
.text:004010C3 mov ebx, [eax]
.text:004010C5 lea ecx, pos4
.text:004010CB mov [ecx], ebx
.text:004010CD add eax, 5 ; posicion 9
.text:004010D0 mov ebx, [eax]
.text:004010D2 lea ecx, pos9
.text:004010D8 mov [ecx], ebx
.text:004010DA add eax, 5 ; posicion 14
.text:004010DD mov ebx, [eax]
.text:004010DF lea ecx, pos14
.text:004010E5 mov [ecx], ebx
.text:004010E7 add eax, 5 ; posicion 19
.text:004010EA mov ebx, [eax]
.text:004010EC lea ecx, pos19
.text:004010F2 mov [ecx], ebx
.text:004010F4 xor eax, eax
.text:004010F6 xor ebx, ebx
.text:004010F8 xor edx, edx
.text:004010FA xor ecx, ecx
.text:004010FC lea eax, pos4
.text:00401102 mov eax, [eax]
.text:00401104 sub eax, 30303030h ; numericos, no hexas
.text:00401109 lea edx, pos4
.text:0040110F mov [edx], eax
.text:00401111 mov bl, [edx]
.text:00401113 mov cl, [edx+1]
.text:00401116 add bl, cl
.text:00401118 mov cl, [edx+2]
.text:0040111B add bl, cl
.text:0040111D mov cl, [edx+3]
.text:00401120 add bl, cl
.text:00401122 cmp bl, 10h ; la suma del bloque
.text:00401122 ; es 16
.text:00401125 jnz mala
.text:0040112B lea edx, pos9 ; otro bloque
.text:00401131 mov bl, [edx]
.text:00401133 cmp bl, 'O' ; siguiente bloque en 'O'
.text:00401136 jnz mala
.text:0040113C mov cl, [edx+1]
.text:0040113F add bl, cl
.text:00401141 mov cl, [edx+2]
.text:00401144 add bl, cl
.text:00401146 mov cl, [edx+3]
.text:00401149 sub bl, cl
.text:0040114B cmp bl, 8Fh ; 'O' + 2do + 3ro - 4to
.text:0040114E jnz short mala
.text:00401150 lea eax, pos14 ; otro bloque
.text:00401156 mov eax, [eax]
.text:00401158 sub eax, 30303030h ; numericos, no hexas
.text:0040115D lea edx, pos14
.text:00401163 mov [edx], eax
.text:00401165 mov bl, [edx]
.text:00401167 mov cl, [edx+1]
.text:0040116A add bl, cl
.text:0040116C mov cl, [edx+2]
.text:0040116F add bl, cl
.text:00401171 mov cl, [edx+3]
.text:00401174 sub cl, 2
.text:00401177 add bl, cl
.text:00401179 cmp bl, 10h ; suma - 2 es 16
.text:0040117C jnz short mala
.text:0040117E lea eax, pos19 ; otro bloque
.text:00401184 mov eax, [eax]
.text:00401186 sub eax, 30303030h ; numericos, no hexas
.text:0040118B lea edx, pos19
.text:00401191 mov [edx], eax
.text:00401193 mov bl, [edx]
.text:00401195 mov cl, [edx+1]
.text:00401198 add bl, cl
.text:0040119A mov cl, [edx+2]
.text:0040119D add bl, cl
.text:0040119F mov cl, [edx+3]
.text:004011A2 add bl, cl
.text:004011A4 cmp bl, 12h ; suma es 18
.text:004011A7 jnz short mala
.text:004011A9 jmp short $+2
.text:004011AB push offset aValidSerialPre ; "Valid Serial (Press Enter To Exit)"
.text:004011B0 call print
.text:004011B5 push 0C8h ; nNumberOfBytesToRead
.text:004011BA push offset exit ; lpBuffer
.text:004011BF call input
.text:004011C4 push 0 ; uExitCode
.text:004011C6 call ExitProcess
.text:004011CB ; ---------------------------------------------------------------------------
.text:004011CB
.text:004011CB mala: ; CODE XREF: start+78 j
.text:004011CB ; start+8E j ...
.text:004011CB push offset aInvalidSerialP ; "Invalid Serial (Press Enter To Exit)"
.text:004011D0 call print
.text:004011D5 push 0C8h ; nNumberOfBytesToRead
.text:004011DA push offset exit ; lpBuffer
.text:004011DF call input
.text:004011E4 push 0 ; uExitCode
.text:004011E6 call ExitProcess
.text:004011EB ; ---------------------------------------------------------------------------
.text:004011EB
.text:004011EB loc_4011EB: ; CODE XREF: start+3F j
.text:004011EB push offset aPleaseInsertAV ; "Please Insert a Valid Mail Address (Pre"...
.text:004011F0 call print
.text:004011F5 push 0C8h ; nNumberOfBytesToRead
.text:004011FA push offset exit ; lpBuffer
.text:004011FF call input
.text:00401204 push 0 ; uExitCode
.text:00401206 call ExitProcess
.text:0040120B ; ---------------------------------------------------------------------------
.text:0040120B
.text:0040120B loc_40120B: ; CODE XREF: start+4C j
.text:0040120B push offset aPleaseEnterAnE ; "Please Enter an email with 4 Characters"...
.text:00401210 call print
.text:00401215 push 0C8h ; nNumberOfBytesToRead
.text:0040121A push offset exit ; lpBuffer
.text:0040121F call input
.text:00401224 push 0 ; uExitCode
.text:00401226 call ExitProcess
.text:00401226 start endp
.text:00401226
.text:00401226 ; ---------------------------------------------------------------------------
.text:0040122B align 4
.text:0040122C ; [00000006 BYTES: COLLAPSED FUNCTION MessageBoxA. PRESS KEYPAD "+" TO EXPAND]
.text:00401232 align 4
.text:00401234
Se trata de una aplicación de consola que presenta ese MessageBox al inicio (aqui se reporta otro nombre para el keygenme, pero lo seguire llamando darkpuzzle). Valida de cierto modo el email, pero finalmente no lo usa para calcular el serial.
Desde IDA Free, entramos directamente en el start() y no necesitaremos nada mas... Por comodidad marque como input() y print() algunas funciones que precan obvias, y cambie la representacion de algunas variables para que aparezcan como chars:
.text:00401000 ; Attributes: noreturn
.text:00401000
.text:00401000 public start
.text:00401000 start proc near
.text:00401000 push 0 ; uType
.text:00401002 push offset Caption ; "ItSecurity.ma KeygenMe (RESTRICTED PATC"...
.text:00401007 push offset Text ; "Itsecurity.ma KeygenME Coded by Souhail"...
.text:0040100C push 0 ; hWnd
.text:0040100E call MessageBoxA
.text:00401013 push offset aPleaseTypeYour ; "Please type your e-mail: "
.text:00401018 call print
.text:0040101D push 0C8h ; nNumberOfBytesToRead
.text:00401022 push offset email ; lpBuffer
.text:00401027 call input
.text:0040102C lea eax, email
.text:00401032 xor edx, edx
.text:00401034 xor ecx, ecx
.text:00401036
.text:00401036 loc_401036: ; CODE XREF: start+47 j
.text:00401036 mov bl, [eax]
.text:00401038 cmp bl, 40h
.text:0040103B jz short loc_401049
.text:0040103D cmp bl, dl
.text:0040103F jz loc_4011EB
.text:00401045 inc ecx
.text:00401046 inc eax
.text:00401047 jmp short loc_401036
.text:00401049 ; ---------------------------------------------------------------------------
.text:00401049
.text:00401049 loc_401049: ; CODE XREF: start+3B j
.text:00401049 cmp cl, 3
.text:0040104C jle loc_40120B
.text:00401052 push offset aPleaseEnterAVa ; "Please Enter a valid serial: "
.text:00401057 call print
.text:0040105C push 0C8h ; nNumberOfBytesToRead
.text:00401061 push offset serial ; lpBuffer
.text:00401066 call input
.text:0040106B push offset serial ; lpString
.text:00401070 call lstrlenA
.text:00401075 cmp eax, 17h
.text:00401078 jnz mala
.text:0040107E lea eax, serial
.text:00401084 xor ebx, ebx
.text:00401086 mov ebx, [eax]
.text:00401088 cmp ebx, '-STI' ; primer bloque
.text:0040108E jnz mala
.text:00401094 add eax, 8
.text:00401097 cmp byte ptr [eax], '-' ; separa el bloque
.text:0040109A jnz mala
.text:004010A0 xor ecx, ecx
.text:004010A2 xor edx, edx
.text:004010A4 mov cl, 3
.text:004010A6 mov dl, 5
.text:004010A8
.text:004010A8 loc_4010A8: ; CODE XREF: start+AF j
.text:004010A8 add eax, edx
.text:004010AA dec cl
.text:004010AC cmp byte ptr [eax], 2Dh ; ITS-????-????-????-????
.text:004010AF jz short loc_4010A8
.text:004010B1 cmp cl, 0
.text:004010B4 jnz mala
.text:004010BA lea eax, serial
.text:004010C0 add eax, 4 ; posicion 4
.text:004010C3 mov ebx, [eax]
.text:004010C5 lea ecx, pos4
.text:004010CB mov [ecx], ebx
.text:004010CD add eax, 5 ; posicion 9
.text:004010D0 mov ebx, [eax]
.text:004010D2 lea ecx, pos9
.text:004010D8 mov [ecx], ebx
.text:004010DA add eax, 5 ; posicion 14
.text:004010DD mov ebx, [eax]
.text:004010DF lea ecx, pos14
.text:004010E5 mov [ecx], ebx
.text:004010E7 add eax, 5 ; posicion 19
.text:004010EA mov ebx, [eax]
.text:004010EC lea ecx, pos19
.text:004010F2 mov [ecx], ebx
.text:004010F4 xor eax, eax
.text:004010F6 xor ebx, ebx
.text:004010F8 xor edx, edx
.text:004010FA xor ecx, ecx
.text:004010FC lea eax, pos4
.text:00401102 mov eax, [eax]
.text:00401104 sub eax, 30303030h ; numericos, no hexas
.text:00401109 lea edx, pos4
.text:0040110F mov [edx], eax
.text:00401111 mov bl, [edx]
.text:00401113 mov cl, [edx+1]
.text:00401116 add bl, cl
.text:00401118 mov cl, [edx+2]
.text:0040111B add bl, cl
.text:0040111D mov cl, [edx+3]
.text:00401120 add bl, cl
.text:00401122 cmp bl, 10h ; la suma del bloque
.text:00401122 ; es 16
.text:00401125 jnz mala
.text:0040112B lea edx, pos9 ; otro bloque
.text:00401131 mov bl, [edx]
.text:00401133 cmp bl, 'O' ; siguiente bloque en 'O'
.text:00401136 jnz mala
.text:0040113C mov cl, [edx+1]
.text:0040113F add bl, cl
.text:00401141 mov cl, [edx+2]
.text:00401144 add bl, cl
.text:00401146 mov cl, [edx+3]
.text:00401149 sub bl, cl
.text:0040114B cmp bl, 8Fh ; 'O' + 2do + 3ro - 4to
.text:0040114E jnz short mala
.text:00401150 lea eax, pos14 ; otro bloque
.text:00401156 mov eax, [eax]
.text:00401158 sub eax, 30303030h ; numericos, no hexas
.text:0040115D lea edx, pos14
.text:00401163 mov [edx], eax
.text:00401165 mov bl, [edx]
.text:00401167 mov cl, [edx+1]
.text:0040116A add bl, cl
.text:0040116C mov cl, [edx+2]
.text:0040116F add bl, cl
.text:00401171 mov cl, [edx+3]
.text:00401174 sub cl, 2
.text:00401177 add bl, cl
.text:00401179 cmp bl, 10h ; suma - 2 es 16
.text:0040117C jnz short mala
.text:0040117E lea eax, pos19 ; otro bloque
.text:00401184 mov eax, [eax]
.text:00401186 sub eax, 30303030h ; numericos, no hexas
.text:0040118B lea edx, pos19
.text:00401191 mov [edx], eax
.text:00401193 mov bl, [edx]
.text:00401195 mov cl, [edx+1]
.text:00401198 add bl, cl
.text:0040119A mov cl, [edx+2]
.text:0040119D add bl, cl
.text:0040119F mov cl, [edx+3]
.text:004011A2 add bl, cl
.text:004011A4 cmp bl, 12h ; suma es 18
.text:004011A7 jnz short mala
.text:004011A9 jmp short $+2
.text:004011AB push offset aValidSerialPre ; "Valid Serial (Press Enter To Exit)"
.text:004011B0 call print
.text:004011B5 push 0C8h ; nNumberOfBytesToRead
.text:004011BA push offset exit ; lpBuffer
.text:004011BF call input
.text:004011C4 push 0 ; uExitCode
.text:004011C6 call ExitProcess
.text:004011CB ; ---------------------------------------------------------------------------
.text:004011CB
.text:004011CB mala: ; CODE XREF: start+78 j
.text:004011CB ; start+8E j ...
.text:004011CB push offset aInvalidSerialP ; "Invalid Serial (Press Enter To Exit)"
.text:004011D0 call print
.text:004011D5 push 0C8h ; nNumberOfBytesToRead
.text:004011DA push offset exit ; lpBuffer
.text:004011DF call input
.text:004011E4 push 0 ; uExitCode
.text:004011E6 call ExitProcess
.text:004011EB ; ---------------------------------------------------------------------------
.text:004011EB
.text:004011EB loc_4011EB: ; CODE XREF: start+3F j
.text:004011EB push offset aPleaseInsertAV ; "Please Insert a Valid Mail Address (Pre"...
.text:004011F0 call print
.text:004011F5 push 0C8h ; nNumberOfBytesToRead
.text:004011FA push offset exit ; lpBuffer
.text:004011FF call input
.text:00401204 push 0 ; uExitCode
.text:00401206 call ExitProcess
.text:0040120B ; ---------------------------------------------------------------------------
.text:0040120B
.text:0040120B loc_40120B: ; CODE XREF: start+4C j
.text:0040120B push offset aPleaseEnterAnE ; "Please Enter an email with 4 Characters"...
.text:00401210 call print
.text:00401215 push 0C8h ; nNumberOfBytesToRead
.text:0040121A push offset exit ; lpBuffer
.text:0040121F call input
.text:00401224 push 0 ; uExitCode
.text:00401226 call ExitProcess
.text:00401226 start endp
.text:00401226
.text:00401226 ; ---------------------------------------------------------------------------
.text:0040122B align 4
.text:0040122C ; [00000006 BYTES: COLLAPSED FUNCTION MessageBoxA. PRESS KEYPAD "+" TO EXPAND]
.text:00401232 align 4
.text:00401234
La idea es bien simple: el serial tiene una longitud 23 y esta compuesto por cinco bloques separados por guiones, el primer bloque es siempre el mismo "ITS", los demas bloques tiene reglas especificas:
A cada caracter del segundo bloque se le restara 0x30, y los resultados se suman. Esta suma debe dar 16.
Lo mas sencillo es usar solo numeros en este bloque, asi al resta 0x30, estaremos pasando de la representacion en en hex al numero en entero.... Visto asi basta con seleccionar 4 numero al azar cuaya suma de 16, durante mi prueba use cuatro cuatros.
El tercer bloque funciona distinto, primero verificamos que el primer caracter del bloque es una 'O' (no es un cero es uan o mayuscula), luego sumamos el primer, segundo y tercer caracter, y le restamos el cuarto (aqui sumamos sus representaciones, ya que no se resto 0x30 en este paso)... El resultado de estas operaciones debe ser 8F. En este caso pueden usarse solo mayusculas, por ejemplo, como la primera letra era una 'O', yo seleccione una 'M' y una 'G' para el segundo y tercer caracteres del bloque, solo para formar un "OMG", a la suma de las representaciones le resto el valor esperado 8F y obtengo que el cuarto caracter para completar esta cadena debe ser una 'T', para el keygen, es cuestion de elegir dos musculas al zar y calcular la ultima
El cuarto bloque es parecido al primero, se resta 0x30 a cada representacion, asi que usaremos numeros para este bloque, ademas a la suma obtenida se le restan 2, y el resultado es perado, es 16, o en otras palabras la suma del bloque debe dar 18. Para mi prueba simplemente use 4545. PAra el keygen, elegir 4 numeros que sumes 18.
El quinto bloque es muy parecido al anterior, simplemente no se resta el 2, y se compara con 18, directamente. Asi que use el mismo valor del bloque anterior. La misma estrategia sirve para el keygen
Mi serial fue entonces este: ITS-4444-OMGT-4545-4545
El keygen es muy simple:
from random import choice
from string import ascii_uppercase
serial = [ '-' ] * 23
serial[0] = 'I'
serial[1] = 'T'
serial[2] = 'S'
serial[4] = str(choice(range(9)))
serial[5] = str(choice(range(9)))
serial[6] = str(8 - int(serial[4]))
serial[7] = str(8 - int(serial[5]))
serial[9] = 'O'
while serial[12] not in ascii_uppercase:
serial[10] = choice(ascii_uppercase)
serial[11] = choice(ascii_uppercase)
serial[12] = chr(ord(serial[10]) + ord(serial[11]) - 64)
serial[14] = str(choice(range(10)))
serial[15] = str(choice(range(10)))
serial[16] = str(9 - int(serial[14]))
serial[17] = str(9 - int(serial[15]))
serial[19] = str(choice(range(10)))
serial[20] = str(choice(range(10)))
serial[21] = str(9 - int(serial[19]))
serial[22] = str(9 - int(serial[20]))
print( ''.join(serial))
Agregue ese while, porque me parecia que se veian mejor los seriales si el bloque estaba todo en mayúsculas, pero no es necesario realmente,
Veamos algunas salidas:
C:\Python33>python.exe darkpuzzle.py
ITS-6523-OMAN-9504-7227
C:\Python33>python.exe darkpuzzle.py
ITS-4642-OGNU-8712-3267
C:\Python33>python.exe darkpuzzle.py
ITS-3751-OMER-8415-0891
C:\Python33>python.exe darkpuzzle.py
ITS-5038-OPBR-0297-9702
Y al probarlas vemos que todas son correctas, asi que eso es todo por hoy y ahora si me voy a almorzar.


Comentarios
Publicar un comentario