隐藏自身(程序运行时不可见)和将客户端程序写入注册表启动项两步
在这两步里遇到了两个巨大的错误
1.
写入启动项代码
程序代码:
void AddToSystem()
{
HKEY hKEY;
char CurrentPath[ MAX_PATH ];
char SysPath[ MAX_PATH ];
long ret = 0;
LPSTR FileNewName;
LPSTR FileCurrentName;
DWORD type = REG_SZ ;
DWORD size = MAX_PATH ;
LPCTSTR Rgspath = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"; //regedit
win + R
GetSystemDirectory (SysPath, size);
GetModuleFileName ( NULL , CurrentPath, size);
//Copy File
FileCurrentName = CurrentPath;
FileNewName = lstrcat (SysPath, "\\Steal.exe");
struct _finddata_t Steal;
printf ("ret1 = %d,FileNewName = %s\n", ret, FileNewName);
if ( _findfirst (FileNewName, &Steal) != -1)
return;//已经安装!
printf ("ret2 = %d\n", ret);
int ihow = MessageBox (0, "该程序只允许用于合法的用途!\n 继续运行该程序将使这台机器
处于被监控的状态!\n 如果您不想这样,请按“取消”按钮退出。\n 按下“是”按钮该程序将被复制
到您的机器上,并随系统启动自动运行。\n 按下“否”按钮,程序只运行一次,不会在您的系统内留下
任何东西。", "警告", MB_YESNOCANCEL | MB_ICONWARNING | MB_TOPMOST );
if (ihow == IDCANCEL )
exit (0);
if (ihow == IDNO )
return;//只运行一次
//复制文件
ret = CopyFile (FileCurrentName, FileNewName, TRUE );
if (!ret)
{
return;
}
//加入注册表
printf ("ret = %d\n", ret);
ret = RegOpenKeyEx ( HKEY_LOCAL_MACHINE , Rgspath, 0, KEY_WRITE , &hKEY);
if (ret != ERROR_SUCCESS )
{
RegCloseKey (hKEY);
return;
}
//Set Key
ret = RegSetValueEx (hKEY, "Steal", NULL , type, (const unsigned char*)FileNewName,
size);
if (ret != ERROR_SUCCESS )
{
RegCloseKey (hKEY);
return;
}
RegCloseKey (hKEY);
}
{
HKEY hKEY;
char CurrentPath[ MAX_PATH ];
char SysPath[ MAX_PATH ];
long ret = 0;
LPSTR FileNewName;
LPSTR FileCurrentName;
DWORD type = REG_SZ ;
DWORD size = MAX_PATH ;
LPCTSTR Rgspath = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"; //regedit
win + R
GetSystemDirectory (SysPath, size);
GetModuleFileName ( NULL , CurrentPath, size);
//Copy File
FileCurrentName = CurrentPath;
FileNewName = lstrcat (SysPath, "\\Steal.exe");
struct _finddata_t Steal;
printf ("ret1 = %d,FileNewName = %s\n", ret, FileNewName);
if ( _findfirst (FileNewName, &Steal) != -1)
return;//已经安装!
printf ("ret2 = %d\n", ret);
int ihow = MessageBox (0, "该程序只允许用于合法的用途!\n 继续运行该程序将使这台机器
处于被监控的状态!\n 如果您不想这样,请按“取消”按钮退出。\n 按下“是”按钮该程序将被复制
到您的机器上,并随系统启动自动运行。\n 按下“否”按钮,程序只运行一次,不会在您的系统内留下
任何东西。", "警告", MB_YESNOCANCEL | MB_ICONWARNING | MB_TOPMOST );
if (ihow == IDCANCEL )
exit (0);
if (ihow == IDNO )
return;//只运行一次
//复制文件
ret = CopyFile (FileCurrentName, FileNewName, TRUE );
if (!ret)
{
return;
}
//加入注册表
printf ("ret = %d\n", ret);
ret = RegOpenKeyEx ( HKEY_LOCAL_MACHINE , Rgspath, 0, KEY_WRITE , &hKEY);
if (ret != ERROR_SUCCESS )
{
RegCloseKey (hKEY);
return;
}
//Set Key
ret = RegSetValueEx (hKEY, "Steal", NULL , type, (const unsigned char*)FileNewName,
size);
if (ret != ERROR_SUCCESS )
{
RegCloseKey (hKEY);
return;
}
RegCloseKey (hKEY);
}
第一个错误
当第一次成功运行后,我想再做一次测试,即重新生成新的exe文件,但是因为有这几行代码的存在
程序代码:
FileCurrentName = CurrentPath;
FileNewName = lstrcat (SysPath, "\\Steal.exe");
struct _finddata_t Steal;
printf ("ret1 = %d,FileNewName = %s\n", ret, FileNewName);
if ( _findfirst (FileNewName, &Steal) != -1)
return;/
FileNewName = lstrcat (SysPath, "\\Steal.exe");
struct _finddata_t Steal;
printf ("ret1 = %d,FileNewName = %s\n", ret, FileNewName);
if ( _findfirst (FileNewName, &Steal) != -1)
return;/
所以我必须要删除掉它在系统文件夹下生成的steal.exe,删除后,重新生成代码,发现已经生成不了了,
总是报无法访问指定文件夹,错误提示是对路径“xxcx"访问被拒绝,当我把代码copy到一个新的工程,
又可以成功生成了,貌似这程序只能生成一次,第二次就不能再生成了,太坑了,这个错误找了好久,一直在想是不是代码错了,真的是被狠狠的上了一课,非必要就不要玩这种高操作。
2.第二个错误
这个隐藏自身代码,也不好用,运行后,没有成功隐藏,还是会又黑框一闪而过,没有做到完全隐藏自身
程序代码:
void HideMyself()
{
HWND hwnd = GetForegroundWindow();
ShowWindow(hwnd, SW_HIDE);
}
实在是太难了,代码均来自网络
[此贴子已经被作者于2023-5-22 12:35编辑过]