hod24-ctf/remote_shell/main.c
2024-12-03 14:22:56 +01:00

56 lines
1.1 KiB
C

#undef _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#define SECRET_PASSWORD "super_secret_password"
#define SECRET_PASSWORD_LEN strlen(SECRET_PASSWORD)
int read_string(char *prompt, char *buf, int n)
{
puts(prompt);
n = read(0, buf, n);
if (n <= 0)
exit(0xc35a);
buf[n - 1] = '\0';
return n;
}
void remote_shell(void) {
char username[32];
char password[32];
int n;
read_string("login: ", username, sizeof(username));
read_string("password: ", password, 128);
if (strncmp(password, SECRET_PASSWORD, SECRET_PASSWORD_LEN) != 0)
exit(0xc35f);
printf("Welcome %s!\n", username);
puts("TO BE IMPLEMENTED\n");
return;
}
char banner[1024];
int main(void) {
int fd;
int n;
setbuf(stdout, NULL);
fd = open("./banner.txt", O_RDONLY);
if (fd == -1)
exit(-1);
n = read(fd, banner, sizeof(banner) - 1);
if (n <= 0)
exit(0xc35e);
banner[n] = '\0';
puts(banner);
close(fd);
remote_shell();
return 0;
}