-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAttack.class.php
More file actions
170 lines (150 loc) · 6.38 KB
/
Attack.class.php
File metadata and controls
170 lines (150 loc) · 6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/*
status
0 = null
1 = cracking
2 = failed
3 = success
4 = terminated
5 = paused
*/
require_once("Wicker.php");
Class Attack
{
private $id;
private $cap_id;
private $attack;
private $status;
private $status_text;
private $password;
private $tmpfile;
private $runtime;
private $current;
private $rate;
private $auth;
private $pid;
private $name = array("10k top passwords (fixed)", "rockyou", "small", "Custom-WPA", "Super-WPA", "big", "bigger", "combined", "eight");
private $size = array(4139, 9605415, 46836902, 109605684, 582620889, 648418381, 915103913, 1623275482, 360747463);
private $statusName = array("-", "<font color='purple'>Cracking</font>", "<font color='red'>Failed</font>", "<font color='green'>Success</font>", "<font color='orange'>Terminated</font>", "<font color='blue'>Paused</font>");
public $db;
public static function fromDB($id, $attack = 1) {
global $wicker;
$instance = new self();
$instance->connectToDatabase();
$statement = $wicker->db->con()->prepare("SELECT * FROM attacks WHERE cap_id = ? AND attack = ?");
$statement->execute(array($id, $attack));
$info = $statement->fetchObject();
$instance->id = $info->id;
$instance->cap_id = $info->cap_id;
$instance->attack = $info->attack;
$instance->status = $info->status;
$instance->status_text = $info->status_text;
$instance->password = $info->password;
$instance->tmpfile = $info->tmpfile;
$instance->runtime = $info->runtime;
$instance->current = $info->current;
$instance->rate = $info->rate;
$instance->auth = $info->auth;
$instance->pid = $info->pid;
return $instance;
}
private function connectToDatabase() {
$database = new Database;
$this->db = $database;
}
private function setVal($field, $val) {
$statement = $this->db->con()->prepare("UPDATE `attacks` SET `$field` = ? WHERE `id` = ?");
$statement->execute(array($val, $this->getID()));
}
public function updateData() {
if ($this->getStatus() != 2 && $this->getStatus() != 3) {
$this->calculateCurrentKey();
$this->updateStatus();
$this->updateRuntime();
$this->calculateRate();
}
}
private function updateStatus() {
exec("ps " . $this->getPID(), $status);
if (isset($status[1])) {
$this->setStatusText("<font color='green'>Yes</font>");
} else {
$this->setStatusText("<font color='red'>No</font>");
}
// Update status code to failed or success if cracked once the PID isn't running anymore
$this->wasCracked();
}
private function wasCracked() {
global $wicker;
$log = file_get_contents("logs/" . $this->getTmpfile());
$keys = $wicker->extractData(substr($log, -1500), "The password is '", "'.");
if ($keys != null) {
$this->setStatus(3);
$this->setPassword($keys);
} else {
if ($this->getStatus() == 1 && $this->getStatusText() == "<font color='red'>No</font>") {
$this->setStatus(2);
$this->setCurrent($this->size[$this->getAttack()-1]);
$this->setPassword("");
}
}
}
private function updateRuntime() {
exec("ps -o time " . $this->getPID(), $runtime);
if (isset($runtime[1])) {
$ex = explode(":", $runtime[1]);
$secs = $ex[0]*3600 + $ex[1]*60 + $ex[2];
$this->setRuntime(gmdate("H:i:s", round($secs/4, 0)));
} else {
if ($this->getStatus() == 0) {
$this->setRuntime("00:00:00");
}
}
}
public function terminate() {
$this->updateData();
$this->setStatus(4);
posix_kill($this->getPID(), 9);
}
public function calculateCurrentKey() {
global $wicker;
$log = file_get_contents("logs/" . $this->getTmpfile());
$keys = $wicker->extractData(substr($log, -1500), "Tried ", " PMKs so");
$current_keys = $keys[count($keys)-1];
$this->setCurrent($current_keys);
}
public function calculateRate() {
global $wicker;
$log = file_get_contents("logs/" . $this->getTmpfile());
$rate = $wicker->extractData(substr($log, -1500), "far; ", " PMKs per");
$rate = $rate[count($rate)-1];
if($this->getStatus() == 1)
$this->setRate($rate);
else
$this->setRate(0);
}
public function getID() { return $this->id; }
public function getCapID() { return $this->cap_id; }
public function getAttack() { return $this->attack; }
public function getStatus() { return $this->status; }
public function getStatusText() { return $this->status_text; }
public function getPassword() { return CapFile::fromDB($this->cap_id)->getPassword(); }
public function getTmpfile() { return $this->tmpfile; }
public function getRuntime() { return $this->runtime; }
public function getAttackName() { return $this->name[$this->attack-1]; }
public function getDictionarySize() { return $this->size[$this->attack-1]; }
public function getCurrent() { return $this->current; }
public function getRate() { return $this->rate; }
public function getAuth() { return $this->auth; }
public function getPID() { return $this->pid; }
public function setAuth($val) { $this->setVal("auth", $val); $this->auth = $val; }
public function setRate($val) { $this->setVal("rate", $val); $this->rate = $val; }
public function setCurrent($val) { $this->setVal("current", $val); $this->current = $val; }
public function setRuntime($val) { $this->setVal("runtime", $val); $this->runtime = $val; }
public function setTmpfile($val) { $this->setVal("tmpfile", $val); $this->tmpfile = $val; }
public function setStatus($val) { $this->setVal("status", $val); $this->status = $val; }
public function setStatusText($val) { $this->setVal("status_text", $val); $this->status_text = $val; }
public function setPassword($val) { CapFile::fromDB($this->cap_id)->setPassword($val); }
public function setPID($val) { $this->setVal("pid", $val); $this->pid = $val; }
public function getStatusName() { return $this->statusName[$this->getStatus()]; }
}