青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆-60  評(píng)論-262  文章-1  trackbacks-0

說(shuō)明: 前段時(shí)間找關(guān)于向系統(tǒng)進(jìn)程注入鏈接庫(kù)的文章, 找到這篇, 加入收藏夾, 但后來(lái)這個(gè)連接死活打不開(kāi)了. 就用 google 的 cache 功能將文章 A 在這里. 查閱方便.

For a while now, I've been searching for the optimal way to inject code into privileged Win32 processes like lsass.exe, csrss.exe, and winlogon.exe.

There are many functions such as the LSA and SAM exports that even users logged in with full administrative rights cannot execute
unless they do so under the context of one of these privileged processes.

There are a few tricks that I learned along the way.

First, it is necessary to adjust the token privileges of your program so that debugging (SE_PRIVILEGE_ENABLED) is allowed.

If you are injecting code into a lower privileged process, then this will not be needed.

Also, the target process will need to be opened with PROCESS_ALL_ACCESS rights.

Its all pretty easy on Windows 2000 and XP Service Pack 0 and 1.
On these systems, you can use the documented CreateRemoteThread() function, but first the code you want
to run in the security context of the remote process needs to exist in that process' virtual memory space.
You can put it there by using VirtualAllocEx() and WriteProcessMemory().

With XP SP2 and later (2003, Vista) some new security measures prevent the traditional CreateRemoteThread() function from working properly.
You should be able to open the process, allocate memory on its heap, and write data to the allocated region,
but when trying to invoke the remote thread, it will fail with ERROR_NOT_ENOUGH_MEMORY.

On Vista, I found that an author can substitute the CreateRemoteThread() call with NtCreateThreadEx() export from ntdll.dll
and it will allow for the thread to execute properly. This requires you to auto-detect the version of the operating system and
branch to this different call if on Vista.

Also, this is isn't really a universal solution, because NtCreateThreadEx() doesn't exist on pre-Vista sytsems.
So now we're stuck with using CreateRemoteThread() on 2000 and XP SP 0,1 and NtCreateThreadEx() on Vista.
This is already getting messy, and we still don't have a solution for XP SP2.

Also, the NtCreateThreadEx() function takes an undocumented structure, whose members can be initialized appropriately
by reversing other binaries that use the function, but it looks really ugly in source code since I don't really know what the members are for,
or why particular values are significant.

For XP SP2 I did a little debugging and found that inside CreateRemoteThread(), there is a call to ZwCreateThread() which is an export
from ntdll.dll. The call is made while specifying that the thread should start suspended, which it does properly,
however down the road still inside CreateRemoteThread() before ZwResumeThread() is called, there is a call to CsrClientCallServer()
which fails and eventually leads to the error message.

This behavior makes you wonder, if you can just call ZwCreateThread() directly, then the call to CsrClientCallServer() will be avoided
and the thread will execute. The problem is that ZwCreateThread() doesn't allow one to set the thread start address easily
(you have to configure the INITIAL_TEB members to set EIP to your start address using mostly undocumented structures and functions).

However, this all can be avoided by using the RtlCreateUserThread() function instead,
which configures and calls all the undocumented functions for you, and eventually invokes ZwCreateThread() with the result.
Although RtlCreateUserThread() is undocumented also, its hardly as complex as the rest and is pretty simple to use.

At this point, we can successfully execute remote threads into privileged processes across all target platforms,
but as mentioned before, its pretty messy.

We're using three different, largely undocumented functions and auto-detecting which one to use based on the OS version.

The better solution is to create a secondary program that adds a service object (your injector program)
to the service control manager database on the target system. Since you're administrator, which is required anyway,
you'll be able to add these entries and start the service. This will enable the injector program
to run with different access rights than normal code, and the traditional CreateRemoteThread()
will work properly on Windows 2000, all of XP, and 2003/Vista.

The API functions for adding and controlling the service are documented by MSDN and remain consistent across all of the platforms.

So, what is learned is that we can use a number of different functions to inject code into privileged remote processes,
including RtlCreateUserThread() on XP SP2, and NtCreateThreadEx() on Vista, but the optimal way is to install a temporary service
and allow CreateRemoteThread() to be the single API that accomplishes the task for all platforms.


PS:

Basically the needed access rights are identical to XP: In both OSs you need admin rights for system wide injection. However, in Vista when UAC is enabled even admin users don't have admin rights by default. So you need to right click your exe and choose "run as administrator" (as LeVuHoang has already said). Alternatively you can add a manifest to your exe which will tell Vista that your app needs admin rights. If you do that, you don't need to do the "run as admin" step, anymore. However, the end user will still have to confirm the operation. If you don't like all this you need to inject from a service (see HookProcessTermination demo).

One other thing to look for is that the hook dll needs enough NTFS rights or else it might not be injected into all processes successfully. Vista is a bit more strict there than XP was.

void Inject(HWND hWnd, char* strDll)
{
    GetWindowThreadProcessId(hWnd, 
&pId);
    HANDLE hProcess 
= OpenProcess(PROCESS_ALL_ACCESS, FALSE, pId);
    LPVOID lpRemoteAddress 
= VirtualAllocEx(hProcess, NULL, strlen(strDll), MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
    WriteProcessMemory(hProcess, lpRemoteAddress, (LPVOID)strDll, strlen(strDll), NULL);
    CreateRemoteThread(hProcess, NULL, 
0,
        (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle(
"Kernel32"), "LoadLibraryA"),
        lpRemoteAddress, 
0, NULL);


The API does not create threads in other sessions (this behavior is documented in MSDN).

One way to load a library into a process of another session is: Create a suspended thread (ntdll!RtlCreateUserThread) at kernel32!ExitThread, schedule an asynchronous procedure call (ntdll!NtQueueApcThread) at kernel32!LoadLibraryEx, resume the thread (kernel32!ResumeThread - this executes the pending APC), and wait for the end of the thread (kernel32!WaitForSingleObject). APCs do not return a value - therefore the return value of kernel32!LoadLibraryEx is lost. There is much more work required to use this method in the exact same manner as CreateRemoteThread(LoadLibrary) (includes reading the PEB’s loader structures).

Other hints:

    * Never ever use CreateRemoteThread on a target process that differs in 'bitness' (kernel32!IsWow64Process). On some Windows versions this freezes your calling thread.
    * Dynamically determine the kernel32’s image base (might not be loaded at all).

 


對(duì)于 RtlCreateUserThread 函數(shù)的線程函數(shù), 以下是個(gè)示例:

#define LoadLibraryA_ADDR       0xDDDDDDDD 
#define RtlExitUserThread_ADDR  0xEEEEEEEE 

static __declspec(naked) DWORD WINAPI ThreadDummy(LPVOID lpParam) 
{
    __asm { 
        push    dword ptr [esp+4]           ; // 將傳進(jìn)來(lái)的線程函數(shù)的參數(shù)壓棧 
        mov     eax, LoadLibraryA_ADDR      ; // LoadLibraryA 或 FreeLibrary 函數(shù)的地址 
        call    eax                         ; // 調(diào)用 LoadLibraryA 函數(shù)
        push    eax                         ; // 將 RtlExitUserThread 函數(shù)的參數(shù)壓棧
        mov     eax, RtlExitUserThread_ADDR ; // RtlExitUserThread 函數(shù)的地址 
        call    eax                         ; // 調(diào)用 RtlExitUserThread 函數(shù)
        ret     4                           ; // 返回 
    } 
}

static __declspec(naked) DWORD WINAPI ThreadDummy_end(LPVOID lpParam) 

    __asm { 
        ret     4                            ; 
    } 
}

PUCHAR FindDWordFromBuffer(PUCHAR lpBuffer, UINT cchMax, DWORD dwValue) 

    PUCHAR pResult 
= NULL; 
    UINT nIter 
= 0
    
for (nIter=0; nIter<cchMax; nIter++
    { 
        
if ( *(DWORD *)(lpBuffer + nIter) == dwValue ) { 
            pResult 
= lpBuffer + nIter; 
            
break
        } 
    } 
    
return pResult; 


BOOL BuildRemoteThreadCode(OUT PUCHAR lpCode, UINT cchMax, BOOL bInject) 

    UINT nCodeLen 
= 0
    PUCHAR pIter 
= NULL; 
    DWORD dwFnAddr 
= 0
    
    
if (NULL==lpCode || 0==cchMax) { 
        
return FALSE; 
    } 
    
    nCodeLen 
= (PUCHAR) &ThreadDummy_end - (PUCHAR) &ThreadDummy; 
    
if (nCodeLen > cchMax) { 
        
return FALSE; 
    } 
    
    memcpy((
void *)lpCode, (void *&ThreadDummy, nCodeLen); 
    
    {
        pIter 
= FindDWordFromBuffer(lpCode, nCodeLen, LoadLibraryA_ADDR); 
        
if (NULL == pIter) { 
            
return FALSE; 
        } 
        
        
if (bInject) { 
            dwFnAddr 
= (DWORD) GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "LoadLibraryA"); 
        } 
else { 
            dwFnAddr 
= (DWORD) GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "FreeLibrary"); 
        } 
        
        
if (0 == dwFnAddr) { 
            
return FALSE; 
        } 
        
*(DWORD *)pIter = dwFnAddr; 
    } 
    
    {
        pIter 
= FindDWordFromBuffer(lpCode, nCodeLen, RtlExitUserThread_ADDR); 
        
if (NULL == pIter) { 
            
return FALSE; 
        } 
        
        dwFnAddr 
= (DWORD) GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "RtlExitUserThread"); 
        
if (0 == dwFnAddr) { 
            
return FALSE; 
        } 
        
*(DWORD *)pIter = dwFnAddr; 
    } 
    
    
