-
Notifications
You must be signed in to change notification settings - Fork 0
/
aircrack.cpp
executable file
·196 lines (148 loc) · 5.32 KB
/
aircrack.cpp
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
#include "aircrack.h"
#include "ui_aircrack.h"
Aircrack::Aircrack(QWidget *parent) :
QWidget(parent),
ui(new Ui::Aircrack)
{
logThread::addLog("Constructor of aircrack GUI", logInfo::MAIN);
attack = new attackAircrack();
ui->setupUi(this);
connect(attack, SIGNAL(processOutput(QString)), this, SLOT(update(QString)));
connect(this->ui->pushButtonStop, SIGNAL(clicked()), this, SLOT(stop()));
connect(this->ui->pushButtonLog, SIGNAL(clicked()), this, SLOT(clearLog()));
//SUPER FIX: maybe we found the key so fast that function update could not execute.
connect(attack->getProcess(), SIGNAL(finished(int)), this, SLOT(update()));
this->setStatus(STOPPED);
}
Aircrack::~Aircrack()
{
logThread::addLog("Destructor of aircrack GUI", logInfo::MAIN);
delete ui;
delete attack;
}
void Aircrack::clearLog(){
utils::customClearLog(this->ui->textEdit, "Aircrack Log");
}
QString Aircrack::getStatusQString()
{
switch (status) {
case STOPPED:
return "STOPPED";
break;
case OPENNING:
return "OPENNING";
break;
case CRACKING:
return "CRACKING";
break;
case KEY_OBTAINED:
return "KEY OBTAINED";
break;
default:
return "UNKOWN";
break;
}
}
void Aircrack::start(const QString &BSSID){
logThread::addLog("Aircrack: Starting cracking " + BSSID, logInfo::MAIN);
//storing last BSSID
lastBSSID = BSSID;
const bool ok = attack->start(BSSID);
if (ok)
this->setStatus(CRACKING);
//reset values
this->resetValues();
}
void Aircrack::toThisLog(const QString &com){
this->ui->textEdit->append(com);
}
void Aircrack::resetValues(){
this->ui->spinBoxRead->setValue(0);
this->ui->spinBoxTested->setValue(0);
}
void Aircrack::setStatus(const STATUS s){
{status = s;}
switch (s) {
case STOPPED:
this->ui->lineEditStatus->setText("STOPPED");
utils::setBackgroundColor(this->ui->lineEditStatus, utils::RED);
break;
case CRACKING:
this->ui->lineEditStatus->setText("CRACKING...");
utils::setBackgroundColor(this->ui->lineEditStatus, utils::YELLOW);
break;
case OPENNING:
this->ui->lineEditStatus->setText("OPENNING FILES...");
utils::setBackgroundColor(this->ui->lineEditStatus, utils::GREEN);
break;
case KEY_OBTAINED:
utils::setBackgroundColor(this->ui->lineEditStatus, utils::GREEN);
this->ui->lineEditStatus->setText("KEY OBTAINED!");
break;
}
logThread::addLog("Aircrack: Changes status to " + getStatusQString(), logInfo::MAIN);
emit statusChanged(getStatusQString());
}
void Aircrack::stop(){
logThread::addLog("Aircrack: Stopping", logInfo::MAIN);
if (attack->isRunning()) {
attack->stop();
toThisLog("Process stopped");
}
if (this->getStatus() != KEY_OBTAINED)
this->setStatus(STOPPED);
}
void Aircrack::update(QString info){
static int index1;
info.remove("\n");
info.remove("\r");
if (!info.isEmpty()) {
//i dont know why aircrack does not start again himself when the IVS getting up. or not?
if (info.contains("Opening"))
this->setStatus(OPENNING);
if ((index1 = info.indexOf("KEY")) != -1) {
toThisLog(utils::htmlVerde(info.remove(0, index1)));
this->setStatus(KEY_OBTAINED);
this->ui->lineEditStatus->setText(info);
//STORING KEY
toThisLog(utils::htmlVerde("Storing key in " + CAPTURE_FOLDER + this->lastBSSID + ".key"));
QFile f;
f.setFileName(CAPTURE_FOLDER + this->lastBSSID + ".key");
if (!f.open(QIODevice::WriteOnly)) {
this->toThisLog(utils::htmlRojo("Error opening .key file"));
}
f.write(info.toLatin1());
f.close();
logThread::addLog(QString("Aircrack: KEY OBTAINED! (BSSID = %1, KEY=%2)").arg(this->lastBSSID).arg(info), logInfo::MAIN);
//FIX: this message blocks the main thread. So we have to do in the last of
//the storing key process.
utils::mostrarMensaje(info, "We have had luck :)");
}
else if (info.contains("Starting PTW")) {
this->ui->spinBoxRead->setValue(utils::dropNumber(info));
toThisLog(info);
this->setStatus(CRACKING);
}
else if (info.contains("Tested")) {
//the line contain two values. Left one tested, right one read
this->ui->spinBoxTested->setValue(utils::dropNumber(info.split("keys").at(0)));
}
else if (info.contains("Next try")){
toThisLog(utils::htmlRojo("Failed. Restarting..."));
//restart
this->start(lastBSSID);
logThread::addLog("Aircrack: Restarting", logInfo::MAIN);
}
else if (info.contains("No file"))
this->setStatus(STOPPED);
else
toThisLog(info);
}
/*
//FORCE UPDATE. IF WE DONT FORCE, I DONT KNOW WHY THE ATTACK COULD BE PARALIZED
if (this->getStatus() == CRACKING && attack->isRunning()) {
////debug::add("Forcing update in process aircrack " + QString::number(process.pid()));
QTimer::singleShot(1000, this, SLOT(update()));
}
*/
}