/
JusticeMenu.php
346 lines (312 loc) · 12.3 KB
/
JusticeMenu.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
<?php
/////////////
//
// Cryptolingus Cracking Suite (CLCS) version 1.1
//
// Modified: 2014-09-27
// Unit: Justice
// File: JusticeMenu.php
//
// Description: Displays the control menu for the Justice unit
//
////////////
include 'Resources/CLCommon/CLCS_Common.php';
///////////////////////////////////////////////////////////////////////////////////////////
// Function name: runMenu
// Inputs: CLCSConfiguration $justiceConfig
// Returns: null
// Description: Displays the control panel
function runMenu($justiceConfig) {
$UserChoice = "I";
$TgtCH = "localhost";
while ($UserChoice <> "X") {
clearScreen();
echo "+-------------------------------------------------------------------------+\n";
echo "| |\n";
echo "| Cryptolingus Cracking Suite (CLCS) - JUSTICE |\n";
echo "| |\n";
echo "+-------------------------------------------------------------------------+\n";
echo "\n";
echo "Current Courthouse: " . $TgtCH . "\n";
echo "\n";
echo "Commands:\n";
echo "---------\n";
echo "[W] Load wordlist\n";
echo "[T] Load targets\n";
echo "\n";
echo "[V] View status\n";
echo "[Q] Query Courthouses\n";
echo "[S] Sync Courthouses\n";
echo "\n";
echo "[C] Show configuration\n";
echo "[I] Initiate/Reset Database\n";
echo "[A] Add Courthouse\n";
echo "[K] Shutdown Courthouse\n";
echo "[X] Exit Justice\n";
echo"\n";
echo "\n";
$UserChoice = getUserInput("Choice:", TRUE);
switch($UserChoice) {
case 'A':
addCourthouse($justiceConfig);
break;
case 'I':
initializeJustice($justiceConfig);
break;
case 'K':
$TargetCourthouse = chooseCourthouse();
stopCourthouse($TargetCourthouse);
userAck();
break;
case 'Q':
updateFromCourthouses($justiceConfig);
break;
case 'C':
$justiceConfig->showAllSettings();
userAck();
break;
case 'T':
loadTargets(FALSE, "Justice", $justiceConfig);
userAck();
break;
case 'V':
showJusticeStatus($justiceConfig);
break;
case 'W':
loadWordlist(FALSE, "Justice", $justiceConfig);
userAck();
break;
case 'X':
break;
case 'S':
updateFromCourthouses($justiceConfig);
updateAllCourthouses($justiceConfig);
break;
default:
showError();
break;
}
}
}
//
// END runMenu
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Function name: addCourthouse
// Inputs: CLCSConfiguration $jConfig (A CLCSConfiguration object to allow connections to the database)
// Returns: null
// Description: Add a courthouse to be controlled by this Justice unit
function addCourthouse($jConfig) {
$chAddress = getUserInput("New address (FQDN or IP address):");
$chPort = getUserInput("Port:");
$chUsername = getUserInput("Username:");
$chPassword = getUserInput("Password:");
$sqlAddCourthouse = "INSERT INTO Courthouses (`address`, `port`, `username`, `userpass` ) VALUES ('" . $chAddress . "', '" . $chPort . "', '" . $chUsername . "', '" . $chPassword . "' );";
$dbCon = connectTo($jConfig, "Justice", TRUE, FALSE);
if ($dbCon->query($sqlAddCourthouse)) {
echo "Courthouse added!\n";
}
userAck();
}
//
// END addCourthouse
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Function name: chooseCourthouse
// Inputs: null
// Returns: String containing the user Courthouse selection
// Description: STUB Select a courthouse
function chooseCourthouse() {
$newCH = getUserInput("What Courthouse would you like to interface with?");
return $newCH;
}
//
// END chooseCourthouse
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Function name: configureCLCS
// Inputs: null
// Returns: null
// Description: Generate new crypto for Justice
function configureCLCS() {
if (getUserInput("Generate new key material? ") == "Y") {
generateCrypto("host", "justice");
}
sleep(2);
}
//
// END configureCLCS
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Function name: initializeJustice
// Inputs: CLCSConfiguration $jConfig (A CLCSConfiguration object containing the database connection information)
// Returns: null
// Description: Reset the database, read in wordlists and targets (if so desired)
function initializeJustice($jConfig) {
resetCLCSdb("Justice", $jConfig);
$processTargetsDirectory = getUserInput("Process the targets directory to load targets [Y/N]?", TRUE);
if ($processTargetsDirectory == "Y") {
loadTargets(TRUE, "Justice", $jConfig);
}
$processWordlistsDirectory = getUserInput("Process the wordlists directory to load wordlists [Y/N]?", TRUE);
if ($processWordlistsDirectory == "Y") {
loadWordlist(TRUE, "Justice", $jConfig);
}
userAck();
}
//
// END initializeJustice
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Function name: showJusticeStatus
// Inputs: CLCSConfiguration $jConfig (A CLCSConfiguration object containing the database connection information)
// Returns: null
// Description: Show status of cracking efforts
function showJusticeStatus($jConfig) {
$dbCon = connectTo($jConfig, "Justice", TRUE, FALSE);
$tempSolvedResult = $dbCon->query("SELECT COUNT(*) FROM Justice.Targets WHERE `isbenchmark`=false AND `cleartext_value` IS NOT NULL");
$tempSolved = $tempSolvedResult->fetch_row();
if (is_null($tempSolved)) {
$resSolved = 0;
} else {
$resSolved = $tempSolved[0];
}
$tempSolvedResult->close();
$tempTotalResult = $dbCon->query("SELECT COUNT(*) FROM Justice.Targets WHERE `isbenchmark`=false");
$tempTotal = $tempTotalResult->fetch_row();
if (is_null($tempTotal)) {
$resTotal = 0;
} else {
$resTotal = $tempTotal[0];
}
$tempTotalResult->close();
if ($resTotal == 0) {
echo "There are no targets defined. Perhaps you should add some?\n";
} else {
$resPercent = 100 * ( floatval($resSolved) / floatval($resTotal) );
echo "There are currently $resSolved / $resTotal ($resPercent %) cracked.\n";
}
$dbCon->close();
userAck();
}
//
// END showJusticeStatus
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Function name: stopCourthouse
// Inputs: String $tgtCourthouse (The courthouse to be stopped)
// Returns: null
// Description: STUB Stop a courthouse
function stopCourthouse($tgtCourthouse) {
echo "Stopping Courthouse: $tgtCourthouse\n";
sleep(2);
}
//
// END stopCourthouse
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Function name: updateAllCourthouses
// Inputs: CLCSConfiguration $jConfig (A CLCSConfiguration object containing the database connection information)
// Returns: null
// Description: Push wordlists and targets to all Courthouses
function updateAllCourthouses($jconfig) {
$dbCon = connectTo($jconfig, "Justice", TRUE, FALSE);
$sqlAllCourthouses = "SELECT `address`,`port`,`username`,`userpass` FROM Courthouses;";
$allCH = $dbCon->query($sqlAllCourthouses);
$sqlAllWords = "SELECT * from Words ORDER BY `id`;";
echo "Retrieving all words...\n";
$allWords = $dbCon->query($sqlAllWords);
// Convert the words to a suitable insertion statement
$sqlInsertWords = "INSERT IGNORE INTO `Words` (`id`, `word`) VALUES ";
while ($wordRecord = $allWords->fetch_row()) {
$wid = $wordRecord[0];
$word = $wordRecord[1];
$sqlInsertWords .= "( '" . $wid . "', '" . $word . "' ),";
}
$sqlInsertWords = substr($sqlInsertWords, 0, -1) . ";";
$sqlAllTargets = "SELECT * from `Targets` ORDER BY `id`;";
echo "Retrieving all unsolved targets...\n";
$allTargets = $dbCon->query($sqlAllTargets);
// Convert the targets to a suitable insertion statement
$sqlInsertTargets = "TRUNCATE TABLE `Targets`; INSERT IGNORE INTO `Targets` (`id`, `ishash`, `isbenchmark`, `hashtype_id`, `hash_value`, `confidence` ) VALUES ";
while ($targetRecord = $allTargets->fetch_row()) {
if (is_null($targetRecord[5])) {
$tID = $targetRecord[0];
$tIH = $targetRecord[1];
$tBM = $targetRecord[2];
$tHI = $targetRecord[3];
$tHV = $targetRecord[4];
$tCF = $targetRecord[6];
$sqlInsertTargets .= "( '" . $tID . "', '" . $tIH . "', '" . $tBM . "', '" . $tHI . "', '" . $tHV . "', '" . $tCF . "' ),";
}
}
$sqlInsertTargets = substr($sqlInsertTargets, 0, -1) . ";";
while ($chRecord = $allCH->fetch_row()) {
$chAddress = $chRecord[0];
$chPort = $chRecord[1];
$chUser = $chRecord[2];
$chPass = $chRecord[3];
$chCon = connectManual($chAddress, $chUser, $chPort, $chPass, "Courthouse", FALSE);
echo "Pushing updated wordlist to " . $chAddress . ":" . $chPort . "\n";
$pushWords = $chCon->query($sqlInsertWords);
echo "Pushing updated targets to " . $chAddress . ":" . $chPort . "\n";
$pushTargets = $chCon->multi_query($sqlInsertTargets);
$chCon->close();
}
$dbCon->close();
userAck();
}
//
// END updateAllCourthouses
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Function name: updateFromCourthouses
// Inputs: CLCSConfiguration $jConfig (A CLCSConfiguration object containing the database connection information)
// Returns: null
// Description: Pull results back form all Courthouses
function updateFromCourthouses($jConfig) {
$dbCon = connectTo($jConfig, "Justice", TRUE, FALSE);
$sqlAllCourthouses="SELECT `address`,`port`,`username`,`userpass` FROM Courthouses;";
$allCH = $dbCon->query($sqlAllCourthouses);
$sqlSolvedTargets="SELECT `hash_value`,`cleartext_value` FROM Targets WHERE `isbenchmark`=false and `cleartext_value` IS NOT NULL;";
$solutions = array();
while ($chRecord = $allCH->fetch_row()) {
$chAddress = $chRecord[0];
$chPort = $chRecord[1];
$chUser = $chRecord[2];
$chPass = $chRecord[3];
$chCon = connectManual($chAddress, $chUser, $chPort, $chPass, "Courthouse", FALSE);
$solvedTargets = $chCon->query($sqlSolvedTargets);
while ($targetSolution = $solvedTargets->fetch_row()) {
$hVal = $targetSolution[0];
$cVal = $targetSolution[1];
$solutions[$hVal] = $cVal;
}
$solvedTargets->close();
}
$chCon->close();
$numSolved = count($solutions);
echo "Found " . $numSolved . " new solutions across all Courthouses.\n";
if ($numSolved) {
$sqlSolutions = "";
foreach ($solutions as $key=>$value) {
$sqlSolutions .= "UPDATE `Targets` SET `cleartext_value`='". $value . "', `confidence`=100 WHERE `hash_value` = '" . $key . "';";
}
$dbCon->multi_query($sqlSolutions);
$dbCon->close();
} else {
$dbCon->close();
}
sleep(1);
}
//
// END updateFromCourthouses
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// //
// Main program execution //
// //
///////////////////////////////////////////////////////////////////////////////////////////
$cfg_file = new CLCSConfiguration("Justice");
runMenu($cfg_file);
?>