有多种方法可以对注册表实现新建、修改、删除等

在恶意代码的行为之中,一般都是将其自身设置到Windows的开机自动启动项中,以达到开机自启动的目的,从而实现对本地机器的监控、开启后门、木马服务端等的功能


方法一:本地运行reg脚本、

举例如下:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run]
"Calculation"="C:\\Windows\\system32\\calc.exe"

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TCPIP6\try\abc]
"valueItem1"="my value"
"valueItem2"=dword:00000014

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TCPIP6\try]
"valueItem3"=hex(7):5c,00,44,00,65,00,76,00

这里有几个细节:

第一行的5.00标识的是XP版本,一般都是在XP虚拟机里做实验的,其他版本有不同的标识

之后的每一个中括号表示在不同项中作的不同修改

[~~~Run]:这里添加了开机启动项,添加了计算器

[~~~abc]:这里添加了两个值,一个是字符串值,一个是数字值

[~~~try]:这里添加了一个二进制值


方法二:C语言代码,利用API函数对注册表进行操作

// reg.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <windows.h>
#include <stdio.h>
#include <string.h>
#pragma comment(lib,"Advapi32.lib")
void CreateStringReg(HKEY hRoot,char *szSubKey,char* ValueName,char *Data)
{
    HKEY hKey;
    long lRet=RegCreateKeyEx(hRoot,szSubKey,0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,NULL);
    if (lRet!=ERROR_SUCCESS)
    {
        printf("error no RegCreateKeyEx %s\n", szSubKey);
        return ;
    }
    lRet=RegSetValueEx(hKey,ValueName,0,REG_SZ,(BYTE*)Data,strlen(Data));
     if (lRet!=ERROR_SUCCESS)
     {
         printf("error no RegSetValueEx %s\n", ValueName);
         return;
     }
    printf("Win~\n");
    RegCloseKey(hKey);
    return;
}

int autorun()
{
    char SystemPath[512];
    GetSystemDirectory(SystemPath,sizeof(SystemPath));
    strcat(SystemPath,"\\calc.exe");
    CreateStringReg(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Windows\\Run","Calculation",SystemPath);
    return 0;
}
 
 
int main(int argc, char* argv[])
{
    autorun();
    return 0;
}