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

隨筆-60  評論-262  文章-1  trackbacks-0

說明: 前段時間找關于向系統進程注入鏈接庫的文章, 找到這篇, 加入收藏夾, 但后來這個連接死活打不開了. 就用 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).

 


對于 RtlCreateUserThread 函數的線程函數, 以下是個示例:

#define LoadLibraryA_ADDR       0xDDDDDDDD 
#define RtlExitUserThread_ADDR  0xEEEEEEEE 

static __declspec(naked) DWORD WINAPI ThreadDummy(LPVOID lpParam) 
{
    __asm { 
        push    dword ptr [esp+4]           ; // 將傳進來的線程函數的參數壓棧 
        mov     eax, LoadLibraryA_ADDR      ; // LoadLibraryA 或 FreeLibrary 函數的地址 
        call    eax                         ; // 調用 LoadLibraryA 函數
        push    eax                         ; // 將 RtlExitUserThread 函數的參數壓棧
        mov     eax, RtlExitUserThread_ADDR ; // RtlExitUserThread 函數的地址 
        call    eax                         ; // 調用 RtlExitUserThread 函數
        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; 
}

自己分配一塊足夠大的內存, 以這塊內存的指針作為參數調用 BuildRemoteThreadCode 函數后, 這塊內存就可以寫到目標進程里面, 并作為 RtlCreateUserThread 函數的線程函數執行了.

當然, 線程函數的參數, 還是得自己準備了, 也就是一個字符串指針或一個模塊的 HMODULE. 相信大家都會, 不用我廢話了.

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

只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   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>
            欧美日韩精品福利| 日韩网站在线| 久久久久久久精| 亚洲伦理在线观看| 夜色激情一区二区| 亚洲欧美成人在线| 久久精品视频在线| 免费成人在线观看视频| 欧美激情二区三区| 日韩天堂在线视频| 亚洲作爱视频| 久久久久9999亚洲精品| 欧美日本不卡| 国产资源精品在线观看| 亚洲第一搞黄网站| 一区二区三区欧美成人| 久久国产精品72免费观看| 免费成人在线观看视频| 一本色道久久综合精品竹菊| 欧美综合77777色婷婷| 欧美va天堂在线| 国产精品亚洲第一区在线暖暖韩国| 国产一区二区av| 9l视频自拍蝌蚪9l视频成人| 翔田千里一区二区| 欧美国产亚洲另类动漫| 中日韩男男gay无套| 久久五月天婷婷| 国产精品一二| 亚洲美女淫视频| 久久久国产精品一区二区三区| 欧美国产欧美亚洲国产日韩mv天天看完整| 亚洲国产精品尤物yw在线观看 | 一区二区三区视频在线观看| 欧美一区二区三区在线看| 欧美不卡三区| 国产一区欧美日韩| 这里是久久伊人| 欧美大胆人体视频| 午夜欧美电影在线观看| 欧美日韩亚洲一区二区三区在线| 久久亚洲图片| 国产精品日日摸夜夜摸av| 亚洲免费高清视频| 欧美**人妖| 久久精品人人做人人爽| 国产精品综合av一区二区国产馆| 9l国产精品久久久久麻豆| 免费中文日韩| 久久精品中文字幕免费mv| 国产精品爽黄69| 亚洲欧美日韩国产| 夜夜嗨av一区二区三区免费区| 欧美激情一区二区三区全黄| 1769国产精品| 蜜臀av性久久久久蜜臀aⅴ| 久久久久久久国产| 亚洲大胆人体在线| 欧美激情1区2区| 蜜臀久久久99精品久久久久久| 激情婷婷亚洲| 久久资源av| 久久免费99精品久久久久久| 国产午夜精品一区理论片飘花| 亚洲欧美乱综合| 亚洲欧美国产高清| 国产视频在线观看一区| 久久精品视频免费| 久久久天天操| 91久久夜色精品国产网站| 亚洲国产日韩一区| 欧美午夜视频网站| 欧美一级成年大片在线观看| 午夜一区二区三区在线观看| 国产综合在线看| 欧美好骚综合网| 欧美日韩 国产精品| 亚洲自啪免费| 久久aⅴ国产紧身牛仔裤| 在线免费观看欧美| 亚洲伦理在线| 国产欧美一区二区精品性色| 久久久久综合| 欧美激情视频网站| 午夜精品视频在线| 久久蜜桃精品| 一本在线高清不卡dvd| 亚洲女人av| 亚洲国产精品123| 一区二区高清| 1000精品久久久久久久久 | 亚洲一本视频| 激情文学综合丁香| 一本久久知道综合久久| 国精产品99永久一区一区| 亚洲国产小视频| 国产美女扒开尿口久久久| 欧美电影免费观看大全| 国产精品美女xx| 亚洲激情精品| 国产一级一区二区| 久久亚洲捆绑美女| 亚洲无毛电影| 久久综合一区| 欧美一区视频| 欧美日韩精品免费观看视频| 久久精品亚洲乱码伦伦中文| 欧美高清一区二区| 久久艳片www.17c.com| 国产精品精品视频| 亚洲人成在线免费观看| 樱花yy私人影院亚洲| 一区二区三区欧美激情| 亚洲欧洲日本mm| 久久精品官网| 久久激情网站| 国产精品每日更新| 日韩午夜中文字幕| 日韩亚洲在线观看| 欧美高清一区二区| 亚洲成人在线视频播放 | 一本大道久久a久久精二百| 亚洲国产精品一区二区第一页| 亚洲欧美日韩视频一区| 中文网丁香综合网| 欧美日韩国产综合视频在线观看中文| 模特精品在线| 亚洲高清不卡在线观看| 久久久久免费观看| 男女激情视频一区| 91久久精品视频| 欧美va天堂| 亚洲国产精品成人精品| 亚洲日韩欧美视频| 欧美精品久久久久久久免费观看| 欧美成人免费一级人片100| 黄色在线成人| 久久亚洲综合网| 亚洲成在线观看| 日韩视频免费观看| 欧美日韩一区综合| 亚洲图色在线| 久久国产婷婷国产香蕉| 国产一区二区在线免费观看| 欧美一级免费视频| 蜜桃久久av一区| 亚洲精品一区在线| 欧美理论电影在线观看| 日韩亚洲欧美成人一区| 亚洲男女自偷自拍| 国产欧美一区二区三区沐欲 | 99热精品在线观看| 欧美亚洲在线| 激情一区二区三区| 欧美激情一区二区三区全黄 | 亚洲欧美日本精品| 老司机成人网| 久久久久9999亚洲精品| 欧美精品色综合| 一区二区三区高清在线观看| 亚洲欧美一区二区三区久久 | 校园春色国产精品| 免费成人在线观看视频| 日韩午夜在线观看视频| 国产精品久久久久高潮| 久久精品国产精品| 亚洲九九爱视频| 久久久噜噜噜久久中文字幕色伊伊 | 99精品热视频| 国产麻豆精品theporn| 久久久99免费视频| 日韩视频在线你懂得| 久久久水蜜桃| 亚洲午夜激情网页| 在线观看视频一区二区欧美日韩| 欧美日本免费| 久久久噜噜噜久久人人看| 日韩亚洲不卡在线| 六月婷婷一区| 亚洲欧美在线一区| 日韩视频在线播放| 国产在线视频欧美| 欧美性开放视频| 美女免费视频一区| 欧美一级免费视频| 宅男精品视频| 亚洲人成亚洲人成在线观看图片 | 精品成人一区二区| 国产精品女主播一区二区三区| 麻豆精品传媒视频| 欧美在线播放一区| 亚洲一区二区三区视频| 亚洲激情专区| 欧美a级在线| 久久夜色精品国产欧美乱极品| 午夜精彩国产免费不卡不顿大片| 日韩视频在线一区二区三区| 亚洲成人自拍视频| 伊人精品成人久久综合软件| 国产欧美一级|