2016年04月

PlaidCTF 2016 writeup hevc

hevc

Misc (50 pts)

Welcome to the future.

ダウンロードしたファイルについて、fileコマンドでファイルタイプを確認します。

$ file out_743a4e0cbbfae017e5197b303c82aa52.raw
out_743a4e0cbbfae017e5197b303c82aa52.raw: data

単なるdataと出ました。次にstringsコマンドでファイル中の文字列を確認します。

$ strings out_743a4e0cbbfae017e5197b303c82aa52.raw
Nx265 (build 79) - 1.9:[Mac OS X][clang 7.0.2][64 bit] 8bit - H.265/HEVC codec - Copyright 2013-2015 (c) Multicoreware Inc - http://x265.org - options: 1080x720 fps=30000/1001 bitdepth=8 wpp ctu=64 min-cu-size=8 max-tu-size=32 tu-intra-depth=1 tu-inter-depth=1 me=1 subme=2 merange=57 no-rect no-amp max-merge=2 temporal-mvp no-early-skip rdpenalty=0 no-tskip no-tskip-fast strong-intra-smoothing no-lossless no-cu-lossless no-constrained-intra no-fast-intra open-gop no-temporal-layers interlace=0 keyint=250 min-keyint=25 scenecut=40 rc-lookahead=20 lookahead-slices=4 bframes=4 bframe-bias=0 b-adapt=2 ref=3 limit-refs=3 no-limit-modes weightp no-weightb aq-mode=1 qg-size=32 aq-strength=1.00 cbqpoffs=0 crqpoffs=0 rd=3 psy-rd=2.00 rdoq-level=0 psy-rdoq=0.00 signhide deblock sao no-sao-non-deblock b-pyramid cutree no-intra-refresh rc=crf crf=28.0 qcomp=0.60 qpmin=0 qpmax=51 qpstep=4 ipratio=1.40 pbratio=1.30

(略)

H265形式の動画フォーマットのようです。Wikipediaによると、H264の後続の動画フォーマットということで、2013年1月に承認されたそうです。今後10年間をサポートする規格だそうです。

ということで、パソコンにコーデックが入っているか確認してみます。


no title


コーデックが入っていたようなので、smplayerで再生してみます。次のとおり再生することが出来ました。


shot0001

左右反転すると次のようになります。


2

したがって、フラグは、

PCTF{DAT_CODEC_THO}

です。





Nuit du Hack CTF Quals 2016 writeup Matriochka - Step 3

Matriochka - Step 3

Description

Can you help me?

Recently, I found an executable binary.

As I'm a true newbie,

Certainly, to solve it, I will have difficulties.

Keep in mind, the first step is quite easy.

Maybe the last one will be quite tricky.

Emulating it could be a good idea.

You must solve steps 1 and 2 first.


Details

Points
300
Category
Crack Me
Validations
90

Attachments

This challenge has no attachment.

Step2で得たBase64エンコードデータ(aaa.txtとして保存)をデコードします。

$ cat aaa.txt | tr -d '\r\n' | base64 -d > bbb

デコードしたファイルのファイルタイプをfileコマンドで確認します。Linuxの64bitバイナリです。

$ file bbb
bbb: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=2ea586c925bc94d07d2d3087837dac6ef32a180c, stripped

実行してみます。コマンドライン引数にパスワードの指定が必要であることが分かります。

$ ./bbb
Usage: ./bbb <pass>

ここで、逆アセンブルして動作を解析してみます。

$ objdump -s -D bbb > ccc.txt

以下の箇所で、シグナル処理関数の登録を行っています。これにより、11:メモリアクセス違反が発生した場合、アドレス0x4007fd番地の関数が呼び出されます。また、8:浮動小数点例外が発生した場合、アドレス0x401050番地の関数が呼び出されます。

  40114b:    be fd 07 40 00           mov    $0x4007fd,%esi        #関数のアドレス
  401150:    bf 0b 00 00 00           mov    $0xb,%edi                 #11:不正なメモリ参照
  401155:    e8 66 f5 ff ff           callq  4006c0 <signal@plt>     #シグナル登録
  40115a:    be 50 10 40 00           mov    $0x401050,%esi      #関数のアドレス
  40115f:    bf 08 00 00 00           mov    $0x8,%edi                  #8:浮動小数点例外
  401164:    e8 57 f5 ff ff           callq  4006c0 <signal@plt>     #シグナル登録

