pages tagged securitylelutin.cahttps://lelutin.ca//tags/security/lelutin.caikiwiki2018-01-02T23:41:19ZSquirrelMail and encrypted headershttps://lelutin.ca//posts/SquirrelMail_and_encrypted_headers/2018-01-02T23:41:19Z2014-07-16T01:50:43Z
<p>Well well.. today I had to sort out a spam run that was originating from our
webmail and boy was I happy to have some way to link email to some account.</p>
<p>But .... eeeek I saw something I didn't want to be real <img src="https://lelutin.ca//smileys/sad.png" alt=":(" /></p>
<p>Let's talk about the way SquirrelMail "encrypts" the headers it adds to mail
for tracking purposes.</p>
<h1>Purpose of those headers</h1>
<p>The two headers that SquirrelMail adds are one for the user name from which the
mail was sent (e.g. authenticated user name) and the other is some kind of hash
on the from field for which I don't quite care for the purposes of killing
spammers.</p>
<h1>Format of those headers</h1>
<p>When you look at an email that was sent by SquirrelMail (and for which you set
the variable $encode_header_key -- which should be done automatically on
debian -- you can see something that will look like the following:</p>
<pre><code>X-Squirrel-UserHash: KVcBIR8rLwwFNDxaLkpWew==
X-Squirrel-FromHash: fQAIWRtqdgJ/
</code></pre>
<h1>How are they generated?</h1>
<p>How the heck is that scheiße generated?</p>
<p>OK let's dig into the code that generates the headers. In file
/usr/share/squirrelmail/class/deliver/Deliver.class.php, inside function
prepareRFC822_Header() we can find the following two lines of interest (with
3rd line before just to give more context):</p>
<pre><code> $rn = "\r\n";
[...]
$header[] = 'X-Squirrel-UserHash: '.OneTimePadEncrypt($username,base64_encode($encode_header_key)).$rn;
$header[] = 'X-Squirrel-FromHash: '.OneTimePadEncrypt($this->ip2hex($REMOTE_ADDR),base64_encode($encode_header_key)).$rn;
</code></pre>
<p>... wait what did we just see?</p>
<p>... yep, the code from file /usr/share/squirrelmail/functions/strings.php does
confirm it. It is a one time pad.</p>
<p>So the headers are encrypted with a one time pad with a never-changing-key. Is
it just me or is that the textbook example of how to NOT use a one time pad?</p>
<p>I will leave reproducing this as an exercise to the reader, but I will claim
that if you're able to catch a few dozen email with such headers, you will be
able to easily retrieve part of the key -- enough to be able to decrypt most
headers that you intercept.</p>
<h1>How do I decrypt those headers?</h1>
<p>Simple, I've written a small script for that that actually uses the function
from SquirrelMail's code. Shame we can't just include the file that defines the
functions though, so I just copied the function definition in the script. It's
tailored for Debian since the $encode_header_key variable is defined in
/etc/squirrelmail/config_local.php but you can easily change this to get the
key from wherever it's lying on your disk:</p>
<pre><code>#!/usr/bin/php
<?php
/**
* Decrypts a password from the cookie
*
* Decrypts a password from the cookie, encrypted by OneTimePadEncrypt.
* This uses the encryption key that is stored in the session.
*
* @param string string the string to decrypt
* @param string epad the encryption key from the session
* @return string the decrypted password
*/
function OneTimePadDecrypt ($string, $epad) {
$pad = base64_decode($epad);
if (strlen($pad)>0) {
// make sure that pad is longer than string
while (strlen($string)>strlen($pad)) {
$pad.=$pad;
}
} else {
// FIXME: what should we do when $epad is not base64 encoded or empty.
}
$encrypted = base64_decode ($string);
$decrypted = '';
for ($i = 0; $i < strlen ($encrypted); $i++) {
$decrypted .= chr (ord($encrypted[$i]) ^ ord($pad[$i]));
}
return $decrypted;
}
set_include_path('/etc');
include "/etc/squirrelmail/config_local.php";
while (! feof(STDIN)) {
$val = fgets(STDIN);
$res = OneTimePadDecrypt($val, base64_encode($encode_header_key));
print ($res);
}
</code></pre>
<p>To use the script, just invoke it as a script within your shell of choice and
for each line of text that you give to it on stdin, it will return the
decrypted value to stdout until it hits EOF.</p>
<h1>So ... what's all this fuss about?</h1>
<p>If leaking your usernames is bad for you, DON'T USE THE SQUIRRELMAIL ENCRYPTED
HEADERS. To disable them, you can just set the $encode_header_key variable to
an empty string.</p>
<p>The downside to not using the headers is that you can't easily track down
trouble makers. But you can always enable the headers when you need to track
such an annoyance.</p>
Setting up MySQL replication via SSLhttps://lelutin.ca//posts/Setting_up_MySQL_replication_via_SSL/2018-01-02T23:41:19Z2014-02-25T03:12:15Z
<p>Today I embarked into the adventure of setting up SSL connections for MySQL
replication and got side-tracked by some pretty bad (or possibly just outdated)
documentation out there. I won't actually detail how to do things here, but
rather just point out that you <em>should</em> use steps documented in the official
documentation, especially if you're creating your own self-signed CA cert and a
pair of client/server certs signed by that CA.</p>
<p>Documentation for CA + pair of self-signed certificates:</p>
<p><a href="https://dev.mysql.com/doc/refman/5.5/en/creating-ssl-certs.html">https://dev.mysql.com/doc/refman/5.5/en/creating-ssl-certs.html</a></p>
<p>Documentation for replication setup:</p>
<p><a href="https://dev.mysql.com/doc/refman/5.5/en/replication-solutions-ssl.html">https://dev.mysql.com/doc/refman/5.5/en/replication-solutions-ssl.html</a></p>
<p>Some tricks are actually really handy to test your setup:</p>
<ul>
<li><p>To verify whether your current connection is encrypted or not:</p>
<h2> mysql> \s</h2>
<p> mysql Ver 14.14 Distrib 5.5.35, for debian-linux-gnu (i686) using readline 6.2</p>
<p> Connection id: 29220
Current database: <br/>
Current user: test@your.server.com
SSL: Cipher in use is DHE-RSA-AES256-SHA
[...]</p></li>
<li><p>To connect to a server via ssl (supposing the certificate files exist -- the
client certificate/key pair must be signed by the same CA as the server's):</p>
<p> mysql --ssl-ca=/etc/ssl/local/mysql.ca.crt --ssl-cert=/etc/ssl/local/mysql-client.crt --ssl-key=/etc/ssl/local/mysql-client.key -h your.server.com -u test -p</p></li>
<li><p>To verify whether SSL configuration was successful in mysql:</p>
<p> mysql> show variables like '%ssl%';
+---------------+---------------------------------+
| Variable_name | Value |
+---------------+---------------------------------+
| have_openssl | YES |
| have_ssl | YES |
| ssl_ca | /etc/ssl/local/mysql.ca.crt |
| ssl_capath | |
| ssl_cert | /etc/ssl/local/mysql-server.crt |
| ssl_cipher | |
| ssl_key | /etc/ssl/local/mysql-server.key |
+---------------+---------------------------------+
7 rows in set (0.02 sec)</p></li>
</ul>
Get off my lawnhttps://lelutin.ca//posts/Get_off_my_lawn/2013-10-12T06:56:17Z2013-09-15T03:34:38Z
<p>What is privacy? "Get off my lawn!" a grandpa would say when law enforcers came on behalf of corporations to take away his land. But some generations later, people would probably say something that sounds more like "I don't need to hide anything, since I'm not doing anything wrong".</p>
<p>What has gone wrong between the generations?</p>
<p>Probably mostly nothing :P The concept of privacy is simple in itself, but the implications that revolve around it are so numorous and touch so much different areas of our lives that it can be difficult to come to a grasp of the concept that encompasses a broader view. Also, the majority of people nowadays don't really want to hear anything about laws and politics and thus they shoo away the implications in this field.</p>
<p>The thing is: privacy in law is not about hiding yourself from the police and judges. It is about leveraging the power that was given to law enforcement:</p>
<p align="center"><iframe src="http://player.vimeo.com/video/29220302?title=0&byline=0&portrait=0" width="560" height="315" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe><br />Check out the other videos at <a href="http://unlawfulaccess.net/">unlawfulaccess.net</a>, they are very informative.</p>
<p>A colleague of mine pointed me to this website, which presents different papers on privacy around a couple of fields:</p>
<p><a href="http://hatswitch.org/~nikita/courses/ece598nb-sp12/schedule.html">http://hatswitch.org/~nikita/courses/ece598nb-sp12/schedule.html</a></p>
<p>I'm particularly interested in the first article of the list, which tries to debunk the "I have nothing to hide" argument and goes on to show that this same argument is actually a crooked response to a flawed question and thus that the whole argument is useless:</p>
<p><a href="http://papers.ssrn.com/sol3/papers.cfm?abstract_id=998565">http://papers.ssrn.com/sol3/papers.cfm?abstract_id=998565</a></p>
<p>This argument was so widely publicized in the media in the last decade or so, that poeple from all fields have become confused about the subject of privacy and are allowing such stupid bills as <a href="http://news.cnet.com/8301-31921_3-57329001-281/how-sopa-would-affect-you-faq/">U.S.A.'s SOPA</a> and <a href="http://www.huffingtonpost.ca/2011/11/22/lawful-access-online-spying-independent-internet-providers_n_1107157.html">Canada's Lawful access</a> that are usually part of trade agreements like the <a href="http://www.copyright.gov/wipo/">WIPO</a> and the <a href="https://www.eff.org/issues/acta">ACTA</a> to be accepted and make it into the laws that regulate our lives, without too much scrutiny, grinding away our right to privacy.</p>
<p>But the problem with the attack on privacy, to the benefit of the so-called security it brings to law enforcement, goes beyond copyright enforcement, <a href="http://boingboing.net/2012/01/10/lockdown.html">says Cory Doctorow</a> (see video below; the linked article is a transcript of the presentation). What we're seeing right now, if we take a step back from all those court rulings, personal suits and bill propositions, are demands for "building general-purpose computers, networks and software that let you do all that you want, except for what upsets a certain group". And, like he says, we're probably going to see more and more buisinesses -- and at that, ones far more powerful and influential than the MPAA -- come up with that sort of demand:</p>
<p align="center"><iframe width="560" height="315" src="http://www.youtube-nocookie.com/embed/HUEvRyemKSg" frameborder="0" allowfullscreen></iframe></p>
<p>The thing is, <em>we don't know how to build a machine that lets you do all the things that you want except those that are prohibited</em>. Building such a thing means that you'll have malware in your computer continually listening to what you're doing in order to block certain things.</p>
<p>What does actually differentiate one computer activity from another? How can you say that one process is evil and another isn't? Up to now, only humans that analyze what a particular process is doing are able to tell if the process is wanted or not. Not because the algorythms and heuristics for determining a process' intents are lacking, but because determining a process' intents is not something that you can do reliably with an algorythm that can run on current computers. There are pretty much an infinite ways you could come up with something that ultimately is used for illegal activities. And most of the times, the ways those illegal activities are achieved are by using methods that could also be used by legitimate actions.</p>
<p>So, regulating what a computer can do means you need to have human oversight. Also, regulating <strong>how</strong> it can do things is acutally <strong>not a realistic demand</strong> because people will always come up with ways to upsmart laws that try to do that. And to go further: how a computer does things is actually not the root cause of the problem! It's just a technological means of doing something. There'll be other technologies in the future to continue sharing music, movies, political wires, trade secrets and whatnot. Finally, in all those attempts to prevent crime, the ones that get penalized are mostly only the legitimate users.</p>
<p>How do you stop someone from committing fraud? The best way you could do this would be to implement an easy way to verify that the numbers balance out in periodical reports and to send an alert to request human oversight when something smells fishy. Heck, sometimes the fishyness is so well hidden that even the previous method wouldn't be enough. How far would you go, then to ban fraud? Would you force computers to kill any network connection that looks like it's about to change information in a suspicious way? Hah! that's not even effective. Actually, by doing so you run the risk of blocking totally legitimate transactions, and we all know that that would destroy the economy.</p>
<p>So the problem in my opinion is not about not having laws for copyright (or whatnot) that deal with new technology, it's actually about having laws that deal with a certain set of technology. And to go deeper, it's about using the wrong set of guidelines to set regulation: laws are meant to define <strong>what</strong> We, as a society, deem is acceptable or not; they should <strong>not</strong> be built with the focus on <strong>how</strong> to stop people from doing what is not acceptable.</p>
<p>So my conclusion will sound like a grandpa. To all of you lobbyists, law enforcers and judges: Get off my lawn!</p>