Click here to Skip to main content
15,886,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've stumbled accross a possible way to bypass UAC which seems kind of troublesome.

Normally inserting values into certain portions of the registry programmaticly requires UAC Elevation to a user with administrative priveledges on the target machine. Right?

That being said, should I be able to do this? The following code works under NET 4.5 on Windows 8 AS-IS.

C#
public void DisableTaskManager()
        {
            try
            {
                if (File.Exists("DisableTaskManager.reg"))
                {
                    File.Delete("DisableTaskManager.reg");
                }
                using (FileStream registryFileStream = File.Create("DisableTaskManager.reg"))
                {
                    Byte[] registryFileContents = new UTF8Encoding(true).GetBytes(Properties.Resources.DisableTaskManager);
                    registryFileStream.Write(registryFileContents, 0, registryFileContents.Length);
                    registryFileStream.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.ToString());
            }
            try
            {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName = "regedit";
                startInfo.Arguments = "/s DisableTaskManager.reg";
                Process.Start(startInfo);
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.ToString());
            }
        }


Is this something I'm missing, or is this another gross example of Microsoft security negligence?
Posted
Comments
lewax00 6-Jun-13 11:44am    
Depends, what is in DisableTaskManager.reg? Some areas of the registry do not require elevation, others do. Or since you aren't checking the output of of your process, it might just be failing completely and you ignore the error message.
ZeroPointSoftware 6-Jun-13 12:05pm    
it puts a key in current user polices that simply sets a flag t disable the task manager.

running this via the registry api requires priveledge elevation. I can provide source code I used to do this on request. The point is that registry changes that haev those kinds of effects should have some kind of safety instead of being able to aribtrartily add whatever keys we want into the registry in sensitive areas. ( ie. group policies, etc )
ZeroPointSoftware 6-Jun-13 12:10pm    
I should not be able to simply inject code into the registry via a arbitrary .reg file which DOES bypass the safeguards of UAC to achieve the same effect ( where using the registry api to inject the same values as contained in the .reg file previously discussed DOES trigger a UAC prompt ) catch my drift?
Sergey Alexandrovich Kryukov 6-Jun-13 12:24pm    
I did not try your code and don't want to, but can you put it straight. Suppose UAC is not disabled and your code is run not under elevated privileges. Are you saying that it will successfully executed and the task manager will be disabled? Is this what you mean by your "AS IS"? I doubt it. If it's the case, how do you know, did you try it?
—SA
lewax00 6-Jun-13 12:16pm    
Current user doesn't require elevation.

EDIT: Try it again in HKLM, it won't work. HKCU is intended to be used by any and all programs without admin permissions.

1 solution

I don't think so. Starting from Vista, and reasonably set up, I think, only in Windows 7, UAC is not to be bypassed. I mean, you can bypass UAC only if the user gives an explicit permission. In particular, the whole UAC check can be disabled for a whole system, and then the system really becomes vulnerable, but if you try to do it automatically, your program cannot bypass the explicit UAC check with the user. It will either throw a permission exception, or, if you write the application "As administrator", the permission will be granted.

(You probably know that being logged on Windows with Administrator privilege is not enough, you have to run each application with elevated privileges. Please see:
http://4sysops.com/archives/vista%E2%80%99s-uac-8-ways-how-to-elevate-an-application-to-run-it-with-administrator-rights/[^],
http://www.sevenforums.com/tutorials/11841-run-administrator.html[^].)

The only thing application can initially do, is to request for elevated privileges from the very beginning, thus saving a user from a troublesome ceremony of choosing this "Run as Administrator" option described above. To do this to your application, you can create and embed appropriate application manifest with required UAC version. This is simple enough and is described here:
http://msdn.microsoft.com/en-us/library/bb756929.aspx[^].

If your application can do something like registry access every time you use it, or on a regular basis, this is a very reasonable thing to do so. And of course, if you want to use Process.Start (which I don't recommend, it's better to use Registry API or anything you can do to avoid starting a child process), your child process will also inherit already elevated privileges. However, it won't bypass any UAC check. It means the request for UAC dialog will be guaranteed to be presented to the user before any APIs requiring elevated access are called. If the user agrees, the application proceeds with elevated privileged, if not, the whole process will be safely terminated. Of course, this is much better than having a security exceptions when your application is already running.

I did not mention such thing as "XP compatibility mode", just don't want to discuss it here. Of course it would make the system vulnerable. I hope this trash will go out of practice with time and will eventually be phased out. For application development, it's too sloppy to keep to the obsolete "don't care about security" practice. At the same time, keeping the application away from security-sensitive actions or otherwise request for proper permissions is way too easy, so ignoring correct safety practices should not be a discussable option.

[EDIT #1]

I just tried to reproduce it on Windows 7. The behavior was correct: it does request my confirmation with UAC dialog. Something is wrong with your OS. Are you sure you did not lower down system security settings?

If you think the wrong part is having Windows 8, I don't know. I'm not going to try out Windows 8, because I don't consider it as a serious OS, by some other, unrelated reasons. If you firmly maintain that it happens to Windows 8 installed by default, without disabling the UAC in system-wide settings, it will be yet another argument against ever using it.

After all, I tried out Vista, but even in nightmare I could not imagine using it in real work. :-)

[EDIT #2]

More detail on the test described above:

Windows 7 has the following options under the applet "Choose to be notified about changes to your computer". It has 4 options:

  1. "Always notify me when…"
  2. Default — Notify me only when programs try to make changes to my computer
    Don't notify me when I make changes to Windows settings.
  3. [Same as above adding "don't dim my desktop"]
  4. Never notify me when…


I tried it with #1 and #2 (default). In both cases, UAC dialog requested me. Normally, I personally use option #1 "Always notify…".

Are you sure you are using the same or equivalent level of UAC notification with Windows 8?

—SA
 
Share this answer
 
v3
Comments
ZeroPointSoftware 6-Jun-13 12:13pm    
Sergey,

I understand for the most part what your saying. Please see my comments to lewax00 for a little more clarification. The point of my initial post is to express my view that this is infact another example of sloppy microsoft security practices which allow this sort of thing to happen.

The end user should be the final authority on allowing system changes, not sloppy code. But of course, it's not an ideal world we live in.
Sergey Alexandrovich Kryukov 6-Jun-13 12:21pm    
I agree with you views. I just think that, as soon as "XP mode" is not used and UAC is not disabled by the user, OS actually meets your requirements. Is it not? Then please tell me where?
I don't mean obsolete systems, I actually mean Windows 7.
—SA
ZeroPointSoftware 6-Jun-13 13:04pm    
LOL. I'm with you on the Windows 8 thing. It was more a lets screw around because I'm bored kind of day. Never dreamed I'd be finding a major issue...waigt...scratch that. lol
Sergey Alexandrovich Kryukov 6-Jun-13 13:10pm    
I also added [EDIT #2] with more detail, asking for another confirmation from you, on Windows 8.
Please reply: if you really have UAC not disabled at the level of system-wide settings, it would be a real crime. How it looks in your case?
—SA
ZeroPointSoftware 6-Jun-13 13:14pm    
installed with the defaults for UAC. No changes made.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900