その後、以下の箇所で繰り返しkill関数を呼び出していますが、この部分でメモリアクセス違反が発生します。したがって、0x4007fd番地の関数へ処理が移ります。

  401172:    8b 45 fc                 mov    -0x4(%rbp),%eax   
  401175:    be 0b 00 00 00           mov    $0xb,%esi
  40117a:    89 c7                    mov    %eax,%edi
  40117c:    e8 5f f5 ff ff           callq  4006e0 <kill@plt>            #メモリアクセス違反
  401181:    83 45 f8 01              addl   $0x1,-0x8(%rbp)                #+1
  401185:    81 7d f8 ff 03 00 00     cmpl   $0x3ff,-0x8(%rbp)         #0x3ff=1023
  40118c:    7e e4                    jle    401172 <fwrite@plt+0xa72>   #小さいか等しい

0x4007fd番地の関数では、0文字目のチェックを行っています。

  400808:    0f b6 05 b1 38 20 00     movzbl 0x2038b1(%rip),%eax  # 6040c0 <stdout+0x20>引数の文字列
  40080f:    0f be c0                 movsbl %al,%eax                          #0文字目
  400812:    89 45 fc                 mov    %eax,-0x4(%rbp)
  400815:    8b 45 fc                 mov    -0x4(%rbp),%eax
  400818:    69 c8 e8 03 00 00        imul   $0x3e8,%eax,%ecx     #ecx=0文字目×1000
  40081e:    ba 79 78 78 78           mov    $0x78787879,%edx      #2021161081
  400823:    89 c8                    mov    %ecx,%eax
  400825:    f7 ea                    imul   %edx                                    #edx(上位4バイト),eax(下位4バイト)=eax×0x78787879
  400827:    c1 fa 05                 sar    $0x5,%edx                          #edx=edx/32
  40082a:    89 c8                    mov    %ecx,%eax                        #0文字目×1000
  40082c:    c1 f8 1f                 sar    $0x1f,%eax                          #31ビット右シフト(最上位ビット)
  40082f:    29 c2                    sub    %eax,%edx                          #edx=edx-eax
  400831:    89 d0                    mov    %edx,%eax                 
  400833:    89 45 fc                 mov    %eax,-0x4(%rbp)
  400836:    81 7d fc e7 03 00 00     cmpl   $0x3e7,-0x4(%rbp)    #999
  40083d:    7e 09                    jle    400848 <fwrite@plt+0x148> #小さいか等しい
  40083f:    81 7d fc e8 03 00 00     cmpl   $0x3e8,-0x4(%rbp)     #1000正解
  400846:    7e 02                    jle    40084a <fwrite@plt+0x14a> #小さいか等しい
  400848:    eb 10                    jmp    40085a <fwrite@plt+0x15a>

これを逆算して0文字目を求めるRubyプログラムが以下です。実行するとDが得られます。

#0moij
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x78787879)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  edx = edx >> 5
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end

0文字目のチェックがOKだと、以下の箇所で再度メモリアクセス違反が発生した場合のシグナルが登録されます。つまり、次にメモリアクセス違反が発生した場合は、0x40085c番地の関数が呼び出されます。

  40084a:    be 5c 08 40 00           mov    $0x40085c,%esi     #関数のアドレス
  40084f:    bf 0b 00 00 00           mov    $0xb,%edi                #11:不正なメモリ参照

  400854:    e8 67 fe ff ff           callq  4006c0 <signal@plt>   #シグナル登録

retで呼び出し元に戻り、kill関数が繰り返し呼び出されますので、再度、メモリアクセス違反が発生し、0x40085c番地の関数へ処理が移ります。ここでは1文字目のチェックが行われ、OKだった場合、再度シグナルが登録されます。

同様な処理が20回ほど行われ、最終的に以下の文字列を得ることが出来ます。

Did_you_like_signals?

実際にコマンドライン引数に指定して実行してみます。

$ ./bbb Did_you_like_signals?
Good good! Now let's play a game...
6ydQg8QCWEBQg+wCWMNQg8QCWEBAUIPsAljDUIPEAliDwARQg+wCWMPo1v9m6wJmLujO/8P76znr

(略)

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=

Goodと表示されました。

したがって、フラグは、

Did_you_like_signals?

です。






以下に、0文字目から各文字のチェックを逆算するRubyプログラムを載せておきます。

 

