IOLI 0x04

0x04

  1. [0x080483d0]> pdd@main
  2. /* r2dec pseudo code output */
  3. /* ./crackme0x04 @ 0x8048509 */
  4. #include <stdint.h>
  5. int32_t main (void) {
  6. int32_t var_78h;
  7. int32_t var_4h;
  8. eax = 0;
  9. eax += 0xf;
  10. eax += 0xf;
  11. eax >>= 4;
  12. eax <<= 4;
  13. printf ("IOLI Crackme Level 0x04\n");
  14. printf ("Password: ");
  15. eax = &var_78h;
  16. scanf (0x8048682, eax);
  17. eax = &var_78h;
  18. check (eax);
  19. eax = 0;
  20. return eax;
  21. }

Let’s enter check.

  1. #include <stdint.h>
  2. int32_t check (char * s) {
  3. char * var_dh;
  4. uint32_t var_ch;
  5. uint32_t var_8h;
  6. int32_t var_4h;
  7. char * format;
  8. int32_t var_sp_8h;
  9. var_8h = 0;
  10. var_ch = 0;
  11. do {
  12. eax = s;
  13. eax = strlen (eax);
  14. if (var_ch >= eax) {
  15. goto label_0;
  16. }
  17. eax = var_ch;
  18. eax += s;
  19. eax = *(eax);
  20. var_dh = al;
  21. eax = &var_4h;
  22. eax = &var_dh;
  23. sscanf (eax, eax, 0x8048638);
  24. edx = var_4h;
  25. eax = &var_8h;
  26. *(eax) += edx;
  27. if (var_8h == 0xf) {
  28. printf ("Password OK!\n");
  29. exit (0);
  30. }
  31. eax = &var_ch;
  32. *(eax)++;
  33. } while (1);
  34. label_0:
  35. printf ("Password Incorrect!\n");
  36. return eax;
  37. }

manually analyze with both the assembly and pseudo code we can simply write down the C-like code to describe this function:

  1. #include <stdint.h>
  2. int32_t check(char *s)
  3. {
  4. var_ch = 0;
  5. var_8h = 0;
  6. for (var_ch = 0; var_ch < strlen(s); ++var_ch)
  7. {
  8. var_dh = s[var_ch];
  9. sscanf(&var_dh, %d, &var_4h); // read from string[var_ch], store to var_4h
  10. var_8h += var_4h;
  11. if(var_8h == 0xf)
  12. printf("Password OK\n");
  13. }
  14. printf("Password Incorrect!\n");
  15. return 0;
  16. }

In short, it calculates the Digit Sum of a number (add a number digit by digit. for example, 96 => 9 + 6 = 15) :

  1. ./crackme0x04
  2. IOLI Crackme Level 0x04
  3. Password: 12345
  4. Password OK!
  5. ./crackme0x04
  6. IOLI Crackme Level 0x04
  7. Password: 96
  8. Password OK!