发新话题
打印

[讨论]关于API RegSaveKey的权限问题

[讨论]关于API RegSaveKey的权限问题

议题提交:代码罐头
信息来源:邪恶八进制信息安全团队(www.eviloctal.com

实在没人.只能放这里问.XFOCUS群里面基本都和死人一样.....唉....

今天开始写关于注册表修改的部分
将WSCRIPT.NETWORK等删除.并且同时将对应的CLSID删除.
在删除前先备份这两个KEY
但是用到RegSaveKey这个函数的时候.
总是提示"客户端没有所需的特权"
对于key.我是试过用ALL_ACCESS或者WRITE权限打开.
对于文件.我已经加上了全局的EVERYONE的全部控制权限.
对于登陆用户.我是使用administrator用户登陆的
但是始终提示这个error.

本人环境.WIN2003 中文企业版 无SP1
VC++ 6.0 SP6

代码如下.
引用:
#include <windows.h>
#include <stdio.h>

int main(){
  HKEY hKey;
     char szProductType[80];
     DWORD dwBufLen;
     RegOpenKeyEx( HKEY_CLASSES_ROOT,
          "WScript.Network",
          0, KEY_WRITE, &hKey );
  LONG result;
     result=RegSaveKey(hKey,"d:\\test.reg",NULL);
     LPVOID lpMsgBuf;
     FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
   NULL,
   result,
   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
   (LPTSTR) &lpMsgBuf,
   0,
   NULL
     );
     printf("%d:%s",result,lpMsgBuf);
     RegCloseKey( hKey );

     RegOpenKeyEx(HKEY_CLASSES_ROOT,"WScript.Network\\CLSID",0,KEY_QUERY_VALUE,&hKey);
     RegQueryValueEx( hKey, "", NULL, NULL,
          (LPBYTE) szProductType, &dwBufLen);
     
  RegCloseKey( hKey );
     printf("%s",szProductType);
     
     char szCLSID[50];
     if (strlen(szProductType)>=40){
          printf("key too long");
          return 0;
     }
     sprintf(szCLSID,"CLSID\\%s",szProductType);
     RegOpenKeyEx( HKEY_CLASSES_ROOT,szCLSID,0,KEY_QUERY_VALUE,&hKey);
     result=RegSaveKey(hKey,"d:\\CLSID.reg",NULL);
          FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
   NULL,
   result,
   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
   (LPTSTR) &lpMsgBuf,
   0,
   NULL
     );
     printf("%d:%s",result,lpMsgBuf);
     RegQueryValueEx(hKey,"",NULL,NULL,(LPBYTE)szProductType,&dwBufLen);
  RegCloseKey( hKey );
     printf("%s",szProductType);

     return 0;
}
连入侵者都敢说自己在做网络安全。关键大家是真正为安全作过什么?

TOP

简单看一下  这个问题真不知道怎么解决  我看MSDN

2003有一个RegOpenUserClassesRoot函数 你可以看看

或者是不是安全描述符的问题?  用RegSetKeySecurity设置

一下看看!
请加47809945   100%通过!每个月总有那么几天,您的网络会受到黑客的攻击--坐立不安,烦躁无力,使用虎虎开发的"月月舒"防火墙,超轻超薄,易于携带,提供由内到外的全方位保护,即使流量再大,也可以冲浪自如,再也不用担心侧漏啦。

TOP

问题是,你必须要有SE_BACKUP_NAME 权限才能调用这个函数。仔细看一下MSDN就知道了~~~~
俺是mika!别叫错了! 俺的QQ:794773 http://hi.baidu.com/stealthwalker/ my private area ------------------------------------------------------------ <a href=http://hi.baidu.com/stealthwalker target=_blank></a>

TOP

HOHO  我和楼主都大意  没有仔细看MSDN
请加47809945   100%通过!每个月总有那么几天,您的网络会受到黑客的攻击--坐立不安,烦躁无力,使用虎虎开发的"月月舒"防火墙,超轻超薄,易于携带,提供由内到外的全方位保护,即使流量再大,也可以冲浪自如,再也不用担心侧漏啦。

TOP

