0x00 前言


2017年11月9日维基解密公布一个代号为Vault8的文档,包含服务器远程控制工具Hive的源代码和开发文档。开发文档中的框架图显示Hive支持流量分发功能,若流量有效,转发至Honeycomb服务器,若流量存在问题,转发至Cover Server。
本文仅站在技术研究的角度,尝试使用Apache的mod_rewrite模块实现http流量分发,完成相同的目标。

标记后的框架图如下:

之前的分析文章:

《CIA Hive测试指南——源代码获取与简要分析》

0x01 简介


本文将要介绍以下内容:

  • Windows系统下安装配置Apache mod_rewrite
  • Ubuntu系统下安装配置Apache mod_rewrite
  • 规则配置技巧与实例
  • 根据判定条件实现http流量分发

0x02 Windows系统下安装配置Apache mod_rewrite


1、下载Apache

地址:

http://httpd.apache.org/download.cgi

选择需要的版本,测试版本Apache 2.4.33,下载地址:

https://www.apachehaus.com/cgi-bin/download.plx?dli=wUWZ1allWW00kej9iUG5UeJVlUGRVYRdnWzQmW

2、安装

解压后通过命令行安装:

  1. cd Apace24bin
  2. httpd -k install

3、开启mod_rewrite模块

编辑文件: Apace24confhttpd.conf

找到#LoadModule rewrite_module modules/mod_rewrite.so,去掉#

4、开启支持.htaccess文件

编辑文件: Apace24confhttpd.conf

定位如下位置:

  1. DocumentRoot "${SRVROOT}/htdocs"
  2. <Directory "${SRVROOT}/htdocs">
  3. #
  4. # Possible values for the Options directive are "None", "All",
  5. # or any combination of:
  6. # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
  7. #
  8. # Note that "MultiViews" must be named *explicitly* --- "Options All"
  9. # doesn't give it to you.
  10. #
  11. # The Options directive is both complicated and important. Please see
  12. # http://httpd.apache.org/docs/2.4/mod/core.html#options
  13. # for more information.
  14. #
  15. Options Indexes FollowSymLinks
  16. #
  17. # AllowOverride controls what directives may be placed in .htaccess files.
  18. # It can be "All", "None", or any combination of the keywords:
  19. # Options FileInfo AuthConfig Limit
  20. #
  21. AllowOverride All
  22. #
  23. # Controls who can get stuff from this server.
  24. #
  25. Require all granted
  26. </Directory>

AllowOverride None改为AllowOverride All

5、编写.htaccess文件,配置规则

保存路径为Apace24htdocs

测试规则为将1.html重定向到2.html,具体内容如下:

  1. <IfModule mod_rewrite.c>
  2. RewriteEngine on
  3. RewriteRule 1.html 2.html
  4. </IfModule>

使用记事本打开,另存为文件,文件名为".htaccess"

注:

文件名包含引号",如下图

2.html保存在Apace24htdocs,内容如下:

  1. <html>
  2. <body>
  3. True page
  4. </body>
  5. </html>

6、开启apache服务

  1. httpd.exe -k start

7、测试

访问http://127.0.0.1/1.html

返回内容True page,代表网页被重定向到了2.html

8、补充

apache的日志路径为Apache24logs

mod_rewrite的日志保存在error.log

文件Apace24confhttpd.conf可指定日志记录等级

0x03 Ubuntu系统下安装配置Apache mod_rewrite


1、下载安装

  1. sudo apt-get install apache2

2、开启mod_rewrite模块

  1. sudo a2enmod rewrite

3、开启支持.htaccess文件

编辑文件: /etc/apache2/apache2.conf

定位如下位置:

  1. <Directory /var/www/>
  2. Options Indexes FollowSymLinks
  3. AllowOverride None
  4. Require all granted
  5. </Di 大专栏  CIA Hive Beacon Infrastructure复现1——使用Apache mod_rewrite实现http流量分发rectory>

AllowOverride None改为AllowOverride All

4、编写.htaccess文件,配置规则

保存路径为varwwwhtml

测试规则为将1.html重定向到2.html,具体内容如下:

  1. <IfModule mod_rewrite.c>
  2. RewriteEngine on
  3. RewriteRule 1.html 2.html
  4. </IfModule>

