LoginSignup
1
3

More than 5 years have passed since last update.

CSCAMP 2014 CTF writeup

Last updated at Posted at 2014-11-23

binary

Elf1 100点

問題ファイル

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

実行するとパスワードを聞かれる
パスワードが間違っていると何も起こらない

$./binary 
*********************************
  welcome to cracking challenge
*********************************
Enter you password: a

gdbで実行しながらexitしないように進めていく

0x400986 <main+34>:        test   rax,rax
(gdb)set $rax=0

0x4008f6 <xxxx+97>:        mov    DWORD PTR [rbp-0x7e4],eax
(gdb)set $eax=0xc

0x400930 <xxxx+155>:        test   eax,eax
(gdb)set $eax=0x0

0x4007f0 <xxxxx+118>:        test   eax,eax
(gdb)set $eax=0x0

このように分岐をスルーしていくとflagが表示される

Flag: ping-pong@
しかしこのflagは通らなかった。

なのでパスワードを求める

0x4007c3 <xxxxx+73>:    call   0x400c10 <base64_decode>
ここで入力したものをbase64でデコードしている

0x4007cf <xxxxx+85>:   mov    eax,0x400f40
RAX: 0x400f40 --> 0x6c460072696d6173 ('samir')
0x400f40にはsamirという文字列が入っている

0x4007df <xxxxx+101>:  repz cmps BYTE PTR ds:[rsi],BYTE PTR es:[rdi]
デコードしたものとsamirを比較している

ということでsamirをbase64でエンコードしたものを入力してみる

./binary 
*********************************
  welcome to cracking challenge
*********************************
Enter you password: c2FtaXI=
Flag: ping-pong@

これらを入力しても正解にならない
ping-pong@
samir
c2FtaXI=

おかしい。
flagをデコードしている場所を見てみる

0x400861 <xxxxx+231>:   call   0x400c10 <base64_decode>
このときの引数
arg[0]: 0x7fffffffdb10 ("cGluZy1wb25n")
arg[1]: 0xc ('\x0c')
arg[2]: 0x7fffffffdb40 --> 0x0 

cGluZy1wb25n これをbase64でデコードするとping-pong

後ろについていた@がいらなかったらしい。 ということで
Flag ping-pong


Elf2 100点

問題ファイル

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

実行しても無反応
bokkenに入れてみる
とりあえずStringsを見ると

0x00400881 7 str.xxyyzz
0x00400878 9 str.Flags
0x0040086e 10 str..flag.txt

どこで使われているか確認

/ function: sym.xxyyzz (94)
| 0x00400697  sym.xxyyzz:
| 0x00400697     55               push rbp
| 0x00400698     4889e5           mov rbp, rsp
| 0x0040069b     4883ec10         sub rsp, 0x10
| 0x0040069f     ba6c084000       mov edx, 0x40086c
| 0x004006a4     b86e084000       mov eax, str..flag.txt
| 0x004006a9     4889d6           mov rsi, rdx
| 0x004006ac     4889c7           mov rdi, rax
| 0x004006af     e89cfeffff       call dword imp.fopen
|     ; imp.fopen()
| 0x004006b4     488945f8         mov [rbp-0x8], rax
| 0x004006b8     48837df800       cmp qword [rbp-0x8], 0x0
| 0x004006bd     750a             jnz loc.004006c9
| 0x004006bf     bf00000000       mov edi, 0x0
| 0x004006c4     e8a7feffff       call dword imp.exit
|     ; imp.exit()
| ; CODE (JMP) XREF 0x004006bd (sym.xxyyzz)
/ loc: loc.004006c9 (44)
| 0x004006c9  loc.004006c9:
| 0x004006c9     b978084000       mov ecx, str.Flags
| 0x004006ce     488b45f8         mov rax, [rbp-0x8]
| 0x004006d2     ba81084000       mov edx, str.xxyyzz
| 0x004006d7     4889ce           mov rsi, rcx
| 0x004006da     4889c7           mov rdi, rax
| 0x004006dd     b800000000       mov eax, 0x0
| 0x004006e2     e849feffff       call dword imp.fprintf
|     ; imp.fprintf()
| 0x004006e7     488b45f8         mov rax, [rbp-0x8]
| 0x004006eb     4889c7           mov rdi, rax
| 0x004006ee     e81dfeffff       call dword imp.fclose
|     ; imp.fclose()
| 0x004006f3     c9               leave
\ 0x004006f4     c3               ret

flag.txtを開くことができたら何かを書き込むのかなー ということで何を書き込むかgdbで見てみる

