ENع
→Backups
الدرس 20 · العمليات الأمنية

Backups and ransomware resilience

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

12 دقيقة11 خطوة5 أسئلةAdvanced
عن هذا الدرس

No defence stops every attack, so resilient organisations plan to recover. Follow one small shop that backs up its orders file by the 3-2-1 rule, saves a SHA-256 fingerprint with an eleven-line Python program, and keeps one copy offline. Ransomware then encrypts the server and the always-connected backup, but cannot reach the offline vault. Watch the shop isolate, rebuild, restore, check the fingerprint and practise against its recovery point and recovery time objectives (RPO and RTO).

ستتعلّم

حدّد ما تشعر بأنك أتقنته. هذا التقييم الذاتي لا يؤثر في درجة الدرس.

شكل 20 · تفاعلي
01 / 11

Plan to recover

No defence stops every attack, so resilient organisations plan to recover. A backup is a separate copy of data you can restore from. Our example: a small shop keeps orders.csv on its server, with a network drive (NAS) and an offline vault.

resilience   keep working, and recover when
             something gets through
backup       a separate copy you can restore from
server       orders.csv (the primary copy)
NAS          network drive, always connected
vault        a drive kept offline and off-site
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. Plan to recover

    No defence stops every attack, so resilient organisations plan to recover. A backup is a separate copy of data you can restore from. Our example: a small shop keeps orders.csv on its server, with a network drive (NAS) and an offline vault.

    resilience   keep working, and recover when
                 something gets through
    backup       a separate copy you can restore from
    server       orders.csv (the primary copy)
    NAS          network drive, always connected
    vault        a drive kept offline and off-site
  2. The 3-2-1 rule

    A classic rule from US-CERT, now part of CISA: keep 3 copies of important data (1 primary, 2 backups), on 2 different media types, with 1 copy off-site. Here: the server, the NAS, and a vault drive kept elsewhere.

    3  copies of important data: 1 primary and 2 backups
       here: server · NAS · vault
    2  different media types
       here: NAS disks · removable vault drive
    1  copy off-site
       here: the vault, kept away from the shop
  3. Lines 2–6: save a fingerprint

    Lines 2 to 5 define sha(): read a file's bytes and return its SHA-256 digest, a fingerprint that changes if any byte changes. Line 6 saves the fingerprint of orders.csv before the backup: 6d2443d8…

    def sha(path)    open in binary ("rb"), read the bytes,
                     return SHA-256 as 64 hex characters
    saved = sha("orders.csv")
      6d2443d8289cdf768dccade37c9a423e
      053c001a314c414c253704738b9e2db2
    (for the example file: order,item,qty / 1001,coffee,2)
  4. Lines 7–8: copy, then unplug

    Line 7 makes the vault folder; line 8 copies the file into it. The NAS gets a copy over the network too. Then the vault is unplugged: an offline copy has no connection, so nothing on the network can reach it.

    os.makedirs("vault", exist_ok=True)   ok if it exists
    shutil.copy2("orders.csv", "vault")   bytes + timestamps
    NAS     copy over the network (stays connected)
    vault   copy over a cable, then unplugged = offline
  5. RPO and RTO

    Two targets from NIST SP 800-34. Recovery point objective (RPO): the point in time data must be recovered to. Recovery time objective (RTO): how long recovery may take. Backing up nightly means up to 24 hours of changes can be lost.

    RPO   the point in time to which data must be
          recovered (how much data you may lose)
    RTO   how long recovery may take before the
          business is harmed
    here  nightly backup → RPO 24 h · RTO 8 h
    more frequent backups → smaller RPO
  6. Ransomware locks the server

    Ransomware is malicious software that encrypts files and demands payment to unlock them. At 14:00 it lands on the server, often through a stolen password or an unpatched flaw. orders.csv is now unreadable.

    ransomware   encrypts files, demands a payment
                 (availability lost)
    common ways in   stolen passwords, unpatched flaws,
                     phishing (see the earlier lessons)
    14:00        orders.csv → unreadable
    since 02:00  12 h of new orders exist only here
  7. It hunts for backups

    CISA warns that many ransomware variants find and delete or encrypt any backups they can reach. The NAS is always connected, so its copy is locked too. The vault has no cable: there is no path to it.

    reachable backups get locked too
      NAS     connected → locked
      vault   unplugged → untouched
    also     a copy that syncs every change
             copies the damage (US-CERT: rolling
             backups propagate corruption)
  8. Isolate first

    First, contain it. CISA's checklist says to work out which systems are affected and isolate them at once, for example by unplugging them from the network. Then wipe and rebuild the server from clean software before restoring any data.

    1  find the affected systems
    2  isolate them now (unplug from the network)
    3  report it and keep evidence
    4  wipe and rebuild from clean software
    5  only then restore data
  9. Line 10: restore from the vault

    Line 9 marks the incident. Line 10 copies the clean file from the vault back onto the rebuilt server. CISA advises restoring from offline backups, most critical services first. Orders after 02:00 are lost: the RPO in action.

    shutil.copy2("vault/orders.csv", ".")
      vault copy → ./orders.csv (overwrites it)
    order    most critical services first
    lost     orders between 02:00 and 14:00
             12 h, inside the 24 h RPO
  10. Line 11: check the fingerprint

    Line 11 hashes the restored file and compares it with the fingerprint saved at backup time. Equal digests print True: the bytes are exactly what was saved. NIST CSF 2.0 asks for this check (RC.RP-03) before restored data is trusted.

    print(sha("orders.csv") == saved)
    restored  6d2443d8…
    saved     6d2443d8…
    output    True  → the bytes are unchanged
    False     → do not trust this copy; try another
  11. Practise the restore

    A backup is only proven by a restore. CISA says to test backups regularly, and NIST CSF 2.0 says backups are created, protected, maintained and tested (PR.DS-11). Time each practice restore: 3 hours here, within the 8-hour RTO.

    PR.DS-11  backups are created, protected,
              maintained and tested
    drill     restore to a spare machine, check digests,
              time it: 3 h ≤ RTO 8 h
    repeat    on a schedule, and after big changes

اختبار يتاح بعد الخطوة الأخيرة.