Tuesday, June 27, 2017

How to parse Windows DNS debug logs with Logparser for VIRUS (eg WannaCRY)

In this article I share a powershell script that will help to identify infected WannaCRY PCs and other botnet in your network. With the help of MS Logparser you can very quickly check the debug log files of windows-dns.

Download powershell script

1. At first enable DNS debug log on all dns-servers
- set limit for file size
- set same path (for script)


2. Install on the PC from which you run the script Logparser

3. For script you have to set
- servers
- domains
- homefolder
- file's path with dns debug logs
- email server (anonymous smtp)
- user email

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
# Set variables
$HomeFolder = "D:\Scripts"
cd $HomeFolder
if (!(test-path "$HomeFolder\Logs")) {New-Item -ItemType directory -Path "$HomeFolder\Logs"}
$LogParser = "C:\Program Files (x86)\Log Parser 2.2\LogParser.exe"

$Servers = @("dc1.blogspot.com","dc2.blogspot.com","dc3.blogspot.com")
$VirDomains = @("iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea","ifferfsodp9ifjaposdfjhgosurijfaewrwergwea","ayylmaoTJHSSTasdfasdfasdfasdfasdfasdfasdf","pingdavinci","wizardtesla","archimedus")

$msg = new-object Net.Mail.MailMessage
$msg.From = "myscript@blogspot.com"
$msg.To.add("i-evgeny@blogspot.com")
$msg.Subject = "Virus DNS Parser"
$SMTPServer = "smtp.blogspot.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$LogTime = Get-Date -Format "yyyy-MM-dd_hh-mm-ss"
$LogFile = $HomeFolder + '\Logs\'+"parser_vir_"+$LogTime+".log"

# Logparser query
$VirDomains_str = ""
$i = 1
foreach ($v in $VirDomains) {
    if ($i -eq "1") {
    $VirDomains_str = "field15 LIKE '%$($v)%' OR field16 LIKE '%$($v)%'"
    } else {
    $VirDomains_str += " OR field15 LIKE '%$($v)%' OR field16 LIKE '%$($v)%'"
    }
    $i++
}

$DCs_str = ""
$i = 1
foreach ($d in $Servers) {
    if ($i -eq "1") {
    $DCs_str = "\\$($d)\c$\Scripts\Logs\Queries.log"
    } else {
    $DCs_str += ",\\$($d)\c$\Scripts\Logs\Queries.log"
    }
    $i++
}

$query = """SELECT * INTO $($LogFile) FROM $DCs_str WHERE $VirDomains_str"""
$LogParserStr = "-i:TSV -iSeparator:space -nFields:16 -headerRow:OFF -nSkipLines:30 -o:csv " + $query
$LP = Start-Process -FilePath $LogParser -ArgumentList $LogParserStr -Wait -Passthru -NoNewWindow
Start-Sleep -s 15
$Result = import-csv $LogFile

# Send alert
    if ($Result) {
        $vir_ip = $result | select field8 -Unique
        $msg.Body = "$($vir_ip.field8)"
        $att = new-object Net.Mail.Attachment($LogFile)
        $msg.Attachments.Add($att)
        $SMTPClient.Send($msg)
    }

4. Schedule a task (eg every 1 hour), runas account must have read permission for DNS Debug files

Quick start with PaloAlto active-active cluster and two ISP. Part1

In the first part, we will create a cluster.
Quick start :)
Case:
Active-Active cluster
Two ISP
Management IP 192.168.0.10/24
DNS IP 192.168.0.20, 192.168.0.30
Gateway 192.168.0.1
6 ethernet card (1 management, 1 local, 1 isp1, 1 isp2, 2 system replication)

1. Login to console, assign IP for manage, DNS. Default cred: admin/admin
Configure
set deviceconfig system ip-address 192.168.0.10 netmask 255.255.255.0 default-gateway 192.168.0.1 dns-setting servers primary 192.168.0.20
set deviceconfig system ip-address 192.168.0.10 netmask 255.255.255.0 default-gateway 192.168.0.1 dns-setting servers secondary 192.168.0.30
commit

Next, go to web-console https://192.168.0.10


2. Go to "Device – Licenses - Activate feature using authorization code" on web-console.
Open https://support.paloaltonetworks.com "ASSETS – VM-Series Auth-Codes – Register VM – lic-file", register and download license.


3. Install license


4. Install updates




5. Set strong password


6. Create cluster: Assign network interface type (You can check network by mac-address, show interface all), zone, virtual router
Ethernet1/1 – ISP1
Ethernet1/2 – ISP2
Ethernet1/3 – repl
Ethernet1/4 – local
Ethernet1/5 – repl



7. Go to "Device – High Availability - General" and create Active-Active Cluster:
Section "Setup": type second node's ip address;
Section "Control Link (HA1)": choose "managment" interface;
Section "Data Link": choose first replication interface - Ethernet1/3, assign ip address.
Commit Config and repeat steps on second node.


8. Go to "Device – High Availability - Active/Active Config". Choose second replication interface - Ethernet1/5 for session replications. Assign virtual ip addresses(two ISP and local). Commit config.


9. Go to "Dashboard" and add "Widgets – System – High Availability". Check cluster.


10. Let's check!