diff --git a/Assignment 5 - Software Security - Teil 1/crackme/Makefile b/Assignment 5 - Software Security - Teil 1/crackme/Makefile new file mode 100644 index 0000000..891daad --- /dev/null +++ b/Assignment 5 - Software Security - Teil 1/crackme/Makefile @@ -0,0 +1,4 @@ +.phony: all +all: crackme +crackme: + gcc -o crackme -m32 -O0 -fno-pie -fno-stack-protector crackme.c \ No newline at end of file diff --git a/Assignment 5 - Software Security - Teil 1/crackme/crackme.c b/Assignment 5 - Software Security - Teil 1/crackme/crackme.c new file mode 100644 index 0000000..fc636e1 --- /dev/null +++ b/Assignment 5 - Software Security - Teil 1/crackme/crackme.c @@ -0,0 +1,44 @@ +#include +#include +#include + +// Define the length of the serial number +#define SERIAL_LENGTH 5 + +int verify_key(char *serial) { + // Allocate a buffer to store the derived key (5 capital letters + null byte) + char derived[SERIAL_LENGTH + 1] = {0}; + + // Derive the key from the serial by iterating over the serial + // and subtracting 2 times the current index from each character + for(int i = 0; i < SERIAL_LENGTH; i++) { + derived[i] = serial[i] - 2 * i; + } + + // Compare the derived key with the expected key "MMNNQ" + if(strcmp(derived, "MMNNQ") == 0) + return 1; // Return 1 if the keys match + + return 0; // Return 0 if the keys do not match +} + +int main(int argc, char **argv) { + // Buffer to store the user input (5 capital letters + null byte) + char serial[SERIAL_LENGTH + 1] = {0}; + + // Read the serial number from the user and store it in the serial buffer + printf("Enter serial (5 capital letters):\n"); + scanf("%5s", serial); + + // Verify the serial number + if(verify_key(serial)) { + // Print this message if the serial is correct + printf("Key is valid! Whoop whoop :)\n"); + } else { + // Print this message if the serial is not correct + printf("Key is not valid :(\n"); + } + + // End the program without errors + return 0; +} \ No newline at end of file diff --git a/Assignment 5 - Software Security - Teil 1/crackme/key.txt b/Assignment 5 - Software Security - Teil 1/crackme/key.txt new file mode 100644 index 0000000..2fd0c80 --- /dev/null +++ b/Assignment 5 - Software Security - Teil 1/crackme/key.txt @@ -0,0 +1 @@ +MORTY \ No newline at end of file