-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflag_print.c
More file actions
58 lines (52 loc) · 1.68 KB
/
Copy pathflag_print.c
File metadata and controls
58 lines (52 loc) · 1.68 KB
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
#include <stdio.h>
#include <stdint.h>
#include <malloc.h>
#include <string.h>
#include "includes.h"
#pragma GCC push_options
#pragma GCC optimize ("-fno-omit-frame-pointer")
#pragma GCC optimize ("-fno-stack-protector")
void run_code() {
unsigned char crypt[24];
__asm__ volatile (
"movq $0x4141414141414141, %%rcx;"
"movq $0x3372373a22322222, %%rax;"
"xorq %%rcx, %%rax;"
"movq %%rax, (%%rdi);"
"movq $0x221e383275241e38, %%rax;"
"xorq %%rcx, %%rax;"
"movq %%rax, 8(%%rdi);"
"movq $0x3c2d2d7529, %%rax;"
"xorq %%rcx, %%rax;"
"movq %%rax, 16(%%rdi);"
: /* outputs */
: "D" (crypt)/* inputs */
: "rax", "rcx"
);
__asm__ volatile (
"syscall"
::"a" (1), "D" (1), "S" (crypt), "d" (sizeof(crypt) - 3)
);
}
void CODE_END(void) { return; }
#pragma GCC pop_options
int main(int argc, char *argv[]) {
unsigned long shellcode_size = (unsigned long) CODE_END - (unsigned long) run_code;
uint32_t *raw_code = (uint32_t *) malloc(shellcode_size);
memcpy(raw_code, (unsigned char *) run_code, shellcode_size);
uint32_t key = FLAG_CIPHERTEXT_KEY;
for (int i = 0; i < shellcode_size / sizeof(uint32_t); i++) {
raw_code[i] ^= key;
}
uint8_t *ptrb_raw_code = (uint8_t *) raw_code;
printf("Generating file at %s", argv[1]);
FILE *fp = fopen(argv[1], "w");
fprintf(fp, "__attribute__((section(\".secret\"))) unsigned char flag_ciphertext[] = {\n\t");
for (int i = 0; i < shellcode_size; i++) {
fprintf(fp, "0x%02x", ptrb_raw_code[i]);
if (i + 1 != shellcode_size) fprintf(fp, ", ");
if ((i + 1) % 16 == 0) fprintf(fp, "\n\t");
}
fprintf(fp, "\n};");
fclose(fp);
}