Locky: Identify infected clients

In these two articles, I already presented a way to protect Windows file servers from Locky and other ransomware:

Tobbi has also implemented the idea for Netapp Filer:

But there are still the clients, from which most of the danger emanates. The faster the computers infected with Locky are identified, the faster the client can be isolated from the network and the Trojan rendered harmless.

So I did a little more thinking and ended up on the Fortinet blog while researching Locky. Fortinet has taken a closer look at Locky:

The article from Fortinet is well worth reading and also contains important information that can be used. Locky contacts command & control servers on the Internet, Fortinet even specifies which ones these are:

Locky

The C&C servers can simply be blocked at the firewall, then they are no longer accessible, but that probably does not prevent Locky from encrypting files, especially since not all C&C servers are probably encrypted yet.

But the C&C servers help to identify the clients that have caught Locky, if the firewall cannot report this directly, you could also have the Windows DNS servers log which computers resolve which domains. The log can then be searched for the C&C domains and if a client tries to resolve a C&C server via DNS, it will probably have caught Locky.

I've prepared something:

In order for the script to identify the computers trying to reach the Locky C&C servers, debug logging must be enabled on the DNS server:

DNS debug logging

After a short time, the DNS debug log is filled:

DNS Log

This log file can be analyzed using PowerShell. If the script finds one of Locky's command & control servers in the DNS log, an email is sent:

Locky Alarm

The script still needs to be adapted a little:

Script

The path to the DNS debug log must be specified in line 1, lines 2 to 5 contain the data for sending the mail. If the script is to run continuously, the value for "LoopScript" can be set to "$true" in line 7.

The script can now either be started in an endless loop via PowerShell (LoopScript = $true) or executed cyclically via Task Scheduler.

Note: If the script runs in an endless loop and hits are found in the log, a small flood of mail is triggered. I still have to adjust this a bit, but it's better to have too many mails than a big mess on Monday...

All C&C servers that I have found so far are listed from line 10 onwards. If you know of any more, please let us know.

19 thoughts on “Locky: Verseuchte Clients identifizieren”

  1. Hallo Franky und andere Mitleser,

    ich habe den DNSLogger mal mit Testseiten auf einem Windows Server 2008 R2 ausprobiert, leider kommt keine E-Mail. Das ist aber erstmal nicht schlimm. Danach dachte ich mir, ich lasse mir den DNS-Log einfach nur schön aufbereiten und extrahiere ihn dann in eine .txt-Datei.
    Das dauert aber verdammt lange. Der DNS-Log hat ca. 100 MB und der DNSLogger läuft über 4 Stunden. Wie lange genau, weiß ich nicht, da ich ihn immer nach 4 Stunden abgebrochen habe. Der powershell-Prozess frisst quasi auch allen RAM. Ist das normal und falls nicht, hat Jemand evtl. eine Idee, woran es liegen könnte?

    Viele Grüße
    Jojo

    Reply
  2. Also läuft tadellos, hab in Line 191 (nach dem Send-MailMessage) innerhalb der LoopScript While ein Start-Sleep -s 600 eingebaut das wenn was gefunden wird nur maximal alle 10 Minute eine Mail pro DNS Server rausgeht.

    Die Liste der „bösen Server“ muss ja manuell geupdated werden.
    Gibts ne möglichkeit den von Atomspion genannten Artikel in dem der Domain-Create-Algorithmus aufgezeigt wird mit einzubauen?

    Reply
  3. Hi,
    hier gibt es eine gute Liste der C&C Server. Die Domainnamen sind natürlich vorher angelegt und werden ja im Code je nach Datum generiert und kontaktiert. Durch die Codeanalyse haben die alle durch die in Locky enthaltene Routine zur generierung von Domainnamen (mit C&C Server dahinter) schon für den Rest von Februar generiert:

    https://blogs.forcepoint.com/security-labs/locky-ransomware-encrypts-documents-databases-code-bitcoin-wallets-and-more

    Auch sonst recht interessante Infos …

    Reply
  4. Hallo,

    erst einmal danke für das Script! Nur leider habe ich ein Problem beim protokollieren der Funde. Obwohl die Log-Datei nicht geöffnet ist, bekomme ich den nachfolgenden Fehler in der Ereignisanzeige.

    „Der DNS-Server konnte die Datei „C:\DNSLog\dns.log“ für den Schreibvorgang nicht öffnen. Wahrscheinlich handelt es sich um eine bereits geöffnete Zonendatei. Schließen Sie die Datei, und starten Sie den Schreibvorgang der Zone neu.“

    Woran könnte das problem liegen?

    Danke und Grüße!

    Reply
  5. @Alex

    z.B. kann man beim Server 2012 R2 den SMTP Server installieren. Dort kann man dann Daten zur Authentifizierung hinterlegen. Dann kann man im Ressourcen-Manager als SMTP-Server z.B. localhost angeben.
    Es finden sich Anleitungen im Netz wie man den konfiguriert. z.B. im mntechblog

    Reply
  6. Hey Franky,

    direkt mal eingebaut und klappt super – einziger Wermutstropfen ist bislang die Mail-Flut, die beim Loop ausgelöst wird.
    Danke dafür!

    Reply
  7. HI,

    irgendwas scheint bei uns falsch zu laufen. Habe via nslookup das „hazentrumsuedperlach.de“ aufgelöst, es erscheint auch in der Log mit folgendem Eintrag (nur das wichtigste): Name „(20)hazentrumsuedperlach(2)de(3)DOMAINNAME(5)local(0)“
    Aber es wird keine Mail ausgelöst. Ich denke, es liegt daran, dass der Domänen Name angehängt wird, richtig?

    Reply
  8. Top Beitrag – Getestet, ab genickt und für gut befunden! Das mit den 2 Emails kann ich bestätigen aber in Kombination mit dem FSRM Emailalarm ist ein nice to have. Dickes Danke aus NRW

    Reply
  9. Super, danke!

    Habe in die Liste der Server mal einen Testeintrag gemacht – Script findet im DNS Log diesen einen Eintrag, verschickt allerdings zwei Emails mit dem gleichen Inhalt.

    Loop steht dabei auf false.

    Reply
  10. Also bei einem unserer Kunden konnte der befallene Rechner sehr schnell ausfindig gemacht werden, da die .txt Anleitungen zum entschlüsseln die Besitzerinformation des bestimmten AD Users zeigten.

    Diese Anleitungen werden in jedem Ordner erstellt, in dem auch Daten verschlüsselt wurden.

    In dem Fall war das der locky Virus

    Reply
  11. Hey Franky,

    danke nochmals für die tollen HowTo’s. Sind direkt mal umgesetzt worden.
    Zum DNS-Skript ist zu sagen, dass die Zeile 7: $LoopScript nicht im Skript aus dem Download vorhanden ist.

    VG
    Daniel

    Reply

Leave a Comment