Simulate Wi-Fi (802.11) between Linux Virtual Machines on Qemu/VirtualBox/...
It can be used in Hypervisors (GNS3, QEmu, Virtualbox, VMware, Hyper-V, ...)
The Wireless emulator uses the mac80211_hwsim
linux driver
Implements the packet loss simulation based on distance
Emulates the node mobility in GNS3
Tested:
hostapd
and wpa_supplicant
with these configurations:
Aircrack-NG
(Kali / Parrot-OS)Remaining features to be implemented:
With the parameter "-h" (or "--help"), all programs display help and their parameters
vwifi-client should be started on the VMs, and vwifi-server on the Host.
vwifi-client and vwifi-server can communicate either with the VHOST protocol (by default), or with the TCP protocol.
With the option "-s" (or "--spy"), vwifi-client :
vwifi-client uses the mac80211_hwsim
kernel module to have the wifi interfaces.
To use TCP protocol, vwifi-server and vwifi-client must be connected to a different IP network than that of the wifi.
vwifi-add-interfaces is used to create the wlan interfaces to the module mac80211_hwsim
. vwifi-client controls only these interfaces. vwifi-add-interfaces can be run several times.
vwifi-ctrl is used to interact with vwifi-server.
vwifi-server can directly enable packet loss with the parameter "-l" (or "--lost-packets")
If vwifi-server detects the same IP for several vwifi-client (due to PAT/NPAT/...), use the option "-u" ("-- use-port-in-hash") on vwifi-server to add the network port to create the ID for each client, instead of just using the IP. Attention, the display of ID by vwifi-server and vwifi-client will no longer be the same.
You can change the defaults IP and ports with parameters (see the parameter "-h" to help)
sudo apt-get install make g++
sudo apt-get install libnl-3-dev libnl-genl-3-dev
make gitversion # To add the last commit id to the VERSION
make update # To download and update the file mac80211_hwsim.h
To change the default ports and IP, edit : src/config.h
To building :
make
make tools # To change the file mode bits of tools
sudo make install
Shell :
# sudo modprobe -r vhost_vsock vmw_vsock_virtio_transport_common vsock # if necessary
sudo modprobe vhost_vsock sudo chmod a+rw /dev/vhost-vsock
* Start the ***vwifi-server*** :
```bash
vwifi-server
Hypervisor
-device vhost-vsock-pci,id=vwifi0,guest-cid=NUM
with NUM an identifier greater than 2-device vhost-vsock-pci,id=vwifi0,guest-cid=%guest-cid%
Load the necessary module mac80211_hwsim with 0 radios :
sudo modprobe mac80211_hwsim radios=0
Create the wlan interfaces (on this example, 2 interfaces) :
sudo vwifi-add-interfaces 2 0a:0b:0c:03:02
Connect all these wlan interfaces to the vwifi-server :
sudo vwifi-client
vwifi-client displays the CID of the VM in the Hypervisor. It is used by vwifi-server to identify this guest.
vwifi-server
Load the necessary module mac80211_hwsim with 0 radios :
sudo modprobe mac80211_hwsim radios=0
Create the wlan interfaces (on this example, 2 interfaces) :
sudo vwifi-add-interfaces 2 0a:0b:0c:03:02
Connect all these wlan interfaces to the vwifi-server :
sudo vwifi-client 172.16.0.1
vwifi-client displays an ID which is an hashsum of the IP. It is used by vwifi-server to identify this guest.
sudo modprobe mac80211_hwsim radios=0
sudo vwifi-client -s -n 1
sudo ip link set wlan0 down
sudo iw wlan0 set monitor control
sudo ip link set wlan0 up
sudo tcpdump -n -i wlan0
sudo wireshark
Show the list of connected guest (display : cid and coordinate x, y z) :
vwifi-ctrl ls
Set the new coordinate (11, 12, 13) of the guest with the cid 10 :
vwifi-ctrl set 10 11 12 13
Set the name "AP" of the guest with the cid 10 :
vwifi-ctrl setname 10 AP
Enable the lost of packets :
vwifi-ctrl loss yes
Disable the lost of packets :
vwifi-ctrl loss no
Display the config of vwifi-server :
vwifi-ctrl status
Display the distance in meters between the guest with the cid 10 and the guest with the cid 20 :
vwifi-ctrl distance 10 20
Set the scale of the distances between the clients to 0.005
vwifi-ctrl scale 0.005
sudo apt install hostapd wpasupplicant
sudo ip a a 10.0.0.1/8 dev wlan0
sudo hostapd tests/hostapd_wpa.conf
sudo wpa_supplicant -Dnl80211 -iwlan0 -c tests/wpa_supplicant.conf
sudo ip a a 10.0.0.2/8 dev wlan0 ping 10.0.0.1
* Guest Wifi 3 :
```bash
sudo wpa_supplicant -Dnl80211 -iwlan0 -c tests/wpa_supplicant.conf
sudo ip a a 10.0.0.3/8 dev wlan0
ping 10.0.0.2
sudo apt install hostapd iw tcpdump
sudo ip a a 10.0.0.1/8 dev wlan0
sudo hostapd tests/hostapd_open.conf
sudo ip link set up wlan0
sudo iw dev wlan0 connect mac80211_open
sudo ip a a 10.0.0.2/8 dev wlan0 ping 10.0.0.1
* Guest Wifi 3 :
```bash
sudo ip link set up wlan0
sudo tcpdump -n -e -I -i wlan0 -w /hosthome/projects/vwifi_capture_wlan0.pcap
tail -f -c +0b /home/user/projects/vwifi_capture_wlan0.pcap | wireshark -k -i -
sudo apt install iw
sudo ip link set up wlan0
sudo iw wlan0 set type ibss
sudo iw wlan0 ibss join MYNETWORK 2412 # frequency 2412 is channel 1
sudo ip a a 10.0.0.1/8 dev wlan0
* Guest Wifi 2 :
```bash
sudo ip link set up wlan0
sudo iw wlan0 set type ibss
sudo iw wlan0 ibss join MYNETWORK 2412 # frequency 2412 is channel 1
sudo ip a a 10.0.0.2/8 dev wlan0
ping 10.0.0.1
sudo apt install hostapd
sudo ip a a 10.0.0.1/8 dev wlan0
sudo hostapd tests/hostapd_wep.conf
cat << EOF | sudo tee -a /etc/network/interfaces > /dev/null
iface wlan0 inet static wireless-essid AP_WEP wireless-key 123456789a address 10.0.0.2 netmask 255.255.255.0
EOF sudo ifup wlan0
ping 10.0.0.1
# Others Tools
* start-vwifi-client.sh : do all the commands necessary to start ***vwifi-client*** on a Guest
* fast-vwifi-update.sh : set with ***vwifi-ctrl*** the coordinates of each VMs which has the option `guest-cid=`, found in the open project of GNS3
* client.sh : configure the client wifi with Open or WPA
* Makefile.dependency.sh : generate automatically the file "Makefile.in", include in "Makefile", which contains dependencies for "make"