(gdb)disas xxyyzz
Dump of assembler code for function xxyyzz:
   0x0000000000400697 <+0>: push   rbp
   0x0000000000400698 <+1>: mov    rbp,rsp
   0x000000000040069b <+4>: sub    rsp,0x10
   0x000000000040069f <+8>: mov    edx,0x40086c
   0x00000000004006a4 <+13>:    mov    eax,0x40086e
   0x00000000004006a9 <+18>:    mov    rsi,rdx
   0x00000000004006ac <+21>:    mov    rdi,rax
   0x00000000004006af <+24>:    call   0x400550 <fopen@plt>
   0x00000000004006b4 <+29>:    mov    QWORD PTR [rbp-0x8],rax
   0x00000000004006b8 <+33>:    cmp    QWORD PTR [rbp-0x8],0x0
   0x00000000004006bd <+38>:    jne    0x4006c9 <xxyyzz+50>
   0x00000000004006bf <+40>:    mov    edi,0x0
   0x00000000004006c4 <+45>:    call   0x400570 <exit@plt>
   0x00000000004006c9 <+50>:    mov    ecx,0x400878
   0x00000000004006ce <+55>:    mov    rax,QWORD PTR [rbp-0x8]
   0x00000000004006d2 <+59>:    mov    edx,0x400881
   0x00000000004006d7 <+64>:    mov    rsi,rcx
   0x00000000004006da <+67>:    mov    rdi,rax
   0x00000000004006dd <+70>:    mov    eax,0x0
   0x00000000004006e2 <+75>:    call   0x400530 <fprintf@plt>
   0x00000000004006e7 <+80>:    mov    rax,QWORD PTR [rbp-0x8]
   0x00000000004006eb <+84>:    mov    rdi,rax
   0x00000000004006ee <+87>:    call   0x400510 <fclose@plt>
   0x00000000004006f3 <+92>:    leave  
   0x00000000004006f4 <+93>:    ret  

fprintfの引数を確認

(gdb) x/s 0x400878
0x400878:    "Flag: %s"
(gdb) x/s 0x400881
0x400881 <__FUNCTION__.3311>:    "xxyyzz"

Flag : xxyyzz が書き込まれるらしい これをsubmitしたら正解でした。


PE 1 100点

問題ファイル

$file level1.exe 
level1.exe: PE32 executable (console) Intel 80386, for MS Windows

実行する

****************
  it's so easy
****************
enter the secret key: a

間違っていると何も起こらない
idaで中身を見る
stringsにFlag is: という文字があるのでそこを見る

kore.png

0x00401A40でジャンプしなければ良さそう
OllyDbgで見る

