Raizo62 / vwifi

Simulator of WiFi (802.11) interfaces to communicate between several Virtual Machines
GNU Lesser General Public License v3.0
57 stars 8 forks source link

What's the right config of TCP connection? #4

Closed sadnoodles closed 3 years ago

sadnoodles commented 3 years ago

I have followed the with-tcp part to setup, but got no lucky.

  1. First setup is: VM1(Debian):
    Running vwifi-server with IP 192.168.42.254

    VM2(Debian): Running ./vwifi-client 192.168.42.254 and hostapd. IP of wlan0 is 10.10.0.1.

    VM3(Debian): Running ./vwifi-client 192.168.42.254 and wpa_supplicant . IP of wlan0 is 10.10.0.2.

    All three VMs in VMware, same network 192.168.42.0/24. This set up can not connect to AP.

  2. Second setup is on Live Raizo: Host Machine running vwifi-server with IP 192.168.42.254.

    In GNS3:

    VM1(Debian): Running ./vwifi-client 192.168.42.254 (killed the systemd vwifi-client) and create_ap -n wlan0 MYSSID MYPASS

    VM2(Debian): Running ./vwifi-client 192.168.42.254 (killed the systemd vwifi-client) and edit /etc/network/interfaces and ifup wlan0

    VM1, VM2, Live Raizo, connected on a switch, they can ping each other.

    This set up VM2 can not get an IP from DHCP. And Host Machine can not find SSID.

Am I using TCP mode correctly? What's the correct setup of TCP mode? Can you provide some examples?

Raizo62 commented 3 years ago

Hi

Your description seem good.

First setup :

modprobe mac80211_hwsim radios=2

Second setup :

sadnoodles commented 3 years ago

Thank you very much for answering. So, basicly those two setups are workable? I will test Liveraizo without fast-vwifi later. My goal is get First setup work, because I cannot change the host machine.

In my First setup. vwifi-client can connect to vwifi-server. And I can see some traffic between server and client, using command tcpdump -ni ens3. Seems like hearbeat. But tcpdump -ni wlan0 shows nothing.

Some logs:

VM1(server):

# modprobe mac80211_hwsim radios=1
# macchanger -a wlan0
# ./vwifi-server                                
CLIENT VHOST : Listener on port : 8211
CLIENT TCP : Listener on port : 8212
SPY : Listener on port : 8213
CTRL : Listener on port : 8214
Size of disconnected : 15
Packet loss : disable
New connection from Client TCP : {[115904](0,0,0)}
New connection from Client TCP : {[115648](0,0,0)}

vwifi-ctrl ls shows like:

[115904](0,0,0)
[115648](0,0,0)

VM2(AP):

# modprobe mac80211_hwsim radios=1
# macchanger -a wlan0
# ./vwifi-client 192.168.42.254
Registered with family MAC80211_HWSIM
nl80211_init
Connection to Server Ok
ID: 115904

And I start AP with hostap tests/hostapd_wpa.conf conf com from vwifi git repo.

VM3(Client):

vwifi-client log same as VM2.

wpa_supplicant -Dnl80211 -iwlan0 -c tests/wpa_supplicant.conf for the client. from here

iw wlan0 link shows no link.

So what should I do to debug this?

I assume this is just like how VPN works. On client, hwsim0 collect traffics and vwifi-client send these traffics to vwifi-server through TCP. Then vwifi-server send to all the others. So vsock is not necessary. Am I right?


By the way, brilliant job!

sadnoodles commented 3 years ago

Does modprobe mac80211_hwsim radios=2 has to be 2? If so why?

Raizo62 commented 3 years ago

basicly those two setups are workable?

yes

My goal is get First setup work, because I cannot change the host machine

I understand

If you want to capture the traffic with tcpdump, you must do before :

sudo ip link set wlan0 down
sudo iw wlan0 set monitor control
sudo ip link set wlan0 up

On the server (VM1), the modprobe (modprobe mac80211_hwsim radios=1) is useless

If you want to use only tcp, the vsock is not necessary

The 2 in modprobe mac80211_hwsim radios=2 is the number of interface to create. You can use 1.

This day, i have tested with success with create_ap and the /etc/network/interfaces. I will test with the test config. But this worked.

Raizo62 commented 3 years ago

On each VM, you use the same version of vwifi ? (-v)

sadnoodles commented 3 years ago

Yes, same version, VMs are cloned.

On each VM, you use the same version of vwifi ? (-v)

Raizo62 commented 3 years ago

The config (wpa_supplicant.conf and hostapd_wpa.conf) works :

Raizo62 commented 3 years ago

In your case, hostapd (or create_ap) displays nothing when wpa_supplicant (or ifup) is started ?

sadnoodles commented 3 years ago

Succeed in the first setup. I got ping through AP and client. I don't know why for now, but I'm testing what change got me succeed.

sadnoodles commented 3 years ago

It has to be something with the NetworkManager and wpa_supplicant. I can not reproduce it every time, but I can reproduce often.

Just stop & start NetworkManager and wpa_supplicant on client machine. And you will encounter it sometimes: the client cannot connect to AP.

# wpa_supplicant -Dnl80211 -iwlan0 -c tests/wpa_supplicant.conf
Successfully initialized wpa_supplicant

wpa_supplicant stuck here, and hostapd got no output.

I have to reboot client machine to recover.

Raizo62 commented 3 years ago

NetworkManager is like networking. It does this own actions which can be in conflit with others program (yours). Often, it is advice to stop it if you use others programs (networking,wpa_supplicant...)

Or, you can use NetworkManager and use it to connect to hostapd

Raizo62 commented 3 years ago

does it work, now ?

sadnoodles commented 3 years ago

Tested a lot. Using NetworkManager with GUI on Kali to create AP, works very well. But when using hostapd, client just cannot connect. I don't have much time to test, I have too move on for now. I am using Kali's GUI to create AP. Sorry didn't found the difference between mine and yours. Maybe later, when I have time, I will test again.

sadnoodles commented 3 years ago

And maybe add some debug log will help ? Is there any advice to locate?

Raizo62 commented 3 years ago

client just cannot connect

On AP, you have in the same time NetworkManager and hostapd ? and on Client, you have NetworkManager and wpa_supplicant ? or other ?

And maybe add some debug log will help ? Is there any advice to locate?

Debug in vwifi ? :

In Makefile : uncomment the line "MODE= -g -Wall -Wextra -pedantic -D_DEBUG" (and comment the other) In src/config.h, you can add or remove the level of warning to uncomment "#define _VERBOSE1" or #define _VERBOSE2"

sadnoodles commented 3 years ago

No, I didn't use them on same machine. NetworkManager is on kali, AP and Client are both kali. hostapd is on debian in gns3/vmware.

On AP, you have in the same time NetworkManager and hostapd ? and on Client, you have NetworkManager and wpa_supplicant ? or other ?

Maybe we can close this issue now. We can not fix an unknow bug.