Thursday, 18 October 2012

[ HackYou CTF 2012 : Binary - Open-Source ]

Next up is Open-Source.
All i've got is an Open Source C code that was given to me here.
The source code looks like this.
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[]) {
    if (argc != 4) {
    printf("what?\n");
    exit(1);
    }

    unsigned int first = atoi(argv[1]);
    if (first != 0xcafe) {
    printf("you are wrong, sorry.\n");
    exit(2);
    }

    unsigned int second = atoi(argv[2]);
    if (second % 5 == 3 || second % 17 != 8) {
    printf("ha, you won't get it!\n");
    exit(3);
    }

    if (strcmp("h4cky0u", argv[3])) {
    printf("so close, dude!\n");
    exit(4);
    }

    printf("Brr wrrr grr\n");

    unsigned int hash = first * 31337 + (second % 17) * 11 + strlen(argv[3]) - 1615810207;

    printf("Get your key: ");
    printf("%x\n", hash);
    return 0;
}

Well, looking at the source code. We can deduce a few things.
first == 0xcafe == 51966
second == 25
argv[3] must be different from h4cky0u but i believe the strlen should be the same.

Finally, hash should be
hash = 51966 * 31337 + (25%17)*11+7 -1615810207
hash will eventually be 1628458637 - 1615810207 -> 12648430

As the results is printed in hexadecimal, the key is c0ffee

Cheers,
Jacob Soo

No comments:

Post a Comment