return TRUE; 
}

自己分配一塊足夠大的內(nèi)存, 以這塊內(nèi)存的指針作為參數(shù)調(diào)用 BuildRemoteThreadCode 函數(shù)后, 這塊內(nèi)存就可以寫(xiě)到目標(biāo)進(jìn)程里面, 并作為 RtlCreateUserThread 函數(shù)的線程函數(shù)執(zhí)行了.

當(dāng)然, 線程函數(shù)的參數(shù), 還是得自己準(zhǔn)備了, 也就是一個(gè)字符串指針或一個(gè)模塊的 HMODULE. 相信大家都會(huì), 不用我廢話了.

posted on 2008-06-18 17:31 free2000fly 閱讀(2411) 評(píng)論(0)  編輯 收藏 引用

只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲伊人伊色伊影伊综合网| 久久久91精品| 欧美亚洲三区| 一本大道av伊人久久综合| 亚洲美女黄网| 亚洲视频一二三| 欧美一区二区高清在线观看| 久久国产精品网站| 欧美成人精品福利| 日韩一级在线观看| 欧美国产欧美亚州国产日韩mv天天看完整| 欧美日韩三区| 久久精品男女| 欧美黄网免费在线观看| 欧美激情国产日韩| 欧美日韩中文字幕| 国产视频亚洲精品| 亚洲韩国日本中文字幕| 亚洲午夜在线观看| 鲁大师影院一区二区三区| 亚洲精品视频中文字幕| 欧美伊人久久久久久久久影院 | 亚洲视频每日更新| 在线亚洲精品福利网址导航| 影音先锋欧美精品| 欧美sm重口味系列视频在线观看| 亚洲激情视频在线观看| 亚洲综合色婷婷| 免播放器亚洲一区| 在线视频精品一区| 久久一本综合频道| 国产精品狼人久久影院观看方式| 在线精品在线| 欧美中文字幕视频| 最新亚洲激情| 欧美一区二区黄| 欧美性事在线| 99精品国产99久久久久久福利| 久久黄色小说| 亚洲一区二区黄| 老司机67194精品线观看| 欧美一区二视频在线免费观看| 亚洲一区二区三区在线看| 亚洲一区二区三区四区五区午夜 | 久久国产精品99国产精| 欧美日韩精品一区二区天天拍小说| 国产亚洲免费的视频看| 亚洲欧美日韩国产另类专区| 欧美激情久久久| 在线成人av.com| 久久精品国产清自在天天线| 亚洲午夜在线视频| 国产精品久久久久久久久久久久| 国产精品99久久久久久久女警| 欧美激情aaaa| 欧美国产高潮xxxx1819| 最新国产拍偷乱拍精品| 免费欧美视频| 久久久久这里只有精品| 精品动漫3d一区二区三区免费| 久久精品在线视频| 久久gogo国模裸体人体| 亚洲精品中文字| 免费视频一区| 欧美亚洲免费| 国产精品一区一区三区| 亚洲免费不卡| 亚洲清纯自拍| 欧美激情一区二区三区蜜桃视频 | 久久久亚洲人| 在线观看成人av电影| 久久午夜精品| 久久天天躁夜夜躁狠狠躁2022| 一区二区三区在线观看国产| 欧美jizzhd精品欧美喷水| 免费在线亚洲欧美| 亚洲国产成人在线| 久久综合九色综合久99| 亚洲欧美日韩中文视频| 欧美在线亚洲一区| 伊人久久亚洲热| 欧美激情欧美狂野欧美精品| 欧美成人一区二区| 亚洲在线一区二区| 久久精品一区二区三区不卡牛牛| 亚洲激情在线观看| 亚洲特色特黄| 亚洲第一在线综合在线| 一本一本a久久| 欲香欲色天天天综合和网| 亚洲黄页一区| 国产精品色婷婷| 欧美日韩国产三区| 亚洲一二区在线| 久久精品99国产精品酒店日本| 欧美国产综合| 香蕉乱码成人久久天堂爱免费| 亚洲二区视频| 夜夜夜久久久| 欧美一级二区| 亚洲性感美女99在线| 欧美日韩一级黄| 性做久久久久久免费观看欧美| 久久美女艺术照精彩视频福利播放| 亚洲精品影视| 欧美中文字幕在线| 99v久久综合狠狠综合久久| 亚洲欧美国产日韩天堂区| 亚洲欧洲三级电影| 羞羞答答国产精品www一本 | 女主播福利一区| 欧美午夜精品久久久久久久| 欧美国产一区二区在线观看| 久久精品日产第一区二区三区| 在线日韩精品视频| 日韩一二三在线视频播| 在线播放日韩| 亚洲一级二级在线| 一本大道久久a久久综合婷婷| 久久久久久9999| 裸体歌舞表演一区二区| 亚洲淫性视频| 欧美日韩999| 免费一级欧美片在线观看| 国产麻豆精品在线观看| 亚洲午夜视频在线观看| 亚洲午夜成aⅴ人片| 欧美精品久久99| 最新中文字幕一区二区三区| 狠狠色狠狠色综合日日91app| 亚洲愉拍自拍另类高清精品| 亚洲女女做受ⅹxx高潮| 亚洲国产精品999| 欧美成人精品激情在线观看| 亚洲五月六月| 久久久不卡网国产精品一区| 欧美一区二区高清| 欧美视频一区在线| 亚洲美女黄网| 亚洲性感激情| 国产精品女人网站| 亚洲——在线| 久久乐国产精品| 尤物在线观看一区| 欧美成人69| 一本久久知道综合久久| 亚洲欧美日韩视频一区| 国产精品午夜视频| 欧美亚洲三区| 免费视频一区二区三区在线观看| 亚洲国产91| 欧美激情第二页| 在线视频日本亚洲性| 午夜精品在线视频| 国产主播一区二区三区| 亚洲调教视频在线观看| 欧美日韩在线播放三区| 亚洲一区在线免费观看| 老司机aⅴ在线精品导航| 亚洲免费观看高清在线观看| 欧美特黄一级| 欧美在线free| 亚洲电影av在线| 亚洲一区二区在线看| 国产亚洲成av人片在线观看桃 | 亚洲精品影院在线观看| 美女国内精品自产拍在线播放| 91久久精品国产91久久性色| 亚洲自拍偷拍色片视频| 国产一区自拍视频| 欧美黑人在线观看| 亚洲一二区在线| 欧美ab在线视频| 亚洲无限av看| 亚洲国产精品成人久久综合一区| 欧美视频日韩| 蜜臀a∨国产成人精品| 亚洲视屏一区| 午夜久久黄色| 久久婷婷丁香| av不卡在线| 精品成人在线| 国产精品激情偷乱一区二区∴| 久久精品国产99| 一区二区三区四区在线| 毛片av中文字幕一区二区| 一区二区三区日韩| 影音欧美亚洲| 国产精品爽黄69| 欧美人妖在线观看| 久久久久久久激情视频| 亚洲一区二区三区四区五区午夜 | 国产亚洲一区二区三区| 欧美日本亚洲韩国国产| 久久精品视频在线看| 亚洲影院在线| 一本久道久久综合婷婷鲸鱼| 欧美国产日韩一区二区在线观看 | 欧美在线免费看| 亚洲视频在线观看一区|