Nuit du Hack CTF Quals 2016

Nuit du Hack CTF Quals 2016 writeup Trololo

Trololo

Description

A computer belonging to a new company has been infected by a malware. This is a known version of a cryptolocker software, that uses a irc server to received commands. Let's try to grab its password...

The challenge is available at : http://static.quals.nuitduhack.com/trololo.pcap


Details

Points
100
Category
Inforensic
Validations
74

Attachments

This challenge has no attachment.

ダウンロードしたファイルはパケットキャプチャしたファイルです。Wiresharkで開いて、「File」→「Export Objects」→「HTTP」を選択します。config.encファイルを選択して保存します。


no title

抽出したconfig.encファイルをバイナリエディタで見てみます。全てのバイトが80~FFの間に入っているので、ビットを反転することですべてASCIIコードの範囲になりそうです。どうなるかやってみましょう。
 ADDRESS   00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F   0123456789ABCDEF
------------------------------------------------------------------------------
 00000000  C3 C0 87 92 93 DF 89 9A 8D 8C 96 90 91 C2 DD CE   テタ��那凹轟鱒堕ンホ
 00000010  D1 CF DD DF 9A 91 9C 90 9B 96 91 98 C2 DD 8A 8B   ムマン゚囁恊尠遭ツン葛
 00000020  99 D2 C7 DD DF C0 C1 F5 C3 9C 90 91 99 96 98 8A   參ヌン゚タチ恊鎗迄轄
(略)
次のRubyプログラムでビット反転させたデータをファイルに出力します。
w = open("aaa.txt", "wb")
f = open("config.enc", "rb")
f.each_byte do |c|
    w.write([c ^ 0xff].pack('C'))
end
f.close
w.close
実行すると次のファイルが出来ます。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
        <mailSettings>
            <smtp from="crypto@ndh2k16.com">
                <network host="hermes.ndh2k16.local" port="25"/>
            </smtp>
        </mailSettings>
        <NDHCrypto.Settings>
            <setting name="EXT_TO_ENCRYPT" serializeAs="String">
                <value>docx:doc:xls:xlsx:pdf:jpg:odt:ods:png:bmp:avi:mp4</value>
            </setting>
            <setting name="KEY" serializeAs="String">
                <value>AD784DA62D1DDBB19B7F0500A52DD15C0BD70F924A5EF7C3CEA134C428747AFB</value>
            </setting>
            <setting name="SUBJECT" serializeAs="String">
                <value>New infected</value>
            </setting>
            <setting name="IRC_SRV" serializeAs="String">
                <value>irc://irc.ndh2k16.com:6667</value>
            </setting>
            <setting name="IRC_CHAN" serializeAs="String">
                <valude>#Crypt0NDH2K16</value>
            </setting>
            <setting name="IRC_CHANPASS" serializeAs="String">
                <value>orudeujieh6oonge4She</value>
            </setting>
        </NDHCrypto.Settings>
</configuration>
IRC_CHANPASS(パスワード)の値がフラグになります。

したがって、フラグは、

orudeujieh6oonge4She

です。





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
です。







記事検索
ギャラリー
  • 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
カテゴリー