CybersLion

नेटवर्क स्निफ़िंग टूल्स — Wireshark, tcpdump, Scapy और प्रैक्टिकल लैब्स

 

नेटवर्क स्निफ़िंग टूल्स — विस्तृत उपयोग और प्रैक्टिस 

मेटा विवरण: जानें कैसे नेटवर्क स्निफ़ करें—Wireshark, tcpdump, tshark, Scapy, Ettercap, Kismet के साथ स्टेप-बाय-स्टेप कमांड, प्रयोग और सुरक्षा उपाय। केवल अधिकृत नेटवर्क पर प्रयोग करें।


1. परिचय

नेटवर्क स्निफ़िंग का अर्थ है नेटवर्क पर बहने वाले पैकेटों को पकड़ना (capture) और उनका विश्लेषण करना। यह नेटवर्क ट्रबलशूटिंग, इनसिडेंट रिस्पॉन्स और एथिकल हैकिंग में अत्यंत उपयोगी है। चूँकि यह संवेदनशील जानकारी (पासवर्ड, कुकीज़) दिखा सकता है, केवल अपने या अनुमति प्राप्त नेटवर्क पर ही प्रयोग करें।

यह गाइड प्रमुख टूल और व्यावहारिक अभ्यास के साथ उपयोग की जानकारी देती है।


2. मुख्य टूल और इंस्टॉलेशन

  • Wireshark — GUI आधारित गहरा विश्लेषण।
    sudo apt install wireshark

  • tcpdump — कमांड-लाइन कैप्चर।
    sudo apt install tcpdump

  • tshark — Wireshark का CLI वैरिएंट।
    sudo apt install tshark

  • Scapy — पाइथन-आधारित पैकेट क्राफ्टिंग/स्निफ़िंग।
    pip3 install scapy

  • Ettercap/Bettercap — MITM प्रयोग (सिर्फ लैब)।

  • Kismet — वायरलेस स्निफ़िंग और डिस्कवरी।

  • ngrep — पैटर्न-आधारित पैकेट खोज।

  • NetworkMiner — पैसिव फॉरेंसिक्स टूल।


3. बेसिक कैप्चर और विश्लेषण

tcpdump से कैप्चर

पूरा पॅकट कैप्चर फ़ाइल बनाएं:

sudo tcpdump -i eth0 -s 0 -w /tmp/capture.pcap

HTTP ट्रैफ़िक टेक्स्ट में देखने के लिए:

sudo tcpdump -i eth0 -nn -A 'tcp port 80'

Wireshark में लाइव एनालिसिस

  1. इंटरफ़ेस चुनें (eth0/wlan0)।

  2. Capture filters: tcp port 80, host 10.0.0.5 आदि।

  3. Display filters: http.request, ip.addr == 192.168.1.10

  4. किसी पैकेट पर Follow → TCP Stream से पूरे संवाद को देखें।

tshark से फील्ड एक्सट्रैक्ट

tshark -r capture.pcap -Y http.request -T fields -e http.host -e http.user_agent

ngrep का प्रयोग

HTTP में किसी पैटर्न को खोजने के लिए:

sudo ngrep -d eth0 -W byline 'password|' 'tcp and port 80'

4. एडवांस्ड: Scapy और ऑटोमेशन

Scapy स्निफ़ उदाहरण:

from scapy.all import sniff sniff(filter="tcp", prn=lambda p: p.summary(), count=10, iface="eth0")

Scapy से पैकेट क्राफ्टिंग और इवैल्यूएशन भी किया जा सकता है।


5. प्रैक्टिकल लैब्स (सुरक्षित वातावरण में)

लैब A — HTTP में पासवर्ड कैप्चर

  1. Attacker VM: sudo tcpdump -i eth0 -s 0 -w lab_http.pcap

  2. Victim VM: टेस्ट HTTP साइट पर लॉगिन करें।

  3. Wireshark खोलें और http.request.method == "POST" फ़िल्टर लगाकर क्रेडेंशियल देखें।

लैब B — ARP स्पूफिंग (केवल लैब)

  1. Attacker VM पर Ettercap/Bettercap से ARP स्पूफ करें।

  2. कैप्चर करके ट्रैफ़िक देखें।

  3. Mitigation: स्विच पर DAI सक्षम करें और हमला विफल देखें।

लैब C — वायरलेस डिआथेरेंटेशन डिटेक्शन

Kismet से AP और क्लाइंट फ्रेम कैप्चर करें और डिआथ के पैटर्न पहचानें।


6. कैप्चर का विश्लेषण — क्या देखें

  • प्लैनटेक्स्ट क्रेडेंशियल्स: HTTP POST/FTP/Telnet आदि।

  • कुकीज़ और सेशन आइटम: Set-Cookie, Cookie — सेशन हाईजैक का खतरा।

  • अनजान होस्ट: गैर-मान्य एक्सटर्नल कनेक्शन।

  • प्रोटोकॉल विसंगतियाँ: DNS के माध्यम से डेटा टनलिंग इत्यादि।


