-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathadmin.php
3085 lines (2874 loc) · 149 KB
/
admin.php
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
include("common.php");
if (strpos($htphost,":")!==false) $htphost=substr($htphost,0,strpos($htphost,":"));
set_time_limit(0);
session_start();
function mysqli_query_wrapper($dblink, $query, $bypass=false) {
$time1=microtime(true);
$kver=mysqli_query($dblink,$query);
// uncomment this line to ditch the sql logs in html comments
// $bypass=true
if ($bypass==false) {
$time2=microtime(true);
echo "\n<!-- $query";
echo "\nTook: ".($time2-$time1);
$afec=mysqli_affected_rows($dblink);
if ($afec>=0) {
echo ", affected: $afec";
} else {
echo ", error: ".mysqli_error($dblink);
}
echo " -->\n";
}
return $kver;
}
// kill cache to debug
//mysqli_query_wrapper($dblink,"SET SESSION query_cache_type = OFF");
$hashlistAlias="#HL#";
$myself=basename(__FILE__);
$cas=time();
$loadtime=microtime(true);
?><html>
<head>
<title>Hashtopus <?php echo $htpver." [$htphost]"; ?></title>
<link rel="icon" href="favicon.ico" type="image/x-icon"/>
<link href='admin.css' rel='stylesheet' type='text/css'>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--<META http-equiv="cache-control" content="no-cache">-->
<script type="text/javascript" src="jscolor/jscolor.js"></script>
</head>
<body>
<table class="big"><tr><td>
<?php
if (isset($_POST["pwd"])) {
if (!isset($config["password"]) || makepwd($_POST["pwd"])==$config["password"]) $_SESSION[$sess_name]=1;
}
if (isset($_SESSION[$sess_name]) && $_SESSION[$sess_name]==1) {
// define redirect place
if (isset($_POST["return"])) {
$returnpage=$_POST["return"];
} else {
$returnpage="";
}
// create the menu
echo '<a href="'.$myself.'"><img src="img/logo.png" alt="Hashtopus"></a><br><ul>
<li><a href="'.$myself.'?a=agents">Agents</a></li>
<li><a href="'.$myself.'?a=deploy">Agent deployer</a></li>
<br>
<li><a href="'.$myself.'?a=tasks">Tasks</a> (<a href="'.$myself.'?a=newtask">new</a>)</li>
<li><a href="'.$myself.'?a=ptasks">Pre-conf tasks</a></li>
<br>
<li><a href="'.$myself.'?a=hashlists">Hashlists</a> (<a href="'.$myself.'?a=newhashlist">new</a>)</li>
<li><a href="'.$myself.'?a=superhashlists">Superhashlists</a> (<a href="'.$myself.'?a=newsuperhashlist">new</a>)</li>
<br>
<li><a href="'.$myself.'?a=files">Global files</a></li>
<br>
<li><a href="'.$myself.'?a=chunks">Chunk activity</a></li>
<br>
<li><a href="'.$myself.'?a=releases">Hashcat releases</a> (<a href="'.$myself.'?a=newrelease">new</a>)</li>';
if (file_exists("custmenu.php")) {
// create custom menu, should it be present
// refer to custmenu file for its documentation in comments
include("custmenu.php");
$custmenu=true;
echo "<br>";
foreach ($custmenuitems as $action=>$menuitem) {
if ($menuitem["condition"]) {
echo "<li><a href=\"$myself?a=custmenu&menu=$action\">".$menuitem["name"]."</a></li>";
}
}
}
echo '</ul>
<hr>
<ul>
<li><a href="'.$myself.'?a=config">Server configuration</a></li>
<li><a href="'.$myself.'?a=manual">Manual</a></li>
<li><a href="'.$myself.'?a=logout">Log out</a></li>
</ul>v'.$htpver.'</td><td>';
// correct password
$platforms=array("unknown","NVidia","AMD");
//$workloads=array(1=>"Low utilization",2=>"Default profile",3=>"High utilization");
$oses=array("<img src=\"img/win.png\" alt=\"Win\" title=\"Windows\">","<img src=\"img/unix.png\" alt=\"Unix\" title=\"Linux\">");
$states=array("New","Init","Running","Paused","Exhausted","Cracked","Aborted","Quit","Bypass","Trimmed","Aborting...");
$formats=array("Text","HCCAP","Binary","Superhashlist");
$formattables=array("hashes","hashes_binary","hashes_binary");
$uperrs=array("","Uploaded file is too big for server settings, use different transfer method (i.e. FTP to import subdir)","Uploaded file is too big for form setting. Have you been playing with admin again?!","File upload was interrupted","No file was uploaded","","Server doesn't have a temporary folder","Failed writing to disk. Maybe no space left or >2GB file on FAT32","Some PHP module stopped the transfer");
$srcchange="function sourceChange(valu){var pasteObject=document.getElementById(\"pasteLine\");var uploadObject=document.getElementById(\"uploadLine\");var importObject=document.getElementById(\"importLine\");var downloadObject=document.getElementById(\"downloadLine\");switch (valu){case 'paste':pasteObject.style.display = '';uploadObject.style.display = 'none';importObject.style.display = 'none';downloadObject.style.display = 'none';break;case 'upload':pasteObject.style.display = 'none';uploadObject.style.display = '';importObject.style.display = 'none';downloadObject.style.display = 'none';break;case 'import':pasteObject.style.display = 'none';uploadObject.style.display = 'none';importObject.style.display = '';downloadObject.style.display = 'none';break;case 'url':pasteObject.style.display = 'none';uploadObject.style.display = 'none';importObject.style.display = 'none';downloadObject.style.display = '';break;}}";
$checkall="function checkAll(formname,checktoggle){var checkboxes = new Array();checkboxes = document.getElementById(formname).getElementsByTagName('input');for (var i=0; i<checkboxes.length; i++){if (checkboxes[i].type == 'checkbox'){checkboxes[i].checked = checktoggle;}}}";
$geta=(isset($_GET["a"]) ? $_GET["a"] : "");
switch ($geta) {
case "agents":
// list agents
$kver=mysqli_query_wrapper($dblink,"SELECT agents.id,agents.uid,agents.active,agents.trusted,agents.cputype,agents.gpus,agents.hcversion,agents.lastact,agents.lasttime,agents.lastip,assignments.task,assignments.speed,agents.os,agents.name,IF(IFNULL(chunks.time,0)>".($cas-$config["chunktimeout"]).",1,0) AS working FROM agents LEFT JOIN assignments ON agents.id=assignments.agent LEFT JOIN tasks ON assignments.task=tasks.id LEFT JOIN (SELECT agent,MAX(GREATEST(dispatchtime,solvetime)) AS time FROM chunks GROUP BY agent) chunks ON chunks.agent=agents.id ORDER BY agents.id ASC");
echo "List of agents (".mysqli_num_rows($kver)."):";
echo "<table class=\"styled\">";
echo "<tr><td>id</td><td>Act</td><td>Name</td><td>OS</td><td>CPU</td><td>GPUs</td><td>Hashcat</td><td>Last activity</td><td>Assignment</td><td>Action</td></tr>";
while($erej=mysqli_fetch_array($kver,MYSQLI_ASSOC)) {
$id=$erej["id"];
echo "<tr><td><a href=\"$myself?a=agentdetail&agent=$id\">$id</a></td>";
echo "<td><form id=\"active$id\" action=\"$myself?a=agentactive\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"agent\" value=\"$id\">";
echo "<input type=\"hidden\" name=\"return\" value=\"a=agents\">";
echo "<input type=\"checkbox\" name=\"active\" value=\"1\"";
if ($erej["active"]==1) echo " checked";
echo " onChange=\"javascript:document.getElementById('active$id').submit();\">";
echo "</form></td>";
echo "<td><a href=\"$myself?a=agentdetail&agent=$id\">".$erej["name"]."</a>";
if ($erej["trusted"]==1) echo " <img src=\"img/lock.gif\" alt=\"Trusted\">";
if ($erej["working"]==1) echo " <img src=\"img/active.gif\" alt=\"Active\" title=\"".nicenum($erej["speed"],100000,1000)."H/s\">";
if ($erej["active"]==0) echo " <img src=\"img/pause.gif\" alt=\"Paused\">";
echo "</td><td>";
echo $oses[$erej["os"]];
echo "<td>".$erej["cputype"]."-bit</td><td>";
$gpus=explode($separator,$erej["gpus"]);
foreach ($gpus as $gpu) {
shortenstring($gpu,32);
echo "<br>";
}
echo "</td><td>".$erej["hcversion"]."</td><td>".$erej["lastact"]." at ".date($config["timefmt"],$erej["lasttime"])."<br>IP: ".$erej["lastip"]."</td><td>";
$task=$erej["task"];
echo "<form id=\"assign$id\" action=\"$myself?a=agentassign\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"return\" value=\"a=agents\">";
echo "<input type=\"hidden\" name=\"agent\" value=\"$id\">";
echo "<select name=\"task\" size=\"1\" onChange=\"javascript:document.getElementById('assign$id').submit();\"><option value=\"\">(unassigned)</option>";
$kve=mysqli_query_wrapper($dblink,"SELECT id,name FROM tasks WHERE hashlist IS NOT NULL ORDER BY id ASC");
while($ere=mysqli_fetch_array($kve,MYSQLI_ASSOC)) {
$idu=$ere["id"];
$nameu=$ere["name"];
echo "<option value=\"$idu\"";
if ($idu==$task) echo " selected";
echo ">$nameu</option>";
}
echo "</select></form></td>";
echo "<td><form action=\"$myself?a=agentdelete\" method=\"POST\" onSubmit=\"if (!confirm('Really delete agent $id?')) return false;\">";
echo "<input type=\"hidden\" name=\"return\" value=\"a=agents\">";
echo "<input type=\"hidden\" name=\"agent\" value=\"$id\">";
echo "<input type=\"submit\" value=\"Delete\"></form></td></tr>";
}
echo "</table>";
break;
case "agentauto":
// enable agent benchmark autoadjust for its current assignment
$agid=intval($_POST["agent"]);
$auto=intval($_POST["auto"]);
$vysledek=mysqli_query_wrapper($dblink,"UPDATE assignments SET autoadjust=$auto WHERE agent=$agid");
if (!$vysledek) {
echo "<script>alert('Could not change autoadjust!');</script>";
}
break;
case "taskauto":
// enable agent benchmark autoadjust for all subsequent agents added to this task
$task=intval($_POST["task"]);
$auto=intval($_POST["auto"]);
$vysledek=mysqli_query_wrapper($dblink,"UPDATE tasks SET autoadjust=$auto WHERE id=$task");
if (!$vysledek) {
echo "<script>alert('Could not change autoadjust!');</script>";
}
break;
case "agentignore":
// switch error ignoring for agent
$agid=intval($_POST["agent"]);
$ignore=intval($_POST["ignore"]);
$vysledek=mysqli_query_wrapper($dblink,"UPDATE agents SET ignoreerrors=$ignore WHERE id=$agid");
if (!$vysledek) {
echo "<script>alert('Could not change error ignoring!');</script>";
}
break;
case "agentactive":
// switch agent activity
$agid=intval($_POST["agent"]);
$active=intval($_POST["active"]);
$vysledek=mysqli_query_wrapper($dblink,"UPDATE agents SET active=$active WHERE id=$agid");
if (!$vysledek) {
echo "<script>alert('Could not change agent activity!');</script>";
}
break;
case "agenttrusted":
// switch agent trusted state
$agid=intval($_POST["agent"]);
$trusted=intval($_POST["trusted"]);
$vysledek=mysqli_query_wrapper($dblink,"UPDATE agents SET trusted=$trusted WHERE id=$agid");
if (!$vysledek) {
echo "<script>alert('Could not change agent trust!');</script>";
}
break;
case "hashlistsecret":
// switch hashlist secret state
$hlist=intval($_POST["hashlist"]);
$secret=intval($_POST["secret"]);
$vysledek=mysqli_query_wrapper($dblink,"UPDATE hashlists SET secret=$secret WHERE id=$hlist");
if ($secret==1) mysqli_query_wrapper($dblink,"DELETE FROM hashlistusers JOIN agents ON agents.id=hashlistusers.agent WHERE hashlistusers.hashlist=$hlist AND agents.trusted<$secret");
if (!$vysledek) {
echo "<script>alert('Could not change hashlist secrecy!');</script>";
}
break;
case "filesecret":
// switch global file secret state
$fid=intval($_POST["file"]);
$secret=intval($_POST["secret"]);
$vysledek=mysqli_query_wrapper($dblink,"UPDATE files SET secret=$secret WHERE id=$fid");
if (!$vysledek) {
echo "<script>alert('Could not change global file secrecy!');</script>";
}
break;
case "agentassign";
// assign agent to a task or unassign it
$agid=intval($_POST["agent"]);
$task=intval($_POST["task"]);
// unassign
$vysledek = mysqli_query_wrapper($dblink,"DELETE FROM assignments WHERE agent=$agid");
mysqli_query_wrapper($dblink,"DELETE FROM hashlistusers WHERE agent=$agid");
if ($task!=0) {
// agent was not assigned, we need a new assignment
$vysledek=mysqli_query_wrapper($dblink,"INSERT INTO assignments (task,agent,benchmark,autoadjust) SELECT id,$agid,0,autoadjust FROM tasks WHERE id=$task");
}
if (!$vysledek) {
echo "Could not assign agent to task $task.";
$returnpage="";
}
break;
case "agentbench";
// adjust agent benchmark
$agid=intval($_POST["agent"]);
$bench=floatval($_POST["bench"]);
$vysledek=false;
$vysledek=mysqli_query_wrapper($dblink,"UPDATE assignments SET benchmark=$bench WHERE agent=$agid");
if (!$vysledek) {
echo "<script>alert('Could not set benchmark!');</script>";
}
break;
case "agentdelete";
// delete agent from the system
$agid=intval($_POST["agent"]);
mysqli_query_wrapper($dblink,"START TRANSACTION");
if (delete_agent($agid)) {
mysqli_query_wrapper($dblink,"COMMIT");
} else {
mysqli_query_wrapper($dblink,"ROLLBACK");
echo "<script>alert('Could not delete agent!');</script>";
}
break;
case "voucherdelete";
// delete registration voucher
$id=$_POST["voucher"];
$vysledek=mysqli_query_wrapper($dblink,"DELETE FROM regvouchers WHERE voucher='".mysqli_real_escape_string($dblink,$id)."'");
if (!$vysledek) {
echo "<script>alert('Could not delete registration voucher!');</script>";
}
break;
case "filedelete";
// delete global file
$fid=intval($_POST["file"]);
mysqli_query_wrapper($dblink,"START TRANSACTION");
$kver=mysqli_query_wrapper($dblink,"SELECT * FROM files WHERE id=$fid");
if ($erej=mysqli_fetch_array($kver)) {
$fname=$erej["filename"];
$kver=mysqli_query_wrapper($dblink,"SELECT 1 FROM taskfiles WHERE file=$fid");
if (mysqli_num_rows($kver)>0) {
// file is used in task
echo "<script>alert('File is used in a task.');</script>";
} else {
$kver2=mysqli_query_wrapper($dblink,"SELECT 1 FROM hashcats WHERE file=$fid");
if (mysqli_num_rows($kver2)>0) {
// file is used as release
echo "<script>alert('File is used as a Hashcat release.');</script>";
} else {
$vysledek1=mysqli_query_wrapper($dblink,"DELETE FROM files WHERE id=$fid");
if ($vysledek1) {
if (file_exists("$filesdir/".$fname)) {
$vysledek2=unlink("$filesdir/".$fname);
} else {
$vysledek2=true;
}
}
if ($vysledek1 && $vysledek2) {
mysqli_query_wrapper($dblink,"COMMIT");
} else {
mysqli_query_wrapper($dblink,"ROLLBACK");
echo "<script>alert('Could not delete file!');</script>";
}
}
}
} else {
echo "<script>alert('Such file is not defined.');</script>";
}
break;
case "releasedelete";
// delete hashcat release
$release=mysqli_real_escape_string($dblink,$_POST["release"]);
mysqli_query_wrapper($dblink,"START TRANSACTION");
$kv=mysqli_query_wrapper($dblink,"SELECT * FROM agents WHERE hcversion='$release'");
if (mysqli_num_rows($kv)>0) {
echo "<script>alert('There are registered agents running this Hashcat version.');</script>";
} else {
$vysledek1=mysqli_query_wrapper($dblink,"DELETE FROM hashcats WHERE version='$release'");
if ($vysledek1) {
mysqli_query_wrapper($dblink,"COMMIT");
} else {
mysqli_query_wrapper($dblink,"ROLLBACK");
echo "<script>alert('Could not delete Hashcat release!');</script>";
}
}
break;
case "hashlistdelete";
// delete hashlist
$hlist=intval($_POST["hashlist"]);
mysqli_query_wrapper($dblink,"START TRANSACTION");
$kv=mysqli_query_wrapper($dblink,"SELECT hashlists.format,hashlists.hashcount FROM hashlists WHERE hashlists.id=$hlist");
$erej=mysqli_fetch_array($kv,MYSQLI_ASSOC);
$hcount=$erej["hashcount"];
// decrease supercount by that of deleted hashlist
$vysledek0=mysqli_query_wrapper($dblink,"UPDATE hashlists JOIN superhashlists ON superhashlists.id=hashlists.id AND hashlists.format=3 AND superhashlists.hashlist=$hlist JOIN hashlists hashlists2 ON hashlists2.id=superhashlists.hashlist SET hashlists.cracked=hashlists.cracked-hashlists2.cracked,hashlists.hashcount=hashlists.hashcount-hashlists2.hashcount");
// then actually delete the list
$vysledek1=$vysledek0 && mysqli_query_wrapper($dblink,"DELETE FROM hashlists WHERE id=$hlist");
$vysledek2=$vysledek1 && mysqli_query_wrapper($dblink,"DELETE FROM hashlistusers WHERE hashlist=$hlist");
$vysledek3=$vysledek2 && mysqli_query_wrapper($dblink,"DELETE FROM zapqueue WHERE hashlist=$hlist");
// and its tasks
$vysledek4=$vysledek3 && mysqli_query_wrapper($dblink,"DELETE FROM taskfiles WHERE task IN (SELECT id FROM tasks WHERE hashlist=$hlist)");
$vysledek5=$vysledek4 && mysqli_query_wrapper($dblink,"DELETE FROM assignments WHERE task IN (SELECT id FROM tasks WHERE hashlist=$hlist)");
$vysledek6=$vysledek5 && mysqli_query_wrapper($dblink,"DELETE FROM chunks WHERE task IN (SELECT id FROM tasks WHERE hashlist=$hlist)");
$vysledek7=$vysledek6 && mysqli_query_wrapper($dblink,"DELETE FROM tasks WHERE hashlist=$hlist");
$vysledek8=$vysledek7 && mysqli_query_wrapper($dblink,"DELETE FROM superhashlists WHERE hashlist=$hlist");
if ($vysledek8) {
mysqli_query_wrapper($dblink,"COMMIT");
echo "Deleted hashlist and associated zaps.<br>";
switch ($erej["format"]) {
case 0:
$radku=mysqli_query_wrapper($dblink,"SELECT 1 FROM hashlists WHERE format=0");
if (mysqli_num_rows($radku)>0) {
echo "Deleting the actual rows (this is going to take A LONG TIME!)...<br>";
$hdelete=0;
$kolik=1;
$cas_pinfo=time();
$cas_start=time();
mysqli_query_wrapper($dblink,"START TRANSACTION");
while($kolik>0) {
$kver="DELETE FROM ".$formattables[$erej["format"]]." WHERE hashlist=$hlist LIMIT 1000";
$vysledek1=mysqli_query_wrapper($dblink,$kver);
$kolik=mysqli_affected_rows($dblink);
$hdelete+=$kolik;
if (time()>=$cas_pinfo+10) {
echo "Progress: $hdelete/$hcount, time spent: ".(time()-$cas_start)." sec<br>";
flush();
mysqli_query_wrapper($dblink,"COMMIT");
mysqli_query_wrapper($dblink,"START TRANSACTION");
$cas_pinfo=time();
}
}
mysqli_query_wrapper($dblink,"COMMIT");
} else {
echo "This was the last hashlist, truncating the table.";
mysqli_query_wrapper($dblink,"TRUNCATE TABLE ".$formattables[$erej["format"]]);
}
break;
case 1:
case 2:
echo "Deleting binary hashes...<br>";
mysqli_query_wrapper($dblink,"DELETE FROM hashes_binary WHERE hashlist=$hlist");
break;
case 3:
echo "Deleting superhashlist links...<br>";
mysqli_query_wrapper($dblink,"DELETE FROM superhashlists WHERE id=$hlist");
break;
}
echo "Done.";
} else {
mysqli_query_wrapper($dblink,"ROLLBACK");
echo "Problems deleting hashlist!";
$returnpage="";
}
break;
case "agentwait";
// change agent waiting time for idle
$agid=intval($_POST["agent"]);
$wait=intval($_POST["wait"]);
$vysledek=mysqli_query_wrapper($dblink,"UPDATE agents SET wait=$wait WHERE id=$agid");
if (!$vysledek) {
echo "<script>alert('Could not change agent idle wait period!');</script>";
}
break;
case "agentpars";
// change agent extra cmd line parameters for hashcat
$agid=intval($_POST["agent"]);
$pars=mysqli_real_escape_string($dblink,$_POST["cmdpars"]);
$vysledek=mysqli_query_wrapper($dblink,"UPDATE agents SET cmdpars='$pars' WHERE id=$agid");
if (!$vysledek) {
echo "<script>alert('Could not change agent-specific parameters!');</script>";
}
break;
case "chunkreset";
// reset chunk state and progress to zero
$chunk=intval($_POST["chunk"]);
$vysledek=mysqli_query_wrapper($dblink,"UPDATE chunks SET state=0,progress=0,rprogress=0,dispatchtime=$cas,solvetime=0 WHERE id=$chunk");
if (!$vysledek) {
echo "<script>alert('Could not reset chunk!');</script>";
}
break;
case "chunkabort";
// reset chunk state and progress to zero
$chunk=intval($_POST["chunk"]);
$vysledek=mysqli_query_wrapper($dblink,"UPDATE chunks SET state=10 WHERE id=$chunk");
if (!$vysledek) {
echo "<script>alert('Could not abort chunk!');</script>";
}
break;
case "taskprio";
// change task priority
$task=intval($_POST["task"]);
$prio=intval($_POST["priority"]);
$kv=mysqli_query_wrapper($dblink,"SELECT 1 FROM tasks WHERE tasks.priority=$prio AND tasks.id!=$task AND tasks.priority>0 AND SIGN(IFNULL(tasks.hashlist,0))=(SELECT SIGN(IFNULL(hashlist,0)) FROM tasks WHERE id=$task) LIMIT 1");
if (mysqli_num_rows($kv)==1) {
// must be unique
echo "<script>alert('Each task has to have unique priority!');</script>";
} else {
$vysledek=mysqli_query_wrapper($dblink,"UPDATE tasks SET priority=$prio WHERE id=$task");
if (!$vysledek) {
echo "<script>alert('Could not change priority!');</script>";
}
}
break;
case "taskcolor";
// change task color
$task=intval($_POST["task"]);
$color=$_POST["color"];
if (preg_match("/[0-9A-Za-z]{6}/",$color)==1) {
$color="'$color'";
} else {
$color="NULL";
}
$vysledek=mysqli_query_wrapper($dblink,"UPDATE tasks SET color=$color WHERE id=$task");
if (!$vysledek) {
echo "<script>alert('Could not change color!');</script>";
}
break;
case "taskrename";
// change task name
$task=intval($_POST["task"]);
$name=mysqli_real_escape_string($dblink,$_POST["name"]);
$kv=mysqli_query_wrapper($dblink,"UPDATE tasks SET name='$name' WHERE id=$task");
if (!$kv) {
echo "<script>alert('Could not rename task!');</script>";
}
break;
case "hashlistrename";
// change hashlist name
$hlist=intval($_POST["hashlist"]);
$name=mysqli_real_escape_string($dblink,$_POST["name"]);
$kv=mysqli_query_wrapper($dblink,"UPDATE hashlists SET name='$name' WHERE id=$hlist");
if (!$kv) {
echo "<script>alert('Could not rename hashlist!');</script>";
}
break;
case "taskpurge";
// delete all task chunks, forget its keyspace value and reset progress to zero
$task=intval($_POST["task"]);
mysqli_query_wrapper($dblink,"START TRANSACTION");
$vysledek1=mysqli_query_wrapper($dblink,"UPDATE assignments SET benchmark=0 WHERE task=$task");
$vysledek2=mysqli_query_wrapper($dblink,"UPDATE hashes SET chunk=NULL WHERE chunk IN (SELECT id FROM chunks WHERE task=$task)");
$vysledek3=mysqli_query_wrapper($dblink,"UPDATE hashes_binary SET chunk=NULL WHERE chunk IN (SELECT id FROM chunks WHERE task=$task)");
$vysledek4=mysqli_query_wrapper($dblink,"DELETE FROM zapqueue WHERE chunk IN (SELECT id FROM chunks WHERE task=$task)");
$vysledek5=mysqli_query_wrapper($dblink,"DELETE FROM chunks WHERE task=$task");
$vysledek6=mysqli_query_wrapper($dblink,"UPDATE tasks SET keyspace=0,progress=0 WHERE id=$task");
if ($vysledek1 && $vysledek2 && $vysledek3 && $vysledek4 && $vysledek5 && $vysledek6) {
mysqli_query_wrapper($dblink,"COMMIT");
} else {
mysqli_query_wrapper($dblink,"ROLLBACK");
echo "<script>alert('Could not purge task!');</script>";
}
break;
case "rebuildcache";
// db utility to recalculate cache for all chunks, hashlists and tasks
// slow
$kv=mysqli_query_wrapper($dblink,"UPDATE chunks LEFT JOIN (SELECT chunk,COUNT(1) AS cracked FROM hashes GROUP BY chunk) hashes ON chunks.id=hashes.chunk LEFT JOIN (SELECT chunk,COUNT(1) AS cracked FROM hashes_binary GROUP BY chunk) hashes_binary ON chunks.id=hashes_binary.chunk SET chunks.cracked=IFNULL(hashes.cracked,0)+IFNULL(hashes_binary.cracked,0)");
$changed=mysqli_affected_rows($dblink);
echo "Chunk cache rebuilt on $changed chunks!<br>";
$kv=mysqli_query_wrapper($dblink,"UPDATE hashes SET chunk=NULL WHERE chunk!=0 AND chunk NOT IN (SELECT id FROM chunks)");
$changed=mysqli_affected_rows($dblink);
echo "Cleaned $changed orphaned text hashes!<br>";
$kv=mysqli_query_wrapper($dblink,"UPDATE hashes_binary SET chunk=NULL WHERE chunk!=0 AND chunk NOT IN (SELECT id FROM chunks)");
$changed=mysqli_affected_rows($dblink);
echo "Cleaned $changed orphaned binary hashes!<br>";
$kv=mysqli_query_wrapper($dblink,"UPDATE hashlists LEFT JOIN (SELECT hashlist,COUNT(1) AS htotal, COUNT(plaintext) AS ctotal FROM hashes GROUP BY hashlist) hashes ON hashlists.format=0 AND hashlists.id=hashes.hashlist LEFT JOIN (SELECT hashlist,COUNT(1) AS htotal, COUNT(plaintext) AS ctotal FROM hashes_binary GROUP BY hashlist) hashes_binary ON hashlists.format IN (1,2) AND hashlists.id=hashes_binary.hashlist SET hashlists.hashcount=IF(hashlists.format=0,hashes.htotal,hashes_binary.htotal),hashlists.cracked=IF(hashlists.format=0,hashes.ctotal,hashes_binary.ctotal) WHERE hashlists.format!=3");
$changed=mysqli_affected_rows($dblink);
echo "Hash count rebuilt on $changed hashlists!<br>";
$kv=mysqli_query_wrapper($dblink,"UPDATE hashlists JOIN (SELECT superhashlists.id,SUM(hashlists.hashcount) AS hashcount,SUM(hashlists.cracked) AS cracked FROM superhashlists JOIN hashlists ON superhashlists.hashlist=hashlists.id GROUP BY superhashlists.id) super ON super.id=hashlists.id SET hashlists.cracked=super.cracked,hashlists.hashcount=super.hashcount");
$changed=mysqli_affected_rows($dblink);
echo "Hash count rebuilt on $changed superhashlists!<br>";
break;
case "rescanfiles";
// db utility to rescan all files in system, chceck if their size match or if they exist
// and attempt to fix problems
// fast
$kv=mysqli_query_wrapper($dblink,"SELECT * FROM files ORDER BY filename");
while($erej=mysqli_fetch_array($kv,MYSQLI_ASSOC)) {
$id=$erej["id"];
$fil=$erej["filename"];
if (file_exists("$filesdir/$fil")) {
if (is_dir("$filesdir/$fil")) {
mysqli_query_wrapper($dblink,"DELETE FROM files WHERE id=$id");
echo "<b>File $fil was a directory, deleted from database</b>";
} else {
$nsize=filesize("$filesdir/$fil");
$size=$erej["size"];
if ($nsize==$size) {
echo "File $fil OK.";
} else {
mysqli_query_wrapper($dblink,"UPDATE files SET size=$nsize WHERE id=$id");
echo "<b>File $fil had wrong size, corrected from $size to $nsize</b>";
}
}
} else {
echo "<b>File $fil does not exist, checking usage in tasks...</b>";
$us=mysqli_query_wrapper($dblink,"SELECT tasks.name FROM taskfiles JOIN tasks ON tasks.id=taskfiles.task WHERE file=$id");
if (mysqli_num_rows($us)>0) {
echo "FILE IS USED IN FOLLOWING TASKS:";
while ($ere=mysqli_fetch_array($us,MYSQLI_ASSOC)) {
echo "<br>- ".$ere["name"];
}
} else {
echo "file is not used, deleting...";
mysqli_query_wrapper($dblink,"DELETE FROM files WHERE id=$id");
}
echo "</b>";
}
echo "<br>";
}
break;
case "clearall";
// db utility to delete everything except agents and pre-conf tasks from the system
// very fast - no logic here at all
if (isset($_SESSION["cleartoken"])) {
$cts=$_SESSION["cleartoken"];
}
if (isset($_GET["cleartoken"])) {
$ctg=$_GET["cleartoken"];
if ($ctg==$cts && $ctg!="") {
unset($_SESSION["cleartoken"]);
echo "Deleting tasks...<br>";
mysqli_query_wrapper($dblink,"TRUNCATE TABLE assignments");
mysqli_query_wrapper($dblink,"DELETE FROM tasks WHERE hashlist IS NOT NULL");
mysqli_query_wrapper($dblink,"DELETE FROM taskfiles WHERE task NOT IN (SELECT id FROM tasks)");
echo "Deleting chunks...<br>";
mysqli_query_wrapper($dblink,"TRUNCATE TABLE chunks");
echo "Deleting hashlists...<br>";
mysqli_query_wrapper($dblink,"TRUNCATE TABLE hashlists");
mysqli_query_wrapper($dblink,"TRUNCATE TABLE hashes");
mysqli_query_wrapper($dblink,"TRUNCATE TABLE hashes_binary");
echo "Deleted all.";
} else {
echo "You clicked the wrong link.";
}
} else {
$cts=generate_random(10);
$_SESSION["cleartoken"]=$cts;
echo "<img src=\"img/pause.gif\"> <a href=\"$myself?a=clearall&cleartoken=$cts\">Really delete all data</a> <img src=\"img/pause.gif\">";
}
break;
case "preconf";
// deploy selected pre-configured tasks on a hashlist
$hlist=intval($_POST["hashlist"]);
$addc=0; $filc=0;
if (isset($_POST["task"])) {
$kv=mysqli_query_wrapper($dblink,"SELECT IFNULL(MAX(priority),0) AS base FROM tasks WHERE hashlist IS NOT NULL");
$erej=mysqli_fetch_array($kv,MYSQLI_ASSOC);
$base=$erej["base"];
foreach($_POST["task"] as $ida) {
$id=intval($ida);
if ($id>0) {
$kv=mysqli_query_wrapper($dblink,"SELECT name,attackcmd,chunktime,statustimer,autoadjust,priority FROM tasks WHERE tasks.id=$id");
$erej=mysqli_fetch_array($kv,MYSQLI_ASSOC);
$addq=mysqli_query_wrapper($dblink,"INSERT INTO tasks (name, attackcmd, hashlist, chunktime, statustimer, autoadjust, priority) VALUES ('HL".$hlist."_".mysqli_real_escape_string($dblink,$erej["name"])."', '".mysqli_real_escape_string($dblink,$erej["attackcmd"])."', $hlist, ".$erej["chunktime"].", ".$erej["statustimer"].", ".$erej["autoadjust"].", ".($erej["priority"]>0 ? $base+$erej["priority"] : 0).")");
$addc+=mysqli_affected_rows($dblink);
$tid=mysqli_insert_id($dblink);
$filq=mysqli_query_wrapper($dblink,"INSERT INTO taskfiles (task, file) SELECT $tid,file FROM taskfiles WHERE task=$id");
$filc+=mysqli_affected_rows($dblink);
echo "Added task $id as $tid.<br>";
}
}
}
if ($addc==0) {
echo "No new tasks were created!";
} else {
$returnpage="a=tasks";
}
break;
case "taskchunk";
// update task chunk time
$task=intval($_POST["task"]);
$chunktime=intval($_POST["chunktime"]);
mysqli_query_wrapper($dblink,"START TRANSACTION");
$vysledek1=mysqli_query_wrapper($dblink,"UPDATE assignments JOIN tasks ON tasks.id=assignments.task SET assignments.benchmark=(assignments.benchmark/tasks.chunktime)*$chunktime WHERE assignments.task=$task");
$vysledek2=mysqli_query_wrapper($dblink,"UPDATE tasks SET chunktime=$chunktime WHERE id=$task");
if ($vysledek1 && $vysledek2) {
mysqli_query_wrapper($dblink,"COMMIT");
} else {
mysqli_query_wrapper($dblink,"ROLLBACK");
echo "<script>alert('Could not update task chunk time!');</script>";
}
break;
case "taskdelete";
// delete a task
$task=intval($_POST["task"]);
mysqli_query_wrapper($dblink,"START TRANSACTION");
if (delete_task($task)) {
mysqli_query_wrapper($dblink,"COMMIT");
} else {
mysqli_query_wrapper($dblink,"ROLLBACK");
echo "<script>alert('Could not delete task!');</script>";
}
break;
case "finishedtasksdelete";
// delete finished tasks
$sez=mysqli_query_wrapper($dblink,"SELECT tasks.id,hashlists.format,tasks.hashlist FROM tasks JOIN hashlists ON tasks.hashlist=hashlists.id JOIN (SELECT task,SUM(progress) AS sumprog FROM chunks WHERE rprogress=10000 GROUP BY task) chunks ON chunks.task=tasks.id WHERE (tasks.progress=tasks.keyspace AND chunks.sumprog=tasks.keyspace) OR hashlists.cracked=hashlists.hashcount");
$seznam=array();
// load the tasks first
while($erej=mysqli_fetch_array($sez,MYSQLI_ASSOC)) {
$seznam[]=$erej;
}
// then process them
foreach ($seznam as $ttd) {
$task=$ttd["id"];
$format=$ttd["format"];
$hlist=$ttd["hashlist"];
mysqli_query_wrapper($dblink,"START TRANSACTION");
if (delete_task($task)) {
mysqli_query_wrapper($dblink,"COMMIT");
echo "Deleted task $task<br>";
} else {
mysqli_query_wrapper($dblink,"ROLLBACK");
echo "<script>alert('Could not delete task $task');</script><br>";
}
}
break;
case "tasks":
// list tasks
$kver=mysqli_query_wrapper($dblink,"SELECT tasks.id AS task,tasks.chunktime,tasks.priority,tasks.color,tasks.name,tasks.attackcmd,tasks.hashlist,tasks.progress,IFNULL(chunks.sumprog,0) AS sumprog,tasks.keyspace,IFNULL(chunks.pcount,0) AS pcount,IFNULL(chunks.ccount,0) AS ccount,IFNULL(taskfiles.secret,0) AS secret,IF(chunks.lastact>".($cas-$config["chunktimeout"]).",1,0) AS active,IFNULL(assignments.acount,0) AS assigncount,taskfiles.fcount AS filescount,IFNULL(taskfiles.fsize,0) AS filesize,hashlists.name AS hname,hashlists.secret AS hsecret,IF(hashlists.cracked<hashlists.hashcount,1,0) AS hlinc FROM tasks JOIN hashlists ON hashlists.id=tasks.hashlist LEFT JOIN (SELECT task,SUM(cracked) AS pcount,COUNT(1) AS ccount,GREATEST(MAX(dispatchtime),MAX(solvetime)) AS lastact,SUM(progress) AS sumprog FROM chunks GROUP BY task) chunks ON chunks.task=tasks.id LEFT JOIN (SELECT task,COUNT(1) AS acount FROM assignments GROUP BY task) assignments ON assignments.task=tasks.id LEFT JOIN (SELECT taskfiles.task,COUNT(1) AS fcount,SUM(files.size) AS fsize,MAX(files.secret) AS secret FROM taskfiles JOIN files ON files.id=taskfiles.file GROUP BY taskfiles.task) taskfiles ON taskfiles.task=tasks.id ORDER BY active DESC, tasks.priority DESC, tasks.id ASC");
echo "List of tasks (".mysqli_num_rows($kver)."): ";
echo "<form action=\"$myself?a=finishedtasksdelete\" method=\"POST\" onSubmit=\"if (!confirm('Really delete all finished tasks?')) return false;\">";
echo "<input type=\"hidden\" name=\"return\" value=\"a=tasks\">";
echo "<input type=\"submit\" value=\"Delete finished\"></form>";
echo "<table class=\"styled\">";
echo "<tr><td>id</td><td>Name</td><td>Hashlist</td><td>Chunks</td><td>Dispatched</td><td>Searched</td><td>Cracked</td><td>Agents</td><td>Files</td><td>Priority</td><td>Action</td></tr>";
while($erej=mysqli_fetch_array($kver,MYSQLI_ASSOC)) {
$id=$erej["task"];
$hlist=$erej["hashlist"];
echo "<tr><td";
if (strlen($erej["color"])>0) {
echo " style=\"background-color: #".$erej["color"]."\"";
}
echo "><a href=\"$myself?a=taskdetail&task=$id\">$id</a></td><td title=\"".$erej["attackcmd"]."\"><a href=\"$myself?a=taskdetail&task=$id\">".$erej["name"]."</a>";
echo tickdone($erej["sumprog"],$erej["keyspace"]);
if ($erej["active"]==1 && $erej["sumprog"]<$erej["keyspace"]) echo " <img src=\"img/active.gif\" alt=\"Active\">";
echo "</td><td>";
if ($hlist=="") {
echo "(pre-configured task)";
} else {
echo "<a href=\"$myself?a=hashlistdetail&hashlist=$hlist\">".$erej["hname"]."</a>";
if ($erej["hsecret"]==1) echo " <img src=\"img/lock.gif\" alt=\"Secret\">";
echo tickdone(($erej["hlinc"]==0 ? 1 : 0),1);
}
echo "</td><td class=\"num\">".$erej["ccount"]." @ ".$erej["chunktime"]."s</td>";
if ($erej["keyspace"]>0) {
echo "<td class=\"num\">";
echo showperc($erej["progress"],$erej["keyspace"])."%";
echo "</td><td class=\"num\">";
echo showperc($erej["sumprog"],$erej["keyspace"])."%";
} else {
echo "<td colspan=\"2\">Keyspace unknown";
}
echo "</td><td class=\"num\">";
if ($erej["pcount"]>0) echo "<a href=\"$myself?a=hashes&task=$id\">".$erej["pcount"]."</a>";
echo "</td><td class=\"num\">";
if ($erej["assigncount"]>0) echo $erej["assigncount"];
echo "</td><td>";
if ($erej["filescount"]>0) echo $erej["filescount"]." (".nicenum($erej["filesize"])."B)";
if ($erej["secret"]==1) echo " <img src=\"img/lock.gif\" alt=\"Secret\">";
echo "</td>";
echo "<td><form action=\"$myself?a=taskprio\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"return\" value=\"a=tasks\">";
echo "<input type=\"hidden\" name=\"task\" value=\"$id\">";
echo "<input type=\"text\" name=\"priority\" size=\"4\" value=\"".$erej["priority"]."\"><input type=\"submit\" value=\"Set\"></form></td>";
echo "<td><form action=\"$myself\" method=\"GET\">";
echo "<input type=\"hidden\" name=\"a\" value=\"newtask\">";
echo "<input type=\"hidden\" name=\"task\" value=\"$id\">";
echo "<input type=\"submit\" value=\"Copy\"></form> ";
echo "<form action=\"$myself?a=taskdelete\" method=\"POST\" onSubmit=\"if (!confirm('Really delete task $id?')) return false;\">";
echo "<input type=\"hidden\" name=\"return\" value=\"a=tasks\">";
echo "<input type=\"hidden\" name=\"task\" value=\"$id\">";
echo "<input type=\"submit\" value=\"Delete\"></form></td>";
echo "</tr>";
if ($erej["sumprog"]<$erej["keyspace"]) echo "<tr><td colspan=\"11\"><img style=\"width: 100%; height: 6px;\" src=\"taskimg.php?task=$id&x=800&y=6\"></td></tr>";
}
echo "</table>";
break;
case "ptasks":
// list pre-conf tasks
$kver=mysqli_query_wrapper($dblink,"SELECT tasks.id,tasks.name,tasks.color,tasks.attackcmd,tasks.priority,taskfiles.fcount AS filescount,IFNULL(taskfiles.fsize,0) AS filesize,IFNULL(taskfiles.secret,0) AS secret FROM tasks LEFT JOIN (SELECT taskfiles.task,COUNT(1) AS fcount,SUM(files.size) AS fsize,MAX(files.secret) AS secret FROM taskfiles JOIN files ON files.id=taskfiles.file GROUP BY taskfiles.task) taskfiles ON taskfiles.task=tasks.id WHERE tasks.hashlist IS NULL ORDER by tasks.priority DESC, tasks.id ASC");
echo "List of pre-configured tasks (".mysqli_num_rows($kver)."):";
echo "<table class=\"styled\">";
echo "<tr><td>id</td><td>Name</td><td>Attack command</td><td>Files</td><td>Priority</td><td>Action</td></tr>";
while($erej=mysqli_fetch_array($kver,MYSQLI_ASSOC)) {
$id=$erej["id"];
echo "<tr><td";
if (strlen($erej["color"])>0) {
echo " style=\"background-color: #".$erej["color"]."\"";
}
echo "><a href=\"$myself?a=taskdetail&task=$id\">$id</a></td><td><a href=\"$myself?a=taskdetail&task=$id\">".$erej["name"]."</a>";
echo "</td><td>";
echo $erej["attackcmd"];
echo "</td><td>";
if ($erej["filescount"]>0) echo $erej["filescount"]." (".nicenum($erej["filesize"])."B)";
if ($erej["secret"]==1) echo " <img src=\"img/lock.gif\" alt=\"Secret\">";
echo "</td><td>";
echo "<form action=\"$myself?a=taskprio\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"return\" value=\"a=ptasks\">";
echo "<input type=\"hidden\" name=\"task\" value=\"$id\">";
echo "<input type=\"text\" name=\"priority\" size=\"4\" value=\"".$erej["priority"]."\"><input type=\"submit\" value=\"Set\"></form></td>";
echo "<td><form action=\"$myself\" method=\"GET\">";
echo "<input type=\"hidden\" name=\"a\" value=\"newtask\">";
echo "<input type=\"hidden\" name=\"task\" value=\"$id\">";
echo "<input type=\"submit\" value=\"Copy\"></form> ";
echo "<form action=\"$myself?a=taskdelete\" method=\"POST\" onSubmit=\"if (!confirm('Really delete task $id?')) return false;\">";
echo "<input type=\"hidden\" name=\"return\" value=\"a=ptasks\">";
echo "<input type=\"hidden\" name=\"task\" value=\"$id\">";
echo "<input type=\"submit\" value=\"Delete\"></form></td></tr>";
}
echo "</table>";
break;
case "hashlists":
// list hashlists
$kver=mysqli_query_wrapper($dblink,"SELECT hashlists.id,hashlists.name,hashlists.hashtype,hashlists.format,hashlists.hashcount,hashlists.cracked,hashlists.secret,hashtypes.description FROM hashlists LEFT JOIN hashtypes ON hashtypes.id=hashlists.hashtype WHERE format!=3 ORDER BY id ASC");
echo "List of hashlists (".mysqli_num_rows($kver)."):";
echo "<table class=\"styled\">";
echo "<tr><td>id</td><td>Name</td><td>Hash type</td><td>Format</td><td>Cracked</td><td>Pre-cracked</td><td>Action</td></tr>";
while($erej=mysqli_fetch_array($kver,MYSQLI_ASSOC)) {
$id=$erej["id"];
echo "<tr><td><a href=\"$myself?a=hashlistdetail&hashlist=$id\">$id</a></td><td><a href=\"$myself?a=hashlistdetail&hashlist=$id\">".$erej["name"]."</a>";
if ($erej["secret"]==1) echo " <img src=\"img/lock.gif\" alt=\"Secret\">";
echo tickdone($erej["cracked"],$erej["hashcount"]);
echo "</td><td>";
echo ($erej["description"]=="" ? $erej["hashtype"] : $erej["description"]);
echo "</td><td>";
echo $formats[$erej["format"]];
echo "</td><td class=\"num\">";
echo showperc($erej["cracked"],$erej["hashcount"])."%<br>";
echo "(<a href=\"$myself?a=hashes&hashlist=$id&filter=cracked\">".$erej["cracked"]."</a> / <a href=\"$myself?a=hashes&hashlist=$id\">".$erej["hashcount"]."</a>)";
echo "</td>";
echo "<td><form action=\"$myself\" method=\"GET\">";
echo "<input type=\"hidden\" name=\"a\" value=\"hashlistzap\">";
echo "<input type=\"hidden\" name=\"hashlist\" value=\"$id\">";
echo "<input type=\"submit\" value=\"Import\"></form>";
echo "<form action=\"$myself\" method=\"GET\"> ";
echo "<input type=\"hidden\" name=\"a\" value=\"export\">";
echo "<input type=\"hidden\" name=\"hashlist\" value=\"$id\">";
echo "<input type=\"submit\" value=\"Export\"></form></td>";
echo "<td><form action=\"$myself?a=hashlistdelete\" method=\"POST\" onSubmit=\"if (!confirm('Really delete hashlist $id?')) return false;\">";
echo "<input type=\"hidden\" name=\"return\" value=\"a=hashlists\">";
echo "<input type=\"hidden\" name=\"hashlist\" value=\"$id\">";
echo "<input type=\"submit\" value=\"Delete\"></form></td>";
echo "</tr>";
}
echo "</table>";
break;
case "superhashlists":
// list superhashlists
$kver=mysqli_query_wrapper($dblink,"SELECT hashlists.id,hashlists.name,hashlists.secret,hashlists.hashtype,hashlists.format,hashlists.hashcount,hashlists.cracked,GROUP_CONCAT(hashlists2.name ORDER BY hashlists2.id SEPARATOR '<br>') AS lists,hashtypes.description FROM hashlists LEFT JOIN hashtypes ON hashtypes.id=hashlists.hashtype JOIN superhashlists ON superhashlists.id=hashlists.id JOIN hashlists hashlists2 ON hashlists2.id=superhashlists.hashlist WHERE hashlists.format=3 GROUP BY superhashlists.id ORDER BY id ASC");
echo "List of superhashlists (".mysqli_num_rows($kver)."):";
echo "<table class=\"styled\">";
echo "<tr><td>id</td><td>Name</td><td>Hash type</td><td>Cracked</td><td>Hashlists</td><td>Pre-cracked</td><td>Action</td></tr>";
while($erej=mysqli_fetch_array($kver,MYSQLI_ASSOC)) {
$id=$erej["id"];
echo "<tr><td><a href=\"$myself?a=hashlistdetail&hashlist=$id\">$id</a></td><td><a href=\"$myself?a=hashlistdetail&hashlist=$id\">".$erej["name"]."</a>";
if ($erej["secret"]==1) echo " <img src=\"img/lock.gif\" alt=\"Secret\">";
echo tickdone($erej["cracked"],$erej["hashcount"]);
echo "</td><td>";
echo ($erej["description"]=="" ? $erej["hashtype"] : $erej["description"]);
echo "</td><td>";
echo showperc($erej["cracked"],$erej["hashcount"])."%<br>";
echo "(<a href=\"$myself?a=hashes&hashlist=$id&filter=cracked\">".$erej["cracked"]."</a> / <a href=\"$myself?a=hashes&hashlist=$id\">".$erej["hashcount"]."</a>)";
echo "</td><td>";
echo $erej["lists"];
echo "</td>";
echo "<td><form action=\"$myself\" method=\"GET\">";
echo "<input type=\"hidden\" name=\"a\" value=\"hashlistzap\">";
echo "<input type=\"hidden\" name=\"hashlist\" value=\"$id\">";
echo "<input type=\"submit\" value=\"Import\"></form>";
echo "<form action=\"$myself\" method=\"GET\"> ";
echo "<input type=\"hidden\" name=\"a\" value=\"export\">";
echo "<input type=\"hidden\" name=\"hashlist\" value=\"$id\">";
echo "<input type=\"submit\" value=\"Export\"></form></td>";
echo "<td><form action=\"$myself?a=hashlistdelete\" method=\"POST\" onSubmit=\"if (!confirm('Really delete superhashlist $id?\\n(Included hashes will stay intact in their hashlists)')) return false;\">";
echo "<input type=\"hidden\" name=\"return\" value=\"a=superhashlists\">";
echo "<input type=\"hidden\" name=\"hashlist\" value=\"$id\">";
echo "<input type=\"submit\" value=\"Delete\"></form>";
echo "</td></tr>";
}
echo "</table>";
break;
case "releases":
// list hashcat releases
$kver=mysqli_query_wrapper($dblink,"SELECT hashcats.version, hashcats.time, files.filename FROM hashcats LEFT JOIN files ON hashcats.file = files.id ORDER BY time DESC");
echo "List of Hashcat releases (".mysqli_num_rows($kver).")";
echo "<table class=\"styled\">";
echo "<tr><td>Version</td><td>Added</td><td>File</td><td>Action</td></tr>";
while($erej=mysqli_fetch_array($kver,MYSQLI_ASSOC)) {
$ver=$erej["version"];
echo "<tr><td>$ver</td><td>";
if ($erej["time"]>0) {
echo date($config["timefmt"],$erej["time"]);
}
echo "</td><td><a href=\"$filesdir/".$erej["filename"]."\" target=\"_blank\" title=\"Test URL\">".basename($erej["filename"])."</a></td>";
echo "<td><form action=\"$myself?a=releasedelete\" method=\"POST\" onSubmit=\"if (!confirm('Really delete Hashcat release $ver?')) return false;\">";
echo "<input type=\"hidden\" name=\"return\" value=\"a=releases\">";
echo "<input type=\"hidden\" name=\"release\" value=\"$ver\">";
echo "<input type=\"submit\" value=\"Delete\"></form></td></tr>";
}
echo "</table>";
break;
case "files":
// list global files
$kver=mysqli_query_wrapper($dblink,"SELECT files.id,files.filename,files.secret,files.size,IFNULL(taskfiles.tasks,0) AS tasks FROM files LEFT JOIN (SELECT file,COUNT(task) AS tasks FROM taskfiles GROUP BY file) taskfiles ON taskfiles.file=files.id ORDER BY filename ASC");
echo "<script>";
echo "function addLine(tablename) { var table=document.getElementById(tablename); var pos=table.getElementsByTagName('tr').length-1; var row=table.insertRow(pos); var cell=row.insertCell(0); cell.innerHTML= '<input type=\\x22file\\x22 name=\\x22upfile[]\\x22><br>'; } ";
echo $checkall;
echo "</script>";
echo "<table><tr><td>";
echo "Existing files (".mysqli_num_rows($kver)."):";
echo "<table class=\"styled\">";
echo "<tr><td>id</td><td>File</td><td><img src=\"img/lock.gif\" alt=\"Secret\"></td><td>Size</td><td>Used</td><td>Action</td></tr>";
while($erej=mysqli_fetch_array($kver,MYSQLI_ASSOC)) {
$id=$erej["id"];
$fname=$erej["filename"];
echo "<tr><td>$id</td><td><a name=\"$id\" href=\"$filesdir/$fname\" target=\"_blank\">$fname</a>";
if ($erej["secret"]==1) echo " <img src=\"img/lock.gif\" alt=\"Secret\">";
echo "</td>";
echo "<td><form id=\"secret$id\" action=\"$myself?a=filesecret\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"file\" value=\"$id\">";
echo "<input type=\"hidden\" name=\"return\" value=\"a=files#$id\">";
echo "<input type=\"checkbox\" name=\"secret\" value=\"1\"";
if ($erej["secret"]==1) echo " checked";
echo " onChange=\"javascript:document.getElementById('secret$id').submit();\">";
echo "</form></td>";
echo "<td class=\"num\">".nicenum($erej["size"])."B</td>";
echo "<td>".$erej["tasks"]."x</td>";
echo "<td><form action=\"$myself?a=filedelete\" method=\"POST\" onSubmit=\"if (!confirm('Really delete file $fname?')) return false;\">";
echo "<input type=\"hidden\" name=\"return\" value=\"a=files\">";
echo "<input type=\"hidden\" name=\"file\" value=\"$id\">";
echo "<input type=\"submit\" value=\"Delete\"></form></td></tr>";
}
echo "</table></td><td>Add new files:<br>";
echo "<form action=\"$myself?a=filesp\" method=\"POST\" enctype=\"multipart/form-data\">";
echo "<input type=\"hidden\" name=\"source\" value=\"upload\">";
echo "<table class=\"styled\" id=\"upfiles\">";
echo "<tr><td>Upload files <button type=\"button\" onclick=\"javascript:addLine('upfiles');\">Add file</button></td></tr>";
echo "<tr><td><input type=\"submit\" value=\"Upload files\"></td></tr>";
echo "</table>";
echo "</form><br>";
echo "<form id=\"impfiles\" action=\"$myself?a=filesp\" method=\"POST\" enctype=\"multipart/form-data\">";
echo "<input type=\"hidden\" name=\"source\" value=\"import\">";
echo "<table class=\"styled\" id=\"imfiles\">";
echo "<tr><td>Import files</td></tr>";
if (file_exists("import") && is_dir("import")) {
$impdir=opendir("import");
$impfiles=array();
while ($f=readdir($impdir)) {
if (($f!=".") && ($f!="..") && (!is_dir($f))) {
$impfiles[]=$f;
}
}
if (count($impfiles)>0) {
foreach ($impfiles as $impfile) {
echo "<tr><td><input type=\"checkbox\" name=\"imfile[]\" value=\"$impfile\">$impfile (".nicenum(filesize("import/".$impfile))."B)</td></tr>";
}
echo "<tr><td><input type=\"submit\" value=\"Import files\"> <input type=\"checkbox\" onChange=\"javascript:checkAll('impfiles',this.checked);\">Select All</td></tr>";
} else {
echo "<tr><td>'import' directory is empty.</td></tr>";
}
} else {
echo "<tr><td>'import' directory is missing,<br>nowhere to import from!</td></tr>";
}
echo "</td></tr>";
echo "</table>";
echo "</form><br>";
echo "<form action=\"$myself?a=filesp\" method=\"POST\" enctype=\"multipart/form-data\">";
echo "<input type=\"hidden\" name=\"source\" value=\"url\">";
echo "<table class=\"styled\" id=\"upfiles\">";
echo "<tr><td colspan=\"2\">Download URL</td></tr>";
echo "<tr><td>URL:</td><td><input type=\"text\" name=\"url\" size=\"35\"></td></tr>";
echo "<tr><td colspan=\"2\"><input type=\"submit\" value=\"Download file\"></td></tr>";
echo "</table>";
echo "</form>";
echo "</td></tr></table>";
break;
case "filesp":
// add file(s)
$pocetup=0;
$source=$_POST["source"];
if (!file_exists("files")) {
echo "First imported file, creating files subdir...";
if (mkdir("files")) echo "OK";
}
$allok=true;
switch ($source) {
case "upload":
// from http upload
$soubory=$_FILES["upfile"];
$pocet=count($_FILES["upfile"]["name"]);
for($i=0;$i<$pocet;$i++) {
// copy all uploaded attached files to proper directory
$realname=basename($soubory["name"][$i]);
if ($realname=="") continue;
$nsoubor=array();
foreach ($soubory as $klic=>$soubor) {
$nsoubor[$klic]=$soubor[$i];
}
$tmpfile="$filesdir/".$realname;
if (uploadFile($tmpfile,$source,$nsoubor)) {
if (insertFile($tmpfile)) {