From: Russ Handorf Date: Sat, 4 Feb 2017 22:19:34 +0000 (-0500) Subject: Using LORCON now for channel hopping and interface setup. Client is pretty much all... X-Git-Url: http://russells-world.com/code/?a=commitdiff_plain;h=2b5147eaa2dd3223a78ffe759465aecc84cbe58b;p=soho-sigint.git Using LORCON now for channel hopping and interface setup. Client is pretty much all done. --- diff --git a/client-wifi/client-c/Makefile b/client-wifi/client-c/Makefile index 1f86b64..6c94214 100644 --- a/client-wifi/client-c/Makefile +++ b/client-wifi/client-c/Makefile @@ -1,6 +1,6 @@ CFLAGS= -std=gnu99 DEPS = endian.h -LIBS=$(LDFLAGS) -L. -lpcap -lcurl -ljson-c -lssl +LIBS=$(LDFLAGS) -L. -lpcap -lcurl -ljson-c -lssl -lorcon2 OBJ = soho-sigint-wifi.o radiotap.o %.o: %.c $(DEPS) diff --git a/client-wifi/client-c/interface-setup.sh b/client-wifi/client-c/interface-setup.sh deleted file mode 100755 index 60d18d7..0000000 --- a/client-wifi/client-c/interface-setup.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -#iw phy phy0 interface add mon1 type monitor flags fcsfail -iw phy phy0 interface add mon0 type monitor -iw dev wlan0 del -ifconfig mon0 up -#iw dev mon0 set freq 2412 -iw dev mon0 set freq 2437 -#iw dev mon0 set freq 2462 diff --git a/client-wifi/client-c/soho-sigint-wifi.c b/client-wifi/client-c/soho-sigint-wifi.c index c577e72..a49e42d 100644 --- a/client-wifi/client-c/soho-sigint-wifi.c +++ b/client-wifi/client-c/soho-sigint-wifi.c @@ -1,17 +1,10 @@ #include +#include #include #include #include #include #include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include #include #include #include "radiotap.h" @@ -19,13 +12,19 @@ #include #include #include +#include const struct pcap_pkthdr* callback_header; time_t start = 0; -char *ssid_buf[34][2] = { NULL, NULL }; -char *probe_resp_buf[34][3] = { NULL, NULL }; -char *probe_buf[34][2] = { NULL, NULL }; +int element = -1; +int changechan=1; +char *ssid_buf[50][2] = { NULL, NULL }; +char *probe_resp_buf[50][3] = { NULL, NULL }; +char *probe_buf[50][2] = { NULL, NULL }; + +lorcon_t *context; +int lchannel = 1; //char post_url[255] = "http://intranet.spangdorfia.com/butler/sohoinput.php"; char *post_url = NULL; @@ -55,8 +54,27 @@ typedef struct { struct json_object *obj1, *obj2, *array, *tmp1, *tmp2; +/* +int change_chan(context) { + if (changechan==1) { + int gchannel=0; + changechan=0; + gchannel=lorcon_get_channel(context); + printf("got channel %d", gchannel); + lchannel=gchannel+1; + if (lchannel == 14) { + lchannel=1; + } + printf("Setting channel %d\n", lchannel); + lorcon_set_channel(context, lchannel); + changechan=1; + } +} +*/ + void send_data(json_object *array) { + //printf("curl start\n"); CURL *curl; CURLcode res; @@ -110,7 +128,7 @@ void send_data(json_object *array) { } curl_global_cleanup(); - + //printf("curl end\n"); } @@ -124,9 +142,9 @@ void my_callback(u_char *args,const struct pcap_pkthdr* pkthdr,const u_char* pac char *ssid; char tmp_channel[2]; char tmp_rssi[1]; - - + int diff; + if (start == 0) { start = time(0); } @@ -162,7 +180,7 @@ void my_callback(u_char *args,const struct pcap_pkthdr* pkthdr,const u_char* pac if (iter.this_arg_index == IEEE80211_RADIOTAP_FLAGS) { flags = (*(u_int8_t *)iter.this_arg); if (flags & IEEE80211_RADIOTAP_F_BADFCS) { - //printf("bad fcs\n"); + printf("bad fcs\n"); fcsfail=1; break; } @@ -180,9 +198,11 @@ void my_callback(u_char *args,const struct pcap_pkthdr* pkthdr,const u_char* pac if (pkthdr->len >= 24) { u_int8_t hlen; - hlen = packet[2]+(packet[3]<<8); //Usually 18 or 13 in some cases + //hlen = packet[2]+(packet[3]<<8); //Usually 18 or 13 in some cases + hlen=36; switch (packet[hlen]) { case 0x40: //probe request + //printf("probe request\n"); ssid_len=packet[61]; memset(ssid, 0, sizeof(ssid)); if (ssid_len>0) { @@ -193,13 +213,17 @@ void my_callback(u_char *args,const struct pcap_pkthdr* pkthdr,const u_char* pac memset(client_mac, 0, sizeof(client_mac)); sprintf(client_mac, "%02x:%02x:%02x:%02x:%02x:%02x", packet[46], packet[47],packet[48],packet[49],packet[50],packet[51]); - for (i=0; i<34; i++) { + for (i=0; i<50; i++) { if (probe_buf[i][0] != NULL) { if ((strcoll(probe_buf[i][0], ssid) == 0 && strcoll(probe_buf[i][1], client_mac) == 0)) { break; } } if (probe_buf[i][0] == NULL) { + if (element < i) { + element=i; + } + //printf("probe element: %d\n", element); probe_buf[i][0] = strdup(ssid); probe_buf[i][1] = strdup(client_mac); obj2 = json_object_new_object(); @@ -220,21 +244,26 @@ void my_callback(u_char *args,const struct pcap_pkthdr* pkthdr,const u_char* pac break; case 0x50: //probe response + //printf("probe response\n"); ssid_len=packet[73]; for (i=0;i0) { for (i=0;i= 5) { + if ((diff >= 5) || (element == 25)) { //printf("time to barf!\n"); + //printf("size: %d\n", element); + //change_chan(context); + int gchannel=0; + gchannel=lorcon_get_channel(context); + //printf("got channel %d", gchannel); + lchannel=gchannel+1; + if (lchannel == 14) { + lchannel=1; + } + //printf("Setting channel %d\n", lchannel); + lorcon_set_channel(context, lchannel); + + lorcon_set_channel(context, lchannel); //for (i=0; i<34; i++) { // printf("barf beacons: buffer %d, ssid: %s \t\t mac: %s channel: %s rssi: %s\n", i, ssid_buf[i][0], ssid_buf[i][1], ssid_buf[i][2], ssid_buf[i][3]); //} //for (i=0; i<34; i++) { // printf("barf probe reponses: buffer %d, ssid: %s \t mac: %s mac: %s channel: %s rssi: %s\n", i, probe_resp_buf[i][0], probe_resp_buf[i][1], probe_resp_buf[i][2], probe_resp_buf[i][3], probe_resp_buf[i][4]); //} - for (i=0; i<34; i++) { + //for (i=0; i<34; i++) { //printf("barf probes: buffer %d, ssid: %s \t mac: %s channel: %s rssi: %s\n", i, probe_buf[i][0], probe_buf[i][1], probe_buf[i][2], probe_buf[i][3]); - } + //} - send_data(array); - //printf ("The json object created: %s\n",json_object_to_json_string(array)); - json_object_put(array); + if (element >= 0) { + //printf("barfing\n"); + send_data(array); + //printf ("The json object created: %s\n",json_object_to_json_string(array)); + json_object_put(array); - memset(ssid_buf, 0, sizeof(ssid_buf)); - memset(probe_resp_buf, 0, sizeof(probe_resp_buf)); - memset(probe_buf, 0, sizeof(probe_buf)); + memset(ssid_buf, 0, sizeof(ssid_buf)); + memset(probe_resp_buf, 0, sizeof(probe_resp_buf)); + memset(probe_buf, 0, sizeof(probe_buf)); + element=-1; + } start = time(0); } //printf("rate: %d channel: %04x rssi: %d\n", rate, channel, rssi); @@ -330,6 +385,9 @@ int main(int argc,char **argv) { int c; char *dev = NULL; + char *interface = NULL; + lorcon_driver_t *drvlist, *driver; + //lorcon_t *context; char errbuf[PCAP_ERRBUF_SIZE]; pcap_t* pcap; struct bpf_program fp; /* hold compiled program */ @@ -345,7 +403,7 @@ int main(int argc,char **argv) totpacket = optarg; break; case 'i': - dev = optarg; + interface = optarg; break; case 'p': post_url = optarg; @@ -359,10 +417,10 @@ int main(int argc,char **argv) if (totpacket == NULL) { totpacket="-1"; - printf("-a not specified... setting to 10.\n"); + printf("-a not specified... looping forever.\n"); } - if (dev == NULL) { + if (interface == NULL) { printf("You forgot -i\n"); exit(0); } @@ -372,13 +430,40 @@ int main(int argc,char **argv) exit(0); } - printf ("%s %s\n", totpacket, dev); + //printf ("%s %s\n", totpacket, dev); - if(dev == NULL) { - printf("%s\n",errbuf); - exit(1); + //if(interface == NULL) { + // printf("%s\n",errbuf); + // exit(1); + //} + + if ( (driver = lorcon_auto_driver(interface)) == NULL) { + printf("[!] Could not determine the driver for %s\n",interface); + return -1; + } else { + printf("[+]\t Driver: %s\n",driver->name); } + // Create LORCON context + if ((context = lorcon_create(interface, driver)) == NULL) { + printf("[!]\t Failed to create context"); + return -1; + } + + // Create Monitor Mode Interface + if (lorcon_open_monitor(context) < 0) { + printf("[!]\t Could not create Monitor Mode interface!\n"); + return -1; + } else { + printf("[+]\t Monitor Mode VAP: %s\n",lorcon_get_vap(context)); + lorcon_free_driver_list(driver); + } + + // Set the channel we'll be injecting on + lorcon_set_channel(context, lchannel); + + dev=lorcon_get_vap(context); + /* ask pcap for the network address and mask of the device */ pcap_lookupnet(dev,&netp,&maskp,errbuf);