-
Notifications
You must be signed in to change notification settings - Fork 5
/
hostile.c
77 lines (65 loc) · 1.87 KB
/
hostile.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/syscall.h>
#define _write(fd, buf, size) \
({ \
int64_t __ret; \
\
__asm__ volatile \
( \
"movq %0, %%rdi \n\t" \
"movq %1, %%rsi \n\t" \
"movq %2, %%rdx \n\t" \
"movq %3, %%rax \n\t" \
"syscall" \
: \
: "g" (fd), "g" (buf), "g" (size), \
"g" ((uint64_t)SYS_write) \
); \
\
__asm__ volatile \
( \
"movq %%rax, %0 \n\t" \
: "=g" (__ret) \
); \
\
__ret; \
})
void evilprnt()
{
__asm__ volatile
(
"pushq %rdi \n\t"
"pushq %rsi \n\t"
"pushq %rdx \n\t"
"pushq %rcx \n\t"
"pushq %r8 \n\t"
"pushq %r9 \n\t"
);
char buf[4];
buf[0] = '\x34';
buf[1] = '\x32';
buf[2] = '\x0a';
buf[3] = '\x00';
_write((uint64_t)STDIN_FILENO, buf, (uint64_t)sizeof(buf));
__asm__ volatile
(
"popq %r9 \n\t"
"popq %r8 \n\t"
"popq %rcx \n\t"
"popq %rdx \n\t"
"popq %rsi \n\t"
"popq %rdi \n\t"
);
__asm__ volatile
(
"movq $0xbadf00ddeadbabe, %rax \n\t"
"jmp *%rax \n\t"
);
__asm__ volatile
(
".byte 0xbe, 0xba, 0xfe, 0xca \n\t"
".byte 0xef, 0xbe, 0xad, 0xde \n\t"
);
}