<?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; Security</title>
	<atom:link href="http://www.paralint.com/blog/category/security/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>Ne jouez pas avec un CAPTCHA sans la surveillance d&#8217;un expert</title>
		<link>http://www.paralint.com/blog/2009/02/06/ne-jouez-pas-avec-un-captcha-sans-la-surveillance-dun-expert/</link>
		<comments>http://www.paralint.com/blog/2009/02/06/ne-jouez-pas-avec-un-captcha-sans-la-surveillance-dun-expert/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 20:22:52 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[En français]]></category>
		<category><![CDATA[Other technical]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/?p=91</guid>
		<description><![CDATA[Je suis tombé sur cette implémentation d&#8217;un CAPTCHA. Je déteste les CAPTCHA. C&#8217;est comme de la mauvaise crypto. Fondamentalement, le CAPTCHA ne fonctionne pas. La tâche d&#8217;analyse (le test de Turing) est complexe juste parce que personne ne s&#8217;est encore donné la peine d&#8217;écrire le code pour réussir. C&#8217;est aussi vrai pour la crypto classique, [...]]]></description>
			<content:encoded><![CDATA[<p>Je suis tombé sur cette implémentation d&#8217;un CAPTCHA.</p>
<div class="mceTemp mceIEcenter">
<dl id="attachment_92" class="wp-caption aligncenter" style="width: 403px;">
<dt class="wp-caption-dt"><img class="size-full wp-image-92" title="Lousy captcha" src="http://www.paralint.com/blog/wp-content/uploads/2009/02/captcha.jpg" alt="Must select 3 hamburgers in this lousy captcha " width="393" height="265" /></dt>
</dl>
</div>
<p>Je déteste les CAPTCHA. C&#8217;est comme de la mauvaise crypto.</p>
<p>Fondamentalement, le CAPTCHA ne fonctionne pas. La tâche d&#8217;analyse (le test de Turing) est complexe juste parce que personne ne s&#8217;est encore donné la peine d&#8217;écrire le code pour réussir. C&#8217;est aussi vrai pour la crypto classique, mais ces mathématiques sont soumises à des études formelles et continues. On sait à quoi s&#8217;en tenir : avec de la bonne crypto, on déplace le problème ailleurs (la gestion de clé, souvent). En intelligence artificielle, la segmentation est difficile, mais l&#8217;ordre de grandeur d&#8217;effort est à la portée des botnets actuels.</p>
<p><span id="more-91"></span>Trouver un éléphant ou un burger est faisable. Google ne trouve-t-il pas déjà les visages sur les photos ?  La faiblesse de ce CAPTCHA, en particulier, c&#8217;est l&#8217;apprentissage (en supposant que l&#8217;implémentation est bonne). La mémoire d&#8217;un ordinateur est infinie. Il est possible d&#8217;avoir la base de données complète des images en relativement peu de temps. D&#8217;identifier ce qui s&#8217;y trouve et automatiser le tout. Bien sûr, il ne faut pas que l&#8217;image soit déjà dans l&#8217;index Google&#8230; Autre faiblesse, on sait toujours d&#8217;avance combien il y a de (chat-chien-burger-bébé-éléphant). Ça aide à prendre une décision automatisée.</p>
<p>Les attaques sur les CAPTCHA de Microsoft et Google a montré que l&#8217;analyse de CAPTCHA n&#8217;a pas un taux de succès de 100 %. Un petit pourcentage, multiplié par un bon botnet, ça fait beaucoup de captcha résolus!</p>
<p>On n&#8217;a qu&#8217;à ajouter de nouvelles images, non? Oui, mais combien coûtera toute cette mécanique, en développement mais surtout en entretien? Quel est le coût réel d&#8217;une utilisation abusive du service? Combien coutera l&#8217;analyse préalable des images, le classement en mots clés, etc.? On m&#8217;a demandé de compter 3 bébés, mais une image en contenait deux, faut-il filtrer ces images-là aussi?</p>
<p>Mais surtout, l&#8217;aspect économique de la sécurité est complètement évacué. Ce CAPTCHA est sur une page qui demande un numéro de carte de crédit, mais pas sur la page qui permet d&#8217;utiliser le service une seule fois, gratuitement.  Et c&#8217;est sans compter qu&#8217;une <a href="http://decapcher.com">ferme de Turing</a> coute 8 $ pour 4000 CAPTCHA résolus. Combien coûte un client légitime dégoûté par toutes ces précautions?</p>
<p>Ce CAPTCHA est l&#8217;œuvre d&#8217;amateurs. Et j&#8217;ai même pas regardé l&#8217;implémentation des cookies, session, etc.  En bref, implémenter correctement ce CAPTCHA par image coûte beaucoup trop cher.</p>
<p>Si j&#8217;étais forcé d&#8217;utiliser un CAPTCHA, j&#8217;utiliserais un simple encodage javascript des champs du formulaire, variable dans le temps, peut-être avec un <a href="http://hashcash.org">hashcash</a> en javascript aussi, et vraiment accolé au pied du mur, j&#8217;essaierais <a href="http://recaptcha.net">recaptcha</a>. L&#8217;idée est de transformer tes utilisateurs en ta propre ferme de Turing. Pas fou!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2009/02/06/ne-jouez-pas-avec-un-captcha-sans-la-surveillance-dun-expert/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Full disk encryption single sing-on and secure backup</title>
		<link>http://www.paralint.com/blog/2008/11/06/full-disk-encryption-single-sing-on-and-secure-backup/</link>
		<comments>http://www.paralint.com/blog/2008/11/06/full-disk-encryption-single-sing-on-and-secure-backup/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 21:22:19 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/?p=67</guid>
		<description><![CDATA[I have a been a TrueCrypt user since version 4.0. I used to have an half-baked solution of TrueCrypt, EFS with SYSKEY option 2 (password). When full disk encryption was introduced, I finally got a laptop encryption scheme that I like. It features : Strong cryptography Thank TrueCrypt for 256 bits AES in XTS mode. [...]]]></description>
			<content:encoded><![CDATA[<div>I have a been a <a href="http://www.truecrypt.org/" target="_blank">TrueCrypt</a> user since version 4.0. I used to have an half-baked solution of TrueCrypt, EFS with SYSKEY option 2 (password). When full disk encryption was introduced, I finally got a laptop encryption scheme that I like. It features :</p>
<ul>
<li> <strong>Strong cryptography</strong><br />
Thank TrueCrypt for 256 bits AES in XTS mode. I think 256 bits is overkill, but 128 is not offered. I don&#8217;t see any performance hit on my modest, stock Fujitsu E8210 laptop.</li>
<li> <strong>Need to know (reduced data exposure)</strong><br />
Data is not available in clear text when I don&#8217;t need it. In other words, when I work, I have my files, when I play they stay encrypted</li>
<li> <strong>Easy encrypted backup</strong><br />
My backups are merely a copy to a file server.</li>
<li> <strong>Single sign-on to any encrypted volume</strong><br />
The pre-boot authentication password (or pass phrase, your call) is the only one you&#8217;ll ever have to enter, and yet, that password is never stored anywhere. Not even in encrypted memory. It&#8217;s only in your head.</li>
<li> <strong>Supports encrypted USB drive</strong><br />
USB drives get the same single sign-on, need to know and backup features. Doesn&#8217;t matter wheter you use file based or whole volume, although using a file based container allows you to store regular data on any computer, instead of carrying to drives.</li>
<li><strong>Platform independent</strong><br />
Works on all platforms that TrueCrypt supports</li>
</ul>
</div>
<div>All that out of the box. Well&#8230; actually there is no box, it is all open source !</div>
<div><span id="more-67"></span></div>
<p>It does not feature, but could be extended to :</p>
<ul>
<li> Plausible deniability</li>
<li> Two factor authentication to encrypted files (TrueCrypt version 6.1 required)</li>
<li>Step-up authentication to encrypted files</li>
<li>Operating system logon integration (stay tuned for that one&#8230;)</li>
<li>Full operating system backup</li>
</ul>
<p>Here is a simplified view of my setup. A laptop, a usb drive and a simple NAS server (I have a Linksys NAS200, but any remote file share or ftp will do).</p>
<p><a href="http://www.paralint.com/blog/wp-content/uploads/2008/11/tcsso.jpg"><img class="aligncenter size-full wp-image-68" title="TrueCrypt single sign-on and encrypted backup" src="http://www.paralint.com/blog/wp-content/uploads/2008/11/tcsso.jpg" alt="Full disk encryption single sign-on diagram" /></a></p>
<ol>
<li><strong>A keyfile is stored on your encrypted partition. </strong><br />
I generated a keyfile with cryptographic random noise. Let&#8217;s call it Entropy.dat. Your pre-boot password and operating system logon will give you access to that key file. It is used to single sing-on to any container. That keyfile is <span style="text-decoration: underline;">never backed up</span>, excluded it from all your backups.</li>
<li><strong>A volume header of your container (with password authentication) is backed up</strong><br />
For any file based volume you create, backup a header that has a password authentication, no keyfiles. Write that password behind a picture of yourself with your kids and send it to your mother. It will be on the her fridge if ever you need it.</li>
<li><strong>Backup a rescue disk ISO file</strong><br />
This is regular TrueCrypt procedure for full disk encryption.</li>
</ol>
<p>To set yourself up like this, follow these steps :</p>
<ol>
<li>Follow TrueCrypt&#8217;s guidelines to enable full disk encryption.</li>
<li>Create a file based TrueCrypt volume, with a strong password that you will remember or write down.</li>
<li>Backup that volume header.</li>
<li>Select (or generate) a keyfile.</li>
<li>Change the volume password to      (nothing, leave the password field blank)</li>
<li>Select the keyfile of step 4 and click Ok</li>
</ol>
<p>Repeat steps 4-5-6 for each file based container. Copy to that container the files you want to be able on a need to know basis. When you need the files, mount the container. I wrote a batch file that mounts a file based container and shows a popup with my <a href="/projects/notifu/">Notifu utility</a> (Windows only).</p>
<pre class="generic:nogutter:nocontrols" name="code">@echo off
REM Mounts a file based TrueCrypt container and displays a pop-up
"C:\Program Files\TrueCrypt\TrueCrypt.exe" /v C:\users\your_username\Clients.tc /l X /q /k "%USERPROFILE%\entropy.dat" /m ts
start "" notifu /m "TrueCrypt drive X was mounted successfully from file Clients.tc" /p "Secure drive mounted" /d 5000 /i "C:\Program Files\TrueCrypt\TrueCrypt.exe"
start "" /MIN "C:\Program Files\TrueCrypt\TrueCrypt.exe" /q background</pre>
<p>The batch is a little different for USB drives.</p>
<pre class="generic:nogutter:nocontrols" name="code">@echo off
REM Mounts a file based TrueCrypt container located on a USB drive and displays a pop-up
setlocal
REM I use this setup on many machines, and the USB drive is not
REM always given the same letter...
if exist f:\mobile.tc set TCFILE=f:\mobile.tc
if exist e:\mobile.tc set TCFILE=e:\mobile.tc
start "TrueCrypt" /MIN "C:\Program Files\TrueCrypt\TrueCrypt.exe" /v %TCFILE% /k "%USERPROFILE%\entropy.dat" /l U /a /q /m rm /m ts
start "" notifu /m "TrueCrypt drive U was mounted successfully from file %TCFILE%" /p "Secure drive mounted" /d 5000 /i "C:\Program Files\TrueCrypt\TrueCrypt.exe"
start "" /MIN "C:\Program Files\TrueCrypt\TrueCrypt.exe" /q background
endlocal</pre>
<p>Feel free to use it and adapt it to your needs !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2008/11/06/full-disk-encryption-single-sing-on-and-secure-backup/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>Reversing WebSphere {xor} password protection</title>
		<link>http://www.paralint.com/blog/2008/03/21/reversing-websphere-xor-password-protection/</link>
		<comments>http://www.paralint.com/blog/2008/03/21/reversing-websphere-xor-password-protection/#comments</comments>
		<pubDate>Sat, 22 Mar 2008 02:48:25 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/2008/03/21/reversing-websphere-xor-password-protection/</guid>
		<description><![CDATA[IBM WebSphere stores its passwords in files. Everybody does that and it is hard to do otherwise. When I am confronted with the problem, I usually say that the only option you have is what file you want a password in. IBM (in WebSphere) went a little further by applying a hardcoded XOR. Each caracter [...]]]></description>
			<content:encoded><![CDATA[<p>IBM WebSphere stores its passwords in files. Everybody does that and it is hard to do otherwise. When I am confronted with the problem, I usually say that the only option you have is what file you want a password in. IBM (in WebSphere) went a little further by applying a hardcoded XOR. Each caracter is XORed with the caracter &#8216;_&#8217;, and the resulting string is encoded in base64. This is not cryptography, it is just enough encoding so that a casual glance at the file will not reveal the password.</p>
<p>If you have access to security.xml and need to know the passwords it contains, compile and run this tool. It supports :</p>
<ul>
<li>Encoded passwords on the command line (as many as you like)</li>
<li>Passwords piped in (default if no arguments are passed)</li>
<li>With or without the leading {xor}</li>
<li>It builds with Visual C++ and GNU g++ (tested with mingw32 version only)</li>
<li>A crude but working parsing so you can pipe the result of a grep, like this :<br />
<code>grep -i password security.xml | waspass</code></li>
</ul>
<p>You can get the source from my Subversion server with this command :</p>
<pre class="generic:nogutter:nocontrols">svn co http://src.paralint.com/spikes/waspass/trunk waspass</pre>
<p>I am also posting the full source inline, just to show off that <a href="http://code.google.com/p/syntaxhighlighter/" target="_blank">cool javascript code parser</a> I just installed&#8230;</p>
<p class="important">Update:With WebSphere v5, you can acheive the same result with IBM&#8217;s own classes</p>
<p>Eric Haszlakiewicz, of <a href="http://www.swapsimple.com/" target="_blank">SwapSimple.com</a>, found a way to acheive the same result with the server&#8217;s own Java classes. Here it is :</p>
<pre>cd /opt/WebSphere/AppServer/lib

../java/bin/java -cp securityimpl.jar:iwsorb.jar com.ibm.ws.security.util.PasswordEncoder secret
../java/bin/java -cp securityimpl.jar:iwsorb.jar com.ibm.ws.security.util.PasswordDecoder '{xor}LDo8LTor'</pre>
<p><span id="more-50"></span></p>
<pre class="cpp:nogutter:nocontrols">#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

// get those 2 functions from
// http://src.paralint.com/spikes/waspass/trunk/waspass/base64.c
extern "C" int base64_init(void);
extern "C" int base64_decode(char *d, unsigned dlen, const char *s);

int decode_password(char *encoded_password);

//Cass decode_password, reading from the command line or stdin
int main(int argc, char* argv[])
{
	printf("Reverses WebSphere XOR password encoding.\n");
	printf("http://www.paralint.com/\n\n");

	base64_init();

	//Should we parse stdin
	if(argc == 1)
	{
		char line[2048];
		while(!feof(stdin))
		{
			fgets(line, sizeof line, stdin);
			decode_password(line);
		}
	}
	//Or read encoded passwords from the command line ?
	else for(int i=1; i&lt;argc; ++i)
	{
		decode_password(argv[i]);
	}

	return 0;
}

//Takes an encoded password like KzY4Oi0= and outputs the original password
//Supports minimal parsing: a password is the text between } and " (quote)
//either are optionnal and will be replaced by begining or end of line if
//missing
int decode_password(char *encoded_password)
{
	char *p;
	char encoded[1024];

	//naive remove the {xor} flag if present
	p = strchr(encoded_password, '}');
	if(p) ++p; else p = encoded_password;

	//naive truncate of the string
	strtok(p, "\"");

	printf("%s ", p);
	base64_decode(encoded, sizeof encoded, p);
	p = encoded;

	//stop at the trailing quote, allowing a brutal pipe from grep
	while(*p &amp;&amp; (*p != '\"'))
	{
		putc(*p++ ^ '_', stdout);
	}

	printf("\n");

	return p - encoded;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2008/03/21/reversing-websphere-xor-password-protection/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>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>GSSP &#8211; Java self study reference links</title>
		<link>http://www.paralint.com/blog/2007/11/27/gssp-java-self-study-reference-links/</link>
		<comments>http://www.paralint.com/blog/2007/11/27/gssp-java-self-study-reference-links/#comments</comments>
		<pubDate>Tue, 27 Nov 2007 16:05:59 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/2007/11/27/gssp-java-self-study-reference-links/</guid>
		<description><![CDATA[This page contains links to useful, free content to prepare to your GSSP certification. I gathered these links as I was preparing for the exam myself. Start by reading the exam blueprint here. All the links below are shown in hyperlink and in full text, so you can study with only a printed version of [...]]]></description>
			<content:encoded><![CDATA[<p>This page contains links to useful, free content to prepare to your GSSP certification. I gathered these links as I was preparing for the exam myself.</p>
<p>Start by reading the <a href="http://www1.sans-ssi.org/blueprint_files/java_blueprint.pdf" id="le:e" title="exam blueprint here" target="_blank">exam blueprint here</a>. All the links below are shown in hyperlink and in full text, so you can study with only a printed version of this page.</p>
<p class="important">This page is probably not enough to pass the test. You won&#8217;t get by just by learning everything here by heart. But it will help you get your study started and quickly find the areas you need to focus on.</p>
<p>There are topics I do not cover. It&#8217;s not because they are not important, it&#8217;s just that I skipped over the stuff I was most familiar with. It doesn&#8217;t mean it&#8217;s not important !</p>
<p>Good luck &#8230;</p>
<p>UPDATE : I passed the exam, I am a certified GIAC Secure Software Programmer for Java ! That means that I have more letters to put after my name than my name contains <img src='http://www.paralint.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><span id="more-23"></span></p>
<h2><strong>Task 1 : Input Handling</strong></h2>
<h3>1.1.1 Input Validation Principles</h3>
<p>That one is easy : trust no one. Any data has to go through some verification before it trusted to move along. The close you get to core, the more check should be applied. It&#8217;s better to do a little verification, each adding more trust to the input, all the way down to the core of your application (like the database).</p>
<h2>1.1.2 Input Validation Sources</h2>
<h3>1.1.3 Input Validation Techniques</h3>
<p><a href="http://java.sun.com/docs/books/tutorial/essential/regex/char_classes.html" target="_blank">Regular expressions</a> : <a href="http://java.sun.com/docs/books/tutorial/essential/regex/char_classes.html" title="http://java.sun.com/docs/books/tutorial/essential/regex/char_classes.html">http://java.sun.com/docs/books/tutorial/essential/regex/char_classes.html</a></p>
<p>Quantifiers apply to single characters, character classes (including predefined ones) and capturing groups.</p>
<table border="1" cellpadding="3" cellspacing="0" width="100%">
<tr border="1">
<th>Quantifier</th>
<th>Example</th>
<th>Will match</th>
<th>Will not match</th>
</tr>
<tr>
<td>* means any number</td>
<td>z*</td>
<td>&#8220;foo&#8221;<br />
&#8220;gssp&#8221;<br />
&#8220;zoo&#8221;<br />
&#8220;&#8221;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>+ means one or more</td>
<td>z+</td>
<td>&#8220;zoo&#8221;<br />
&#8220;snazzy&#8221;</td>
<td>&#8220;zoo&#8221;<br />
&#8220;lazy&#8221;<br />
&#8220;foo&#8221;</td>
</tr>
<tr>
<td>? means 0 or 1</td>
<td>z?</td>
<td>&#8220;zoo&#8221;<br />
&#8220;lazy&#8221;<br />
&#8220;&#8221;</td>
<td>&#8220;foo&#8221;</td>
</tr>
</table>
<h2><strong>Task 2 : Authentication &amp; Session Management</strong></h2>
<h3>1.2.1 When to Authenticate</h3>
<h3>1.2.2 Authentication Protection</h3>
<h3>1.2.3 Session Protection</h3>
<h3>1.2.4 Authentication Techniques</h3>
<p>JAAS : Try the book Core Security Patterns, from page 197</p>
<p>JAAS Defines a Subject (javax.security.auth.Subject) that is a container for one or more Principals (java.security.Principal). A principal is a name that is bound to a Subject. JAAS handles authentication. It can also handle authorization.</p>
<p>JAAS is three things :</p>
<ol>
<li>Common classes (Subject and Principal),</li>
<li>Authentication classes (LoginContext, LoginModule, Configuration and CallbackHandler),</li>
<li>Authorization classes (Policy and a few others).</li>
</ol>
<p>A client will instanciate a LoginContext. That LoginContext will read the configuration and instanciate the required LoginModules (more on that next). Each LoginModule will create a set of callbacks used to interact with the user (through the CallbackHandler). Here is a collaboration diagram that helped me. It shows a configuration with only one username-password logon module.</p>
<p><img src="http://www.paralint.com/blog/wp-content/uploads/2007/12/jaas-collaboration-diagram1.png" alt="JAAS collaboration diagram" height="697" width="678" /></p>
<p>The method Subject.doAs will associate the Subject and the Action with the current access control context. Subject.doAsPriviledge will associate the Subject and the Action to a specific access control context.</p>
<p>The LoginContext enforces the required, requisite, sufficient and optional flags assigned to each LoginModule in the configuration file. It will process them according to their authentication flags, as describe in this table :</p>
<table border="1" cellpadding="2" cellspacing="0" width="100%">
<tr>
<th>Authentication flag</th>
<th>Must succeed</th>
<th>Login process will continue</th>
</tr>
<tr>
<td>required</td>
<td>yes</td>
<td>always</td>
</tr>
<tr>
<td>requisite</td>
<td>yes</td>
<td>only if successful</td>
</tr>
<tr>
<td>sufficient</td>
<td>no</td>
<td>only if failed</td>
</tr>
<tr>
<td>optional</td>
<td>no</td>
<td>always</td>
</tr>
</table>
<h3>1.2.5 Authentication responsibilities</h3>
<p>I wasn&#8217;t sure where to put the web.xml stuff. It&#8217;s on the exam, since this section talks about maximum session length, it thought this would be the place for it. Here is a hierarchy of the security related tags in web.xml</p>
<p><a href="http://edocs.bea.com/wls/docs61/webapp/web_xml.html" target="_blank">WEB.XML</a> : <a href="http://edocs.bea.com/wls/docs61/webapp/web_xml.html" title="http://edocs.bea.com/wls/docs61/webapp/web_xml.html">http://edocs.bea.com/wls/docs61/webapp/web_xml.html</a></p>
<p>security-constraint<br />
pattern<br />
method<br />
auth-constraint<br />
role<br />
user-data-constraint<br />
NONE, CONFIDENTIAL or INTEGRAL. (None is nothing, the other two will get you SSL)<br />
login-config<br />
auth-method (BASIC, FORM, CLIENT-CERT)<br />
real-name (optionnal)<br />
form-login-config<br />
security-role (just a name a description)</p>
<p>What&#8217;s wrong with BASIC authentication ?</p>
<ul>
<li>The password is in the clear (actually, base 64 encoded)</li>
<li>There is no way to log out !</li>
</ul>
<p>Even if you did log out the user by destroying its session, it would be recreated at the next call because the browser caches the credentials and sends them with every request.</p>
<p>By default, the session never times out. You need to set it (in seconds) in the session-config/session-timeout tag</p>
<p>Always specify CONFIDENTIAL or INTEGRAL if your auth-method is CLIENT-CERT. The latter will get you HTTPS for authentication only. But if you HTTP server can serve content to/from your application and you forgot to set this, you might get redirected to a regular HTTP session where your session cookie could be stolen.</p>
<h2><strong>Task 3 : Access Control (Authorization)</strong></h2>
<h3>1.3.1 Restricting Access To Resources</h3>
<h3>1.3.2 Restricting Access To Functions</h3>
<h3>1.3.3 Declarative Access Control</h3>
<p>A full fledge J2EE application will have these configuration files for security : application.xml, web.xml, ejb-jar.xml and ra.xml. An EAR file can contain any number of those, and each can be package on its own. Most (if not all) implementation will have another xml file alongside the standard files to do implementation specific stuff.</p>
<p><img src="http://www.paralint.com/blog/wp-content/uploads/2007/12/declarative-security.png" alt="Java J2EE declarative security configuration files" height="329" width="389" /></p>
<h3>1.3.4 Programmatic Access Control</h3>
<p>There are two things you can do and to ways to get them depending on the context (web application or enterprise java bean) you are in. This table sums it up :</p>
<table border="1" cellpadding="2" cellspacing="0" width="100%">
<tr>
<th>What you can do</th>
<th>Web Module</th>
<th>EJB</th>
</tr>
<tr>
<td>Get the identity of the caller</td>
<td>HttpServletRequest.getUserPrincipal()</td>
<td>EJBContext.getCallerPrincipal()</td>
</tr>
<tr>
<td>Check authorization</td>
<td>HttpServletRequest.isUserInRole(String)</td>
<td>EJBContext.isCallerInRole(String)</td>
</tr>
</table>
<p>Remember that when you get to those methods, the Subject has already been authenticated (by whatever means). So get the identity of the caller has nothing to do with authentication. At this point, it&#8217;s identification.</p>
<h3>1.3.5 JAAS</h3>
<p>It&#8217;s already covered in section 1.2.4 !</p>
<h2><strong>Task 4 : Java types &amp; JVM Management</strong></h2>
<h3>1.4.1 java.lang.String</h3>
<p><a href="http://www.janeg.ca/scjp/lang/strLiteral.html">String literals</a> : <a href="http://www.janeg.ca/scjp/lang/strLiteral.html" title="http://www.janeg.ca/scjp/lang/strLiteral.html">http://www.janeg.ca/scjp/lang/strLiteral.html</a></p>
<h3>1.4.2 Integer and Double overflow</h3>
<p><a href="http://www.phrack.org/archives/60/p60-0x0a.txt" target="_blank">Integer overflows</a> : <a href="http://www.phrack.org/archives/60/p60-0x0a.txt" title="http://www.phrack.org/archives/60/p60-0x0a.txt" target="_blank">http://www.phrack.org/archives/60/p60-0x0a.txt</a><br />
<a href="http://www.javacoffeebreak.com/books/extracts/javanotesv3/c9/s1.html" target="_blank">Double overflows</a> : <a href="http://www.javacoffeebreak.com/books/extracts/javanotesv3/c9/s1.html" title="http://www.javacoffeebreak.com/books/extracts/javanotesv3/c9/s1.html" target="_blank">http://www.javacoffeebreak.com/books/extracts/javanotesv3/c9/s1.html</a> (scroll down, its at the bottom)</p>
<p>Integers wrap to negative values if they are signed, or to 0 if they are unsigned. Having an integer wrap around could cause anything from a array out of bounds exception to allowing a runtime access check to succed.</p>
<p>Java Double does not &#8220;wrap around&#8221; to negative values. Instead, they are represented by special values that have no numerical equivalent. The values <tt>Double.POSITIVE_INFINITY</tt> and <tt>Double.NEGATIVE_INFINITY</tt> represent numbers outside the range of legal values</p>
<h3>1.4.4 ArrayList vs Vector</h3>
<p>I will have to check this one out myself&#8230; It boils down to this, but apart from the first item (synchronization), opinions differs.</p>
<ol>
<li>Arraylist is not synchronized while vector is.</li>
<li>Arraylist increment it&#8217;s size by half the initial capacity, Vector increments by the full capacity each time.</li>
<li>Arraylist can be seen directly without any iterator while vector requires an iterator to display all it&#8217;s content. (not very sure).</li>
<li>Vector works with a 1.1 JVM.</li>
</ol>
<h3>1.4.5 Class security</h3>
<p><a href="http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html" target="_blank">Accessibility Modifiers</a> : <a href="http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html" title="http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html">http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html</a></p>
<p>That&#8217;s rather easy&#8230; And its a duplicate of topic 1.9.1 !</p>
<p><a href="http://www.onjava.com/pub/a/onjava/excerpt/JavaRMI_10/index.html?page=3" target="_blank">Serialization</a> : <a href="http://www.onjava.com/pub/a/onjava/excerpt/JavaRMI_10/index.html?page=3" title="http://www.onjava.com/pub/a/onjava/excerpt/JavaRMI_10/index.html?page=3">http://www.onjava.com/pub/a/onjava/excerpt/JavaRMI_10/index.html?page=3</a>, <a href="http://java.sun.com/developer/technicalArticles/ALT/serialization/" title="http://java.sun.com/developer/technicalArticles/ALT/serialization/">http://java.sun.com/developer/technicalArticles/ALT/serialization/</a></p>
<p>It has be done properly. It can be abused to get around a Singleton requirement, clone an object that refuses to be cloned or to get to private data inside a class.</p>
<p>Fields with the transient keyword will not be serialized. But you can control what will be serialized with ObjectStreamField. It takes precedence over transient fields.</p>
<p><a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html#clone()" target="_blank">Cloning</a> : <a href="http://java.sun.com/javase/6/docs/api/java/lang/Object.html#clone()" title="http://java.sun.com/javase/6/docs/api/java/lang/Object.html#clone()">http://java.sun.com/javase/6/docs/api/java/lang/Object.html#clone()</a></p>
<p>That&#8217;s straight from the horse&#8217;s mouth, as my mother used to say. Clone does only a shallow copy.</p>
<p><a href="http://www.cs.umd.edu/~pugh/java/SecureInnerClasses.pdf" target="_blank">Inner classes</a> : <a href="http://www.cs.umd.edu/~pugh/java/SecureInnerClasses.pdf" title="http://www.cs.umd.edu/~pugh/java/SecureInnerClasses.pdf">http://www.cs.umd.edu/~pugh/java/SecureInnerClasses.pdf</a></p>
<p>Inner classes are not supported (or understood if you prefer) by the JVM. It was to allow for a JVM 1.0 to work with code that had inner classes. The problem is that inner classes are given package level visibility. Inner classes are just a compile time trick. If you add a malicious class to the package (see 1.9.2), it can call private methods on your inner class.</p>
<h3>1.4.6 Code Privileges</h3>
<p><a href="http://java.sun.com/j2se/1.4.2/docs/guide/security/PolicyFiles.html#FileSyntax" target="_blank">Policy file</a> : <a href="http://java.sun.com/j2se/1.4.2/docs/guide/security/PolicyFiles.html#FileSyntax" title="http://java.sun.com/j2se/1.4.2/docs/guide/security/PolicyFiles.html#FileSyntax">http://java.sun.com/j2se/1.4.2/docs/guide/security/PolicyFiles.html#FileSyntax</a></p>
<p>Before performing a sensitive operation, the <code>SecurityManager</code> determines the operation&#8217;s identity and whether it can be performed in its security context.</p>
<p>The SecurityManager is enable by specifying -Djava.security.manager on the JVM command line (it may be buried deep down in your J2EE application server). It is not enabled by default, except for applets or web start applications.</p>
<p>The class loader is responsible for locating and fetching the class file, consulting the security policy, and defining the class object with the appropriate permissions. There is by default a single system-wide policy file, and a single (optional) user policy file. You always get a union of all the policy, unless you specify a policy file with == (instead of =).</p>
<p>Code security is based on protection domains. A protection domain is the combination of classes, grants and permissions. There are two types of protection domains :</p>
<ul>
<li>System domain : files, sockets and everything having a foot in the native world</li>
<li>Application domain : classes and objects (instances of classes)</li>
</ul>
<p>The ClassLoader puts classes it loads in a protection domain and it stays there. You cannot change protection domains at runtime.</p>
<p>A SecurityManager uses a policy file, that has grant entries based on any combination of codebase, signed by or Principal. If there are multiple principals on a single grant entry, a Subject must have every principal.</p>
<h2><strong>Task 5 : Application Faults &amp; Logging</strong></h2>
<h3>1.5.1 Exception Handling</h3>
<h3>1.5.2 Logging</h3>
<h3>1.5.3 Configuration of Error Handling</h3>
<p><a href="http://edocs.bea.com/wls/docs61/webapp/web_xml.html#1017571" target="_blank">Error pages</a> : <a href="http://edocs.bea.com/wls/docs61/webapp/web_xml.html#1017571" title="http://edocs.bea.com/wls/docs61/webapp/web_xml.html#1017571">http://edocs.bea.com/wls/docs61/webapp/web_xml.html#1017571</a></p>
<p>In WEB-INF\web.xml file, you can configure what page is used when an error occurs, like 404 (not found) or 500 (Server Error) or a specific Exception bubbles back up to the web container. The location of the page is relative to the root of your web application.</p>
<pre name="code" class="xml:nocontrols:nogutter">   &lt;error-page&gt;
      &lt;error-code&gt;404&lt;/error-code&gt;
      &lt;location&gt;/404error.html&lt;/location&gt;
   &lt;/error-page&gt;
   &lt;error-page&gt;
      &lt;error-code&gt;500&lt;/error-code&gt;
      &lt;location&gt;/500error.html&lt;/location&gt;
   &lt;/error-page&gt;
   &lt;error-page&gt;
      &lt;exception-type&gt;javax.servlet.ServletException&lt;/exception-type&gt;
      &lt;location&gt;/ExceptionHandler.jsp&lt;/location&gt;
   &lt;/error-page&gt;
<web><error></error></web></pre>
<h2><strong>Task 6 : Encryption Services</strong></h2>
<h3>1.6.1 Communications Encryption</h3>
<p>You configure SSL (JSSE) using a keystore. Both the client and the server have their own, independent keystores (assuming their both written in Java). They also have another keystore, called a truststore, that holds the public key certificates of any number of trusted root certificate authorities (root CA). Messing up the truststore will get you the dreaded pop-up saying the certificate cannot be trusted.</p>
<p>A server-side keystore (the end that waits for a SSL connection, like a HTTPS web server would). :</p>
<ul>
<li>Has at least one private key, protected by a password</li>
<li>The password can be in a configuration file or entered at startup (that&#8217;s implementation dependent)</li>
<li>The private key is used to issue a server certificate, from which a certificate signing request is generated and sent to a root CA the <u>client trusts</u> (although you will much likely trust it yourself).</li>
<li>The CA signs the server certificate and it is installed in the keystore</li>
</ul>
<p>A client-side keystore is used to hold a private key that could be used to authenticate with a server. It is optional and rarely used for end users. For this to work, you must have :</p>
<ul>
<li>In the client keystore a certificate corresponding to the private key you hold.</li>
<li>That certificate issued by a root CA the <u>server trusts</u> (although you will much likely trust it yourself).</li>
<li>The password (or other authentication) to decrypt that private key you hold.</li>
</ul>
<p>About truststores : Java comes with a keystore called cacerts that contains public key certificates of all the major root CA in the world, and then some. So having a client root CA trusted by the server (or vice-versa) is rather easy if you&#8217;re willing to spend the money. If not, you can <a href="http://sial.org/howto/openssl/ca/" target="_blank">set up your own root CA</a> and add that CA&#8217;s certificate to the truststore at both end.</p>
<p>The following table summarize what goes on at both ends of an SSL connection programmatically, with or without a client certificate.</p>
<table border="1" cellpadding="2" cellspacing="0" width="100%">
<tr>
<th>Client</th>
<th>Server</th>
</tr>
<tr>
<td>Register providers</td>
<td>Register providers</td>
</tr>
<tr>
<td>Create a SocketFactory (this is where you set a proxy, if needed)</td>
<td>Create a SocketFactory (and set your client certificate requirement if any)</td>
</tr>
<tr>
<td>Create socket</td>
<td>Accept</td>
</tr>
<tr>
<td>Create or get input and output streams</td>
<td>Create or get input and output streams</td>
</tr>
<tr>
<td>Close everything</td>
<td>Close everything</td>
</tr>
</table>
<h2>1.6.2 Encryption of Data at Rest</h2>
<p>There is two API, because of extensibility and export regulation. Every Java installation has the Java Cryptography Architecture (JCA). Not to be confused with the Java Connector Architecture, also referred to as JCA. The Java Cryptography Architecture contains classes able to do the following :</p>
<ul>
<li>Message Digest algorithm (MD5 and SHA-1)</li>
<li>Key pair generation (for DSA only)</li>
<li>Key store manipulation (JKS only)</li>
<li>Digital signature (again, for DSA only)</li>
<li>Cryptographic strength random number generator</li>
</ul>
<p>Pretty much everything else is in JCE. You can have has many providers as you like, of any algorithm you like that can perform these cryptographic operations :</p>
<ul>
<li>Symmetric key generation</li>
<li>Symmetric key encryption (from weak like DES to unlimited AES-256 and up)</li>
<li>Password based encryption (PBE or sometimes PBKDF2)</li>
<li>Message authentication codes (MAC, a symmetric key signature)</li>
<li>PKCS11 support (hardware cryptographic device such as smart cards)</li>
</ul>
<p>The graphic below is taken from the book <a href="http://www.coresecuritypatterns.com/" target="_blank">Core Security Patterns</a>.</p>
<p><img src="http://www.paralint.com/blog/wp-content/uploads/2007/12/java-crypto-relations.png" alt="Java crypto relations" height="239" width="557" /></p>
<p>You can serialize an object in an encrypted form, you create a CipherOutputStream and use it with a ObjectOutputStream.</p>
<h2>Task 7 : Concurrency and Threading</h2>
<h3>1.7.1 Race Conditions</h3>
<h3>1.7.2 Singletons &amp; Shared resources</h3>
<p><a href="http://www.javacoffeebreak.com/articles/designpatterns/index.html" target="_blank">Singleton pattern</a> : <a href="http://www.javacoffeebreak.com/articles/designpatterns/index.html" title="http://www.javacoffeebreak.com/articles/designpatterns/index.html">http://www.javacoffeebreak.com/articles/designpatterns/index.html</a></p>
<p>A singleton is any regular class that has these particular implementation features</p>
<ul>
<li>It has an empty, private constructor</li>
<li>It has a public static synchronized method that returns the unique instance of the object (say MyClass.getSingleInstance())</li>
<li>It creates an instance of itself on the first call to the accessor method (MyClass.getSingleInstance())</li>
<li>Implements a clone() method that always throw a CloneNotSupportedException</li>
</ul>
<p>But you can bypass a singleton class by serializing the object to a temporary stream and back to another instance of it. See 1.4.5</p>
<h2>Task 8 : Connection Patterns</h2>
<h3>1.8.1 Parameterized Queries/Prepared Statements</h3>
<h3>1.8.2 Output Encoding</h3>
<p><a href="http://www.owasp.org/index.php/How_to_perform_HTML_entity_encoding_in_Java" target="_blank">HTML Output Encoding</a> : <a href="http://www.owasp.org/index.php/How_to_perform_HTML_entity_encoding_in_Java" title="http://www.owasp.org/index.php/How_to_perform_HTML_entity_encoding_in_Java">http://www.owasp.org/index.php/How_to_perform_HTML_entity_encoding_in_Java</a></p>
<p>There is no standard way to do HTML output encoding. The characters to watch out for are &lt; &gt; / &#8216;  &amp;, but OWASP suggest to encode everything that is not a a letter or digit.</p>
<p>Use output encoding when you are sending back data you got from a client, even if you validated it on its way in. There were double decode bugs in the past&#8230;</p>
<h2><strong>Task 9 : Miscellaneous</strong></h2>
<h2>1.9.1 Class/Package/Method Access Modifiers</h2>
<p><a href="http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html" target="_blank">Accessibility Modifiers</a> : <a href="http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html" title="http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html">http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html</a></p>
<p>Here is the duplicate of topic 1.4.5 !</p>
<h4>1.9.2 Class File Protection</h4>
<p><a href="http://java.sun.com/developer/JDCTechTips/2001/tt0130.html" id="qm_." title="JAR sealing" target="_blank">JAR sealing</a> : <a href="http://java.sun.com/developer/JDCTechTips/2001/tt0130.htmlg" target="_blank">http://java.sun.com/developer/JDCTechTips/2001/tt0130.htmlg</a></p>
<p>JAR sealing prevents classes defined anywhere other than the original JAR to see public methods of that original JAR. Someone could create a class with the same package name as yours and call your public methods and break things.</p>
<ul>
<li>Sealing is off by default (packages are not secured by default)</li>
<li>You can apply RuntimePermissions to a policy file with accessClassInPackage and defineClassInPackage, but default classloaders don&#8217;t enforce them !</li>
<li>In java.security (located in ${JAVA_HOME}/jre/lib/security) you can protect classes with package.access and package.definition</li>
<li>Class visibility is package by default</li>
<li>java.* has its seal hardcoded in the classloader.</li>
<li>You put the Sealed: true directive in the manifest (META-INF/MANIFEST.MF)</li>
</ul>
<h3>1.9.3 JAVA EE Filters</h3>
<p><a href="http://javaboutique.internet.com/tutorials/Servlet_Filters/index.html" target="_blank">Writing servlet filters</a> : <a href="http://javaboutique.internet.com/tutorials/Servlet_Filters/index.html" target="_blank">http://javaboutique.internet.com/tutorials/Servlet_Filters/index.html</a><br />
<a href="http://java.sun.com/products/servlet/Filters.html" target="_blank">The essentials of Filters</a> : <a href="http://java.sun.com/products/servlet/Filters.html" target="_blank">http://java.sun.com/products/servlet/Filters.html </a></p>
<p>A J2EE Filter is applied to a servlet, not an Enterprise Java Bean (EJB).</p>
<ul>
<li>They are configured in web.xml.</li>
<li>They can read, modify or block requests and responses to/from a servlet.</li>
<li>They cannont filter arbiratry request (for example, a request to an image).</li>
<li>Any number of filters can be applied to any number of servlets</li>
<li>Security roles do not apply to Filters</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2007/11/27/gssp-java-self-study-reference-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Change Paros Proxy MITM SSL certificate</title>
		<link>http://www.paralint.com/blog/2007/01/16/change-paros-proxy-mitm-ssl-certificate/</link>
		<comments>http://www.paralint.com/blog/2007/01/16/change-paros-proxy-mitm-ssl-certificate/#comments</comments>
		<pubDate>Tue, 16 Jan 2007 19:16:24 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/?p=9</guid>
		<description><![CDATA[Don&#8217;t you just love man-in-the-middle (MITM) HTTPS proxies ? I use Burp proxy a lot, it does man-in-the-middle and gzip. But I have an assignment where the client configuration cannot be changed. The client rejects certificates from non-trusted CA and I cannot add Portswigger&#8217;s certificate to the trusted roots. I went looking for an open [...]]]></description>
			<content:encoded><![CDATA[<p>Don&#8217;t you just love man-in-the-middle (MITM) HTTPS proxies ? I use <a href="http://www.portswigger.net/proxy/">Burp proxy</a> a lot, it does man-in-the-middle and gzip.</p>
<p>But I have an assignment where the client configuration cannot be changed. The client rejects certificates from non-trusted CA and I cannot add Portswigger&#8217;s certificate to the trusted roots. I went looking for an open source HTTPS mitm proxy, hoping I could recompile it to use a trusted certificate that I have in hand.</p>
<p><a href="http://www.parosproxy.org/">Paros proxy</a> fits the bill. Here is how you can change Paros proxy&#8217;s man-in-the-middle certificate for your own using keytool, openssl, and jar.</p>
<p><span id="more-9"></span>First of all, Paros certificate is the file ./resource/paroskey. It is a JKS keystore and it&#8217;s password is &#8220;!@#$%^&amp;*()&#8221;, without the quotes (the password is in the source code, I am not <a href="http://www.google.com/codesearch?q=+%22!%40%23%24%25%5E%26*()%22+show:1nVTaHJQG2I:3qN8LO4APgY:RwTWy1IW3Kc&amp;sa=N&amp;cd=5&amp;ct=rc&amp;cs_p=http://gentoo.osuosl.org/distfiles/paros-3.2.9-src.zip&amp;cs_f=paros/src/org/parosproxy/paros/network/SSLConnector.java#a0">revealing any secrets</a>). Extract it with this command :</p>
<pre name="code" class="generic:nocontrols:nogutter">jar xvf paros.jar resource/paroskey</pre>
<p>You can view the certificate using this command (you might have to escape some characters for it to work on your platform) :</p>
<pre name="code" class="generic:nocontrols:nogutter">keytool -list -v -keystore resource/paroskey -storepass "!@#$%^&amp;*()"</pre>
<p class="important">If something goes wrong, you can type that command and compare the original and the new certificate. Run it from after each keytool operations if you want to follow what is going on in there.</p>
<p>To keep it as simple as possible, I will simply replace the paroskey file with my own certificate, using the same alias and password that is hardcoded. It will allow you to do the same without the need to use the java SDK. Ok, maybe just keytool.</p>
<p>Now, you have to get your hand on a certificate. I suggest using your own certificate authority (CA) to start and play with the proxy right away. <a href="http://sial.org/howto/openssl/ca/" title="Your own CA with openssl and make" target="_blank">This page</a> is perfect for this. It even works well on Windows with cygwin. A better setup would be to have a test CA in your company or lab that would sign your certificates. I also packaged the <a href="http://www.paralint.com/blog/wp-content/uploads/2007/06/parosmitm.zip" class="zip" title="Two sample certificate files">two sample certificate files</a> I refer two in this article in a zip file.</p>
<p>So if you have your CA public key in a file named ca-cert.pem, copy it to the local directory and import it in your brand new keystore with this command :</p>
<pre name="code" class="generic:nocontrols:nogutter">keytool -import -trustcacerts -alias "my-ca" -file ca-cert.pem -keystore resource/paroskey -noprompt -storepass "!@#$%^&amp;*()"</pre>
<p>Now you must choose the hostname of your proxy. It doesn&#8217;t have to match any DNS record, but if you want your setup to be warning-free, make them match. I choose mitm.paralint.com, and I delete the old certificate and generate a new private key with those two commands :</p>
<pre name="code" class="generic:nocontrols:nogutter">keytool -delete -alias paros -keystore resource/paroskey -storepass "!@#$%^&amp;*()"</pre>
<pre name="code" class="generic:nocontrols:nogutter">keytool -genkey -keyalg RSA -alias paros -keystore resource/paroskey -storepass "!@#$%^&amp;*()" -keypass "!@#$%^&amp;*()" -dname "CN=mitm.paralint.com" -validity 720</pre>
<p>Adjust the validity period to your needs, but do not change the alias or passwords. Now create a certificate signing request with this command :</p>
<pre>keytool -certreq -v -alias paros -keystore resource/paroskey -storepass "!@#$%^&#038;*()" -file mitm.paralint.com.csr</pre>
<p>Hand over the mitm.paralint.com.csr file to your CA. If you are using the CA suggested above, initialize it with make init, copy the csr file in that same directory as the makefile and type make sign.</p>
<p>Your CA will send you back a signed certificate (mitm.paralint.com.cert). It must be in DER format to be imported in the JKS keystore. If it is not (like if you are using the CA mentionned above), type this command to convert it :</p>
<pre>openssl x509 -in mitm.paralint.com.cert -out mitm.paralint.com.der -outform DER</pre>
<p>Now import that DER encoded certificate in a JKS keystore with this keytool command :</p>
<pre>keytool -import -v -alias paros -file mitm.paralint.com.der -keystore resource/paroskey -storepass "!@#$%^&#038;*()" -storetype JKS</pre>
<p>All this work has got you a certificate with a hostname you selected, in a keystore that can be used as a drop-in replacement for Paros built-in hardcoded keystore. Use your favorite tool for this or keep reading if all you have is the jar utility.</p>
<p>Replace the old keystore with the new one in paros.jar with this command (backup paros.jar before, just in case…) :</p>
<pre>jar uvf paros.jar resource\paroskey</pre>
<p>That’s all there is to it ! Your Paros proxy will now show mitm.paralint.com as it’s hostname. Remember that to be completely warning free, you must trust the root CA. If it’s not already there, import the root CA public key certificate in your browser.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2007/01/16/change-paros-proxy-mitm-ssl-certificate/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>ASP.NET Impersonation</title>
		<link>http://www.paralint.com/blog/2006/07/20/aspnet-impersonation/</link>
		<comments>http://www.paralint.com/blog/2006/07/20/aspnet-impersonation/#comments</comments>
		<pubDate>Thu, 20 Jul 2006 14:18:35 +0000</pubDate>
		<dc:creator>Guillaume</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.paralint.com/blog/?p=6</guid>
		<description><![CDATA[I was looking for a table that showed how client authentication, server authentication and impersonate flag work together. I found many good examples and tutorials explaining how to make any combinaison work, but not a quick reference table. So I made one. I tested on a Windows Server 2003 with ASP.NET version 2.0. I used [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking for a table that showed how client authentication, server authentication and impersonate flag work together. I found many good examples and tutorials explaining how to make any combinaison work, but not a quick reference table.</p>
<p>So I made one. I tested on a Windows Server 2003 with ASP.NET version 2.0. I used wfecth as client to be sure of what was going on. Not every configuration makes sense in real life, but I included it for completeness. HTH !</p>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>Client sends creds</td>
<td>Server require creds</td>
<td>Impersonate</td>
<td>Result</td>
</tr>
<tr>
<td>don&#8217;t care</td>
<td>No</td>
<td>false</td>
<td>NETWORK_SERVICE</td>
</tr>
<tr>
<td>No</td>
<td>Yes</td>
<td>don&#8217;t care</td>
<td>401 Unauthorized</td>
</tr>
<tr>
<td>Yes</td>
<td>Yes</td>
<td>False</td>
<td>NETWORK_SERVICE</td>
</tr>
<tr>
<td>don&#8217;t care</td>
<td>No</td>
<td>True</td>
<td>IUSR_MACHINENAME</td>
</tr>
<tr>
<td>Yes</td>
<td>Yes</td>
<td>True</td>
<td>Domain\User</td>
</tr>
</table>
<p>ps : Actually, NETWORK_SERVICE is the account the application pool is running under.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.paralint.com/blog/2006/07/20/aspnet-impersonation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
