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

<channel>
	<title>DamianGrace.com &#187; patter_create.rb</title>
	<atom:link href="http://www.damiangrace.com/tag/patter_create-rb/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.damiangrace.com</link>
	<description>Behind the scenes</description>
	<lastBuildDate>Wed, 28 Dec 2011 21:42:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Metasploit pattern_create.rb 2 Code Creator</title>
		<link>http://www.damiangrace.com/coding/metasploit-pattern_create-rb-code-creator/120/</link>
		<comments>http://www.damiangrace.com/coding/metasploit-pattern_create-rb-code-creator/120/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 08:53:20 +0000</pubDate>
		<dc:creator>Damian</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Metasploit]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[creator]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[pattern2code]]></category>
		<category><![CDATA[pattern_offset.rb]]></category>
		<category><![CDATA[patter_create.rb]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.damiangrace.com/?p=120</guid>
		<description><![CDATA[UPDATE: Pattern2Code is now at V.03. This page has been updated with that version of code. Pattern_create.rb is a great little tool that can be found in the /tools directory of your Metasploit framework. It is used to create a pattern of characters to a specified length which you can then inject into applications as [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE: Pattern2Code is now at V.03. This page has been updated with that version of code.</strong></p>
<p>Pattern_create.rb is a great little tool that can be found in the /tools directory of your Metasploit framework. It is used to create a pattern of characters to a specified length which you can then inject into applications as a buffer overflow. Its sister script, pattern_offset.rb, is then  used to identify how many bytes from the start of the string a particular part of the pattern occurred.</p>
<p>pattern2code.py is a script I created to save me manually modifying the pattern_create.rb patterns to fit into my fuzzing code. Its simple to use and will output the pattern into either Python, Perl or C code.</p>
<p>Running the script is as simple as piping the output from pattern_create.rb into the pattern2code.py and specifying a name for the buffer, a length of each split, and the language output.</p>
<p>The instructions below can also be found in the script if required;</p>
<p>[+] Usage: ./pattern2code.py &lt;buffername&gt; &lt;length&gt; &lt;languagename&gt; &lt;input&gt;<br />
[+] &lt;buffername&gt; = Custom buffer name<br />
[+] &lt;length&gt; = Length of each split<br />
[+] &lt;languagename&gt; = Perl, Python or C<br />
[+] &lt;input&gt; piped input from pattern_create.rb</p>
<p>Output examples:</p>
<blockquote><p><strong># ./pattern_create.rb 180 | ./splitter.py overflowbuff 50 python</strong></p>
<p>overflowbuff = &#8220;Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab&#8221;<br />
overflowbuff += &#8220;6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2A&#8221;<br />
overflowbuff += &#8220;d3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9&#8243;<br />
overflowbuff += &#8220;Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9&#8243;</p></blockquote>
<p><span style="color: #999999;">^ Python code output with a 50 character split.</span></p>
<p><span style="color: #999999;"><br />
</span></p>
<blockquote><p><strong># ./pattern_create.rb 260 | ./splitter.py newbuffer 40 perl</strong></p>
<p>my $newbuffer =<br />
&#8220;Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2A&#8221; .<br />
&#8220;b3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac&#8221; .<br />
&#8220;6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9&#8243; .<br />
&#8220;Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2A&#8221; .<br />
&#8220;f3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag&#8221; .<br />
&#8220;6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9&#8243; .<br />
&#8220;Ai0Ai1Ai2Ai3Ai4Ai5Ai&#8221;;</p></blockquote>
<p><span style="color: #999999;">^ Perl code output with 40 a character split</span></p>
<p><span style="color: #999999;"><br />
</span></p>
<blockquote><p><strong># ./pattern_create.rb 260 | ./splitter.py newbuffer 55 c</strong></p>
<p>unsigned char newbuffer[] =<br />
&#8220;Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7A&#8221;<br />
&#8220;b8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad&#8221;<br />
&#8220;6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4&#8243;<br />
&#8220;Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2A&#8221;<br />
&#8220;h3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4Ai5Ai&#8221;;</p></blockquote>
<p><span style="color: #999999;">^ C code output with a 55 character split.</span></p>
<p>Here is the code for your enjoyment <img src='http://www.damiangrace.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">!=</span> <span style="color: #ff4500;">4</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;++++++++++++++++++++++++++++++++++++++++++++++++++++++++&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pattern2code.py V0.03 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;+ Created by Damian Grace - http://www.damiangrace.com +&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;+ &nbsp; &nbsp; &nbsp; Restructure based on code by Jamie Gadd&nbsp; &nbsp; &nbsp; &nbsp; +&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;++++++++++++++++++++++++++++++++++++++++++++++++++++++++<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[+] Usage: ./pattern2code.py &lt;buffername&gt; &lt;length&gt; &lt;languagename&gt; &lt;input&gt;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[+] &lt;buffername&gt; = Custom buffer name&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[+] &lt;length&gt; = Length of each split&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[+] &lt;languagename&gt; = Perl, Python or C&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[+] &lt;input&gt; piped input from pattern_create.rb<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[+] This program is for use with pattern_create.rb which comes&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[+] bundled with Metasploit in the tools directory.&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[+] To make it executable: chmod 755 ./pattern2code.py&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[+] While its in the tools directory run it like so:&quot;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[+] ./pattern_create.rb 2000 | ./pattern2code.py buffer python<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># read buffer name and split length</span><br />
buffername <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><br />
splitlength <span style="color: #66cc66;">=</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># read pattern and remove newline</span><br />
pattern <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdin</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>:-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># language options</span><br />
language <span style="color: #66cc66;">=</span> <span style="color: black;">&#123;</span><span style="color: #483d8b;">&quot;perl&quot;</span>:<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;my $&quot;</span>+buffername+<span style="color: #483d8b;">&quot; = <span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>+pattern<span style="color: black;">&#91;</span>:splitlength<span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> .<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;python&quot;</span>:<span style="color: black;">&#40;</span>buffername+<span style="color: #483d8b;">&quot; = <span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>+pattern<span style="color: black;">&#91;</span>:splitlength<span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>+buffername+<span style="color: #483d8b;">&quot; += <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #66cc66;">,</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;c&quot;</span>:<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;unsigned char &quot;</span>+buffername+<span style="color: #483d8b;">&quot;[] = <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>+pattern<span style="color: black;">&#91;</span>:splitlength<span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># parse args</span><br />
start<span style="color: #66cc66;">,</span>mid<span style="color: #66cc66;">,</span>end <span style="color: #66cc66;">=</span> language.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span><span style="color: #66cc66;">,</span><span style="color: #483d8b;">''</span><span style="color: #66cc66;">,</span><span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># main</span><br />
<span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>start<span style="color: black;">&#41;</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>splitlength<span style="color: #66cc66;">,</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>pattern<span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span>splitlength<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>mid+pattern<span style="color: black;">&#91;</span>x:x+splitlength<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
<span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>end<span style="color: black;">&#41;</span></div></td></tr></tbody></table></div>
<p>The code can also be downloaded <a title="pattern2code" href="http://www.damiangrace.com/tools/pattern2code/pattern2code.v.03.tar" target="_self">here</a></p>
<p>Enjoy!</p>
<p>P.S. I would love to hear feedback on how to improve my code so please leave a comment&#8230;</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.damiangrace.com%2Fcoding%2Fmetasploit-pattern_create-rb-code-creator%2F120%2F&amp;title=Metasploit%20pattern_create.rb%202%20Code%20Creator" id="wpa2a_2"><img src="http://www.damiangrace.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.damiangrace.com/coding/metasploit-pattern_create-rb-code-creator/120/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
