1. Description
So you started revving up, but is it enough to take off? Find the problem in /problems/2020/taking_off/ in the shell server.
Author: aplet123
2. Write up
# file taking_off
taking_off: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=fc4deaf2c2da6fdaf4cb7bc1e83d4f1372720832, not stripped
Bash
복사
문제 파일은 64bit elf 파일이다.
$ ls -al
total 40
drwxr-xr-x 2 problem2020_taking_off problem2020_taking_off 4096 Mar 14 00:23 .
drwxr-xr-x 16 root root 4096 Mar 14 01:00 ..
-rw-r--r-- 1 problem2020_taking_off problem2020_taking_off 220 Aug 31 2015 .bash_logout
-rw-r--r-- 1 problem2020_taking_off problem2020_taking_off 3771 Aug 31 2015 .bashrc
-r--r----- 1 problem2020_taking_off problem2020_taking_off 27 Mar 9 14:25 flag.txt
-rw-r--r-- 1 problem2020_taking_off problem2020_taking_off 655 May 16 2017 .profile
-r-xr-sr-x 1 problem2020_taking_off problem2020_taking_off 13120 Mar 9 14:39 taking_off
$ id
uid=12270(team6332) gid=12270(team6332) groups=12270(team6332),1001(teams)
Bash
복사
문제 서버내에 있는 문제 디렉토리로 이동해서 안의 내용을 보면 위와 같다.
나의 계정은 team6332이고 flag.txt를 보기 위해서는 problem2020_taking_off의 계정 권한이나 그룹 권한이 필요하다. 같은 경로에 taking_off이라는 파일이 존재하는데 이 파일은 SetGID 권한이 걸려있다. 따라서 taking_off를 이용해서 flag.txt를 열어야 한다.
문제 파일을 IDA에서 연 뒤 Pseudocode로 보면 위와 같다. 확인 결과 print_flag()라는 함수가 눈에 띈다.
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]에 저장된 값과 같아야 한다. desired[i]와 0x2A를 다시 XOR 연산을 함으로써 입력할 문자열을 찾았다.
# cat exploit.py
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))
# chicken
Python
복사
세가지 조건을 모두 찾아서 대입해주면 플래그가 나온다.
$ ./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}