Skip to content
This repository has been archived by the owner on Mar 11, 2018. It is now read-only.

Besside-ng: Added automatic channel detection of 2GHz and 5GHz channels #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 47 additions & 6 deletions src/besside-ng.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ struct channel {
struct conf {
char *cf_ifname;
struct channel cf_channels;
int cf_autochan;
int cf_hopfreq;
int cf_deauthfreq;
unsigned char *cf_bssid;
Expand Down Expand Up @@ -246,6 +247,7 @@ struct state {

static void attack_continue(struct network *n);
static void attack(struct network *n);
static void autodetect_channels();

void show_wep_stats(int UNUSED(B), int UNUSED(force),
PTW_tableentry UNUSED(table[PTW_KEYHSBYTES][PTW_n]),
Expand Down Expand Up @@ -1610,7 +1612,7 @@ static void attack(struct network *n)
channel_set(n->n_chan);

time_printf(V_VERBOSE,
"Pwning [%s] %s\n", n->n_ssid, mac2str(n->n_bssid));
"Pwning [%s] %s on chan %d\n", n->n_ssid, mac2str(n->n_bssid), n->n_chan);

if (n->n_start.tv_sec == 0)
memcpy(&n->n_start, &_state.s_now, sizeof(n->n_start));
Expand Down Expand Up @@ -1841,6 +1843,10 @@ static void wifi_beacon(struct network *n, struct ieee80211_frame *wh,
goto __bad;
break;

case IEEE80211_ELEMID_HTINFO:
n->n_chan = *p;
break;

default:
// printf("id %d len %d\n", id, l);
break;
Expand Down Expand Up @@ -2950,6 +2956,9 @@ static void pwn(void)
time_printf(V_VERBOSE, "mac %s\n", mac2str(_state.s_mac));
time_printf(V_NORMAL, "Let's ride\n");

if (_conf.cf_autochan)
autodetect_channels();

if (wi_set_channel(s->s_wi, _state.s_chan) == -1)
err(1, "wi_set_channel()");

Expand Down Expand Up @@ -3010,14 +3019,45 @@ static void channel_add(int num)
c->c_next = _conf.cf_channels.c_next;
}

static void init_conf(void)
static void autodetect_freq(int start, int end, int incr)
{
int i;
int freq;
int chan;

_conf.cf_channels.c_next = &_conf.cf_channels;
for (freq = start; freq <= end; freq += incr)
{
if (wi_set_freq(_state.s_wi, freq) == 0)
{
chan = wi_get_channel(_state.s_wi);
channel_add(chan);
time_printf(V_VERBOSE, "Found channel %d on frequency %d\n", chan, freq);
}
else
{
time_printf(V_VERBOSE, "No channel found on frequency %d\n", freq);
}
}
}

static void autodetect_channels()
{
time_printf(V_NORMAL, "Autodetecting supported channels...\n");

// autodetect 2ghz channels
autodetect_freq(2412, 2472, 5); // 1-13
autodetect_freq(2484, 2484, 1); // 14

for (i = 1; i <= 11; i++)
channel_add(i);
// autodetect 5ghz channels
autodetect_freq(5180, 5320, 10); // 36-64
autodetect_freq(5500, 5720, 10); // 100-144
autodetect_freq(5745, 5805, 10); // 149-161
autodetect_freq(5825, 5825, 1); // 165
}

static void init_conf(void)
{
_conf.cf_channels.c_next = &_conf.cf_channels;
_conf.cf_autochan = 1;

_state.s_hopchan = _conf.cf_channels.c_next;

Expand Down Expand Up @@ -3191,6 +3231,7 @@ int main(int argc, char *argv[])
_conf.cf_channels.c_next = &_conf.cf_channels;
channel_add(atoi(optarg));
_state.s_hopchan = _conf.cf_channels.c_next;
_conf.cf_autochan = 0;
break;

case 'v':
Expand Down