da ich heute morgen frei hatte und mir langweilig war und ja immer mal wieder die Frage nach CTRL+ALT+DEL abstellen aufkommt hab ich mal eine Lösung geschrieben (DLL Injection in Winlogon und Callbackumleitung vom SAS Window) und dazu noch ein paar einfache DLL Injection funktionen.
Achja ich hab Das nur auf XP getestet wäre nett wenn jemand mit Vista das auch nochmal testen könnte
Inspieriert hat mich das hier (teilweise auch im Code geportet eingeflossen): http://www.codeproject.com/win32/Antoni ... print=true
Die Funktionen:Funktionen
Inject(PID,DLLPath.s) -> DLL Injecten, Wichtig: Kompletten Pfad angeben
Eject(PID,hLibModule) -> DLL Ejecten, hLibModule wird von Inject zurückgegeben
GetPIDFromName(Name.s) -> PID einer Exe ermitteln
DebugPrevileg(Bool) -> #True = Debug Previleg an, benötigt man wenn man z.B. in SYSTEM Anwendungen DLLs injecten will, die Funktion wird von Inject und Eject automatisch benutzt.
Code: Alles auswählen
EnableExplicit
Procedure GetPIDFromName(Name.s)
Define hSnapshot.l, ProcessInfo.PROCESSENTRY32, Retval.l, PID.l
hSnapshot = CreateToolhelp32Snapshot_(#TH32CS_SNAPPROCESS, 0)
ProcessInfo\dwSize = SizeOf(ProcessInfo)
Retval = Process32First_(hSnapshot,@ProcessInfo)
While Retval
If PeekS(@ProcessInfo\szExeFile) = Name
PID=PeekL(@ProcessInfo\th32ProcessID)
Break
Else
Retval = Process32Next_(hSnapshot,@ProcessInfo)
EndIf
Wend
ProcedureReturn PID
EndProcedure
Procedure DebugPrevileg(Flag)
Define tk.TOKEN_PRIVILEGES, hToken.l
OpenProcessToken_(GetCurrentProcess_(),#TOKEN_ADJUST_PRIVILEGES | #TOKEN_QUERY | #TOKEN_READ, @hToken)
LookupPrivilegeValue_(0,"SeDebugPrivilege",tk\Privileges\Luid)
tk\PrivilegeCount = 1
If Flag = #True
tk\Privileges\Attributes = #SE_PRIVILEGE_ENABLED
Else
tk\Privileges\Attributes = 0
EndIf
AdjustTokenPrivileges_(hToken,0,tk,0,0,0)
EndProcedure
Procedure Inject(PID,DLLPath.s)
Define hThread.l, hProcess.l,pLibRemote.l,hLibModule.l
DebugPrevileg(#True)
hProcess = OpenProcess_(#PROCESS_ALL_ACCESS, #False, PID)
pLibRemote = VirtualAllocEx_(hProcess, #Null, 255, #MEM_COMMIT, #PAGE_READWRITE)
WriteProcessMemory_(hProcess, pLibRemote, DLLPath, 255, #Null)
hThread = CreateRemoteThread_(hProcess,#Null,0,GetProcAddress_(GetModuleHandle_("Kernel32"), "LoadLibraryA"),pLibRemote,0,#Null)
WaitForSingleObject_(hThread, #INFINITE)
GetExitCodeThread_(hThread, @hLibModule)
CloseHandle_(hThread)
CloseHandle_(hProcess)
VirtualFreeEx_(hProcess, pLibRemote, SizeOf(DLLPath), #MEM_RELEASE)
DebugPrevileg(#False)
ProcedureReturn hLibModule
EndProcedure
Procedure Eject(PID,hLibModule.l)
Define hThread.l, hProcess.l
DebugPrevileg(#True)
hProcess = OpenProcess_(#PROCESS_ALL_ACCESS, #False, PID)
hThread = CreateRemoteThread_(hProcess,#Null,0,GetProcAddress_(GetModuleHandle_("Kernel32"), "FreeLibrary"),hLibModule,0,#Null)
WaitForSingleObject_(hThread, #INFINITE)
CloseHandle_(hThread)
CloseHandle_(hProcess)
DebugPrevileg(#False)
EndProcedure
Code: Alles auswählen
Global hSASWnd.l,OldSASProc.l
ProcedureDLL MakeLong(low,high)
ProcedureReturn low + (high << 16)
EndProcedure
ProcedureDLL SASWindowProc(hWnd,uMsg,wParam,lParam)
If uMsg = #WM_HOTKEY
If lParam = MakeLong(#MOD_CONTROL | #MOD_ALT, #VK_DELETE)
ProcedureReturn 1
EndIf
EndIf
ProcedureReturn CallWindowProc_(OldSASProc, hWnd, uMsg, wParam, lParam)
EndProcedure
ProcedureDLL AttachProcess(hInstance)
hSASWnd = FindWindow_("SAS Window class","SAS window")
OldSASProc = SetWindowLong_(hSASWnd, #GWL_WNDPROC, @SASWindowProc())
EndProcedure
ProcedureDLL DetachProcess(hInstance)
SetWindowLong_(hSASWnd, #GWL_WNDPROC, OldSASProc)
EndProcedure
Code: Alles auswählen
Define hLibModule.l,PID.l
PID=GetPidFromName("winlogon.exe")
hLibModule=Inject(PID,"<Voller Pfad zur DLL>")
Delay(10000)
Eject(PID,hLibModule)
125