Skip to content

Commit 39173ba

Browse files
committed
TheMain task added
1 parent c640e97 commit 39173ba

File tree

9 files changed

+163
-0
lines changed

9 files changed

+163
-0
lines changed

TheMain/create/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.PHONY: all clean
2+
3+
keep_symbols = -K main -K __libc_start_main -K super_secure_call -K super_secure_return
4+
all: main
5+
6+
main: main.c safecall.s fun.s
7+
gcc -nostartfiles -o $@ $^ -Wl,-e_start -g
8+
strip $(keep_symbols) $@
9+
10+
clean:
11+
rm main

TheMain/create/README.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
$ make
2+
# дать участнику ./main

TheMain/create/flag.enc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
R��]5��*��g)��V��V��h��d��*

TheMain/create/flag.plain

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ STCTF#main_is_not_always_main#

TheMain/create/fun.s

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.text
2+
.globl _start, flag
3+
_start:
4+
xor %ebp,%ebp
5+
pop %esi
6+
mov %esp,%ecx
7+
and $0xfffffff0,%esp
8+
push %eax
9+
push %esp
10+
push %edx
11+
push $0x80484d0
12+
push $0x8048460
13+
push %ecx
14+
push %esi
15+
push $main
16+
call __libc_start_main
17+
push $lol
18+
call printf
19+
push $0
20+
call exit
21+
22+
__libc_start_main:
23+
push $solve
24+
call super_secure_call
25+
push %eax
26+
call exit
27+
28+
lol:
29+
.string "Unbellieveable!\n"

TheMain/create/main.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
extern int super_secure_call(void *func, ...);
6+
extern void super_secure_return(int status);
7+
8+
#define call super_secure_call
9+
#define ret super_secure_return
10+
11+
int main()
12+
{
13+
// break your logic here
14+
// this code will never be executed
15+
16+
printf("passphrase: ");
17+
char c[100];
18+
scanf("%s", c);
19+
if ( (char *)c != "lolol" )
20+
return;
21+
if ( (int) c[1] != (int) "azaza")
22+
return;
23+
printf("wrong!\n");
24+
ret(0);
25+
}
26+
27+
unsigned int hash(const char *s)
28+
{
29+
unsigned int result = 0xdeadbeef;
30+
while(*s) {
31+
result = result * 33 + *(s++);
32+
}
33+
ret(result);
34+
}
35+
36+
void xor(char *s, const char *k, int n)
37+
{
38+
register int i = 0;
39+
for (i = 0; i < n; ++i) {
40+
s[i] ^= k[i % 4];
41+
}
42+
ret(0);
43+
}
44+
45+
char flag[] =
46+
"\x52\xfe\xf0\x5d\x35\x8a\xe5\x2a\x1b"
47+
"\xbf\xca\x67\x29\xb7\xd0\x56\x18\xb1"
48+
"\xd7\x56\x17\xb2\xd4\x68\x0f\xad\xfc"
49+
"\x64\x17\xb7\xcd\x2a";
50+
51+
int solve()
52+
{
53+
char pass[1000];
54+
printf("password: ");
55+
scanf("%s", pass);
56+
57+
unsigned int key = call(hash, pass);
58+
call(xor, flag, &key, strlen(flag));
59+
60+
printf("here is your flag:\n%s\n", flag);
61+
ret(0);
62+
}

TheMain/create/safecall.s

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.data
2+
return_stack_top: /* глубина текущего вызова, начиная от start */
3+
.long return_stack
4+
.bss
5+
return_stack: /* стек с адресами возврата */
6+
.space 4 * 0x1000
7+
8+
9+
/* ----------------------------------------------------------- */
10+
11+
.globl super_secure_call, super_secure_return
12+
.text
13+
14+
super_secure_call:
15+
mov (%esp), %eax
16+
mov 4(%esp), %ebx
17+
18+
mov %ebx, (%esp)
19+
movl $0xdeadbeef, 4(%esp)
20+
21+
mov return_stack_top, %edi
22+
mov %eax, (%edi)
23+
add $4, %edi
24+
mov %edi, return_stack_top
25+
26+
ret
27+
28+
super_secure_return:
29+
add $4, %esp
30+
mov (%esp), %eax
31+
mov return_stack_top, %ebx
32+
sub $4, %ebx
33+
mov %ebx, return_stack_top
34+
mov (%ebx), %ebx
35+
36+
mov %ebp, %esp
37+
pop %ebp
38+
39+
push %ebx
40+
ret
41+

TheMain/solution/solution.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
1. Разбираем бинарник.
2+
2. Видим, что флаг расшифровывается шифром Вернама с 4-х байтовым
3+
ключом равным хешу пароля. (искать правильный пароль не нужно, его
4+
может не существовать)
5+
3. Ручками достаем флаг из бинарника.
6+
4. Вспоминаем, что флаг начинается с 'STCTF#'
7+
5. Перебираем возможные позиции 'STCTF#', находим ключ
8+
6. Profit

TheMain/summary.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
answer_regex: STCTF#main_is_not_always_main#
3+
author: gnull
4+
category: reverse
5+
description: |
6+
7+
name: TheMain
8+
price: 150

0 commit comments

Comments
 (0)