开源蜜罐HFish使用心得2 - 高交互Web蜜罐

前言

这里魔改的HFish指的是三斤大佬维护的版本,现在的版本为闭源免费使用。

考虑到蜜罐的使用场景,主要为伪装成开放端口、服务和对外的web服务

经过测试,这个版本的HFish,无法捕获全端口位置扫描,当然可以通过自定义配置端口监听,可实现端口TCP三次握手后的捕获,syn扫描无法捕获

部署在内网,在我看来,不需要太多的交互,低交互蜜罐就够用了,及时发现内网中的异常行为,我在内网部署了一套OpenCanray低交互蜜罐,这里推荐美团大佬 P师傅 p1r06u3 的项目https://github.com/p1r06u3/opencanary_web,提供了web端管理后台

这篇文章写一下我对web蜜罐的一些想法

 

诱饵

web蜜罐,需要一个交互式的web网站,我用了fastadmin框架模拟了一个web后台,申请了一个比较有诱惑力的域名,如admin1、admins、sysadmin、sadmin、adminer、devadmin、testadmin、loginadmin、wpadmin等等,登陆的前端代码注释里面留一下测试账号等等

1

这里和HFish 自带的web蜜罐报警不一样,因为是高交互,有后台,这里对暴力破解不会产生报警,只有登陆成功才会触发报警

这样有一个好处就是,对外仅保留web蜜罐,蜜罐上报接口和key不会暴漏

改造

HFish 对于web的上报接口主要有3个

1
2
3
web_url = /api/v1/post/report                   # WEB蜜罐上报 API
deep_url = /api/v1/post/deep_report             # 暗网蜜罐上报 API
plug_url = /api/v1/post/plug_report             # 插件蜜罐上报 API

做一下区分:

其中plug接口用于做攻击行为感知

deep接口用于接收登陆成功攻击成功的告警

web接口用于接收文件操作命令监控溯源等信息

这里修改一下deep接口的代码,ip通过表单提交,因为登陆成功和攻击成功,都是在后台上报,无法在客户端获取

/view/api/view.go

1
2
3
4
5
func ReportDeepWeb(c *gin.Context) {
    ...
    ip := c.PostForm("ip")
    ...
}

登陆成功告警

