| 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 |
#undef NDEBUG |
| 33 |
|
| 34 |
#include <sys/time.h> |
| 35 |
#include <assert.h> |
| 36 |
#include <limits.h> |
| 37 |
|
| 38 |
#include "ophcrack.h" |
| 39 |
#include "message.h" |
| 40 |
#include "lmtable.h" |
| 41 |
#include "ntproba.h" |
| 42 |
#include "ntseven.h" |
| 43 |
#include "nteightxl.h" |
| 44 |
|
| 45 |
struct timeval tm_main_total; |
| 46 |
struct timeval tm_main_start; |
| 47 |
|
| 48 |
void table_set_size_4test(table_t *tbl) { |
| 49 |
const uint64_t *sizes = NULL; |
| 50 |
|
| 51 |
switch (tbl->kind) { |
| 52 |
case lmalphanum5k: |
| 53 |
sizes = lmalphanum5k_sizes; |
| 54 |
break; |
| 55 |
|
| 56 |
case ntseven: |
| 57 |
sizes = ntseven_sizes; |
| 58 |
break; |
| 59 |
|
| 60 |
case nteightxl: |
| 61 |
sizes = nteightxl_sizes; |
| 62 |
break; |
| 63 |
|
| 64 |
case ntprobafree: |
| 65 |
sizes = ntprobafree_sizes; |
| 66 |
break; |
| 67 |
|
| 68 |
case ntproba10g: |
| 69 |
sizes = ntproba10g_sizes; |
| 70 |
break; |
| 71 |
|
| 72 |
case ntproba60g: |
| 73 |
sizes = ntproba60g_sizes; |
| 74 |
break; |
| 75 |
|
| 76 |
default: |
| 77 |
assert(0); |
| 78 |
} |
| 79 |
|
| 80 |
tbl->idxsize = sizes[1]; |
| 81 |
tbl->endsize = sizes[2*tbl->idx+2]; |
| 82 |
tbl->srtsize = sizes[2*tbl->idx+3]; |
| 83 |
} |
| 84 |
|
| 85 |
uint64_t find_freeram_4preload(void) { |
| 86 |
return ULLONG_MAX; |
| 87 |
} |
| 88 |
|
| 89 |
ophcrack_t *create_crack_4test(table_t **tables, int ntables) { |
| 90 |
arg_t *arg = arg_alloc(); |
| 91 |
ophcrack_t *crack = ophcrack_alloc(1, arg); |
| 92 |
|
| 93 |
crack->find_freeram = find_freeram_4preload; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
for (int i=0; i<ntables; ++i) { |
| 98 |
table_t *tbl = tables[i]; |
| 99 |
|
| 100 |
table_set_size_4test(tbl); |
| 101 |
ophcrack_setup_table(tbl); |
| 102 |
ophcrack_add_table(crack, tbl); |
| 103 |
|
| 104 |
tbl->enabled = 1; |
| 105 |
list_add_tail(crack->enabled, tbl); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
char pwdump[] = |
| 111 |
"3e645334fd788c5f949a30c86b9f0fb1:535f34e7eb41001a5d5eea2714d20315"; |
| 112 |
|
| 113 |
list_t *hashes = list_alloc(); |
| 114 |
hash_extract_lmnt(pwdump, hashes, 0); |
| 115 |
|
| 116 |
assert(hashes->size == 3); |
| 117 |
|
| 118 |
for (list_nd_t *nd = hashes->head; nd != NULL; nd = nd->next) { |
| 119 |
hash_t *hash = nd->data; |
| 120 |
|
| 121 |
ophcrack_add_hash(crack, hash); |
| 122 |
|
| 123 |
for (list_nd_t *nd = crack->enabled->head; nd != NULL; nd = nd->next) { |
| 124 |
table_t *tbl = nd->data; |
| 125 |
ophcrack_associate(crack, hash, tbl); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
list_free(hashes); |
| 130 |
|
| 131 |
return crack; |
| 132 |
} |
| 133 |
|
| 134 |
void preload_4test(ophcrack_t *crack, table_t **tables, int ntables) { |
| 135 |
ophtask_t *task = ophtask_alloc(preload_all); |
| 136 |
ophload_t *load = task->data; |
| 137 |
|
| 138 |
for (int i=0; i<ntables; ++i) |
| 139 |
list_add_tail(load->tables, tables[i]); |
| 140 |
|
| 141 |
ophcrack_preload_all(crack, task, 0); |
| 142 |
ophtask_free(task); |
| 143 |
} |
| 144 |
|
| 145 |
void free_crack_4test(ophcrack_t *crack) { |
| 146 |
for (list_nd_t *nd = crack->hashes->head; nd != NULL; nd = nd->next) { |
| 147 |
hash_t *hash = nd->data; |
| 148 |
hash_free(hash); |
| 149 |
} |
| 150 |
|
| 151 |
for (list_nd_t *nd = crack->tables->head; nd != NULL; nd = nd->next) { |
| 152 |
table_t *tbl = nd->data; |
| 153 |
table_free(tbl); |
| 154 |
} |
| 155 |
|
| 156 |
arg_free(crack->arg); |
| 157 |
ophcrack_free(crack); |
| 158 |
} |
| 159 |
|
| 160 |
void check_unload_task(scheduler_t *sched, table_t *tbl) { |
| 161 |
assert(sched->ntasks > 0); |
| 162 |
|
| 163 |
ophtask_t *task = scheduler_get(sched, 0); |
| 164 |
assert(task->kind == unload); |
| 165 |
|
| 166 |
ophload_t *load = task->data; |
| 167 |
assert(load->tbl == tbl); |
| 168 |
|
| 169 |
ophtask_free(task); |
| 170 |
scheduler_done(sched, 0); |
| 171 |
} |
| 172 |
|
| 173 |
void check_preload_task0(scheduler_t *sched, table_t *tbl, table_preload_t preload) { |
| 174 |
ophtask_t *task = scheduler_get(sched, 0); |
| 175 |
assert(task->kind == preload_one); |
| 176 |
|
| 177 |
ophload_t *load = task->data; |
| 178 |
assert(load->tbl == tbl); |
| 179 |
assert(load->preload == preload); |
| 180 |
|
| 181 |
ophtask_free(task); |
| 182 |
scheduler_done(sched, 0); |
| 183 |
} |
| 184 |
|
| 185 |
void check_preload_task(scheduler_t *sched, table_t *tbl, table_preload_t preload) { |
| 186 |
static const table_preload_t preloads[] = { preload_init, |
| 187 |
preload_idx, |
| 188 |
preload_end, |
| 189 |
preload_srt }; |
| 190 |
|
| 191 |
static const int npreloads = sizeof(preloads) / sizeof(table_preload_t); |
| 192 |
|
| 193 |
if (preload == preload_none) |
| 194 |
check_preload_task0(sched, tbl, preload_none); |
| 195 |
else |
| 196 |
for (int i=0; i<npreloads; ++i) |
| 197 |
if (preload & preloads[i]) |
| 198 |
check_preload_task0(sched, tbl, preloads[i]); |
| 199 |
} |
| 200 |
|
| 201 |
void check_preload_message(table_t *tbl, table_preload_t preload, int done, uint64_t size) { |
| 202 |
message_t *msg = message_tryget(); |
| 203 |
|
| 204 |
assert(msg != NULL); |
| 205 |
assert(msg->kind == msg_preload); |
| 206 |
|
| 207 |
msg_load_t *msg_load = msg->data; |
| 208 |
|
| 209 |
assert(msg_load->tbl == tbl); |
| 210 |
assert(msg_load->preload == preload); |
| 211 |
assert(msg_load->done == done); |
| 212 |
assert(msg_load->size == size); |
| 213 |
|
| 214 |
message_free(msg); |
| 215 |
} |
| 216 |
|
| 217 |
void test_ophcrack_preload_all0() { |
| 218 |
|
| 219 |
|
| 220 |
table_t *tables[] = { |
| 221 |
|
| 222 |
table_alloc(0x0fa2031c, ".", 0), |
| 223 |
table_alloc(0x0fa2031c, ".", 1), |
| 224 |
table_alloc(0x0fa2031c, ".", 2), |
| 225 |
table_alloc(0x0fa2031c, ".", 3), |
| 226 |
}; |
| 227 |
|
| 228 |
int ntables = sizeof(tables) / sizeof(table_t*); |
| 229 |
ophcrack_t *crack = create_crack_4test(tables, ntables); |
| 230 |
|
| 231 |
assert(crack->enabled->size == ntables); |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
uint64_t preload_size = 0; |
| 236 |
|
| 237 |
for (int i=0; i<ntables; ++i) |
| 238 |
preload_size += table_preload_size(tables[i], preload_full); |
| 239 |
|
| 240 |
crack->freeram = preload_size; |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
preload_4test(crack, tables, ntables); |
| 245 |
|
| 246 |
assert(crack->active->size == 4); |
| 247 |
assert(crack->remaining->size == 0); |
| 248 |
assert(crack->remaining->size == crack->enabled->size - crack->active->size); |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
assert(crack->sched->ntasks == 18); |
| 253 |
|
| 254 |
check_unload_task(crack->sched, NULL); |
| 255 |
|
| 256 |
for (int i=0; i<ntables; ++i) |
| 257 |
check_preload_task(crack->sched, tables[i], preload_full); |
| 258 |
|
| 259 |
check_preload_task(crack->sched, NULL, preload_none); |
| 260 |
|
| 261 |
assert(crack->sched->ntasks == 0); |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
check_preload_message(NULL, preload_none, 0, preload_size); |
| 266 |
|
| 267 |
message_t *msg = message_tryget(); |
| 268 |
assert(msg == NULL); |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
free_crack_4test(crack); |
| 273 |
} |
| 274 |
|
| 275 |
void test_ophcrack_preload_all1() { |
| 276 |
table_t *tables[] = { |
| 277 |
|
| 278 |
table_alloc(0x47000fdf, ".", 0), |
| 279 |
table_alloc(0x47000fdf, ".", 1), |
| 280 |
table_alloc(0x47000fdf, ".", 2), |
| 281 |
table_alloc(0x47000fdf, ".", 3) |
| 282 |
}; |
| 283 |
|
| 284 |
int ntables = sizeof(tables) / sizeof(table_t*); |
| 285 |
ophcrack_t *crack = create_crack_4test(tables, ntables); |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
crack->arg->preload = 2; |
| 290 |
|
| 291 |
uint64_t preload_size = |
| 292 |
table_preload_size(tables[0], preload_full - preload_srt) + |
| 293 |
table_preload_size(tables[1], preload_full - preload_srt) + |
| 294 |
table_preload_size(tables[2], preload_full - preload_srt) + |
| 295 |
table_preload_size(tables[3], preload_full - preload_srt); |
| 296 |
|
| 297 |
crack->freeram = |
| 298 |
preload_size - |
| 299 |
table_preload_size(tables[1], preload_init) - |
| 300 |
table_preload_size(tables[2], preload_init) - |
| 301 |
table_preload_size(tables[3], preload_init); |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
preload_4test(crack, tables, ntables); |
| 306 |
|
| 307 |
assert(crack->active->size == ntables); |
| 308 |
assert(crack->remaining->size == 0); |
| 309 |
assert(crack->remaining->size == crack->enabled->size - crack->active->size); |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
assert(crack->sched->ntasks == 1 + 4*3 + 1); |
| 314 |
check_unload_task(crack->sched, NULL); |
| 315 |
|
| 316 |
check_preload_task(crack->sched, tables[0], preload_full - preload_srt); |
| 317 |
check_preload_task(crack->sched, tables[1], preload_full - preload_srt); |
| 318 |
check_preload_task(crack->sched, tables[2], preload_full - preload_srt); |
| 319 |
check_preload_task(crack->sched, tables[3], preload_full - preload_srt); |
| 320 |
|
| 321 |
check_preload_task(crack->sched, NULL, preload_none); |
| 322 |
assert(crack->sched->ntasks == 0); |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
check_preload_message(NULL, preload_none, 0, preload_size); |
| 327 |
|
| 328 |
message_t *msg = message_tryget(); |
| 329 |
assert(msg == NULL); |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
free_crack_4test(crack); |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
void test_ophcrack_preload_all3() { |
| 339 |
table_t *tables[] = { |
| 340 |
|
| 341 |
table_alloc(0x0fa2031c, ".", 0), |
| 342 |
table_alloc(0x0fa2031c, ".", 1), |
| 343 |
table_alloc(0x0fa2031c, ".", 2), |
| 344 |
table_alloc(0x0fa2031c, ".", 3) |
| 345 |
}; |
| 346 |
|
| 347 |
int ntables = sizeof(tables) / sizeof(table_t*); |
| 348 |
ophcrack_t *crack = create_crack_4test(tables, ntables); |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
crack->freeram = 0; |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
preload_4test(crack, tables, ntables); |
| 357 |
|
| 358 |
assert(crack->active->size == ntables); |
| 359 |
assert(crack->remaining->size == 0); |
| 360 |
assert(crack->remaining->size == crack->enabled->size - crack->active->size); |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
assert(crack->sched->ntasks == 1 + 4 + 1); |
| 365 |
|
| 366 |
check_unload_task(crack->sched, NULL); |
| 367 |
check_preload_task(crack->sched, tables[0], preload_init); |
| 368 |
check_preload_task(crack->sched, tables[1], preload_init); |
| 369 |
check_preload_task(crack->sched, tables[2], preload_init); |
| 370 |
check_preload_task(crack->sched, tables[3], preload_init); |
| 371 |
check_preload_task(crack->sched, NULL, preload_none); |
| 372 |
|
| 373 |
assert(crack->sched->ntasks == 0); |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
check_preload_message(NULL, preload_none, 0, 0); |
| 378 |
|
| 379 |
message_t *msg = message_tryget(); |
| 380 |
assert(msg == NULL); |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
free_crack_4test(crack); |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
void test_ophcrack_preload_all4() { |
| 390 |
table_t *tables[] = { |
| 391 |
|
| 392 |
table_alloc(0x0fa2031c, ".", 0), |
| 393 |
table_alloc(0x0fa2031c, ".", 1), |
| 394 |
table_alloc(0x0fa2031c, ".", 2), |
| 395 |
table_alloc(0x0fa2031c, ".", 3) |
| 396 |
}; |
| 397 |
|
| 398 |
int ntables = sizeof(tables) / sizeof(table_t*); |
| 399 |
ophcrack_t *crack = create_crack_4test(tables, ntables); |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
uint64_t preload_size = |
| 404 |
table_preload_size(tables[0], preload_full) + |
| 405 |
table_preload_size(tables[1], preload_full) + |
| 406 |
table_preload_size(tables[2], preload_full) + |
| 407 |
table_preload_size(tables[3], preload_full); |
| 408 |
|
| 409 |
crack->freeram = preload_size; |
| 410 |
|
| 411 |
for (int s=0; s<2; ++s) { |
| 412 |
|
| 413 |
|
| 414 |
if (s == 0) { |
| 415 |
assert(crack->enabled->size == ntables); |
| 416 |
preload_4test(crack, tables, ntables); |
| 417 |
|
| 418 |
assert(crack->active->size == ntables); |
| 419 |
assert(crack->remaining->size == 0); |
| 420 |
} |
| 421 |
else { |
| 422 |
for (int i=0; i<ntables; ++i) |
| 423 |
tables[i]->enabled = 0; |
| 424 |
|
| 425 |
list_clear(crack->enabled); |
| 426 |
|
| 427 |
assert(crack->enabled->size == 0); |
| 428 |
preload_4test(crack, tables, 0); |
| 429 |
|
| 430 |
assert(crack->active->size == 0); |
| 431 |
assert(crack->remaining->size == 0); |
| 432 |
} |
| 433 |
|
| 434 |
assert(crack->remaining->size == crack->enabled->size - crack->active->size); |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
if (s == 0) { |
| 439 |
assert(crack->sched->ntasks == 1 + 4*4 + 1); |
| 440 |
|
| 441 |
while (crack->sched->ntasks > 0) { |
| 442 |
ophtask_t *task = scheduler_get(crack->sched, 0); |
| 443 |
ophtask_free(task); |
| 444 |
scheduler_done(crack->sched, 0); |
| 445 |
} |
| 446 |
} |
| 447 |
else { |
| 448 |
assert(crack->sched->ntasks == 1); |
| 449 |
check_preload_task(crack->sched, NULL, preload_none); |
| 450 |
} |
| 451 |
|
| 452 |
assert(crack->sched->ntasks == 0); |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
if (s == 0) |
| 457 |
check_preload_message(NULL, preload_none, 0, preload_size); |
| 458 |
else |
| 459 |
check_preload_message(NULL, preload_none, 0, 0); |
| 460 |
|
| 461 |
message_t *msg = message_tryget(); |
| 462 |
assert(msg == NULL); |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
free_crack_4test(crack); |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
void test_ophcrack_preload_all7() { |
| 473 |
table_t *tables[] = { |
| 474 |
|
| 475 |
table_alloc(0xbb00950e, ".", 0), |
| 476 |
table_alloc(0xbb00950e, ".", 1), |
| 477 |
table_alloc(0xbb00950e, ".", 2), |
| 478 |
}; |
| 479 |
|
| 480 |
int ntables = sizeof(tables) / sizeof(table_t*); |
| 481 |
ophcrack_t *crack = create_crack_4test(tables, ntables); |
| 482 |
|
| 483 |
crack->freeram = table_preload_size(tables[0], preload_init) / 2; |
| 484 |
|
| 485 |
preload_4test(crack, tables, ntables); |
| 486 |
|
| 487 |
assert(crack->active->size == 0); |
| 488 |
assert(crack->remaining->size == 0); |
| 489 |
|
| 490 |
assert(crack->sched->ntasks == 1); |
| 491 |
|
| 492 |
check_preload_task(crack->sched, NULL, preload_none); |
| 493 |
|
| 494 |
check_preload_message(NULL, preload_none, 0, 0); |
| 495 |
assert(message_tryget() == NULL); |
| 496 |
|
| 497 |
free_crack_4test(crack); |
| 498 |
} |
| 499 |
|
| 500 |
void test_ophcrack_preload_all_idx_only() { |
| 501 |
table_t *tables[] = { |
| 502 |
|
| 503 |
table_alloc(0x229e1899, ".", 0), |
| 504 |
table_alloc(0x229e1899, ".", 1), |
| 505 |
table_alloc(0x229e1899, ".", 2), |
| 506 |
table_alloc(0x229e1899, ".", 3) |
| 507 |
}; |
| 508 |
|
| 509 |
int ntables = sizeof(tables) / sizeof(table_t*); |
| 510 |
ophcrack_t *crack = create_crack_4test(tables, ntables); |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
uint64_t preload_size = |
| 515 |
table_preload_size(tables[0], preload_full - preload_end - preload_srt) + |
| 516 |
table_preload_size(tables[1], preload_full - preload_end - preload_srt) + |
| 517 |
table_preload_size(tables[2], preload_full - preload_end - preload_srt) + |
| 518 |
table_preload_size(tables[3], preload_full - preload_end - preload_srt); |
| 519 |
|
| 520 |
crack->freeram = preload_size; |
| 521 |
|
| 522 |
preload_4test(crack, tables, ntables); |
| 523 |
|
| 524 |
assert(crack->active->size == 4); |
| 525 |
|
| 526 |
free_crack_4test(crack); |
| 527 |
} |
| 528 |
|
| 529 |
int main(int argc, char **argv) { |
| 530 |
message_init(); |
| 531 |
|
| 532 |
gettimeofday(&tm_main_start, 0); |
| 533 |
tm_main_total.tv_sec = 0; |
| 534 |
|
| 535 |
test_ophcrack_preload_all0(); |
| 536 |
test_ophcrack_preload_all1(); |
| 537 |
test_ophcrack_preload_all3(); |
| 538 |
test_ophcrack_preload_all4(); |
| 539 |
test_ophcrack_preload_all7(); |
| 540 |
test_ophcrack_preload_all_idx_only(); |
| 541 |
|
| 542 |
return 0; |
| 543 |
} |