-
Notifications
You must be signed in to change notification settings - Fork 0
/
cat_exploit2.c
55 lines (42 loc) · 1017 Bytes
/
cat_exploit2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#define BUFFER_SIZE 1000
char buffer[BUFFER_SIZE];
int my_open(const char *pathname, int flags) {
int ret;
asm volatile
(
"syscall"
: "=a" (ret)
: "0"(2), "D"(pathname), "S"(flags)
: "rcx", "r11", "memory"
);
return ret;
}
int main(int argc, char *argv[]) {
for(int idx = 1; idx < argc; idx++) {
// int open(const char *pathname, int flags);
int file = my_open(argv[idx], O_RDONLY);
if (file == -1) {
perror("open");
continue;
}
ssize_t r = 0;
while((r = read(file, buffer, BUFFER_SIZE-1)) > 0) {
printf("%s", buffer);
fflush(stdout);
}
if (r < 0) {
perror("read");
}
if(close(file) == -1) {
perror("close");
continue;
}
}
return 0;
}