1. Description
Oh no! We were gonna make this an easy challenge where you just had to run the binary and it gave you the flag, but then clam came along under the name of "The Patcherman" and edited the binary! I think he also touched some bytes in the header to throw off disassemblers. Can you still retrieve the flag?
Alternatively, find it on the shell server at /problems/2020/patcherman/.
Author: aplet123
2. Write up
# file patcherman
patcherman: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, stripped
Bash
복사
문제 파일은 64bit elf 파일이다.
$ ls -al
total 32
drwxr-xr-x 2 problem2020_patcherman problem2020_patcherman 4096 Mar 13 23:59 .
drwxr-xr-x 16 root root 4096 Mar 14 01:00 ..
-rw-r--r-- 1 problem2020_patcherman problem2020_patcherman 220 Aug 31 2015 .bash_logout
-rw-r--r-- 1 problem2020_patcherman problem2020_patcherman 3771 Aug 31 2015 .bashrc
-r-xr-xr-x 1 problem2020_patcherman problem2020_patcherman 8768 Feb 26 19:04 patcherman
-rw-r--r-- 1 problem2020_patcherman problem2020_patcherman 655 May 16 2017 .profile
Bash
복사
문제 서버내에 있는 문제 디렉토리로 이동해서 안의 내용을 보면 위와 같다.
이번 문제의 설명을 보면 flag가 있었으나 patcherman 프로그램이 수정했다고 한다.
문제 파일을 IDA에서 열어보면 문제의 설명에서 헤더의 일부 바이트를 수정했다는 것처럼 위와 같이 함수의 심볼들이 사라져있는 것을 확인할 수 있다. 그렇지만 위의 그림을 보면 엔트리 포인트에서 첫번째로 call하는 함수가 _libc_start_main인 것으로 볼때 sub_400713는 main함수인 것을 알 수 있다.
print_flag() 함수의 내부를 보면 flag.txt 출력해주고 있다. 그렇다면 print_flag() 함수를 호출할 조건만 만족시켜주면 이 문제는 풀린다.
print_flag() 함수를 호출하기 위해서는 총 3가지의 조건을 만족시켜야 한다.
•
첫번째 조건은 인자 개수가 5개이면 만족한다. 인자값에 대해서는 두번째 조건을 확인해야 한다.
•
두번째 조건의 경우에는 네번째 인자값은 "chicken" 문자열과 일치해야 하고 첫번째, 두번째, 세번째 인자값은 숫자이고 다음 조건을 만족해야한다.
100 * argv[2] + 10 * argv[1] + argv[3] == 932
argv[1] = 3, argv[2] = 9, argv[3] = 2
Bash
복사
•
세번째 조건의 경우에는 입력한 문자열과 0x2A를 XOR 연산한 결과가 desired[i]에 저장된 값과 같아야 한다.
파이썬을 통해서 각 아스키 값과 0x2A를 XOR 연산했다.
import sys
key = "5A 46 4F 4B 59 4F 0A 4D 43 5C 4F 0A 4C 46 4B 4D 2A"
key = key.split(" ")
for i in key:
sys.stdout.write(chr(int(i,16) ^ 0x2a))
# python exploit.py
# please give flag
Python
복사
연산한 결과 문자열은 "please give flag"였다. 이제 모든 조건을 통해서 플래그를 구하면 된다.
$ ./taking_off 3 9 2 chicken
So you figured out how to provide input and command line arguments.
But can you figure out what input to provide?
Well, you found the arguments, but what's the password?
please give flag
Good job! You're ready to move on to bigger and badder rev!
actf{th3y_gr0w_up_s0_f4st}
Bash
복사
3. FLAG
actf{th3y_gr0w_up_s0_f4st}