我仔细看了.没有SE_BACKUP_NAME相关内容...
难道是LPSECURITY_ATTRIBUTES lpSecurityAttributes里面定义的securtiy descriptor?
难道我看的太老了?
我的是2001 july....
先说好.打人不准打脸
连入侵者都敢说自己在做网络安全。关键大家是真正为安全作过什么?

TOP

晕死。。。。
看这里:http://msdn.microsoft.com/librar ... base/regsavekey.asp
注意Remarks 部分的最后一句
俺是mika!别叫错了! 俺的QQ:794773 http://hi.baidu.com/stealthwalker/ my private area ------------------------------------------------------------ <a href=http://hi.baidu.com/stealthwalker target=_blank></a>

TOP

2001里面的

Remarks
If hKey represents a key on a remote computer, the path described by lpFile is relative to the remote computer.

The RegSaveKey function saves only nonvolatile keys. It does not save volatile keys. A key is made volatile or nonvolatile at its creation; see RegCreateKeyEx.

You can use the file created by RegSaveKey in subsequent calls to the RegLoadKey, RegReplaceKey, or RegRestoreKey functions. If RegSaveKey fails part way through its operation, the file will be corrupt and subsequent calls to RegLoadKey, RegReplaceKey, or RegRestoreKey for the file will fail.

Windows NT/2000 or later: The new file has the archive attribute.

Windows 95/98/Me: The new file has the archive, hidden, read-only, and system attributes.

Windows NT/2000 or later: The calling process must have the SE_BACKUP_NAME privilege enabled. For more information about privileges, see Privileges.

Windows 95/98/Me: No registry subkey or value name may exceed 255 characters.

终于在那么多里面找到这句了....实在是没仔细看...唉...惭愧啊...
连入侵者都敢说自己在做网络安全。关键大家是真正为安全作过什么?

TOP

还是在线的最新 我装的MSDN 2003  有很多东西都没有
请加47809945   100%通过!每个月总有那么几天,您的网络会受到黑客的攻击--坐立不安,烦躁无力,使用虎虎开发的"月月舒"防火墙,超轻超薄,易于携带,提供由内到外的全方位保护,即使流量再大,也可以冲浪自如,再也不用担心侧漏啦。

TOP

我有October 2004,你要我可以给你.4.4G
不过从2001 july之后的MSDN都没法和VS 6集成了.
连入侵者都敢说自己在做网络安全。关键大家是真正为安全作过什么?

TOP

经过无敌的提示.
给出正确代码.已帮助和我一样在这里碰到问题的朋友

#include <windows.h>
#include <stdio.h>

int EnablePrivilege(LPCTSTR lpszPrivilege,BOOL bEnable)
{
HANDLE hToken;
TOKEN_PRIVILEGES tp;
LUID luid;
if(!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES |
  TOKEN_QUERY | TOKEN_READ,&hToken))
  return 1;
//if(!LookupPrivilegeValue(NULL, lpszPrivilege, &luid))
//  return 1;
if(!LookupPrivilegeValue(NULL,lpszPrivilege,&luid ) )      // receives LUID of privilege
    return 2;
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = (bEnable) ? SE_PRIVILEGE_ENABLED : 0;

AdjustTokenPrivileges(hToken,FALSE,&tp,NULL,NULL,NULL);
CloseHandle(hToken);
return 0;
}

void ShowError(const LONG ErrorNo){
    LPVOID lpMsgBuf;
    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
   NULL,
   ErrorNo,
   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
   (LPTSTR) &lpMsgBuf,
   0,
   NULL
    );
    printf("ID:%d\n%s",ErrorNo,lpMsgBuf);
}

int main(){
    EnablePrivilege(SE_BACKUP_NAME,TRUE);

           HKEY hKey;

    RegOpenKeyEx( HKEY_CLASSES_ROOT,
          "WScript.Network",
          0, KEY_WRITE, &hKey );
  LONG result;



    result=RegSaveKey(hKey,"d:\\test.reg",NULL);
    ShowError(result);

    RegCloseKey( hKey );

           return 0;
}
连入侵者都敢说自己在做网络安全。关键大家是真正为安全作过什么?

TOP

还有发现一点
如果是调用RegDeleteKey
则需要删除的KEY下面
不能再有sub key
否则会返回拒绝访问
但是98,ME,XP好像不受影响
连入侵者都敢说自己在做网络安全。关键大家是真正为安全作过什么?

TOP

发新话题