Snippets

Masafumi Yabu Defcamp CTF Qualification 2015 Writeup

Created by Masafumi Yabu last modified nomeaning777

Web 100

よく分からないがPHPSESSIDを空にしたら解けてしまった。実際にはレースコンディションを起こす問題だったらしい。

$ tsocks curl http://10.13.37.2/ -b 'PHPSESSID=' 
You have $60.DCTF{3a9bad36a0fb1edcaa83b6669d667061}%           

Rev 100

0x400787にブレークポイントをしかけることでeaxに正しいパスワードの文字+1が入る。edxを正しい文字に変更しながら実行していくことでフラグを得ることが出来た。

バイナリにはptraceによるデバッガの妨害があるが気にせず、Ctrl + \で終了し、call *0x4006fd("Code")のように実行した。

Rev 200

人力逆コンパイルするとこんな感じになる。

typedef struct list {
  int no;
  char c;
  struct list * next
} List;
List head = NULL; // 0x601080

int check(char *in) {
  int first[6];
  int second[6] = {5,2,7,2,5,6};
  for(int i = 0; i <= 5; i++) {
    List *cur = head;
    int tno;
    for(;cur != NULL; cur = cur->next) {
      if(in[i] == cur->c) {
        tno = cur->no;
        break;
      }
    }
    first[i] = tno;

  }
  for(int i = 0; i <= 5; i++) {
    if(first[i] != second[i]) return 1;
  }
  return 0;
}
int main() {
  for(int i = 1; i <= 0xa; i++) {
    List lst  = (List)malloc(0x10);
    lst.no = i;
    lst.c = (char)(i + 'm');
    lst.next = head;
    head = lst;
  }
  printf("Enter the password: ");
  char buf[10];
  fgets(in, 7, stdin);
  if(check(in) == 0) {
    puts("Nice!");
  }
} 

ということで

irb(main):013:0> [5,2,7,2,5,6].map{|a| a+?m.ord}.pack("C*")
=> "rotors"

Rev 400

0x6010d8から0x82バイトを入力の4byteの繰り返しXORして実行している。バイト列の繰り返しなどから鍵を推測していき、最終的に"4bf6"が鍵だと分かった。

require 'metasm'
require 'facets'
decoded = Metasm::ELF.decode_file './r400'
@dasm = decoded.disassembler
def data_at(addr, size)
  s = @dasm.get_section_at(addr)
  s[0].read(size)
end

func = data_at(0x6010d8,82)
print func ^ ("4bf6" * 20)
$ ruby solve.rb | ndisasm -b 64 -
00000000  6A0A              push byte +0xa
00000002  686F726421        push qword 0x2164726f
00000007  6861737377        push qword 0x77737361
0000000C  6868652070        push qword 0x70206568
00000011  686E642074        push qword 0x7420646e
00000016  6820666F75        push qword 0x756f6620
0000001B  6820596F75        push qword 0x756f5920
00000020  686F6E7321        push qword 0x21736e6f
00000025  686C617469        push qword 0x6974616c
0000002A  6872617475        push qword 0x75746172
0000002F  68436F6E67        push qword 0x676e6f43
00000034  BA2A000000        mov edx,0x2a
00000039  89E1              mov ecx,esp
0000003B  BB01000000        mov ebx,0x1
00000040  B804000000        mov eax,0x4
00000045  CD80              int 0x80
00000047  B801000000        mov eax,0x1
0000004C  CD80              int 0x80
0000004E  90                nop
0000004F  90                nop
00000050  F0                lock
00000051  0D                db 0x0d

生成された文字列を4byte毎に逆順にすることで良い感じの文字列が出てくる。

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.