accessing a remote registry with local credentials

2019-03-04 13:05发布

The title is a bit long but i will try to explain: i'm trying to connect from one machine (which is connected to a domain) to another machine which also connected to a domain but lost the supportedencryptiontypes of the kerberos. path: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\kerberos\parameters

basically, when this value changes i as domain admin can't manage this computer or access it, as if this machine is not on the domain anymore. but when i change back this value to the proper value (when i connect locally with local admin user) i get the full management rights and it seems that everything is fine and dandy again.

so basically what i'm trying to do is changing this value remotely, that means connect to the machine's registry with it's own local admin credentials and change back the value.

i'm not posting any code ATM because i have none, except the normal way of accessing a registry remotely with a current logged on user credentials.

will post this code if needed of course.

1条回答
神经病院院长
2楼-- · 2019-03-04 13:45

I found a nice class for that purpose here at SO: https://stackoverflow.com/a/1197430/4547223

I wrote a quick sample with this class with success:

...
using Microsoft.Win32;
using System.Net;
...

string hostName = 192.168.1.1;

using (new NetworkConnection(@"\\" + hostName + @"\admin$", new NetworkCredential(@"ad\administrator", "TopSecret")))
{
    using (RegistryKey remoteHklm = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, hostName))
    {
        using (RegistryKey serviceKey = remoteHklm.OpenSubKey("System\\CurrentControlSet\\Services", true))
        {
            if (serviceKey != null)
            {
                foreach (string key in serviceKey.GetSubKeyNames())
                {
                    Console.WriteLine(key);
                }
            }
        }

    }
}
查看更多
登录 后发表回答