2.html保存在varwwwhtml,内容如下:

  1. <html>
  2. <body>
  3. True page
  4. </body>
  5. </html>

5、开启apache服务

  1. sudo /etc/init.d/apache2 restart

6、测试

访问http:/IP/1.html

返回内容True page,代表网页被重定向到了2.html

7、补充

apache的日志路径为/var/log/apache2/

mod_rewrite的日志保存在error.log

文件/etc/apache2/apache2.conf可指定日志记录等级

0x04 规则配置技巧与实例


1、将所有网页重定向至 https://www.baidu.com

.htaccess文件内容如下:

  1. <IfModule mod_rewrite.c>
  2. RewriteEngine on
  3. RewriteRule . https://www.baidu.com
  4. </IfModule>

2、过滤Request Header

(1) User Agent

只针对特定User Agent的请求进行重定向

实例:

使用Mac下的Safari浏览器访问1.html,将其重定向到2.html

.htaccess文件内容如下:

  1. <IfModule mod_rewrite.c>
  2. RewriteEngine on
  3. RewriteCond "%{HTTP_USER_AGENT}" "Macintosh; Intel Mac OS X 10_9_3" [NC]
  4. RewriteRule 1.html 2.html
  5. </IfModule>

参数说明:

RewriteCond "%{HTTP_USER_AGENT}" "Macintosh; Intel Mac OS X 10_9_3" [NC]代表判定条件,判断HTTP_USER_AGENT是否包含字符串"Macintosh; Intel Mac OS X 10_9_3"(大小写不敏感)

NC: 字符比较,大小写不敏感

详细参数说明可参考:

https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond

1.使用curl进行测试

模拟Chrome浏览器:

  1. curl -A "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36" http://192.168.62.137/1.html

并没重定向,如下图

模拟Mac Safari浏览器:

  1. curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A" http://192.168.62.137/1.html

网页重定向,获得2.html的内容,如下图

2.Chrome浏览器修改User Agent的方法

访问页面,F12 -> More tools -> Network conditions,选择User agent 为 Safari —— Mac

如下图

####(2) Peferer

只针对特定来源的请求进行重定向

实例:

如果来源为test.com,访问1.html时将其重定向到2.html

  1. <IfModule mod_rewrite.c>
  2. RewriteEngine on
  3. RewriteCond "%{HTTP_REFERER}" "test.com" [NC]
  4. RewriteRule 1.html 2.html
  5. </IfModule>

使用curl进行测试:

  1. curl -e "test.com" http://192.168.62.137/1.html

(3) 其他可供选择的过滤条件

如下图

注:

图片来源于https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond

补充:

Jeff Dimmock在他的博客分享了使用mod_rewrite配置规则的心得,值得学习,地址如下:

https://bluescreenofjeff.com/tags

0x05 小结


本文介绍了Windows系统和Ubuntu系统下安装配置Apache mod_rewrite的方法,分享配置技巧与实例,在技术研究的角度实现了根据请求条件进行http流量分发。

下篇文章将要介绍https的流量分发实现。


LEAVE A REPLY

上一篇:CIA Hive Beacon Infrastructure复现2——使用Apache mod_rewrite实现https流量分发

下一篇:利用Assembly Load & LoadFile绕过Applocker的分析总结

