Activity Log: كل حاجة بالوقت
ليه كل خطوة لازم يبقى عليها وقت بالـ UTC، وإزاي تعمل Activity Log بسيط بـ Python وتحفَظه في ملف.
نص شرح المعلم والكود الذي كتبه ونتيجة تشغيله، بنفس ترتيب الدرس.
أهلاً بيك. تخيّل إن الـ server بتاع العميل وقع الساعة اتنين الضهر، وفي نفس اليوم إنت كنت بتعمل Pentest. أول سؤال هيتسأل: إنت السبب؟
هنا الـ Activity Log بيحميك. كل command عملته، بالوقت بالزبط. لو العميل سأل، تقوله: الساعة دي أنا كنت بعمل كدا بالزبط. وكمان فريق الأمن عند العميل بيقارن الـ Log بتاعك باللي شافوه عندهم.
وخد بالك من الوقت نفسه: استخدم UTC، علشان العميل ممكن يكون في بلد تاني. واكتب التاريخ كامل، مش الساعة بس. نعمل function اسمها note، بتاخد العملية والنتيجة، وتضيف الوقت لوحدها. نشغّل… كل سطر عليه الوقت، والـ command، والنتيجة.
from datetime import datetime, timezone
log = []
def note(action, result):
t = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
log.append((t, action, result))
note("nmap -sV 10.10.10.5", "22 ssh, 80 http open")
note("gobuster dir on port 80", "found /admin")
for t, action, result in log:
print(f"[{t}] {action} -> {result}")المخرجات
[2026-10-12 10:00:34 UTC] nmap -sV 10.10.10.5 -> 22 ssh, 80 http open [2026-10-12 10:00:34 UTC] gobuster dir on port 80 -> found /admin
بس الـ log ده هيضيع لو قفلنا البرنامج. خلّينا نحفَظه في ملف اسمه activity dot log. نشغّل… كده اتحَفَظ في ملف، وتقدر ترجعله في أي وقت.
from datetime import datetime, timezone
log = []
def note(action, result):
t = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
log.append((t, action, result))
note("nmap -sV 10.10.10.5", "22 ssh, 80 http open")
note("gobuster dir on port 80", "found /admin")
with open("activity.log", "w") as f:
for t, action, result in log:
f.write(f"[{t}] {action} -> {result}\n")
print(open("activity.log").read())المخرجات
[2026-10-12 10:00:34 UTC] nmap -sV 10.10.10.5 -> 22 ssh, 80 http open [2026-10-12 10:00:34 UTC] gobuster dir on port 80 -> found /admin
دورك: ضيف note تالتة: إنك جرّبت login على admin بباسورد admin، والنتيجة success.
ضيف note("login admin:admin on /admin", "success") قبل الحفظ.
الحل: نشغّل…
from datetime import datetime, timezone
log = []
def note(action, result):
t = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
log.append((t, action, result))
note("nmap -sV 10.10.10.5", "22 ssh, 80 http open")
note("gobuster dir on port 80", "found /admin")
note("login admin:admin on /admin", "success")
with open("activity.log", "w") as f:
for t, action, result in log:
f.write(f"[{t}] {action} -> {result}\n")
print(open("activity.log").read())المخرجات
[2026-10-12 10:00:34 UTC] nmap -sV 10.10.10.5 -> 22 ssh, 80 http open [2026-10-12 10:00:34 UTC] gobuster dir on port 80 -> found /admin [2026-10-12 10:00:34 UTC] login admin:admin on /admin -> success
الدرس الجاي: بدل ما تكتب كل command بإيدك… نخلّي الـ terminal يسجّل كل حاجة لوحده. يلا بينا.
03 / دروس المسار (21)
- 01ليه التقرير أهم حاجة في الـ Pentest
- 02مين بيقرا التقرير؟
- 03نظام Notes من أول دقيقة
- 04Activity Log: كل حاجة بالوقتانت هنا
- 05خلّي الـ Terminal يسجّل لوحده
- 06الأدلة: إيه اللي يعتبر دليل؟
- 07سلامة الأدلة: Hash و Chain of Custody
- 08إخفاء البيانات الحساسة (Redaction)
- 09خطوات إعادة التنفيد (Steps to Reproduce)
- 10الـ Impact: الخطر الحقيقي على البيزنس
- 11CVSS: الخطورة برقم
- 12الـ Risk Matrix: الاحتمال في الـ Impact
- 13ترتيب الأولويات والـ Quick Wins
- 14هيكل تقرير اختبار الاختراق
- 15الـ Executive Summary: صفحة للإدارة
- 16كتابة الـ Finding التقني
- 17توصيات الإصلاح اللي تتنفّد فعلاً
- 18خلّي Python يكتب التقرير
- 19المراجعة قبل التسليم والـ Retest
- 20تقرير امتحان OSCP
- 21المراجعة النهائية: من الـ Note للتقرير