<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Parallel Interface &#187; Windows</title>
	<atom:link href="http://www.paralint.com/blog/category/windows/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.paralint.com/blog</link>
	<description>Programming security in Java and C++, one line at a time</description>
	<lastBuildDate>Thu, 26 Aug 2010 17:24:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Porting a custom Gina to a Credential provider</title>
		<link>http://www.paralint.com/blog/2009/02/24/porting-a-custom-gina-to-a-credential-provider/</link>
		<comments>http://www.paralint.com/blog/2009/02/24/porting-a-custom-gina-to-a-credential-provider/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 02:27:36 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Other technical]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/?p=108</guid>
		<description><![CDATA[Making a replacement Gina behave like a Credential Provider (not the other way around) looks like the ticket to have a single source solution to a Gina and Credential Provider.]]></description>
			<content:encoded><![CDATA[<p>I am still amazed by the popularity of <a title="Any user can unlock now with this replacement Gina" href="/projects/aucun/">my replacement Gina</a> (it allows any user to unlock). Most users are quite happy using it with Windows XP and Server 2003, but I do get the occasionnal request for a Vista port. I am looking forward to doing it, but there are important desing changes that I must work with. I think I found a way to have a single source solution Gina and Credential Provider, with a clean architecture on any Windows version.</p>
<p><span id="more-108"></span>Credential Providers cannot make an authentication decision. They only collect credentials. The approach I took in &#8220;Aucun&#8221; is that the Gina actually makes the authentication decision. That will not work under the new Credential provider architecture.</p>
<p>When I started looking to port my Gina to a Credential Provider, I first though of saving the initial credentials (when the first user logs on), then check any other user&#8217;s credential in my own Credential Provider, and if all is good, replay the initial credentials.</p>
<p>That bothered on many grounds :</p>
<ul>
<li>There will be a unlock event logged to the initial user, although that user never unlocked the workstation</li>
<li>I don&#8217;t like saving passwords, even to encrypted memory</li>
<li>That architecture didn&#8217;t look like something that would last</li>
</ul>
<p>Looking deeper into the Credential Provider interface, I saw that there is one decision a Credential Provider <span style="text-decoration: underline;">can</span> make. It can select what Authentication Package will honor the logon request (or unlock request, in my case). That takes place in my (your) <a href="http://msdn.microsoft.com/en-us/library/bb776026(VS.85).aspx">ICredentialProviderCredential::GetSerialisation</a>, by setting the ulAuthenticationPackage field of the <a href="http://msdn.microsoft.com/en-us/library/bb773242(VS.85).aspx">CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION</a> structure.</p>
<p>So I believe the right way of doing this is to have two components :</p>
<ol>
<li>An authentication package that implements the unlock policy (any user can unlock, depending on group membership).</li>
<li>A credential provider that collects credentials (and while you&#8217;re at it, the session you want to unlock) and instruct winlogon to forward them the &#8220;unlock&#8221; authentication package.</li>
</ol>
<p>That architecture fixes all three points above. And as a bonus, I can greatly simplify my existing Gina by merely collecting the credentials and forward them to the same authentication package. No need to hook dialog procedures and sending magic, reversed engineered constants to winlogon. In short, instead of making the Credential Provider look like a Gina, I make the Gina behave like a Credential Provider.</p>
<p>Authentication packages are the same under Vista and XP, that&#8217;s a good thing. But to <a href="http://blogs.msdn.com/alejacma/archive/2007/11/13/how-to-debug-lsass-exe-process.aspx">debug them</a>, you need the scary kernel remote debugging tools. You also need to reboot every time you mess up. But I have a working authentication package from CVS NT code source, and another called <a href="http://www.cse.unsw.edu.au/~matthewc/">YPAuth</a> (YP means yellow pages, the <a href="http://en.wikipedia.org/wiki/Network_Information_Service">old name of NIS</a>). None of them support the unlock scenario, though&#8230;</p>
<p>Stay tuned !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2009/02/24/porting-a-custom-gina-to-a-credential-provider/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Stop internal drive from showing up in &quot;Safely remove hardware&quot;</title>
		<link>http://www.paralint.com/blog/2008/11/13/stop-internal-drive-showing-up-in-safely-remove-hardware/</link>
		<comments>http://www.paralint.com/blog/2008/11/13/stop-internal-drive-showing-up-in-safely-remove-hardware/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 04:27:19 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Other technical]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/?p=82</guid>
		<description><![CDATA[Like many of you, I had a drive that showed up in the &#8220;Safely remove hardware&#8221; tray icon, and was unable to remove it. The trick is to subtract 4 from the Capabilities in the registry. Not easy, but it can be done. The only thing is that it keeps coming back after every boot [...]]]></description>
			<content:encoded><![CDATA[<p>Like many of you, I had a drive that showed up in the &#8220;Safely remove hardware&#8221; tray icon, and was unable to remove it.</p>
<p>The trick is to subtract 4 from the Capabilities in the registry. Not easy, but it can be done. The only thing is that it keeps coming back after every boot ! And it looks like the value cannot be edited under Vista. Here is how to fix it for good.</p>
<p><span id="more-82"></span></p>
<h3>What has to be done (but doesn&#8217;t work)</h3>
<p>Find the drive that shows up in the safely remove hardware icon in your registry. It will be somewhere under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IDE\. My DVD drive was here :</p>
<pre class="generic:nogutter:nocontrols">HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IDE\CdRomHL-DT-ST_DVDRAM_GMA4082Nj_______________PM01____</pre>
<p>There is a numerical an alphanumerical key under that with a DWORD Capabilities value.</p>
<p><img src="http://www.paralint.com/blog/wp-content/uploads/2008/11/image.png" alt="image" width="788" height="318" /></p>
<p>It is a bit field. The bit 0010 (4 in decimal) is the REMOVABLE bit. Clear it by subtracting 4 from the value you have. The value I had was 6, so now I am down to 2.</p>
<p>If you try to do that, you will get an access denied. That&#8217;s ok, we will get around that. For now, right click on the key name and copy it (the key named 5&amp;3392c8c4&amp;0&amp;0.0.0 in my example).</p>
<h3>Same idea, that works manually under Vista</h3>
<p>You need to have the TCB privileged enabled to modify that registry key. Running regedit as an administrator (or elevated, if you have UAC) will not work. You can fix the value with this command line :</p>
<pre class="generic:nogutter:nocontrols">psexec -s reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IDE\CdRomHL-DT-ST_DVDRAM_GMA4082Nj_______________PM01____\5&amp;3392c8c4&amp;0&amp;0.0.0" /v Capabilities /t REG_DWORD /d 2 /f</pre>
<p>You will have to replace the key name with what you found in <span style="text-decoration: underline;">your</span> registry. Running psexec -r regedit might work, but who wants to do that every time the computer boots ?</p>
<h3>Permanent fix</h3>
<p>I hardly ever run as an administrator, so putting the above command in a script was out of the question. The solution was to create a Task using Windows Task Scheduler. I set it to run at startup, under the SYSTEM account. Don&#8217;t forget the /f (force) flag, or else the job will appear to hang, waiting a confirmation from you.</p>
<p>Create a new task. In the &#8220;General&#8221; tab, click Change User or Group and enter &#8220;SYSTEM&#8221; . Trigger on startup and enter the same command as above, but without psexec -s. Your task is running reg.exe, with everything right of that (in the command line, earlier) as optional arguments.</p>
<p><img src="http://www.paralint.com/blog/wp-content/uploads/2008/11/image1.png" alt="image" width="419" height="480" /></p>
<p>Good luck and HTH !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2008/11/13/stop-internal-drive-showing-up-in-safely-remove-hardware/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Step by step guide to create your own MSCASH hashes</title>
		<link>http://www.paralint.com/blog/2008/07/06/step-by-step-guide-to-create-your-own-mscash-hashes/</link>
		<comments>http://www.paralint.com/blog/2008/07/06/step-by-step-guide-to-create-your-own-mscash-hashes/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 04:49:37 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/2008/07/06/step-by-step-guide-to-create-your-own-mscash-hashes/</guid>
		<description><![CDATA[I wanted to test the relative strength of a password policy. I wanted to run a password cracking tool over different passwords, from a dictionary based password (like Banana42) to a random one (generated with Password Safe). Creating users setting passwords and running different password extraction tools was a lot of trouble. I found a [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to test the relative strength of a password policy. I wanted to run a password cracking tool over different passwords, from a dictionary based password (like Banana42) to a random one (generated with <a href="http://passwordsafe.sourceforge.net/" target="_blank">Password Safe</a>). Creating users setting passwords and running different password extraction tools was a lot of trouble.</p>
<p>I found a detailed <a href="http://www.securiteam.com/tools/5JP0I2KFPA.html" target="_blank">explanation of the MSCASH format</a>. Here is how you make your own MSCASH hashes to do close to reality benchmarks of your favourite password cracking tool.</p>
<p><span id="more-54"></span></p>
<p>The format is MD4(MD4(password) + username). password and username are in Unicode. In the explanation linked above, we have the classical &quot;user&quot; and &quot;password&quot; combination. Using notepad, type your password. Save the file using Unicode format. The first two bytes of the file will be FF and EF, a flag called the byte order mark (BOM). Delete them using <a href="http://www.mh-nexus.de/hxd/" target="_blank">an hexadecimal editor</a>. It should look like this :</p>
<pre class="generic:nogutter:nocontrols" name="code">Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000  70 00 61 00 73 00 73 00 77 00 6F 00 72 00 64 00  p.a.s.s.w.o.r.d.</pre>
<p>Now calculate the first hash with openssl, with a binary output :</p>
</p>
<pre class="generic:nogutter:nocontrols" name="code">openssl dgst -md4 -binary password.unicode.txt &gt; md4.password</pre>
</p>
<p>Type and save your user name in Unicode format, remove the BOM, and concatenate the Unicode user name to the first hash.</p>
</p>
<pre class="generic:nogutter:nocontrols" name="code">copy /b md4.password + user.unicode.txt md4.password.user</pre>
</p>
<p>The file should look like this (the first 16 bytes is the md4 hash of the password) :</p>
<pre class="generic:nogutter:nocontrols" name="code">Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000  88 46 F7 EA EE 8F B1 17 AD 06 BD D8 30 B7 58 6C  &#710;F&#247;&#234;&#238;.&#177;...&#189;&#216;0&#183;Xl
00000010  75 00 73 00 65 00 72 00                          u.s.e.r.</pre>
<p>Now just hash that last file, again with openssl :</p>
</p>
<pre class="generic:nogutter:nocontrols" name="code">openssl dgst -md4 md4.password.user
MD4(md4.password.user)= 2d9f0b052932ad18b87f315641921cda</pre>
</p>
<p>You can now use that MSCASH hash for your benchmarks. I hope you find it usefull. I might write a program in C to automate this, If I see good traffic on this post. Spread the word !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2008/07/06/step-by-step-guide-to-create-your-own-mscash-hashes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Notifu updated, now with Vista support</title>
		<link>http://www.paralint.com/blog/2008/02/04/notifu-updated-now-with-vista-support/</link>
		<comments>http://www.paralint.com/blog/2008/02/04/notifu-updated-now-with-vista-support/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 21:23:32 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Updates]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/2008/02/04/notifu-updated-now-with-vista-support/</guid>
		<description><![CDATA[Here is just a little update to my Notifu utility. It is a drop-in replacement (no new command-line switches) that features Vista Home Premium and Vista Business support (same binary works on XP and Vista) Better error handling on platforms that don&#8217;t support IUserNotification Option to specify pop-up delay in seconds (/d 5 or /d [...]]]></description>
			<content:encoded><![CDATA[<p>Here is just a little update to my Notifu utility. It is a drop-in replacement (no new command-line switches) that features</p>
<ul>
<li>Vista Home Premium and Vista Business support (same binary works on XP and Vista)</li>
<li>Better error handling on platforms that don&#8217;t support IUserNotification</li>
<li>Option to specify pop-up delay in seconds (/d 5 or /d 5000 will give you 5 seconds)</li>
</ul>
<p>I updated the <a href="/projects/notifu/" title="Yellow pop-up ballon utility">main project page</a>. There are a couple of typos and the email link is gone. I will fix that sometimes this week. Click on the bitmap here or on the project page to download.</p>
<p><img src="/projects/notifu/screen_shot_02.png" alt="IUserNotification (Notifu) screen shot on Vista" align="middle" /></p>
<p>Enjoy !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2008/02/04/notifu-updated-now-with-vista-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remplacement GINA now allows force logoff, administrator exclusion</title>
		<link>http://www.paralint.com/blog/2008/02/04/remplacement-gina-now-allows-force-logoff-administrator-exclusion/</link>
		<comments>http://www.paralint.com/blog/2008/02/04/remplacement-gina-now-allows-force-logoff-administrator-exclusion/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 16:50:39 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Updates]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/2008/02/04/remplacement-gina-now-allows-force-logoff-administrator-exclusion/</guid>
		<description><![CDATA[I was a little overwhelmed by the reaction to my custom GINA. The good thing about it is that it motivated me to put a better version out that addresses all the comments I had so far, namely : Allow force log off without being a member of the administrator group Allow an arbitrary group [...]]]></description>
			<content:encoded><![CDATA[<p>I was a little overwhelmed by the reaction to my custom GINA. The good thing about it is that it motivated me to put a better version out that addresses all the comments I had so far, namely :</p>
<ul>
<li>Allow force log off without being a member of the administrator group</li>
<li>Allow an arbitrary group to be excluded from this GINA unlock policy</li>
<li>Show a notice that a custom GINA is in place</li>
</ul>
<p>I also put up a <a href="/projects/aucun/" title="Permanent home page for my replacement GINA DLL project">permanent page for the project</a>. It has better documentation and fancy graphics. Enjoy !</p>
<p><img src="/projects/aucun/architecture.png" alt="Replament GINA hooks Winlogon and MSGINA" align="middle" height="270" width="588" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2008/02/04/remplacement-gina-now-allows-force-logoff-administrator-exclusion/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unlock any user&#8217;s session without losing data or killing processes</title>
		<link>http://www.paralint.com/blog/2008/01/05/unlock-any-users-session-without-losing-data-or-killing-processes/</link>
		<comments>http://www.paralint.com/blog/2008/01/05/unlock-any-users-session-without-losing-data-or-killing-processes/#comments</comments>
		<pubDate>Sat, 05 Jan 2008 13:58:50 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/2008/01/05/unlock-any-users-session-without-losing-data-or-killing-processes/</guid>
		<description><![CDATA[UPDATED Feb. 2nd 2008 : There is an enhanced version out, with better code, features and documentation. A friend of mine wanted a special group of users to be able to unlock a workstation without losing any data. Putting those uses in the administrator groups was not a solution, because the default behaviour of Windows [...]]]></description>
			<content:encoded><![CDATA[<p class="important">UPDATED Feb. 2nd 2008 : <a href="/projects/aucun/">There is an enhanced version</a> out, with better code, features and documentation.</p>
<p>A friend of mine wanted a special group of users to be able to unlock a workstation without losing any data. Putting those uses in the administrator groups was not a solution, because the default behaviour of Windows was to close or terminate every process and give the administrator a brand new session. Fast user switching added some tricks, but in the end there was no way to recover an open document with modifications in it from a locked Windows workstation.</p>
<p>The <a href="/projects/aucun/">project has its own page</a> now. If you are a computer historian, read on for the original first release.<br />
<!-- more --></p>
<p><span id="more-37"></span>He asked me if I could write a screen saver to do this, but the answer was a little deeper under the hood, and a lot more fun. I wrote a replacement Graphical Identification and Authentication DLL (GINA DLL) that hooks the standard Microsoft Windows Gina DLL of Windows XP and Windows Server 2003. It also supports Terminal services sessions. It allows you grant members of a group (any group) to unlock any user&#8217;s session. No need to be an administrator. Any user can unlock now (Aucun).</p>
<p class="important">Microsoft replaced GINA DLLs with credentials providers (ICredentialProvider), somewhat like the Solaris pluggable authentication modules PAM. This Gina DLL will never work in Vista, by design.</p>
<p>Turns out it is pretty easy. You can <a title="Aucun.DLL version 1.2" href="/projects/aucun/">get the source code and a compiled binary here</a>. I recommend that you don&#8217;t trust me with your password and work with the source. Anonymous Subversion access with this command</p>
<pre>svn co <a href="http://src.paralint.com/aucun/trunk">http://src.paralint.com/aucun/trunk</a> aucun</pre>
<p><!--more--></p>
<p>I started with the Gina Hook sample from the SDK, and added support for terminal services. Then I stripped away all the unnecessary hooks and updated the dialog detection code. A few registry calls later and some basic group membership checking later was all that was needed.</p>
<p>To allow any user from any given group to unlock a Windows session, you have to:</p>
<ol>
<li>Hook every function of the regular Gina, msgina.dll</li>
<li>Export every function yourself, forwarding them all to msgina.dll as is except for WlxNegotiate and WlxInitialize</li>
<li>In WlxInitialize, hook the Windows provided function WlxDialogBoxParam (so msgina.dll will call your DLL when it creates a dialog box)</li>
<li>In your version of WlxDialogBoxParam, let everything go through except requests to create the unlock dialog</li>
<li>Hook the DLGPROC and wait for WM_COMMAND with wParam == IDOK</li>
<li>Check the user&#8217;s password (LogonUser with LOGON32_LOGON_UNLOCK)
<ul>
<li>If it doesn&#8217;t match, let the call go through the regular GINA</li>
<li>If it matches, and the user is part of the group you want to be able to unlock (CheckTokenMembership), call EndDialog with IDOK</li>
<li>It it matches and the user is not in the group you want to be able to unlock, let the regular GINA handle it</li>
</ul>
</li>
</ol>
<p>That&#8217;s about it. The third bullet of item 6 is actually what will happen most of time. The same user that locked its station comes back and enters a password that matches, but that regular user is not part of the unlock group. MSGINA.DLL handles it and unlock the session as usual. (UPDATED january 8th 2008 -&gt;) If you audit logon events, succesfull or failed, they will be logged under the name of the person unlocking the session, not the original user. It is a deterrent measure only, it will not give you non-repudiation of actions made after the session was unlocked.</p>
<p>I insists there is no need for the users to be members of the administrators group for this to work. With my implementation, you merely set a registry key with the name of the group you want to use. Add any user(s) or group(s) to this group.</p>
<pre>HKEY_LOCAL_MACHINE\SOFTWARE\Paralint.com\Aucun"GroupName"="paralint.com\DG_SESSION_UNLOCKERS"</pre>
<p>I might add a blacklist feature, so that members of the the administrative group can never be unlocked. It is not hard to do. If I see interest in this project, I write it happen.</p>
<p>The code is all plain old, good old C. Function pointers, hooked procedures. All the fun stuff .Net hides from you <img src='http://www.paralint.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Remember: Gina were introduced in Windows NT 3.51, some 15 years ago. And yes, I was already a Windows programmer back then&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2008/01/05/unlock-any-users-session-without-losing-data-or-killing-processes/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Denial of service on Vista using Resource Monitor</title>
		<link>http://www.paralint.com/blog/2008/01/05/denial-of-service-on-vista-using-resource-monitor/</link>
		<comments>http://www.paralint.com/blog/2008/01/05/denial-of-service-on-vista-using-resource-monitor/#comments</comments>
		<pubDate>Sat, 05 Jan 2008 13:57:39 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/2008/01/05/denial-of-service-on-vista-using-resource-monitor/</guid>
		<description><![CDATA[Microsoft wants you to run with lower privileges. They went out of their way in Windows Vista. You are a member of the Administrative group in Vista, but you the group is for deny only in your token. When you elevate, you get a new token without that deny group. Just like an administrator removing [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft wants you to run with lower privileges. They went out of their way in Windows Vista. You are a member of the Administrative group in Vista, but you the group is for deny only in your token. When you elevate, you get a new token without that deny group. Just like an administrator removing its newbie mask.</p>
<p>But I don&#8217;t run Vista like that: I run it the hard way. I am a regular user, and in the rare cases I need it, I switch over to another account that has administrative privileges. I disabled user account control (UAC) alltogether.</p>
<p>If you&#8217;re like me, try this 2 step trick to render you Vista slow or completely DOS (denial of service) depending on CPU and memory.</p>
<p class="Important">Save you work before you try this, you might have to reboot&#8230;</p>
<p>Bring up the task manager with CTRL-SHIFT-ESC. Click the &#8220;Resource Monitor&#8221;. Watch your screen flicker as your CPU goes up and your battery goes down&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2008/01/05/denial-of-service-on-vista-using-resource-monitor/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Getting the username from a desktop handle (HDESK)</title>
		<link>http://www.paralint.com/blog/2007/12/19/getting-the-username-from-a-desktop-handle-hdesk/</link>
		<comments>http://www.paralint.com/blog/2007/12/19/getting-the-username-from-a-desktop-handle-hdesk/#comments</comments>
		<pubDate>Wed, 19 Dec 2007 19:35:20 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/2007/12/19/getting-the-username-from-a-desktop-handle-hdesk/</guid>
		<description><![CDATA[I was struggling with an strange error message, trying to retrieve a username from a desktop handle (HDESK). The Windows function LookupAccountName would always return error code 0&#215;534 (that&#8217;s 1332 in decimal). Looking it up with GetLastError gave this : No mapping between account names and security IDs was done It would have happened with [...]]]></description>
			<content:encoded><![CDATA[<p>I was struggling with an strange error message, trying to retrieve a username from a desktop handle (HDESK). The Windows function LookupAccountName would always return error code 0&#215;534 (that&#8217;s 1332 in decimal). Looking it up with GetLastError gave this :</p>
<p>No mapping between account names and security IDs was done</p>
<p>It would have happened with a Windows Station handle (HWINSTA) also. It turns out there is a sensible and documented reason for that. But since I had to found out the hard (as in fun) way, I am posting it here.</p>
<p>If you are familiar with the ways SID (security identifiers) are handed out when you logon, here is the reason straight up :</p>
<p class="important">The SID associated with desktops and window stations is not the SID of the logged on user, but the logon SID, a SID generated at logon time that identifies exactly and only this logon session. No account name is mapped to this transient SID, hence the error message.</p>
<p>Still confused ? Read on.</p>
<p><span id="more-33"></span></p>
<h2>Security descriptor crash course</h2>
<p>Consider this : you open a remote desktop connection (terminal server) to a server and log in. You have a logon session on that machine. Keeping that session alive, you walk up to the server and log-in again, interactively. You now have 2 logon sessions on that machine. How does windows prevents one session from interfering with the other?</p>
<p>Well, security is always about assigning security descriptor (SECURITY_DESCRIPTOR) to things. A security descriptor is a discretionary access control list (DACL) made up of access control entries. Each ACE is a combination of allowed or denied access rights for a SID. A System Access Control list (SACL) that controls auditing and a few flags are also present, but it doesn&#8217;t matter to us now. So each desktop and window station (and any other object for that matter) are assigned something like this :</p>
<p><img alt="SECURITY_DESCRIPTOR" src="http://www.paralint.com/blog/wp-content/uploads/2007/12/sd.png" /></p>
<p>So we have a security descriptor, what will we use to authenticate against ? Our process or thread token, of course.</p>
<h2>You are your logon session (any of them)</h2>
<p>A token is like a conceptual pointer to a logon session. That logon session contains a unique logon identifier (LUID), the users SID and another SID, generated on the fly, that uniquely identifies a particular logon session. Here is a schematic view of the logon sessions and their SID:</p>
<p><img alt="Two logon session gives two logon SID" src="http://www.paralint.com/blog/wp-content/uploads/2007/12/logon_session.png" /></p>
<p>You can see that the user SID is the same in the two logon sessions, but the Logon SID is different. Only the User SID is mapped to the principal (Alice in this example).</p>
<p>Keith Brown has a tool that lets <a href="http://www.pluralsight.com/tools.aspx" target="_blank">view and change the security descriptor of the current window station and desktop</a>. Running this tool (in the logon session with logon SID S-1-5-5-0-218443) shows this:</p>
<p><img alt="Running winstadacl to show the user SID and logon SID" src="http://www.paralint.com/blog/wp-content/uploads/2007/12/winstadacl.png" /></p>
<p>To prevent one window station from interfering with the other, Windows uses the granularity of the security API to its advantage (who wouldn&#8217;t?). Processes and threads from each logon have a token pointing back to the logon session they were started from. The desktop and window station are assigned a security descriptor that doesn&#8217;t grant or deny any rights to the users SID. Rights are granted to the logon SID.</p>
<h2>What about my 0&#215;534 error code?</h2>
<p>For a reason I don&#8217;t really understand, the logon SID is not granted any name. When you crawl you way from a HDESK or (HWINSTA) handle, using GetUserObjectInformation and LookupAccountName, you will get error 0&#215;534. It says &quot;No mapping between account names and security IDs was done&quot; because there never was a mapping of the logon SID with a name to begin with! <img src='http://www.paralint.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2007/12/19/getting-the-username-from-a-desktop-handle-hdesk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LoadLibrary fails when impersonating</title>
		<link>http://www.paralint.com/blog/2007/06/19/loadlibrary-fails-when-impersonating/</link>
		<comments>http://www.paralint.com/blog/2007/06/19/loadlibrary-fails-when-impersonating/#comments</comments>
		<pubDate>Tue, 19 Jun 2007 17:28:46 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/2007/06/19/loadlibrary-fails-when-impersonating/</guid>
		<description><![CDATA[I was playing around with SSPI, the Security Support Provider Interface. I stumbled across a behavior that I cannot explain : you cannot call LoadLibrary when you are impersonating. If you check you program with SysInternals (now Microsoft&#8217;s) Process Monitor, you&#8217;ll find an error saying&#8221;Bad Impersonation&#8221;. LoadLibrary returns NULL and a call to GetLastError() says [...]]]></description>
			<content:encoded><![CDATA[<p>I was playing around with SSPI, the Security Support Provider Interface. I stumbled across a behavior that I cannot explain : you cannot call LoadLibrary when you are impersonating.</p>
<p>If you check you program with SysInternals (now Microsoft&#8217;s) <a href="http://www.microsoft.com/technet/sysinternals/ProcessesAndThreads/processmonitor.mspx" title="ProcessMonitor download page">Process Monitor</a>, you&#8217;ll find an error saying&#8221;Bad Impersonation&#8221;.</p>
<p>LoadLibrary returns NULL and a call to GetLastError() says &#8220;Either a required impersonation level was not provided, or the provided impersonation level is invalid&#8221;.</p>
<p>If you just specify a filename, LoadLibrary will look in the current directory only. If supply a full path to the DLL, LoadLibrary will find it but the CreateFile will fail with Bad Impersonation.</p>
<p>I am still baffled by this behavior. I will keep looking into it. Meanwhile, here is a <a href="http://src.paralint.com/spikes/badimpersonation/BadImpersonation/BadImpersonation.cpp" title="BadImpernation.cpp shows LoadLibrary failing">simple program that reproduces the problem</a>.</p>
<p><a href="http://src.paralint.com/spikes/badimpersonation/BadImpersonation/BadImpersonation.cpp" title="BadImpernation.cpp shows LoadLibrary failing" class="download">BadImpersonation.cpp</a></p>
<p>You can get the full project using anonymous subversion :</p>
<p><code>svn co <a href="http://src.paralint.com/spikes/badimpersonation">http://src.paralint.com/spikes/badimpersonation</a> BadImpersonation</code></p>
<p>Good luck !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2007/06/19/loadlibrary-fails-when-impersonating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
