BND-CTF: 86-GBE Message Service
Der nächste Writeup aus den BND-CTFs. Nach der Backdoor in der RSA-Schlüsselerzeugung, dieses Mal aus der Kategorie Binary Exploitation.
Das Ziel:
Exploit a binary to gain a remote shell.
Wir bekommen die server.c, sowie die auf dem Server genutzte libc.
Server-Code
{%- highlight c linenos -%} // gcc server.c -o server -g -ggdb -Wl,-z,norelro -fstack-protector-all#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h>
int my_read(FILE *fd, char *buf, size_t max) { int read = 0; while (read < max && !feof(fd)) { int ch = getc(fd); if (ch == ‘\n’) { break; } else { buf[read] = ch; read++; } } buf[read] = 0;
return read;
}
char rot13(char ch) { if (ch >= ‘a’ && ch <= ‘z’) { return ((ch - ‘a’ + 13) % 26) + ‘a’; } else if (ch >= ‘A’ && ch <= ‘Z’) { return ((ch - ‘A’ + 13) % 26) + ‘A’; } else if (ch >= ‘0’ && ch <= ‘9’) { return ((ch - ‘0’ + 5) % 10) + ‘0’; } else { return ch; } }
int main(int argc, char** argv) { setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0);
char inp[0x100];
char cc;
puts("Welcome to our 86-GBE service!");
puts("Enter your message and press return.");
puts("Enter quit to exit.");
unsigned char len;
for (;;) {
len = my_read(stdin, inp, sizeof (inp) - 1);
if (strcmp(inp, "quit") == 0) {
exit(0);
}
for (int i = 0; i < len; i++) {
inp[i] = rot13(inp[i]);
}
for (int i = 0; i < len / 2; i++) {
cc = inp[i];
inp[i] = inp[len -i -1];
inp[len - i - 1] = cc;
}
printf(inp);
putc('\n', stdout);
}
exit(0);
} {%- endhighlight -%}
Nehmt Euch am Besten etwas Zeit, um den Code erstmal anzuschauen.
Falls Ihr das nachstellen wollt, die Sha1-Hashes der beiden Shared-Objects und der bereitgestellten server-Executable sind: