Ich möchte die Adresse der Funktion CreateTransaction
in PowerShell erhalten.Wie bekomme ich CreateTransaction Adresse von PowerShell
Ich weiß, wie es in C++ zu tun:
#include "stdafx.h"
#include <Windows.h>
typedef NTSTATUS(NTAPI *CreateTransaction)
(
IN LPSECURITY_ATTRIBUTES lpTransactionAttributes OPTIONAL,
IN LPGUID UOW OPTIONAL,
IN DWORD CreateOptions OPTIONAL,
IN DWORD IsolationLevel OPTIONAL,
IN DWORD IsolationFlags OPTIONAL,
IN DWORD Timeout OPTIONAL,
IN LPWSTR Description OPTIONAL
);
int main()
{
HMODULE hKtmw32 = GetModuleHandle(L"Ktmw32.dll");
CreateTransaction createTransaction = (CreateTransaction)GetProcAddress(hKtmw32, "CreateTransaction");
return 0;
}
Wie kann ich es in Powershell?
Ich habe versucht, die folgende Funktion zu verwenden, um es zu tun.
Es funktioniert gut mit anderen Funktionen, aber nicht mit CreateTransaction
.
function Local:Get-ProcAddress
{
Param
(
[OutputType([IntPtr])]
[Parameter(Position = 0, Mandatory = $True)]
[String]
$Module,
[Parameter(Position = 1, Mandatory = $True)]
[String]
$Procedure
)
# Get a reference to System.dll in the GAC
$SystemAssembly = [AppDomain]::CurrentDomain.GetAssemblies() |
Where-Object { $_.GlobalAssemblyCache -And $_.Location.Split('\\')[-1].Equals('System.dll') }
$UnsafeNativeMethods = $SystemAssembly.GetType('Microsoft.Win32.UnsafeNativeMethods')
# Get a reference to the GetModuleHandle and GetProcAddress methods
$GetModuleHandle = $UnsafeNativeMethods.GetMethod('GetModuleHandle')
$GetProcAddress = $UnsafeNativeMethods.GetMethod('GetProcAddress')
# Get a handle to the module specified
$Kern32Handle = $GetModuleHandle.Invoke($null, @($Module))
$hexAddrs = [convert]::ToString($Kern32Handle.ToInt32(), 16)
Write-Host "[*] Got $($Module) at 0x$($hexAddrs)"
$tmpPtr = New-Object IntPtr
$HandleRef = New-Object System.Runtime.InteropServices.HandleRef($tmpPtr, $Kern32Handle)
# Return the address of the function
Write-Output $GetProcAddress.Invoke($null, @([System.Runtime.InteropServices.HandleRef]$HandleRef, $Procedure))
}
Get-ProcAddress Ktmw32.dll CreateTransaction # => DOES NOT WORK
Get-ProcAddress ntdll.dll NtCreateSection # => WORKS
Referenz:
https://github.com/HarmJ0y/Misc-PowerShell/blob/master/Get-System.ps1
Ich weiß nicht, warum es mich nicht zurückkehren die Adresse CreateTransaction
.
Ich habe Abhilfe die Funktion zu nennen, aber es interessant, mich noch, wie kann ich die Funktionsadresse mit Powershell erhalten:
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
namespace PInvoke {
public class Program
{
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES {
int nLength;
IntPtr lpSecurityDescriptor;
int bInheritHandle;
}
[DllImport("Ktmw32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreateTransaction(
SECURITY_ATTRIBUTES securityAttributes,
IntPtr guid, int options, int isolationLevel, int isolationFlags,
int milliSeconds, string description
);
}
}
"@
$Class1 = New-Object PInvoke.Program
$struct = New-Object PInvoke.Program+SECURITY_ATTRIBUTES
[PInvoke.Program]::CreateTransaction($struct, 0, 0, 0, 0, 0, "notepad.exe")
Hat 'Write-Host '[*] $ ($ Module) bei 0x $ ($ hexAddrs)" 'irgendwas zurückgeben? –
@LievenKeersmaekers Nur Ausgabe an die Zeichenfolge. Sie können diese Zeile ignorieren oder entfernen. – E235
Ich weiß, was "Write-Host" tut. Die Frage war, zeigt es dir etwas Sinnvolles? Hat der GetModuleHandle zumindest gelingen? –