Csitool安装
一:安装
首先是工具的安装,详情参见官网
https://dhalperi.github.io/linux-80211n-csitool/faq.html
作者已经描述得很详细,但是还是会出一些问题。安装过程中穿插一些小提示,有些可以不去管它,按照步骤一步步输入命令就行,下面我列出我觉得必要的步骤,大家一步步照着输到终端就行
- Prerequisites
sudo apt-get install gcc make linux-headers-$(uname -r) git-core
- Build and Install the Modified Wireless Driver
CSITOOL_KERNEL_TAG=csitool-$(uname -r | cut -d . -f 1-2)
git clone https://github.com/dhalperi/linux-80211n-csitool.git
cd linux-80211n-csitool
git checkout ${CSITOOL_KERNEL_TAG}
make -C /lib/modules/$(uname -r)/build M=$(pwd)/drivers/net/wireless/iwlwifi modules
sudo make -C /lib/modules/$(uname -r)/build M=$(pwd)/drivers/net/wireless/iwlwifi INSTALL_MOD_DIR=updates modules_install
sudo depmod
cd ..
- Install the Modified Firmware
git clone https://github.com/dhalperi/linux-80211n-csitool-supplementary.git
for file in /lib/firmware/iwlwifi-5000-*.ucode; do sudo mv $file $file.orig; done
sudo cp linux-80211n-csitool-supplementary/firmware/iwlwifi-5000-2.ucode.sigcomm2010 /lib/firmware/
sudo ln -s iwlwifi-5000-2.ucode.sigcomm2010 /lib/firmware/iwlwifi-5000-2.ucode
- Build the Userspace Logging Tool
make -C linux-80211n-csitool-supplementary/netlink
二:收数
1 AP模式
将安装好的电脑作为client,连接一台没有密码的路由器(有密码的是连不上的)
执行
sudo rmmod iwldvm iwlwifl mac80211 cfg80211
or
modprobe -r iwldvm iwlwifi mac80211
这一步如果报错 …is in use by … ,说明想要卸载的模块在被其他模块使用,加sudo执行就行
接着执行
sudo modprobe iwlwifi connector_log=0x1
连接上路由器wifi后,我们可以查看其connection information,在Default Route栏获取路由器的IP地址。假设为192.168.1.1。使用ctrl+alt+T新建另一个终端,并执行指令
ping 192.168.1.1 -i 0.5
(0.5为发包间隔,使用sudo权限可以获取更短的发包间隔)
我们的电脑会不停地ping AP,这时就可以测CSI了
在原终端打开log_to_file收数,执行
cd /home/csi/linux-supplementary/netlink
(这里的csi是你的计算机名称)
sudo ./log_to_file test.dat
可以看到输出了 wrote 393 bytes
received 393 bytes?26 val:1 seq:10 clen:393等字样,收数成功!可以打开netlink目录查看收到的test.dat文件。
2 monitor模式
使用AP模式的缺陷在于ping 命令速度比较慢,且不能精确控制发送的参数,比如接收的包数量是不可控的。Monitor模式比ap模式更加稳定,可以发送指定数量的包,可以设置发送包之间的间隔,以及信道和带宽。Monitor模式可以调制发送速率、发包数量、发送天线个数、HT模式、short/long guard interval等等,因此调通Monitor模式是必须的
启用Monitor模式需要两台安装CSI tool工具的电脑。
monitor模式操作具体也可参见
https://github.com/dhalperi/linux-80211n-csitool-supplementary/tree/master/injection
令A电脑为接收端,B电脑为发送端。A和B电脑均需安装lorcon,那么均需在A和B电脑上执行下列流程:
ctrl+alt+T打开终端窗口,运行:
sudo apt-get install libpcap-dev
git clone https://github.com/dhalperi/lorcon-old.git
cd lorcon-old
./configure
make
sudo make install
cd linux-80211n-csitool-supplementary/injection
make
使用
接收端
ctrl+alt+T打开终端窗口,运行:
./setup_monitor_csi.sh.sh 64 HT20
sudo ../netlink/log_to_file log.dat
发送端
./setup_injection.sh 64 HT20
sudo echo 0x4101|sudotee/sys/kernel/debug/ieee80211/phy0/iwlwifi/iwldvm/debug/monitor_tx_rate
sudo ./random_packets 1 100 1
其中 第1行的64为频段编号
需要注意的是最后2行,0x4101是对发送速率的选择,需要根据自己的情况设置,每一位
的含义见下图。最后一行就是发送方发包命令,有4个参数,第一个是包的数量,第二个
是包的长度,第三个是模式,默认1就行。最后一个是发包间隔,单位us。
由于原来的setup_monitor_csi和setup_inject两个脚本运行会出现各种问题,所以需要修改一下,将代码替换到源文件就可以了。下面是两个脚本的代码:
setup_inject
#!/usr/bin/sudo /bin/bash
sudo modprobe -r iwldvm iwlwifi mac80211
modprobe -r iwlwifi mac80211 cfg80211
modprobe iwlwifi debug=0x40000
if [ "$#" -ne 2 ]; then
echo "Going to use default settings!"
chn=64
bw=HT20
else
chn=$1
bw=$2
fi
ifconfig wlan0 2>/dev/null 1>/dev/null
while [ $? -ne 0 ]
do
ifconfig wlan0 2>/dev/null 1>/dev/null
done
iw dev wlan0 interface add mon0 type monitor
ifconfig wlan0 down
while [ $? -ne 0 ]
do
ifconfig wlan0 down
done
ifconfig mon0 up
while [ $? -ne 0 ]
do
ifconfig mon0 up
done
iw mon0 set channel $chn $bw
setup_monitor_csi
#!/usr/bin/sudo /bin/bash
sudo modprobe -r iwldvm iwlwifi mac80211
modprobe -r iwlwifi mac80211 cfg80211
modprobe iwlwifi connector_log=0x1
if [ "$#" -ne 2 ]; then
echo "Going to use default settings!"
chn=64
bw=HT20
else
chn=$1
bw=$2
fi
iwconfig wlan0 mode monitor 2>/dev/null 1>/dev/null
while [ $? -ne 0 ]
do
iwconfig wlan0 mode monitor 2>/dev/null 1>/dev/null
done
ifconfig wlan0 up 2>/dev/null 1>/dev/null
while [ $? -ne 0 ]
do
ifconfig wlan0 up 2>/dev/null 1>/dev/null
done
iw wlan0 set channel $chn $bw
执行了上述所有操作后,我们可在接收端看到A电脑收到了数据,之后就可以对数据进行解析了。