7. डिटेक्शन और सुरक्षा उपाय

  • ट्रैफिक एन्क्रिप्ट करें: TLS/HTTPS अनिवार्य करें।

  • नेटवर्क सेगमेंटेशन और VLANs लागू करें।

  • स्विच सुरक्षा: Port security, DHCP snooping, Dynamic ARP Inspection चालू रखें।

  • VPN और एन्क्रिप्टेड टनल्स का उपयोग करें।

  • प्रोमिसक्यूअस मोड मॉनिटरिंग से स्निफ़र का पता लगाएँ।


8. कानूनी और एथिकल बातें

  • बिना लिखित अनुमति के किसी नेटवर्क पर स्निफ़िंग करना गैरकानूनी और अनैतिक है।

  • टेस्टिंग से पहले ऑथराइज़ेशन लें और सभी निष्कर्ष दस्तावेज़ करें।

  • संवेदनशील डेटा पाए जाने पर कंपनी की नीति और कानून के अनुरूप रिपोर्ट करें।


9. सामान्य प्रश्न (FAQs)

Q: पहली बार किस टूल से शुरू करूँ?
A: tcpdump से कैप्चर और Wireshark में विश्लेषण — यह बेसिक और शक्तिशाली है।

Q: क्या मैं HTTPS पढ़ सकता/सकती हूँ?
A: नहीं, बिना सर्वर की प्राइवेट की या सफल MITM के HTTPS payload नहीं पढ़ सकते। केवल मेटाडेटा दिखाई देगा (SNI, IP)।

Q: कैसे पता चलेगा कि कोई स्निफ़र है?
A: अजीब MAC/IP मैपिंग, ARP टेबल में अनपेक्षित प्रविष्टि, या पोर्ट-सिक्योरिटी अलर्ट से संकेत मिलता है।



Network Sniffing Tools — Wireshark, tcpdump, Tshark, Scapy & Practical Labs

 

Network Sniffing Tools — Detailed Usage with Practice 

Meta Description: Learn how to use network sniffing tools (Wireshark, tcpdump, tshark, Scapy, Ettercap, Kismet) with step-by-step commands, hands-on labs, interpretation tips, and defensive measures. For ethical hackers & students.


1. Introduction

Network sniffing is the process of capturing and analyzing packets that flow across a network. For ethical hackers, security analysts, and network administrators, sniffing is essential for troubleshooting, incident response, and penetration testing. But because sniffing can expose sensitive data (passwords, cookies, internal hosts), always perform it only on networks you own or have explicit permission to test.

This guide gives you practical, tool-focused workflows and labs using the most common sniffers: Wireshark, tcpdump, tshark, Scapy, Ettercap/Bettercap, Kismet, ngrep, and NetworkMiner — plus prevention and detection techniques.


2. Core Tools & Quick Install

  • Wireshark — GUI packet capture & analysis.
    sudo apt install wireshark

  • tcpdump — CLI packet capture (writing/reading pcap).
    sudo apt install tcpdump

  • tshark — Wireshark’s CLI (parsing & extraction).
    sudo apt install tshark

  • Scapy — Python packet crafting & sniffing.
    pip3 install scapy

  • Ettercap / Bettercap — MITM/ARP spoofing frameworks (use in labs only).
    sudo apt install ettercap-common ettercap-graphical or apt install bettercap

  • Kismet — Wireless sniffing, discovery, and capture.
    sudo apt install kismet

  • ngrep — grep-like packet matching for quick pattern searching.
    sudo apt install ngrep

  • NetworkMiner — Passive network forensics (Windows/.NET or Linux mono). Download from vendor site.


3. Basic Capture & Analysis Workflows

3.1 Capture with tcpdump

Create a full capture file for later analysis:

sudo tcpdump -i eth0 -s 0 -w /tmp/capture.pcap # -i eth0 -> interface, -s 0 -> snaplen (capture entire packet), -w -> write pcap

Capture HTTP traffic only and print payload in ASCII:

sudo tcpdump -i eth0 -nn -A 'tcp port 80' # -nn prevents name resolution, -A prints ASCII payload

Stop with Ctrl+C. Open capture.pcap in Wireshark for deep analysis.

3.2 Live GUI Analysis with Wireshark

  1. Launch Wireshark, select interface (e.g., eth0 or wlan0).

  2. Apply capture filters to reduce noise:

    • tcp port 80 (capture only HTTP)

    • host 10.0.0.5 (capture from/to host)

  3. Use display filters to focus after capture:

    • http.request or http.request.method == "POST"

    • ip.addr == 192.168.1.10 && tcp.port == 443

  4. Right-click a TCP packet → FollowTCP Stream to view full conversation (useful for reconstructing HTTP credentials in plaintext).

Tip: Use View → Name Resolution sparingly — resolving names can slow capture display.

