Код:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined _WIN32
#include <winsock.h>
#define sleep(x) Sleep(x)
#define close(x) closesocket(x)
#pragma comment(lib, "ws2_32.lib")
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#endif
static char *fetch_url(const char *, const char *, int *);
int main(int argc, char *argv[])
{
FILE *in, *out_bad, *out_good;
char *body;
char hash[34];
char url[64];
int g = 0, b = 0;
if (argc < 2 || argc > 3) {
printf("%s <input>\n", argv[0]);
return 1;
}
in = fopen(argv[1], "rb");
if (!in) {
perror("fopen");
return 1;
}
out_bad = fopen("bad_hash", "wb");
out_good = fopen("good_hash", "wb");
while (!feof(in)) {
fscanf(in, "%s\n", hash);
sprintf(url, "/api/api.php?md5=%s", hash);
body = fetch_url("hashkiller.com", url, 0);
if (strstr(body, "false")) {
printf("[-] Hash not found %s\n", hash);
fprintf(out_bad, "%s\n", hash);
b++;
} else {
printf("[+] Hash found %s\n", hash);
fprintf(out_good, "%s\n", hash);
g++;
}
}
printf("[i] Hash checking complete\n"
"\t%d good hash\n"
"\t%d bad hash\n", g, b);
return 0;
}
int hard_fetch_ip = 0;
#define MAX_LEN 1024
static char *fetch_url(const char *host, const char *url, int *res_len)
{
struct hostent *phe;
struct sockaddr_in sin;
int s, len, len_respose;
char *body_send;
char *body_recv;
char *body_response;
#if defined _WIN32
WSADATA wsaData;
WSAStartup(0x101, &wsaData);
#endif
s = socket(AF_INET, SOCK_STREAM, 0);
if (s == -1) {
perror("socket");
return NULL;
}
if (!hard_fetch_ip) {
phe = gethostbyname(host);
if (phe == NULL) {
perror("gethostbyname");
return NULL;
}
hard_fetch_ip = ((struct in_addr*)phe->h_addr_list[0])->s_addr;
}
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = hard_fetch_ip;
sin.sin_port = htons(80);
if (connect(s, (struct sockaddr*)&sin, sizeof(struct sockaddr_in))) {
perror("connect");
return NULL;
}
body_send = (char *)malloc(MAX_LEN);
body_recv = (char *)malloc(MAX_LEN);
body_response = (char *)malloc(MAX_LEN);
memset(body_response, 0, MAX_LEN);
len_respose = 0;
sprintf(body_send,
"GET /%s HTTP/1.1\r\n"
"Host: %s\r\n"
"Connection: close\r\n"
"Accept: */*\r\n\r\n", url, host);
send(s, body_send, strlen(body_send), 0);
int new_len = MAX_LEN;
char *tmp;
do {
len = recv(s, body_recv, MAX_LEN, 0);
len_respose += len;
if (len_respose > new_len) {
new_len = new_len * 2;
body_response = (char *) realloc(body_response, new_len );
}
memcpy(body_response + (len_respose - len), body_recv, len);
} while (len);
// remove headers
tmp = strstr(body_response, "\r\n\r\n");
len_respose -= (tmp - body_response + 4);
memcpy(body_response, tmp + 4, len_respose);
free(body_recv);
free(body_send);
close(s);
if (res_len) {
*res_len = len_respose;
}
return body_response;
}
GNU/Linux
$ gcc check-hash.c -Wall -o check-hash
$ ./check-hash input.txt
[+] Hash found 098f6bcd4621d373cade4e832627b4f6
[+] Hash found 098f6bcd4621d373cade4e832627b4f6
[-] Hash not found 00000000000000000000000000000000
[-] Hash not found 23423423842378947289374892734897
[i] Hash checking complete
2 good hash
2 bad hash
Windows
$ i586-mingw32msvc-gcc check-hash.c -Wall -lws2_32 -o check-hash.exe
$ wine ./check-hash.exe input.txt
[+] Hash found 098f6bcd4621d373cade4e832627b4f6
[+] Hash found 098f6bcd4621d373cade4e832627b4f6
[-] Hash not found 00000000000000000000000000000000
[-] Hash not found 23423423842378947289374892734897
[i] Hash checking complete
2 good hash
2 bad hash