-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathusrnamegrabber.cxx
More file actions
238 lines (197 loc) · 7.52 KB
/
usrnamegrabber.cxx
File metadata and controls
238 lines (197 loc) · 7.52 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#include <curl/curl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <pthread.h>
#include "libs/parson.h" // Using Parson for JSON handling
#include "libs/parson.c"
#define BASE_URL "https://api.scratch.mit.edu/accounts/checkusername/"
volatile int running = 1;
int valid_count = 0;
int total_checked = 0;
int delay_old = 450000; // Default delay (0.45s)
int delay = 500;
int username_length = 4; // Default username length
FILE *file = NULL;
// Struct for API response buffer
struct Response {
char *data;
size_t size;
};
// Callback function for cURL to write API response
size_t writefunc(void *ptr, size_t size, size_t nmemb, struct Response *res) {
size_t total_size = size * nmemb;
char *new_data = (char *)realloc(res->data, res->size + total_size + 1);
if (new_data == NULL) {
fprintf(stderr, "Memory allocation failed\n");
return 0;
}
res->data = new_data;
memcpy(res->data + res->size, ptr, total_size);
res->size += total_size;
res->data[res->size] = '\0'; // Null-terminate
return total_size;
}
// Function to generate a random string
void generate_random_string(char *str, size_t length) {
static const char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for (size_t i = 0; i < length; i++) {
str[i] = charset[rand() % (sizeof(charset) - 1)];
}
str[length] = '\0'; // Null-terminate
}
// JSON Configuration Handling
void load_or_create_config() {
JSON_Value *root_value = json_parse_file("config.json");
if (root_value == NULL) {
printf("Config file not found, creating one with default values...\n");
root_value = json_value_init_object();
JSON_Object *root_object = json_value_get_object(root_value);
json_object_set_number(root_object, "delay", 450); // Save in seconds
json_object_set_number(root_object, "username_length", 4);
json_serialize_to_file(root_value, "config.json");
printf("Default config file created.\n");
} else {
JSON_Object *root_object = json_value_get_object(root_value);
// Check if keys exist before using them
if (json_object_has_value(root_object, "delay")) {
delay = (int)(json_object_get_number(root_object, "delay")); // Convert to ms
} else {
printf("Warning: 'delay' not found in config, using default.\n");
}
if (json_object_has_value(root_object, "username_length")) {
username_length = (int)json_object_get_number(root_object, "username_length");
} else {
printf("Warning: 'username_length' not found in config, using default.\n");
}
printf("Loaded config: Delay = %dms, Username Length = %d\n", delay, username_length);
}
json_value_free(root_value);
}
// Function to generate a timestamped filename
void get_timestamped_filename(char *filename, size_t size) {
time_t now = time(NULL);
struct tm *t = localtime(&now);
snprintf(filename, size, "foundusernames_%04d-%02d-%02d_%02d-%02d-%02d.txt",
t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
t->tm_hour, t->tm_min, t->tm_sec);
}
// Function to check if the username exists
void check_username(const char *username) {
char url[256];
snprintf(url, sizeof(url), "%s%s", BASE_URL, username);
CURL *curl = curl_easy_init();
if (!curl) {
fprintf(stderr, "Failed to initialize cURL\n");
return;
}
struct Response res = {NULL, 0};
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &res);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res.data) {
total_checked++;
if (strstr(res.data, "\"msg\":\"username exists\"")) {
printf("❌ TAKEN: %s\n", username);
if (file) fprintf(file, "❌ %s\n", username);
} else if (strstr(res.data, "\"msg\":\"valid username\"")) {
valid_count++;
printf("✅ VALID: %s (Total: %d)\n", username, valid_count);
if (file) fprintf(file, "✅ %s\n", username);
} else {
printf("❔ UNKNOWN: %s\n", username);
if (file) fprintf(file, "❔ %s\n", username);
}
free(res.data);
}
}
// Function to handle API requests
void *request_loop(void *arg) {
while (running) {
if (!running) break; // Double-check before generating a username
char random_string[username_length + 1];
generate_random_string(random_string, username_length);
check_username(random_string);
if (!running) break; // Another check before sleeping
usleep(delay * 1000);
}
printf("Stopped.\n");
return NULL;
}
// Function to listen for Enter key to stop
void *input_listener(void *arg) {
getchar();
printf("Stopping...\n");
running = 0;
return NULL;
}
int main() {
printf("I, yoann256, am not responsible if you get banned from Scratch/Scratch API or got limited use to Scratch/Scratch API.\nThis project is purely educational and is not affiliated in any way with Scratch or the Scratch Team.\n");
srand(time(NULL)); // Seed the random number generator
// **Mode Selection**
int mode;
printf("Select Mode:\n");
printf("1. Normal Mode (0.5s delay)\n");
printf("2. Fast Mode (0.3s delay)\n");
printf("3. Ultra Mode (0.2s delay) [WARNING: Might get rate-limited!]\n");
printf("4. Custom Mode\n");
printf("5. Load from JSON\n");
printf("Enter your choice: ");
scanf("%d", &mode);
// **Clear input buffer**
while (getchar() != '\n');
switch (mode) {
case 1: delay = 500; break;
case 2: delay = 300; break;
case 3:
printf("WARNING: Ultra Mode may cause rate-limiting!\n");
delay = 200;
break;
case 4:
printf("Enter custom delay (in ms): ");
scanf("%d", &delay);
while (getchar() != '\n'); // **Clear buffer again**
break;
case 5:
load_or_create_config();
break;
default:
printf("Invalid choice! Defaulting to Normal Mode.\n");
delay = 500;
}
// **File Handling**
char filename[64];
get_timestamped_filename(filename, sizeof(filename));
file = fopen(filename, "w");
if (!file) {
fprintf(stderr, "Error: Could not open file for writing.\n");
return 1;
}
printf("Saving results to: %s\n", filename);
printf("Press Enter to stop...\n");
// **Start Threads**
pthread_t request_thread, input_thread;
pthread_create(&request_thread, NULL, request_loop, NULL);
pthread_create(&input_thread, NULL, input_listener, NULL);
// **Wait for Threads to Finish**
pthread_join(request_thread, NULL);
pthread_join(input_thread, NULL);
// **Final Statistics**
double accuracy = (total_checked > 0) ? ((double)valid_count / total_checked) * 100 : 0.0;
printf("\nResults saved to %s\n", filename);
printf("Total Usernames Checked: %d\n", total_checked);
printf("Valid Usernames Found: %d\n", valid_count);
printf("Accuracy: %.2f%%\n", accuracy);
// **Write Stats to File**
if (file) {
fprintf(file, "\nTotal Usernames Checked: %d\n", total_checked);
fprintf(file, "Valid Usernames Found: %d\n", valid_count);
fprintf(file, "Accuracy: %.2f%%\n", accuracy);
fclose(file);
}
return 0;
}