周末玩了玩CTF,做个小记录
平台地址:
[HCTF 2018]WarmUp
访问靶机,只发现一滑稽.
查看网页源码,发现注释写着 source.php
。遂访问之。得到一个 highlight_file
的 php 源码
代码可以阉割成如下:
1 |
|
由于白名单中提示了一个 hint.php
。访问之。提示:
1 | flag not here, and flag in ffffllllaaaagggg |
综合以上的分析,我们得知虽然在 checkFile()
函数中,会对 $_REQUEST['file']
进行截取,保留 ?
符号 前面的部分存入 $_page
中。但是最后 inlucde 的还是原始的 $_REQUEST['file']
。
绕过 PAYLOAD:
1 | ?file=source.php?/../hint.php |
source.php
后面紧跟着 ?
号。确保在 checkFile()
中能够返回 true。
source.php
和 ?/
一起组合成了 source.php?/
。php 将会将其当作一个目录名,即使这个目录不存在。接着使用 ../
跳出目录,包含 hint.php
以验证 payload。
实验证明,上述 payload 确实有效。
获取 flag 的姿势也是一样的,就改个文件名和路径而已。 需要注意的是flag 在 Linux 根目录下而不是和 Web 同级。
[极客大挑战 2019]PHP
访问靶机,发现提示 备份网站。遂开 burp 跑字典
推荐下 key师傅 的字典。这里跑的字典用的是 Dir/Ctf.txt
https://github.com/gh0stkey/Web-Fuzzing-Box

获得备份文件 www.zip。下载解压

index.php 源码可以阉割成这样:
1 |
|
class.php 源码可以阉割成这样如下:
1 |
|
看到一个 __wakeup()
。这个函数会将 $this->username
赋值为 guest。可是其值需要为 admin 才能获取 flag。
我们可以试试 CVE-2016-7124。这个 CVE 是专门针绕过 __wakeup()
方法的。影响范围为 PHP before 5.6.25 and 7.x before 7.0.10。
利用方式为,当序列化字符串中 ,若对象属性数大于实际属性数时, __wakeup()
将不会被自动调用
若不会PHP反序列化,安利下之前写过的一篇文章 :)
https://www.freebuf.com/articles/web/209975.html
poc:
1 | class Name{ |
1 | php5.6 ttt.php |
1 | 原 payload。实际对象属性数为2 |
payload打上去即显示 flag
[MRCTF2020]你传你🐎呢
参考:
https://book.hacktricks.xyz/pentesting-web/file-upload
这道题只要上传文件名为 .php* .phtml* 都会被拦截。
另辟蹊径,上传 .htaccess 进行绕过。.htaccess 内容为 当前目录下所有 .jpg 后缀文件都以 php 进行解析
.htaccess
1 | <Files *.jpg> |
上传成功后再传个普通的 php一句话即可,查看 phpinfo()
。
disable_functions:
1 | pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,system,exec,shell_exec,popen,proc_open,passthru,symlink,link,syslog,imap_open,ld |
由于只是 get flag。那就不 getshell了。 bypass disable_function 过几天本地搭建研究下(挖一坑)。直接使用 php 内置的扫目录和读文件命令 scandir
和 file_get_contents
来进行读 flag 操作
payload:
1 | [扫目录] |