CIA Hive Beacon Infrastructure复现1——使用Apache mod_rewrite实现http流量分发的更多相关文章

  1. 【原创】大叔问题定位分享(16)spark写数据到hive外部表报错ClassCastException: org.apache.hadoop.hive.hbase.HiveHBaseTableOutputFormat cannot be cast to org.apache.hadoop.hive.ql.io.HiveOutputFormat

    spark 2.1.1 spark在写数据到hive外部表(底层数据在hbase中)时会报错 Caused by: java.lang.ClassCastException: org.apache.h ...

  2. ERROR hive.HiveConfig: Could not load org.apache.hadoop.hive.conf.HiveConf. Make sure HIVE_CONF_DIR is set correctly.

    Sqoop导入mysql表中的数据到hive,出现如下错误:  ERROR hive.HiveConfig: Could not load org.apache.hadoop.hive.conf.Hi ...

  3. 开启Apache mod_rewrite模块(解决404 Not Found)

    网站搭建完成了,进入登录界面就是访问不了. 原因大概是没有开启Apache mod_rewrite模块,或者没有配置完全. 步骤1: 启用mod_rewrite模块 在conf目录的httpd.con ...

  4. Apache mod_rewrite实现HTTP和HTTPS重定向跳转

    当你的站点使用了HTTPS之后,你可能会想把所有的HTTP请求(即端口80的请求),全部都重定向至HTTPS(即端口443).这时候你可以用以下的方式来做到:(Apache mod_rewrite) ...

  5. 关于Apache mod_rewrite的中文配置、使用和语法介绍(实现URL重写和防盗链功能)

    以数据库后台驱动的动态内容的网站,经常会遇到这些的问题: 当在浏览器的地址栏输入一个无效的参数时,会出现数据库的错误提示,这是一个安全的隐患 搜索引擎无法收录你的所有网页 网页的链接地址是一系列的参数 ...

  6. openSUSE中启用apache mod_rewrite

    1. 编辑 "/etc/sysconfig/apache2"文件 查找 APACHE_MODULES,你应该会找到一行像 APACHE_MODULES="actions ...

  7. <关于数据仓库>基于docker的Mysql与Hadoop/Hive之间的数据转移 (使用Apache Sqoop™)

    原创博客,转载请联系博主! 摘要:本文介绍了如何使用docker快速搭建一个可以从外部访问的mysql服务容器,和由docker搭建的分布式Hadoop文件系统,并且使用ApacheSqoop完成将m ...

  8. Hive JDBC:java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): User: root is not allowed to impersonate anonymous

    今天使用JDBC来操作Hive时,首先启动了hive远程服务模式:hiveserver2 &(表示后台运行),然后到eclipse中运行程序时出现错误: java.sql.SQLExcepti ...

  9. 开启Apache mod_rewrite模块完全解答

    启用mod_rewrite模块 在conf目录的httpd.conf文件中找到 LoadModule rewrite_module modules/mod_rewrite.so 将这一行前面的#去掉. ...

随机推荐

  1. target到底是什么?

    xmake是一个基于Lua的轻量级现代化c/c++的项目构建工具,主要特点是:语法简单易上手,提供更加可读的项目维护,实现跨平台行为一致的构建体验. 本文主要详细讲解下,如果在一个项目中维护和生成多个 ...

  2. windows 安装Bitcoin Core使用

    1.官网下载https://bitcoin.org/en/download 选择Windows  其他系统就选择对应的就好 2.双击安装完过后,进入bin目录,打开bitcoin-qt.exe运行,提 ...

  3. 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结【第一天】

    本人做过一年的MATLAB编程和简单维护过VB和C++的项目.是跟着网上获得的黑马的Java双元视频课来自学入门Java知识和常用框架的使用. 淘淘商城(SpringMVC+Spring+Mybati ...

  4. 项目开发git-短信验证-redis数据库

    项目开发git操作 基本流程 """ 1.开发前,拉一次远程仓库 2.工作区进行开发 3.将开发结果提交到本地版本库 - git status查看时没有待处理的事件 4. ...

  5. Python模块——json

    简介 json全名是JavaScript Object Notation(即:Javascript对象标记).它是JavaScript的子集,JSON是轻量级的文本数据交换格式.前端和后端进行数据交互 ...

  6. 洛谷 P5017 摆渡车

    题目传送门 解题思路: 个人感觉DP这东西,只可意会,不可言传 AC代码: #include<iostream> #include<cstdio> #include<cs ...

  7. 论文或github中一些通用思想

    (1) 云从 上海交大 ECCV2018 http://openaccess.thecvf.com/content_ECCV_2018/papers/Yao_Feng_Joint_3D_Face_EC ...

  8. day18-5个内置方法

    # 1. __str__方法: 必须return class Goods: def __str__(self): return 'apple' g = Goods() print(g) #apple, ...

  9. 阿里巴巴IconFont的使用方式

    一.解释一下为什么要使用IconFont? IconFont顾名思义就是把图标用字体的方式呈现. 其优点在于以下几个方面: 1.可以通过css的样式改变其颜色:(最霸气的理由) 2.相对于图片来说,具 ...

  10. 《C Prime Plus》第九节笔记

    第九节 函数 9.1 复习函数 函数原型 function prototype 函数调用 function call 函数定义 function definition 形参 实参 典型的ANSI C函 ...