3.3 Command-line parsing with tshark

Extract fields quickly from pcap:

tshark -r capture.pcap -T fields -e frame.time -e ip.src -e ip.dst -e tcp.port -E separator=,

Find HTTP hosts:

tshark -r capture.pcap -Y http.request -T fields -e http.host -e http.user_agent

3.4 Quick pattern matching with ngrep

Search live traffic for a string (e.g., login=):

sudo ngrep -d eth0 -W byline 'login=' 'tcp and port 80'

ngrep is handy for spotting cleartext credentials fast.

3.5 Wireless sniffing with Kismet

Start Kismet (requires compatible wireless card in monitor mode):

sudo kismet

Kismet discovers access points, captures management/data frames, and logs pcap files for Wi-Fi analysis.


4. Advanced: Scapy & Tshark Automation

4.1 Scapy sniff example (Python)

Capture 10 TCP packets and print a summary:

from scapy.all import sniff def show(pkt): print(pkt.summary()) sniff(filter="tcp", prn=show, count=10, iface="eth0")

Scapy can also rebuild sessions, craft packets to test network behavior, or export captures.

4.2 Extract HTTP URIs from pcap with tshark

tshark -r capture.pcap -Y http.request -T fields -e http.request.method -e http.host -e http.request.uri

Great for automated reconnaissance reports.


5. Practical Labs (Hands-on, safe environment)

Setup: Use two VMs (Attacker and Victim) on an isolated lab network (no internet exposure), or a physical lab VLAN with explicit permission.

Lab A — Plaintext HTTP credential capture

  1. On Attacker: run sudo tcpdump -i eth0 -s 0 -w lab_http.pcap.

  2. On Victim: browse an intentionally configured test web app that uses HTTP (not HTTPS) and log in.

  3. Stop capture; open lab_http.pcap in Wireshark.

  4. Filter: http.request.method == "POST"Follow TCP Stream → find credentials.

Learning: Shows why TLS matters — credentials visible on network when unencrypted.

Lab B — ARP spoofing MITM (educational only)

  1. Configure lab with isolated VMs.

  2. Use Ettercap/Bettercap on Attacker to ARP-poison Victim ↔ Gateway.

  3. Run Wireshark on Attacker to capture intercepted traffic.

  4. Mitigation exercise: enable dynamic ARP inspection on switch and observe how attack fails.

Ethics: Only perform in lab/scope. ARP spoofing is intrusive and illegal outside authorized testing.

Lab C — Wireless deauthentication detection

  1. Use Kismet to capture AP and client frames.

  2. Generate deauth frames in a lab AP (with tools like aireplay-ng on a test AP).

  3. Observe repeated deauths in Kismet logs and analyze frame details.


6. Interpreting Captures — What to Look For

  • Plaintext credentials: HTTP POSTs, FTP, Telnet, POP3, IMAP unencrypted.

  • Session cookies: Look for Set-Cookie / Cookie headers — session hijacking risk if not secure/HTTPOnly.

  • Unusual traffic patterns: Large volumes or repeated connection attempts may indicate exfiltration or scanning.

  • Unexpected hosts: Internal systems contacting unknown external IPs—indicator of compromise.

  • Protocol anomalies: Suspicious DNS TXT records, large base64 payloads in DNS — data tunneling signs.


7. Detection & Hardening (Preventive Measures)

  • Encrypt traffic: Enforce HTTPS/TLS for all apps; use HSTS and secure cookie flags.

  • Use network segmentation & VLANs to limit broadcast domains and sniffing exposure.

  • Switch security: Enable port security, DHCP snooping, Dynamic ARP Inspection (DAI).

  • Certificate pinning & mutual TLS for sensitive apps.

  • Monitor for ARP anomalies and suspicious MAC/IP mappings.

  • Use VPNs and encrypted tunnels for remote access.

  • Disable promiscuous mode detection alarms to catch suspicious sniffers.


8. Legal & Ethical Considerations

Network sniffing is a powerful capability that can easily be abused. Always:

  • Obtain written authorization before testing.

  • Keep logs and time-stamped captures for auditing.

  • Follow responsible disclosure if you find sensitive data leaks.

  • Avoid capturing personal data unless explicitly required for the test and permitted by policy/law.


9. FAQs

Q: Which tool is best for beginners?
A: tcpdump + Wireshark. tcpdump for quick captures; Wireshark to analyze visually.

Q: Can I sniff HTTPS traffic?
A: You cannot read HTTPS payloads without the server’s private key or a successful MITM (which requires credentials/certificates). Focus on metadata (SNI, IPs) instead.

Q: How to detect someone sniffing my network?
A: Monitor for promiscuous mode, unexpected ARP table changes, odd MAC/IP pairs, or unknown switch port activity. IDS/IPS can help.

Q: What’s the difference between capture filters and display filters in Wireshark?
A: Capture filters (BPF) limit what is stored; display filters only limit what you see after capture.