Created
December 25, 2018 15:46
-
-
Save dnutiu/86b4391c0ea3b9cc6a9bb3bb16ee9012 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Keygen for the "KeygenMe or Not" challenge. | |
* */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdbool.h> | |
void exit_error(char * e) { | |
fprintf(stderr, "%s\n", e); | |
exit(EXIT_FAILURE); | |
} | |
void auth(char * username, unsigned magicNumber) { | |
unsigned username_length = strnlen(username, 32); | |
unsigned uiSeed = (username[3] ^ 0x1337) + 0x5EEDED; | |
unsigned uiAccumulator = 0; | |
while(true) { | |
if (uiAccumulator >= username_length) { | |
/* I've commented the check from below in order to get the uiSeed. This is the keygen, basically */ | |
// if (magicNumber != uiSeed) { | |
// exit_error("magicNumber is not equal to uiSeed"); | |
// } | |
/* I guess the block from below gives the title "Keygenme or Not" to this challenge. */ | |
// if (magicNumber == 6235464) { | |
// printf("Solution found!\n"); | |
// } | |
printf("Solution found: %u\n", uiSeed); | |
break; | |
} else { | |
/* Checks wheter username is a character between a ' '(space) and ''(empty) */ | |
if (username[uiAccumulator] < 0x20 || username[uiAccumulator] > 0x7F) { | |
exit_error("err: username[uiAccumulator] < 0x20 || username[uiAccumulator] < 0x7F"); | |
} else { | |
unsigned dividend = username[uiAccumulator] ^ uiSeed; | |
uiSeed += dividend % 0x539; | |
uiAccumulator += 1; | |
} | |
} | |
} | |
} | |
int main(int argc, char *argv[], char *envp[]) { | |
if (argc < 3) { | |
auth("root-me.org", 6235464); | |
} else { | |
auth(argv[1], atoi(argv[2])); | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment