Monthly Archives: July 2008

Vista Elevator 2.0

(This post is moved here from the TweakUAC web site, where it was first published on February 27, 2007)

Vista Elevator 2.0 is an updated version of the sample application Vista Elevator that uses a different approach to solving the problem of starting a non-elevated task from an elevated one.

The first version of Vista Elevator used a trick that created a non-elevated process by programming Vista Task Scheduler to start such a process immediately upon its registration. It worked even if the parent process was elevated. However, there were a few problems with that:

  1. It worked well when the process was started by an administrator (that is, by an account with a “split token”). However, if the account was of a standard user (or a Guest account) it did not work as expected: the secondary non-elevated process was created by Task Scheduler to be executed in the administrator’s context, rather than in the original context of the standard user account. The task would launch not when it was registered, but later on, when the administrator logged on to the system.
  2. The target machine could have Task Scheduler disabled. In such a case, this method would fail to start the secondary non-elevated task at all.

To solve these problems, a different approach is necessary. An obvious method of achieving the goal would be to have a separate helper executable that would help the main application launch a non-elevated task, when necessary. Specifically, it would work as follows:

  1. When a user wants to run the application (main.exe), s/he would start by launching the helper executable (helper.exe) first.
  2. The helper process would start non-elevated, but it would launch main.exe, and request it to start elevated (for example, by using the Run Elevated() function).
  3. After the administrator would have approved the launch of main.exe, the user would work with it, as usual. Helper.exe would keep running non-elevated, waiting for a signal from main.exe.
  4. When main.exe would need to start a non-elevated task, it would send a signal to helper.exe, using some sort of inter-process communication, and helper.exe would start a non-elevated process on main.exe’s behalf.

Such an approach would solve both problems described above: it would not require Task Scheduler to be running on the target system, and it would launch the non-elevated task in the context of the original user, whether it is an administrator, a standard user, or a guest.

What is not good about this approach, it requires a separate helper process to be running all the time, wasting the CPU cycles. It also requires to design a communication protocol between the helper and the main executable, which is not a trivial task and is subject to errors. Wouldn’t it be better if we could use some other non-elevated process already running on the target system to launch a non-elevated process on the main.exe’s behalf? Let’s see… There actually is a process that is guaranteed to run all the time while the user is logged on to the system: the Windows shell! And it runs non-elevated, just what we need. Seems like a perfect candidate for our helper process. But how can we ask Windows shell to launch a process on our behalf? Simply calling ShellExecute() or Start Process() would not work, because they would be executed by our process, not by the shell. What we need to do is inject our code into the shell process and make it launch a process on our behalf!

So, the plan of the attack could be as follows:

  1. Our process would find a window that belongs to the shell, and that is guaranteed to be available at any time. A good window for this purpose is Progman, that is responsible for displaying the desktop. We can call the FindWindow() API to obtain a handle to this window.
  2. Our process would call RegisterWindowsMessage() API to register a unique message that we would use to communicate with the shell’s window. It must be unique to avoid possible conflicts and side effects if we would have accidentally picked a message that is already used by the shell for some purpose.
  3. Our elevated process would call SetWindowsHookEx() API to install a global hook, to be invoked when a windows message gets processed by any process running on the system.
  4. Once the hook is installed we would send our unique message to the shell’s window, and that would make our hook procedure to get invoked. (That’s how we inject our code into the shell’s process!)
  5. When the hook procedure is called (in the context of the shell process), it would call ShellExecute() API to launch the non-elevated process that we need. The process would start non-elevated because the shell’s process is not elevated, and our process would inherit the shell’s elevation level.
  6. Finally, we would remove the hook, as we no longer need it and it should no longer be called and waste system resources and CPU cycles.

That’s the plan that is implemented as the RunNonElevated() function in the VistaTools.cxx file that VistaElevator 2.0 uses. To make it work, the design of the VistaElevator application had to be changed significantly:

Firstly, in order to be able to install a global hook, the hook procedure must reside in a DLL. It means that we can no longer have a single executable, we must create a DLL to go with it, as well.

Secondly, in order to be able to pass data from our process to our code injected in the shell’s process, we must set up a special code section to be shared between several processes.

Finally, to be able to use this method with both 32-bit and 64-bit versions of Vista, we must produce two separate builds, one 32-bit and another one 64-bit. The reason for that is that on a 64-bit Vista the shell is a native 64-bit process, and in order to be able to hook it, we need to use 64-bit code, too.

To see the details, use the download links below:

THIS CODE AND INFORMATION IS PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

VistaElevator2.zip

(the compiled executables only, without the source code)

VistaElevator2-src.zip

(the source code, a Visual Studio 2005 project)

Note: If you want to compile the source code on your own, make sure you have the latest Windows SDK (see msdn.microsoft.com for more information).

Did you know? Our USB Encryption Software can protect any USB flash drive or any other external drive with a password and strong encryption. Try it free for 30 days! Read more…

The first bug in Vista UAC?

(This post is moved here from the TweakUAC web site, were it appeared first on January 1st, 2007).

I believe I’ve stumbled upon the first bug in Vista UAC (in the final release of Vista, not in a beta version).

It’s very easy to see the bug in action:

  • Login to your computer with the Guest account. (You may need to enable the Guest account first, using the Control Panel).
  • Download any digitally signed program (such as TweakUAC), save it to the default download folder (C:\Users\Guest\Downloads).
  • Now run the file you’ve just downloaded, and take a look at the elevation prompt displayed:

As you can see, UAC cannot recognize that the file contains a valid digital signature, and it warns you that the program is “unidentified”. This is a bug, because you can check that the digital signature of the file is actually valid:

This problem is not limited to the TweakUAC file, any other digitally signed executable (such as the installation utilities of most software packages) will produce the same effect. All you need to do to reproduce this bug is login to Vista with the Guest account and run a digitally signed file from the Guest\Downloads folder. Note that if you copy the executable into the C:\Program Files folder, and run the file from there, its digital signature would magically become recognizable by UAC! Move the file to the root folder C:\, and the file again becomes unidentified to UAC.

Is this bug dangerous? Yes, it is! The whole idea behind UAC is to shift the responsibility of distinguishing the bad programs from the good ones to the end user (you!). The only tool that UAC gives you in this regard is the digital signature information, and it turns out it’s broken! How are you supposed to make the decision whether to trust a certain program or not if UAC does not provide you with the correct information? (Nevermind, it’s a rhetorical question).

Andrei Belogortseff

WinAbility Software Corp.

Comments:

21 Responses to “The first bug in Vista UAC?”

  1. Myria Says:

    I believe that this is because there is an NTFS fork on the directory that says that anything in that directory shouldn’t be trusted. This is similar to XP in how it knows that a file was downloaded recently by IE.

  2. Soumitra Says:

    Hi Andrei,

    Have a quick question about TweakUAC. Can I suppress UAC messages only for a single application using TWeak? Or does it suppress all UAC messages, system wide?

    Thanks.

    Regards,

    Soumitra

  3. Andrei Belogortseff Says:

    Hi Soumitra,

    > Can I suppress UAC messages only for a single application using TWeak?

    No, it’s impossible.

    > Or does it suppress all UAC messages, system wide?

    Yes, that’s how it works.

    Andrei.

  4. Andrei Belogortseff Says:

    Hi Myria,

    > I believe that this is because there is an NTFS fork on the directory that says that anything in that directory shouldn’t be trusted. This is similar to XP in how it knows that a file was downloaded recently by IE.

    It may very well be so, but it does not make it any less of a bug. If a file contains a valid digital signature, Windows should not misrepresent it as coming from an unidentified publisher.

    Andrei.

  5. Chris Says:

    How did you take a screenshot of the UAC? I can’t get Print Screen to copy it to the clipboard, and the snipping tool isn’t working either.

  6. Andrei Belogortseff Says:

    Hi Chris,

    > How did you take a screenshot of the UAC? I can’t get Print Screen to copy it to the clipboard, and the snipping tool isn’t working either.

    Those tools don’t work because UAC displays its messages on the secure desktop, to which the “normal” user tools have no access. To solve this problem, I’ve changed the local security policy to make the UAC prompts to appear on the user’s desktop. After that, I used the regular Print Screen key to capture the screenshots.

    Hope this helps,

    Andrei.

  7. Matthew Bragg Says:

    Hi Andrei,

    I sell software to a *very* non-technical customer base. My setup procedure includes installation of an .ocx file into the \windows\system32 folder and registration of it using regsvr32. In order to copy anything into the \windows\system32 folder under Vista I have to turn off UAC. I would like to be able to do this automatically, programmatically, so I don’t have to make my users mess with UAC. I’d like to be able to turn off UAC for a second or two programmatically, then turn it back on. Will your software enable me to do that?

    Thanks

  8. Andrei Belogortseff Says:

    Hi Matthew,

    > I’d like to be able to turn off UAC for a second or two programmatically, then turn it back on.

    Unfortunately it’s impossible: if you enable or disable the UAC, Windows must be restarted before the change would have take effect.

    To solve your problem:

    > In order to copy anything into the \windows\system32 folder under Vista I have to turn off UAC.

    It looks like your setup process is executing non-elevated, that’s why it cannot do that. You may want to try to start it elevated and see if it would have solved the problem without turning off the UAC.

    HTH

    Andrei.

  9. caz Says:

    don’t use TweakUAC because this program makes your Vista unsafe!

  10. Herbys Says:

    > How are you supposed to make the decision whether to trust a certain program or not if UAC does not provide you with the correct information? (Nevermind, it’s a rhetorical question).

    The answer is you are not. A guest should not be allowed to make any decision about installing software. If you log on as a valid user, the prompt works just fine. If you log on as a guest, you shouldn’t be installing software, so any dire warning is fine.

    Yes, this might be unintended behavior (or perhaps it is not), but its impact is null.

  11. Andrei Belogortseff Says:

    Hi Herbys, you wrote:

    > The answer is you are not. A guest should not be allowed to make any decision about installing software.

    Sorry, but you are missing the point: the UAC displays this information for the _administrator_ to use and to make a decision, not for the guest user. The administrator is supposed to review the information and enter his or her password to approve the action. Take a look at the screenshot and see for yourself.

    > If you log on as a guest, you shouldn’t be installing software

    Why shouldn’t I? What if I want to install a program for use by the guests only? For example, I use only one web browser (IE), but I never know what browser a guest may want to use. So, being a good host :-) I want to install also Firefox and Opera, but I don’t want them to clutter my desktop, etc., I want them to be used by the guests only. To achieve that, I would log in to the guest account and install the additional browsers from there.

    > so any dire warning is fine.

    Wrong.

    > Yes, this might be unintended behavior (or perhaps it is not), but its impact is null.

    May be, may be not. In any case, it does not make it any less of a bug!

  12. Timothy Conner Says:

    Is there any plan to adapt your program into a Control Panel Applet? I think that would be very clever.

  13. Andrei Belogortseff Says:

    Hi Timothy, you wrote:

    > Is there any plan to adapt your program into a Control Panel Applet?

    No, we don’t have such plans at this time, sorry.

  14. Mike Says:

    Anyone know why Vista won’t let me rename any new folder?

    The permissions are all checked for me as administrator, still I get an error message, “folder does not exist”. I can put things in folder and move it, but can’t rename it?

  15. Bob Says:

    To be honest, I have always thought that digitally signing was merely a way of generating more revenue. It doesn’t offer you any more security and windows will always moan at you regardless of an application having a signature or not.

    Even if your application has the “all powerful” and completely unnecessary Windows Logo certification, it still offers nothing to you as a user other than the reassurance that the person/s developing the software has allot of spare cash.

  16. Thomas Says:

    Bob Said:

    > To be honest, I have always thought that digitally signing was merely a way of generating more revenue.

    I have to agree. I’ve heard the argument of how it’s all designed to protect users from malicious software, and that’s all well and good as far as that goes — but since Vista, and most mobile OSes, don’t offer a way for users to say “okay, I understand the risk, I accept full responsibility, please go ahead and run this unsigned application without restrictions, and never bother me again when I try to run this application”… That makes it pretty clear it’s just a racket initiated by VeriSign and the like, and happily endorsed by Microsoft.

  17. Andrew Says:

    This is not a bug.

    The first screen shot shows that Windows doesn’t trust the identity contained in the certificate. In other words, “I can read this, but I don’t know if I should trust the person who wrote it.”

    The second screen shot just shows that the certificate is well-formed, that Windows can understand the information contained within it. It says nothing about what Windows will do with that information.

    Who did you did you pay to sign the certificate for you? If they’re not someone with a well-established reputation, then I don’t WANT my computer to automatically trust them.

    It’s just like how web browsers automatically trust SSL certificates signed by Thawte or Verisign, but will ask you before accepting a certificate from Andy’s Shady Overnight Certificate Company. As always, it’s a balancing act between usability and security.

  18. Andrei Belogortseff Says:

    Andrew, you wrote:

    > This is not a bug.

    OK, there is a fine line between a bug and a feature, let’s assume for a moment that it’s a feature rather than a bug. If so, what benefit is this feature supposed to provide? As the second screen shows, the file is digitally signed, and Vista can detect that. Yet, it shows the publisher as “unidentified” on the first screen. Note also (as I mentioned in the post), that if you move the file to one a few specific folders (such as C:/Program files), Vista would magically begin to recognize the publisher. Move the file to some other folder, and it’s unidentified again.

    If you can explain why they designed it that way, I would agree with you. Until then, it’s a bug. Guilty until proven innocent!

    > Who did you pay to sign the certificate for you?

    That particular file was signed with a Verisign certificate, but the same problem occurs with _any_ file, signed with _any_ certificate. Try it yourself and you will see.

  19. Farthen Says:

    I think that it occurs because of IE7 protected mode – see http://victor-youngun.blogspot.com/2008/03/internet-explorer-7-protected-mode-vs.html, it’s a guide to run firefox in protected mode, and this explains very good how the protected mode works… the prompt is because the “Download” Folder is a protected folder (level “low”) and I think it only displays at the guest, because Windows forces UAC to display certificate in normal user mode in “low” level folders, but NOT for the MUCH MORE RESTRICTED “guest” account. This would be my explanaition.

    It doesn’t mean that I like it how Microsoft handels this but this would eventually explain WHY the warning appears sometimes and sometimes not.

  20. Farthen Says:

    sorry, in my last post there is a comma in the link, the correct link is:

    http://victor-youngun.blogspot.com/2008/03/internet-explorer-7-protected-mode-vs.html

  21. Andrei Belogortseff Says:

    Farthen: thank you for the information and explanation!

A book review: “Conversation Marketing” by Ian Lurie

Summary: If you are a small business owner who’s got a web site, but is unsure what to do next,  where to invest your hard earned money to make the web site actually work for your business, this book will serve you well as a good introduction into the Internet marketing.

Although anyone can read this book online for free, I’ve ordered a paper version of it about a year ago, after seeing it mentioned by Bob Walsh in his blog. I was not in the marketing mood, and I did not read it then. These days, I’m getting closer to releasing a new software product (stay tuned for the big announcement here, any day now :-) ), and I’m preparing myself to switching from the programming to the marketing mode for some time, so I decided it was time to read it now. I’m not a novice in the Internet matters (I created the first web site for my business back in 1994, before Google, Yahoo!, and MSN even existed), still I found this book of a good value.

Not that it took too long to read the book: it’s only 93 pages, including the Table of Contents and Acknowledgments. That was my first suprise when I got the book, “Can a book this thin be any good?”. It was, although not without some shortcomings. The biggest of which were rather awkward analogies used throughout the book. For example, the book begins with a description of an imaginary Farmer’s Market that is neat, shiny, visited by a lot of people, but that happens not to have any lettuce on its shelves. This analogy is used to illustrate a poorly designed web site, that does not do a good job of delivering what the visitors are looking for. To me, the analogy is poor: the problem of the missing lettuce was probably caused by a one-time misjudgement of the market’s management, and is easily fixed (by ordering the lettuce!). Problems with web site design and navigation are not so easy to correct.

Another example of a poor analogy is further in the book, when the author explains that you must use a double-opt-in method of subscribing people to your email list. “Don’t sign them up and then ask to unsubscribe!”, writes the author, “That’s just rude, like eating the last piece of cake and then asking if anyone wants it”. Sure, eating the last piece of cake is rude, but it does not illustrate the rudeness of the subscribing to an email list without asking for the permission first. A better analogy, IMHO, would be, for example,  a situation when you are standing on a bus stop, waiting for your bus, and a taxi driver would suddenly stop by you, push you into the car, and start driving, yelling “I’ll take you whenever you want to go, if you don’t want that, I can drop you off on the next corner!”. Now that’s what’s getting on an unwanted email list feels like, if you ask me.

Anyway, those are minor things, which fortunately did not diminish the good value of the book itself for me. What I really liked about the book is the practical advice the author has given, taking an imaginary small business as a case study. Too many books on the Internet marketing give a too abstract advice, that’s difficult to apply to the reality. “Choose the right keyphrases”, “implement good site navigation”, “start a blog”, all that sounds well in theory, but when it comes down to the reality, the question “how do I apply that to my particular situation, to my specific business?” often remains hard to answer. What the author of “Conversation marketing” did, he illustrated the advice he was giving by applying it to the specific situation of a specific small business, step by step, taking it from a regular “brick and walls” business to a business with strong Internet presence, and solid Internet strategy for the future.

The author does not go into the technical details too deeply, and that’s probably why the book turned out so thin in the end. But that’s a good thing, in my opinion: you don’t need to allocate a lot of time for reading it, just a few hours would be enough. Of course, when you start applying the advice to your own business and web site, you will want to revisit the pages, to make sure you’re not missing anything.

To summarize, if you are looking for a good review of the current state of the art and practical advice on doing business on the Internet, get this book. (Just ignore the analogies it has or come up with your own :-) )