00401704  /$  55            PUSH EBP
00401705  |.  89E5          MOV EBP,ESP
00401707  |.  83EC 18       SUB ESP,18
0040170A  |.  A1 00934800   MOV EAX,DWORD PTR DS:[<&KERNEL32.IsDebug>; |
0040170F  |.  FFD0          CALL NEAR EAX                            ; |[IsDebuggerPresent
00401711  |.  83F8 01       CMP EAX,1                                ; |
00401714  |.  0F94C0        SETE AL                                  ; |
00401717  |.  84C0          TEST AL,AL                               ; |
00401719  |.  74 1D         JE SHORT level1.00401738                 ; |
0040171B  |.  C70424 E80300>MOV DWORD PTR SS:[ESP],3E8               ; |
00401722  |.  A1 38934800   MOV EAX,DWORD PTR DS:[<&KERNEL32.Sleep>] ; |
00401727  |.  FFD0          CALL NEAR EAX                            ; \Sleep
00401729  |.  83EC 04       SUB ESP,4
0040172C  |.  C70424 000000>MOV DWORD PTR SS:[ESP],0                 ; |
00401733  |.  E8 48460100   CALL <JMP.&msvcrt.exit>                  ; \exit
00401738  |>  C9            LEAVE
00401739  \.  C3            RETN

IsDebuggerPresentがあるので適当につぶし
0x00401a40をJNE SHORT 00401A98やNOPなどにするとflagがでる

Flag is :aiiajc(eik


PE 2 100点

問題ファイル

$file binary-pe.exe 
binary-pe.exe: PE32 executable (console) Intel 80386 (stripped to external PDB), for MS Windows

実行する

enter the key: a

間違っていると何も起こらない

idaのstringsを見る
kore.png

0x004014ACこのcmp命令があっていればflagが表示されるみたい
OllyDbgで値を確認する

kore2.png

これを10進数にしたものを入力

enter the key: 1309495
Flag: 1309495

Flag : 1309495


PE 3 200点

問題ファイル

$file bin.exe 
bin.exe: data

ということでバイナリエディタにれる

00000000  4e 5a 90 00 03 00 00 00  04 00 00 00 ff ff 00 00  |NZ..............|
00000010  b8 00 00 00 00 00 00 00  40 00 00 00 00 00 00 00  |........@.......|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 80 00 00 00  |................|
00000040  0e 1f ba 0e 00 b4 09 cd  21 b8 01 4c cd 21 54 68  |........!..L.!Th|
00000050  69 73 20 70 72 6f 67 72  61 6d 20 63 61 6e 6e 6f  |is program canno|
00000060  74 20 62 65 20 72 75 6e  20 69 6e 20 44 4f 53 20  |t be run in DOS |
00000070  6d 6f 64 65 2e 0d 0d 0a  24 00 00 00 00 00 00 00  |mode....$.......|
00000080  50 45 00 00 4c 01 08 00  d8 3f 6b 54 00 1c 0a 00  |PE..L....?kT....|
00000090  1a 38 00 00 e0 00 07 03  0b 01 02 17 00 be 06 00  |.8..............|

先頭のNZをMZに直す

$file bin.exe 
bin.exe: PE32 executable (console) Intel 80386 (stripped to external PDB), for MS Windows

実行する

*****************************************
         welcome in cairo ctf
*****************************************

idaのstringsを見るとFlag:というものがある

.text:00401491                 push    ebp
.text:00401492                 mov     ebp, esp
.text:00401494                 push    ebx
.text:00401495                 sub     esp, 24h
.text:00401498                 lea     eax, [ebp-11h]
.text:0040149B                 mov     ecx, eax
.text:0040149D                 call    nullsub_2
.text:004014A2                 lea     eax, [ebp-18h]
.text:004014A5                 lea     edx, [ebp-11h]
.text:004014A8                 mov     [esp+4], edx
.text:004014AC                 mov     dword ptr [esp], offset aFlagflag ; "flagflag"
.text:004014B3                 mov     ecx, eax
.text:004014B5                 call    sub_44473C
.text:004014BA                 sub     esp, 8
.text:004014BD                 lea     eax, [ebp-11h]
.text:004014C0                 mov     ecx, eax
.text:004014C2                 call    nullsub_3
.text:004014C7                 lea     eax, [ebp-0Ch]
.text:004014CA                 lea     edx, [ebp-18h]
.text:004014CD                 mov     [esp], edx
.text:004014D0                 mov     ecx, eax
.text:004014D2                 call    sub_444960
.text:004014D7                 sub     esp, 4
.text:004014DA                 lea     eax, [ebp-10h]
.text:004014DD                 lea     edx, [ebp-0Ch]
.text:004014E0                 mov     [esp+4], edx
.text:004014E4                 mov     [esp], eax
.text:004014E7                 call    sub_4013B0
.text:004014EC                 lea     eax, [ebp-18h]
.text:004014EF                 lea     edx, [ebp-10h]
.text:004014F2                 mov     [esp], edx
.text:004014F5                 mov     ecx, eax
.text:004014F7                 call    sub_445BC8
.text:004014FC                 sub     esp, 4
.text:004014FF                 lea     eax, [ebp-10h]
.text:00401502                 mov     ecx, eax
.text:00401504                 call    sub_445B38
.text:00401509                 lea     eax, [ebp-0Ch]
.text:0040150C                 mov     ecx, eax
.text:0040150E                 call    sub_445B38
.text:00401513                 mov     dword ptr [esp+4], offset aFlag ; "Flag: "
.text:0040151B                 mov     dword ptr [esp], offset dword_472F80
.text:00401522                 call    sub_465CE4
.text:00401527                 lea     edx, [ebp-18h]
.text:0040152A                 mov     [esp+4], edx
.text:0040152E                 mov     [esp], eax
.text:00401531                 call    sub_465F20
.text:00401536                 mov     dword ptr [esp+4], offset asc_474075 ; "\n"
.text:0040153E                 mov     [esp], eax
.text:00401541                 call    sub_465CE4
.text:00401546                 lea     eax, [ebp-18h]
.text:00401549                 mov     ecx, eax
.text:0040154B                 call    sub_445B38
.text:00401550                 jmp     short loc_401596

デバッガで普通に実行していると0x00401491この処理に入ることができなかったので適当に飛ばしてあげる
自分はちょうど0x004010ffにいたのでそこから飛ばしてあげました。

*****************************************
         welcome in cairo ctf
*****************************************
Flag: galfgalf

Flag: galfgalf


CTF KeyGen 300点(バイナリ部分)

問題ファイル

$file KeyGen.exe 
KeyGen.exe: PE32 executable (console) Intel 80386 Mono/.Net assembly, for MS Windows

.NETなのでデコンパイル
JetBrains dotPeek

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace bruter
{
  internal class Program
  {
    public static byte[] AES_Encrypt(byte[] bytesToBeEncrypted, byte[] passwordBytes)
    {
      byte[] bytes = Encoding.ASCII.GetBytes(Environment.UserName.ToLower().PadLeft(8, 'a'));
      using (MemoryStream memoryStream = new MemoryStream())
      {
        using (RijndaelManaged rijndaelManaged = new RijndaelManaged())
        {
          rijndaelManaged.KeySize = 256;
          rijndaelManaged.BlockSize = 128;
          Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(passwordBytes, bytes, 1000);
          rijndaelManaged.Key = rfc2898DeriveBytes.GetBytes(rijndaelManaged.KeySize / 8);
          rijndaelManaged.IV = rfc2898DeriveBytes.GetBytes(rijndaelManaged.BlockSize / 8);
          rijndaelManaged.Mode = CipherMode.CBC;
          using (CryptoStream cryptoStream = new CryptoStream((Stream) memoryStream, rijndaelManaged.CreateEncryptor(), CryptoStreamMode.Write))
          {
            cryptoStream.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length);
            cryptoStream.Close();
          }
          return memoryStream.ToArray();
        }
      }
    }

   public static byte[] AES_Decrypt(byte[] bytesToBeDecrypted, byte[] passwordBytes)
    {
      byte[] bytes = Encoding.ASCII.GetBytes(Environment.UserName.ToLower().PadLeft(8, 'a'));
      using (MemoryStream memoryStream = new MemoryStream())
      {
        using (RijndaelManaged rijndaelManaged = new RijndaelManaged())
        {
          rijndaelManaged.KeySize = 256;
          rijndaelManaged.BlockSize = 128;
          Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(passwordBytes, bytes, 1000);
          rijndaelManaged.Key = rfc2898DeriveBytes.GetBytes(rijndaelManaged.KeySize / 8);
          rijndaelManaged.IV = rfc2898DeriveBytes.GetBytes(rijndaelManaged.BlockSize / 8);
          rijndaelManaged.Mode = CipherMode.CBC;
          using (CryptoStream cryptoStream = new CryptoStream((Stream) memoryStream, rijndaelManaged.CreateDecryptor(), CryptoStreamMode.Write))
          {
            cryptoStream.Write(bytesToBeDecrypted, 0, bytesToBeDecrypted.Length);
            cryptoStream.Close();
          }
          return memoryStream.ToArray();
        }
      }
    }

   public static string EncryptText(string input, string password)
    {
      return Convert.ToBase64String(Program.AES_Encrypt(Encoding.UTF8.GetBytes(input), SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(password))));
    }

   public static string DecryptText(string input, string password)
    {
      return Encoding.UTF8.GetString(Program.AES_Decrypt(Convert.FromBase64String(input), SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(password))));
    }

 private static void Main(string[] args)
    {
      string str = Environment.MachineName.ToLower().Substring(0, 3).PadRight(10, 'Z');
      string password = str + ((int) str[0] % 2 == 0 ? "E" : "O");
      try
      {
        >Console.WriteLine(Program.DecryptText("PUIrT3Y/JtMMnOoxew7Mj937vKbBYgVPfOL5MdQ1VgE=", password));
        Console.ReadLine();
      }
      catch (Exception ex)
      {
        Console.WriteLine("Try again");
      }
    }
  }
}

mainにあるマシンネームと
AES_Decryptにあるユーザーネームを総当りすればデコードできそう

string str = Environment.MachineName.ToLower().Substring(0, 3).PadRight(10, 'Z');


byte[] bytes = Encoding.ASCII.GetBytes(Environment.UserName.ToLower().PadLeft(8, 'a'));

ユーザー名はバイナリの中に書いてある

C:\Users\Adham\Documents\CTF\bruter\bruter\obj\x86\Release\bruter.pdb

適当にマシーン名だけ総当り
マシンネーム先頭 ozi のときにうまくデコードできた
Flag: IWISHCTFSHADKEYGENS


PE4は解けませんでした。
問題ファイル


Exploit 1 も解けませんでした。
問題ファイル

178.63.58.69 3016
usr: ctf, pass: canyoudoit
flag in /home/flag/flag.txt


1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3