#0moij
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x78787879)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  edx = edx >> 5
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#1moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x9c09c09d - 0xffffffff - 1)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  eax = ecx + edx
  edx = eax >> 6
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#2moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x51eb851f)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  edx = edx >> 5
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#3moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0xac769185 - 0xffffffff - 1)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  eax = ecx + edx
  edx = eax >> 6
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#4moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x43b3d5b)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  edx = edx >> 1
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#5moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x939a85c5 - 0xffffffff - 1)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  eax = ecx + edx
  edx = eax >> 6
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#6moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x8c08c08d - 0xffffffff - 1)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  eax = ecx + edx
  edx = eax >> 6
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#7moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0xac769185 - 0xffffffff - 1)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  eax = ecx + edx
  edx = eax >> 6
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#8moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x4bda12f7)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  edx = edx >> 5
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#9moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x9c09c09d - 0xffffffff - 1)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  eax = ecx + edx
  edx = eax >> 6
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#10moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x4c8f8d29)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  edx = edx >> 5
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#11moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x288df0cb)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  edx = edx >> 4
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#12moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0xac769185 - 0xffffffff - 1)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  eax = ecx + edx
  edx = eax >> 6
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#13moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x473c1ab7)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  edx = edx >> 5
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#14moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x9c09c09d - 0xffffffff - 1)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  eax = ecx + edx
  edx = eax >> 6
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#15moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x13e22cbd)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  edx = edx >> 3
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#16moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x94f2095 - 0xffffffff - 1)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  edx = edx >> 2
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#17moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x151d07eb)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  edx = edx >> 3
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#18moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x4bda12f7)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  edx = edx >> 5
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#19moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x473c1ab7)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  edx = edx >> 5
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end
#20moji
for i in 32..126 do
  ecx = i * 0x3e8
  tmp = ecx * (0x82082083 - 0xffffffff - 1)
  edx = tmp.to_s(16)[0..-9].to_i(16)
  eax = tmp.to_s(16)[-8, 8].to_i(16)
  eax = ecx + edx
  edx = eax >> 5
  eax = ecx >> 0x1f
  edx = edx - eax
  if edx.to_s(16).start_with?("3e8") then
    print i.chr
    break
  end
end






 

Nuit du Hack CTF Quals 2016 writeup Matriochka - Step 2

Matriochka - Step 2

Description

Can you help me?

Recently, I found an executable binary.

As I'm a true newbie,

Certainly, to solve it, I will have difficulties.

Keep in mind, the first step is quite easy.

Maybe the last one will be quite tricky.

Emulating it could be a good idea.

You must solve step 1 first.


Details

Points
100
Category
Crack Me
Validations
98

Attachments

This challenge has no attachment.

Step1の最後で出力されたBase64エンコードデータ(bbb.txtファイルとして保存)をデコードします。改行コードが邪魔なので取り除いてデコードします。
$ cat bbb.txt | tr -d '\r\n' | base64 -d > ccc
fileコマンドでファイルタイプを確認します。
$ file ccc

ccc: POSIX tar archive (GNU)

tarコマンドで解凍します。stage2.binファイルが出来ました。

$ tar xvf ccc
stage2.bin

fileコマンドでstage2.binファイルのファイルタイプを確認します。Linuxの64bitバイナリのようです。

$ file stage2.bin
stage2.bin: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=7b2fd52d0de50c9e575793a0fd17fdd2574c5c53, stripped

実行してみると、コマンドライン引数にパスワードを指定しなければいけないことが分かります。

$ ./stage2.bin
Usage: ./stage2.bin <pass>

ここで、逆アセンブルして動作を解析します。

$ objdump -s -D stage2.bin > ddd.txt

まず以下の箇所でコマンドライン引数の文字列の長さをチェックしています。長さは11文字である必要があります。

  400742:    e8 c9 fd ff ff           callq  400510 <strlen@plt> #引数の文字列長を求める

  400747:    48 8d 50 01              lea    0x1(%rax),%rdx      #+1して
  40074b:    48 89 d0                 mov    %rdx,%rax
  40074e:    48 c1 e0 02              shl    $0x2,%rax               #*4して
  400752:    48 01 d0                 add    %rdx,%rax               #この時点で(文字列長+1)を5倍
  400755:    48 c1 e0 02              shl    $0x2,%rax               #さらに*4
  400759:    48 01 d0                 add    %rdx,%rax               #この時点で(文字列長+1)を21倍
  40075c:    48 01 c0                 add    %rax,%rax               #この時点で(文字列長+1)の42倍
  40075f:    48 3d f8 01 00 00        cmp    $0x1f8,%rax       #1f8=504/42=12→12-1=11文字

