zoukankan      html  css  js  c++  java
  • 简单学习哥斯拉流量解密+Zeek捕获

    本来想简单复现学学的 但Zeek坑点比较多 就简单写篇文章记录一下

    1、简介

    哥斯拉:webshell管理工具 现今比较好用的webshell管理工具 流量加密 生成马天然免杀 插件多
    Zeek:一个比较成熟的网络分析/监控框架 也有编写专门的zeek语言 感觉可以专门当个语言来学了

    2、下载哥斯拉

    链接:https://github.com/BeichenDream/Godzilla/releases
    
    

      

    界面也是好看了不少 前几个版本以前经常被吐槽难看

    3、下载哥斯拉源码

    本来想反编译的 有现成反编译好的项目,也是最新版 链接:https://github.com/808Mak1r/GodzillaSource
    直接下载就行,git clone git://github.com/808Mak1r/GodzillaSource 会稍微快点

    4、简单的流程过一遍

    翻下加密的方法,定位到GodzillashellscryptionsphpXor emplate目录下的PhpXor里的E函数,这里将payload加密的方法,进行了先异或,base64加密再url编码再转为byte,再发送

     生成个木马看看

    大致逻辑和工具源码里的一样 进行解码执行

     

    传到服务端连上去

     

    连接时候有三个数据包,第一个包长度30893  第二个37 第三个 51

     

    将post data url解码 扔进shell解密打印

     第一个解密 看麻了 一大堆操作先放着

     

    第二个解密为 methodNametest

     

    第三个解密为 methodName getBasicsInfo 看其他表哥的分析这空白的是=号 之前也遇到过

     

    5、Zeek捕获哥斯拉流量

    安装一些依赖和下载可以参考 https://zeek-docs-cn.readthedocs.io/zh_CN/chinese/install/install.html

    因为比较大 所以得忍一下

    下的时候最好git设置一下

    git config --global http.postBuffer 1048576000 #设置缓存大小
    
    #
    只有十分钟(600秒)传输速率都低于 1KB/s 的话才会timeout
    git config --global http.lowSpeedLimit 1000
    
    git config --global http.lowSpeedTime 600

    我一般都是有现成的直接用 没有的再造 之前有S4KUR4写好的zeek哥斯拉检测代码 但直接贴上去报错了

    error in ././try.zeek, line 8: no such field in record (c$http$client_body)
    error in ././try.zeek, line 8: no such field in record (c$http$server_body)

    这zeek的错误貌似不太好查 看来还是得学学语法

    event http_message_done(c: connection, is_orig: bool, stat: http_message_stat)
    {
      if ( c?$http && c$http?$status_code && c$http?$method )
      {
        if ( c$http$status_code == 200 && c$http$method == "POST" )
          {
            local key_str: string = c$http$uid + "$_$" + cat(c$id$orig_h) + "$_$" + cat(c$id$orig_p) + "$_$" + cat(c$http$status_code) + "$_$" + cat(c$id$resp_h)+ "$_$" + cat(c$id$resp_p) + "$_$" + c$http$uri;
            local observe_str: string = cat(c$http$ts) + "$_$" + c$http$client_body + "$_$" + c$http$server_body;
            SumStats::observe("godzilla_webshell_event", SumStats::Key($str=key_str), SumStats::Observation($str=observe_str));
          }
      }
    }

     

    简单打印个helloworld

    官方文档http的位置  https://zeek-docs-cn.readthedocs.io/ 这里的函数是内置的一个函数 在解析 HTTP 消息结束时会调用

    有点感觉到这个中英混合的文档不太简单

     

    后面终于追到了那些调用的变量对应的地方

    https://zeek-docs-cn.readthedocs.io/zh_CN/chinese/scripts/base/protocols/http/main.zeek.html#type-HTTP::Info

    找到了一个在线调的 方便多了 对应的打印出来  

     但之前直接跑那两个报错 在文档还没找到 用于获取请求包和返回包的data的

    c$http$client_body
    c$http$server_body

    尝试一下老版本的特性也不太行

     

    github再搜一下 确认是自定义的

     后面找了找了找资料自己定义了两个.zeek

    vim /usr/local/zeek/share/zeek/base/protocols/http/request.zeek

    ##! This script reassembles full HTTP bodies and raises an event with the
    ##! complete contents.
    module HTTP;
    export {
        redef record Info += {
            request_body:  string  &log &optional;
            };
    }
    ## Users write a handler for this event to process the current HTTP body.
    event http_entity_data(c: connection , is_orig: bool , length: count , data: string ) &priority=5
            {
            set_state(c,is_orig);
            if(is_orig)
                    {
                    c$http$request_body = data;
                    }
            }

    用之前也最好测试一下有没有语法问题

     vim /usr/local/zeek/share/zeek/base/protocols/http/response.zeek

    module HTTP;
    export {
        redef record Info += {
           response_body: string &log &optional;
        };
        ## Flag that indicates whether to hook reply bodies.
        const hook_reply_bodies = T &redef;
    }
    ## Users write a handler for this event to process the current HTTP body.
    event http_begin_entity(c: connection, is_orig: bool)
        {
        if ( (is_orig) || (! is_orig && ! hook_reply_bodies) )
            return;
        c$http$response_body= "";
        }
    event http_entity_data(c: connection, is_orig: bool, length: count,
                           data: string) &priority=5
        {
        c$http$response_body += data;
        }

     vim /usr/local/zeek/share/zeek/base/protocols/http/__load__.zeek 添加

    @load ./request
    @load ./response

    成功获取到了请求包的data数据

    event http_message_done(c: connection, is_orig: bool, stat: http_message_stat)#http消息完成便会调用
    {
      if ( c?$http && c$http?$status_code && c$http?$method )#如果是http请求
      {
        if ( c$http$status_code == 200 && c$http$method == "POST" )#如果http等于200且为post
          { 
            #c$http$uid 用户id 标识符
            #c$id$orig_h 来源ip
            #c$id$orig_p 来源端口 
            #c$http$status_code 请求的状态码        #c$id$resp_h 服务端ip
            #c$id$resp_p 服务端端口
            #c$http$uri 请求使用的url 
            #c$http$ts 请求的时间戳
            #c$http$request_body 请求包的body
            #c$http$response_body 返回包的body
            print c$http$request_body;
            print c$http$response_body;
      }
    }
    }

     

     6、捕获哥斯拉流量

    现在该捕获了 被zeek搞得有点心累 这里直接简单无脑捕获 他第二个返回包的内容 固定是这一串 11cd6a8758984163fL1tMGI4YTljMv79NDQm7r9PZzBiOA==6c37ac826a2a04bc最终代码如下 太忙了(懒了)有些bug还有优化都没调 有时间再弄

    event http_message_done(c: connection, is_orig: bool, stat: http_message_stat)#http消息完成便会调用
    {
      if ( c?$http && c$http?$status_code && c$http?$method )#如果是http请求
      {
        if ( c$http$status_code == 200 && c$http$method == "POST" )#如果http等于200且为post
          { 
            #c$http$uid 用户id 标识符
            #c$id$orig_h 来源ip
            #c$id$orig_p 来源端口 
            #c$http$status_code 请求的状态码        #c$id$resp_h 服务端ip
            #c$id$resp_p 服务端端口
            #c$http$uri 请求使用的url 
            #c$http$ts 请求的时间戳
            #c$http$request_body 请求包的body
            #c$http$response_body 返回包的body
    
            if("11cd6a8758984163fL1tMGI4YTljMv79NDQm7r9PZzBiOA==6c37ac826a2a04bc" in c$http$response_body){
                print "[+]find godzilla";
                print "emergency url is "+c$http$uri;
                print fmt("attacker ip is: %s", c$id$orig_h);
                }
          }
      }
    }

    参考

    https://my.oschina.net/u/4587690/blog/4451917

    https://mp.weixin.qq.com/s/qnrizGo_B12RzmEF6nePDA

    https://zeek-docs-cn.readthedocs.io/zh_CN/chinese/install/install.html

    https://0x0c.cc/2020/12/05/%E5%B7%A7%E7%94%A8Zeek%E5%9C%A8%E6%B5%81%E9%87%8F%E5%B1%82%E7%8B%A9%E7%8C%8E%E5%93%A5%E6%96%AF%E6%8B%89Godzilla/

  • 相关阅读:
    列表标签
    超链接标签
    HTML:如何把一个无序列表转换成横向菜单
    window界面控制
    C++文件读写
    宽度,对齐方式的设置
    取出一个整数的每一位
    求两个数的最大公约数
    判断素数
    天才ACM ---待复习标志
  • 原文地址:https://www.cnblogs.com/Chuantouli/p/15271638.html
Copyright © 2011-2022 走看看