Skip to content

Instantly share code, notes, and snippets.

@vient
Created October 22, 2021 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vient/0264b17c517edc86c7ba211f4e3a8d58 to your computer and use it in GitHub Desktop.
Save vient/0264b17c517edc86c7ba211f4e3a8d58 to your computer and use it in GitHub Desktop.
Cyberschool 2021 C
#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
int strcmp(const char *a, const char *b) {
printf("strcmp %s %s\n", a, b);
((int(*)(const char *, const char *))(dlsym(RTLD_NEXT, "strcmp")))(a, b);
}
#include <stdio.h>
#include <string.h>
int main() {
FILE* f = fopen("/tmp/kek", "r");
if (f == NULL) {
fprintf(stderr, "fopen failed\n");
return -1;
}
char buf[1024];
fgets(buf, sizeof(buf), f);
if (strcmp(buf, "[secret]\n")) {
fprintf(stderr, "1\n");
return -1;
}
fgets(buf, sizeof(buf), f);
char *it = strchr(buf, '\n');
if (it != 0) {
*it = '\0';
}
if (strcmp(buf, "JLJPMzknyLbj39VaaYitC79KmXEYzH4wzdzafzCYdziskECfe4R7bUPUmq7Cqi3c")) {
fprintf(stderr, "2\n");
return -1;
}
it = buf;
while (*it) {
if (*it > '9') {
*it ^= 0x20;
}
it++;
}
printf("CS{%s}\n", buf);
return 0;
}
.PHONY: nopie pie static hook clean
nopie:
gcc -no-pie main.c -o main
pie:
gcc main.c -o main
static:
gcc -static main.c -o main
hook:
gcc -shared hook.c -ldl -o libhook.so
clean:
rm main libhook.so 2>/dev/null; true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment