邪恶八进制信息安全团队技术讨论组's Archiver

EvilOctal 2006-3-30 02:22

[转载]Fixing LUA(Limited User Account) bugs

原始连接:<A href="http://blogs.msdn.com/aaron_margosis/archive/2006/02/16/533077.aspx">[url]http://blogs.msdn.com/aaron_margosis/archive/2006/02/16/533077.aspx[/url]</A><BR><BR>
<P class=MsoNormal><FONT face=Arial size=2>First, what is "LUA"?</FONT></P>
<P class=MsoNormal><FONT face=Arial size=2>"LUA" is an acronym that variously refers to "Limited User Account", "Least-privileged User Account", "Least User Access", and probably several other clumsy phrases that ultimately indicate a computer user account that cannot make changes that affect other users of the system or the operating system itself. In Windows, these are typically members of the built-in "Users" group; they are explicitly <I>not</I> members of powerful groups such as "Administrators", Power Users", or "Backup Operators", and do not hold elevated privileges such as "Load and unload device drivers," "Take ownership of files or other objects," or "Act as part of the operating system".</FONT></P>
<P class=MsoNormal><FONT face=Arial size=2>A "LUA bug," then, refers to an application -- or a feature of an application -- that works correctly when run with elevated privileges but fails to work for a LUA user, <I>and</I> where there is no technical or business reason for requiring elevated privileges. A common example is when an application saves its runtime settings to a registry key under HKEY_LOCAL_MACHINE (which is read-only to LUA users), instead of to HKEY_CURRENT_USER.</FONT></P>
<P class=MsoNormal><FONT face=Arial size=2>Windows doesn't allow LUA users to change the system time. That is not a LUA bug, because changing the system time has security implications with respect to auditing and to the Kerberos protocol. The fact that Windows XP doesn't allow LUA users to change the time zone is arguably a LUA bug, as is the fact that double-clicking the clock in the taskbar's notification area gives you an error message instead of a read-only view of the Date&Time applet. (Note 1: Vista is heavily focused on a more seamless LUA experience -- see the </FONT><A href="http://blogs.msdn.com/uac/"><FONT face=Arial size=2>UAC blog</FONT></A><FONT face=Arial size=2> for more info -- and the Date&Time applet is a primary target for an upgraded experience. Note 2: I wrote </FONT><A href="http://blogs.msdn.com/aaron_margosis/archive/2005/02/11/371474.aspx"><FONT face=Arial size=2>an earlier post</FONT></A><FONT face=Arial size=2> about how to grant a Windows XP user the ability to change the date, time and/or time zone.)</FONT></P>
<P class=MsoNormal><FONT face=Arial size=2>By far, the majority of LUA bugs are due to registry and file system access. A program might try to save its settings into its installation folder under %ProgramFiles%, or it might try to open a key under HKLM for "All-Access" even if it only ever needs Read access. However, there are other types of LUA bugs: attempting to start or stop a service, load a device driver, access hardware resources directly, create or manage file shares, or even explicitly check whether the current user is a member of the Administrators group.</FONT></P>
<P class=MsoNormal><FONT face=Arial size=2>At the core, there are always one or more low-level operations ("API calls") that succeed when performed as admin but that fail when performed as LUA. You can see some of these yourself using tools such as </FONT><A href="http://www.sysinternals.com/"><FONT face=Arial size=2>SysInternals</FONT></A><FONT face=Arial size=2>' </FONT><A href="http://www.sysinternals.com/Utilities/Regmon.html"><FONT face=Arial size=2>Regmon</FONT></A><FONT face=Arial size=2> and </FONT><A href="http://www.sysinternals.com/Utilities/Filemon.html"><FONT face=Arial size=2>Filemon</FONT></A><FONT face=Arial size=2>. However, is every one of these a real LUA bug? The answer is that it depends on how the application responds to the failure. The responses I have seen can be categorized in one of three ways:</FONT></P>
<UL style="MARGIN-TOP: 0in" type=disc>
<LI class=MsoNormal><FONT face=Arial><FONT size=2><I>"Fire and forget"</I>: The application invokes the operation, doesn't check the result,but doesn't depend on the operation having succeeded in order to continue working correctly. <I><STRONG>This is not a LUA bug.</STRONG></I></FONT></FONT><BR>
<LI class=MsoNormal><FONT face=Arial><FONT size=2><I>"Gracefully degrade"</I>: The application invokes the operation, checks whether it succeeded, and handles failure in an appropriate way. <I><STRONG>This is not a LUA bug.</STRONG></I></FONT></FONT><BR>
<LI class=MsoNormal><FONT face=Arial><FONT size=2><I>"True LUA bug"</I>: The application invokes the operation, assumes it succeeded, and <I>depends on the operation having succeeded</I> in order to continue working correctly. A variation on this is that the app checks whether the operation succeeded, but handles the failure inappropriately, such as by displaying an error message and falling over dead.</FONT></FONT></LI></UL>
<P class=MsoNormal><FONT face=Arial size=2>If you've ever monitored a GUI app running as LUA with Regmon, you've probably come across an example that could be categorized as fire-and-forget: a failed attempt to open <SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Lucida Console'">HKLM \ System \ CurrentControlSet \ Control \ MediaProperties \ PrivateProperties \ Joystick \ Winmm</SPAN> for All-Access. This occurs during initialization of the joystick subsystem for the process. The specific operation fails, but it does not impact the correct behavior of your application. However, I have seen "guidance" on the web (no doubt from people misinterpreting Regmon output) claiming that to fix some particular application you need to grant the user full access to this key. No! It's not a true LUA bug. You should never need to change permissions on this key!</FONT></P>
<P class=MsoNormal><FONT face=Arial size=2>Before you go making wholesale changes to security settings, you should verify that you're remediating a true LUA bug and not just a phantom, and that there aren't better ways that don't increase exposure. More on that in upcoming posts.<BR></FONT><FONT face=Arial size=2><BR></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">You have an application that you – or your users – need to run.<SPAN style="mso-spacerun: yes"> </SPAN>It’s a normal app – it isn’t designed to perform system administration of your computer, but for some reason, it doesn’t work correctly unless it’s run from an account that has administrator-level access (see “<A href="http://blogs.msdn.com/aaron_margosis/archive/2006/02/06/525455.aspx">What is a "LUA Bug"? (And what isn't a LUA bug?)</A>”.<SPAN style="mso-spacerun: yes"> </SPAN>But you don’t want your users running as admin.<SPAN style="mso-spacerun: yes"> </SPAN>What to do?<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The “workaround” most frequently chosen is simply to add the user to the Administrators group.<SPAN style="mso-spacerun: yes"> </SPAN>Sometimes this approach is not decided by the IT department, but by some “helpful” HelpDesk technician:<SPAN style="mso-spacerun: yes"> </SPAN>“Let’s see whether this fixes the problem.”<SPAN style="mso-spacerun: yes"> </SPAN>The technician forgets to remove you from the Admins group, inevitably leading to another HelpDesk call within a few weeks:<SPAN style="mso-spacerun: yes"> </SPAN>“HelpDesk, why is my computer running so slowly, and why are all these porn ads popping up whenever I log on?”<SPAN style="mso-spacerun: yes"> </SPAN>(Answer:<SPAN style="mso-spacerun: yes"> </SPAN>Because you’ve been running as admin!)<SPAN style="mso-spacerun: yes"> </SPAN>Let’s just call this “workaround” a non-starter and not give it any further consideration.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Other common but <I style="mso-bidi-font-style: normal">sub-optimal</I> workarounds are:<SPAN style="mso-spacerun: yes"> </SPAN>1) run the one program as administrator, or 2) run the program as a regular user, but after granting Everyone “Full Control” over the program’s installation folder and all of its registry keys under HKEY_LOCAL_MACHINE, and to all of HKEY_CLASSES_ROOT.<SPAN style="mso-spacerun: yes"> </SPAN>Oh, and while we’re at it, grant the user the “Debug”, “Take ownership” and “Act as part of the operating system” privileges.<SPAN style="mso-spacerun: yes"> </SPAN>These are seriously high-risk ways to get the program to run, and should be avoided.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">So what do you do?<SPAN style="mso-spacerun: yes"> </SPAN>In this mini-series of posts, I’ll lay out a systematic approach for working around LUA bugs that minimizes exposure.<SPAN style="mso-spacerun: yes"> </SPAN>I’ll discuss approaches from most-preferred to least-preferred, with some of the pros and cons of each.<SPAN style="mso-spacerun: yes"> </SPAN>By the way, while this guidance is targeted primarily to Windows XP, it will also work on Windows Vista.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: Arial"><FONT size=4>#1:<SPAN style="mso-spacerun: yes"> </SPAN>It is a bug – treat it like one and make the developers fix it!<o:p></o:p></FONT></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">This is the most preferred approach.<SPAN style="mso-spacerun: yes"> </SPAN>If there is no <I style="mso-bidi-font-style: normal">legitimate</I> business or technical reason for the app to require admin privileges, then failure of the app to work for a regular user account is a serious bug that compromises system security, stability and manageability.<SPAN style="mso-spacerun: yes"> </SPAN>(Note:<SPAN style="mso-spacerun: yes"> </SPAN>if the development team says something like “It’s mission-critical, so it has to run as admin”, or “it writes to HKEY_LOCAL_MACHINE, so it has to run as admin”, the correct response from you is, “You’re talking nonsense.<SPAN style="mso-spacerun: yes"> </SPAN>Fix the bug!”)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Benefits of this approach:<o:p></o:p></SPAN></P>
<OL style="MARGIN-TOP: 0in" type=1>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l6 level1 lfo1; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Once it is fixed this way, you don’t need to carry forward any shims, tweaks or workarounds.<o:p></o:p></SPAN>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l6 level1 lfo1; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Developers may learn from the experience, and stop creating new LUA bugs.<SPAN style="mso-spacerun: yes"> </SPAN>(Note:<SPAN style="mso-spacerun: yes"> </SPAN>Developers running as admin are the #1 cause of LUA bugs!)<o:p></o:p></SPAN></LI></OL>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">There are some drawbacks, though:<o:p></o:p></SPAN></P>
<OL style="MARGIN-TOP: 0in" type=1>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The expense in time and/or money may be prohibitive, particularly if you have limited resources and a lot of apps to fix.<SPAN style="mso-spacerun: yes"> </SPAN>You have to consider the possibility of the app having to be rearchitected, and the possibility of new bugs being introduced in the process.<o:p></o:p></SPAN>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo2; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The developers and/or the source code may not be available.<SPAN style="mso-spacerun: yes"> </SPAN>It may be 3<SUP>rd</SUP> party code from a company that no longer exists.<SPAN style="mso-spacerun: yes"> </SPAN>The developers may be in rehab.<SPAN style="mso-spacerun: yes"> </SPAN>Or jail.<SPAN style="mso-spacerun: yes"> </SPAN>Or working for your competitor.<SPAN style="mso-spacerun: yes"> </SPAN>Or they may be working on something “more important”.<o:p></o:p></SPAN></LI></OL>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: Arial"><FONT size=4>#2:<SPAN style="mso-spacerun: yes"> Application Compatibility Toolkit</SPAN></FONT></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Use the LUA Mode shims of the Application Compatibility Toolkit (ACT).<SPAN style="mso-spacerun: yes"> </SPAN>(File and Registry Virtualization is the equivalent solution built into Windows Vista.)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The LUA Mode shims detect attempts to write to system-wide locations in the file system and registry and silently redirect them to per-user locations.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Benefits of this approach:<o:p></o:p></SPAN></P>
<OL style="MARGIN-TOP: 0in" type=1>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l5 level1 lfo3; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">It is easy to implement<o:p></o:p></SPAN></LI></OL>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Drawbacks:<o:p></o:p></SPAN></P>
<OL style="MARGIN-TOP: 0in" type=1>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l2 level1 lfo4; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The LUA Mode shims on XP often do not work (<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:place w:st="on">Vista</st1:place>’s Virtualization is a complete rewrite and will have much higher compatibility marks than XP’s ACT LUA Modes.)<o:p></o:p></SPAN>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l2 level1 lfo4; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The added complexity of the resulting underlying operations can make your troubleshooting more complicated when things don’t work.<o:p></o:p></SPAN></LI></OL>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The next 3 items (3a, 3b and 3c) are system changes that solve different specific issues, but share the common feature of not granting any elevated access to system-wide resources.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: Arial"><FONT size=4>#3a:<SPAN style="mso-spacerun: yes"> </SPAN>Copy specific HKCR keys to HKCU\Software\Classes<o:p></o:p></FONT></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">(Registry notations used here:<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">HKLM = HKEY_LOCAL_MACHINE; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">HKCR = HKEY_CLASSES_ROOT; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">HKCU = HKEY_CURRENT_USER)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Some background:</SPAN></B><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-spacerun: yes"> </SPAN>Prior to Windows 2000, </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">HKCR</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> was just a symbolic link to </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">HKLM\Software\Classes</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">, which only Administrators can write to.<SPAN style="mso-spacerun: yes"> </SPAN>In other words, operations performed on </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">HKCR\.txt</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> would actually occur in </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">HKLM\Software\Classes\.txt</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">.<SPAN style="mso-spacerun: yes"> </SPAN>Windows 2000 introduced per-user registration data, so now </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">HKCR</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> is a <I style="mso-bidi-font-style: normal">merged view</I> of </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">HKLM\Software\Classes</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> and </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">HKCU\Software\Classes</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> (which the user <I style="mso-bidi-font-style: normal">can</I> write to).<SPAN style="mso-spacerun: yes"> </SPAN>If a key exists in the latter, it takes precedence.<SPAN style="mso-spacerun: yes"> </SPAN>So now an operation on </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">HKCR\.txt</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> will occur in </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">HKCU\Software\Classes\.txt</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> <I style="mso-bidi-font-style: normal">if that key already exists</I>, otherwise it will occur in </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">HKLM\Software\Classes\.txt</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> as it had in the past.<SPAN style="mso-spacerun: yes"> </SPAN><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The issue to fix:</SPAN></B><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-spacerun: yes"> </SPAN>A number of applications write to HKCR at runtime to “reinforce” their file associations, COM registration data, etc., and raise an error if the write fails, even if the data they want to write is already there. The same data is written every time the app runs. If that same registration data were stored in </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">HKCU\Software\Classes</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">, then the write operations would succeed, without changing program behavior.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">How to fix it:</SPAN></B><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-spacerun: yes"> </SPAN>First you must identify the keys under HKCR that the application is trying to write to.<SPAN style="mso-spacerun: yes"> </SPAN>(How to do that will be covered in later posts.)<SPAN style="mso-spacerun: yes"> </SPAN>Export those keys to one or more </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">.reg </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">files (in Regedit, use File/Export, Selected branch).<SPAN style="mso-spacerun: yes"> </SPAN>Using a text editor, replace all instances of<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">[HKEY_CLASSES_ROOT\<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">with<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">[HKEY_CURRENT_USER\Software\Classes\<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">and save your changes.<SPAN style="mso-spacerun: yes"> </SPAN>Import the edited .reg file into the registry of the user who needs to run the program.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Benefits of this approach:<o:p></o:p></SPAN></B></P>
<OL style="MARGIN-TOP: 0in" type=1>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l3 level1 lfo5; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">This fixes issues where applications perform operations in HKCR that should have been done only during installation.<o:p></o:p></SPAN>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l3 level1 lfo5; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">This approach is better than loosening access control on system-wide resources under HKCR (HKLM).<SPAN style="mso-spacerun: yes"> </SPAN>Malware overwriting keys under HKCU will not affect operating system components or other users of the computer.<o:p></o:p></SPAN></LI></OL>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Drawbacks:<o:p></o:p></SPAN></B></P>
<OL style="MARGIN-TOP: 0in" type=1>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l7 level1 lfo6; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">It is not easy, with today’s tools, to identify HKCR writes as the source of LUA bugs, and exactly which keys are involved.<SPAN style="mso-spacerun: yes"> </SPAN>(More on this in upcoming posts.)<o:p></o:p></SPAN></LI></OL>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: Arial"><FONT size=4>#3b:<SPAN style="mso-spacerun: yes"> </SPAN>IniFileMapping<o:p></o:p></FONT></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Background:<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Back in the days of Windows 3.x, before there was the Registry that we know and love, the OS and applications stored configuration and preference data to </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">.ini</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> (initialization) files, such as </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">win.ini</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">.<SPAN style="mso-spacerun: yes"> </SPAN>Windows did and still does offer API-level support for .ini files via the “Profile” APIs (e.g., <A href="http://msdn.microsoft.com/library/en-us/sysinfo/base/writeprivateprofilestring.asp">WritePrivateProfileString</A>).<SPAN style="mso-spacerun: yes"> </SPAN>Many apps (including <A href="http://blogs.msdn.com/aaron_margosis/archive/2005/02/09/370264.aspx">some Windows applets</A>) still use these APIs to try to write to .ini-formatted files, often in folders where Users are not supposed to write.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Windows NT 3.1 encouraged the migration from .ini files to the more scalable and manageable Registry, and provided a means for automatically redirecting .ini file reads and writes to registry keys.<SPAN style="mso-spacerun: yes"> </SPAN>The internal implementation of the “Profile” APIs was augmented to use mappings found under </SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\IniFileMapping\</SPAN><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">.<SPAN style="mso-spacerun: yes"> </SPAN>If a mapping for a .ini file is not found under that key, then the operation is performed in the file system as before.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The issue to fix:<SPAN style="mso-spacerun: yes"> </SPAN></SPAN></B><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">If access to an .ini-formatted file – via the “Profile” APIs – is the cause of a LUA bug, it can be remediated by adding a key under the IniFileMapping key to redirect access to HKCU.<SPAN style="mso-spacerun: yes"> </SPAN>Note that IniFileMapping is under HKLM and requires administrative privileges to configure.<SPAN style="mso-spacerun: yes"> </SPAN>The config specifics are described in the documentation for the “Profile” APIs, such as <A href="http://msdn.microsoft.com/library/en-us/sysinfo/base/writeprivateprofilestring.asp">WritePrivateProfileString</A>.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Benefits of this approach:<o:p></o:p></SPAN></B></P>
<OL style="MARGIN-TOP: 0in" type=1>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l4 level1 lfo7; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">This approach is better than loosening access control on system-wide resources in the file system.<SPAN style="mso-spacerun: yes"> </SPAN>Malware overwriting keys under HKCU will not affect operating system components or other users of the computer.<o:p></o:p></SPAN></LI></OL>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Drawbacks:<o:p></o:p></SPAN></B></P>
<OL style="MARGIN-TOP: 0in" type=1>
<LI class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo8; tab-stops: list .5in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">It is not easy, with today’s tools, to identify .ini-file access as the source of LUA bugs.<SPAN style="mso-spacerun: yes"> </SPAN>(More on this in upcoming posts.)<o:p></o:p></SPAN></LI></OL>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: Arial"><FONT size=4>#3c:<SPAN style="mso-spacerun: yes"> </SPAN>SafeDisc<o:p></o:p></FONT></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">A number of games depend on the “secdrv” device driver, also known as “SafeDisc”, from Macrovision.<SPAN style="mso-spacerun: yes"> </SPAN>The secdrv driver that ships with Windows XP is a demand-start driver, which users are not allowed to stop and start, resulting in errors when accessed by programs.<SPAN style="mso-spacerun: yes"> </SPAN>There is an update, available from <A href="http://www.microsoft.com/downloads/details.aspx?familyid=eae20f0f-c41c-44fe-84ce-1df707d7a2e9&displaylang=en">Microsoft</A> and from <A href="http://www.macrovision.com/products/safedisc/downloads.shtml">Macrovision</A> that configures the driver to be loaded when the system starts so that the user does not need to start it.<SPAN style="mso-spacerun: yes"> </SPAN>This change allows some games to work correctly for a non-admin user.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">(Note that as of this writing, the Microsoft download page for this update says that “[t]his software will not alter or patch any component on your system, it will only change the startup state of the system component…”<SPAN style="mso-spacerun: yes"> </SPAN>This is actually not true – it installs an updated driver.)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Benefits:</SPAN></B><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-spacerun: yes"> </SPAN>Easy to implement, and no ACL changes to systemwide resources.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Drawbacks:</SPAN></B><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN style="mso-spacerun: yes"> </SPAN>None, really.<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><I style="mso-bidi-font-style: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Coming up in Part 2:<o:p></o:p></SPAN></I></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><I style="mso-bidi-font-style: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">#4:<SPAN style="mso-spacerun: yes"> </SPAN>Loosening specific ACLs, and<o:p></o:p></SPAN></I></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><I style="mso-bidi-font-style: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">#5:<SPAN style="mso-spacerun: yes"> </SPAN>Running the one app as admin<BR><BR></P>
<P class=MsoNormal><B><SPAN style="FONT-SIZE: 13.5pt"><FONT face=Arial>#4: Loosen ACLs</FONT></SPAN></B></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><FONT face=Arial>The usual reason for LUA bugs is that the developers (and often, the testers) always ran as admin. They didn’t explicitly set out to require that the end-user run as admin, but things crept into the code that depended on admin access, such as writing to files in the root folder of the C: drive, in the app’s installation folder under %ProgramFiles%, or in %windir%. The app worked correctly until you ran it on <I>your</I> machine as a regular User. The app wasn’t designed to handle that scenario gracefully, and barfed. (See </FONT><A href="http://blogs.msdn.com/aaron_margosis/archive/2006/02/06/525455.aspx"><FONT face=Arial>What is a LUA Bug…</FONT></A><FONT face=Arial>).</FONT></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><FONT face=Arial>Option #4 is to change the Access Control List (ACL) on objects to grant your User the access that the program requires. Typically the objects that need tweaking will be in the registry or in the file system (if using NTFS). This must be done very carefully, though, and only after all of the more-preferred options have failed.</FONT></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><B><FONT face=Arial>Constraints:</FONT></B></P>
<OL style="MARGIN-TOP: 0in" type=1>
<LI class=MsoNormal><FONT face=Arial><B>App-specific resources only: </B>ACL changes should only ever be considered on <I>application-specific</I> resources, not on OS-wide resources. While it <I>might</I> be OK to change the ACL on <SPAN style="FONT-FAMILY: 'Courier New'">%ProgramFiles%\VendorX\AppX\DataFolder</SPAN>, you should never change the ACL on <SPAN style="FONT-FAMILY: 'Courier New'">%SystemRoot%\System32</SPAN> – to loosen <I>or</I> to tighten access. (See </FONT><A href="http://support.microsoft.com/default.aspx/kb/885409"><FONT face=Arial>KB article 885409</FONT></A><FONT face=Arial> for more information.)</FONT></LI></OL>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<OL style="MARGIN-TOP: 0in" type=1 start=2>
<LI class=MsoNormal><FONT face=Arial><B>Not used by admins: </B>Avoid changing ACLs on resources – particularly executables such as .exe and .dll files – that are ever used by administrators or services. Doing so increases the risk of elevation of privilege leading to compromise of the entire system. (Even so, the attack surface would remain far smaller than it would be with everything always running as admin.)</FONT></LI></OL>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<OL style="MARGIN-TOP: 0in" type=1 start=3>
<LI class=MsoNormal><FONT face=Arial><B>Avoid binaries:</B> Avoid changing ACLs on program code (e.g., exe, dll, or ocx files) if at all possible, to prevent malware from infecting or replacing them.</FONT></LI></OL>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<OL style="MARGIN-TOP: 0in" type=1 start=4>
<LI class=MsoNormal><FONT face=Arial><B>Single non-admin user (ideal): </B><I>Ideally</I>, the resource should be one that is only ever accessed by a single non-admin user. If the resource is accessed by multiple non-admin users, there is increased risk of one user causing another user’s account to be compromised. As described above, if it is ever used by an admin user or a service, risks are increased further.</FONT></LI></OL>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<OL style="MARGIN-TOP: 0in" type=1 start=5>
<LI class=MsoNormal><FONT face=Arial><B>Least additional privilege: </B>You should grant the least amount of additional access to the smallest possible number of resources and to the smallest possible number of users in order to allow the app to work. Granting Full Control to Everyone on a big chunk of the file system or registry should never be necessary. <BR><BR>Granting the additional access only to the computer’s primary user is optimal, but that may be difficult to manage across a large number of systems when each computer has a different primary user (e.g., grant MARY the permissions on one system, STEVE on another, etc). If you can define a set of users who need to use the program, add them to a group and grant the access to that group.<BR><BR>Another alternative to consider is to grant access to the built-in INTERACTIVE pseudo-group. This will grant the additional access only to whoever is interactively logged on at the time, without also granting any additional remote access to the resource. Note that in a terminal server or Fast User Switching scenario there can be multiple simultaneous users on the computer with INTERACTIVE in their tokens.</FONT></LI></OL>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><B><FONT face=Arial>Benefits of this approach:</FONT></B></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><FONT face=Arial>Big return on the investment of your time – most of the LUA bugs that my colleagues and I have seen revolve around file and registry permissions. This approach will probably fix a larger share of your LUA bugs than any other approach.</FONT></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><B><FONT face=Arial>Drawbacks to this approach:</FONT></B></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<OL style="MARGIN-TOP: 0in" type=1>
<LI class=MsoNormal><FONT face=Arial>It’s #4 on the list for a reason. This approach allows otherwise-constrained users to change shared resources – for good or evil, and makes it easier for one user (or malware unintentionally run by that user) to affect others. If the affected user is an admin, the entire system can be compromised.</FONT></LI></OL>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<OL style="MARGIN-TOP: 0in" type=1 start=2>
<LI class=MsoNormal><FONT face=Arial>As with items #3a and 3b, it is not easy, with today’s tools, to identify precisely which resources should be opened up and by how much. (More on this in upcoming posts.)</FONT></LI></OL>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<OL style="MARGIN-TOP: 0in" type=1 start=3>
<LI class=MsoNormal><FONT face=Arial>It can be difficult to know for certain whether opening access to a resource will inadvertently expose an avenue for elevation of privilege, allowing system takeover.</FONT></LI></OL>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><B><SPAN style="FONT-SIZE: 13.5pt"><FONT face=Arial>#5: Run the one app with elevated privileges</FONT></SPAN></B></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><FONT face=Arial>As a last resort, after all else fails, consider running that one app with elevated groups and/or privileges. Some apps, for example, “address” their LUA bugs by explicitly checking for admin group membership on startup and displaying an error message insisting that you simply have to be an admin to use the program. This may be due to developer laziness, incompetence or arrogance (or all three), but these apps will be resistant to any other workarounds available to you.</FONT></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><FONT face=Arial>Typically, this approach means running the app as admin. You could instead run the app elevated but less-than-full-admin – for example, as a member of Power Users or with a specific privilege such as SeLoadDriverPrivilege. Note, though, that with a little more work many of these other groups and privileges can still be used to take over an entire system.</FONT></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><B><FONT face=Arial>Benefits of this approach:</FONT></B></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><FONT face=Arial>It’s better than always running everything as admin. That’s it – that is the only benefit of this approach.</FONT></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><B><FONT face=Arial>Drawbacks of this approach:</FONT></B></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><FONT face=Arial>Running an app with elevated privileges exposes far more risk than any of the options described earlier. It becomes very difficult to defend the system against a malicious user or malicious software when there’s an app running as admin. A simple example: Run “Notepad” as admin, then choose File/Open – that dialog is now a little Explorer-like window that gives you full, admin-level access to the entire file system, and even the ability to launch programs as admin. That can be exploited by a malicious user, or by malware pumping keystrokes or window messages into the elevated program.</FONT></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><B><FONT face=Arial>How to do it:</FONT></B></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><FONT face=Arial><B>If you trust the user with the admin password</B> or to otherwise make security and trust decisions:</FONT></P>
<UL style="MARGIN-TOP: 0in" type=disc>
<LI class=MsoNormal><FONT face=Arial><B><I>RunAs</I></B> – see </FONT><A href="http://blogs.msdn.com/aaron_margosis/archive/2004/06/23/163229.aspx"><FONT face=Arial>"RunAs" basic (and intermediate) topics</FONT></A><FONT face=Arial> and </FONT><A href="http://blogs.msdn.com/aaron_margosis/archive/2004/07/07/175488.aspx"><FONT face=Arial>RunAs with Explorer</FONT></A><FONT face=Arial> for more information.</FONT>
<LI class=MsoNormal><FONT face=Arial><B><I>MakeMeAdmin</I></B> – see </FONT><A href="http://blogs.msdn.com/aaron_margosis/archive/2004/07/24/193721.aspx"><FONT face=Arial>the original post</FONT></A><FONT face=Arial> and </FONT><A href="http://blogs.msdn.com/aaron_margosis/archive/2005/03/11/394244.aspx"><FONT face=Arial>this follow-up</FONT></A><FONT face=Arial>. MakeMeAdmin is a batch file, so you can easily customize it to run something other than a command shell. You can also customize it to make the elevated context less than full-admin.</FONT>
<LI class=MsoNormal><B><I><A href="http://www.sysinternals.com/Utilities/PsExec.html"><FONT face=Arial>PsExec</FONT></A></I></B><FONT face=Arial> and <B><I><A href="http://www.sysinternals.com/Utilities/ProcessExplorer.html">Process Explorer</A></I></B> from </FONT><A href="http://www.sysinternals.com/"><FONT face=Arial>SysInternals</FONT></A><FONT face=Arial> offer various RunAs-like options. See Mark’s </FONT><A href="http://www.sysinternals.com/blog/2006/03/running-as-limited-user-easy-way.html"><FONT face=Arial>blog post</FONT></A><FONT face=Arial> for more information.</FONT>
<LI class=MsoNormal><B><I><A href="http://www.harper.no/valery/PermaLink,guid,99b85fa3-104f-4a41-a28f-4786c68e77e4.aspx"><FONT face=Arial>RunAsAdmin</FONT></A></I></B><FONT face=Arial>, an interesting </FONT><A href="http://sourceforge.net/projects/runasadmin"><FONT face=Arial>open-source</FONT></A><FONT face=Arial> utility by </FONT><A href="http://www.harper.no/valery/"><FONT face=Arial>Valery Pryamikov</FONT></A><FONT face=Arial>, a very smart Developer Security MVP. RunAsAdmin takes an approach a little like </FONT><A href="http://www.microsoft.com/technet/windowsvista/security/uac.mspx"><FONT face=Arial>Windows Vista’s UAC</FONT></A><FONT face=Arial>, elevating the current user in place without requiring a password.</FONT></LI></UL>
<P class=MsoNormal><B><FONT face=Arial>If you don’t trust the user with the admin password:</FONT></B></P>
<UL style="MARGIN-TOP: 0in" type=disc>
<LI class=MsoNormal><B><I><A href="http://www.desktopstandard.com/PolicyMakerApplicationSecurity.aspx"><FONT face=Arial>PolicyMaker Application Security</FONT></A></I></B><FONT face=Arial> by </FONT><A href="http://www.desktopstandard.com/"><FONT face=Arial>DesktopStandard</FONT></A><FONT face=Arial> uses a Group Policy extension to configure rules for modifying process tokens. PMAS mitigates some of the drawbacks described above. For example, it can be configured so that child processes launched by a targeted app do not inherit its modified token, and can perform granular token modification, raising (or lowering) permissions, and/or adding (or removing) privileges.</FONT>
<LI class=MsoNormal><B><I><A href="http://www.winternals.com/Products/ProtectionManager/Default.aspx"><FONT face=Arial>Protection Manager</FONT></A></I></B><FONT face=Arial> by </FONT><A href="http://www.winternals.com/"><FONT face=Arial>Winternals</FONT></A><FONT face=Arial> (the for-profit side of </FONT><A href="http://www.sysinternals.com/"><FONT face=Arial>SysInternals</FONT></A><FONT face=Arial>) uses a lightweight client-server application and a whitelist approach to block all untrusted applications – while also allowing applications that to have their process tokens and privileges elevated to that of an Administrator or reduced to that of a User (in cases where end users are non-Administrators or Administrators, respectively). Protection Manager also doesn’t allow a child process of an elevated app to run elevated unless it is also explicitly configured as an elevated app. Conversely, all process children of reduced privilege processes are reduced automatically (to also minimize security risk). Applications can be allowed, blocked, elevated, or reduced as specified by an administrator via Digital Signatures, Hashes, NTFS File Ownership, or Path.</FONT></LI></UL>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><B><FONT face=Arial>Trying to "hide" the admin password:</FONT></B></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><FONT face=Arial>The DesktopStandard and Winternals products determine in kernel-mode code whether, when and how to modify a process token. Passwords are not used and are therefore not at risk to exposure, and the modification decision cannot be interfered with by non-admins. By contrast, there are various tools available that perform RunAs-like operations with the admin account credentials encrypted (or sometimes just obfuscated). Even though this raises the bar and will stop some users from getting the admin creds, those passwords still have to be decrypted within the user’s security context, and so are exposed to a user with the right tools.</FONT></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><FONT face=Arial>A frequently asked question is whether the RunAs.exe /savecred option would let one create a shortcut to run a single app as admin using a saved password and not requiring further password entry. There are several issues you should be aware of:</FONT></P>
<UL style="MARGIN-TOP: 0in" type=disc>
<LI class=MsoNormal><FONT face=Arial>The credentials are not tied to any one shortcut – once the creds have been saved they can be used to start any app</FONT>
<LI class=MsoNormal><FONT face=Arial>While the password is securely encrypted with a user-specific key, it will still be decrypted in the user’s security context and at least briefly exposed</FONT>
<LI class=MsoNormal><FONT face=Arial>The /savecred option is not available on XP Home Edition.</FONT></LI></UL>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><FONT face=Arial>//TODO: Discuss my thoughts about the SRP/DropMyRights approach. (Bottom line: I dislike it.)</FONT></P>
<P class=MsoNormal><FONT face=Arial></FONT></P>
<P class=MsoNormal><FONT face=Arial>Much thanks for help and insight for this post goes to Eric Voskuil and Kevin Sullivan of DesktopStandard, and to Mark Russinovich and Wes Miller of Sysinternals/Winternals.</FONT></P><o:p></o:p></SPAN></I></FONT>

页: [1]
© 1999-2008 EvilOctal Security Team