File reaver_MR350.patch of Package reaver

From 3f47d222638b820c2e7f058eb4786caa8e4c7d8e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= <jskarvad@redhat.com>
Date: Tue, 14 Dec 2021 22:03:07 +0100
Subject: [PATCH] add support for building with the libnl3 (--enable-libnl3)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fixes #349

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
---
 src/Makefile      |  2 +-
 src/config.mak.in |  2 +-
 src/configure.ac  |  7 ++++++
 src/iface.c       | 61 ++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/src/Makefile b/src/Makefile
index 4063210..7394f23 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -120,7 +120,7 @@ wash: reaver
 	ln -sf ./reaver wash
 
 reaver: $(PROG_OBJS) $(LIB_OBJS)
-	$(CC) $(CFLAGS) $(INC) $(PROG_OBJS) $(LIB_OBJS) $(LDFLAGS) -lpthread -o reaver
+	$(CC) $(CFLAGS) $(INC) $(PROG_OBJS) $(LIB_OBJS) $(LDFLAGS) $(LIB_NL3) -lpthread -o reaver
 
 extest.o: exchange.c
 	$(CC) $(CFLAGS) -g3 -O0 -DEX_TEST -c exchange.c -o extest.o
diff --git a/src/config.mak.in b/src/config.mak.in
index 93568f6..e8ad6ae 100644
--- a/src/config.mak.in
+++ b/src/config.mak.in
@@ -5,4 +5,4 @@ CONFDIR=@localstatedir@/lib/@target@
 CC=@CC@
 CFLAGS_USER=@CFLAGS@
 LDFLAGS=@LDFLAGS@
-
+LIB_NL3=@LIB_NL3@
diff --git a/src/configure.ac b/src/configure.ac
index b593fe9..cb0d198 100644
--- a/src/configure.ac
+++ b/src/configure.ac
@@ -17,6 +17,13 @@ AC_HELP_STRING([--enable-savetocurrent],
   [saves the current session file to the directory reaver was started from])
 , [ CFLAGS="$CFLAGS -DSAVETOCURRENT" ])
 
+AC_ARG_ENABLE(libnl3,
+AC_HELP_STRING([--enable-libnl3],
+  [compiles with the libnl3 instead of the wext])
+, [ CFLAGS="$CFLAGS -DLIBNL3 $(pkg-config --cflags libnl-3.0 libnl-genl-3.0)"; LIB_NL3="$(pkg-config --libs libnl-3.0 libnl-genl-3.0)" ])
+
+AC_SUBST(LIB_NL3)
+
 DESIRED_FLAGS="-Werror-unknown-warning-option -Wno-unused-but-set-variable"
 for flag in $DESIRED_FLAGS; do
   AS_COMPILER_FLAG([$flag], [CFLAGS="$CFLAGS $flag"])
diff --git a/src/iface.c b/src/iface.c
index 37aac75..6945ff8 100644
--- a/src/iface.c
+++ b/src/iface.c
@@ -32,10 +32,18 @@
  */
 
 #include "iface.h"
-#include "lwe/iwlib.h"
 #include "globule.h"
 #include <net/if.h>
 #include <netinet/in.h>
+#ifdef LIBNL3
+#include <net/ethernet.h>
+#include <netlink/netlink.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/ctrl.h>
+#include <linux/nl80211.h>
+#else
+#include "lwe/iwlib.h"
+#endif
 #include <sys/ioctl.h>
 #include <stdlib.h>
 
@@ -159,6 +167,56 @@ int change_channel(int channel)
 	return 0;
 }
 #else
+#ifdef LIBNL3
+/* took from the Aircrack-ng */
+static int ieee80211_channel_to_frequency(int chan)
+{
+	if (chan < 14) return 2407 + chan * 5;
+
+	if (chan == 14) return 2484;
+
+	/* FIXME: dot11ChannelStartingFactor (802.11-2007 17.3.8.3.2) */
+	return (chan + 1000) * 5;
+}
+
+int change_channel(int channel)
+{
+	int skfd = 0, ret_val = 0;
+	unsigned int freq;
+
+	cprintf(VERBOSE, "[+] Switching %s to channel %d\n", get_iface(), channel);
+
+/* Modified example from the stackoverflow probably inspired by the Aircrack-ng code */
+/* https://stackoverflow.com/questions/21846965/set-wireless-channel-using-netlink-api */
+	freq = ieee80211_channel_to_frequency(channel);
+	/* Create the socket and connect to it. */
+	struct nl_sock *sckt = nl_socket_alloc();
+	genl_connect(sckt);
+
+	/* Allocate a new message. */
+	struct nl_msg *mesg = nlmsg_alloc();
+
+	/* Check /usr/include/linux/nl80211.h for a list of commands and attributes. */
+	enum nl80211_commands command = NL80211_CMD_SET_WIPHY;
+
+	/* Create the message so it will send a command to the nl80211 interface. */
+	genlmsg_put(mesg, 0, 0, genl_ctrl_resolve(sckt, "nl80211"), 0, 0, command, 0);
+
+	/* Add specific attributes to change the frequency of the device. */
+	NLA_PUT_U32(mesg, NL80211_ATTR_IFINDEX, if_nametoindex(get_iface()));
+	NLA_PUT_U32(mesg, NL80211_ATTR_WIPHY_FREQ, freq);
+
+	/* Finally send it and receive the amount of bytes sent. */
+	int ret = nl_send_auto_complete(sckt, mesg);
+
+	ret_val = 1;
+
+nla_put_failure:
+	nlmsg_free(mesg);
+
+	return ret_val;
+}
+#else // !LIBNL3
 int change_channel(int channel)
 {
         int skfd = 0, ret_val = 0;
@@ -193,4 +251,5 @@ int change_channel(int channel)
 
         return ret_val;
 }
+#endif // LIBNL3
 #endif
openSUSE Build Service is sponsored by