<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4093139800580227296</id><updated>2012-03-02T05:34:41.755-08:00</updated><title type='text'>Hooked on Mnemonics Worked for Me</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://hooked-on-mnemonics.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Alexander Hanel</name><uri>http://www.blogger.com/profile/14943273470531588187</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_fER_9l4iokM/SbA1HWjUNUI/AAAAAAAAAAM/TFFVhDX_YBA/S220/ihatealex1.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>12</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4093139800580227296.post-2234393964061676930</id><published>2012-02-19T13:55:00.000-08:00</published><updated>2012-02-19T14:01:14.833-08:00</updated><title type='text'>Visualizing RC4 Key Initialization</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-JPQ7UslDy3c/T0FXdcjDlvI/AAAAAAAAANQ/rzuSSmGNidk/s1600/example-A.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-JPQ7UslDy3c/T0FXdcjDlvI/AAAAAAAAANQ/rzuSSmGNidk/s1600/example-A.png" /&gt;&lt;/a&gt;&lt;/div&gt;Recently, I was curious about what the key initialization for RC4 key stream would look like visually. If you are unfamiliar with RC4 I would recommend Wikipedia's &lt;a href="http://en.wikipedia.org/wiki/RC4" target="_blank"&gt;article&lt;/a&gt;. What I'm focusing on in this post is the key scheduling algorithm. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Key scheduling algorithm:&lt;/b&gt;&lt;br /&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;for&lt;/span&gt; i from &lt;span style="color: #008c00;"&gt;0&lt;/span&gt; to &lt;span style="color: #008c00;"&gt;255&lt;/span&gt;&lt;br /&gt;    S&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;i&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt; &lt;span style="color: #808030;"&gt;:&lt;/span&gt;= i&lt;br /&gt;&lt;br /&gt;endfor&lt;br /&gt;j &lt;span style="color: #808030;"&gt;:&lt;/span&gt;= &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;for&lt;/span&gt; i from &lt;span style="color: #008c00;"&gt;0&lt;/span&gt; to &lt;span style="color: #008c00;"&gt;255&lt;/span&gt;&lt;br /&gt;    j &lt;span style="color: #808030;"&gt;:&lt;/span&gt;= &lt;span style="color: purple;"&gt;(&lt;/span&gt;j + S&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;i&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt; + key&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;i mod keylength&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;span style="color: purple;"&gt;)&lt;/span&gt; mod &lt;span style="color: #008c00;"&gt;256&lt;/span&gt;&lt;br /&gt;    swap values of S&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;i&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt; and S&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;j&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;endfor&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;What I found interesting about this algorithm is it originally starts with a 256 bytes array/list in sequential order (0,1,2,3,4...253,254,255). This range could be represented in the form of a gradient. The above image is the visual representation of each loop of the key stream. The bottom left hand corner from left to right is the initial sequential list. The loop iterates 256 times. Each time the loop iterates the key stream is modified.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-_9i8pIidTbE/T0FYxxb2emI/AAAAAAAAANY/N1O68nlGLxY/s1600/example-B.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-_9i8pIidTbE/T0FYxxb2emI/AAAAAAAAANY/N1O68nlGLxY/s1600/example-B.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Another image with the char 'B' as the key. The very top row is the complete key stream from the key-scheduling algorithm. &lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-068RRTnvcjc/T0FbrFAsnII/AAAAAAAAANg/GGHsVoCujLQ/s1600/example-Z.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-068RRTnvcjc/T0FbrFAsnII/AAAAAAAAANg/GGHsVoCujLQ/s1600/example-Z.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;pre style="background: #ffffff; color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;Another image with the char 'Z' as the key. The above image was created in Python using matplotlib. The code will iterate through chars from 'A' to 'Z'. The images will be saved with a file name of example-char.png. &lt;br /&gt;&lt;pre style="background: none repeat scroll 0% 0% rgb(255, 255, 255); color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;&lt;pre style="background: none repeat scroll 0% 0% rgb(255, 255, 255); color: black;"&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;import&lt;/span&gt; matplotlib&lt;span style="color: #808030;"&gt;.&lt;/span&gt;pyplot as plt&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;import&lt;/span&gt; numpy as np&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;import&lt;/span&gt; random&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;import&lt;/span&gt; sys&lt;br /&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;def&lt;/span&gt; rc4_init&lt;span style="color: #808030;"&gt;(&lt;/span&gt;key&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: dimgrey;"&gt;# creates a list of the stream for each loop of the key stream &lt;/span&gt;&lt;br /&gt;    c &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;br /&gt;    k &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;range&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;256&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    j &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;br /&gt;    x &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;br /&gt;    x &lt;span style="color: #808030;"&gt;=&lt;/span&gt; x &lt;span style="color: #808030;"&gt;+&lt;/span&gt; k&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;for&lt;/span&gt; i &lt;span style="color: maroon; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;range&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;256&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;:&lt;/span&gt;&lt;br /&gt;        j &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;j &lt;span style="color: #808030;"&gt;+&lt;/span&gt; k&lt;span style="color: #808030;"&gt;[&lt;/span&gt;i&lt;span style="color: #808030;"&gt;]&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;ord&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;key&lt;span style="color: #808030;"&gt;[&lt;/span&gt;i &lt;span style="color: #808030;"&gt;%&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;len&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;key&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;%&lt;/span&gt; &lt;span style="color: #008c00;"&gt;256&lt;/span&gt;&lt;br /&gt;        k&lt;span style="color: #808030;"&gt;[&lt;/span&gt;i&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; k&lt;span style="color: #808030;"&gt;[&lt;/span&gt;j&lt;span style="color: #808030;"&gt;]&lt;/span&gt; &lt;span style="color: #808030;"&gt;=&lt;/span&gt; k&lt;span style="color: #808030;"&gt;[&lt;/span&gt;j&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt; k&lt;span style="color: #808030;"&gt;[&lt;/span&gt;i&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;br /&gt;        x &lt;span style="color: #808030;"&gt;=&lt;/span&gt; x &lt;span style="color: #808030;"&gt;+&lt;/span&gt; k&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;return&lt;/span&gt; x&lt;br /&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;def&lt;/span&gt; createImage&lt;span style="color: #808030;"&gt;(&lt;/span&gt;key&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: dimgrey;"&gt;# get list of RC4 key values size (256*257)&lt;/span&gt;&lt;br /&gt;    data &lt;span style="color: #808030;"&gt;=&lt;/span&gt; np&lt;span style="color: #808030;"&gt;.&lt;/span&gt;array&lt;span style="color: #808030;"&gt;(&lt;/span&gt;rc4_init&lt;span style="color: #808030;"&gt;(&lt;/span&gt;key&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    data&lt;span style="color: #808030;"&gt;.&lt;/span&gt;shape &lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;257&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;span style="color: #008c00;"&gt;256&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: dimgrey;"&gt;# use heat map &lt;/span&gt;&lt;br /&gt;    plt&lt;span style="color: #808030;"&gt;.&lt;/span&gt;hot&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    plt&lt;span style="color: #808030;"&gt;.&lt;/span&gt;ylabel&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;'Loop Iteration'&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    plt&lt;span style="color: #808030;"&gt;.&lt;/span&gt;xlabel&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;'Array Value 0-256'&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    plt&lt;span style="color: #808030;"&gt;.&lt;/span&gt;title&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;'RC4 Key Initialize with Value of '&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; &lt;span style="color: #0000e6;"&gt;'\''&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;str&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;key&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; &lt;span style="color: #0000e6;"&gt;'\''&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;    &lt;br /&gt;    plt&lt;span style="color: #808030;"&gt;.&lt;/span&gt;axis&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;span style="color: #008c00;"&gt;256&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;span style="color: #008c00;"&gt;257&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    plt&lt;span style="color: #808030;"&gt;.&lt;/span&gt;pcolormesh&lt;span style="color: #808030;"&gt;(&lt;/span&gt;data&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    plt&lt;span style="color: #808030;"&gt;.&lt;/span&gt;colorbar&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: dimgrey;"&gt;#plt.show()&lt;/span&gt;&lt;br /&gt;    plt&lt;span style="color: #808030;"&gt;.&lt;/span&gt;savefig&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #0000e6;"&gt;'example-'&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;str&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;key&lt;span style="color: #808030;"&gt;)&lt;/span&gt; &lt;span style="color: #808030;"&gt;+&lt;/span&gt; &lt;span style="color: #0000e6;"&gt;'.png'&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;    plt&lt;span style="color: #808030;"&gt;.&lt;/span&gt;close&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;def&lt;/span&gt; main&lt;span style="color: #808030;"&gt;(&lt;/span&gt;argv&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: maroon; font-weight: bold;"&gt;for&lt;/span&gt; x &lt;span style="color: maroon; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;range&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;65&lt;/span&gt;&lt;span style="color: #808030;"&gt;,&lt;/span&gt;&lt;span style="color: #008c00;"&gt;91&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;:&lt;/span&gt;&lt;br /&gt;        createImage&lt;span style="color: #808030;"&gt;(&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;chr&lt;/span&gt;&lt;span style="color: #808030;"&gt;(&lt;/span&gt;x&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: maroon; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;__name__&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt;&lt;span style="color: #808030;"&gt;=&lt;/span&gt; &lt;span style="color: #0000e6;"&gt;'__main__'&lt;/span&gt;&lt;span style="color: #808030;"&gt;:&lt;/span&gt;&lt;br /&gt;        main&lt;span style="color: #808030;"&gt;(&lt;/span&gt;sys&lt;span style="color: #808030;"&gt;.&lt;/span&gt;argv&lt;span style="color: #808030;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #808030;"&gt;:&lt;/span&gt;&lt;span style="color: #808030;"&gt;]&lt;/span&gt;&lt;span style="color: #808030;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Visually I think this is pretty cool. I decided to take it a step further and create an animated gif. The .gif displays the image with value keys of 'A' through 'Z'. Warning the .gif is over 2MBs in size.&lt;a href="http://dl.dropbox.com/u/243193/RC4.gif" target="_blank"&gt; LINK&lt;/a&gt; Odds are my terminology is off in some of the description of the algorithm. Please feel free to leave comments if you see one. &lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4093139800580227296-2234393964061676930?l=hooked-on-mnemonics.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hooked-on-mnemonics.blogspot.com/feeds/2234393964061676930/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2012/02/visualizing-rc4-key-initialization.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/2234393964061676930'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/2234393964061676930'/><link rel='alternate' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2012/02/visualizing-rc4-key-initialization.html' title='Visualizing RC4 Key Initialization'/><author><name>Alexander Hanel</name><uri>http://www.blogger.com/profile/14943273470531588187</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_fER_9l4iokM/SbA1HWjUNUI/AAAAAAAAAAM/TFFVhDX_YBA/S220/ihatealex1.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-JPQ7UslDy3c/T0FXdcjDlvI/AAAAAAAAANQ/rzuSSmGNidk/s72-c/example-A.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4093139800580227296.post-428708377961088419</id><published>2012-02-10T23:59:00.000-08:00</published><updated>2012-02-13T19:00:28.205-08:00</updated><title type='text'>Shellcode Extraction, Automated Decoding and Carving using Pefile</title><content type='html'>A little while back a friend of mine asked about a tool for carving out executables from file streams. PE carvers are useful for analyst who spend time analyzing files on the command line or extracting PE files from malicious documents. The initial post was going to be a simple Python script using Pefile for carving out executables. The simplicity was destroyed when I choose a random sample that used an offset specific encoding. I could have chosen another sample with a simpler encoding but that's boring. This post will cover three main topics. The first one is extracting and analyzing the shellcode from a malicious document CVE-2010-3333. The second  is using patterns from encoding null bytes for automatically decoding (xor-count-up) embedded files. No static analysis or brute-forcing is used. The last topic is using Pefile for carving out executable files from file streams. This post is all Python except for the hexdump which is vim.&lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;vim CVE-2010-3333_DOC.bad&lt;br /&gt;&lt;br /&gt;{\rtf1{\shp{\*\shpinst{\sp{\sn pFragments}{\sv 1;1;ffffffffff050000000000000000000000..&lt;br /&gt;..&lt;br /&gt;&lt;br /&gt;:Vi can be used as a hexdump with the following command &lt;br /&gt;:%!xxd &lt;br /&gt;&lt;br /&gt;0000000: 7b5c 7274 6631 7b5c 7368 707b 5c2a 5c73  {\rtf1{\shp{\*\s&lt;br /&gt;0000010: 6870 696e 7374 7b5c 7370 7b5c 736e 2070  hpinst{\sp{\sn p&lt;br /&gt;0000020: 4672 6167 6d65 6e74 737d 7b5c 7376 2031  Fragments}{\sv 1&lt;br /&gt;0000030: 3b31 3b66 6666 6666 6666 6666 6630 3530  ;1;ffffffffff050&lt;br /&gt;0000040: 3030 3030 3030 3030 3030 3030 3030 3030  0000000000000000&lt;br /&gt;0000050: 3030 3030 3030 3030 3030 3030 3030 3030  0000000000000000&lt;br /&gt;0000060: 3030 3030 3030 3062 3735 6631 6637 6430  0000000b75f1f7d0&lt;br /&gt;0000070: 3030 3038 3037 6330 3030 3038 3037 6342  000807c0000807cB&lt;br /&gt;0000080: 4242 4242 4242 4243 4343 4343 4343 4344  BBBBBBBCCCCCCCCD&lt;br /&gt;0000090: 4444 4444 4444 4439 3039 3039 3039 3039  DDDDDDD909090909&lt;br /&gt;00000a0: 3039 3034 3134 3134 3134 3134 3134 3134  0904141414141414&lt;br /&gt;00000b0: 3134 3134 3134 3134 3134 3165 3830 3130  14141414141e8010&lt;br /&gt;....&lt;br /&gt;0000740: 6239 3838 3730 6436 3730 6439 3839 3833  b98870d670d98983&lt;br /&gt;0000750: 3038 3366 3766 3766 3766 3766 3766 3766  083f7f7f7f7f7f7f&lt;br /&gt;0000760: 3765 6230 3665 6230 3430 3932 3330 3033  7eb06eb040923003&lt;br /&gt;0000770: 3065 6230 3665 6230 3438 6332 3430 3033  0eb06eb048c24003&lt;br /&gt;0000780: 3065 3837 3766 3466 6666 667d 7d7d 7d5c  0e877f4ffff}}}}\&lt;br /&gt;0000790: 6164 6566 6c61 6e67 3130 3235 5c61 6e73  adeflang1025\ans&lt;br /&gt;00007a0: 695c 616e 7369 6370 6739 3336 5c75 6332  i\ansicpg936\uc2&lt;br /&gt;00007b0: 5c61 6465 6666 3331 3530 375c 6465 6666  \adeff31507\def&lt;br /&gt;.....&lt;br /&gt;:%!xxd -r &lt;br /&gt;:q!&lt;br /&gt;&lt;/pre&gt;Some quick notes in regards to CVE-2010-3333 via &lt;a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-3333" target="_blank"&gt;Mitre&lt;/a&gt; "Stack-based buffer overflow in Microsoft Office XP SP3, Office 2003 SP3, Office 2007 SP2, Office 2010, Office 2004 and 2008 for Mac, Office for Mac 2011, and Open XML File Format Converter for Mac allows remote attackers to execute arbitrary code via crafted RTF data, aka "RTF Stack Buffer Overflow Vulnerability."&lt;br /&gt;&lt;br /&gt;The intent of this post is not to analyze CVE-2010-3333 but rather the encoding algorithm in the shellcode. For more information on the exploit see the following &lt;a href="http://labs.m86security.com/2011/07/resurrection-of-cve-2010-3333-in-the-wild/" target="_blank"&gt;link&lt;/a&gt;. The most relevant parts are the rtf file header, the fragment objects (pFragments) and the data following the semicolon. The shellcode resides in the large ascii data block in the range 0-9A-F. If we read two ASCII chars and then treat them as hex/binary we would have valid Intel instructions. Let's see what this would look like in Python&lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;Python &lt;span style="color: #009f00;"&gt;2.7&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;r27&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #008c00;"&gt;82525&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; Jul  &lt;span style="color: #008c00;"&gt;4&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2010&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;09&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #008c00;"&gt;01&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #008c00;"&gt;59&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;MSC v&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1500&lt;/span&gt; &lt;span style="color: #008c00;"&gt;32&lt;/span&gt; bit &lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;Intel&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt; on win32&lt;br /&gt;Type &lt;span style="color: #00c4c4;"&gt;"copyright"&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;"credits"&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;or&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;"license()"&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;for&lt;/span&gt; more information&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; sys&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; os&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; pydasm&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #9999a9;"&gt;# Open our specimen &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; f &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;open&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;"CVE-2010-3333_DOC.bad"&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;"rb"&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;seek&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x97&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #9999a9;"&gt;# 0x97 is the start of the ascii encoded shellcode&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; b &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; buff &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;""&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;while&lt;/span&gt; b &lt;span style="color: #d2cd86;"&gt;!&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;''&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        buff &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; buff&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;chr&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;int&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;b&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #008c00;"&gt;16&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        b &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;ValueError&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;break&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;The variable buff contains our ascii to binary shellcode. We can use Pydasm to disassemble it.&lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; offset &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;while&lt;/span&gt; offset &lt;span style="color: #d2cd86;"&gt;&amp;lt;&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;len&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;buff&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;    i &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; pydasm&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;get_instruction&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;buff&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;offset&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;pydasm&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;MODE_32&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; offset &lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;' '&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;pydasm&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;get_instruction_string&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;i&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;pydasm&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;FORMAT_INTEL&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; offset&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;not&lt;/span&gt; i&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;break&lt;/span&gt;&lt;br /&gt;    offset &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;  i&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;length&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #008c00;"&gt;2&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #008c00;"&gt;3&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #008c00;"&gt;4&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #008c00;"&gt;5&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #008c00;"&gt;6&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #008c00;"&gt;7&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #008c00;"&gt;8&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #008c00;"&gt;9&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #008c00;"&gt;10&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #008c00;"&gt;11&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #008c00;"&gt;12&lt;/span&gt;   call &lt;span style="color: #00a800;"&gt;0x12&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008c00;"&gt;17&lt;/span&gt;   add &lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;ebx&lt;span style="color: #d2cd86;"&gt;-&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x3b7cdbf4&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;cl&lt;br /&gt;&lt;span style="color: #008c00;"&gt;23&lt;/span&gt;   add al&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x8d&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008c00;"&gt;25&lt;/span&gt;   dec ecx&lt;br /&gt;&lt;span style="color: #008c00;"&gt;26&lt;/span&gt;   adc al&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;ecx&lt;span style="color: #d2cd86;"&gt;-&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x80&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008c00;"&gt;29&lt;/span&gt;   xor &lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;edi&lt;span style="color: #d2cd86;"&gt;-&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x80&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;esp&lt;br /&gt;&lt;span style="color: #008c00;"&gt;32&lt;/span&gt;   &lt;span style="color: #e34adc;"&gt;cmp&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;eax&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x600df775&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;edx&lt;br /&gt;&lt;span style="color: #008c00;"&gt;38&lt;/span&gt;   psubd mm6&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;esi&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008c00;"&gt;85&lt;/span&gt;   push dword &lt;span style="color: #00a800;"&gt;0x1300f74&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008c00;"&gt;90&lt;/span&gt;   push byte &lt;span style="color: #00a800;"&gt;0xffffff98&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008c00;"&gt;92&lt;/span&gt;   &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;Notice after address 12 the code turns to junk instructions. This is caused by our disassembly being off by 1 byte after the call. We can modify our pydasm loop to skip this null byte.&lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; offset &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;while&lt;/span&gt; offset &lt;span style="color: #d2cd86;"&gt;&amp;lt;&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;len&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;buff&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;    i &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; pydasm&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;get_instruction&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;buff&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;offset&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;pydasm&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;MODE_32&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;hex&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;offset&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;' '&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;pydasm&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;get_instruction_string&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;i&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;pydasm&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;FORMAT_INTEL&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; offset&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;not&lt;/span&gt; i&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;break&lt;/span&gt;&lt;br /&gt;    offset &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;  i&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;length&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; offset &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;17&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        offset &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x0&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x2&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x3&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x4&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x5&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x6&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x7&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x8&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x9&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xa&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xb&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xc&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   call &lt;span style="color: #00a800;"&gt;0x12&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x12&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   mov ecx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;esp&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x15&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   add esp&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x4&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x18&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   lea ecx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;ecx&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x12&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1b&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1c&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   xor byte &lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;ecx&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x67&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1f&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   &lt;span style="color: #e34adc;"&gt;cmp&lt;/span&gt; byte &lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;ecx&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x90&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x22&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   jnz &lt;span style="color: #00a800;"&gt;0x1b&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x24&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   &lt;span style="color: #e66170; font-weight: bold;"&gt;or&lt;/span&gt; eax&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x36fa0f60&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x53&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   aad &lt;span style="color: #00a800;"&gt;0x51&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x55&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   push dword &lt;span style="color: #00a800;"&gt;0x1300f74&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x5a&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   push byte &lt;span style="color: #00a800;"&gt;0xffffff98&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x5c&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;Note: address changes to hex. At the address 0x12 we can see the start of the XOR loop with a key of 0x67. The rest of the code is junk due to it being XORed. The next step to get to the second stage of the shellcode.&lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; buff2 &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; buff&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #008c00;"&gt;35&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# Read past XOR loop&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; c &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;36&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;while&lt;/span&gt; c &lt;span style="color: #d2cd86;"&gt;&amp;lt;&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;len&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;buff&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;-&lt;/span&gt;&lt;span style="color: #008c00;"&gt;36&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;    buff2 &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;  buff2 &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;chr&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;ord&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;buff&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;c&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;^&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x67&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    c &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;The above code is a simple XOR loop. Now we can dissasemble the second stage using Pydasm&lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; offset &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;while&lt;/span&gt; offset &lt;span style="color: #d2cd86;"&gt;&amp;lt;&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;len&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;buff2&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        i &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; pydasm&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;get_instruction&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;buff2&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;offset&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;pydasm&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;MODE_32&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;hex&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;offset&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;' '&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;pydasm&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;get_instruction_string&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;i&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;pydasm&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;FORMAT_INTEL&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; offset&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;not&lt;/span&gt; i&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;break&lt;/span&gt;&lt;br /&gt;        offset &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;  i&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;length&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; offset &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;17&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            offset &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x0&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x2&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x3&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x4&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x5&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x6&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x7&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x8&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x9&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xa&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xb&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xc&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   call &lt;span style="color: #00a800;"&gt;0x12&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x12&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   mov ecx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;esp&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x15&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   add esp&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x4&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x18&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   lea ecx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;ecx&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x12&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1b&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1c&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   xor byte &lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;ecx&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x67&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1f&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   &lt;span style="color: #e34adc;"&gt;cmp&lt;/span&gt; byte &lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;ecx&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x90&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x22&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   jnz &lt;span style="color: #00a800;"&gt;0x8e&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x24&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   pop es&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x25&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   push dword &lt;span style="color: #00a800;"&gt;0x3519d&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x2a&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   push dword &lt;span style="color: #00a800;"&gt;0x2d000&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x2f&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   push dword &lt;span style="color: #00a800;"&gt;0x819d&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x8f&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   xor edx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;edx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x91&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   mov ebx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;fs&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;edx&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x30&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;    &lt;span style="color: #d2cd86;"&gt;;&lt;/span&gt; GET PEB&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x95&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   mov ecx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;ebx&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0xc&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x98&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   mov ecx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;ecx&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x1c&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xba&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   mov esi&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;ebx&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;edi&lt;span style="color: #d2cd86;"&gt;*&lt;/span&gt;&lt;span style="color: #008c00;"&gt;4&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xbd&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   add esi&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;ebp&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xbf&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   cwd &lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xc0&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   movsx eax&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;esi&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xc3&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   &lt;span style="color: #e34adc;"&gt;cmp&lt;/span&gt; al&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;ah&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xc5&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   jz &lt;span style="color: #00a800;"&gt;0xcf&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xc7&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   ror edx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x7&lt;/span&gt;        &lt;span style="color: #d2cd86;"&gt;;&lt;/span&gt; ROR API HASH&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xca&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   add edx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;eax&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xcc&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc esi&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0xcd&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   jmp &lt;span style="color: #00a800;"&gt;0xc0&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1b1&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   mov &lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;ebp&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x604&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;ebx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1b7&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   xor ecx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1b9&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   lea esi&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;ebp&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;ecx&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x200&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1c0&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   lodsb &lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1c1&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   xor al&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;cl            &lt;span style="color: #d2cd86;"&gt;;&lt;/span&gt; decode&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1c3&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   xchg edx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;edi&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1c5&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   lea edi&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;ebp&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;ecx&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x200&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1cc&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   stosb &lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1cd&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   xchg edx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;edi&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1cf&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc ecx&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1d0&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   &lt;span style="color: #e34adc;"&gt;cmp&lt;/span&gt; ecx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;ebp&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x604&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x1d6&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   jnz &lt;span style="color: #00a800;"&gt;0x1b9&lt;/span&gt;            &lt;span style="color: #d2cd86;"&gt;;&lt;/span&gt; loop&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x34e&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   push ebp&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x34f&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   mov ebp&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;esp&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x351&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   mov eax&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;edi&lt;span style="color: #d2cd86;"&gt;-&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0x14&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #00a800;"&gt;0x354&lt;/span&gt;&lt;span style="color: #006600;"&gt;L&lt;/span&gt;   inc &lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;eax&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;Now that we have our shellcode. If we scroll up we will see a loop with xor al, cl and then an inc ecx. This is our xor-count-up loop. This type of encoding can be tricky because we have to know the exact offset of where the loop starts decoding data.  Usually this means we would have to do some good old fashioned static analysis. There's only so many times we can reverse shellcode until you get bored. Let's get creative. Let's try something that hasn't been done before (probably wrong?). We know it's a xor-count-up so let's mimic the pattern the XOR would create in null data.&lt;br /&gt;&lt;pre style="background: none repeat scroll 0% 0% rgb(0, 0, 0); color: #d1d1d1;"&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; o  &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;open&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'out.bin'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'wb+'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; d &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; k &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;''&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;for&lt;/span&gt; x &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;range&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0xff&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        k &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; k &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;chr&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;x&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; k&lt;br /&gt;&lt;span style="color: #00c4c4;"&gt;'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r...'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;&lt;br /&gt;# Get subset of the full XOR-Countup outpu&lt;/span&gt;&lt;/pre&gt;&lt;pre style="background: none repeat scroll 0% 0% rgb(0, 0, 0); color: #d1d1d1;"&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;  key &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; k&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #008c00;"&gt;15&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;Note: The k value was edited due to formatting issues.&amp;nbsp; For a&amp;nbsp; screenshot of the output please see the following &lt;a href="http://i.imgur.com/P5psI.png" target="_blank"&gt;link&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;This is where things get kind of interesting with the encoding. Firstly we are going to do a search for a subset (key) of the recurring pattern (k). The pattern would appear on null bytes that have been XORed with count-up. We choose a subset because the full pattern would not likely be present because the null bytes would need to have a length of 255. If we know the address of k and the algorithm we can calculate the one to one relationship of the first value 0x0-0xFF to the first byte of the file. Once we have that information we will just need to mimic the xor-count-up code from the start of the file.&lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #9999a9;"&gt;#  &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; i &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0xff&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;-&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;d&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;find&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;key&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0xff&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; &lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; b&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;''&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;for&lt;/span&gt; val &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; d&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        b &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;str&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;b&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;chr&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;ord&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;val&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;^&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;i&lt;span style="color: #d2cd86;"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color: #00a800;"&gt;0xff&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        i &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; o&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;write&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;b&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; o&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;close&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;close&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;/pre&gt;Let's see what our saved off buffer looks like in a VIM hexdump.&lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;vim out.bin&lt;br /&gt;0000000: 8d8c ae92 9090 909b 9997 9dca cccf cba3  ................&lt;br /&gt;0000010: 616f 716a 5864 6874 616a 7a6c 353e 3853  aoqjXdhtajzl5&amp;gt;8S&lt;br /&gt;0000020: 6572 204f 7571 7371 7e2a 2b2e 2c2a 427b  er Ouqsq~*+.,*B{&lt;br /&gt;0000030: 4547 4413 7856 5254 404f 4e49 4f45 1d1e  EGD.xVRT@ONIOE..&lt;br /&gt;0000040: 0501 076f 4741 455f 5e55 5558 540e 0f0a  ...oGAE_^UUXT...&lt;br /&gt;0000050: 7077 1e30 3036 2e21 2020 2923 7f7c 7b7f  pw.006.!  )#.|{.&lt;br /&gt;0000060: 660d 2127 273d 3035 316a 6b6e 6c6a 023b  f.!''=051jknlj.;&lt;br /&gt;..&lt;br /&gt;:/This&lt;br /&gt;00255b0: 0000 0000 0408 b004 4d5a 9000 0300 0000  ........MZ......&lt;br /&gt;00255c0: 0400 0000 ffff 0000 b800 0000 0000 0000  ................&lt;br /&gt;00255d0: 4000 0000 0000 0000 0000 0000 0000 0000  @...............&lt;br /&gt;00255e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................&lt;br /&gt;00255f0: 0000 0000 f000 0000 0e1f ba0e 00b4 09cd  ................&lt;br /&gt;0025600: 21b8 014c cd21 5468 6973 2070 726f 6772  !..L.!This progr&lt;br /&gt;0025610: 616d 2063 616e 6e6f 7420 6265 2072 756e  am cannot be run&lt;br /&gt;0025620: 2069 6e20 444f 5320 6d6f 6465 2e0d 0d0a   in DOS mode....&lt;br /&gt;0025630: 2400 0000 0000 0000 b3bf 303a f7de 5e69  $.........0:..^i&lt;br /&gt;:q!&lt;br /&gt;&lt;/pre&gt;Yeah, that's hot. Now that we have the file decoded we can carve out the executable from the data stream. The first indicator for an embedded executable is the MZ header. If we find the MZ header we would need to jump 0x3c bytes, read the value, jump to that value, check for the PE header... or we could use &lt;a href="http://code.google.com/p/pefile/" target="_blank"&gt;pefile&lt;/a&gt; to validate the PE file for us. All we need to do is search a stream of data for the MZ header, set the file pointer to that address, read till end of file, pass the data to pefile and then check for errors. If there is no errors we will have pefile trim the file and then write it to disk. This might not be the best method if the file is large or if we were overly concerned about file overlays.&lt;br /&gt;&lt;pre style="background: none repeat scroll 0% 0% rgb(0, 0, 0); color: #d1d1d1;"&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; pefile&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; re&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; sys&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; carve&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;    c &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;for&lt;/span&gt; y &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;tmp&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;start&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;for&lt;/span&gt; tmp &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; re&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;finditer&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'\x4d\x5a'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;seek&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;y&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            pe &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; pefile&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;PE&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;data&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;pass&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;continue&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #9999a9;"&gt;# determine file ext&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; pe&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;is_dll&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;True&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            ext &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'dll'&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; pe&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;is_driver&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;True&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            ext &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;  &lt;span style="color: #00c4c4;"&gt;'sys'&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; pe&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;is_exe&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;True&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            ext &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'exe'&lt;/span&gt;&lt;br /&gt;        o &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;open&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;str&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;c&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'.'&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; ext&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'wb'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; ext &lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'found at offset'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;hex&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;y&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;br /&gt;        o&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;write&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;pe&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;trim&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        o&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;close&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        c &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; c &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; &lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;br /&gt;        ext &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;''&lt;/span&gt;&lt;br /&gt;        f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;seek&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        pe&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;close&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; main&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;argv&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;len&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;sys&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;argv&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;&amp;lt;&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;"cpe.py &amp;lt;file-stream&amp;gt;"&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;else&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        i &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;open&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;sys&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;argv&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;"rb"&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        carve&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;i&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        i&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;close&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;__name__&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'__main__'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        main&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;sys&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;argv&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;Output from the above script on the out.bin&lt;br /&gt;&lt;pre style="background: none repeat scroll 0% 0% rgb(0, 0, 0); color: #d1d1d1;"&gt;python cpe.py out.bin&lt;br /&gt;exe found at offset 0x7a10&lt;br /&gt;dll found at offset 0x255b8&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4093139800580227296-428708377961088419?l=hooked-on-mnemonics.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hooked-on-mnemonics.blogspot.com/feeds/428708377961088419/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2012/02/shellcode-extraction-automated-decoding.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/428708377961088419'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/428708377961088419'/><link rel='alternate' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2012/02/shellcode-extraction-automated-decoding.html' title='Shellcode Extraction, Automated Decoding and Carving using Pefile'/><author><name>Alexander Hanel</name><uri>http://www.blogger.com/profile/14943273470531588187</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_fER_9l4iokM/SbA1HWjUNUI/AAAAAAAAAAM/TFFVhDX_YBA/S220/ihatealex1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4093139800580227296.post-7328135125739552445</id><published>2011-12-18T08:35:00.000-08:00</published><updated>2011-12-18T08:49:48.431-08:00</updated><title type='text'>Yara + MD5</title><content type='html'>There seems to be a good amount of people searching for &lt;a href="http://code.google.com/p/yara-project/" target="_blank"&gt;Yara &lt;/a&gt;+ &lt;a href="http://en.wikipedia.org/wiki/MD5" target="_blank"&gt;MD5 &lt;/a&gt;and landing on this blog. Yara does not support MD5 hashing. There are a couple options for detecting files via MD5. One solution is to write a md5 scanner using your favorite programming language, the second is to use ClamAV and another is to use Yara and Python. Below is a quick demonstration of the later. Let's assume we already have the MD5 hash of a bad file A1EB325F994E5A1720C0E401731B5ED9 . We will now need to create a Yara rule with the MD5 hash as a string. &lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;rule MD5_BAD_FILE&lt;br /&gt;&lt;span style="color: #b060b0;"&gt;{&lt;/span&gt;&amp;nbsp; &lt;br /&gt;strings&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $md5 &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;"A1EB325F994E5A1720C0E401731B5ED9"&lt;/span&gt; nocase&lt;br /&gt;condition&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $md5&lt;br /&gt;&lt;span style="color: #b060b0;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;The Yara rule will alert on the string of the MD5 hash. Now we need some code that will open a file, hash the file and then scan the hash value using the Yara rule. &lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; hashlib&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; sys&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; imp&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; yara &lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; MD5&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;d&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# d = buffer of the read file &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# This function hashes the buffer&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# source: http://stackoverflow.com/q/5853830&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;type&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;d&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;is&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;str&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; d &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; StringIO&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;d&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; md5 &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; hashlib&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;md5&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;while&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;True&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; d&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;128&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;not&lt;/span&gt; data&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;break&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; md5&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;update&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;data&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; md5&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;hexdigest&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; yaraScan&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;d&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# d = buffer of the read file &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# Scans SWF using Yara&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #9999a9;"&gt;# test if yara module is installed&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #9999a9;"&gt;# if not Yara can be downloaded from http://code.google.com/p/yara-project/&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; imp&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;find_module&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'yara'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; yara &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;ImportError&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[ERROR] Yara module not installed - aborting scan'&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #9999a9;"&gt;# test for yara compile errors&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; yara&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;compile&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;r'md5.yara'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;pass&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[ERROR] Yara compile error - aborting scan'&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #9999a9;"&gt;# get matches&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; r&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;match&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;data&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;d&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #9999a9;"&gt;# print matches&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;for&lt;/span&gt; X &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; m&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[BAD] Yara Signature Hit:'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; X&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; main&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;open&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;sys&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;argv&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;len&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;sys&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;argv&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;-&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'rb+'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;Exception&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'[ERROR] File can not be opended/accessed'&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; yaraScan&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;MD5&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;__name__&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'__main__'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; main&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;/pre&gt;Example&lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;C:\Documents and Settings\XOR\My Documents\Projects\yaramd5&amp;gt;python yaraMD5.py "6UHp0dCM12c[1].swf"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [BAD] Yara Signature Hit: MD5_BAD_FILE&lt;/pre&gt;Most of the code is from &lt;a href="http://hooked-on-mnemonics.blogspot.com/2011/12/xxxswfpy.html" target="_blank"&gt;xxxswf.py. &lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4093139800580227296-7328135125739552445?l=hooked-on-mnemonics.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hooked-on-mnemonics.blogspot.com/feeds/7328135125739552445/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2011/12/yara-md5.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/7328135125739552445'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/7328135125739552445'/><link rel='alternate' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2011/12/yara-md5.html' title='Yara + MD5'/><author><name>Alexander Hanel</name><uri>http://www.blogger.com/profile/14943273470531588187</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_fER_9l4iokM/SbA1HWjUNUI/AAAAAAAAAAM/TFFVhDX_YBA/S220/ihatealex1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4093139800580227296.post-3246709153742918921</id><published>2011-12-07T21:01:00.001-08:00</published><updated>2011-12-10T07:15:22.336-08:00</updated><title type='text'>xxxswf.py</title><content type='html'>xxxswf.py is a Python script for carving, scanning, compressing, decompressing and analyzing Flash SWF files. The script can be used on an individual SWF, single SWF or multiple SWFs embedded in a file stream or all files in a directory. The tool could be useful for system admistrators, incident response, exploit analyst, malware analyst or web developers. &lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;C:\Documents and Settings\XOR\My Documents\Projects\swfxxx&amp;gt;python xxxswf.py -h&lt;br /&gt;Usage: xxxswf.py [options] file.bad&lt;br /&gt;&lt;br /&gt;Options:&lt;br /&gt;  -h, --help            show this help message and exit&lt;br /&gt;  -x, --extract         Extracts the embedded SWF(s), names it MD5HASH.swf &amp;amp;&lt;br /&gt;                        saves it in the working dir. No addition args needed&lt;br /&gt;  -y, --yara            Scans the SWF(s) with yara. If the SWF(s) is&lt;br /&gt;                        compressed it will be deflated. No addition args&lt;br /&gt;                        needed&lt;br /&gt;  -s, --md5scan         Scans the SWF(s) for MD5 signatures. Please see func&lt;br /&gt;                        checkMD5 to define hashes. No addition args needed&lt;br /&gt;  -H, --header          Displays the SWFs file header. No addition args needed&lt;br /&gt;  -d, --decompress      Deflates compressed SWFS(s)&lt;br /&gt;  -r PATH, --recdir=PATH&lt;br /&gt;                        Will recursively scan a directory for files that&lt;br /&gt;                        contain SWFs. Must provide path in quotes&lt;br /&gt;  -c, --compress        Compresses the SWF using Zlib&amp;lt;/pre&amp;gt;&lt;br /&gt;&lt;/pre&gt;xxxswf.py with no options and a file passed. The output is extremely simple. The [SUMMARY] shows the count of embedded SWFs. The MD5 and name of the scanned file, the address of the embedded SWF and the header of the SWF. FWS is uncompressed and CWS is compressed with zlib. &lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;C:\Documents and Settings\XOR\My Documents\Projects\swfxxx&amp;gt;python xxxswf.py test.swf&lt;br /&gt;[SUMMARY] 1 SWF(s) in MD5:7ca4ab177f480503653702b33366111f:test.swf&lt;br /&gt;        [ADDR] SWF 1 at 0xa18  - CWS Header&lt;br /&gt;&lt;/pre&gt;xxxswf.py with the -x (--extract) option. The file will be carved and saved to the working directory. The name will be the MD5 of the deflated SWF and the '.swf' extension. If there are multiple files with the same MD5 the file's name will be MD5.count.swf. The count will only go up to 50. A useful example of this will be given later.  &lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;C:\Documents and Settings\XOR\My Documents\Projects\swfxxx&amp;gt;python xxxswf.py -x x.bin&lt;br /&gt;[SUMMARY] 2 SWF(s) in MD5:32fed596fa850057211121488f6c6b75:x.bin&lt;br /&gt;        [ADDR] SWF 1 at 0x0  - FWS Header&lt;br /&gt;                [FILE] Carved SWF MD5: c46299a5015c6d31ad5766cb49e4ab4b.swf&lt;br /&gt;        [ADDR] SWF 2 at 0x7774  - FWS Header&lt;br /&gt;                [FILE] Carved SWF MD5: c46299a5015c6d31ad5766cb49e4ab4b.2.swf&lt;br /&gt;&lt;/pre&gt;The -r or --recdir option can be used to recursively search or carve out all SWFs in a directory. This could be used on a temporary internet directory or a repository of malicious documents. It's recommend to pipe the output to a text file. The path will need to be in quotes. This can take a few minutes due to the size of the directory and the speed of your processor.   &lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;C:\Documents and Settings\XOR\My Documents\Projects\swfxxx&amp;gt;python xxxswf.py -x -r "C:\Documents and Settings\XOR\Desktop\samples\mal" &amp;gt; out.txt&lt;br /&gt;&lt;br /&gt;vi out.txt&lt;br /&gt;&lt;br /&gt;[SUMMARY] 1 SWF(s) in MD5:93d63b5f9167d7ab579ca9bd70d1dd3e:C:\Documents and Settings\XOR\Desktop\samples\mal\301.xls=&lt;br /&gt;    [ADDR] SWF 1 at 0x13ef81 - [ERROR]: Zlib decompression error. Invalid CWS SWF&lt;br /&gt;&lt;br /&gt;[SUMMARY] 1 SWF(s) in MD5:d2cad99c92a1a43b8ed0c217b6a501af:C:\Documents and Settings\XOR\Desktop\samples\mal\CVE-2009-3129.xls&lt;br /&gt;    [ADDR] SWF 1 at 0x13ef81 - [ERROR]: Zlib decompression error. Invalid CWS SWF&lt;br /&gt;&lt;br /&gt;[SUMMARY] 1 SWF(s) in MD5:358895e898866ef0432391b931096209:C:\Documents and Settings\XOR\Desktop\samples\mal\CWS.swf&lt;br /&gt;    [ADDR] SWF 1 at 0x0  - CWS Header&lt;br /&gt;        [FILE] Carved SWF MD5: f05ba07d32e9a7b47a18aa3f172ad4e5.swf&lt;br /&gt;&lt;br /&gt;[SUMMARY] 1 SWF(s) in MD5:c46299a5015c6d31ad5766cb49e4ab4b:C:\Documents and Settings\XOR\Desktop\samples\mal\simple.swf&lt;br /&gt;    [ADDR] SWF 1 at 0x0  - FWS Header&lt;br /&gt;        [FILE] Carved SWF MD5: c46299a5015c6d31ad5766cb49e4ab4b.3.swf&lt;br /&gt;&lt;br /&gt;[SUMMARY] 7 SWF(s) in MD5:7089ec4198e70f58f09547201ae4e185:C:\Documents and Settings\XOR\Desktop\samples\mal\swfxxx.py&lt;br /&gt;    [ADDR] SWF 1 at 0x607  - [ERROR] Invalid SWF Version&lt;br /&gt;    [ADDR] SWF 2 at 0x60b  - [ERROR] Invalid SWF Version&lt;br /&gt;    [ADDR] SWF 3 at 0x958  - [ERROR] Invalid SWF Version&lt;br /&gt;    [ADDR] SWF 4 at 0x981  - [ERROR] Invalid SWF Size&lt;br /&gt;    [ADDR] SWF 5 at 0x18d0  - [ERROR] Invalid SWF Size&lt;br /&gt;    [ADDR] SWF 6 at 0x1c45  - [ERROR] Invalid SWF Size&lt;br /&gt;    [ADDR] SWF 7 at 0x1cc3  - [ERROR] Invalid SWF Size&lt;br /&gt;....&lt;br /&gt;&lt;/pre&gt;The search for embedded SWFs is done simply by using a regular expression with "FWS" and "CWS" as the search criteria. This generic search will return false positives. Verifying the SWF is done by checking for a valid version, valid size and valid decompression (if compressed). Please see the function verifySWF(). This approach is time consuming but it does work. Above we can see the different errors being generated. All errors will contain the string "[ERROR]". If the sample set is large enough odds are there will be recurring MD5 file names. xxxswf.py can be used to classify or alert on commonly used MD5 SWFs. The function checkMD5 can be edited to alert on specific MD5s.&lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; checkMD5&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;md5&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# checks if MD5 has been seen in MD5 Dictionary &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# MD5Dict contains the MD5 and the CVE&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# For { 'MD5':'CVE', 'MD5-1':'CVE-1', 'MD5-2':'CVE-2'}&lt;/span&gt;&lt;br /&gt;    MD5Dict &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #b060b0;"&gt;{&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'c46299a5015c6d31ad5766cb49e4ab4b'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'CVE-XXXX-XXXX'&lt;/span&gt;&lt;span style="color: #b060b0;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; MD5Dict&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;get&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;md5&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[BAD] MD5 Match on'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; MD5Dict&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;get&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;md5&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;The MD5 "c46299a5015c6d31ad5766cb49e4ab4b" was found in the x.bin example from a couple example above. MD5 scanning is done by passing the -s or --md5scan. All hashing or signature alerts contain the string [BAD]. &lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;C:\Documents and Settings\XOR\My Documents\Projects\swfxxx&amp;gt;python xxxswf.py -s x.bin&lt;br /&gt;[SUMMARY] 2 SWF(s) in MD5:32fed596fa850057211121488f6c6b75:x.bin&lt;br /&gt;        [ADDR] SWF 1 at 0x0  - FWS Header&lt;br /&gt;        [BAD] MD5 Match on CVE-XXXX-XXXX&lt;br /&gt;        [ADDR] SWF 2 at 0x7774  - FWS Header&lt;br /&gt;        [BAD] MD5 Match on CVE-XXXX-XXXX&lt;br /&gt;&lt;/pre&gt;xxxswf can be used to decompress a single SWF by using the -d --decompress option.&lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;C:\Documents and Settings\XOR\My Documents\Projects\swfxxx&amp;gt;python xxxswf.py -d test.swf&lt;br /&gt;[SUMMARY] 1 SWF(s) in MD5:7ca4ab177f480503653702b33366111f:test.swf&lt;br /&gt;        [ADDR] SWF 1 at 0xa18  - CWS Header&lt;br /&gt;                [FILE] Carved SWF MD5: f0f40a975ef68cf6358f84515a8f103e.4.swf&lt;br /&gt;&lt;/pre&gt;It can compress SWFs using the -c or --compress options. Note: In testing I wasn't able to decompress a SWF downloaded from the internet and compress it again to get a matching MD5. A single byte is off. If someone could give me a clue on this one or recommend another technique please let me know. &lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;C:\Documents and Settings\XOR\My Documents\Projects\swfxxx&amp;gt;python xxxswf.py -c f0f40a975ef68cf6358f84515a8f103e.2.swf&lt;br /&gt;[SUMMARY] 1 SWF(s) in MD5:f0f40a975ef68cf6358f84515a8f103e:f0f40a975ef68cf6358f8&lt;br /&gt;4515a8f103e.2.swf&lt;br /&gt;        [ADDR] SWF 1 at 0x0  - FWS Header&lt;br /&gt;                [FILE] Compressed SWF MD5: e9e6c13c461dc38006ff7d26c18e904e.swf&lt;br /&gt;&lt;/pre&gt;The SWF headers information can be displayed by using -H or --header&lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;C:\Documents and Settings\XOR\My Documents\Projects\swfxxx&amp;gt;python xxxswf.py -H 11cc16d78597fe9999b7f6b714727ac3.10.swf&lt;br /&gt;[SUMMARY] 1 SWF(s) in MD5:11cc16d78597fe9999b7f6b714727ac3:11cc16d78597fe9999b7f&lt;br /&gt;6b714727ac3.10.swf&lt;br /&gt;        [ADDR] SWF 1 at 0x0  - FWS Header&lt;br /&gt;        [HEADER] File header: FWS&lt;br /&gt;        [HEADER] File version: 7&lt;br /&gt;        [HEADER] File size: 52647&lt;br /&gt;        [HEADER] Rect Nbit: 15&lt;br /&gt;        [HEADER] Rect Xmin: 0&lt;br /&gt;        [HEADER] Rect Xmax: 11000&lt;br /&gt;        [HEADER] Rect Ymin: 0&lt;br /&gt;        [HEADER] Rect Ymax: 3600&lt;br /&gt;        [HEADER] Frame Rate: 7936&lt;br /&gt;        [HEADER] Frame Count: 1&lt;br /&gt;&lt;/pre&gt;The output for Rect is in twips. The script contains the ability to scan the deflated SWF(s) with yara. The options are -y and --yara. This makes it easy to create signatures on malicious SWF files that do not have static MD5s. Due to the scanning set only being in a SWF file the signatures can be a little more generic. Let's walk through an example using  information gathered from the excellent write up by Microsoft.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://blogs.technet.com/b/mmpc/archive/2011/03/17/a-technical-analysis-on-the-cve-2011-0609-adobe-flash-player-vulnerability.aspx%20" target="_blank"&gt;http://blogs.technet.com/b/mmpc/archive/2011/03/17/a-technical-analysis-on-the-cve-2011-0609-adobe-flash-player-vulnerability.aspx&amp;nbsp;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;After reading the link we know some key things. We know what is triggering the exploit (bytecode verification error), we know there is some shellcode and we know there is some code for creating the heap spray. The analysis gives a nice clue about the exploit and what to target. From the analysis "The Adobe Flash file embedded inside the Excel file is another carrier for the exploit. It loads shellcode inside memory, performs heap-spraying, and loads a Flash byte stream from memory to exploit the 0-day vulnerability". If you look closely at the byte stream in the screenshot you will notice the string "43575309". What would this sring or Flash byte stream looks like if it was actually binary data and not a string?&lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; sys&lt;br /&gt;s &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;"43575309"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;for&lt;/span&gt; i &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;xrange&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;len&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;s&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt; &lt;br /&gt;    sys&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;stdout&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;write&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;chr&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;int&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'0x'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; s&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;i&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;i&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #008c00;"&gt;16&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;CWS&lt;br /&gt;&lt;/pre&gt;As mentioned earlier 'CWS' is the header for a compressed SWF. Nine is the Flash version. We have an embedded SWF that is stored into a byte array and then converted from hex to binary. Let's create a yara signature targeting this. Note: the string hexToBin is the name of a function and in a way is arbitrary. It's better to go after the code or data related to triggering the exploit. This exploit is a little more difficult because the trigger is embedded in a compressed SWF stored as ASCII hex. For more information please see my poor-grammar-non-proof-read post called &lt;a href="http://hooked-on-mnemonics.blogspot.com/2011/01/intro-to-creating-anti-virus-signatures.html" target="_blank"&gt;An Intro to Creating Anti-Virus Signatures&lt;/a&gt;. &lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;rule CVE_2011_0609&lt;br /&gt;&lt;span style="color: #b060b0;"&gt;{&lt;/span&gt;  &lt;br /&gt;strings&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;  &lt;br /&gt;    $CWSHeader &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;"435753"&lt;/span&gt;&lt;br /&gt;    $FWSHeader &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;"465753"&lt;/span&gt;&lt;br /&gt;    $hex2bin &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;"hexToBin"&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;condition&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;  &lt;br /&gt;    &lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;$CWSHeader &lt;span style="color: #e66170; font-weight: bold;"&gt;or&lt;/span&gt; $FWSHeader&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;and&lt;/span&gt; $hex2bin&lt;br /&gt;&lt;span style="color: #b060b0;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;Saved int the working dir as rules.yar. &lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;C:\Documents and Settings\XOR\My Documents\Projects\swfxxx&amp;gt;python xxxswf.py -y "CVE-2011-0609_.xls__"&lt;br /&gt;[SUMMARY] 1 SWF(s) in MD5:4bb64c1da2f73da11f331a96d55d63e2:CVE-2011-0609_.xls=__&lt;br /&gt;&lt;br /&gt;        [ADDR] SWF 1 at 0xa18  - FWS Header&lt;br /&gt;        [BAD] Yara Signature Hit: CVE_2011_0609&lt;br /&gt;&lt;/pre&gt;If you would like to import this script there is a function called bad(). This function can be used for scanning a SWF with MD5 and Yara. An open file handle will need to be passed to the function. The output will then need to be parsed for a line containing [BAD]. If interested in Yara and MD5 signatures feel free to contact me. I won't be posting my signature sets but I might be able to share depending on the organization or group.&lt;br /&gt;&lt;br /&gt;Summary&lt;br /&gt;The goal of this tool is to be able to work with embedded SWF files in an easy and quick way.  This script is a work in progress. With a recent move to NYC I needed a new project. If you find any bugs or have some comments please &lt;a href="https://plus.google.com/116435610018692137667/posts%20" target="_blank"&gt;contact me&lt;/a&gt; or leave a comment.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;xxxswf.py - &lt;a href="http://codepad.org/hosku69i/raw.py" target="_blank"&gt;download &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="background: #000000; color: #d1d1d1;"&gt;&lt;span style="color: #9999a9;"&gt;# xxxswf.py was created by alexander dot hanel at gmail dot com&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# version 0.1 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# Date - 12-07-2011 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# To do list&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;#   - Tag Parser&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;#   - ActionScript Decompiler&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; fnmatch &lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; hashlib&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; imp&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; math&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; os&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; re&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; struct&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; sys&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; time&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;from&lt;/span&gt; StringIO &lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; StringIO&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;from&lt;/span&gt; optparse &lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; OptionParser&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; zlib&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; checkMD5&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;md5&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# checks if MD5 has been seen in MD5 Dictionary &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# MD5Dict contains the MD5 and the CVE&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# For { 'MD5':'CVE', 'MD5-1':'CVE-1', 'MD5-2':'CVE-2'}&lt;/span&gt;&lt;br /&gt;    MD5Dict &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #b060b0;"&gt;{&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'c46299a5015c6d31ad5766cb49e4ab4b'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'CVE-XXXX-XXXX'&lt;/span&gt;&lt;span style="color: #b060b0;"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; MD5Dict&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;get&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;md5&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[BAD] MD5 Match on'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; MD5Dict&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;get&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;md5&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt;    &lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; bad&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;for&lt;/span&gt; idx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; x &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;enumerate&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;findSWF&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        tmp &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; verifySWF&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;x&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; tmp &lt;span style="color: #d2cd86;"&gt;!&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            yaraScan&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;tmp&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            checkMD5&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;hashBuff&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;tmp&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; &lt;br /&gt;    &lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; yaraScan&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;d&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# d = buffer of the read file &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# Scans SWF using Yara&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# test if yara module is installed&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# if not Yara can be downloaded from http://code.google.com/p/yara-project/&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        imp&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;find_module&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'yara'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;import&lt;/span&gt; yara &lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;ImportError&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[ERROR] Yara module not installed - aborting scan'&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# test for yara compile errors&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        r &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; yara&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;compile&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;r'rules.yar'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;pass&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[ERROR] Yara compile error - aborting scan'&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# get matches&lt;/span&gt;&lt;br /&gt;    m &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; r&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;match&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;data&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;d&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# print matches&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;for&lt;/span&gt; X &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; m&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[BAD] Yara Signature Hit:'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; X&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; findSWF&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;d&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# d = buffer of the read file &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# Search for SWF Header Sigs in files&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;tmp&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;start&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;for&lt;/span&gt; tmp &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; re&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;finditer&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'CWS|FWS'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; d&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; hashBuff&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;d&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# d = buffer of the read file &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# This function hashes the buffer&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# source: http://stackoverflow.com/q/5853830&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;type&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;d&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;is&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;str&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;      d &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; StringIO&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;d&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    md5 &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; hashlib&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;md5&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;while&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;True&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        data &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; d&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;128&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;not&lt;/span&gt; data&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;break&lt;/span&gt;&lt;br /&gt;        md5&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;update&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;data&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; md5&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;hexdigest&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; verifySWF&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;addr&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Start of SWF&lt;/span&gt;&lt;br /&gt;    f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;seek&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;addr&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Read Header&lt;/span&gt;&lt;br /&gt;    header &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;3&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Read Version&lt;/span&gt;&lt;br /&gt;    ver &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; struct&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;unpack&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'&amp;lt;b'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Read SWF Size&lt;/span&gt;&lt;br /&gt;    size &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; struct&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;unpack&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'&amp;lt;i'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;4&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Start of SWF&lt;/span&gt;&lt;br /&gt;    f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;seek&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;addr&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #9999a9;"&gt;# Read SWF into buffer. If compressed read uncompressed size. &lt;/span&gt;&lt;br /&gt;        t &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;size&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;pass&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #9999a9;"&gt;# Error check for invalid SWF&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;' - [ERROR] Invalid SWF Size'&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;type&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;t&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;is&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;str&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;      f &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; StringIO&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;t&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Error check for version above 20&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; ver &lt;span style="color: #d2cd86;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #008c00;"&gt;20&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;' - [ERROR] Invalid SWF Version'&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'CWS'&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; header&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;3&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            tmp &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'FWS'&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;5&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; zlib&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;decompress&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;' - CWS Header'&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; tmp&lt;br /&gt;        &lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;pass&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'- [ERROR]: Zlib decompression error. Invalid CWS SWF'&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;br /&gt;        &lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;elif&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'FWS'&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; header&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            tmp &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;size&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;' - FWS Header'&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; tmp&lt;br /&gt;        &lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;pass&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;' - [ERROR] Invalid SWF Size'&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;br /&gt;        &lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;else&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;' - [Error] Logic Error Blame Programmer'&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; headerInfo&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# f is the already opended file handle &lt;/span&gt;&lt;br /&gt;&lt;span style="color: #9999a9;"&gt;# Yes, the format is is a rip off SWFDump. Can you blame me? Their tool is awesome.&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# SWFDump FORMAT    &lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# [HEADER]        File version: 8&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# [HEADER]        File is zlib compressed. Ratio: 52%&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# [HEADER]        File size: 37536&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# [HEADER]        Frame rate: 18.000000&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# [HEADER]        Frame count: 323&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# [HEADER]        Movie width: 217.00&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# [HEADER]        Movie height: 85.00&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;type&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;is&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;str&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;      f &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; StringIO&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    sig &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;3&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;             &lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[HEADER] File header:'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; sig&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'C'&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; sig&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[HEADER] File is zlib compressed.'&lt;/span&gt;&lt;br /&gt;    version &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; struct&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;unpack&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'&amp;lt;b'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[HEADER] File version:'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; version&lt;br /&gt;    size &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; struct&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;unpack&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'&amp;lt;i'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;4&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[HEADER] File size:'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; size&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# deflate compressed SWF&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'C'&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; sig&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        f &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; verifySWF&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;type&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;is&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;str&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            f &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; StringIO&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;seek&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        x &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;8&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    ta &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;tell&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    tmp &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; struct&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;unpack&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'&amp;lt;b'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;    nbit &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;  tmp &lt;span style="color: #d2cd86;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: #008c00;"&gt;3&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[HEADER] Rect Nbit:'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; nbit&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Curretely the nbit is static at 15. This could be modified in the&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# future. If larger than 9 this will break the struct unpack. Will have&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# to revist must be a more effective way to deal with bits. Tried to keep&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# the algo but damn this is ugly...&lt;/span&gt;&lt;br /&gt;    f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;seek&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;ta&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    rect &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;  struct&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;unpack&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'&amp;gt;Q'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;int&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;math&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;ceil&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;nbit&lt;span style="color: #d2cd86;"&gt;*&lt;/span&gt;&lt;span style="color: #008c00;"&gt;4&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;/&lt;/span&gt;&lt;span style="color: #009f00;"&gt;8.0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;    tmp &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; struct&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;unpack&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'&amp;lt;b'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;    tmp &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; bin&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;tmp&lt;span style="color: #d2cd86;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #008c00;"&gt;7&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;zfill&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# bin requires Python 2.6 or higher&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# skips string '0b' and the nbit &lt;/span&gt;&lt;br /&gt;    rect &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;  bin&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;rect&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;7&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt; &lt;br /&gt;    xmin &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;int&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;rect&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;nbit&lt;span style="color: #d2cd86;"&gt;-&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[HEADER] Rect Xmin:'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; xmin&lt;br /&gt;    xmax &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;int&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;rect&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;nbit&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;nbit&lt;span style="color: #d2cd86;"&gt;*&lt;/span&gt;&lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;-&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[HEADER] Rect Xmax:'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; xmax&lt;br /&gt;    ymin &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;int&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;rect&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;nbit&lt;span style="color: #d2cd86;"&gt;*&lt;/span&gt;&lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;nbit&lt;span style="color: #d2cd86;"&gt;*&lt;/span&gt;&lt;span style="color: #008c00;"&gt;3&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;-&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[HEADER] Rect Ymin:'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; ymin&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# one bit needs to be added, my math might be off here&lt;/span&gt;&lt;br /&gt;    ymax &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;int&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;rect&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;nbit&lt;span style="color: #d2cd86;"&gt;*&lt;/span&gt;&lt;span style="color: #008c00;"&gt;3&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;nbit&lt;span style="color: #d2cd86;"&gt;*&lt;/span&gt;&lt;span style="color: #008c00;"&gt;4&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;-&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;str&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;tmp&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[HEADER] Rect Ymax:'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; ymax&lt;br /&gt;    framerate &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; struct&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;unpack&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'&amp;lt;H'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[HEADER] Frame Rate:'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; framerate&lt;br /&gt;    framecount &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; struct&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;unpack&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'&amp;lt;H'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt; &lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[HEADER] Frame Count:'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; framecount&lt;br /&gt;       &lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; walk4SWF&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;path&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# returns a list of [folder-path, [addr1,addrw2]]&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Don't ask, will come back to this code. &lt;/span&gt;&lt;br /&gt;    p &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;''&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;    r &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; p&lt;span style="color: #d2cd86;"&gt;*&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; os&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;path&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;isdir&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;path&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;!&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;True&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;and&lt;/span&gt; path &lt;span style="color: #d2cd86;"&gt;!&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;''&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[ERROR] walk4SWF path must be a dir.'&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; &lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;for&lt;/span&gt; root&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; dirs&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; files &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; os&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;walk&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;path&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;for&lt;/span&gt; name &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; files&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt; &lt;br /&gt;                x &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;open&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;os&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;path&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;join&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;root&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; name&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'rb'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #e66170; font-weight: bold;"&gt;pass&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #e66170; font-weight: bold;"&gt;break&lt;/span&gt;&lt;br /&gt;            y &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; findSWF&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;x&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;len&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;y&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;!&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #9999a9;"&gt;# Path of file SWF&lt;/span&gt;&lt;br /&gt;                p&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; os&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;path&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;join&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;root&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; name&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #9999a9;"&gt;# contains list of the file offset of SWF header&lt;/span&gt;&lt;br /&gt;                p&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; y&lt;br /&gt;                r&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;insert&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;len&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;r&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;p&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;                p &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;''&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;                y &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;''&lt;/span&gt;&lt;br /&gt;            x&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;close&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; r&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; tagsInfo&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; fileExist&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;n&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; ext&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Checks the working dir to see if the file is&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# already in the dir. If exists the file will&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# be named name.count.ext (n.c.ext). No more than&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# 50 matching MD5s will be written to the dir. &lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; os&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;path&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;exists&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt; n &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'.'&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; ext&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;                c &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #e66170; font-weight: bold;"&gt;while&lt;/span&gt; os&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;path&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;exists&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;n &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'.'&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;str&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;c&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'.'&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; ext&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;                    c &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;  c &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; &lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;br /&gt;                    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; c &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #008c00;"&gt;50&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;                        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[ERROR] Skipped 50 Matching MD5 SWFs'&lt;/span&gt;&lt;br /&gt;                        &lt;span style="color: #e66170; font-weight: bold;"&gt;break&lt;/span&gt;&lt;br /&gt;                n &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; n &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'.'&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;str&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;c&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;                &lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; n &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'.'&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; ext&lt;br /&gt;    &lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; CWSize&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# The file size in the header is of the uncompressed SWF.&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# To estimate the size of the compressed data, we can grab&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# the length, read that amount, deflate the data, then&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# compress the data again, and then call len(). This will&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# give us the length of the compressed SWF. &lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; compressSWF&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;type&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;is&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;str&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;      f &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; StringIO&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;3&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        tmp &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'CWS'&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;5&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt; zlib&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;compress&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; tmp&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;pass&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[ERROR] SWF Zlib Compression Failed'&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; disneyland&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;filename&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; options&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# because this is where the magic happens&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# but seriously I did the recursion part last..&lt;/span&gt;&lt;br /&gt;    retfindSWF &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; findSWF&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;seek&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\n[SUMMARY] %d SWF(s) in MD5:%s:%s'&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;%&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;len&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;retfindSWF&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;hashBuff&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; filename &lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# for each SWF in file &lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;for&lt;/span&gt; idx&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; x &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;enumerate&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;retfindSWF&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[ADDR] SWF %d at %s'&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;%&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;idx&lt;span style="color: #d2cd86;"&gt;+&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;hex&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;x&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;br /&gt;        f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;seek&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;x&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        h &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;read&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;seek&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;x&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        swf &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; verifySWF&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;x&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; swf &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;continue&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; options&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;extract &lt;span style="color: #d2cd86;"&gt;!&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            name &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; fileExist&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;hashBuff&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;swf&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'swf'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t\t[FILE] Carved SWF MD5: %s'&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;%&lt;/span&gt; name &lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;                o &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;open&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;name&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'wb+'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;IOError&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; e&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[ERROR] Could Not Create %s '&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;%&lt;/span&gt; e&lt;br /&gt;                &lt;span style="color: #e66170; font-weight: bold;"&gt;continue&lt;/span&gt; &lt;br /&gt;            o&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;write&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;swf&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            o&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;close&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; options&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;yara &lt;span style="color: #d2cd86;"&gt;!&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            yaraScan&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;swf&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; options&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;md5scan &lt;span style="color: #d2cd86;"&gt;!&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            checkMD5&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;hashBuff&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;swf&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; options&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;decompress &lt;span style="color: #d2cd86;"&gt;!&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            name &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; fileExist&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;hashBuff&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;swf&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'swf'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t\t[FILE] Carved SWF MD5: %s'&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;%&lt;/span&gt; name &lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;                o &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;open&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;name&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'wb+'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;IOError&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; e&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[ERROR] Could Not Create %s '&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;%&lt;/span&gt; e&lt;br /&gt;                &lt;span style="color: #e66170; font-weight: bold;"&gt;continue&lt;/span&gt;&lt;br /&gt;            o&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;write&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;swf&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            o&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;close&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; options&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;header &lt;span style="color: #d2cd86;"&gt;!&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            headerInfo&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;swf&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; options&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;compress &lt;span style="color: #d2cd86;"&gt;!&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            swf &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; compressSWF&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;swf&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; swf &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #e66170; font-weight: bold;"&gt;continue&lt;/span&gt; &lt;br /&gt;            name &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; fileExist&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;hashBuff&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;swf&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'swf'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t\t[FILE] Compressed SWF MD5: %s'&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;%&lt;/span&gt; name&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;                o &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;open&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;name&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'wb+'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;IOError&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; e&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'\t[ERROR] Could Not Create %s '&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;%&lt;/span&gt; e&lt;br /&gt;                &lt;span style="color: #e66170; font-weight: bold;"&gt;continue&lt;/span&gt;&lt;br /&gt;            o&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;write&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;swf&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            o&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;close&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;def&lt;/span&gt; main&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Scenarios:&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Scan file for SWF(s)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Scan file for SWF(s) and extract them &lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Scan file for SWF(s) and scan them with Yara&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Scan file for SWF(s), extract them and scan with Yara&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Scan directory recursively for files that contain SWF(s) &lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Scan directory recursively for files that contain SWF(s) and extract them&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    parser &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; OptionParser&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    usage &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'usage: %prog [options] &amp;lt;file.bad&amp;gt;'&lt;/span&gt;&lt;br /&gt;    parser &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; OptionParser&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;usage&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;usage&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    parser&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;add_option&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'-x'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'--extract'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; action&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'store_true'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; dest&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'extract'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; help&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'Extracts the embedded SWF(s), names it MD5HASH.swf &amp;amp; saves it in the working dir. No addition args needed'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    parser&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;add_option&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'-y'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'--yara'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; action&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'store_true'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; dest&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'yara'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; help&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'Scans the SWF(s) with yara. If the SWF(s) is compressed it will be deflated. No addition args needed'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    parser&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;add_option&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'-s'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'--md5scan'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; action&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'store_true'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; dest&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'md5scan'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; help&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'Scans the SWF(s) for MD5 signatures. Please see func checkMD5 to define hashes. No addition args needed'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    parser&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;add_option&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'-H'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'--header'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; action&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'store_true'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; dest&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'header'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; help&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'Displays the SWFs file header. No addition args needed'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    parser&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;add_option&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'-d'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'--decompress'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; action&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'store_true'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; dest&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'decompress'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; help&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'Deflates compressed SWFS(s)'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    parser&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;add_option&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'-r'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'--recdir'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; dest&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'PATH'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;type&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'string'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; help&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'Will recursively scan a directory for files that contain SWFs. Must provide path in quotes'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    parser&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;add_option&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'-c'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'--compress'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; action&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'store_true'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; dest&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'compress'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; help&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'Compresses the SWF using Zlib'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;options&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; args&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; parser&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;parse_args&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Print help if no argurments are passed&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;len&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;sys&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;argv&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;&amp;lt;&lt;/span&gt; &lt;span style="color: #008c00;"&gt;2&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        parser&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;print_help&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Note files can't start with '-'&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'-'&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; sys&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;argv&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;len&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;sys&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;argv&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;-&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt; &lt;span style="color: #e66170; font-weight: bold;"&gt;and&lt;/span&gt; options&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;PATH &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        parser&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;print_help&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# Recusive Search&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; options&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;PATH &lt;span style="color: #d2cd86;"&gt;!&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;None&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        paths &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; walk4SWF&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;options&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;PATH&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;for&lt;/span&gt; y &lt;span style="color: #e66170; font-weight: bold;"&gt;in&lt;/span&gt; paths&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #9999a9;"&gt;#if sys.argv[0] not in y[0]:&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;                t &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;open&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;y&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'rb+'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;                disneyland&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;t&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt; y&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #008c00;"&gt;0&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;options&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;            &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;IOError&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #e66170; font-weight: bold;"&gt;pass&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; &lt;br /&gt;        &lt;br /&gt;    &lt;span style="color: #9999a9;"&gt;# try to open file &lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;try&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        f &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;open&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;sys&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;argv&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;len&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;sys&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;argv&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;-&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;&lt;span style="color: #00c4c4;"&gt;'rb+'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;        filename &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; sys&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;argv&lt;span style="color: #d2cd86;"&gt;[&lt;/span&gt;&lt;span style="color: #e34adc;"&gt;len&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;sys&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;argv&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;-&lt;/span&gt;&lt;span style="color: #008c00;"&gt;1&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;]&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;except&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;Exception&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;print&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'[ERROR] File can not be opended/accessed'&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    disneyland&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;f&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;filename&lt;span style="color: #d2cd86;"&gt;,&lt;/span&gt;options&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    f&lt;span style="color: #d2cd86;"&gt;.&lt;/span&gt;close&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #e66170; font-weight: bold;"&gt;return&lt;/span&gt; &lt;br /&gt;        &lt;br /&gt;&lt;span style="color: #e66170; font-weight: bold;"&gt;if&lt;/span&gt; &lt;span style="color: #e34adc;"&gt;__name__&lt;/span&gt; &lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;=&lt;/span&gt; &lt;span style="color: #00c4c4;"&gt;'__main__'&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;:&lt;/span&gt;&lt;br /&gt;   main&lt;span style="color: #d2cd86;"&gt;(&lt;/span&gt;&lt;span style="color: #d2cd86;"&gt;)&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="background: none repeat scroll 0% 0% rgb(0, 0, 0); color: #d1d1d1;"&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4093139800580227296-3246709153742918921?l=hooked-on-mnemonics.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hooked-on-mnemonics.blogspot.com/feeds/3246709153742918921/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2011/12/xxxswfpy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/3246709153742918921'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/3246709153742918921'/><link rel='alternate' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2011/12/xxxswfpy.html' title='xxxswf.py'/><author><name>Alexander Hanel</name><uri>http://www.blogger.com/profile/14943273470531588187</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_fER_9l4iokM/SbA1HWjUNUI/AAAAAAAAAAM/TFFVhDX_YBA/S220/ihatealex1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4093139800580227296.post-8362984007420689372</id><published>2011-09-05T19:25:00.000-07:00</published><updated>2011-10-03T18:54:21.933-07:00</updated><title type='text'>Visual Studio Options for Cleaner Assembly</title><content type='html'>Experimenting with Visual Studio compiler options has been an interest of mine lately. The goal is to get cleaner assembly in IDA. While writing C code I sometimes wonder "how would this C code translate to assembly?". Google gave me some decent command line options for CL but I still couldn't get the code I wanted. Luckily, I stumbled upon some extremely helpful slides by &lt;a href="http://opensecuritytraining.info/IntroX86.html"&gt;OpenSecurityTraining.com&lt;/a&gt;. Sadly, the slides are zipped and haven't been indexed by Google. Below are the options for Visual Studio C++ for cleaner assembly. &lt;br /&gt;&lt;pre name="code" class="C++"&gt;(right click on .c or .cpp)&lt;br /&gt;Source File &amp;gt; Properties&lt;br /&gt;&lt;br /&gt;Configuration Properties &amp;gt; C/C++ &amp;gt; General&lt;br /&gt;&amp;gt; Debug Information Format - Program DataBase (/Zi)&lt;br /&gt;&amp;gt; Warning Level - Level3 (/W3)&lt;br /&gt;&lt;br /&gt;Configuration Properties &amp;gt; C/C++ &amp;gt; Code Generation&lt;br /&gt;&amp;gt; Enable Minimal Rebuilt - No&lt;br /&gt;&amp;gt; Enable C++ Exception - No&lt;br /&gt;&amp;gt; Basic Runtime Checks - Default&lt;br /&gt;&amp;gt; Buffer Security Check - No (/GS-)&lt;br /&gt;&lt;br /&gt;Configuration Properties &amp;gt; C/C++ &amp;gt; Advanced&lt;br /&gt;&amp;gt; Compile As - Compile as C Code (/TC)&lt;br /&gt;&lt;br /&gt;Configuration Properties &amp;gt; Linker &amp;gt; General&lt;br /&gt;&amp;gt; Enable Incremental Linking - No (/INCREMENTAL:NO)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So how does each one of these options effect a "Hello World" when we change one option, compile and then change the next? &lt;br /&gt;&lt;pre name="code" class="C++"&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt;int main(void)&lt;br /&gt;{&lt;br /&gt;  printf("Hello world!");&lt;br /&gt;  return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Compiled using Visual Studio 2010 C++ default settings. &lt;br /&gt;&lt;pre name="code" class="C++"&gt;&lt;br /&gt;.text:00411380 main            proc near               ; CODE XREF: j_main j&lt;br /&gt;.text:00411380&lt;br /&gt;.text:00411380 var_C0          = dword ptr -0C0h&lt;br /&gt;.text:00411380&lt;br /&gt;.text:00411380                 push    ebp&lt;br /&gt;.text:00411381                 mov     ebp, esp&lt;br /&gt;.text:00411383                 sub     esp, 0C0h&lt;br /&gt;.text:00411389                 push    ebx&lt;br /&gt;.text:0041138A                 push    esi&lt;br /&gt;.text:0041138B                 push    edi&lt;br /&gt;&lt;br /&gt;//////////////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;.text:0041138C                 lea     edi, [ebp+var_C0]&lt;br /&gt;.text:00411392                 mov     ecx, 30h&lt;br /&gt;.text:00411397                 mov     eax, 0CCCCCCCCh&lt;br /&gt;.text:0041139C                 rep stosd     &lt;br /&gt;&lt;br /&gt;//////////////////////////////////////////////////////////////////////////////&lt;br /&gt;// Initialization of local variables to a nonzero value. This helps identify &lt;br /&gt;// bugs that do not appear when running in debug mode. There is a greater &lt;br /&gt;// chance that stack variables will still be zero in a debug build compared &lt;br /&gt;// to a release build because of compiler optimizations of stack variables in &lt;br /&gt;// a release build. Once a program has used an area of its stack, it is never &lt;br /&gt;// reset to 0 by the compiler. Therefore, subsequent, uninitialized stack &lt;br /&gt;// variables that happen to use the same stack area can return values left &lt;br /&gt;// over from the prior use of this stack memory.&lt;br /&gt;// Source http://msdn.microsoft.com/en-us/library/8wtf2dfz.aspx&lt;br /&gt;//////////////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;.text:0041139E                 mov     esi, esp&lt;br /&gt;.text:004113A0                 push    offset aHelloWorld  ; "Hello world!"&lt;br /&gt;.text:004113A5                 call    ds:__imp__printf&lt;br /&gt;.text:004113AB                 add     esp, 4&lt;br /&gt;.text:004113AE                 cmp     esi, esp&lt;br /&gt;.text:004113B0                 call    j__RTC_CheckEsp&lt;br /&gt;.text:004113B5                 xor     eax, eax&lt;br /&gt;.text:004113B7                 pop     edi&lt;br /&gt;.text:004113B8                 pop     esi&lt;br /&gt;.text:004113B9                 pop     ebx&lt;br /&gt;.text:004113BA                 add     esp, 0C0h&lt;br /&gt;.text:004113C0                 cmp     ebp, esp&lt;br /&gt;.text:004113C2                 call    j__RTC_CheckEsp&lt;br /&gt;&lt;br /&gt;//////////////////////////////////////////////////////////////////////////////&lt;br /&gt;// In debug versions of executables, the Microsoft Visual Studio compilers &lt;br /&gt;// insert a call to RTC_CheckEsp() after each function call. Prior to the &lt;br /&gt;// function call, the contents of the stack pointer register (ESP/RSP) are &lt;br /&gt;// saved into a general-purpose register. This function compares the contents &lt;br /&gt;// of that general-purpose register with the stack pointer to verify that the &lt;br /&gt;// stack pointer was restored correctly. This error usually occurs when a &lt;br /&gt;// function is declared using one calling-convention and actually implemented &lt;br /&gt;// using another. If there is a mismatch, the library generates an error message &lt;br /&gt;// and a breakpoint.&lt;br /&gt;// Source: http://blogs.phoenix.com/phoenix_technologies_bios/2008/11/bios-undercover-porting-cc-to-phoenix-uefi.html&lt;br /&gt;//////////////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;.text:004113C7                 mov     esp, ebp&lt;br /&gt;.text:004113C9                 pop     ebp&lt;br /&gt;.text:004113CA                 retn&lt;br /&gt;.text:004113CA main            endp&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Size 27,136 bytes. &lt;br /&gt;&lt;br /&gt;Configuration Properties &gt; C/C++ &gt; General  &gt; Debug Information Format - Program DataBase (/Zi)&lt;pre name="code" class="C++"&gt;&lt;br /&gt;&lt;br /&gt;//////////////////////////////////////////////////////////////////////////////&lt;br /&gt;// Produces a program database (PDB) that contains type information and symbolic &lt;br /&gt;// debugging information for use with the debugger. The symbolic debugging &lt;br /&gt;// information includes the names and types of variables, as well as functions and &lt;br /&gt;// line numbers.&lt;br /&gt;&lt;br /&gt;//  /Zi does not affect optimizations. However, /Zi does imply /debug; see /DEBUG &lt;br /&gt;// (Generate Debug Info) for more information.&lt;br /&gt;// Source: http://msdn.microsoft.com/en-us/library/958x11bc%28v=vs.80%29.aspx&lt;br /&gt;//////////////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;.text:00401010 main            proc near               ; CODE XREF: j_main j&lt;br /&gt;.text:00401010                 push    ebp&lt;br /&gt;.text:00401011                 mov     ebp, esp&lt;br /&gt;.text:00401013                 push    esi&lt;br /&gt;.text:00401014                 mov     esi, esp&lt;br /&gt;.text:00401016                 push    offset aHelloWorld ; "Hello world!"&lt;br /&gt;.text:0040101B                 call    ds:__imp__printf&lt;br /&gt;.text:00401021                 add     esp, 4&lt;br /&gt;.text:00401024                 cmp     esi, esp&lt;br /&gt;.text:00401026                 call    _RTC_CheckEsp&lt;br /&gt;.text:0040102B                 xor     eax, eax&lt;br /&gt;.text:0040102D                 pop     esi&lt;br /&gt;.text:0040102E                 cmp     ebp, esp&lt;br /&gt;.text:00401030                 call    _RTC_CheckEsp&lt;br /&gt;.text:00401035                 pop     ebp&lt;br /&gt;.text:00401036                 retn&lt;br /&gt;.text:00401036 main            endp&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Size 26,624 bytes.  &lt;br /&gt;&lt;br /&gt;Configuration Properties &gt; C/C++ &gt; Code Generation &gt; Enable Minimal Rebuilt - No (/GM-)&lt;br /&gt;* No changes in code or size.&lt;br /&gt;&lt;br /&gt;Configuration Properties &gt; C/C++ &gt; Code Generation &gt; Enable C++ Exception - No&lt;br /&gt;* No changes in code or size.&lt;br /&gt;&lt;br /&gt;Configuration Properties &gt; C/C++ &gt; Code Generation &gt; Basic Runtime Checks - Default&lt;pre name="code" class="C++"&gt;&lt;br /&gt;&lt;br /&gt;//////////////////////////////////////////////////////////////////////////////&lt;br /&gt;// Used to enable and disable the run-time error checks feature, in conjunction &lt;br /&gt;// with the runtime_checks pragma.&lt;br /&gt;// Source:http://msdn.microsoft.com/en-us/library/8wtf2dfz.aspx&lt;br /&gt;//////////////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;.text:00401010 main            proc near               ; CODE XREF: j_main j&lt;br /&gt;.text:00401010                 push    ebp&lt;br /&gt;.text:00401011                 mov     ebp, esp&lt;br /&gt;.text:00401013                 push    offset aHelloWorld ; "Hello world!"&lt;br /&gt;.text:00401018                 call    ds:__imp__printf&lt;br /&gt;.text:0040101E                 add     esp, 4&lt;br /&gt;.text:00401021                 xor     eax, eax&lt;br /&gt;.text:00401023                 pop     ebp&lt;br /&gt;.text:00401024                 retn&lt;br /&gt;.text:00401024 main            endp&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Size 18,432 bytes&lt;br /&gt;&lt;br /&gt;Configuration Properties &gt; C/C++ &gt; Code Generation &gt; Buffer Security Check - No (/GS-&lt;br /&gt;* No changes in code or size.&lt;br /&gt;&lt;br /&gt;Project Name &gt; Properties &gt; Configuration Properties &gt; Linker &gt; General &lt;br /&gt;&gt; Enable Incremental Linking - No (/INCREMENTAL:NO)&lt;pre name="code" class="C++"&gt;&lt;br /&gt;&lt;br /&gt;//////////////////////////////////////////////////////////////////////////////&lt;br /&gt;// The /INCREMENTAL option controls how the linker handles incremental linking.&lt;br /&gt;// By default, the linker runs in incremental mode. To override a default &lt;br /&gt;// incremental link, specify /INCREMENTAL:NO. An incrementally linked program is &lt;br /&gt;// functionally equivalent to a program that is nonincrementally linked. However, &lt;br /&gt;// because it is prepared for subsequent incremental links, an incrementally &lt;br /&gt;// linked executable (.exe) file or dynamic-link library (DLL). Is larger than a &lt;br /&gt;// nonincrementally linked program because of padding of code and data. (Padding &lt;br /&gt;// allows the linker to increase the size of functions and data without recreating &lt;br /&gt;// the .exe file.) May contain jump thunks to handle relocation of functions to &lt;br /&gt;// new addresses. &lt;br /&gt;// Source: http://msdn.microsoft.com/en-us/library/4khtbfyf%28v=vs.80%29.aspx &lt;br /&gt;//////////////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;.text:00401000 main            proc near               ; CODE XREF: __tmainCRTStartup+1BA p&lt;br /&gt;.text:00401000                 push    ebp&lt;br /&gt;.text:00401001                 mov     ebp, esp&lt;br /&gt;.text:00401003                 push    offset aHelloWorld ; "Hello world!"&lt;br /&gt;.text:00401008                 call    ds:__imp__printf&lt;br /&gt;.text:0040100E                 add     esp, 4&lt;br /&gt;.text:00401011                 xor     eax, eax&lt;br /&gt;.text:00401013                 pop     ebp&lt;br /&gt;.text:00401014                 retn&lt;br /&gt;.text:00401014 main            endp&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Size 8,192 bytes&lt;br /&gt;&lt;br /&gt;Configuration Properties &gt; C/C++ &gt; Optimization - Minimum Size (/01)&lt;br /&gt;&lt;pre name="code" class="C++"&gt;&lt;br /&gt;//////////////////////////////////////////////////////////////////////////////&lt;br /&gt;// The /O options control various optimizations that help you create code for&lt;br /&gt;// maximum speed or minimum size. /O1 optimizes code for minimum size.&lt;br /&gt;// Source: http://msdn.microsoft.com/en-us/library/k1ack8f1.aspx&lt;br /&gt;//////////////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;.text:00401000 main            proc near               ; CODE XREF: __tmainCRTStartup+1BA p&lt;br /&gt;.text:00401000                 push    offset aHelloWorld ; "Hello world!"&lt;br /&gt;.text:00401005                 call    ds:__imp__printf&lt;br /&gt;.text:0040100B                 pop     ecx&lt;br /&gt;.text:0040100C                 xor     eax, eax&lt;br /&gt;.text:0040100E                 retn&lt;br /&gt;.text:0040100E main            endp&lt;br /&gt;.text:0040100E&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Size 8,192 bytes&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4093139800580227296-8362984007420689372?l=hooked-on-mnemonics.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hooked-on-mnemonics.blogspot.com/feeds/8362984007420689372/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2011/09/visual-studio-options-for-cleaner.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/8362984007420689372'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/8362984007420689372'/><link rel='alternate' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2011/09/visual-studio-options-for-cleaner.html' title='Visual Studio Options for Cleaner Assembly'/><author><name>Alexander Hanel</name><uri>http://www.blogger.com/profile/14943273470531588187</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_fER_9l4iokM/SbA1HWjUNUI/AAAAAAAAAAM/TFFVhDX_YBA/S220/ihatealex1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4093139800580227296.post-6553753138475736207</id><published>2011-06-29T20:46:00.000-07:00</published><updated>2011-07-01T10:53:32.415-07:00</updated><title type='text'>The Massive 2 mb Shellcode API Hash List</title><content type='html'>I have been trying to get the  &lt;a href="http://www.google.com/cse/home?cx=011750002002865445766:pc60zx1rliu"&gt;Malware Analysis Search&lt;/a&gt; to include a page for searching Windows API Hashes. The ror hashing technique is quite popular in shellcode. I'm not going to write about the technique but there are plenty of great posts on it. I'd recommend Rolf's &lt;a href="http://www.openrce.org/blog/view/681/Shellcode_Analysis"&gt;post&lt;/a&gt; on OpenRCE. I hashed (key values 0x0 through 0x1f) over 5k exported functions in advapi32.dll, gdi32.dll, kernel32.dll, netapi32.dll, ntdll.dll, shlwapi.dll, shlwapi.dll, user32.dll, wininet.dll, ws2_32.dll and ws2help.dll. Currently, I have had no luck with getting Google to index the page. So here is a Google spreadsheet &lt;a href="https://spreadsheets.google.com/spreadsheet/pub?key=0AsJdvp2NWuJDdHdiYmRUTzNJaHctZEVaZXZndjNCTlE&amp;amp;output=csv"&gt;link&lt;/a&gt; for anyone who would like a local copy. Just a warning the spreadsheet is 2 MB.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4093139800580227296-6553753138475736207?l=hooked-on-mnemonics.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hooked-on-mnemonics.blogspot.com/feeds/6553753138475736207/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2011/06/massive-2-mb-shellcode-api-hash-list.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/6553753138475736207'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/6553753138475736207'/><link rel='alternate' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2011/06/massive-2-mb-shellcode-api-hash-list.html' title='The Massive 2 mb Shellcode API Hash List'/><author><name>Alexander Hanel</name><uri>http://www.blogger.com/profile/14943273470531588187</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_fER_9l4iokM/SbA1HWjUNUI/AAAAAAAAAAM/TFFVhDX_YBA/S220/ihatealex1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4093139800580227296.post-1997352217877183672</id><published>2011-03-02T19:53:00.000-08:00</published><updated>2011-04-12T19:59:24.850-07:00</updated><title type='text'>IDA MSDN Local Lookup</title><content type='html'>Most of my reverse engineering is done offline. Having the &lt;a href="http://msdn.microsoft.com/en-us/windows/bb980924"&gt;Windows SDK&lt;/a&gt; Document Explorer (aka dexplorer.exe) installed is extremely helpful. Even when I'm online I prefer it over the &lt;a href="http://msdn.microsoft.com/en-us/library/"&gt;MSDN library&lt;/a&gt;. Below is a python script I created so I can see the reference to an API in two clicks. The QT version of IDA has a tendency to add junk data to the copied string. I use the old version rather than the QT. Use at your own risk. &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="python"&gt;&lt;br /&gt;import subprocess&lt;br /&gt;import sys&lt;br /&gt;import idaapi&lt;br /&gt;from win32clipboard import *&lt;br /&gt;import win32api&lt;br /&gt;# http://sourceforge.net/projects/pywin32/files/pywin32/&lt;br /&gt;&lt;br /&gt;# NOTE Older version of IDA will crash if the child process of dexplorer.exe is not closed before closing out IDA. &lt;br /&gt;# The newer version of IDA will crash if subprocess.call(cmd) is used. &lt;br /&gt;&lt;br /&gt;# Usage load the python script, highlight the API, CTRL-C, then ALT-Z, Offline MSDN&lt;br /&gt;# The API name has to be exact: GetAtomName corrent, GetAtomNameA Error &lt;br /&gt;&lt;br /&gt;def lz_msdn():&lt;br /&gt;        #Right click on Windows SDK Documentaion &gt; Properties &gt; Open File Location. &lt;br /&gt;        dexplore_path = r'"C:\Program Files (x86)\Common Files\microsoft shared\Help 9\dexplore.exe"'&lt;br /&gt;        #Open up dexplore.exe search for a random API, the url above the function title will have the namespace&lt;br /&gt;        #Example ms-help://MS.W7SDK.1033/MS.W7SDKCOM.1033/dllproc/base/getprocaddress.htm, copy from "://" to '/' &lt;br /&gt;        namespace = "MS.W7SDK.1033/"&lt;br /&gt;&lt;br /&gt;        #Copy the contents of the clipboard&lt;br /&gt;        OpenClipboard() &lt;br /&gt;        api = GetClipboardData(win32con.CF_TEXT) # get clipboard data&lt;br /&gt;        CloseClipboard()&lt;br /&gt; &lt;br /&gt; #Create dexplore cmd line&lt;br /&gt;        cmd = dexplore_path  + " " + "/helpcol ms-help://" + namespace + " " + "/LaunchFKeywordTopic" + " " + '"' + api + '"'&lt;br /&gt;        subprocess.Popen(cmd)&lt;br /&gt;        print cmd&lt;br /&gt;        &lt;br /&gt; &lt;br /&gt;if __name__ == '__main__':&lt;br /&gt;        if sys.platform == 'win32':&lt;br /&gt;                from win32clipboard import *&lt;br /&gt;                import win32gui, win32con&lt;br /&gt;                idaapi.CompileLine('static altz() { RunPythonStatement("lz_msdn()"); }')&lt;br /&gt;                AddHotkey("alt+z", 'altz')&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4093139800580227296-1997352217877183672?l=hooked-on-mnemonics.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hooked-on-mnemonics.blogspot.com/feeds/1997352217877183672/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2011/03/ida-msdn-local-lookup.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/1997352217877183672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/1997352217877183672'/><link rel='alternate' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2011/03/ida-msdn-local-lookup.html' title='IDA MSDN Local Lookup'/><author><name>Alexander Hanel</name><uri>http://www.blogger.com/profile/14943273470531588187</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_fER_9l4iokM/SbA1HWjUNUI/AAAAAAAAAAM/TFFVhDX_YBA/S220/ihatealex1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4093139800580227296.post-5377152613774440204</id><published>2011-01-17T19:44:00.001-08:00</published><updated>2011-12-02T20:25:57.782-08:00</updated><title type='text'>An Intro to Creating Anti-Virus Signatures:</title><content type='html'>This is an introductory post on creating anti-virus signatures. This post will cover the three main types of signature detections. The most common signatures are hashes, byte-signature and heuristics. The intended audience is for malware analyst and reverse engineers. Experience in binary code analysis is expected. This article is going to focus primarily on creating signatures for Microsoft Portable Executables. The ideas expressed in this post could also be used for creating signatures on other file types that contain exploits. The reason for this post is because there is very little information in regards to creating anti-virus signatures on the internet. A few articles exist on how to create signatures with &lt;a href="http://www.clamav.net/lang/en/"&gt;ClamAV&lt;/a&gt; or using diffing tools. I'm hoping the information in this post will be helpful for others in aiding in creating signatures for classifying malware or detecting malicious documents. If you have any questions or would like more clarity please leave a comment.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;To error on the side of caution.&lt;/span&gt;&lt;br /&gt;There are a couple best practices for creating signatures. The first one is do not target packer or cryptography library code. This type of code is often reused and has a high potential for false positives. The code is usually complicated and is hard to understand the assembly representation. In situations where the packer is unique the code can be used to identify the family of malware. This type of detection has it's flaws. Detecting malware based off of packers gives very little insight into classifying multiple variants. The code could be reused across multiple variants or authors.  Packed code creates a dilemma for signature detection. If the files have been packed or compressed, the file will need to uncompressed or dumped before scanned. Anti-virus engines use emulators and unpackers to get the files to an uncompressed or dumped state before scanning the file. If the files are compressed or packed tools such as &lt;a href="http://www.python.org/"&gt;Python&lt;/a&gt;, &lt;a href="http://www.reversinglabs.com/products/TitanEngine.php"&gt;TitanEngine&lt;/a&gt; or the &lt;a href="http://www.immunityinc.com/products-immdbg.shtml"&gt;Immunity Debugger&lt;/a&gt; could be used for creating dumps or uncompressed files. A side effect of these tools is they will need to be run in a isolated environment such as VMware or Wine.  ClamAV can also unpack some packers such as UPX, FSG, Petite and a couple others.&lt;br /&gt;&lt;br /&gt;Data that has been obfuscated or compressed should never be used as a candidate for a signature. As in the case of file hashes such as &lt;a href="http://en.wikipedia.org/wiki/MD5"&gt;MD5&lt;/a&gt;; changing one byte of data can change the obfuscated or compressed code. Since the bytes can be easily changed by different data or key, there is a chance that the data will not be present in other variants. An example would be if the code obfuscated a URL and then the author changes the URL. All of the code would be static but the bytes of the obfuscated URL would be different. Hence breaking the signature. This scenario is not only applicable for PE files but also compressed steams in PDFs, compressed SWFs and other compressed or obfuscated data.  If there is data in a section of a &lt;a href="http://en.wikipedia.org/wiki/Portable_Executable"&gt;Portable Executable&lt;/a&gt; (PE) that is encrypted and is static throughout multiple files, this would be a good candidate for a sectional MD5.&lt;br /&gt;&lt;br /&gt;The second best practice is do not create signatures on code that can not be understood. Experience in reverse engineering and analyzing a wide range of code will help with choosing sections of code that will not give a false positive. If the code's function can not be understood along with what is calling code, it should not be used as a signature. This will help eliminate the possibility of false positives on library code and other commonly used code. &lt;a href="http://www.hex-rays.com/idapro/"&gt;IDA&lt;/a&gt;'s Flirt signature is extremely useful for helping with identifying common compiler code. If developers of open source and closed source libraries created Flirt signatures and sent them to Hex-Rays they would never have an anti-virus software detect their code again. If the code can be understood then more analysis will be needed or another section of code should be targeted.&lt;br /&gt;&lt;br /&gt;The third is look for the author's hand or internet. A couple of questions to ask in regards to the authors hand. Is the section of code being targeted applicable only towards this piece of malware or is it a common routine such as reading a registry setting? Would the author have written this piece of code for this piece of malware or have hundred authors written the same routine for different programs? This can be difficult to access. Google can be helpful in this situation. Sometimes googling a combination of the APIs can return examples of the code or the malware source code.&lt;br /&gt;&lt;br /&gt;The fourth best practice is to make sure to understand the scope of the scanned files and implications of detection. If the signatures are scanning a repository of malware then the signatures can be vague. If the signature will be scanning desktops across an enterprise network and deleting the detected files, the signature must be accurate. It's always best to error on the side of caution when their is a chance that removing a file can have negative effect. Creating multiple signature for multiple variants is usually safer than creating a generic signature that has potential for false positives.&lt;br /&gt;&lt;br /&gt;The final best practice, strings should be used as a last resort. Strings rarely give any details about the actual code. Strings and data are cheap, code is more expensive and time consuming. Code is more likely to stay static. In some situations such as executables written in Visual Basic strings are advantageous but overall code is best to target. Code and strings can always be combined to make a stronger signatures.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Tools&lt;/span&gt;&lt;br /&gt;There are a couple of open source tools that can be used for scanning files and will be used for examples in this article. Once the initial learning curve is over, these tools are easy to use and can be adapted quickly to most environments. These tools can be run in a Linux or Windows environments. Below is the name of tool and some of it's scanning capabilities. All commands are included in the examples so the reader can try out the examples.&lt;br /&gt;&lt;br /&gt;* &lt;a href="http://www.clamav.net/lang/en/"&gt;ClamAV&lt;/a&gt; -  Hex Byte Scanning, regex, md5 file scanning,  md5 sectional scanning, sigtool ( tool for creating signatures and hashes )&lt;br /&gt;* &lt;a href="http://code.google.com/p/yara-project/"&gt;Yara&lt;/a&gt; -  A powerful rule based scanner that supports many conditions and data types, does not support hashing&lt;br /&gt;* &lt;a href="http://ssdeep.sourceforge.net/"&gt;ssdeep&lt;/a&gt; - A tool for creating and comparing context triggered piecewise hash.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Hash Signatures&lt;/span&gt;&lt;br /&gt;The most basic and easiest type of signature is a hash value.  A hash value is created by a hash function that is a procedure or mathematical function which converts a large amount of data into a single value. The most commonly used hash function is MD5 and SHA-1. These hash functions are extremely accurate. For example if there is block of data that is hashed and then the same block of data has a byte changed then rehashed the hash values will be different.&lt;br /&gt;&lt;br /&gt;&lt;pre class="python" name="code"&gt;&lt;br /&gt;md5 of the string "WeBuiltThisCity!"  = "07363ec9aa7a39c28da675ee2291946b"&lt;br /&gt;md5 of the string "WeBuiltThisCity" = "80b135388f2c979d53c229546c129a61"&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Md5 based signatures can be created using ClamAV. Yara does not support file hashing. ClamAV requires two attributes in order to create a MD5 hash signature. The first is the file size in bytes and the second is the MD5 hash.  ClamAV comes with a tool called sigtool that can be used to generate MD5 signatures. Sigtool can be found in the "bin" directory in the installation folder of ClamAV.&lt;br /&gt;&lt;br /&gt;&lt;pre class="python" name="code"&gt;&lt;br /&gt;C:\XOR\clamwin\bin&amp;gt;sigtool.exe --md5 1.txt&lt;br /&gt;07363ec9aa7a39c28da675ee2291946b:16:C:\XOR\1.txt&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;ClamAV signatures are separated with by a colon ':'.  The first part is the MD5 (07363ec9aa7a39c28da675ee2291946b), the second is the size (16) and the last part is the file location or output. The output is usually the malware name or something specific to the file. Colons can not be used in the output because these are treated as special characters in ClamAV signatures database. MD5 signatures need to be saved in a file with a .hdb extension. The above output from sigtool could be piped ( &amp;gt; ) to a file called shredder.hdb. This makes it very easy to create MD5 signatures with all files in a directory using a simple for loop in bash or the window command line.  See reference 1 for more information. This also makes it possible to create ClamAV signatures from &lt;a href="http://www.virustotal.com/"&gt;Virustotal&lt;/a&gt; results without having the file because the MD5 and file size are provided in the Virustotal Analysis.&lt;br /&gt;&lt;br /&gt;Hash values are useful if the malware sample is static but if one byte in the executable is changed; the hash signature is broken. In some instances the code of the executable never changes but the data that the executable uses does. An example of code that might not change would be the executable produced by a GUI Remote Access Trojan kit. The codes sections would be the same but if one user used 192.168.0.1 and another used 192.160.2 the data sections would be different. In this example sectional hashing could be used to target the codes section data block and create a hash based signature.&lt;br /&gt;&lt;br /&gt;&lt;pre class="python" name="code"&gt;&lt;br /&gt;Example of a sectional hash using ClamAV:&lt;br /&gt;PESectionSize:MD5:MalwareName&lt;br /&gt;.code:80b135388f2c979d53c229546c129a61:Rocksteady&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The signature will need to be saved in a file with a .mdb file extension in order to be in the proper ClamAV format. As stated before colons are treated as special characters for separating data in the ClamAV signature database. The first part is the PE section name (.code), the second is the MD5 hash of the section (80b135388f2c979d53c229546c129a61) and the last is the output or name of the malware (Rocksteady). See reference 1 for more information.&lt;br /&gt;&lt;br /&gt;Hashing can also be used to identify files that have been modified.  Fuzzy hashing is a combination of recursive computing and context triggered hashing. It can be used to identify files that have had data deleted, modified or new data inserted. Jesse Kornblum is the developer of a tool called ssdeep.  Below is an example of comparing two executable  files with a single byte difference.&lt;br /&gt;&lt;br /&gt;&lt;pre class="python" name="code"&gt;&lt;br /&gt;C:\XOR&amp;gt;md5sum *&lt;br /&gt;623eea5c4c6209e1ebe44b2e6ca16428 *simple - edit.exe&lt;br /&gt;e300ef28554d39ee3668dca05d5d5415 *simple.exe&lt;br /&gt;&lt;br /&gt;C:\XOR&amp;gt;ssdeep *&lt;br /&gt;ssdeep,1.1--blocksize:hash:hash,filename&lt;br /&gt;384:hJyMBCI1Ex85hKuwoK/ZiBqv5ICmOKk7iw:hJlC38wBY0,"C:\XOR\simple - edit.exe"&lt;br /&gt;384:BJyMBCI1Ex85hKuwoK/ZiBqv5ICmOKk7iw:BJlC38wBY0,"C:\XOR\simple.exe"&lt;br /&gt;&lt;br /&gt;C:\XOR\simple.exe matches C:\XOR\simple - edit.exe (99)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Fuzzy hashing requires all the hashes to be stored in an ascii text file and then each hashed file will need to be matched against the ascii hash text file. This type of scanning is more computational intensive than other forms of scanning due to the hashing and comparing of all the hash values. An issue with fuzzy hashing ( or all hashes for that matter ) is that what might seem like slight modifications by the author/programmer can noticeably change the calculated match value. Our &lt;a href="http://codepad.org/fjYQxFJ6"&gt;simple.exe&lt;/a&gt; was modified by changing some of the output strings and recompiled as &lt;a href="http://codepad.org/LIFXRG6X"&gt;simple2.exe&lt;/a&gt;; no code was changed.&lt;br /&gt;&lt;br /&gt;&lt;pre class="python" name="code"&gt;&lt;br /&gt;C:\XOR\ssdeep *&lt;br /&gt;ssdeep,1.1--blocksize:hash:hash,filename&lt;br /&gt;384:BJyMBCI1Ex85hKuwoK/ZiBqv5ICmOKk7iw:BJlC38wBY0,"C:\XOR\simple.exe"&lt;br /&gt;384:5JTMJCv1w05hDuwoKoRiBqP5IqmuKk7iw:5JOCXrQQ0,"C:XOR\simple2.exe"&lt;br /&gt;&lt;br /&gt;C:\XOR\diff-strings\New Folder&amp;gt;ssdeep&lt;br /&gt;ssdeep: No input files&lt;br /&gt;&lt;br /&gt;C:\XOR\diff-strings\New Folder&amp;gt;ssdeep -d *&lt;br /&gt;&lt;br /&gt;C:\XOR\diff-strings\New Folder&amp;gt;ssdeep *&lt;br /&gt;ssdeep,1.1--blocksize:hash:hash,filename&lt;br /&gt;384:BJyMBCI1Ex85hKuwoK/ZiBqv5ICmOKk7iw:BJlC38wBY0,"C:\XOR\diff-strings\New Folde&lt;br /&gt;r\simple.exe"&lt;br /&gt;384:5JTMJCv1w05hDuwoKoRiBqP5IqmuKk7iw:5JOCXrQQ0,"C:\XOR\diff-strings\New Folder\&lt;br /&gt;simple2.exe"&lt;br /&gt;&lt;br /&gt;C:\XOR\&amp;gt;ssdeep simple.exe &amp;gt; out.txt&lt;br /&gt;C:\XOR\&amp;gt;ssdeep simple2.exe &amp;gt; out2.txt&lt;br /&gt;&lt;br /&gt;C:\XOR\&amp;gt;ssdeep -d out*&lt;br /&gt;C:\XOR\out2.txt matches C:\XOR\out.txt (50)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Since all hashes need to be saved to a text file and then compared ssdeep can be computational expensive. See reference 2 for more information.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Byte-Signatures &lt;/span&gt;&lt;br /&gt;Byte-signature or byte detections are a signature based off a sequence of file bytes that are present in a file or data stream. Byte signatures are a very common form of detection and have been used since the first anti-virus scanner. Their usefulness is due to the accuracy they provide for detecting a sequence of bytes. The sequence of bytes is chosen because it exist in multiple variants of malware from the same family.&amp;nbsp; Byte-signatures can be any type of data such as code or data contained inside of a data stream of an executable, a XORed .pdf or a Word document.&lt;br /&gt;&lt;br /&gt;&lt;pre class="python" name="code"&gt;&lt;br /&gt;Example of a byte signature in the ClamAV format.&lt;br /&gt;Simple dot exe:1:90FF1683EE0483EB0175F6&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;"Simple dot exe" is the output displayed by the ClamAV scanner; this is usually the malware family name. The second section is for the ClavAV engine to know the file type of the scanned file. The value '1' is for the engine to scan portable executable files. To scan any file type the value '0' needs to be used. The "90FF1683EE0483EB0175F6" is the hexadecimal representation of the opcodes. It represents the below assembly.&lt;br /&gt;&lt;br /&gt;&lt;pre class="python" name="code"&gt;&lt;br /&gt;start: 0x401A2E  length: 0xC&lt;br /&gt;90     nop&lt;br /&gt;FF 16     call    dword ptr [esi]&lt;br /&gt;83 EE 04    sub     esi, 4&lt;br /&gt;83 EB 01    sub     ebx, 1&lt;br /&gt;75 F6     jnz     short loc_401A30&lt;br /&gt;&lt;br /&gt;Example of a byte signature in the Yara format.&lt;br /&gt;rule example&lt;br /&gt;{&lt;br /&gt;strings:&lt;br /&gt;signature = { 66 90 FF 16 83 EE 04 83 EB 01 75 F6 }&lt;br /&gt;condition:&lt;br /&gt;signature&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Yara's signature format is much different than ClamAV. The syntax style is similar to a C struct. The first string defines that we are creating a rule of "example".  The "strings" and "condition" are keywords used by the Yara engine. The strings defines the signatures. Yara's signatures can be any many formats from strings, hex-bytes, regex and a number of other formats. The keyword "condition" defines under what circumstances Yara should alert on the signature. There are many conditions that can be constructed for Yara to detect a file. See reference 6 for more information.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Binary Diffing&lt;/span&gt;&lt;br /&gt;Manual and automated analysis techniques can be used for finding code blocks that are present throughout variants. The process of comparing multiple executables for similarities is called binary diffing.  Manual binary diffing consists of reviewing the disassembly of multiple files and noting sections of code that are present in multiple files. Once blocks of code are identified a side-by-side comparison can be done checking for similarities. If the code has a high similarity it might be a good candidate for a byte-signature. A semi-automated approach of binary diffing would consist of grouping files into sets of files that are similar, use a disassembler to to get the assembly in a text output, diff the outputs, create more specific sets for diffs that match and then manually analyze the sections of codes that were found in the diffs that matched. For example, we could use IDA to create the assembly output and then use &lt;a href="http://kdiff3.sourceforge.net/"&gt;Kdiff&lt;/a&gt; to diff the assembly outputs.&lt;br /&gt;&lt;br /&gt;&lt;pre class="python" name="code"&gt;&lt;br /&gt;C:\XOR\&amp;gt;dir&lt;br /&gt;     23,503 simple.exe&lt;br /&gt;     23,503 simple2.exe&lt;br /&gt;&lt;br /&gt;C:\XOR\&amp;gt;"C:\Program Files\IDA Free\idag.exe" -B "simple.exe"&lt;br /&gt;&lt;br /&gt;C:\XOR\&amp;gt;"C:\Program Files\IDA Free\idag.exe" -B "simple2.exe"&lt;br /&gt;&lt;br /&gt;C:\XOR\&amp;gt;dir&lt;br /&gt;     51,262 simple.asm&lt;br /&gt;     23,503 simple.exe&lt;br /&gt;    204,956 simple.idb&lt;br /&gt;     51,274 simple2.asm&lt;br /&gt;     23,503 simple2.exe&lt;br /&gt;    204,956 simple2.idb&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The "-B" flag is for creating an IDA database (.idb) and a text output of the assembly (.asm). The assembly output can then be diffed. Kdiff is a good tool to diff files because it does not do a straight diff of the two files. It will try to align sections that our separated by large amounts of data or code. These sections could be different because of a function that wasn't included in one executable or the presence of junk code or data. KDiff can also diff up to three files at a time. Automated tools such as &lt;a href="http://www.zynamics.com/bindiff.html"&gt;Bindiff&lt;/a&gt;, &lt;a href="http://code.google.com/p/patchdiff2/"&gt;PatchDiff2&lt;/a&gt; and &lt;a href="http://www.darungrim.org/"&gt;DarunGrim&lt;/a&gt; can be used to find differences between IDA database files. These tools are more specifically designed towards binary diffing paths. &lt;a href="http://www.zynamics.com/vxclass.html"&gt;VxClass&lt;/a&gt; is another tool that can be used for creating sets of variants, binary diffing and identifying sections of code that could be used for potential signatures **.&lt;br /&gt;&lt;br /&gt;Diffing is also very useful for displaying sections of code where wildcards will need to be used for byte-signatures. The wildcards will allow the scanner to ignore bytes of code that are not static throughout multiple variants.  The non-static bytes could be caused by the insertion of junk code, addition or removal of code or the addition or removal of data. A slight change in file alignment can break byte-signatures that targets instructions. Common instructions that use offsets based off of file alignment are long jmps, call sub-routine or call an api or others that cmp, mov, sub, add, etc that reference offsets. It's best when creating signatures to always add the wildcards for the offsets even if they are static throughout multiple variants.  An example below can be seen how file alignment can break byte-signatures. The two code blocks are from simple.exe and simple2.exe. The starting codes address, functionality and length are exactly the same. The only difference between the two blocks of code are the address offsets of the dword that is compared against ebx. The difference in file alignment was caused by the output strings being a different length.&lt;br /&gt;&lt;br /&gt;&lt;pre class="python" name="code"&gt;&lt;br /&gt;simple.exe&lt;br /&gt;start: 0x401902  length: 0x14&lt;br /&gt;81 FB 8C 31 40 00   cmp     ebx, offset dword_40318C&lt;br /&gt;0F 83 3A FF FF FF   jnb     loc_401848&lt;br /&gt;BE 00 00 40 00    mov     esi, 400000h&lt;br /&gt;8D 7D E0    lea     edi, [ebp+var_20]&lt;br /&gt;&lt;br /&gt;81 FB 8C 31 40 00 0F 83 3A FF FF FF BE 00 00 40 00 8D 7D E0&lt;br /&gt;&lt;br /&gt;simple2.exe&lt;br /&gt;start: 0x401902  length: 0x14&lt;br /&gt;81 FB 94 31 40 00   cmp     ebx, offset dword_403194&lt;br /&gt;0F 83 3A FF FF FF   jnb     loc_401848&lt;br /&gt;BE 00 00 40 00    mov     esi, 400000h&lt;br /&gt;8D 7D E0    lea     edi, [ebp+var_20]&lt;br /&gt;&lt;br /&gt;81 FB 94 31 40 00 0F 83 3A FF FF FF BE 00 00 40 00 8D 7D E0&lt;br /&gt;&lt;br /&gt;ClamAV Format&lt;br /&gt;Both Simple dot exe:1:81FB********0F833AFFFFFFBE000040008D7DE0&lt;br /&gt;&lt;br /&gt;Yara Format&lt;br /&gt;rule both_simple_dot_exe&lt;br /&gt;{&lt;br /&gt;strings:&lt;br /&gt;signature = { 81 FB ?? ?? ?? ?? 0F 83 3A FF FF FF BE 00 00 40 00 8D 7D E0 }&lt;br /&gt;condition:&lt;br /&gt;signature&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Heuristics&lt;/span&gt;&lt;br /&gt;The last type of signature detections is heuristics. Heuristics is used when the malware is too complex for hash and byte-signatures. Heuristics is a general term for the different techniques used to detect malware by their behavior. It is one of the most complex forms of detections. An anti-virus engine might use emulation, API hooking, sand-boxing, file anomalies and other analysis techniques. Each anti-virus engine uses different algorithms and different proprietary techniques. A simple example of creating a heuristics signature would include an API logger and rules based off the APIs. Let's start with the "Hello World" of malware, Poison Ivy. We can use a server as an example for creating an API rule based signature. When Poison Ivy is executed it will create a mutex, write a registry key and copy itself over to the System32 directory. The default mutex for Poison Ivy is ")!VoqA.I4". Using Kerberos API Monitor we can simulate an API hook (that an anti-virus engine might use). A heuristics API rule for Poison Ivy can be seen below. &lt;br /&gt;&lt;br /&gt;&lt;pre class="python" name="code"&gt;&lt;br /&gt;Rule A&lt;br /&gt;An API call to RtlMoveMemory with a string of "SOFTWARE\Classes\http\shell\open\commandV"&lt;br /&gt;&lt;br /&gt;Rule B&lt;br /&gt;An API call to CreateMutexA with a string of ")!VoqA.I4"&lt;br /&gt;&lt;br /&gt;Rule C&lt;br /&gt;An API call to GetSystemDirectory&lt;br /&gt;&lt;br /&gt;if ( Rule A then Rule B then Rule C )&lt;br /&gt;then&lt;br /&gt;Process  = PoisonIvy&lt;br /&gt;&lt;br /&gt;Keribos Output&lt;br /&gt;Rule A&lt;br /&gt;simple.exe   | 00401447 | RtlMoveMemory(0012F458, 0040162F: "SOFTWARE\Classes\http\shell\open\commandV", 00000028) returns: 0012F458&lt;br /&gt;...........&lt;br /&gt;Rule B&lt;br /&gt;simple.exe   | 0040155D | CreateMutexA(00000000, 00000000, 0012F43B: ")!VoqA.I4") returns: 0000003C&lt;br /&gt;...........&lt;br /&gt;Rule C&lt;br /&gt;simple.exe   | 004018BF | GetSystemDirectoryA(0012F6F1, 000000FF) returns: 00000013&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Parsing API logs from tools such as Norman and CWS Sandbox could be used to create similar rules for malware that is packed, encrypted or hash or byte-signatures fail to detect.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;This post is just an introductory to creating anti-virus signatures. I am by no means an expert in the different technologies and algorithms used for scanning files. My experience is limited to hashing, byte-signatures, memory offset byte-signatures and creating detection mechanisms for malicious documents. I hope this article was useful and might give some ideas for other reverse engineers and malware analyst. If you know of any good articles on anti-virus scanning and the algorithms please leave a comment. I'd like to thank b0ne for all his help over the years.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;References:&lt;/span&gt;&lt;br /&gt;1. www.clamav.net/doc/latest/signatures.pdf&lt;br /&gt;2. http://dfrws.org/2006/proceedings/12-Kornblum.pdf&lt;br /&gt;3. http://www.virustotal.com/file-scan/report.html?id=fab272012d934f75915cd888f213e8857c390086363351eab3bf69f19ce67b65-1292244815&lt;br /&gt;4. http://www.zynamics.com/bindiff.html,  http://code.google.com/p/patchdiff2/, http://www.darungrim.org/&lt;br /&gt;5. http://kdiff3.sourceforge.net/&lt;br /&gt;6. http://code.google.com/p/yara-project/downloads/list&lt;br /&gt;** The author has never personally used VxClass. This information is second hand from Zynamics blog and site.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4093139800580227296-5377152613774440204?l=hooked-on-mnemonics.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hooked-on-mnemonics.blogspot.com/feeds/5377152613774440204/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2011/01/intro-to-creating-anti-virus-signatures.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/5377152613774440204'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/5377152613774440204'/><link rel='alternate' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2011/01/intro-to-creating-anti-virus-signatures.html' title='An Intro to Creating Anti-Virus Signatures:'/><author><name>Alexander Hanel</name><uri>http://www.blogger.com/profile/14943273470531588187</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_fER_9l4iokM/SbA1HWjUNUI/AAAAAAAAAAM/TFFVhDX_YBA/S220/ihatealex1.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4093139800580227296.post-8568625282150004377</id><published>2010-11-09T18:19:00.001-08:00</published><updated>2010-11-09T20:48:34.780-08:00</updated><title type='text'>Malware Analysis Search</title><content type='html'>This is a custom Google that searches anti-virus analysis pages, malware analysis blogs and other related malware/RCE websites. Currently about 75 different sites are used. This helps with removing all the clutter of forums and other useless search results. Sometimes when looking at malware I want to know if someone else has already analyzed it. Hopefully this will be helpful.&lt;br /&gt;&lt;br /&gt;Easily Memorable Google Hosted Link (Thanks Google!)&lt;br /&gt;&lt;a href="http://www.google.com/cse/home?cx=011750002002865445766:pc60zx1rliu"&gt;http://www.google.com/cse/home?cx=011750002002865445766:pc60zx1rliu&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Currently the following sites are being searched. &lt;br /&gt;http://xml.ssdsandbox.net/archive/&lt;br /&gt;http://www.threatexpert.com/report.aspx?&lt;br /&gt;http://www.virustotal.com/file-scan/&lt;br /&gt;http://blog.fireeye.com/&lt;br /&gt;http://blogs.technet.com/b/mmpc/&lt;br /&gt;http://www.microsoft.com/security/portal/Threat/Encyclopedia/&lt;br /&gt;http://vrt-sourcefire.blogspot.com/&lt;br /&gt;http://community.websense.com/blogs/securitylabs/&lt;br /&gt;http://blog.scansafe.com/&lt;br /&gt;http://www.f-secure.com/weblog/ &lt;br /&gt;http://www.f-secure.com/v-descs/&lt;br /&gt;http://blog.fortinet.com/&lt;br /&gt;http://www.fortiguard.com/encyclopedia/virus/&lt;br /&gt;http://www.securelist.com/en/&lt;br /&gt;http://www.prevx.com/blog.asp&lt;br /&gt;http://research.pandasecurity.com/&lt;br /&gt;http://www.pandasecurity.com/homeusers/security-info/about-malware/encyclopedia/&lt;br /&gt;‪http://www.avira.com/en/support-threats-summary/‬    &lt;br /&gt;‪http://techblog.avira.com/en/‬    &lt;br /&gt;‪http://eureka.cyber-ta.org/‬    &lt;br /&gt;‪http://twitter.com/taviso/‬    &lt;br /&gt;‪http://twitter.com/sans_isc/‬    &lt;br /&gt;‪http://twitter.com/RolfRolles/‬    &lt;br /&gt;‪http://twitter.com/rcecoder/‬    &lt;br /&gt;‪http://twitter.com/pedramamini/‬    &lt;br /&gt;‪http://twitter.com/OComputing/‬    &lt;br /&gt;‪http://twitter.com/ochsff/‬    &lt;br /&gt;‪http://twitter.com/nicolasbrulez/‬    &lt;br /&gt;‪http://twitter.com/nickharbour/‬    &lt;br /&gt;‪http://twitter.com/msuiche/‬    &lt;br /&gt;‪http://twitter.com/mlsau/‬    &lt;br /&gt;‪http://twitter.com/mikkohypponen/‬    &lt;br /&gt;‪http://twitter.com/mdowd/‬    &lt;br /&gt;‪http://twitter.com/jvanegue/‬    &lt;br /&gt;‪http://twitter.com/j00ru/‬    &lt;br /&gt;‪http://twitter.com/Ivanlef0u/‬    &lt;br /&gt;‪http://twitter.com/hdmoore/‬    &lt;br /&gt;‪http://twitter.com/halvarflake/‬    &lt;br /&gt;‪http://twitter.com/erocarrera/‬    &lt;br /&gt;‪http://twitter.com/DidierStevens/‬    &lt;br /&gt;‪http://twitter.com/egyp7/‬    &lt;br /&gt;‪http://twitter.com/dinodaizovi/‬    &lt;br /&gt;‪http://twitter.com/codypierce/‬    &lt;br /&gt;‪http://twitter.com/attractr/‬    &lt;br /&gt;‪http://twitter.com/alexsotirov/‬    &lt;br /&gt;‪http://bugix-security.blogspot.com/‬    &lt;br /&gt;‪http://seclists.org/#fulldisclosure‬    &lt;br /&gt;‪http://blog.trendmicro.com/‬    &lt;br /&gt;‪http://www.exploit-db.com/‬    &lt;br /&gt;‪http://xanalysis.blogspot.com/‬    &lt;br /&gt;‪http://research.zscaler.com/‬    &lt;br /&gt;‪http://jsunpack.blogspot.com/‬    &lt;br /&gt;‪http://www.sophos.com/security/analyses/‬    &lt;br /&gt;‪http://www.symantec.com/security_response/‬    &lt;br /&gt;‪http://www.symantec.com/connect/blogs/‬    &lt;br /&gt;‪http://vil.nai.com/vil/content/‬    &lt;br /&gt;‪http://blogs.mcafee.com/mcafee-labs/‬ &lt;br /&gt;&lt;br /&gt;Reviewing the links you might have noticed a lot of twitter feeds. These are useful for finding information on exploits or 0days. I just started ripping through my RSS feed and will be adding more sites as I come across them. If I'm missing something please leave a comment.&lt;br /&gt;&lt;br /&gt;Give it a shot.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Malware Analysis Search&lt;/span&gt;&lt;br /&gt;&lt;form action="http://www.google.com/cse" id="cse-search-box"&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;input type="hidden" name="cx" value="011750002002865445766:pc60zx1rliu" /&gt;&lt;br /&gt;&lt;input type="hidden" name="ie" value="UTF-8" /&gt;&lt;br /&gt;&lt;input type="text" name="q" size="31" /&gt;&lt;br /&gt;&lt;input type="submit" name="sa" value="Search" /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt;&lt;script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4093139800580227296-8568625282150004377?l=hooked-on-mnemonics.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hooked-on-mnemonics.blogspot.com/feeds/8568625282150004377/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2010/11/malware-analysis-search.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/8568625282150004377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/8568625282150004377'/><link rel='alternate' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2010/11/malware-analysis-search.html' title='Malware Analysis Search'/><author><name>Alexander Hanel</name><uri>http://www.blogger.com/profile/14943273470531588187</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_fER_9l4iokM/SbA1HWjUNUI/AAAAAAAAAAM/TFFVhDX_YBA/S220/ihatealex1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4093139800580227296.post-800604381507711682</id><published>2010-04-28T19:59:00.000-07:00</published><updated>2010-06-30T21:19:48.854-07:00</updated><title type='text'>Creating Your Own Virustotal..Well Kind Of..Ok, Not Really</title><content type='html'>&lt;a href="http://www.virustotal.com/"&gt;Virustotal&lt;/a&gt; is free website that allows individual to upload files to be scanned by 41 anti-virus engines and file identification tools. Virustotal was created in 2004 by &lt;a href="http://www.hispasec.com/"&gt;Hispasec Sistemas&lt;/a&gt;. Virustotal is a very valuable tool for many system admins, technical support engineers or anyone else who is curious if a file malicious. The main downside to Virustotal is that you have to submit your samples through a web interface or email. Sometimes it's nicer to have a quick report from the command line but in certain situations you can't submit the samples. &lt;br /&gt;&lt;br /&gt;This post focuses on analyzing Microsoft Portable Executable (PE) files using Python, PeFile, PEID and a command line anti-virus scanner. This post will display the Python code for creating the PE information displayed under the anti-Virus scanner results on Virustotal results page. The post also will contain the code to call and display the results for an anti-virus command line scanner.&lt;br /&gt;&lt;br /&gt;Python still feels new to me so please feel free to email me or leave a comment if you have any recommendations or advice on the code. The full source code can be found &lt;a href="http://hooked-on-mnemonics.blogspot.com/p/portable-executable-virustotal-example.html"&gt;here&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;Let's start at the top of the code with the imports. &lt;br /&gt;&lt;pre name="code" class="python"&gt;&lt;br /&gt;import sys&lt;br /&gt;import os&lt;br /&gt;import pefile&lt;br /&gt;import peutils&lt;br /&gt;import math&lt;br /&gt;import time&lt;br /&gt;import datetime&lt;br /&gt;import subprocess&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The only non-standard modules listed above are Pefile and Peutils. These were created by Ero Carrea. Both of these modules can be found &lt;a href="http://code.google.com/p/pefile/"&gt;here&lt;/a&gt;. For anyone new to Python, modules are files that contain statements and definitions that can be used to import functionality. Please see this &lt;a href="http://effbot.org/zone/import-confusion.htm"&gt; article&lt;/a&gt; for more details. &lt;br /&gt;&lt;br /&gt;Below is the first function that will be called. The function "attributes" extracts  basic information from the Portable Executable. The Portable Executable is a file format that the Windows operating system uses to encapsulates data and code. The Windows OS Loader uses the data structure to manage the wrapped executable code. &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="python"&gt;&lt;br /&gt;## Print PE file attributes&lt;br /&gt;def attributes():  &lt;br /&gt;        print "Image Base:", hex(pe.OPTIONAL_HEADER.ImageBase)&lt;br /&gt;        print "Address Of Entry Point:", hex(pe.OPTIONAL_HEADER.AddressOfEntryPoint)&lt;br /&gt;        machine = 0&lt;br /&gt;        machine = pe.FILE_HEADER.Machine&lt;br /&gt;        print "Required CPU type:", pefile.MACHINE_TYPE[machine]&lt;br /&gt;        dll = pe.FILE_HEADER.IMAGE_FILE_DLL&lt;br /&gt;        print "DLL:", dll&lt;br /&gt;        print "Subsystem:", pefile.SUBSYSTEM_TYPE[pe.OPTIONAL_HEADER.Subsystem]&lt;br /&gt;        print "Compile Time:",   datetime.datetime.fromtimestamp(pe.FILE_HEADER.TimeDateStamp)&lt;br /&gt;        print "Number of RVA and Sizes:", pe.OPTIONAL_HEADER.NumberOfRvaAndSizes&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Above we are using PeFile to read and display data from the PE format. Before using Pefile the executable will need to be loaded into memory. This will be covered when Main() is discussed.  &lt;br /&gt;&lt;br /&gt;Output:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Portable Executable Information&lt;br /&gt;Optional Header: 0x400000&lt;br /&gt;Address Of Entry Point: 0x78020&lt;br /&gt;Required CPU type: IMAGE_FILE_MACHINE_I386&lt;br /&gt;DLL: False&lt;br /&gt;Subsystem: IMAGE_SUBSYSTEM_WINDOWS_GUI&lt;br /&gt;Compile Time: 2007-04-29 05:43:12&lt;br /&gt;Number of RVA and Sizes: 16&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Attributes from the PE can give information about the executable that can be valuable when analyzing an unknown executable. The first output line is the Image Base of the executable. The default value for an application is 0x00400000 and 0x10000000 for a Dll. A value that is non-standard could be a possible flag and should be noted. &lt;br /&gt;&lt;br /&gt;The second output is the address of the entry point. The entry point is the starting address for the executable, address of the initialization function for device drivers and the entry point is optional for a Dll. The standard value for the entry point is 0x01000. If the value is non-standard it should be noted because the entry point could have possibly been changed by a packer or obfuscation tool. &lt;br /&gt;&lt;br /&gt;The third output is the Machine Type. This can be used to identify if the file is 32-bit or 64-bit. If the Machine Type value is IMAGE_FILE_MACHINE_I386 then executable is 32-bit. To identify a 64-bit executable the Machine Type value would be IMAGE_FILE_MACHINE_AMD64 or IMAGE_FILE_MACHINE_IA64.&lt;br /&gt;&lt;br /&gt;The fourth output simply identifies if the executable is DLL or not. &lt;br /&gt;&lt;br /&gt;The fifth output identifies the subsystem type. In the example above IMAGE_SUBSYSTEM_WINDOWS_GUI identifies that the executable has a Windows GUI. If the subsystem was IMAGE_SUBSYSTEM_WINDOWS_CUI it would mean the executable is a console application. The third common subsystem type is IMAGE_SUBSYSTEM_NATIVE. This is reserved for drivers and native system processes. Just a side not to idenitfy a Xbox executable the subsystem type would be IMAGE_SUBSYSTEM_XBOX.&lt;br /&gt;&lt;br /&gt;The sixth line of output is the time the executable was compiled. &lt;br /&gt;&lt;br /&gt;The last line of output displays the NumberOfRvaAndSizes. The default value for this attribute is 0x10 or 16 in decimal. Modification of this value can be used to crash Ollydbg. If the value is non-standard and Ollydbg gives an error patching this field might be needed. These values are helpful because they give clues if there is anything non-standard about the executable. Non-standard values could be from a packer, some code obfuscation tool or by the programmer passing the compiler flags. &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="python"&gt;&lt;br /&gt;def sections_analysis():&lt;br /&gt;        print "Number of Sections:", pe.FILE_HEADER.NumberOfSections&lt;br /&gt;        print&lt;br /&gt;        print "Section  VirtualAddress VirtualSize SizeofRawData Entropy"&lt;br /&gt;        for section in pe.sections:&lt;br /&gt;                print "%-8s"  % section.Name, "%-14s" % hex(section.VirtualAddress), "%-11s" % hex(section.Misc_VirtualSize),\&lt;br /&gt;                      "%-13s" % section.SizeOfRawData, "%.2f" % E(section.data)&lt;br /&gt;        print &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The next function called is "sections_analysis". This sections outputs the name of the sections, it's  virtual address, it's virtual size, size of raw data and it's entropy. This information is valuable because certain packers will modify these attributes. Packers will sometime rename sections, create new sections, or modify other attributes. For a detailed analysis of how packer work please see Websense's "&lt;a href="http://securitylabs.websense.com/content/Assets/HistoryofPackingTechnology.pdf"&gt;The History of Packing Technology&lt;/a&gt;".&lt;br /&gt;&lt;br /&gt;Output:&lt;code&gt;&lt;br /&gt;Number of Sections: 3&lt;br /&gt;&lt;br /&gt;Section  VirtualAddress VirtualSize SizeofRawData Entropy&lt;br /&gt;UPX0     0x1000               0x42000     0                          0.00&lt;br /&gt;UPX1     0x43000            0x36000     217600               7.93&lt;br /&gt;.rsrc        0x79000            0x2000       7680                     4.00&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The above output gives hints to what type of packer was used just be reviewing the section names. In the case of the test executable, Putty.exe was compressed using &lt;a href="http://en.wikipedia.org/wiki/UPX"&gt;UPX&lt;/a&gt;.  The string UPX can be observed in the section names. Two other attributes that should be mentioned is the zero size of the raw data of UPX0 and the high entropy of the section UPX1. During execution of a packed executable UPX will need to write the uncompressed data to a section. The section UPX0 with a size of zero will be used for storing the uncompressed data. Not all packers will use this technique but this is another characteristics that should be noted. &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="python"&gt;&lt;br /&gt;## Entropy calculation from Ero Carrera's blog ###############&lt;br /&gt;def E(data):&lt;br /&gt;        entropy = 0  &lt;br /&gt;        if not data:&lt;br /&gt;                return 0&lt;br /&gt;        ent = 0&lt;br /&gt;        for x in range(256):&lt;br /&gt;                p_x = float(data.count(chr(x)))/len(data)&lt;br /&gt;                if p_x &gt; 0:&lt;br /&gt;                        entropy += - p_x*math.log(p_x, 2)&lt;br /&gt;        return entropy&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Entropy is a measurement of how organized or disorganized data is. The more random the data is the higher the entropy will be. Packers will apply an algorithm to either compress the data or obfuscate it. The output of the packed data has a higher entropy and is more random than the original compiled executable. The  entropy range for the "E" function ranges between 0.0 and 8.0. The closer the entropy is to 8.0 the higher the chances that the section is packed or obfuscated. Please see &lt;a href="http://blog.dkbza.org/2007/05/scanning-data-for-entropy-anomalies.html"&gt;here&lt;/a&gt; for more details. &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="python"&gt;&lt;br /&gt;## Load PEID userdb.txt database and scan file&lt;br /&gt;def PEID():&lt;br /&gt;        signatures = peutils.SignatureDatabase('userdb.txt')&lt;br /&gt;        matches = signatures.match_all(pe,ep_only = True)&lt;br /&gt;        print "PEID Signature Match(es): ", matches&lt;br /&gt;        print&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;PEID is tool for detecting common packers, cryptors and compilers for PE files. By identifying the algorithm the PE file is compressed or obfuscated it can help speed up analysis. Google, the name of the packer and the string "tutorial" will usually return an analysis on how to unpack the file. Pefile has functionality to use PEID's user database (userdb.txt) to scan a PE file. The main PEID user database was created by BobSoft and can be downloaded &lt;a href="http://www.peid.info/BobSoft/Downloads.html"&gt;here&lt;/a&gt;. Many individuals use Panda Anti-Virus userdb.txt. A warning to users of Panda's userdb.txt. Pefile will throw exceptions and will not work due to some non-standard characters. It's recommended to use BobSoft's userdb.txt. &lt;br /&gt;&lt;br /&gt;Output:&lt;code&gt;&lt;br /&gt;PEID Signature Matche(s):  [['UPX 2.90 [LZMA] -&gt; Markus Oberhumer, Laszlo Molnar &amp; John Reiser']]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The last function is called IAT(). This function will display all imported Dlls and the imported API name.   &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="python"&gt;&lt;br /&gt;## Dump Imports&lt;br /&gt;def IAT():&lt;br /&gt;        print "Imported DLLS:"&lt;br /&gt;        i = 1&lt;br /&gt;        for entry in pe.DIRECTORY_ENTRY_IMPORT:&lt;br /&gt;                bool = 1 ## For Formattting &lt;br /&gt;                print "%2s" % [i], "%-17s" % entry.dll&lt;br /&gt;                print "\t",&lt;br /&gt;                for imp in entry.imports:&lt;br /&gt;                        if bool:&lt;br /&gt;                                print "%-1s" % imp.name,&lt;br /&gt;                                bool = 0&lt;br /&gt;                        else:&lt;br /&gt;                                sys.stdout.write("%s%s" % (", ",imp.name)) # Python Print adds a blank space &lt;br /&gt;                print&lt;br /&gt;                i += 1&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Reviewing all API calls can help with giving a high level view of the behavior of the executable. If the APIs list is sparse this might be a sign that the executable has had it's Import table removed.  The standard "Hello, World" complied in C using LCC would contain 19 API names. If there are only three APIs listed such as LoadLibrary, GetProcAddress and ExitProcess odds are the file is packed or obfuscated in some manner. &lt;br /&gt;&lt;br /&gt;Output:&lt;code&gt;&lt;br /&gt;Imported DLLS:&lt;br /&gt;[1] KERNEL32.DLL     &lt;br /&gt; LoadLibraryA, GetProcAddress, ExitProcess&lt;br /&gt;[2] ADVAPI32.dll     &lt;br /&gt; RegCloseKey&lt;br /&gt;[3] COMCTL32.dll     &lt;br /&gt; None&lt;br /&gt;[4] comdlg32.dll     &lt;br /&gt; ChooseFontA&lt;br /&gt;[5] GDI32.dll        &lt;br /&gt; LineTo&lt;br /&gt;[6] IMM32.dll        &lt;br /&gt; ImmGetContext&lt;br /&gt;[7] SHELL32.dll      &lt;br /&gt; ShellExecuteA&lt;br /&gt;[8] USER32.dll       &lt;br /&gt; GetDC&lt;br /&gt;[9] WINMM.dll        &lt;br /&gt; PlaySoundA&lt;br /&gt;[10] WINSPOOL.DRV     &lt;br /&gt; WritePrinter&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The final function calls  a local command line anti-virus scanner. &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="python"&gt;&lt;br /&gt;## Print Sophos&lt;br /&gt;def sophos(filetmp):&lt;br /&gt;        print "Sophos Scan in progress.."&lt;br /&gt;        output = "None"&lt;br /&gt;        path = os.path.abspath(filetmp)&lt;br /&gt;        pwd = os.getcwd()&lt;br /&gt;        output = subprocess.call([os.path.join(pwd, 'cmd_scan', 'Sophos', 'SAV32CLI.EXE'), path])&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Output:&lt;code&gt;&lt;br /&gt;Sophos Scan in progress..&lt;br /&gt;Sophos Anti-Virus&lt;br /&gt;Version 4.52.0 [Win32/Intel]&lt;br /&gt;Virus data version 4.52E, April 2010&lt;br /&gt;Includes detection for 1542982 viruses, trojans and worms&lt;br /&gt;Copyright (c) 1989-2010 Sophos Plc. All rights reserved.&lt;br /&gt;&lt;br /&gt;System time 21:36:32, System date 03 May 2010&lt;br /&gt;&lt;br /&gt;Quick Scanning&lt;br /&gt;&lt;br /&gt;1 file swept in 3 seconds.&lt;br /&gt;No viruses were discovered.&lt;br /&gt;Ending Sophos Anti-Virus.&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This function will need to be copied and modified for each scanner. There are a few free anti-virus scanners. The function above used Sophos's free command line scanner. The scanner can be downloaded &lt;a href="http://www.sophos.com/support/knowledgebase/article/13251.html"&gt;here&lt;/a&gt;.   Other free scanner are ClamAV, Panda and a couple of others. ClamAV can be used as a portable application and does not need to be fully installed. The portable ClamAV can be downloaded &lt;a href="http://portableapps.com/apps/utilities/clamwin_portable"&gt;here&lt;/a&gt;. Most purchased anti-virus applications do have command line interface.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="python"&gt;&lt;br /&gt;if len(sys.argv) &lt; 2:&lt;br /&gt;        print "Pyton Script &lt;file&gt;"&lt;br /&gt;        sys.exit(3)&lt;br /&gt;exename = sys.argv[1]&lt;br /&gt;pe = pefile.PE(exename)&lt;br /&gt;print "\nPortable Executable Information"&lt;br /&gt;attributes()&lt;br /&gt;sections_analysis()&lt;br /&gt;PEID()&lt;br /&gt;IAT()&lt;br /&gt;sophos(exename)&lt;br /&gt;&lt;br /&gt;## &lt;/file&gt;  &lt;- Format bug with SyntaxHighlighter (remove line)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This script will need to have a Portable executable file passed to it. Once a file is passed Pefile will load the executable and then call all the functions. &lt;br /&gt;&lt;br /&gt;In closing, this script is a quick example of using Python to analyze an unknown executable file. The current version is 0.01. Overtime I'll keep updating the script. As previously stated if there are any question or ideas please leave a comment.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4093139800580227296-800604381507711682?l=hooked-on-mnemonics.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hooked-on-mnemonics.blogspot.com/feeds/800604381507711682/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2010/04/creating-your-own-virustotal-well-kind.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/800604381507711682'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/800604381507711682'/><link rel='alternate' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2010/04/creating-your-own-virustotal-well-kind.html' title='Creating Your Own Virustotal..Well Kind Of..Ok, Not Really'/><author><name>Alexander Hanel</name><uri>http://www.blogger.com/profile/14943273470531588187</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_fER_9l4iokM/SbA1HWjUNUI/AAAAAAAAAAM/TFFVhDX_YBA/S220/ihatealex1.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4093139800580227296.post-7612490944024735731</id><published>2010-04-10T15:04:00.000-07:00</published><updated>2012-02-13T04:41:51.115-08:00</updated><title type='text'>01010101</title><content type='html'>Ones and zeros is a very popular term for computers. Unfortunately most individuals do not know how those numbers equate to actual programming instructions or data. Below is a quick walk through of how those ones and zeros are interpreted. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;b&gt;Binary&lt;/b&gt;&lt;br /&gt;.code      &lt;br /&gt;01010101 10001001 11100101 10000011 11101100 00001000 10000011 11100100 11110000 10111000 00000000 00000000 00000000 00000000 10000011 11000000 00001111 10000011 11000000 00001111 11000001 11101000 00000100 11000001 11100000 00000100 10001001 01000101 11111100 10001001 01000101 11111100 11101000 00011011 00000101 00000000 00000000 11101000 11010110 00000001 00000000 00000000 11000111 00000100 00100100 00000000 00110000 01000000 00000000 11101000 01110010 00000101 00000000 00000000 11001001 11000011 &lt;br /&gt;.data &lt;br /&gt;01001001 00100000 01001100 01101111 01110110 01100101 00100000 01011001 01101111 01110101&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Binary is a base-2 numeral counting system. The base-2 means that the binary number can be represented by two mutually exclusive states. These states can be for example either On or Off, as in the case of a light bulb. Each one and zero above represents one of those states. A simple way to think about the data above is to visualize 528 light bulbs in a row either off or on depending on their state. &lt;br /&gt;&lt;br /&gt;Binary numbers can be used to represent integers (4,234,-6) rather than just being for a single one or zero state. For example, the first eight binary digits above 01010101 is equal to 85 in decimal (base-10 or using your fingers). Here is the classical arthritic for converting binary to decimal:  [(0) × 2^7] + [(1) × 2^6] +[(0) × 2^5] + [(1) × 2^4] + [(0) × 2^3] + [(1) × 2^2] + [(0) × 2^1] + [(1) × 2^0] = 85. Basically what this means is that we can use ones and zeros to represent an infinite set of integers. &lt;br /&gt;&lt;br /&gt;In the early years of computing, binary numbers were used to program in machine code. This is no longer the case. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Hexadecimal &lt;/b&gt;&lt;code&gt;&lt;br /&gt;.code&lt;br /&gt;85 89 E5 83 EC 08 83 E4 F0 B8 00 00 00 00 83 C0 0F 83 C0 0F C1 E8 04 C1 E0 04 89 45 FC 89 45 FC E8 1B 05 00 00 E8 D6 01 00 00 C7 04 24 00 30 40 &lt;br /&gt;00 E8 72 05 00 00 C9 C3&lt;br /&gt;.data&lt;br /&gt;49 20 4C 6F 76 65 20 59 6F 75&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Programming in binary (also called machine code) is an extremely tedious process. In order to simplify this process mnemonic codes were used rather than binary digits. Mneomic codes are helpful because they are closer to human language. Mneomic codes are represented in the numerical format of hexadecimal. &lt;br /&gt;&lt;br /&gt;Hexadecimal is a base-16 numeral format. Rather than having two states as in the case of binary hexadecimal can have 16 states. The different states are represented by the digits 1,2,3,4...9,A,B,C,D,E,F. The digit 'E' equals 15 in decimal. Hexadecimal is easy for computers because 2 (on or off)  to the power of 4 equals 16. Hexadecimal is visually easier to read than binary. 01010101 binary equals 55 hexadecimal.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Assembly Language &lt;/b&gt;&lt;code&gt;&lt;br /&gt;.code&lt;br /&gt;PUSH EBP&lt;br /&gt;MOV EBP,ESP&lt;br /&gt;SUB ESP,8&lt;br /&gt;AND ESP,FFFFFFF0&lt;br /&gt;MOV EAX,0&lt;br /&gt;ADD EAX,0F&lt;br /&gt;ADD EAX,0F&lt;br /&gt;SHR EAX,4&lt;br /&gt;SHL EAX,4&lt;br /&gt;MOV [LOCAL.1],EAX&lt;br /&gt;MOV EAX,[LOCAL.1]&lt;br /&gt;CALL love.00401820&lt;br /&gt;CALL love.004014E0&lt;br /&gt;MOV DWORD PTR SS:[ESP],love.00403000     ; |ASCII "I Love You."&lt;br /&gt;CALL &lt;jmp.&amp;msvcrt.printf&gt;                ; \printf&lt;br /&gt;LEAVE&lt;br /&gt;RETN&lt;br /&gt;.data&lt;br /&gt;I Love You.&lt;/jmp.&amp;msvcrt.printf&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Converting hexadecimal to mnemonics code is done by a disassembler. When a disassembler converts hexadecimal to mnemonics code the output is assembly language. The hexadecimal has to be valid mnemonics code in order to be converted to assembly language. The hexadecimal to mnemonic code conversion is defined by what processor the computer using. In the case about the assembly language was been defined by Intel (x86).&lt;br /&gt;&lt;br /&gt;The ".code" indicates that the hexadecimal is executable and not data. Example of executable code would be "MOV EBP,ESP". This assembly language means move ESP into EBP. The CPU would interrupt this assembly language as a doable action. The ".data" indicates that the hexadecimal is data. An example of data would be the phrase "I Love You.". &lt;br /&gt;&lt;br /&gt;&lt;b&gt;C Programming Language&lt;/b&gt;&lt;code&gt;&lt;br /&gt;#include&lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt;main()&lt;br /&gt;{&lt;br /&gt;    printf("I Love You"); &lt;br /&gt;}&lt;/stdio.h&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Assembly Language is considered a low level programming language. This is due to it's close interaction with the CPU. Interaction at this level is extremely complicated. To ease the complexity higher level programming languages were created.  An example of this can be seen in the code above written in the C programming language. Three lines of code in C is equal to 17 lines of assembly.  &lt;br /&gt;&lt;br /&gt;In order to get from C to the binary digits the code would need to be compiled. A compiler converts source code to a binary format. The final output that the user would see if they clicked on the compiled C code.&lt;br /&gt;&lt;br /&gt;I Love You. &lt;blink&gt;_&lt;/blink&gt;&lt;br /&gt;&lt;br /&gt;To recap the computer at it's lowest level stores everything as ones and zeros, the source code is compiled to create the binary, those ones and zeros can be read as hexadecimal, the hexadecimal can then be converted to either assembly language or data.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4093139800580227296-7612490944024735731?l=hooked-on-mnemonics.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hooked-on-mnemonics.blogspot.com/feeds/7612490944024735731/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2010/04/01010101.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/7612490944024735731'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/7612490944024735731'/><link rel='alternate' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2010/04/01010101.html' title='01010101'/><author><name>Alexander Hanel</name><uri>http://www.blogger.com/profile/14943273470531588187</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_fER_9l4iokM/SbA1HWjUNUI/AAAAAAAAAAM/TFFVhDX_YBA/S220/ihatealex1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4093139800580227296.post-6294273952537268814</id><published>2010-04-10T14:59:00.000-07:00</published><updated>2010-04-10T15:00:35.310-07:00</updated><title type='text'></title><content type='html'>&lt;code&gt;&lt;br /&gt; int main() &lt;br /&gt; {&lt;br /&gt;        printf("hello, world");&lt;br /&gt;        return 0;&lt;br /&gt; }&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4093139800580227296-6294273952537268814?l=hooked-on-mnemonics.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hooked-on-mnemonics.blogspot.com/feeds/6294273952537268814/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2010/04/int-main-printfhello-world-return-0.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/6294273952537268814'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4093139800580227296/posts/default/6294273952537268814'/><link rel='alternate' type='text/html' href='http://hooked-on-mnemonics.blogspot.com/2010/04/int-main-printfhello-world-return-0.html' title=''/><author><name>Alexander Hanel</name><uri>http://www.blogger.com/profile/14943273470531588187</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_fER_9l4iokM/SbA1HWjUNUI/AAAAAAAAAAM/TFFVhDX_YBA/S220/ihatealex1.jpg'/></author><thr:total>0</thr:total></entry></feed>