找到后台登陆逻辑
/fastadmin/application/admin/controller/Index.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public function login(){
    ...
    $result = $this->auth->login($username, $password, $keeplogin ? 86400 : 0);
    $username = $this->request->post('username');
    $password = $this->request->post('password');
    $ip = $this->request->ip();

    if ($result === true) {
        $url1 = "http://127.0.0.1:8080/api/v1/post/deep_report";
        $name = "后台登录成功告警";
        $jsonStr = "$name&info=$username%26%26$password&sec_key=xxx&ip=$ip";
        $a = $this->request_by_curl($url1, $jsonStr);
    ...
}

攻击行为感知

这里参考:HFish 插件 (任意站点,皆可蜜罐),通过nginx + lua,将请求头和请求体发送到蜜罐,就是存放完整的访问日志,在检测到攻击告警时,通过分析日志来判断攻击者做了什么操作

这里省事,直接安装OpenResty

这里从docker镜像里,把lua脚本扒出来

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
local cjson = require "cjson"
local http = require "resty.http"

local function http_post(url, body)
    local httpc = http.new()
    httpc:set_timeout(30000)
    local res, err_ = httpc:request_uri(url, {
        method = "POST",
        body = body,
        headers = {["Content-Type"] = "application/json"}
    })
    httpc:set_keepalive(5000, 100)
    httpc:close()
end

local function get_data()
    local data = {
        host = ngx.var.host,
        uri = ngx.var.uri,
        method = ngx.var.request_method,
        remote_addr = ngx.var.http_x_forwarded_for,
        time_local = ngx.var.time_local,
        http_user_agent = ngx.var.http_user_agent,
        request_time = ngx.var.request_time
    }

    if "GET" == ngx.var.request_method then
        data["args"] = ngx.req.get_uri_args()
    elseif "POST" == ngx.var.request_method then
        ngx.req.read_body()
        data["args"] = ngx.req.get_post_args()
    end


    function string.split(input, delimiter)
        input = tostring(input)
    	delimiter = tostring(delimiter)
        if (delimiter=='') then return false end
    	local pos,arr = 0, {}
    	-- for each divider found
    	for st,sp in function() return string.find(input, delimiter, pos, true) end do
    	    table.insert(arr, string.sub(input, pos, st - 1))
    	    pos = sp + 1
    	end
    	table.insert(arr, string.sub(input, pos))
    	return arr
    end

    local headers=ngx.req.get_headers()
    local clientIP=headers["X_FORWARDED_FOR"]
    if clientIP == nil or string.len(clientIP) == 0 or clientIP == "unknown" then
        clientIP = ngx.var.remote_addr    
    end
    if clientIP ~= nil and string.len(clientIP) >15  then
        local pos  = string.split(clientIP,',')
        clientIP = pos[1]

    end

    local result = {
        name = ngx.var.hfish_name,
        info = data,
        sec_key = ngx.var.hfish_sec_key,
        ip = clientIP
    }

    return cjson.encode(result)
end

http_post(ngx.var.hfish_api, get_data())

nginx配置文件添加

1
2
3
4
5
set $hfish_name '攻击行为感知';  # 插件名称
set $hfish_sec_key 'xxx';  # 接口安全密钥
set $hfish_api 'http://127.0.0.1:8989/api/v1/post/plug_report';    # 插件接口
    # HFish 插件核心模块
access_by_lua_file '/usr/local/src/honeypot/hfish.lua';

效果图

攻击行为感知

<i class="fa fa-pencil-square-o  article-title-icon"></i>开源蜜罐HFish使用心得2 - 高交互Web蜜罐

后台登陆成功,这里可以配合企业微信/钉钉/飞书自动告警及时响应

<i class="fa fa-pencil-square-o  article-title-icon"></i>开源蜜罐HFish使用心得2 - 高交互Web蜜罐

<i class="fa fa-pencil-square-o  article-title-icon"></i>开源蜜罐HFish使用心得2 - 高交互Web蜜罐

没时间研究的

通过nginx + lua实现更多的功能

参考:蜜罐背后的影子系统探秘 https://cloud.tencent.com/developer/article/1045869
参考:Juggler - 一个也许能骗到黑客的系统 https://github.com/C4o/Juggler

一般场景下我们会在内部部署蜜罐系统,当外部有渗透时,碰到蜜罐就会报警,蜜罐会去检索攻击源的位置,确定别攻击机器的IP端口,取得payload数据,配合IDS我们可以捕获事件的过程,然后采取对应防御措施。还有一种办法,我们可以在蜜罐被触碰的时候,把流量引入到一台具体的机器上,伪装成一个正常的服务,像侦查机一样,收集攻击服务。我们以WEB服务为例,有一个接近真实的HTTP服务器,主动或是被动的配合蜜罐收集更多的数据,当蜜罐发现威胁IP时,运用动态迁移技术,将威胁服务引到到一个提新预备好的WEB服务,记录攻击行业,还原威胁事件。

负载均衡和灰度测试的WEB服务就是根据特定的用户和被访问机器的负载情况,决定将用户的请求切入到那台服务上。我们也用这种技术, 对有可以行为的攻击请求,进行环境切换。

我们用Openresty的上流反向代理来实现这种模式。

发布者:糖太宗,转载请注明出处:https://www.qztxs.com/archives/science/technology/11374

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022年5月27日 上午11:06
下一篇 2022年5月27日 上午11:28

相关推荐

  • use_algolia_search

    去algolia官网注册账号 新建index索引 Blog   在hex项目下安装 1 2 3 4 5 6 7 8 9 10 # npm install hexo-algolia --save # export HEXO_ALGOLIA_INDEXING_KEY=xxxxxxxxxxxxxxxxxxxxxx # hexo algolia INFO ...

    技术 2022年6月2日
    1600
  • OpenRASP 部署

    0x00 前言 上周一台web服务器部署单机版OpenRASP之后感觉还不错,想在公司内部推广一下,准备在一些后台系统的服务器上安装agent,单机版部署报警日志查看不是很方便,遂部署管理后台方便管理   0x01 准备 OpenRASP使用了 ElasticSearch 和 MongoDB 两种数据库。前者用来存储报警和统计信息,后者用来存储应用...

    2022年6月13日
    7500
  • 7000字+24张图带你彻底弄懂线程池

    大家好。今天跟大家聊一聊无论是在工作中常用还是在面试中常问的线程池,通过画图的方式来彻底弄懂线程池的工作原理,以及在实际项目中该如何自定义适合业务的线程池。 一、什么是线程池 线程池其实是一种池化的技术的实现,池化技术的核心思想其实就是实现资源的一个复用,避免资源的重复创建和销毁带来的性能开销。在线程池中,线程池可以管理一堆线程,让线程执行完任务之后不会进行...

    2023年1月26日
    700
  • 我去,拷贝代码,居然还有这等好处?

    什么是耦合?耦合,是架构中,本来不相干的代码、模块、服务、系统因为某些原因联系在一起,各自独立性差,影响则相互影响,变动则相互变动的一种架构状态。感官上,怎么发现系统中的耦合?作为技术人,每每在心中骂上下游,骂兄弟部门,“这个东西跟我有什么关系?为什么需要我来配合做这个事情?”。明明不应该联动,却要被动配合,就可能有潜在的耦合。  因为公共库,导致相互受影响...

    技术 2022年5月11日
    1400
  • 某鱼App加密参数x-sign生成教程

    通过对某鱼App抓包,可发现数据请求接口中都必须携带x-sign参数,而x-sign参数的生成方式不得而知,只能通过对App进行反编译破解。本教程将利用HermesAgent框架实现对x-sign生成方法的Hook及远程调用签名方法。 本教程以某鱼App v6.5.10版本为例 第一步:反编译某鱼App 利用dex2jar工具反编译某鱼APK文件,反编译具体...

    2022年5月7日
    23300

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信