From 2abac594dca364d9a694cdd98a05aa037da00210 Mon Sep 17 00:00:00 2001 From: jc Date: Mon, 28 Oct 2024 16:25:49 +0300 Subject: [PATCH] helper --- random_challs/mad_seccomp/read_file.c | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 random_challs/mad_seccomp/read_file.c diff --git a/random_challs/mad_seccomp/read_file.c b/random_challs/mad_seccomp/read_file.c new file mode 100644 index 0000000..e5e64d0 --- /dev/null +++ b/random_challs/mad_seccomp/read_file.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include + +int main(void){ + // get syscall num + printf("openat2: %d\n", SYS_openat2); + printf("pread64: %d\n", SYS_pread64); + printf("writev: %d\n", SYS_writev); + + // struct + struct open_how how; + memset(&how, 0, sizeof(how)); + how.flags = O_RDWR; + how.resolve = RESOLVE_IN_ROOT; + size_t size = sizeof(how); + + // openat2 + const char *file = "flag.txt"; + long rax = syscall(SYS_openat2, AT_FDCWD, file, &how, size); + printf("fd: %d\n", rax); + + // pread64 + char buf[64]; + long rax2 = syscall(SYS_pread64, rax, buf, 100, 0); + printf("string size: %d\n", rax2); + + // struct + char *str = "Some string here"; + struct iovec { + void *iov_base; + size_t iov_len; + }; + struct iovec iov[1]; + iov[0].iov_base = str; + iov[0].iov_len = strlen(str); + + // writev + syscall(SYS_writev, 1, iov, 1); + return 0; +} \ No newline at end of file