36.4 Netcat and Socat: The Network Swiss Army Knife
Netcat (nc) – "TCP/UDP cha Swiss army knife". Listen, connect, file transfer, simple banner grab – ekach binary. Socat – Netcat cha power-up: TLS, relays, forks, more address types.
Listen ani connect (lab):
# Terminal A on Metasploitable / any lab host – listen
nc -lvp 4444
# Terminal B on Kali – connect
nc 192.168.56.20 4444
# type messages both ways – chat over TCP
File transfer (lab):
# receiver
nc -lvp 9001 > received.txt
# sender
nc 192.168.56.10 9001 < notes.txt
Reverse / bind shell – CONCEPT (defensive): attacker victim la connect karun shell milavto (reverse: victim outbound Kali kade; bind: victim port open, Kali connect). Lab madhe samjun ghya, production madhe detect kara:
# On a lab host you own – see unexpected listeners
ss -tulnp
netstat -tulnp
# Look for odd ports (4444, 5555, 1234) listening or established
Socat basics:
sudo apt install -y socat
# simple relay: local 8080 -> lab web
socat TCP-LISTEN:8080,fork TCP:192.168.56.20:80
# TLS wrapper idea (own certs in lab)
# socat OPENSSL-LISTEN:8443,cert=lab.pem,verify=0 TCP:127.0.0.1:80
Defence: egress firewall (outbound odd ports band), host firewall, ss/netstat monitoring, EDR alerts on nc/socat spawning shells, least privilege. Bind shell sathi inbound unused ports band. Samjla ka?
Shells are real attack techniques
Reverse/bind shells IT Act khali unauthorized access madhe yetat. Fact lab VMs (192.168.56.10 / .20) ani written permission. Real network var try karu naka.
Ravindra Bagale's Tip
Students learn nc -e /bin/bash (exec shell) and think that is "hacking". In modern netcat builds -e is often not available – and it is the concept that matters, not the flag. In interviews: "How would you detect a reverse shell?" – ss, firewall egress, process ancestry. Detecting earns more marks than running the tool.
Ravindra Bagale's Tip – मराठी
Students nc -e /bin/bash (exec shell) शिकून थेट "hacking" समजतात. Modern netcat builds मध्ये -e बऱ्याचदा नसतो – आणि concept महत्त्वाचा आहे, flag नाही. Interview मध्ये: "How would you detect a reverse shell?" – ss, firewall egress, process ancestry. Tool चालवण्यापेक्षा detect करणे जास्त marks देते.
Ravindra Bagale's Tip – हिंदी
Students nc -e /bin/bash (exec shell) सीखकर सीधे उसे "hacking" समझ लेते हैं. Modern netcat builds में -e अक्सर नहीं होता – और concept ज़रूरी है, flag नहीं. Interview में: "How would you detect a reverse shell?" – ss, firewall egress, process ancestry. Tool चलाने से ज़्यादा detect करना marks दिलाता है.
Lab
Kali ani Metasploitable madhe Netcat chat set kara (port 4444). Mag ek chota text file transfer kara. Dono hosts var ss -tulnp | grep 4444 – listener disto ka te bagha. Lab session samplya var listener band kara. Socat ne ek simple TCP relay try kara (8080 -> .20:80) ani browser madhun http://127.0.0.1:8080 open kara.
Extended teaching notes
Why this lesson matters
A SOC turns logs into action. Good juniors triage with playbooks: what fired, which asset, how bad, contain or escalate, write the timeline.
- Prepare: asset list, contacts, runbooks.
- Detect: SIEM/EDR alerts with context.
- Contain: disable account, isolate host, block IOC.
- Eradicate & recover: patch, rebuild, restore.
- Lessons: one improvement ticket per incident.
Indian company (sample)
A 24×7 SOC at a large Indian IT services firm handles phishing and malware for many clients. Tier-1 analysts follow a script; they do not freestyle on production.
Mini case study
Suppose we are on a purple-team exercise for an Indian mid-size company (sample data). Red notes a technique from this lesson against a lab clone. Blue must show the control that stops it, the log that would have fired, and the ticket that hardens production. That is the standard this course trains you for.
Defender's worksheet (do this today)
- Write the lesson title, date and the exact lab target you are allowed to use.
- List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
- Run one safe check from the lesson on a lab system only. Paste the command and output.
- Write a two-sentence fix you would give a teammate.
- Name one related public advisory (CERT-In, CISA, NVD, or a vendor bulletin) with its date.
Indian workplace (sample data)
Suppose we are a junior analyst at Infosys, TCS, Wipro or a fintech SOC in Bengaluru/Pune. Turn this lesson into one checklist item with an owner, a due date and a place to store evidence (ticket + screenshot).
Global practice
Compare your notes with OWASP, CIS Benchmarks, NIST CSF/IR guidance or a cloud Well-Architected security question. Write five lines on what overlaps.
Everyday analogy
Explain the risk and the fix to a family member without jargon. If they can repeat the warning, you understand it well enough to teach juniors.
Key terms
- Control: a safeguard (patch, config, process, detection).
- Finding: a weakness backed by evidence.
- Remediation: the fix plus how you verified it.
- Scope: systems you have written permission to touch.
- Least privilege: only the access the task needs.
- Defence in depth: several layers so one failure does not end the story.
Common mistakes
- Skipping written permission "just for a quick scan".
- Practising on hostel, office or public targets without authorisation.
- Collecting tool output without writing the fix.
- Copying attack steps onto production to "verify". Defenders verify with versions, configs and patches.
- Publishing screenshots that contain secrets, cookies or internal hostnames.
Recap
- Evidence, fix, owner, date.
- Own lab only.
- Fix > spectacle.