次に以下の箇所で0文字目の文字をチェックしています。0文字目はPです。
  40077a:    48 8b 00                 mov    (%rax),%rax          #rax=引数

  40077d:    0f b6 00                 movzbl (%rax),%eax         #0文字目
  400780:    3c 50                    cmp    $0x50,%al               #0x50=P

さらに以下の箇所で3文字目のチェックをしています。3文字目はdです。

  400793:    48 8b 00                 mov    (%rax),%rax           #rax=引数
  400796:    48 83 c0 03              add    $0x3,%rax             #+3
  40079a:    0f b6 00                 movzbl (%rax),%eax          #3文字目
  40079d:    0f be c0                 movsbl %al,%eax
  4007a0:    01 c0                    add    %eax,%eax               #2倍して
  4007a2:    3d c8 00 00 00           cmp    $0xc8,%eax       #c8=200/2=100=d

続いて6文字目のチェックです。6文字目はpです。

  4007c1:    8d 50 10                 lea    0x10(%rax),%edx        #0文字目=P(80)+16=96
  4007c4:    48 8b 45 d0              mov    -0x30(%rbp),%rax
  4007c8:    48 83 c0 08              add    $0x8,%rax
  4007cc:    48 8b 00                 mov    (%rax),%rax
  4007cf:    48 83 c0 06              add    $0x6,%rax                   #+6

  4007d3:    0f b6 00                 movzbl (%rax),%eax              #6文字目
  4007d6:    0f be c0                 movsbl %al,%eax
  4007d9:    83 e8 10                 sub    $0x10,%eax                #-16して
  4007dc:    39 c2                    cmp    %eax,%edx                  #edx=96+16=112=p

続いて5文字目のチェックです。5文字目は_です。
  4007f2:    48 83 c0 05              add    $0x5,%rax                 #+5

  4007f6:    0f b6 00                 movzbl (%rax),%eax              #5文字目
  4007f9:    48 0f be d8              movsbq %al,%rbx
  4007fd:    48 8b 45 d0              mov    -0x30(%rbp),%rax
  400801:    48 83 c0 08              add    $0x8,%rax
  400805:    48 8b 00                 mov    (%rax),%rax               #引数の先頭
  400808:    48 89 c7                 mov    %rax,%rdi
  40080b:    e8 00 fd ff ff           callq  400510 <strlen@plt>
  400810:    48 89 c2                 mov    %rax,%rdx                  #長さ=11
  400813:    48 89 d0                 mov    %rdx,%rax
  400816:    48 c1 e0 03              shl    $0x3,%rax                  #8倍=88
  40081a:    48 01 d0                 add    %rdx,%rax                  #加算して99
  40081d:    48 83 e8 04              sub    $0x4,%rax                #99-4=95
  400821:    48 39 c3                 cmp    %rax,%rbx                 #95=_

続いて以下の箇所で1文字目と7文字目が同じでなければいけないことが分かります。

  400838:    48 83 c0 01              add    $0x1,%rax                 #+1
  40083c:    0f b6 10                 movzbl (%rax),%edx              #1文字目
  40083f:    48 8b 45 d0              mov    -0x30(%rbp),%rax
  400843:    48 83 c0 08              add    $0x8,%rax
  400847:    48 8b 00                 mov    (%rax),%rax
  40084a:    48 83 c0 07              add    $0x7,%rax                 #+7
  40084e:    0f b6 00                 movzbl (%rax),%eax              #7文字目
  400851:    38 c2                    cmp    %al,%dl                        #1文字目=7文字目

さらに1文字目と10文字目も同じです。

  400867:    48 83 c0 01              add    $0x1,%rax                 #+1
  40086b:    0f b6 10                 movzbl (%rax),%edx             #1文字目
  40086e:    48 8b 45 d0              mov    -0x30(%rbp),%rax
  400872:    48 83 c0 08              add    $0x8,%rax
  400876:    48 8b 00                 mov    (%rax),%rax
  400879:    48 83 c0 0a              add    $0xa,%rax                #+10
  40087d:    0f b6 00                 movzbl (%rax),%eax             #10文字目
  400880:    38 c2                    cmp    %al,%dl                       #1文字目=10文字目

