commit 9b7d18fa2111607ef1392cee18e4a8a1b12640fb
parent 54d4e1d66f3dd1c37faaa4909aeb77798a86a02a
Author: oblique <psyberbits@gmail.com>
Date: Fri, 2 Mar 2012 23:07:23 +0200
add iw_can_change_channel, fix a bug in channel changing
Diffstat:
3 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/README b/README
@@ -8,10 +8,10 @@ purposes only. It works only in Linux and requires wireless card
drivers capable of injecting packets in wireless networks.
If your Linux kernel is version 2.6.35 or above, you have to
-apply the patch patches/cfg80211_monitor_mode_channel_-1_fix.patch
+apply the patch patches/cfg80211_monitor_mode_channel_fix.patch
to the kernel.
How to use it: Just run it as root and put as first argument the
card interface. It will put your interface in monitor mode automatically,
it will start DoSing and change channel every 3 seconds. The channel
-range is 1 - 13.
-\ No newline at end of file
+range is 1 - 13.
diff --git a/patches/cfg80211_monitor_mode_channel_-1_fix.patch b/patches/cfg80211_monitor_mode_channel_fix.patch
diff --git a/wificurse.c b/wificurse.c
@@ -176,6 +176,25 @@ ssize_t iw_read(int fd, void *buf, size_t count, uint8_t **pkt, size_t *pkt_sz)
return r;
}
+int iw_can_change_channel(struct dev *dev) {
+ struct iwreq iwr;
+ ssize_t ret;
+
+ /* set channel */
+ memset(&iwr, 0, sizeof(iwr));
+ strncpy(iwr.ifr_name, dev->ifname, sizeof(iwr.ifr_name)-1);
+ iwr.u.freq.flags = IW_FREQ_FIXED;
+ iwr.u.freq.m = 1;
+
+ if (ioctl(dev->fd, SIOCSIWFREQ, &iwr) < 0)
+ return 0;
+ if (ioctl(dev->fd, SIOCGIWFREQ, &iwr) < 0)
+ return 0;
+
+ /* channel 1 frequency is 2412 */
+ return iwr.u.freq.m == 2412;
+}
+
int iw_set_channel(struct dev *dev, int chan) {
struct iwreq iwr;
ssize_t ret;
@@ -311,6 +330,13 @@ int main(int argc, char *argv[]) {
goto _errout;
}
+ if (!iw_can_change_channel(&dev)) {
+ fprintf(stderr, "%s cannot change channels in monitor mode.\n"
+ "Maybe you will need to patch your kernel with:\n"
+ " patches/cfg80211_monitor_mode_channel_fix.patch\n", dev.ifname);
+ goto _errout;
+ }
+
pfd[1].fd = dev.fd;
pfd[1].revents = 0;
pfd[1].events = POLLIN;
@@ -351,15 +377,19 @@ int main(int argc, char *argv[]) {
/* change channel every 3 seconds */
if (time(NULL) - tm1 >= 3) {
- chan = (chan % 13) + 1;
- if (iw_set_channel(&dev, chan) < 0) {
+ int n = 0;
+ do {
+ chan = (chan % 13) + 1;
+ ret = iw_set_channel(&dev, chan);
+ /* if fails try next channel */
+ } while(++n < 13 && ret < 0);
+ if (ret < 0) {
print_error();
goto _errout;
}
printf("Channel: %d\n", dev.chan);
tm1 = time(NULL);
}
-
}
printf("\nExiting..\n");