<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Security for Canadian Developers : Guest Bloggers</title><link>http://blogs.msdn.com/s4cd/archive/tags/Guest+Bloggers/default.aspx</link><description>Tags: Guest Bloggers</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>[Guest Blog] User Account Control for Developers</title><link>http://blogs.msdn.com/s4cd/archive/2007/04/16/guest-blog-user-account-control-for-developers.aspx</link><pubDate>Mon, 16 Apr 2007 17:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2155068</guid><dc:creator>jldavid</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/s4cd/comments/2155068.aspx</comments><wfw:commentRss>http://blogs.msdn.com/s4cd/commentrss.aspx?PostID=2155068</wfw:commentRss><description>&lt;FONT size=2&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;A class="" href="http://www.kennyandkarin.com/Kenny/biography.htm" target=_blank mce_href="http://www.kennyandkarin.com/Kenny/biography.htm"&gt;Kenny Kerr&lt;/A&gt; is our guest blogger this month. Here is his bio: Kenny Kerr is a founding employee and Chief Software Architect at PlateSpin Ltd. where he designs and builds new products and helps drive the technical direction for PlateSpin’s market-leading product family. Prior to PlateSpin, Kenny has worked for leading software companies in Africa, the United States, and Canada. With a specialty in commercial software development, he focuses on designing distributed systems, open APIs, performance tuning, Windows systems programming, and most notably secure design and programming practices around C++.&lt;BR&gt;&lt;BR&gt;---&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Since the release of Windows 2000, the developers working on Windows have been trying to create an environment where users can work safely and securely. Windows 2000 introduced techniques for creating restricted tokens that can effectively limit the permissions and privileges afforded to an application. Windows XP introduced further improvements but it has simply not been pervasive enough to make any real difference for the average user... until now. Whatever your initial reaction, User Account Control (UAC) is here to stay and really isn’t as bad as critics make it out to be. As developers we have a responsibility to embrace it so that the applications we develop don’t annoy and desensitize our users with needless prompts. In this article we are taking a practical look at UAC and specifically what can be done programmatically with respect to elevation and integrity control.&lt;/P&gt;&lt;B&gt;
&lt;P&gt;What is security context?&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;Security context refers to those things that define and constrain what a process or thread can do in terms of permissions and privileges. A security context on Windows is defined in terms of a logon session and these are manipulated via tokens. As its name suggests, a logon session represents a specific session on a single computer for a given user. Programmers interact with logon sessions by means of tokens. Any number of tokens can be created that refer to the same logon session. These tokens can offer different sets of permissions and privileges based on a subset of those provided by the logon session. This is really the key to how UAC works or at least a big part of it.&lt;/P&gt;&lt;B&gt;
&lt;P&gt;So how does UAC work?&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;On Windows Vista there are two predominant types of user accounts, standard users and administrators. The first user account that you can create will be an administrator at least initially and any subsequent user accounts will be standard users by default. Standard user accounts are for those people who you do not trust with complete control over the computer. Administrator accounts are for those users who also enjoy complete control over the computer. Unlike previous versions of Windows, you don’t have to logon as a standard user to protect yourself from malicious code that may find its way to your computer. The logon sessions created for standard users and administrators are equally capable of protecting from such threats.&lt;/P&gt;
&lt;P&gt;When a standard user logs on to a computer a new logon session is created and they are presented with a shell application such as Windows Explorer that was created by the system and associated with the user’s newly created logon session by means of a token. This effectively limits what the user can do since Windows Explorer can only run those applications and access those resources that the user’s logon session permits based on the permissions and privileges specified by the token.&lt;/P&gt;
&lt;P&gt;When an administrator logs on to a computer things are a little different and this is where Windows Vista differs dramatically from previous versions. Although the system creates a new logon session, it creates not one but two different tokens representing the same logon session. The first token grants all the permissions and privileges afforded to the administrator while the second token is a restricted token, sometimes called a filtered token, offering far fewer permissions and privileges. This restricted token offers practically the same capabilities and constraints as would be granted to a standard user. The system then creates the shell application using the restricted token. This means that although the user is logged on as an administrator, applications are by default run with limited permissions and privileges.&lt;/P&gt;
&lt;P&gt;When the administrator needs to perform some task that requires additional permissions or privileges not granted to the restricted token, he or she can elect to run an application using the full security context provided by the unrestricted token. What protects the administrator from malicious code is that this elevation to the unrestricted token is only allowed after the administrator has confirmed the desire to use the unrestricted token by means of a secure prompt provided by the system. Malicious code cannot suppress this prompt and thereby gain complete control over the computer without the user’s knowledge. As I hinted at before, restricted tokens are not new Windows Vista but it is in Windows Vista that they are finally being used in an integrated way in the shell to provide a more secure environment for users to work (and play).&lt;/P&gt;&lt;B&gt;
&lt;P&gt;Restricted tokens&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;Although you will typically not have to create restricted tokens yourself, it is useful to understand how it’s done so that you have a better idea of what is being done on your behalf and so that you can have more insight into the environment in which your application will run. As a developer you may also find yourself needing to create an even more restrictive environment than what is provided by UAC in which case knowing how to create restricted tokens is a must. The aptly named CreateRestrictedToken function creates a new token that is a duplicate of an existing token with certain restrictions. This function can restrict the toke in a number of ways:&lt;/P&gt;
&lt;P&gt;• By specifying deny-only security identifiers (SIDs) that can only be used to deny access to securable resources.&lt;/P&gt;
&lt;P&gt;• By specifying restricting SIDs that will be used as an additional access check.&lt;/P&gt;
&lt;P&gt;• By deleting privileges.&lt;/P&gt;
&lt;P&gt;The restricted token used by UAC is created by adding deny-only SIDs and deleting privileges. Restricted SIDs are not used. Let’s walk through a simple example. The first thing we need is a token to duplicate and restrict. Let’s grab the process token:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;
&lt;P&gt;CHandle processToken;&lt;/P&gt;
&lt;P&gt;VERIFY(::OpenProcessToken(::GetCurrentProcess(),&lt;/P&gt;
&lt;P&gt;TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY | TOKEN_QUERY,&lt;/P&gt;
&lt;P&gt;&amp;amp;processToken.m_h));&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;Next we need an array of SIDs to disable. This ensures that they can never be used to allow access. The following code uses my handy WellKnownSid class to construct the SID for the built-in Administrators group. The WellKnownSid class is available with the download for this article.&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;
&lt;P&gt;WellKnownSid administratorsSid = WellKnownSid::Administrators();&lt;BR&gt;SID_AND_ATTRIBUTES sidsToDisable[] = &lt;BR&gt;{&lt;BR&gt;&amp;amp;administratorsSid, 0&lt;BR&gt;// add additional SIDs to disable here&lt;BR&gt;};&lt;/P&gt;
&lt;P&gt;Next we need an array of privileges to delete. We first need to look up the privilege’s LUID value:&lt;/P&gt;
&lt;P&gt;LUID shutdownPrivilege = { 0 };&lt;BR&gt;VERIFY(::LookupPrivilegeValue(0, // local system&lt;BR&gt;SE_SHUTDOWN_NAME,&lt;BR&gt;&amp;amp;shutdownPrivilege));&lt;/P&gt;
&lt;P&gt;LUID_AND_ATTRIBUTES privilegesToDelete[] = &lt;BR&gt;{&lt;BR&gt;shutdownPrivilege, 0&lt;BR&gt;// add additional privileges to delete here&lt;BR&gt;};&lt;/P&gt;
&lt;P&gt;Finally, we can call CreateRestrictedToken to create the restricted token:&lt;/P&gt;
&lt;P&gt;CHandle restrictedToken;&lt;BR&gt;VERIFY(::CreateRestrictedToken(processToken,&lt;BR&gt;0, // flags&lt;BR&gt;_countof(sidsToDisable),&lt;BR&gt;sidsToDisable,&lt;BR&gt;_countof(privilegesToDelete),&lt;BR&gt;privilegesToDelete,&lt;BR&gt;0, // number of SIDs to restrict,&lt;BR&gt;0, // no SIDs to restrict,&lt;BR&gt;&amp;amp;restrictedToken.m_h));&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;The resulting token’s group SIDs will have an entry for the built-in Administrators group with the SE_GROUP_USE_FOR_DENY_ONLY flag making sure that the SID is used to deny access but not allow access. The token will also be stripped of the SeShutdownPrivilege privilege ensuring that the token cannot be used to restart, sleep, or shutdown the computer. If this sounds interesting you can try a quick experiment. Copy the code above to a console application and then add the following call to the CreateProcessAsUser function, updating the path to the Windows Explorer executable as appropriate:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;
&lt;P&gt;STARTUPINFO startupInfo = { sizeof (STARTUPINFO) };&lt;BR&gt;ProcessInfo processInfo;&lt;BR&gt;VERIFY(::CreateProcessAsUser(restrictedToken,&lt;BR&gt;L"C:\\Windows\\Explorer.exe",&lt;BR&gt;0, // cmd line&lt;BR&gt;0, // process attributes&lt;BR&gt;0, // thread attributes&lt;BR&gt;FALSE, // don't inherit handles&lt;BR&gt;0, // flags&lt;BR&gt;0, // inherit environment&lt;BR&gt;0, // inherit current directory&lt;BR&gt;&amp;amp;startupInfo,&lt;BR&gt;&amp;amp;processInfo));&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;Now kill any existing Explorer.exe process on your computer and run the code. You should notice that you can no longer use Explorer to restart, sleep, or shutdown the computer. These options in the Start menu should be disabled.&lt;/P&gt;
&lt;P&gt;Finally, there is a function called IsTokenRestricted. It does not however tell you whether the token was created using the CreateRestrictedToken function but merely reports on whether the token contains restricted SIDs. So unless you’re using restricted SIDs it is not a very useful function.&lt;/P&gt;&lt;B&gt;
&lt;P&gt;Integrity levels&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;One aspect of UAC that gets very little attention is a concept called Mandatory Integrity Control. This is a new authorization feature added to processes and security descriptors. Securable resources can specify an integrity level in their security descriptors. Each process on the system is also marked with an integrity level which is then validated against the integrity level of the resource as an added authorization step. Despite its relative simplicity, it is a surprisingly useful feature as it allows you to very simply and effectively partition what a particular process can access.&lt;/P&gt;
&lt;P&gt;Imagine you are developing an application that must routinely deal with data from untrusted sources such as the Internet. Since it may be possible for malicious code to circumvent any steps you may have taken to protect the computer, it is helpful to add a certain amount of "defense in depth" as an added layer of protection. One extremely effective solution was described in the previous section using restricted tokens. It can however be complicated to figure out exactly what SIDs to allow and what SIDs to deny access to certain resources and specifically what permissions to grant each identity considering that the application itself still needs certain permissions to function. This is where integrity levels come in. Integrity levels are primarily used to prevent write access while allowing read and execute access. By allowing read and execute access you allow applications to continue to perform the majority of their functions but preventing write access limits the harm they can cause by overwriting system files or tainting the user’s search paths as an example. This is exactly what Internet Explorer 7 does. It runs portions of the browser in a separate process with low integrity and there are only a handful of file system locations that provide write access to low integrity applications.&lt;/P&gt;
&lt;P&gt;There are four integrity levels available to user-mode processes:&lt;/P&gt;
&lt;P&gt;• Low&lt;/P&gt;
&lt;P&gt;• Medium&lt;/P&gt;
&lt;P&gt;• High&lt;/P&gt;
&lt;P&gt;• System&lt;/P&gt;
&lt;P&gt;Standard user tokens as well as restricted (non-elevated) administrator tokens have an integrity level of Medium. Unrestricted (elevated) administrator tokens have an integrity level of High. Processes running under the Local System account have an integrity level of System. The Internet Explorer process token has an integrity level of Low. A simple way to see the integrity levels for various processes is to get the latest version of Process Explorer which includes an optional column to display the integrity level of each process.&lt;/P&gt;
&lt;P&gt;A child process will by default inherit the integrity level of the parent. You can change the integrity level when a process is created but not once it has been created. Further, you cannot raise the integrity level of a child process to anything higher than that of the parent. This avoids code with lower integrity from gaining higher integrity. Let’s first take a look at how to query and set the integrity level for a process and then we’ll examine how to set the integrity level for securable resources.&lt;/P&gt;&lt;B&gt;
&lt;P&gt;Process integrity levels&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;You can determine the integrity level for a process by examining the process token. The GetTokenInformation function returns different classes of information. For example, to determine the user account represented by the token you specify the TokenUser class. GetTokenInformation will then populate a TOKEN_USER structure based on the information in the token. Similarly the TokenIntegrityLevel class can be specified to query the integrity level of the process and a TOKEN_MANDATORY_LABEL structure will be produced. Most of the structures populated by GetTokenInformation are variable length structures and since only GetTokenInformation knows how much space is required you need to follow a rigid pattern for calling this function. Since most of the low-level security functions use LocalAlloc and LocalFree to allocate and release memory, I use a LocalMemory class template along with a GetTokenInformation function template to simplify matters dramatically. You can find these templates in the download that accompanies this article. Here we will simply focus on the subject at hand:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;
&lt;P&gt;CHandle processToken;&lt;BR&gt;VERIFY(::OpenProcessToken(::GetCurrentProcess(),&lt;BR&gt;TOKEN_QUERY,&lt;BR&gt;&amp;amp;processToken.m_h));&lt;BR&gt;LocalMemory&amp;lt;PTOKEN_MANDATORY_LABEL&amp;gt;info;&lt;BR&gt;COM_VERIFY(GetTokenInformation(processToken,&lt;BR&gt;TokenIntegrityLevel,&lt;BR&gt;info));&lt;BR&gt;SID* sid = static_cast&amp;lt;SID*&amp;gt;(info-&amp;gt;Label.Sid);&lt;BR&gt;DWORD rid = sid-&amp;gt;SubAuthority[0];&lt;BR&gt;switch (rid)&lt;BR&gt;{&lt;BR&gt;case SECURITY_MANDATORY_LOW_RID:&lt;BR&gt;{&lt;BR&gt;// Low integrity process&lt;BR&gt;break;&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;case SECURITY_MANDATORY_MEDIUM_RID:&lt;BR&gt;{&lt;BR&gt;// Medium integrity process&lt;BR&gt;break;&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;case SECURITY_MANDATORY_HIGH_RID:&lt;BR&gt;{&lt;BR&gt;// High integrity process&lt;BR&gt;break;&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;case SECURITY_MANDATORY_SYSTEM_RID:&lt;BR&gt;{&lt;BR&gt;// System integrity level&lt;BR&gt;break;&lt;BR&gt;}&lt;BR&gt;default:&lt;BR&gt;{&lt;BR&gt;ASSERT(false);&lt;BR&gt;}&lt;BR&gt;}&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;Here OpenProcessToken is used again to get the process token to query. My GetTokenInformation function template is then called with the appropriate information class and LocalMemory class template specifying the information type. The populated TOKEN_MANDATORY_LABEL structure contains a SID that represents the integrity level. Dissecting it will give you the relative identifier (RID) representing the integrity level that you program against.&lt;/P&gt;
&lt;P&gt;To set the integrity level for a child process is pretty straightforward. Start by creating a duplicate of the parent process token. Then simply set the integrity level using the same information class and data structure used to query the integrity level in the previous example. The SetTokenInformation function comes in handy for this. Finally you can call CreateProcessAsUser to create the child process using the modified token. Here’s an example:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;
&lt;P&gt;CHandle processToken;&lt;BR&gt;VERIFY(::OpenProcessToken(::GetCurrentProcess(),&lt;BR&gt;TOKEN_DUPLICATE,&lt;BR&gt;&amp;amp;processToken.m_h));&lt;BR&gt;CHandle duplicateToken;&lt;BR&gt;VERIFY(::DuplicateTokenEx(processToken,&lt;BR&gt;MAXIMUM_ALLOWED,&lt;BR&gt;0, // token attributes&lt;BR&gt;SecurityAnonymous,&lt;BR&gt;TokenPrimary,&lt;BR&gt;&amp;amp;duplicateToken.m_h));&lt;BR&gt;WellKnownSid integrityLevelSid(WellKnownSid::MandatoryLabelAuthority,&lt;BR&gt;SECURITY_MANDATORY_LOW_RID);&lt;BR&gt;TOKEN_MANDATORY_LABEL tokenIntegrityLevel = { 0 };&lt;BR&gt;tokenIntegrityLevel.Label.Attributes = SE_GROUP_INTEGRITY;&lt;BR&gt;tokenIntegrityLevel.Label.Sid = &amp;amp;integrityLevelSid;&lt;BR&gt;VERIFY(::SetTokenInformation(duplicateToken,&lt;BR&gt;TokenIntegrityLevel,&lt;BR&gt;&amp;amp;tokenIntegrityLevel,&lt;BR&gt;sizeof (TOKEN_MANDATORY_LABEL) + ::GetLengthSid(&amp;amp;integrityLevelSid)));&lt;BR&gt;STARTUPINFO startupInfo = { sizeof (STARTUPINFO) };&lt;BR&gt;ProcessInfo processInfo;&lt;BR&gt;VERIFY(::CreateProcessAsUser(duplicateToken,&lt;BR&gt;L"C:\\Windows\\Notepad.exe",&lt;BR&gt;0, // cmd line&lt;BR&gt;0, // process attributes&lt;BR&gt;0, // thread attributes&lt;BR&gt;FALSE, // don't inherit handles&lt;BR&gt;0, // flags&lt;BR&gt;0, // inherit environment&lt;BR&gt;0, // inherit current directory&lt;BR&gt;&amp;amp;startupInfo,&lt;BR&gt;&amp;amp;processInfo));&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;This example launches Notepad. Give it a try. You should notice that although Notepad can open text files in most locations, it cannot save to any location that is not marked with a low integrity level. Finally, you can get a display name for integrity levels using the LookupAccountSid function, but they’re not all that user friendly so you’re better off using a string table with values like "Low", "Medium", "High", and "System". The token created by the system for standard users has an integrity level of Medium. The restricted, or filtered, token created by the system for administrators also has an integrity level of Medium, but the unrestricted administrator token has an integrity level of High. Now let’s examine how to set the integrity level for a particular resource.&lt;/P&gt;&lt;B&gt;
&lt;P&gt;Resource integrity levels&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;The integrity level for a resource is stored in a special access control entry (ACE) in the system access control list (SACL) of the resource’s security descriptor. The simplest way to set or update this value for system resources is using the SetNamedSecurityInfo function. AddMandatoryAce is a new function provided by Windows Vista to add the special ACE, known as a mandatory ACE, to an ACL. Remember, security is all about confusing people with acronyms…&lt;/P&gt;
&lt;P&gt;Seriously, the code is quite simple if you’re familiar with programming security descriptors. Start off by preparing an ACL pointing to a buffer that is just large enough to hold a single ACE. This is achieved using the InitializeAcl function. Next the SID representing the integrity level is created and added to the ACL using the AddMandatoryAce function. Finally the integrity level is updated using the SetNamedSecurityInfo function. Notice the new LABEL_SECURITY_INFORMATION flag being used in the sample below:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;
&lt;P&gt;LocalMemory&amp;lt;PACL&amp;gt; acl;&lt;BR&gt;const DWORD bufferSize = 64;&lt;BR&gt;COM_VERIFY(acl.Allocate(bufferSize));&lt;BR&gt;VERIFY(::InitializeAcl(acl.m_p,&lt;BR&gt;bufferSize,&lt;BR&gt;ACL_REVISION));&lt;BR&gt;WellKnownSid sid(WellKnownSid::MandatoryLabelAuthority,&lt;BR&gt;SECURITY_MANDATORY_LOW_RID);&lt;BR&gt;COM_VERIFY(Kerr::AddMandatoryAce(acl.m_p,&lt;BR&gt;&amp;amp;sid));&lt;BR&gt;CString path = L"C:\\SampleFolder";&lt;BR&gt;DWORD result = ::SetNamedSecurityInfo(const_cast&amp;lt;PWSTR&amp;gt;(path.GetString()),&lt;BR&gt;SE_FILE_OBJECT,&lt;BR&gt;LABEL_SECURITY_INFORMATION,&lt;BR&gt;0, // owner&lt;BR&gt;0, // group&lt;BR&gt;0, // dacl&lt;BR&gt;acl.m_p); // sacl&lt;BR&gt;ASSERT(ERROR_SUCCESS == result);&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;Retrieving the integrity level of a resource is equally simple provided you realize that most resources won’t have an integrity level set explicitly. Rather the system interprets the absence of an integrity label as if the resource were marked with "Medium" integrity. Start by calling GetNamedSecurityInfo with the same security information flag namely LABEL_SECURITY_INFORMATION. If a valid ACL pointer is returned and contains an ACE then you know the integrity level is set explicitly. Now simply call the GetAce function to retrieve a pointer to the ACE storing the integrity level SID and read the RID value to determine the integrity level. Here is an example:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;
&lt;P&gt;CString path = L"C:\\SampleFolder";&lt;BR&gt;LocalMemory&amp;lt;PSECURITY_DESCRIPTOR&amp;gt;descriptor;&lt;BR&gt;PACL acl = 0;&lt;BR&gt;DWORD result = ::GetNamedSecurityInfo(const_cast&amp;lt;PWSTR&amp;gt;(path.GetString()),&lt;BR&gt;SE_FILE_OBJECT,&lt;BR&gt;LABEL_SECURITY_INFORMATION,&lt;BR&gt;0,&lt;BR&gt;0,&lt;BR&gt;0,&lt;BR&gt;&amp;amp;acl,&lt;BR&gt;&amp;amp;descriptor.m_p);&lt;BR&gt;ASSERT(ERROR_SUCCESS == result);&lt;BR&gt;DWORD integrityLevel = SECURITY_MANDATORY_MEDIUM_RID;&lt;BR&gt;if (0 != acl &amp;amp;&amp;amp; 0 &amp;lt; acl-&amp;gt;AceCount)&lt;BR&gt;{&lt;BR&gt;ASSERT(1 == acl-&amp;gt;AceCount);&lt;BR&gt;SYSTEM_MANDATORY_LABEL_ACE* ace = 0;&lt;BR&gt;VERIFY(::GetAce(acl,&lt;BR&gt;0,&lt;BR&gt;reinterpret_cast&amp;lt;void**&amp;gt;(&amp;amp;ace)));&lt;BR&gt;ASSERT(0 != ace);&lt;BR&gt;SID* sid = reinterpret_cast&amp;lt;SID*&amp;gt;(&amp;amp;ace-&amp;gt;SidStart);&lt;BR&gt;integrityLevel = sid-&amp;gt;SubAuthority[0];&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;ASSERT(SECURITY_MANDATORY_LOW_RID == integrityLevel);&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;B&gt;
&lt;P&gt;Run as administrator&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;So far we’ve looked at some of the individual building blocks that make up UAC such as restricted tokens and integrity levels. Let’s now take a look at what it means to "Run as administrator" and how this can be done programmatically. You have probably noticed that you can right-click an application or shortcut and select a context menu option entitled "Run as administrator". This is available for both standard users and administrators. The concept of running as an administrator is more commonly referred to simply as elevation or creating an elevated process. Standard users are prompted for administrator credentials while administrators are simply prompted for permission to elevate. Either way the end result is a new process running with an unrestricted administrator token and all the permissions and privileges it affords.&lt;/P&gt;
&lt;P&gt;The process of elevation is a bit complicated but fortunately much of the complexity is hidden behind an updated ShellExecute(Ex) function. ShellExecute on Windows Vista makes use of the new Application Information (appinfo) service to perform elevation through an undocumented COM interface. ShellExecute first calls CreateProcess to attempt to create the new process. CreateProcess does all the work of checking application compatibility settings, application manifests, runtime loaders, etc. If it determines that the application requires elevation but the calling process is not elevated then CreateProcess fails with ERROR_ELEVATION_REQUIRED. ShellExecute then calls the Application Information service to handle the elevation prompt and creation of the elevated process since the calling process obviously doesn’t have the necessary permissions to perform such a task. The Application Information service ultimately calls CreateProcessAsUser with an unrestricted administrator token.&lt;/P&gt;
&lt;P&gt;If on the other hand you want to create an elevated process regardless of what application information is available then you can specify the little-known "runas" verb with ShellExecute. This has the effect of requesting elevation regardless of what an application’s manifest and compatibility information might prescribe. The runas verb is not actually new to Windows Vista. It was available on Windows XP and Windows 2003 and was often used to create a restricted token directly from the shell. This behavior has however changed. Here is a simple example:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;
&lt;P&gt;::ShellExecute(0, // owner window&lt;BR&gt;L"runas",&lt;BR&gt;L"C:\\Windows\\Notepad.exe",&lt;BR&gt;0, // params&lt;BR&gt;0, // directory&lt;BR&gt;SW_SHOWNORMAL);&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;Considering how much is going on behind the scenes, aren’t you glad this is all the code you need to write? Although creating a new elevated process is reasonable, it’s not always the most appropriate solution if you only need to elevate temporarily. Enter elevated COM objects.&lt;/P&gt;&lt;B&gt;
&lt;P&gt;Creating an elevated COM object&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;If you invested heavily in the COM era you’ll know that COM supports creating COM servers hosted in a surrogate process. Well this technique has been augmented to allow COM servers to be created in an elevated surrogate process. This is extremely useful since you can simply create the COM object on the fly in your application without having to create a whole new process directly. The hardest part about using this technique is registering the COM server correctly to indicate that it should be loaded in a surrogate process and support elevation since the COM object needs to specifically declare its cooperation. &lt;/P&gt;
&lt;P&gt;This first thing to do is update the COM registration to declare that your library (DLL) server can be run in a surrogate process. All you need to do is add the "DllSurrogate" named value under your server’s AppID registry key. In ATL you simply update the project’s main RGS file to look something like this:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;
&lt;P&gt;HKCR&lt;BR&gt;{&lt;BR&gt;NoRemove AppID&lt;BR&gt;{&lt;BR&gt;'%APPID%' = s 'SampleServer'&lt;BR&gt;{&lt;BR&gt;val DllSurrogate = s ''&lt;BR&gt;}&lt;BR&gt;'SampleServer.DLL'&lt;BR&gt;{&lt;BR&gt;val AppID = s '%APPID%'&lt;BR&gt;}&lt;BR&gt;}&lt;BR&gt;}&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;An empty value for DllSurrogate indicates that the system-supplied surrogate is to be used. The COM client can now specify the CLSCTX_LOCAL_SERVER execution context to create the COM server in the surrogate process:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;
&lt;P&gt;CComPtr&amp;lt;ISampleServer&amp;gt;server;&lt;BR&gt;COM_VERIFY(server.CoCreateInstance(__uuidof(SampleServer),&lt;BR&gt;0,&lt;BR&gt;CLSCTX_LOCAL_SERVER));&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;The next step is to enable elevated launch of the COM class. This involves adding entries to the COM class registration script. An elevation key is added to indicate that elevation is supported for this particular COM class and a "LocalizedString" named value is also required and provides the display name used by the UAC prompt. An ATL COM class registration script should look something like this:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;
&lt;P&gt;HKCR&lt;BR&gt;{&lt;BR&gt;SampleServer.SampleServer.1 = s 'SampleServer Class'&lt;BR&gt;{&lt;BR&gt;CLSID = s '{91C5423A-CF90-4E62-93AD-E5B922AE8681}'&lt;BR&gt;}&lt;BR&gt;SampleServer.SampleServer = s 'SampleServer Class'&lt;BR&gt;{&lt;BR&gt;CLSID = s '{91C5423A-CF90-4E62-93AD-E5B922AE8681}'&lt;BR&gt;CurVer = s 'SampleServer.SampleServer.1'&lt;BR&gt;}&lt;BR&gt;NoRemove CLSID&lt;BR&gt;{&lt;BR&gt;ForceRemove {91C5423A-CF90-4E62-93AD-E5B922AE8681} = s 'SampleServer Class'&lt;BR&gt;{&lt;BR&gt;ProgID = s 'SampleServer.SampleServer.1'&lt;BR&gt;VersionIndependentProgID = s 'SampleServer.SampleServer'&lt;BR&gt;InprocServer32 = s '%MODULE%'&lt;BR&gt;{&lt;BR&gt;val ThreadingModel = s 'Neutral'&lt;BR&gt;}&lt;BR&gt;val AppID = s '%APPID%'&lt;BR&gt;'TypeLib' = s '{A43B074B-0452-4FF4-8308-6B0BF641C3AE}'&lt;BR&gt;Elevation&lt;BR&gt;{&lt;BR&gt;val Enabled = d 1&lt;BR&gt;}&lt;BR&gt;val LocalizedString = s '@%MODULE%,-101'&lt;BR&gt;}&lt;BR&gt;}&lt;BR&gt;}&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;Don’t forget to add a string to your string table for the localized name. The COM client can now launch the elevated COM server. As with CreateProcess, the CoCreateInstance function won’t create an elevated COM object directly. Instead you need to use the COM elevation moniker. This is most easily achieved using the CoGetObject function to build the moniker and return a proxy to the object that is ultimately created:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;
&lt;P&gt;template &amp;lt;typename T&amp;gt;&lt;BR&gt;HRESULT CreateElevatedInstance(HWND window,&lt;BR&gt;REFCLSID classId,&lt;BR&gt;T** object)&lt;BR&gt;{&lt;BR&gt;BIND_OPTS3 bindOptions;&lt;BR&gt;::ZeroMemory(&amp;amp;bindOptions, sizeof (BIND_OPTS3));&lt;BR&gt;bindOptions.cbStruct = sizeof (BIND_OPTS3);&lt;BR&gt;bindOptions.hwnd = window;&lt;BR&gt;bindOptions.dwClassContext = CLSCTX_LOCAL_SERVER;&lt;BR&gt;CString string;&lt;BR&gt;const int guidLength = 39;&lt;BR&gt;COM_VERIFY(::StringFromGUID2(classId,&lt;BR&gt;string.GetBufferSetLength(guidLength),&lt;BR&gt;guidLength));&lt;BR&gt;string.ReleaseBuffer();&lt;BR&gt;string.Insert(0, L"Elevation:Administrator!new:");&lt;BR&gt;return ::CoGetObject(string,&lt;BR&gt;&amp;amp;bindOptions,&lt;BR&gt;__uuidof(T),&lt;BR&gt;reinterpret_cast&amp;lt;void**&amp;gt;(object));&lt;BR&gt;}&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;Using the function template is just as simple as calling CoCreateInstance:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;
&lt;P&gt;CComPtr&amp;lt;ISampleServer&amp;gt;server;&lt;BR&gt;COM_VERIFY(CreateElevatedInstance(0, // window&lt;BR&gt;__uuidof(SampleServer),&lt;BR&gt;&amp;amp;server);&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;As with ShellExecute, the window handle is used by UAC to determine whether the prompt will steal the focus or whether it will be waiting for the user in the background.&lt;/P&gt;&lt;B&gt;
&lt;P&gt;Using application manifests&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;Remember when I said that CreateProcess checks application compatibility settings and application manifests among other things? As it turns out, Windows Vista goes to great lengths to ensure that legacy 32-bit applications run properly. This involves a tremendous amount of plumbing to virtualize areas of the file system and registry that applications traditionally had full access to but no longer do under the more restrictive environment imposed by UAC. As impressive as all this virtualization is, the key is to avoid it if at all possible. It’s meant for legacy applications. If you’re writing an application today make sure to provide an application manifest which is the surest way to make sure that virtualization is not applied to your application. Indeed Microsoft is planning on removing the virtualization capabilities in a future version of Windows.&lt;/P&gt;
&lt;P&gt;The application manifest schemas have received an upgrade in Windows Vista to allow them to express the application’s requested security context. What makes it a little more complicated is that Visual C++ by default automatically generates an application manifest. This is actually a very good thing. The linker is keenly aware of the dependencies of your application and the manifest is used to define dependencies on side-by-side assemblies. Fortunately it also provides an option for merging in additional manifest files into the manifest that is ultimately embedded into the application executable. The Visual C++ project’s "Additional Manifest Files" setting is just the thing. Here’s a simple manifest file that declares a dependency on Common Controls 6.0 and specifies a desired security context:&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;
&lt;P&gt;&amp;lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&amp;gt;&lt;BR&gt;&amp;lt;assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"&amp;gt;&lt;BR&gt;&amp;lt;dependency&amp;gt;&lt;BR&gt;&amp;lt;dependentAssembly&amp;gt;&lt;BR&gt;&amp;lt;assemblyIdentity&lt;BR&gt;type="win32"&lt;BR&gt;name="Microsoft.Windows.Common-Controls"&lt;BR&gt;version="6.0.0.0"&lt;BR&gt;processorArchitecture="*"&lt;BR&gt;publicKeyToken="6595b64144ccf1df"&lt;BR&gt;language="*"&lt;BR&gt;/&amp;gt;&lt;BR&gt;&amp;lt;/dependentAssembly&amp;gt;&lt;BR&gt;&amp;lt;/dependency&amp;gt;&lt;BR&gt;&amp;lt;v3:trustInfo xmlns:v3="urn:schemas-microsoft-com:asm.v3"&amp;gt;&lt;BR&gt;&amp;lt;v3:security&amp;gt;&lt;BR&gt;&amp;lt;v3:requestedPrivileges&amp;gt;&lt;BR&gt;&amp;lt;!-- level can be "asInvoker", "highestAvailable", or "requireAdministrator" --&amp;gt;&lt;BR&gt;&amp;lt;v3:requestedExecutionLevel level="highestAvailable" /&amp;gt;&lt;BR&gt;&amp;lt;/v3:requestedPrivileges&amp;gt;&lt;BR&gt;&amp;lt;/v3:security&amp;gt;&lt;BR&gt;&amp;lt;/v3:trustInfo&amp;gt;&lt;BR&gt;&amp;lt;/assembly&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;The requested execution level can specify one of three values. "asInvoker" is the default and a new process will simply inherit the token of the parent process. "highestAvailable" indicates that the application is requesting the most unrestictive security context available to the user. For standard users this is the same as "asInvoker" but for administrators this is a demand for the unrestricted token. "requireAdministrator" indicates that a unrestricted administrator token is needed. Standard users will be prompted for administrator credentials and administrators will be prompted for consent to elevate.&lt;/P&gt;
&lt;P&gt;Remember, CreateProcess will check the manifest and fail to create the process if the requested execution level does not match that of the parent process. Only ShellExecute makes use of the Application Information service to perform elevation.&lt;/P&gt;&lt;B&gt;
&lt;P&gt;Am I already elevated?&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;Finally, if all you need is to determine whether or not you are currently elevated you can simply call the IsUserAnAdmin function. If you need more precision you can also use GetTokenInformation but in most cases that is overkill.&lt;/P&gt;&lt;B&gt;
&lt;P&gt;Conclusion&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;That’s it for UAC. I hope you’ve found this helpful. Very little of what I’ve described is currently documented. Hopefully that will change. I should add that all the samples I present typically use assertions and similar macros to check for errors. I do this to identify where error handling is necessary. If you use some of the code in your own applications, be sure to replace these macros with whatever error handling strategy you use, whether its exceptions, HRESULTs or something else.&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2155068" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/s4cd/archive/tags/Guest+Bloggers/default.aspx">Guest Bloggers</category><category domain="http://blogs.msdn.com/s4cd/archive/tags/Security+Testing/default.aspx">Security Testing</category><category domain="http://blogs.msdn.com/s4cd/archive/tags/Windows+Vista/default.aspx">Windows Vista</category></item><item><title>[Guest Blogger] Kevin Lam Thoughts on Code Scanning Tools</title><link>http://blogs.msdn.com/s4cd/archive/2006/10/01/780122.aspx</link><pubDate>Mon, 02 Oct 2006 03:22:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:780122</guid><dc:creator>dansellers</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/s4cd/comments/780122.aspx</comments><wfw:commentRss>http://blogs.msdn.com/s4cd/commentrss.aspx?PostID=780122</wfw:commentRss><description>&lt;table cellspacing="0" cellpadding="0" border="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="center"&gt;&lt;img src="http://blogs.msdn.com/photos/cdndevs/images/556626/original.aspx" border="1"&gt;&lt;/td&gt; &lt;td width="8"&gt;&lt;/td&gt; &lt;td&gt; &lt;p&gt;&lt;strong&gt;&lt;a href="http://blogs.msdn.com/kevinlam/"&gt;&lt;font size="2"&gt;Kevin Lam&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; (Redmond, Washington)&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;&lt;strong&gt;[Guest Blogger] Thoughts on Code Scanning Tools &lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Information managers, developers and testers commonly make the mistake of seeing code scanning tools as replacement for security QA processes. As a result they get a false sense of security about their software development lifecycle. Rather than using code scanning tools as a QA team replacement, think of code scanning tools an enforcement mechanism to help ensure that developers are following best practices and more importantly application security development policies. &lt;/p&gt; &lt;p&gt;Secondly tools need to be tightly integrated into a SDLC and not done as a one-off exercise. I visit a lot of customers each year to train them on developing applications securely and often ask them about their development processes and where tools fit into those processes. A common, almost consistent, response I hear is “developers run tools if they know they exist and if they remember.” Ouch. One way in which I’ve helped customers in the past is to integrated tools as a direct gate within their SDLC. Failure to complete this step affects the developer’s ability to proceed forward. As I always say, there’s a difference between what you say you do, and what you actually do. &lt;/p&gt; &lt;p&gt;Another common request from customers I get is for me suggest to them which is the ‘best’ tool. My response: potato. There is no best tool per se, but rather there is a best tool that meets their code scanning requirements. In order for a tool to be identified, I help my customers define those requirements first – otherwise they’ve just purchased or downloaded a tool that they have no idea whether or not is adding value or not. &lt;/p&gt; &lt;p&gt;Have fun scanning! &lt;/p&gt; &lt;ul&gt; &lt;li&gt;Prefast: &lt;a href="http://www.microsoft.com/whdc/devtools/ddk/default.mspx"&gt;http://www.microsoft.com/whdc/devtools/ddk/default.mspx&lt;/a&gt;  &lt;li&gt;FxCop: &lt;a href="http://www.gotdotnet.com/team/fxcop/"&gt;http://www.gotdotnet.com/team/fxcop/&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br&gt; &lt;p&gt;Kevin Lam&lt;br&gt;Senior Security Technologist &lt;br&gt;Microsoft ACE Security Services&lt;/p&gt; &lt;p&gt; &lt;table cellspacing="0" cellpadding="0" border="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top"&gt;&lt;img alt="Kevin Lam" src="http://blogs.msdn.com/photos/s4cd/images/780109/secondarythumb.aspx" border="1"&gt;&lt;/td&gt; &lt;td width="8"&gt;&lt;/td&gt; &lt;td valign="top"&gt; &lt;p&gt;&lt;font size="2"&gt;Kevin Lam is a Senior Security Strategist at Microsoft with over 7 years experience in information security. At Microsoft he is responsible for conducting security assessments (security code review, penetration testing and architectural review) for high valued targets such as XBOX Live, Windows, .NET Framework, MSN Money and critical business services. Kevin is also responsible for driving security strategy and policy changes across Microsoft company-wide and works closely with senior management. He recently published a book for Microsoft Press titled “Assessing Network Security” (ISBN: 0-7356-2033-4) that has received excellent reviews industry-wide, and has also been published in literature such as TechNet magazine. He is a frequent speaker and has participated on several expert security panel discussions. &lt;/font&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=780122" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/s4cd/archive/tags/Guest+Bloggers/default.aspx">Guest Bloggers</category><category domain="http://blogs.msdn.com/s4cd/archive/tags/Security+Testing/default.aspx">Security Testing</category></item><item><title>[Guest Blogger] Dana Epp on Security Myth:  Only Large Teams Can Write Secure Code</title><link>http://blogs.msdn.com/s4cd/archive/2006/09/19/763109.aspx</link><pubDate>Wed, 20 Sep 2006 07:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:763109</guid><dc:creator>dansellers</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/s4cd/comments/763109.aspx</comments><wfw:commentRss>http://blogs.msdn.com/s4cd/commentrss.aspx?PostID=763109</wfw:commentRss><description>&lt;TABLE cellSpacing=0 cellPadding=0 border=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD vAlign=center&gt;&lt;IMG src="http://blogs.msdn.com/photos/cdndevs/images/556626/original.aspx" border=1&gt;&lt;/TD&gt;
&lt;TD width=8&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;A href="http://silverstr.ufies.org/blog/"&gt;&lt;FONT size=2&gt;Dana Epp&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=2&gt; (Chilliwack B.C.)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;&lt;STRONG&gt;[Guest Bloggers] Security Myth: Only Large Teams Can Write Secure Code &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If you ask me, one of the biggest fallacies of writing secure code is that you can only accomplish it when you work in large teams and have bigger budgets.&amp;nbsp; There is a disconnect between the theory of secure programming, and the practice as smaller ISVs believe they simply don’t have the resources to meet the objectives required for safer software.&lt;/P&gt;
&lt;P&gt;What is interesting is that a lot of businesses are put at more risk because of this. Many buy tools from these small ISVs, since the ISV typically focuses on small verticals the big boys aren’t after.&amp;nbsp; But if the same defensive coding strategies aren’t applied, the business is at more potential risk, and typically doesn’t even know it.&lt;/P&gt;
&lt;P&gt;Recently I was brought into an environment to audit some code in business workflow that caused a major failure in a manufacturing facility by exposed privileged information publicly and shutting down a key system. They had built a web service to expose status and engineering change orders of just-in-time manufacturing for their customers. I can’t really go into much more detail, but to state that poor coding practices in how to handle failure code paths resulted in private information to get plastered on the public facing website and an exception thrown that wasn’t caught properly, causing the whole thing to tumble down. The problem was pinpointed to a 3rd party library that simply wasn’t written properly to handle tainted input from an untrusted source, which in this case was completely accidental. &lt;/P&gt;
&lt;P&gt;After discussing this with the ISV and making suggestions on how to fix it, I was presented with the argument that they can’t afford the time or tools to do this. They said they didn’t have the resources needed, and that ticked me off. I felt it was a cop out. So I decided I would do something about it.&lt;/P&gt;
&lt;P&gt;I knew I had a project coming up that I wanted to do, and felt it would be the perfect time to highlight how some front loading of design decisions and the selection of the proper tools could go a long way for a small ISV in building better software.&amp;nbsp; From mindmapping features to threat modeling functionality, I wanted to show the end to end process of building software. Well, at least how we do it around here. Every software company will have their own methods to do this.&lt;/P&gt;
&lt;P&gt;So last month I did just that. In 30 days I went from the idea of a product to the reality in 30 days. With just ONE person…. aka me. Now this wasn’t to impress anyone with my ability to write code. It was to impress upon the readers that it was indeed possible to do it with a small team. Can’t get any smaller than one guy. And I blogged and screencasted the process as I went along.&lt;/P&gt;
&lt;P&gt;If you are interested in sharing in my experience, feel free to check out the Project Anvil blog at &lt;A href="http://www.scorpionsoft.com/anvil/"&gt;http://www.scorpionsoft.com/anvil/&lt;/A&gt;.&amp;nbsp; I highly recommend you read it from the first post at the end of July and read along as I built Anvil. It was quite an experience. And the product is now being dogfooded in house in a set of betas we hope to open to the public next month.&lt;/P&gt;
&lt;P&gt;So don’t let the excuse of limited time and budgets dissuade you from writing secure code. It is possible. But like anything, you need to think objectively before hand and build it into your development process from the get go. Not sure how to do that? May I recommend that you pick up the book “&lt;A href="http://www.amazon.ca/Security-Development-Lifecycle-Michael-Howard/dp/0735622140/ref=sr_11_1/701-2744404-2215511?ie=UTF8"&gt;The Security Development Lifecycle&lt;/A&gt;” written by Michael Howard and Steve Lipner (ISBN: 0735622140)? It will go a long way to show how Microsoft does it, and will allow you to adopt what you think makes sense in your own dev process.&lt;/P&gt;
&lt;P&gt;Dana Epp&lt;BR&gt;Microsoft Security MVP &lt;/P&gt;
&lt;P&gt;
&lt;TABLE cellSpacing=0 cellPadding=0 border=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD vAlign=top&gt;&lt;IMG alt="Dana Epp" src="http://blogs.msdn.com/photos/s4cd/images/763093/secondarythumb.aspx" border=1&gt;&lt;/TD&gt;
&lt;TD width=8&gt;&lt;/TD&gt;
&lt;TD vAlign=top&gt;
&lt;P&gt;&lt;FONT size=2&gt;Dana Epp, Scorpion Software Corp’s founder and CEO, researches software security and sets the vision in the convergence of information security principles and practices with digital information asset protection for small business. As a computer security software architect, Mr. Epp has spent the last 15 years focusing on computer programming with a particular emphasis on security engineering to offer a safer computing environment for business. His latest research has been on risk-based authentication, focusing on strong two-factor authentication (2FA) for small business.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=763109" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/s4cd/archive/tags/Guest+Bloggers/default.aspx">Guest Bloggers</category></item><item><title>[Guest Blogger] Tatiana Zamachnaia on Security Paranoia Revisited: Do Not Trust Even Gurus</title><link>http://blogs.msdn.com/s4cd/archive/2006/09/13/752316.aspx</link><pubDate>Wed, 13 Sep 2006 19:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:752316</guid><dc:creator>dansellers</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/s4cd/comments/752316.aspx</comments><wfw:commentRss>http://blogs.msdn.com/s4cd/commentrss.aspx?PostID=752316</wfw:commentRss><description>&lt;TABLE cellSpacing=0 cellPadding=0 border=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD vAlign=center&gt;&lt;IMG src="http://blogs.msdn.com/photos/cdndevs/images/556626/original.aspx" border=1&gt;&lt;/TD&gt;
&lt;TD width=8&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;A href="http://csharpgal.spaces.live.com/blog/"&gt;&lt;FONT size=2&gt;Tatiana Zamachnaia&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=2&gt; (Ottawa)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;&lt;STRONG&gt;[Guest Bloggers] Security Paranoia Revisited: Do Not Trust Even Gurus&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;My latest consulting gig called for a reporting solution. I tried the GridView and other ASP.NET 2.0 controls but this solution needed a custom ASP.NET Server Control that would be extremely light weight in nature. The custom control needed to be similar to the repeater with extra features and functionality such as the ability to do paging on demand. 
&lt;P&gt;I went online to take a look at what the best of the best recommend. I run into the &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/pagercontrols.asp"&gt;Pager control&lt;/A&gt; by one of the best .NET researchers. 
&lt;P&gt;I downloaded the code and tested it and it was a good match. The license allowed incorporating it in the project and I was really happy about this little pager control. 
&lt;P&gt;Never on earth I would question author’s expertise. His prestige is high and his leadership in ASP.NET is unquestionable. I’ve never seen any article from him that wouldn’t offer valuable stuff. I am just raving about his work, to everybody: my students, .NET friends, developers. However, when I test,&lt;STRONG&gt; &lt;/STRONG&gt;I test. After I was satisfied with the functionality, I wanted to break the thing. The very first thing I did is I used my friend &lt;A href="http://www.pluralsight.com/tools.aspx"&gt;View State Decoder by Fritz Onion&lt;/A&gt;. 
&lt;P&gt;Lo and behold! I could see the connection string staring at me (which of course I suspected when I looked at the code, but again, I though that this couldn't happen to the guru’s component). 
&lt;P&gt;Unfortunately, I thought that there would be issues with the original design if I tried to fix it (of course, the first thing I thought of is to encrypt the connection string). 
&lt;P&gt;This issue was discovered in the beginning of January and sent to the Microsoft. I got the response that it was resent and things will be taken care of. 
&lt;P&gt;It looks like an article is still dated and has not been updated. Or at least from what I can see. 
&lt;P&gt;My concern is that many developers might be using this control without questioning security. Again, prestige of the author of the control is extremely high, and I really admire what he does. So does everybody. I am afraid developers would just blindly grab the control as it is. 
&lt;P&gt;During my security seminar in Ottawa I showed .NET Developers a view state piece by viewing the page source. I sounded enthusiastic when I was commenting on the garbagey look of it. So, when I asked whether it is encrypted, most of the people said: yes. So, you get idea about how many people think they are safe. (For reference: it is encoded, but not encrypted). 
&lt;P&gt;&lt;STRONG&gt;Morale: Do Not Trust Anything (Or Anybody) Unless Proved Harmless&lt;/STRONG&gt; 
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;
&lt;P&gt;
&lt;TABLE cellSpacing=0 cellPadding=0 border=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD vAlign=top&gt;&lt;IMG alt="Tatiana Zamachnaia" src="http://blogs.msdn.com/photos/s4cd/images/752258/secondarythumb.aspx" border=1&gt;&lt;/TD&gt;
&lt;TD width=8&gt;&lt;/TD&gt;
&lt;TD vAlign=top&gt;
&lt;P&gt;&lt;FONT size=2&gt;Tatiana Zamachnaia is an independent consultant who specializes in ASP.NET architecture and has a passion for ASP.NET security.&amp;nbsp; She has been working with .NET since early beta and became interested in ASP.NET security in late 2003. Tatiana is a .NET evangelist and has mentored .NET developers and taught .NET in academic settings. Tatiana aspires to public speaking on the subject of security and had started regionally by making presentations in Ottawa area.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=752316" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/s4cd/archive/tags/Guest+Bloggers/default.aspx">Guest Bloggers</category></item></channel></rss>