そして次の箇所で1文字目が確定します。したがって、1,7,10文字目がaになります。

  400896:    48 83 c0 01              add    $0x1,%rax                #+1
  40089a:    0f b6 00                 movzbl (%rax),%eax             #1文字目
  40089d:    0f be c0                 movsbl %al,%eax
  4008a0:    8d 50 ef                 lea    -0x11(%rax),%edx       #-17して
  4008a3:    48 8b 45 d0              mov    -0x30(%rbp),%rax
  4008a7:    48 83 c0 08              add    $0x8,%rax
  4008ab:    48 8b 00                 mov    (%rax),%rax              #引数の先頭
  4008ae:    0f b6 00                 movzbl (%rax),%eax
  4008b1:    0f be c0                 movsbl %al,%eax                 #0文字目
  4008b4:    39 c2                    cmp    %eax,%edx                #1文字目=0文字目(80)+17=97=a

次に以下の箇所で3文字目と9文字目を比較しています。9文字目はdです。

  4008ca:    48 83 c0 03              add    $0x3,%rax                #+3
  4008ce:    0f b6 10                 movzbl (%rax),%edx             #3文字目
  4008d1:    48 8b 45 d0              mov    -0x30(%rbp),%rax
  4008d5:    48 83 c0 08              add    $0x8,%rax
  4008d9:    48 8b 00                 mov    (%rax),%rax
  4008dc:    48 83 c0 09              add    $0x9,%rax                #+9
  4008e0:    0f b6 00                 movzbl (%rax),%eax            #9文字目

  4008e3:    38 c2                    cmp    %al,%dl                      #3文字目=d=9文字目

続いて、4文字目はiです。

  4008f9:    48 83 c0 04              add    $0x4,%rax              #+4
  4008fd:    0f b6 00                 movzbl (%rax),%eax           #4文字目
  400900:    3c 69                    cmp    $0x69,%al                #0x69=i

続いて1文字目と2文字目を比較しています。2文字目はnです。

  400916:    48 83 c0 02              add    $0x2,%rax                #+2
  40091a:    0f b6 00                 movzbl (%rax),%eax             #2文字目
  40091d:    0f be d0                 movsbl %al,%edx
  400920:    48 8b 45 d0              mov    -0x30(%rbp),%rax
  400924:    48 83 c0 08              add    $0x8,%rax
  400928:    48 8b 00                 mov    (%rax),%rax
  40092b:    48 83 c0 01              add    $0x1,%rax                #+1
  40092f:    0f b6 00                 movzbl (%rax),%eax              #1文字目
  400932:    0f be c0                 movsbl %al,%eax
  400935:    29 c2                    sub    %eax,%edx                  #2文字目-1文字目
  400937:    89 d0                    mov    %edx,%eax
  400939:    83 f8 0d                 cmp    $0xd,%eax                 #d=13+1文字目(97)=110=n

続いて7文字目と8文字目を比較しています。8文字目はnです。

  400950:    48 83 c0 08              add    $0x8,%rax                #+8
  400954:    0f b6 00                 movzbl (%rax),%eax             #8文字目
  400957:    0f be d0                 movsbl %al,%edx
  40095a:    48 8b 45 d0              mov    -0x30(%rbp),%rax
  40095e:    48 83 c0 08              add    $0x8,%rax
  400962:    48 8b 00                 mov    (%rax),%rax
  400965:    48 83 c0 07              add    $0x7,%rax                #+7
  400969:    0f b6 00                 movzbl (%rax),%eax             #7文字目
  40096c:    0f be c0                 movsbl %al,%eax
  40096f:    29 c2                    sub    %eax,%edx                   #8文字目-7文字目
  400971:    89 d0                    mov    %edx,%eax
  400973:    83 f8 0d                 cmp    $0xd,%eax                #d=13+7文字目(97)+13=110=n

以上により、コマンドライン引数にPandi_pandaを指定すればよさそうです。実際に試してみます。

$ ./stage2.bin Pandi_panda
Good good!
f0VMRgIBAQAAAAAAAAAAAAIAPgABAAAAEAdAAAAAAABAAAAAAAAAANBBAAAAAAAAAAAAAEAAOAAJ

(略)

AA==

Goodと表示されました。したがって、フラグは、

Pandi_panda

