forked from keitharm/Wicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.php
526 lines (473 loc) · 18.3 KB
/
setup.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
<?php
// Color Codes
define(W, "\033[0m");
define(R, "\033[31m");
define(G, "\033[32m");
define(O, "\033[33m");
define(B, "\033[34m");
define(P, "\033[35m");
define(C, "\033[36m");
echo "__ ___ _\n";
echo "\ \ / (_) ___| | _____ _ __\n";
echo " \ \ /\ / /| |/ __| |/ / _ \ '__|\n";
echo " \ V V / | | (__| < __/ |\n";
echo " \_/\_/ |_|\___|_|\_\___|_|\n";
echo "Version 1.3.0\n\n";
if ($argv[1] == "--view-config") {
if (file_exists("wicker.conf.php")) {
require_once("Config.class.php");
$config->viewConfig();
die;
} else {
echo R . "Wicker configuration file not found.\n" . W;
die;
}
} else if ($argv[1] == "--view-config-serialized") {
if (file_exists("wicker.conf.php")) {
require_once("Config.class.php");
echo $config->viewConfigSerialized() . "\n";
die;
} else {
echo R . "Wicker configuration file not found.\n" . W;
die;
}
} else if ($argv[1] == "--empty-dirs") {
emptydirs();
echo G . "logs, uploads, and scans have been deleted successfully!\n" . W;
die;
} else if ($argv[1] == "--reset-db") {
resetdb();
die;
} else {
if (isset($argv[1])) {
echo R . "Invalid argument\n" . W . "Available options are:\n" . G . "--view-config" . W . "\n" . G . "--empty-dirs" . W . "\n" . G . "--reset-db" . W . "\n" . G . "--view-config-serialized" . W . "\n";
die;
}
}
// Check for configuration file.
if (file_exists("wicker.conf.php")) {
echo O . "Warning" . W . ": There already appears to be a Wicker configuration file.\nIf you continue with the setup, the configuration file will be overwritten.\nYou may view your current configuration by typing " . G . "php setup.php --view-config" . W . ".\n\n" . W;
}
// Check if Wicker configuration file is corrupt.
$config_raw = @file_get_contents("wicker.conf.php");
$lines = explode("\n", $config_raw);
if (count($lines) != 5 && file_exists("wicker.conf.php")) {
echo R . "Error" . W . ": Wicker configuration file appears to be corrupt!\n\n";
}
// Perform dependencies check
checkForDependencies();
echo "\nWelcome to the Wicker Setup script.\n\n";
echo "This script will help you configure all of Wicker's settings.\n";
echo "If you wish to keep the default settings (the value between [ ]),\nkeep your answer blank.\n\n";
// Database
echo "=====" . C . " Database Connection " . W . "=====\n";
$database = false;
do {
echo W . "Database URL [localhost]:\t";
$data["database"]["url"] = input("localhost");
echo W . "Database name:\t\t\t";
$data["database"]["name"] = input();
echo W . "Database username:\t\t";
$data["database"]["username"] = input();
echo W . "Database password:\t\t";
$data["database"]["password"] = input();
echo W . "Attempting to connect to MySQL Server...\n";
$database = connectToDatabase();
if ($database == true) {
echo "Are these settings ok?\t\t";
if (!in_array(strtolower(input()), array("yes", "y"))) {
$database = false;
}
}
} while ($database == false);
echo W . "=====" . C . " Database Setup " . W . "=====\n";
// if true, ask if you want to import tables else ask if you want to create database and import tables.
setupDatabase();
// Webserver user
echo W . "\n=====" . C . " Webserver User " . W . "=====\n";
$webserver = false;
do {
echo W . "Webserver User:\t\t\t";
$data["webserver"]["user"] = input();
echo W . "Are these settings ok?\t\t";
if (!in_array(strtolower(input()), array("yes", "y"))) {
$webserver = false;
} else {
$webserver = true;
}
} while ($webserver == false);
// Wireless
echo W . "\n=====" . C . " Wireless " . W . "=====\n";
$wireless = false;
$rfkill = false;
do {
do {
echo W . "Does rfkill block your wifi card? [true]:\t";
$data["wireless"]["rfkill"] = strtolower(input("true"));
if (in_array($data["wireless"]["rfkill"], array("true", "false", "yes", "no", "y", "n"))) {
$rfkill = true;
if (in_array($data["wireless"]["rfkill"], array("true", "yes", "y"))) {
$data["wireless"]["rfkill"] = "true";
} else {
$data["wireless"]["rfkill"] = "false";
}
}
} while ($rfkill == false);
echo W . "Wireless interface to use [wlan0]:\t\t";
$data["wireless"]["interface"] = input("wlan0");
echo W . "Are these settings ok?\t\t\t\t";
if (!in_array(strtolower(input()), array("yes", "y"))) {
$wireless = false;
} else {
$wireless = true;
}
} while ($wireless == false);
// Tools
echo W . "\n=====" . C . " Tools " . W . "=====\n";
$tools = false;
do {
echo W . "airodump-ng location? [" . exec("which airodump-ng") . "]:\t";
$data["tools"]["airodump-ng"] = input(exec("which airodump-ng"));
echo W . "pyrit location? [" . exec("which pyrit") . "]:\t";
$data["tools"]["pyrit"] = input(exec("which pyrit"));
echo W . "pcapfix location? [" . exec("which pcapfix") . "]:\t";
$data["tools"]["pcapfix"] = input(exec("which pcapfix"));
echo W . "mysql location? [" . exec("which mysql") . "]:\t";
$data["tools"]["mysql"] = input(exec("which mysql"));
echo W . "lm-sensors location? [" . exec("which sensors") . "]:\t";
$data["tools"]["lm-sensors"] = input(exec("which sensors"));
echo W . "Are these settings ok?\t\t";
if (!in_array(strtolower(input()), array("yes", "y"))) {
$tools = false;
} else {
$tools = true;
}
} while ($tools == false);
// Set up directories for Wicker
echo W . "\n=====" . C . " Initial Directory Setup " . W . "=====\n";
echo "Creating directories\n";
echo "logs";
pause(false);
@mkdir("logs");
echo G . "done\n" . W;
echo "scans";
pause(false);
@mkdir("scans");
echo G . "done\n" . W;
echo "uploads";
pause(false);
@mkdir("uploads");
echo G . "done\n\n" . W;
echo "Setting up permissions for web user\n";
echo "Setting " . $data["webserver"]["user"] . " as group for directories";
pause(false);
exec("sudo chgrp " . $data["webserver"]["user"] . " logs scans uploads");
echo G . "done\n" . W;
echo "Setting permissions to 775 for directories";
pause(false);
exec("sudo chmod 775 logs scans uploads");
echo G . "done\n" . W;
echo "Setting group bit for directories";
pause(false);
exec("sudo chmod g+s logs scans uploads");
echo G . "done\n" . W;
// Generate conf file
echo W . "\nGenerating Wicker Configuration file";
pause();
file_put_contents("wicker.conf.php", "<?php\ndie;\n#" . serialize($data) . "\n?>\n");
if (!file_exists("wicker.conf.php")) {
file_put_contents("/tmp/wicker.conf.php", "<?php\ndie;\n#" . serialize($data) . "\n?>\n");
echo R . "Error" . W . ": Unable to save configuration file.\nPlease copy file /tmp/wicker.conf.php to this directory manually to complete setup.\n";
} else {
echo G . "\nWicker Configuration file saved successfully!\n" . W;
}
echo "Setting group to " . $data["webserver"]["user"] . " for Wicker Configuration File";
pause(false);
exec("sudo chgrp " . $data["webserver"]["user"] . " wicker.conf.php");
echo G . "done\n" . W;
echo "Setting permissions to 664 for Wicker Configuration File";
pause(false);
exec("sudo chmod 664 wicker.conf.php");
echo G . "done\n\n" . W;
echo G . "Wicker Setup Complete!\n" . W;
function input($default = null) {
echo O;
$var = trim(fgets(STDIN));
if ($var == null) {
return $default;
} else {
return $var;
}
}
function connectToDatabase() {
global $data;
sleep(1);
try {
$dbh = new PDO('mysql:host=' . $data["database"]["url"], $data["database"]["username"], $data["database"]["password"], array(PDO::ATTR_TIMEOUT => "3"));
echo G . "Connection successful!" . W . "\n\n";
return true;
} catch (PDOException $e) {
echo R . "Unable to connect to server!" . W . "\n\n";
return false;
}
}
function setupDatabase() {
global $data;
echo "Checking if database exists";
pause();
$dbh = new PDO('mysql:host=' . $data["database"]["url"] . ';dbname=INFORMATION_SCHEMA', $data["database"]["username"], $data["database"]["password"], array(PDO::ATTR_TIMEOUT => "3"));
// Check if database exists
$query = $dbh->query("SELECT * FROM `SCHEMATA` WHERE `SCHEMA_NAME` = '" . $data["database"]["name"] . "'");
if ($query->rowCount() == 0) {
echo R . "Database was not found (or your credentials don't have valid permissions)\n\n" . W;
$found = false;
} else {
echo G . "Database was found\n\n" . W;
$found = true;
}
if ($found) {
// Check for tables
echo "Checking tables";
pause();
$dbh = new PDO('mysql:host=' . $data["database"]["url"] . ';dbname=' . $data["database"]["name"], $data["database"]["username"], $data["database"]["password"], array(PDO::ATTR_TIMEOUT => "3"));
$query = $dbh->query("show tables");
while ($results = $query->fetch()) {
$tables[] = $results[0];
}
if ($tables == null) {
echo G . "Database is empty" . W . "\n";
importWickerTables(0, 0);
} else {
echo O . "Database is occupied" . W . "\n\n";
echo "Listing tables in database.\n" . G . "Green" . W . " = Wicker tables\n" . R . "Red " . W . " = Other tables\n----------\n";
$good = 0; $bad = 0;
foreach ($tables as $table) {
if (in_array($table, array("aps", "attacks", "caps", "clients", "scans"))) {
echo G . $table . W . "\n";
$good++;
} else {
echo R . $table . W . "\n";
$bad++;
}
}
echo "----------\n";
importWickerTables($good, $bad);
}
print_r($results);
} else {
$dbh = new PDO('mysql:host=' . $data["database"]["url"], $data["database"]["username"], $data["database"]["password"], array(PDO::ATTR_TIMEOUT => "3"));
echo "Attemping to create database";
pause();
$dbh->query("CREATE DATABASE IF NOT EXISTS " . $data["database"]["name"]);
if ($dbh->errorCode() != "00000") {
echo R . "An error has occured while attempting to create the database.\nPlease verify that the credentials supplied have valid database creation permissions." . W . "\n";
die;
} else {
echo G . "Database " . O . $data["database"]["name"] . G . " was created successfully!" . W . "\n";
}
// Import tables
importWickerTables(0, 0);
}
}
function checkForDependencies() {
$bad = false;
echo "Performing dependencies check\n";
// Check for PDO
if (!defined('PDO::ATTR_DRIVER_NAME')) {
echo R . "✗ PDO\n" . W;
$bad = true;
} else {
echo G . "✓ PDO\n" . W;
}
usleep(250000);
// Check for Pyrit
if (!command_exist("pyrit")) {
echo R . "✗ Pyrit\n" . W;
$bad = true;
} else {
echo G . "✓ Pyrit\n" . W;
}
usleep(250000);
// Check for Airodump-ng
if (!command_exist("airodump-ng")) {
echo R . "✗ Airodump-ng\n" . W;
$bad = true;
} else {
echo G . "✓ Airodump-ng\n" . W;
}
usleep(250000);
// Check for Pyrit
if (!command_exist("pcapfix")) {
echo R . "✗ Pcapfix\n" . W;
$bad = true;
} else {
echo G . "✓ Pcapfix\n" . W;
}
usleep(250000);
// Check for MySQL
if (!command_exist("mysql")) {
echo O . "✗ MySQL\n" . W;
$bad = true;
} else {
echo G . "✓ MySQL\n" . W;
}
usleep(250000);
// Check for lm-sensrs
if (!command_exist("sensors")) {
echo O . "- lm-sensors\n" . W;
$sensors = false;
} else {
echo G . "✓ lm-sensors\n" . W;
$sensors = true;
}
usleep(250000);
if ($bad) {
echo R . "Error" . W . ": Your system is missing some dependencies that Wicker...depends on.\nPlease install the missing dependencies before attempting setup again.\n";
die;
} else {
if (!$sensors) {
echo W . "Warning" . W . ": lm-sensors is not required but it provides temperature information for your CPU.\n";
}
echo "\n" . G . "Everything looks good :)\n" . W;
}
}
function command_exist($cmd) {
$returnVal = shell_exec("which $cmd");
return (empty($returnVal) ? false : true);
}
function pause($return = true) {
echo ".";
usleep(250000);
echo ".";
usleep(250000);
echo ".";
usleep(250000);
if ($return) {
echo "\n";
}
}
function importWickerTables($good, $bad) {
global $data;
echo W . "=====" . C . " Database Setup " . W . "=====\n";
if ($good == 5) {
$table = false;
do {
echo W . "There already appear to be Wicker tables in this database.\nWhat would you like to do?\n\n";
echo "(" . O . "D" . W . ")rop tables and import latest Wicker table structure.\n";
echo "(" . O . "C" . W . ")ontinue without modifying tables.\n";
echo "Choice: ";
$choice = input();
if (in_array(strtolower($choice), array('c', 'd'))) {
$table = true;
}
} while ($table == false);
if (strtolower($choice) == "c") {
echo W . "Continuing without modifying tables.\n";
return;
} else {
echo W . "Dropping old tables";
pause();
$dbh = new PDO('mysql:host=' . $data["database"]["url"] . ';dbname=' . $data["database"]["name"], $data["database"]["username"], $data["database"]["password"], array(PDO::ATTR_TIMEOUT => "3"));
//"aps", "attacks", "caps", "clients", "scans"
$dbh->query("DROP TABLE `aps`, `attacks`, `caps`, `clients`, `scans`");
if ($dbh->errorCode() != "00000") {
echo R . "An error has occured while attempting to drop old Wicker tables.\nPlease verify that the credentials supplied have valid database permissions." . W . "\n";
die;
}
echo W . "Importing new Wicker tables";
pause();
exec("mysql -u " . $data["database"]["username"] . " -p" . $data["database"]["password"] . " -D " . $data["database"]["name"] . " < sql/wicker.sql", $output, $code);
if ($code != 0) {
echo R . "An error has occured while attempting to import new Wicker tables.\nPlease verify that the credentials supplied have valid database permissions." . W . "\n";
die;
} else {
echo G . "Wicker tables imported successfully!\n";
}
return;
}
//Database is empty
} else if ($good == 0 && $bad == 0) {
echo W . "Importing Wicker tables";
pause();
exec("mysql -u " . $data["database"]["username"] . " -p" . $data["database"]["password"] . " -D " . $data["database"]["name"] . " < sql/wicker.sql", $output, $code);
if ($code != 0) {
echo R . "An error has occured while attempting to import new Wicker tables.\nPlease verify that the credentials supplied have valid database permissions." . W . "\n";
die;
} else {
echo G . "Wicker tables imported successfully!\n";
}
return;
} else {
echo W . "Something weird happened\n";
die;
}
}
function emptydirs() {
exec("rm -rf logs/* 2>/dev/null");
exec("rm -rf uploads/* 2>/dev/null");
exec("rm -rf scans/* 2>/dev/null");
}
function resetdb() {
global $data;
require_once("Config.class.php");
$data["database"]["url"] = $config->getDBURL();
$data["database"]["username"] = $config->getDBUser();
$data["database"]["password"] = $config->getDBPass();
$data["database"]["name"] = $config->getDBName();
echo "Checking if database exists";
pause();
$dbh = new PDO('mysql:host=' . $data["database"]["url"] . ';dbname=INFORMATION_SCHEMA', $data["database"]["username"], $data["database"]["password"], array(PDO::ATTR_TIMEOUT => "3"));
// Check if database exists
$query = $dbh->query("SELECT * FROM `SCHEMATA` WHERE `SCHEMA_NAME` = '" . $data["database"]["name"] . "'");
if ($query->rowCount() == 0) {
echo R . "Database was not found (or your credentials don't have valid permissions)\n\n" . W;
$found = false;
} else {
echo G . "Database was found\n\n" . W;
$found = true;
}
if ($found) {
// Check for tables
echo "Checking tables";
pause();
$dbh = new PDO('mysql:host=' . $data["database"]["url"] . ';dbname=' . $data["database"]["name"], $data["database"]["username"], $data["database"]["password"], array(PDO::ATTR_TIMEOUT => "3"));
$query = $dbh->query("show tables");
while ($results = $query->fetch()) {
$tables[] = $results[0];
}
if ($tables == null) {
echo G . "Database is empty" . W . "\n";
importWickerTables(0, 0);
} else {
echo O . "Database is occupied" . W . "\n\n";
echo "Listing tables in database.\n" . G . "Green" . W . " = Wicker tables\n" . R . "Red " . W . " = Other tables\n----------\n";
$good = 0; $bad = 0;
foreach ($tables as $table) {
if (in_array($table, array("aps", "attacks", "caps", "clients", "scans"))) {
echo G . $table . W . "\n";
$good++;
} else {
echo R . $table . W . "\n";
$bad++;
}
}
echo "----------\n";
importWickerTables($good, $bad);
}
print_r($results);
} else {
$dbh = new PDO('mysql:host=' . $data["database"]["url"], $data["database"]["username"], $data["database"]["password"], array(PDO::ATTR_TIMEOUT => "3"));
echo "Attemping to create database";
pause();
$dbh->query("CREATE DATABASE IF NOT EXISTS " . $data["database"]["name"]);
if ($dbh->errorCode() != "00000") {
echo R . "An error has occured while attempting to create the database.\nPlease verify that the credentials supplied have valid database creation permissions." . W . "\n";
die;
} else {
echo G . "Database " . O . $data["database"]["name"] . G . " was created successfully!" . W . "\n";
}
// Import tables
importWickerTables(0, 0);
}
}
?>