这个程序的源没什么,只要是这个程序当你点"利用特殊方法修改注册表"的时候,这个程序会释放出一个c:\\xyz2.hiv文件,然后将SeRestorePrivilege事件作为参数传递给一个函数,这个函数负责把程序提升到system。之后对注册表进行操作,最后作者del xyz2.hiv了
真正的精华,是xyz2.hiv。
.text:004014D3 loc_4014D3:
.text:004014D3 cmp ax, 401h ;用户是否点了“退出”按扭
.text:004014D7 jnz short loc_4014FD ;点了就退
.text:004014D7
.text:004014D9 call sub_401090 ;如果没点,就利用特殊方法修改注册表
.text:004014D9
.text:004014DE mov eax, [esp+4]
.text:004014E2 push 20h
.text:004014E4 push offset s_S ; "提示"
.text:004014E9 push offset s_TIVSAPUB___CJ ; "\n特殊方法修改注册表自启动项 B
...\r\n\r\n如"...
.text:004014EE push eax
.text:004014EF call ds:MessageBoxA
.text:004014F5 mov eax, 1
.text:004014FA retn 10h
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
下面才是此程序的精华部分:
.text:00401090 sub_401090 proc near ; CODE XREF: .text:004014D9p
.text:00401090
.text:00401090 var_14 = dword ptr -14h
.text:00401090 phkResult = dword ptr -8
.text:00401090 NumberOfBytesWritten= dword ptr -4
.text:00401090
.text:00401090 sub esp, 8 ;分配内存
.text:00401093 push ebx ;这里不是参数,而是保存寄存器
.text:00401094 push esi
.text:00401095 push edi
.text:00401096 push offset Type ; "xyz2"
.text:0040109B push 84h ; lpName
.text:004010A0 push 0 ; hModule
.text:004010A2 call ds:FindResourceA ; 查找xyz2资源
.text:004010A8 mov esi, eax
.text:004010AA push esi ; hResInfo
.text:004010AB push 0 ; hModule
.text:004010AD call ds:SizeofResource ; 获取资源长度
.text:004010B3 push esi ; hResInfo
.text:004010B4 push 0 ; hModule
.text:004010B6 mov edi, eax
.text:004010B8 call ds:LoadResource ; 装载资源
.text:004010BE push 0 ; hTemplateFile
.text:004010C0 push 0 ; dwFlagsAndAttributes
.text:004010C2 push 2 ; dwCreationDisposition
.text:004010C4 push 0 ; lpSecurityAttributes
.text:004010C6 push 0 ; dwShareMode
.text:004010C8 push 40000000h ; dwDesiredAccess
.text:004010CD push offset FileName ; "c:\\xyz2.hiv"
.text:004010D2 mov ebx, eax
.text:004010D4 call ds:CreateFileA ; 打开文件准备把资源写入
.text:004010DA push 0 ; lpOverlapped
.text:004010DC mov esi, eax
.text:004010DE lea eax, [esp+18h+NumberOfBytesWritten]
.text:004010E2 push eax ; lpNumberOfBytesWritten
.text:004010E3 push edi ; nNumberOfBytesToWrite
.text:004010E4 push ebx ; hResData
.text:004010E5 call ds:LockResource ; 锁定资源
.text:004010EB push eax ; lpBuffer
.text:004010EC push esi ; hFile
.text:004010ED call ds:WriteFile ; 创建一个C:\xyz2.hiv文件
.text:004010F3 mov ebx, ds:CloseHandle
.text:004010F9 push esi ; hObject
.text:004010FA call ebx ; CloseHandle
.text:004010FC push offset Name ; "SeRestorePrivilege"
.text:00401101 call sub_401000 ; SeRestorePrivilege事件作为参数传递给一个 ;函数
.text:00401101
.text:00401106 add esp, 4 ; 把空间还给系统
.text:00401109 lea ecx, [esp+14h+phkResult]
.text:0040110D push ecx ; phkResult
.text:0040110E push offset SubKey ; ;"SOFTWARE\\Microsoft\\Windows\\CurrentVersi"...
.text:00401113 push 80000002h ; hKey
.text:00401118 call ds:RegOpenKeyA ; sub_401000函数已经帮我们把一切都摆平了, ;可以设置了
.text:0040111E mov edi, ds:RegRestoreKeyA
.text:00401124 xor esi, esi
.text:00401126 jmp short loc_401130
.text:0040115C pop ebx
.text:0040115D add esp, 8 ;典型的函数自己恢复堆栈
.text:00401160 retn
.text:00401160
.text:00401160 sub_401090 endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
将SeRestorePrivilege事件传递之后,程序做了如下动作,典型的调用OpenProcessToken等函数获取并且修改令牌来提升权限:
.text:00401000 TokenHandle = dword ptr -1Ch
.text:00401000 Luid = _LUID ptr -18h
.text:00401000 NewState = _TOKEN_PRIVILEGES ptr -10h
.text:00401000 lpName = dword ptr 4
.text:00401000
.text:00401000 sub esp, 1Ch
.text:00401003 lea eax, [esp+1Ch+TokenHandle]
.text:00401006 push eax ; TokenHandle
.text:00401007 push 28h ; DesiredAccess
.text:00401009 call ds:GetCurrentProcess
.text:0040100F push eax ; ProcessHandle
.text:00401010 call ds:OpenProcessToken ; Open the access token associated with a process
.text:00401016 test eax, eax
.text:00401018 jz short loc_401084
.text:00401018
.text:0040101A mov edx, [esp+1Ch+lpName]
.text:0040101E lea ecx, [esp+1Ch+Luid]
.text:00401022 push ecx ; lpLuid
.text:00401023 push edx ; lpName
.text:00401024 push 0 ; lpSystemName
.text:00401026 call ds:LookupPrivilegeValueA
.text:0040102C test eax, eax
.text:0040102E jnz short loc_40103E
.text:0040102E
.text:00401030 mov eax, [esp+1Ch+TokenHandle]
.text:00401033 push eax ; hObject
.text:00401034 call ds:CloseHandle
.text:0040103A add esp, 1Ch
.text:0040103D retn
.text:0040103D
.text:0040103E ; ---------------------------------------------------------------------------
.text:0040103E
.text:0040103E loc_40103E: ; CODE XREF: sub_401000+2Ej
.text:0040103E mov ecx, [esp+1Ch+Luid.LowPart]
.text:00401042 mov edx, [esp+1Ch+Luid.HighPart]
.text:00401046 push 0 ; ReturnLength
.text:00401048 push 0 ; PreviousState
.text:0040104A push 10h ; BufferLength
.text:0040104C lea eax, [esp+28h+NewState]
.text:00401050 push eax ; NewState
.text:00401051 mov [esp+2Ch+NewState.Privileges.Luid.LowPart], ecx
.text:00401055 mov ecx, [esp+2Ch+TokenHandle]
.text:00401059 push 0 ; DisableAllPrivileges
.text:0040105B push ecx ; TokenHandle
.text:0040105C mov [esp+34h+NewState.PrivilegeCount], 1
.text:00401064 mov [esp+34h+NewState.Privileges.Luid.HighPart], edx
.text:00401068 mov [esp+34h+NewState.Privileges.Attributes], 2
.text:00401070 call ds:AdjustTokenPrivileges ; Enable/disable privileges in the specified access token
.text:00401076 test eax, eax
.text:00401078 jnz short loc_401084
.text:00401078
.text:0040107A mov edx, [esp+1Ch+TokenHandle]
.text:0040107D push edx ; hObject
.text:0040107E call ds:CloseHandle
.text:0040107E
.text:00401084
.text:00401084 loc_401084: ; CODE XREF: sub_401000+18j
.text:00401084 ; sub_401000+78j
.text:00401084 add esp, 1Ch
.text:00401087 retn
.text:00401087
.text:00401087 sub_401000 endp