Last active
August 29, 2015 14:16
-
-
Save chipitsine/df8451dc046508cb0897 to your computer and use it in GitHub Desktop.
scan with SCEP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -version 4 | |
cls | |
[System.Reflection.Assembly]::LoadWithPartialName('MySql.Data') | Out-Null | |
$Connection = New-Object MySql.Data.MySqlClient.MySqlConnection | |
$Connection.ConnectionString = 'server=nnn;port=3306;uid=nnn;pwd=nnn;database=nnn' | |
$Connection.Open() | |
$Command = New-Object MySql.Data.MySqlClient.MySqlCommand | |
$Command.Connection = $Connection | |
for($i = 10; $i -lt 1000; $i++){ | |
$Command.CommandText = 'select id, octet_length(content), content from samples where id not in (select id from microsoft) limit 1' | |
$reader = $Command.ExecuteReader() | |
if($reader.Read()){ | |
$id = $reader.GetString(0) | |
$Size = $reader.GetString(1) | |
$fn = [System.IO.Path]::GetTempFileName() | |
$rawData = New-Object Byte[] $Size | |
$reader.GetBytes($reader.GetOrdinal('content'), 0, $rawData, 0, $Size) | Out-Null | |
$fs = New-Object IO.FileStream $fn ,'Open', 'Write' | |
$fs.Write($rawData,0,$Size) | |
$fs.Close(); | |
$ScanResult = ( & 'C:\Program Files\Microsoft Security Client\MpCmdRun.exe' -Scan -ScanType 3 -DisableRemediation -File $fn) | Out-String | |
} | |
$reader.Close() | |
if($ScanResult.Contains('found no threats')){ | |
$text = 'OK' | |
}else{ | |
$text = $ScanResult | |
$ScanResult.Split(“`n”).Where({$_ -like 'Threat*'},'First') | % { | |
$text = $_.Substring(26) | |
} | |
} | |
Write-Host $text | |
$Command.CommandText = "INSERT INTO microsoft (id, description) values ($id, ""$text"")" | |
$RowsInserted = $Command.ExecuteNonQuery() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment