My friend connected to WIFI and after 5 minutes he told me which sites I had actually been browsing, and who I chat with.
My question is: how do I defend myself against this, and also how did he do this?
Information Security Stack Exchange is a question and answer site for information security professionals. It only takes a minute to sign up.Sign up to join this community
In a WiFi network, all information which is sent over the network is broadcasted over the air. Usually network interfaces are configured to just ignore any network traffic not addressed to them, but there are tools available which change them to "promiscuous mode" which allows them to also log and show any traffic which they receive even though it is directed at other network participants. Although WiFi networks are usually encrypted nowadays, the key is shared between all participants, so any network participant can eavesdrop on the traffic of everyone else.
The only defense against this is end-to-end encryption.
For casual webbrowsing, you should try to always use the
https:// version of a website. That way a sniffer on your WiFi network will only learn the domain you browse, but not which specific URL, what you read there and what you send there. When someone would eavesdrop on you right now, they would learn that you made a TLS handshake with
https://security.stackexchange.com but not that the exact URL you view is
https://security.stackexchange.com/questions/74471/how-to-know-what-other-browse-through-the-network/ and what you are currently reading here. Should you choose to comment on this, that outgoing message would also be encrypted. I recommend the browser extension HTTPS Everywhere which makes your webbrowser prefer https over http whenever possible.
Regarding chatting: Many chat systems do not offer encryption. When you are security-conscious, you should refuse to use these. There are too many chat systems available to list them all here, but the Electronic Frontier Foundation has a good comparison of the security features of many chat systems.
However, when you have a high security need, the best way to protect yourself on a public WiFi network without having to change most of your habits is to pay for a VPN service. With a VPN service, all your internet activity is routed through an encrypted channel to a server on the internet which then works as a proxy. As long as you trust your VPN provider, this allows you to do confidential internet activity from an untrusted network. The greatest advantage is that this works for any network traffic, so it does not matter if the software you use encrypts or not. However, keep in mind that the connection is only secured between you and the VPN provider. This 1. means that your VPN provider could eavesdrop and 2. that the connection between the VPN provider and your destination is unsecured.
Your friend is likely using a network packets capture tool like wireshark or tcpdump to collect data that are transferred from and to your machine.
At least to make it hard to your friend you have to use services or websites that offer data encryption which is commonly implemented using TLS, for instance when you are browsing a website make sure the website adress starts with https and not http.
In order to Protect yourself, use high security encrption level like WPA2. It assing differnet Keys to each WiFi Client.
How to trace:
Other than that, you can impose a transparent proxy on your network and monitor activities from there. Also, you can log connection history using a pfSense box.
Most of this comes under softcore hacking. Hacking, however, is illegal, under any pretext whatsoever. You can get sued if there's a security breach/identity theft/phishing attack on the network just because you previously tried to do the same. Your computer can be stripped for evidences. Likely is that you'll get into trouble. Now that you know this stuff doesn't mean that you should immediately test it out, and that too on a third person.
Disclaimer: I'm in no way endorsing hacking/spoofing.
Although https (SSL/TLS) is a security layer you really want to use wherever and whenever possible, it is not always available, such as with a lot of chat services.
If you enable proper wifi security settings (WPA2) with (one) password that is known to everyone who needs access to the network, each client (and each session) gets its own unique encryption keys that makes it practically impossible to listen to the traffic of other users.
Using a wireless card in promiscious mode on such a network will only show the encrypted traffic.
This way, even if users or applications aren't using HTTPS enabled webpages are still protected with WPA2.
A VPN, as suggested in the other answer is also a solution, but is much more difficult (an more expensive) to setup.