nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | #include <stdio.h> |
2 | #include <assert.h> |
||
3 | #include <time.h> |
||
4 | #include <stdlib.h> |
||
5 | #include <string.h> |
||
6 | |||
7 | #include "helpers.h" |
||
8 | #include "mac_addr.h" |
||
9 | #include "linkedlist.h" |
||
10 | #include "greylist.h" |
||
11 | #include "dumpfile.h" |
||
12 | #include "brute.h" |
||
13 | |||
14 | void print_chars_decimal(char *values, int count) { |
||
15 | int i; |
||
16 | |||
17 | for(i=0; i<count; i++) printf("%d ", values[i]); |
||
18 | } |
||
19 | |||
20 | void print_strings(char **values, int count) { |
||
21 | int i; |
||
22 | |||
23 | for(i=0; i<count; i++) printf("\"%s\" ", values[i]); |
||
24 | } |
||
25 | |||
26 | void print_clist(struct clist *cl) { |
||
27 | if (!cl) return; |
||
28 | |||
29 | struct clist *first = cl; |
||
30 | |||
31 | do { |
||
32 | printf(" CList at %X contains: Status %d, Data %s\n", (unsigned int) cl, cl->status, cl->data); |
||
33 | cl = cl->next; |
||
34 | } while (cl != first); |
||
35 | } |
||
36 | |||
37 | void test_helpers() { |
||
38 | char chan[8]; |
||
39 | char *ssid[8]; |
||
40 | int i; |
||
41 | char *line; |
||
42 | |||
43 | printf("Testing generic helpers:\n"); |
||
44 | |||
45 | for(i=0; i<8; i++) chan[i] = generate_channel(); |
||
46 | printf("Random channels: "); print_chars_decimal(chan, 8); |
||
47 | for(i=0; i<8; i++) { |
||
48 | assert(chan[i] > 0); |
||
49 | assert(chan[i] < 15); |
||
50 | } |
||
51 | |||
52 | for(i=0; i<8; i++) ssid[i] = generate_ssid(0); |
||
53 | printf("\nRandom SSIDs: "); print_strings(ssid, 8); |
||
54 | for(i=0; i<8; i++) { |
||
55 | assert(strlen(ssid[i]) > 0); |
||
56 | assert(strlen(ssid[i]) < 33); |
||
57 | free(ssid[i]); |
||
58 | } |
||
59 | |||
60 | printf("\nWho are my authors?:\n"); |
||
61 | line = read_next_line("./AUTHORS", 1); |
||
62 | while (line) { |
||
63 | printf(" READING: %s\n", line); |
||
64 | free(line); |
||
65 | line = read_next_line("./AUTHORS", 0); |
||
66 | } |
||
67 | |||
68 | printf("\n\n"); |
||
69 | } |
||
70 | |||
71 | void show_some_macs(struct ether_addr mac, struct ether_addr mac2) { |
||
72 | int i; |
||
73 | |||
74 | printf("\n First MAC: "); print_mac(get_next_mac(mac, &mac2)); |
||
75 | printf("\n Second MAC: "); print_mac(get_next_mac(mac, &mac2)); |
||
76 | for(i=0; i<99998; i++) get_next_mac(mac, &mac2); |
||
77 | printf("\n MAC 100000: "); print_mac(get_next_mac(mac, &mac2)); |
||
78 | for(i=0; i<16677214; i++) get_next_mac(mac, &mac2); |
||
79 | printf("\n Many MACs later: "); print_mac(get_next_mac(mac, &mac2)); |
||
80 | if (MAC_IS_BCAST(mac2)) printf("\n Ran out of MAC addresses (correct in semi-auto and manual)."); |
||
81 | for(i=0; i<123456; i++) get_next_mac(mac, &mac2); |
||
82 | printf("\n New base: "); print_mac(get_next_mac(mac, &mac2));} |
||
83 | |||
84 | void test_mac_addr() { |
||
85 | struct ether_addr mac, mac2; |
||
86 | char parse1[18] = "aa:bB:Cc:DD:00:0f"; |
||
87 | char parse2[13] = "aabbCCdDEef9"; |
||
88 | |||
89 | printf("Testing MAC Address parsers and generators:\n"); |
||
90 | |||
91 | MAC_SET_NULL(mac); |
||
92 | printf("Null MAC: "); print_mac(mac); |
||
93 | assert(MAC_IS_NULL(mac)); |
||
94 | |||
95 | MAC_SET_BCAST(mac); |
||
96 | printf("\nBroadcast MAC: "); print_mac(mac); |
||
97 | assert(MAC_IS_BCAST(mac)); |
||
98 | |||
99 | printf("\nParsing %s: ", parse1); print_mac(parse_mac(parse1)); |
||
100 | printf("\nParsing %s: ", parse2); print_mac(parse_mac(parse2)); |
||
101 | |||
102 | printf("\nRandom MAC: "); print_mac(generate_mac(MAC_KIND_RANDOM)); |
||
103 | printf("\nRandom valid client MAC: "); print_mac(generate_mac(MAC_KIND_CLIENT)); |
||
104 | printf("\nRandom valid AP MAC: "); print_mac(generate_mac(MAC_KIND_AP)); |
||
105 | |||
106 | printf("\nMAC filter Bruteforcer in auto-mode:"); |
||
107 | MAC_SET_NULL(mac); MAC_SET_NULL(mac2); |
||
108 | show_some_macs(mac, mac2); |
||
109 | printf("\nMAC filter Bruteforcer in semi-auto mode starting with F0:EE:DD:"); |
||
110 | mac.ether_addr_octet[0] = 0xF0; |
||
111 | mac.ether_addr_octet[1] = 0xEE; |
||
112 | mac.ether_addr_octet[2] = 0xDD; |
||
113 | MAC_SET_NULL(mac2); |
||
114 | show_some_macs(mac, mac2); |
||
115 | printf("\nMAC filter Bruteforcer in manual mode starting with F0:EE:DD:AA:00:85"); |
||
116 | mac2.ether_addr_octet[0] = 0xAA; |
||
117 | mac2.ether_addr_octet[1] = 0x00; |
||
118 | mac2.ether_addr_octet[2] = 0x85; |
||
119 | show_some_macs(mac, mac2); |
||
120 | |||
121 | printf("\n\n"); |
||
122 | } |
||
123 | |||
124 | void test_linkedlist() { |
||
125 | struct clist *cl = NULL; |
||
126 | char tdata[10] = "testdata"; |
||
127 | char *rdata; |
||
128 | int i; |
||
129 | |||
130 | printf("Testing Circular Linked Lists:\n"); |
||
131 | |||
132 | printf("Test A: Data CList\n"); |
||
133 | printf(" Searching status in empty list: %X\n", (unsigned int) search_status(cl, 0)); |
||
134 | printf(" Searching \"%s\" in empty list: %X\n", tdata, (unsigned int) search_data(cl, (u_char *) tdata, strlen(tdata))); |
||
135 | printf(" Adding random data to list.\n"); |
||
136 | for (i=0; i<5; i++) { |
||
137 | rdata = generate_ssid(0); |
||
138 | cl = add_to_clist(cl, (u_char *) rdata, random(), strlen(rdata)+1); |
||
139 | free(rdata); |
||
140 | } |
||
141 | printf(" Adding \"%s\"\n", tdata); |
||
142 | cl = add_to_clist(cl, (u_char *) tdata, 0, strlen(tdata)+1); |
||
143 | printf(" Adding more random data to list.\n"); |
||
144 | for (i=0; i<15; i++) { |
||
145 | rdata = generate_ssid(0); |
||
146 | cl = add_to_clist(cl, (u_char *) rdata, random(), strlen(rdata)+1); |
||
147 | free(rdata); |
||
148 | } |
||
149 | printf(" CList DUMP:\n"); |
||
150 | print_clist(cl); |
||
151 | printf(" Searching status in full list: %X\n", (unsigned int) search_status(cl, 0)); |
||
152 | printf(" Searching \"%s\" in full list: %X\n", tdata, (unsigned int) search_data(cl, (u_char *) tdata, strlen(tdata))); |
||
153 | |||
154 | printf("Test B: WIDS AP CList - not implemented\n"); |
||
155 | printf("Test C: WIDS Client CList - not implemented\n"); |
||
156 | } |
||
157 | |||
158 | void test_greylist() { |
||
159 | struct ether_addr target = parse_mac("000011112222"); |
||
160 | |||
161 | printf("Testing Greylist\n"); |
||
162 | |||
163 | //Using an example file that is not well formed ;) |
||
164 | load_greylist(1, "./useful_files/fakeap-example.txt"); |
||
165 | |||
166 | if (is_blacklisted(target)) { |
||
167 | printf(" Target MAC has been found blacklisted\n"); |
||
168 | } else { |
||
169 | printf(" Target MAC is NOT blacklisted!\n"); |
||
170 | } |
||
171 | |||
172 | printf("Turning list into a whitelist:\n"); |
||
173 | load_greylist(0, NULL); |
||
174 | |||
175 | if (is_blacklisted(target)) { |
||
176 | printf(" Target MAC has been found blacklisted\n"); |
||
177 | } else { |
||
178 | printf(" Target MAC is NOT blacklisted!\n"); |
||
179 | } |
||
180 | } |
||
181 | |||
182 | void test_packet() { |
||
183 | struct packet pkt; |
||
184 | int i; |
||
185 | uint16_t caps; |
||
186 | struct ether_addr bssid, station; |
||
187 | char *ssid; |
||
188 | char enc[4] = {'n', 'w', 't', 'a'}; |
||
189 | |||
190 | printf("Opening testdump.cap\n"); |
||
191 | |||
192 | start_dump("testdump.cap"); |
||
193 | |||
194 | printf("Creating random beacons :)\n"); |
||
195 | for(i=0; i<20; i++) { |
||
196 | bssid = generate_mac(MAC_KIND_AP); |
||
197 | ssid = generate_ssid(0); |
||
198 | pkt = create_beacon(bssid, ssid, (uint8_t) (random() % 14), enc[random() % 4], (random() % 2) * 54, random() % 2); |
||
199 | dump_packet(&pkt); |
||
200 | free(ssid); |
||
201 | ssid = get_ssid(&pkt, NULL); |
||
202 | caps = get_capabilities(&pkt); |
||
203 | printf("SSID found in beacon: %s\n", ssid); |
||
204 | printf("Capabilities: %04X\n", caps); |
||
205 | free(ssid); |
||
206 | } |
||
207 | printf("Creating random auths :)\n"); |
||
208 | for(i=0; i<20; i++) { |
||
209 | bssid = generate_mac(MAC_KIND_AP); |
||
210 | station = generate_mac(MAC_KIND_CLIENT); |
||
211 | pkt = create_auth(bssid, station, (random() % 2) + 1); |
||
212 | dump_packet(&pkt); |
||
213 | } |
||
214 | printf("Creating random probes :)\n"); |
||
215 | for(i=0; i<20; i++) { |
||
216 | station = generate_mac(MAC_KIND_CLIENT); |
||
217 | ssid = generate_ssid(0); |
||
218 | pkt = create_probe(station, ssid, (random() % 2) * 54); |
||
219 | dump_packet(&pkt); |
||
220 | free(ssid); |
||
221 | } |
||
222 | printf("Creating random kicks :)\n"); |
||
223 | for(i=0; i<20; i++) { |
||
224 | station = generate_mac(MAC_KIND_CLIENT); |
||
225 | bssid = generate_mac(MAC_KIND_AP); |
||
226 | pkt = create_deauth(bssid, station, bssid); |
||
227 | dump_packet(&pkt); |
||
228 | pkt = create_deauth(station, bssid, bssid); |
||
229 | dump_packet(&pkt); |
||
230 | pkt = create_disassoc(bssid, station, bssid); |
||
231 | dump_packet(&pkt); |
||
232 | pkt = create_disassoc(station, bssid, bssid); |
||
233 | dump_packet(&pkt); |
||
234 | } |
||
235 | printf("Creating random associations :)\n"); |
||
236 | for(i=0; i<20; i++) { |
||
237 | bssid = generate_mac(MAC_KIND_AP); |
||
238 | ssid = generate_ssid(0); |
||
239 | station = generate_mac(MAC_KIND_CLIENT); |
||
240 | pkt = create_assoc_req(station, bssid, 0x0431, ssid, 54); |
||
241 | dump_packet(&pkt); |
||
242 | free(ssid); |
||
243 | } |
||
244 | printf("done!\n"); |
||
245 | } |
||
246 | |||
247 | void test_brute() { |
||
248 | char word[3] = { 'x', 'x', 0x00 }; //Can't init with "xx", would be READ ONLY! |
||
249 | int sl; |
||
250 | char *fresh = NULL; |
||
251 | |||
252 | printf("Words after %s, using lowercase and numbers:\n", word); |
||
253 | sl = strlen(word); |
||
254 | |||
255 | while(get_brute_word("ln", word, sl)) { |
||
256 | printf("%s, ", word); |
||
257 | fflush(stdout); |
||
258 | } |
||
259 | |||
260 | printf("Keyspace exhausted!\n"); |
||
261 | |||
262 | printf("Fresh 2 char words:\n"); |
||
263 | while((fresh = get_brute_word("u", fresh, 2))) { //Yep, use assignment as truth value. |
||
264 | printf("%s, ", fresh); |
||
265 | fflush(stdout); |
||
266 | } |
||
267 | printf("Keyspace exhausted!\n"); |
||
268 | |||
269 | free(fresh); |
||
270 | } |
||
271 | |||
272 | int main() { |
||
273 | |||
274 | printf("mdk3 Implementation Tests\n\n"); |
||
275 | |||
276 | srandom(time(NULL)); //Fresh numbers each run |
||
277 | |||
278 | test_helpers(); |
||
279 | test_linkedlist(); |
||
280 | test_greylist(); |
||
281 | test_packet(); |
||
282 | test_mac_addr(); |
||
283 | test_brute(); |
||
284 | |||
285 | stop_dump(); |
||
286 | return 0; |
||
287 | } |
||
288 |