<?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>HEAVYWORKS &#187; Security</title>
	<atom:link href="http://www.heavyworks.net/blog/category/security/feed" rel="self" type="application/rss+xml" />
	<link>http://www.heavyworks.net</link>
	<description>Extreme Software Engineering</description>
	<lastBuildDate>Fri, 27 Aug 2010 01:55:58 +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>Scytale, a greek cryptography system implemented in C++</title>
		<link>http://www.heavyworks.net/blog/posts/scytale-a-greek-cryptography-implemented-in-c</link>
		<comments>http://www.heavyworks.net/blog/posts/scytale-a-greek-cryptography-implemented-in-c#comments</comments>
		<pubDate>Thu, 27 Aug 2009 04:39:30 +0000</pubDate>
		<dc:creator>Jan Seidl</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[cryptography]]></category>
		<category><![CDATA[scytale]]></category>
		<category><![CDATA[symmetric key]]></category>
		<category><![CDATA[transposition cypher]]></category>

		<guid isPermaLink="false">http://www.heavyworks.net/?p=264</guid>
		<description><![CDATA[During TISafe&#8216;s Security Officer training this month, while talking about cryptography, the Scytale technique came up. This was one of the first cryptography method with historical registry, used by the Greeks (Spartans, more specifically) to cypher messages during military campaigns thus not letting the enemy know their moves even if the message carrier gets caught, [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.heavyworks.net/wordpress/wp-content/uploads/skytale.jpg" alt="Scytale" title="Scytale" width="250" height="143" class="alignright size-full wp-image-265" />During <a href="http://www.tisafe.com">TISafe</a>&#8216;s <a href="http://en.wikipedia.org/wiki/Chief_security_officer">Security Officer</a> training this month, while talking about cryptography, the <a href="http://en.wikipedia.org/wiki/Scytale">Scytale</a> technique came up.</p>
<p>This was one of the first cryptography method with historical registry, used by the Greeks (Spartans, more specifically) to cypher messages during military campaigns thus not letting the enemy know their moves even if the message carrier gets caught, tortured or killed.<br />
<span id="more-264"></span></p>
<h2>The cypher</h2>
<p>A very simple approach implements <a href="http://en.wikipedia.org/wiki/Transposition_cipher">transposition cypher</a> with a strip of leather, cloth or paper around a baton. Baton diameter inflicts directly in the encryption result so we can say that it is this algorithm&#8217;s <a href="http://en.wikipedia.org/wiki/Symmetric-key_algorithm">symmetric key</a></p>
<h2>Encryption process</h2>
<p>To encrypt the message, the sender rolls the strip of leather (or cloth, or paper, etc) around his baton and draw the message (vertically, character by character) across the strips, going back to the first strip on the next &#8220;line&#8221; when writing to the last strip, like <a href="http://en.wikipedia.org/wiki/Word_wrap">word-wrap</a>.</p>
<p>This example from Wikipedia ilustrates well the concept:</p>
<blockquote>
<pre>
_____________________________________________________________
       |   |   |   |   |   |  |
       | H | E | L | P | M |  |
     __| E | I | A | M | U |__|
    |  | N | D | E | R | A |
    |  | T | T | A | C | K |
    |  |   |   |   |   |   |
_____________________________________________________________
</pre>
</blockquote>
<h2>Decryption process</h2>
<p>As most symmetrical-key cypher systems, the decryption process is given by reversing the encryption process with the same key applied. The person with a baton with the same diameter (the same key) would be able to roll the strip over it and decrypt the message.</p>
<h2>Key value restrictions</h2>
<p>For a baton with 1cm diameter, the message will look just like the original, so we will discard key values of <code>1</code>. The same occurs if key value is equal to the message length.</p>
<h2>The algorithm</h2>
<p>The key represents the number of characters in each line of text:</p>
<dl>
<dt>key value: <code>2</code></dt>
<dd>2 characters per line</dd>
<dt>key value: <code>4</code></dt>
<dd>4 characters per line</dd>
</dl>
<p>For the explanation of this algorithm we&#8217;ll encrypt the following message: &#8220;<b>HEAVYWORKS</b>&#8221; (nice huh?)</p>
<h3>Chunk split</h3>
<p>The message is split into chunks of <code>N</code> characters, being <code>N</code> being the key value.</p>
<table class="dataTable">
<thead>
<th>Original</th>
<th>Key <code>2</code></th>
<th>Key <code>3</code></th>
<th>Key <code>4</code></th>
</thead>
<tfoot>
</tfoot>
<tbody>
<tr>
<td>HEAVYWORKS</td>
<td>
<pre>
HE
AV
YW
OR
KS
</pre>
</td>
<td>
<pre>
HEA
VYW
ORK
S
</pre>
</td>
<td>
<pre>
HEAV
YWOR
KS
</pre>
</td>
</tr>
</tbody>
</table>
<h3>Key relation</h3>
<p>All the character sequences are now ordered in columns after we splitted the message in chunks with the length of the key value. You should realized already that the number of columns will be equal to the chunk length and thus the key value. </p>
<h3>Transposition</h3>
<p>The transposition is made by creating new (encrypted) chunks with the characters from each column. These chunks will be of the same length of the corresponding column.<br />
At the end of the process, all cyphered chunks are put together.</p>
<table class="dataTable">
<thead>
<th>&nbsp;</th>
<th>Key <code>2</code></th>
<th>Key <code>3</code></th>
<th>Key <code>4</code></th>
</thead>
<tfoot>
</tfoot>
<tbody>
<tr>
<td>Cyphered chunks</td>
<td>
<pre>HAYOK EVWRS</pre>
</td>
<td>
<pre>HVOS EYR AWK</pre>
</td>
<td>
<pre>HYK EWS AO VR</pre>
</td>
</tr>
<tr>
<td>Cyphered message</td>
<td>
<pre>HAYOKEVWRS</pre>
</td>
<td>
<pre>HVOSEYRAWK</pre>
</td>
<td>
<pre>HYKEWSAOVR</pre>
</td>
</tr>
</tbody>
</table>
<h2>The C++ Way</h2>
<p>The Scytale class got very simple, as the algorithm is very simple. It uses only three libraries: <code>iostream</code>, <code>vector</code> (for variable-length arrays) and <code>cmath</code> (for some <code>ceil</code> calculation).</p>
<p>The binary is called from command-line with the <code>-k</code> keylenght and <code>-m</code> message (quote escaped).</p>
<h3>Under the hood</h3>
<p>The <code>main</code> function fetches the options using GNU <code>getopts</code> and thus does some early input checking and error handling. </p>
<p>All OK, the key is set by Scytale&#8217;s class&#8217; <code>setKey</code> method and message is passed as a parameter to the <code>encrypt</code> method. From this point <code>validate</code> method is called in order to validate if the key and messages are fit into the needs on <code>try/catch</code> statements.</p>
<p>Passing the validation, the <code>createStack</code> method creates the character chunk stack (oh, really!?) from the plain-text message with two nested <code>for</code> laces (first for rows, second for char position) that is handled over to <code>scrambleStack</code> in order to perform the transposition with another two netsted <code>for</code> laces (now the first for column and the second for row).</p>
<p>Finally, the encrypted message</p>
<p><em>NOTE: If validation fails, program exits with a <code>EXIT_FAILURE</code> error code and the error message is echoed to <code>stderr</code>.</em></p>
<h3>Source</h3>
<p>The source file is well documented using a kind of <a href="http://java.sun.com/j2se/javadoc/">Javadoc</a> syntax and can be downloaded <a href="http://www.heavyworks.net/wordpress/wp-content/uploads/scripts/cryptography/algorithms/scytale/scytale.zip">here</a>.</p>
<h4>MD5 Sum</h4>
<p><code>a33edf6a4c4670380ce8c8e40edcb3d7  scytale.zip</code></p>
<h3>Compiling</h3>
<p>In order to compile with <code>g++</code> use the following line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">g++</span> <span style="color: #660033;">-Wall</span> <span style="color: #660033;">-ansi</span> <span style="color: #660033;">-pedantic</span> <span style="color: #660033;">-o</span> scytale scytale.cpp</pre></div></div>

<p><em>NOTE: I was not able to compile this under Windows XP with <a href="http://www.mingw.org/">MinGW</a>&#8216;s <code>g++</code>. Got compiling errors because of <code>getopts</code> and <code>vector</code>. If someone succeeds in compiling under Windows XP post a comment!</em></p>
<h2>Drawbacks</h2>
<p>This system cannot assure authenticity because it has no way to prove the author of the message so it can be crafted by the enemy that deduced, guessed or stolen the key.</p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.heavyworks.net/blog/posts/scytale-a-greek-cryptography-implemented-in-c/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Advanced SQL Injection</title>
		<link>http://www.heavyworks.net/blog/posts/advanced-sql-injection</link>
		<comments>http://www.heavyworks.net/blog/posts/advanced-sql-injection#comments</comments>
		<pubDate>Mon, 17 Aug 2009 04:58:03 +0000</pubDate>
		<dc:creator>Jan Seidl</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[pentest]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql injection]]></category>

		<guid isPermaLink="false">http://www.heavyworks.net/?p=259</guid>
		<description><![CDATA[Found that great video at LearnSecurityOnline.com of a presentation by one of its founders, Joseph McCray at Saecur&#8216;s DojoSec (monthly event hosted by Marcus Carey), earlier this year in February. Joseph speaks in a very well-humorous way about &#8220;Advanced SQL Injection&#8221; covering from Error-based SQL Injection to Blind SQL Injection, pretty nasty and nice! Gives [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Found that great video at <a href="http://www.learnsecurityonline.com/">LearnSecurityOnline.com</a> of a presentation by one of its founders, Joseph McCray at <a href="http://www.saecur.com/">Saecur</a>&#8216;s <a href="http://www.saecur.com/us/dojosec/">DojoSec</a> (monthly event hosted by Marcus Carey), earlier this year in February.</p>
<p>Joseph speaks in a very well-humorous way about &#8220;Advanced <acronym title="Structured Query Language">SQL</acronym> Injection&#8221; covering from Error-based <acronym title="Structured Query Language">SQL</acronym> Injection to Blind <acronym title="Structured Query Language">SQL</acronym> Injection, pretty nasty and nice! Gives another good overview under what we developers should look when protecting our code.</p>
<p>Here is the video:<br />
<object width="400" height="300"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=3418947&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=3418947&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object>
<p><a href="http://vimeo.com/3418947">DojoSec Monthly Briefings &#8211; February 2009 &#8211; Joseph McCray</a> from <a href="http://vimeo.com/marcuscarey">Marcus Carey</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>Don&#8217;t forget to check out other DojoSec videos at <a href="http://vimeo.com/marcuscarey">Marcus Carey</a>&#8216;s Vimeo channel and <a href="http://www.learnsecurityonline.com/">LearnSecurityOnline.com</a> to great security-related material!</p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.heavyworks.net/blog/posts/advanced-sql-injection/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick-tip: PHP mail() header misuse &#8220;vulnerability&#8221;</title>
		<link>http://www.heavyworks.net/blog/posts/quick-tip-php-mail-header-misuse-vulnerability</link>
		<comments>http://www.heavyworks.net/blog/posts/quick-tip-php-mail-header-misuse-vulnerability#comments</comments>
		<pubDate>Tue, 10 Mar 2009 17:59:36 +0000</pubDate>
		<dc:creator>Jan Seidl</dc:creator>
				<category><![CDATA[Quickies]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[email header]]></category>
		<category><![CDATA[exploiting]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xss]]></category>

		<guid isPermaLink="false">http://www.heavyworks.net/?p=139</guid>
		<description><![CDATA[When thinking about contact forms in PHP, people use to create a simple form that submits data to a simple script that calls PHP&#8217;s mail function. This function has the following parameters: mail&#40;$recipient, $subject, $message, $headers&#41;; Note the $headers part. Headers are meta information about the message that contains the sender, subject, date sent, CC, [...]


Related posts:<ol><li><a href='http://www.heavyworks.net/blog/posts/alternative-syntax-for-php-control-structures' rel='bookmark' title='Permanent Link: Alternative syntax for PHP control structures'>Alternative syntax for PHP control structures</a></li>
<li><a href='http://www.heavyworks.net/blog/posts/smartly-resolving-your-wordpress-pages-and-posts-javascript-and-css-dependences' rel='bookmark' title='Permanent Link: Smartly resolving your WordPress pages and posts JavaScript and CSS dependences'>Smartly resolving your WordPress pages and posts JavaScript and CSS dependences</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>When thinking about contact forms in <acronym title="PHP: Hypertext Preprocessor">PHP</acronym>, people use to create a simple form that submits data to a simple script that calls <acronym title="PHP: Hypertext Preprocessor">PHP</acronym>&#8217;s <code>mail</code> function.</p>
<p>This function has the following parameters:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$recipient</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Note the <code>$headers</code> part. Headers are meta information about the message that contains the sender, subject, date sent, <acronym title="Carbon-Copy">CC</acronym>, <acronym title="Blind Carbon-Copy">BCC</acronym>, the recipient name and other stuff that the mail deamons (and anti-spam software) puts and uses to track the email path from sender to recipient.</p>
<p>You may have noticed that I&#8217;ve put the word <em>vulnerability</em> between quotes. Yes, this is <strong>NOT</strong> a <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> function vulnerability but it becomes one when misused.</p>
<p>The fact is that as this function doesn&#8217;t have a <code>$from</code> parameter, people passes this information via the <code>$header</code> parameter as the following example.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;From: <span style="color: #006699; font-weight: bold;">{$_POST['name']}</span> &lt;<span style="color: #006699; font-weight: bold;">{$_POST['email']}</span>&gt;&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// &quot;From: SomeUser &lt;jon@doe.com&gt;&quot;</span></pre></div></div>

<p>This is our fail-point: <a href="http://www.php.net/magic_quotes"><acronym title="PHP: Hypertext Preprocessor">PHP</acronym> Magic Quotes</a> &#8220;protected&#8221; people from most XSS input attacks since it escapes quotes and stuff but as headers are separated by newlines (<code>\n</code>), the header can be easily spoofed by inputting:</p>

<div class="wp_syntax"><div class="code"><pre class="email" style="font-family:monospace;">Buy Viagra &lt;xx@xx.com&gt;\nBcc: email1, email2, email3″</pre></div></div>

<p>Note that I&#8217;ve added a <acronym title="Blind Carbon-Copy">BCC</acronym> entry and now the email is going to be sent to the email address specified under <code>$recipient</code> parameter at the <code>mail</code> function AND to my <acronym title="Blind Carbon-Copy">BCC</acronym> entries. </p>
<p><em>&#8220;Congratulations, your e-mail form (and server) is being used now to send my spam&#8221;</em><br />
(Just a quote, Heavyworks&#8217; ethics code would never let me SPAM!)</p>
<p><strong>Solution</strong><br />
Do not forward inputs directly to the header parameter or use a email class like <a href="http://phpmailer.codeworxtech.com/">Codeworx&#8217;s PHPMailer</a>.</p>
<p><em>NOTE: Learn more about e-mail headers at <a href="http://en.wikipedia.org/wiki/Email#Header" title="E-mail Headers">Wikipedia</a></em></p>
<p><em>There is a <a title="Segurança no envio de emails em PHP @ Ataraxia" href="http://www.ataraxia.com.br/posts/seguranca-no-envio-de-emails">Brazillian portuguese version of this vulnerability at Bruno&#8217;s Blog</a></em></p>

<p>Related posts:<ol><li><a href='http://www.heavyworks.net/blog/posts/alternative-syntax-for-php-control-structures' rel='bookmark' title='Permanent Link: Alternative syntax for PHP control structures'>Alternative syntax for PHP control structures</a></li>
<li><a href='http://www.heavyworks.net/blog/posts/smartly-resolving-your-wordpress-pages-and-posts-javascript-and-css-dependences' rel='bookmark' title='Permanent Link: Smartly resolving your WordPress pages and posts JavaScript and CSS dependences'>Smartly resolving your WordPress pages and posts JavaScript and CSS dependences</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.heavyworks.net/blog/posts/quick-tip-php-mail-header-misuse-vulnerability/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
