-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCapFile.class.php
More file actions
151 lines (126 loc) · 5.25 KB
/
CapFile.class.php
File metadata and controls
151 lines (126 loc) · 5.25 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
<?php
require_once("Wicker.php");
Class CapFile
{
private $id;
private $location;
private $repaired;
private $raw;
private $checksum;
private $complete;
private $runtime;
private $status;
private $password;
private $bssid;
private $essid;
private $packets;
private $size;
private $timestamp;
public $db;
public static function import($location) {
$instance = new self();
$instance->connectToDatabase();
$instance->location = $location;
// Fix pcap file if it needs to be repaired
$instance->fixCap();
// Analyze pcap file and extract info from it
$instance->analyzeCap();
// Insert record into DB
$instance->addToDB();
// Generate attack records
$instance->generateAttackRecords();
return $instance;
}
public static function fromDB($id) {
global $wicker;
$instance = new self();
$instance->connectToDatabase();
if (substr($id, 0, 3) == "[C]") {
$id = substr($id, 3);
$statement = $wicker->db->con()->prepare("SELECT * FROM `caps` WHERE `checksum` = ?");
} else {
$statement = $wicker->db->con()->prepare("SELECT * FROM `caps` WHERE `id` = ?");
}
$statement->execute(array($id));
$info = $statement->fetchObject();
$instance->id = $info->id;
$instance->location = $info->location;
$instance->repaired = $info->repaired;
$instance->raw = $info->raw;
$instance->checksum = $info->checksum;
$instance->complete = $info->complete;
$instance->runtime = $info->runtime;
$instance->status = $info->status;
$instance->password = $info->password;
$instance->timestamp = $info->timestamp;
$instance->size = $info->size;
$instance->bssid = $info->bssid;
$instance->essid = $info->essid;
$instance->packets = $info->packets;
return $instance;
}
private function connectToDatabase() {
$database = new Database;
$this->db = $database;
}
private function fixCap() {
global $wicker;
$this->changeToUploads();
shell_exec($wicker->config->getPCAPFix() . " " . $this->location);
if (file_exists("fixed_" . $this->location)) {
$this->location = "fixed_" . $this->location;
$this->repaired = true;
} else {
$this->repaired = false;
}
}
private function analyzeCap() {
global $wicker;
$this->changeToUploads();
$this->raw = shell_exec($wicker->config->getPyrit() . " -r " . $this->location . " analyze");
$this->bssid = $wicker->extractData($this->raw, "AccessPoint ", " ('");
$this->essid = $wicker->extractData($this->raw, "('", "'):");
$this->packets = $wicker->extractData($this->raw, "Parsed ", " packets");
$this->checksum = md5(file_get_contents($this->location));
$this->size = filesize($this->location);
}
private function addToDB() {
global $wicker;
// Check if this is a duplicate
if (!$wicker->doesExist("caps", "checksum", $this->checksum)) {
$statement = $this->db->con()->prepare("INSERT INTO `caps` (`essid`, `bssid`, `checksum`, `location`, `raw`, `packets`, `size`, `timestamp`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$statement->execute(array($this->essid, $this->bssid, $this->checksum, $this->location, $this->raw, $this->packets, $this->size, time()));
} else {
$cap = CapFile::fromDB("[C]" . $this->checksum);
$wicker->error("This Cap File was imported " . $wicker->timeconv($cap->getTimestamp()) . ".", "Cap file hash: " . $this->checksum);
}
}
private function changeToUploads() {
if (basename(getcwd()) != "uploads") {
chdir("uploads");
}
}
private function generateAttackRecords() {
$cap = CapFile::fromDB("[C]" . $this->getChecksum());
for ($a = 1; $a <= 9; $a++) {
$statement = $this->db->con()->prepare("INSERT INTO `attacks` (`cap_id`, `attack`) VALUES (?, ?)");
$statement->execute(array($cap->getID(), $a));
}
}
private function setVal($field, $val) {
$statement = $this->db->con()->prepare("UPDATE `caps` SET `$field` = ? WHERE `id` = ?");
$statement->execute(array($val, $this->getID()));
}
public function getTimestamp() { return $this->timestamp; }
public function getLocation() { return $this->location; }
public function getID() { return $this->id; }
public function getChecksum() { return $this->checksum; }
public function getESSID() { return $this->essid; }
public function getBSSID() { return $this->bssid; }
public function getPackets() { return $this->packets; }
public function getSize() { return $this->size; }
public function getStatus() { return $this->status; }
public function getPassword() { return $this->password; }
public function setStatus($val) { $this->setVal("status", $val); $this->status = $val; }
public function setPassword($val) { $this->setVal("password", $val); $this->password = $val; }
}