です。



アセンブリ言語スタートブック
高田美樹
技術評論社
2015-08-08

Nuit du Hack CTF Quals 2016 writeup Matriochka - Step 1

Matriochka - Step 1

Description

Can you help me?

Recently, I found an executable binary.

As I'm a true newbie,

Certainly, to solve it, I will have difficulties.

Keep in mind, the first step is quite easy.

Maybe the last one will be quite tricky.

Emulating it could be a good idea.

The challenge is available at : http://static.quals.nuitduhack.com/stage1.bin


Details

Points
50
Category
Crack Me
Validations
222

Attachments

Filename Size Hash (SHA-256)
stage1.bin 64.58 kB ed0093922d7b3f42a34610a3dd3d09f92c42ef8647a514a7cce8dea7fecbf116
fileコマンドでダウンロードしたファイルのファイルタイプを確認します。Linuxの64bitバイナリのようです。
$ file stage1.bin
stage1.bin: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=d023239e2bf37734ba5a67401a092ba6273c37b6, not stripped
ダウンロードしたファイルを実行すると、次のとおり引数にパスワードを指定する必要があることが分かります。
$ ./stage1.bin
Usage: ./stage1.bin <pass>
ここでstringsコマンドでファイル中の文字列を確認します。
$ strings stage1.bin
(略)
Much_secure__So_safe__Wow
Good good!
Try again...
;*3$"
Much_secure__So_safe__Wowという文字列が怪しいですね。これを引数に指定して実行してみます。下記のとおりGoodと表示され、Base64でエンコードされた文字列が出力されました。
$ ./stage1.bin Much_secure__So_safe__Wow
Good good!
c3RhZ2UyLmJpbgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
(略)
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
したがって、フラグは、
Much_secure__So_safe__Wow
です。







Pwn2Win CTF 2016 writeup Hidden in Plain Sight

Hidden in Plain Sight
Points: 40
Category: Forensics
Description:
Hidden in Plain Sight

HINT: you need to know the basic principle behind how MEGA works in order to solve this challenge. Flag.txt is the flag, but it is hidden... in plain sight ;)

DICA: você precisa saber o princípio básico de funcionamento do MEGA para resolver esse desafio. Flag.txt é a flag, mas ela está escondida... em plena vista ;)

Hints:
2016-03-25 16:49:23 - The flag is in the file, but maybe you shouldn't download the file the usual way ;)
2016-03-25 17:58:46 - When I read PLAIN, it reminds me of PLAINTEXT
2016-03-25 18:51:57 - As we first said in the IRC channel, this challenge should be simple to solve using only a webbrowser (e.g. Firefox or Chrome)
リンクをクリックすると、次のようにオンラインストレージサービス「MEGA」のダウンロードページが表示されます。

no title

そのままflag.txtをダウンロードしても、下記のとおり文字化け?しています。
}ッv#ハヨ學QxJZzム\M�2失��ニ&Nイ<ュzエ犇┥ナ*求�
�k/テテオ
ここで、オンラインストレージサービス「MEGA」の仕組みを調べてみます。
http://www.fortinet.co.jp/security_blog/130618-DotComs-Mega-Encryption-Scheme-Illustrated.html
http://y4miken.blog.jp/archives/mega.co.nz.html

URLの!で囲まれた部分!6N0gmRLK!がファイルID、その後ろの残りの部分VsN9gLdiYbxMVTA-AdsRjsvezMpdEqiR9ngwrS6gR7kが復号鍵になります。ファイルはダウンロードされた後に、この復号鍵を使ってクライアントサイドで復号されるそうです。
ということで、Chromeのデベロッパーツールを使用して、複合化する前のデータを確認してみます。

1

やはり復号前のデータのほうが平文だったようです。
フラグは、
CTF-BR{0_CLUB3_C0s7um4_us4r_CryPt0___mas_nem_sempre}
です。



記事検索
ギャラリー
  • TetCTF 2023 NewYearBot
  • UUT CTF writeup Find The Password
  • UUT CTF writeup The Puzzle
  • Hack Zone Tunisia 2019 writeup Microscope
  • Hack Zone Tunisia 2019 writeup Welcome
  • SwampCTF 2019 writeup Brokerboard
  • SwampCTF 2019 writeup Leap of Faith
  • SwampCTF 2019 writeup Last Transmission
  • CBM CTF 2019 writeup Long road
カテゴリー