Preparando Windows XP-SP2 para entorno de pruebas de auditoría
Hola!
Muy buenas a todos/as!
Si queremos hacer prácticas con Metasploit u otras herramientas en un entorno controlado es bueno poder tener un sistema operativo configurado de manera que pueda ser susceptible a ataques para poder practicar. Los de Offensive Security tienen una guía de como configurar un Windows XP Service Pack 2 para habilitar servicios y aplicaciones vulnerables. Me he basado en la web de Offensive Security, recordad que para habilitar estos servicios deberemos de contar una licencia de Windows XP SP2.
No entraré en detalles de como realizar una instalación de Windows, sólo hay que instalarla con las opciones por defecto.
Una vez instalado vamos a configurar ciertas cosas.
- Primero lo que haremos será deshabilitar protecciones nativas del sistema operativo además de desactivar las notificaciones.
Nos vamos al centro de Seguridad en Windows XP.

Desactivamos Firewall, antivirus, y vamos a las opciones de notificación que hay marcadas en la imagen

Desmarcamos las checkboxes.
Por defecto viene activado la compartición de archivos simple, pero no está de mas revisarlo. En opciones de carpeta comprobamos que este marcado:

Ahora ya hemos configurado una parte de sistema operativo
- Lo segundo es configurar servicios adicionales, por eso nos iremos a añadir o remover componentes de Windows en Agregar o quitar programas

Instalamos ISS y FTP. Además también instalamos SNMP

- Tercero instalamos SQL Server Express para configurar una aplicación vulnerable
Para instalar SQL Server Express nos hará falta como requisitos Net Framework y Windows Installer 3.1
En la instalación de SQLL Server Express cuando lleguemos al apartado de autenticación

Ponemos como password password1
Una vez terminada la instalación tenemos que configurarlo.
Accedemos al SQL Server Configuration Manager

En el apartado de TCP/IP en propiedades configuramos

Dejamos los valores como pone en la imagen

En el apartado de SQL Browser ponemos que se inicie de manera automática

Ahora para finalizar con Netstat miramos las conexiones
Primero bajamos Server Management Studio Express
Una vez abierto, nos autenticamos con sa y password1

Creamos una nueva base de datos

En la nueva base de datos creamos una tabla

Rellenamos la tabla con los siguientes campos

Rellenamos la tabla con datos reales

Ahora en el apartado de Seguridad le damos a New Login

En Login le damos a search y buscamos el usuario aspnet

Por último configuramos que el usuario aspnet sea owner de la base de datos que hemos creado

Para crear la aplicación vulnerable web creamos en wwwroot el archivo Default.aspx
<%@ Page Language=”C#” AutoEventWireup=”true” ValidateRequest=”false” CodeFile=”Default.aspx.cs” Inherits=”_Default” %> <%–the ValidateRequest=”true” in the page directive will check for <script> and other potentially dangerous inputs–%> <!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”>
</head> <body bgcolor=”white”> <form id=”form1″ runat=”server”> <div>
<font color=”black”><h1>Login Page</h1></font> <asp:Label ID=”lblErrorMessage” Font-Size=”Larger” ForeColor=”red” Visible=”false” runat=”server” />
<font color=”black”> <asp:Panel ID=”pnlLogin” Visible=”true” runat=”server”> <asp:Table ID=”tblLogin” runat=”server”> <asp:TableRow> <asp:TableCell> <asp:Literal Text=”Login:” runat=”server” /> </asp:TableCell> <asp:TableCell> <asp:TextBox ID=”txtLogin” width=”200″ BackColor=”white” ForeColor=”black” runat=”server” /> </asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell> <asp:Literal ID=”ltrlPassword” Text=”Password” runat=”server” /> </asp:TableCell> <asp:TableCell> <asp:TextBox ID=”txtPassword” width=”200″ TextMode=”password” BackColor=”white” ForeColor=”black” runat=”server” /> </asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell ColumnSpan=”2″ HorizontalAlign=”center”> <asp:Button ID=”btnSubmit” BorderColor=”white” BackColor=”white” ForeColor=”black” Text=”Login” OnClick=”btnSubmit_Clicked” runat=”server” /> <br /></asp:TableCell> </asp:TableRow> </asp:Table> <h5>Please dont hack this site</asp:Panel> <asp:Panel ID=”pnlChatterBox” Visible=”false” runat=”server”> You haz logged in!
</asp:Panel> </font>
</div> </form> </body> </html>
También creamos el archivo Default.aspx.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected SqlConnection objConn = new SqlConnection(ConfigurationManager.ConnectionStrings["test"].ToString());
protected string sql = "";
protected void Page_Load(object sender, EventArgs e)
{
if((Request.QueryString["login"] != null) &&
(Request.QueryString["password"] != null))
{
Response.Write(Request.QueryString["login"].ToString() + "<BR><BR><BR>" + Request.QueryString["password"].ToString());
sql = "SELECT first_name + ' ' + last_name + ' ' + middle_name FROM users WHERE username = '" + Request.QueryString["login"] + "' " +
"AND password = '" + Request.QueryString["password"] + "'";
Login();
}
}
public void btnSubmit_Clicked(object o, EventArgs e)
{
lblErrorMessage.Text = "";
lblErrorMessage.Visible = false;
if (txtLogin.Text == "")
{
lblErrorMessage.Text = "Missing login name!<br />";
lblErrorMessage.Visible = true;
}
else
{
if (txtPassword.Text == "")
{
lblErrorMessage.Text = "Missing password!<br />";
lblErrorMessage.Visible = true;
}
else
{
sql = "SELECT first_name + ' ' + last_name + ' ' + middle_name FROM users WHERE username = '" + txtLogin.Text + "' " +
"AND password = '" + txtPassword.Text + "'";
Login();
}
}
}
private void Login()
{
//correct sql string using sql parameters.
//string sql = "SELECT first_name + ' ' + last_name FROM users WHERE username = @txtLogin " +
// "AND password = @txtPassword";
SqlCommand cmd = new SqlCommand(sql, objConn);
//each parameter needs added for each user inputted value...
//to take the input literally and not break out with malicious input....
//cmd.Parameters.AddWithValue("@txtLogin", txtLogin.Text);
//cmd.Parameters.AddWithValue("@txtPassword", txtPassword.Text);
objConn.Open();
if (cmd.ExecuteScalar() != DBNull.Value)
{
if (Convert.ToString(cmd.ExecuteScalar()) != "")
{
lblErrorMessage.Text = "Sucessfully logged in!";
lblErrorMessage.Visible = true;
pnlLogin.Visible = false;
pnlChatterBox.Visible = true;
}
else
{
lblErrorMessage.Text = "Invalid Login!";
lblErrorMessage.Visible = true;
}
}
else
{
lblErrorMessage.Text = "Invalid Username/";
lblErrorMessage.Visible = true;
}
objConn.Close();
}
//<style type="text/css">TABLE {display: none !important;}</style> //remove tables totally.
//<style type="text/css">body{background-color: #ffffff;}</style> //change background color
//<style type="text/css">div {display: none !important;}</style> //remove all divs, blank out page
//<script>alert("hello");</script>
//<meta http-equiv="refresh" content="0; url=http://www.google.com" />
}
Y por último creamos el archivo web.config
<?xml version=”1.0″?> <configuration> <connectionStrings> <add name=”test” connectionString=”server=localhost;database=WebApp;uid=sa;password=password1;” providerName=”System.Data.SqlClient”/> </connectionStrings> <system.web>
<!– DYNAMIC DEBUG COMPILATION Set compilation debug=”true” to enable ASPX debugging. Otherwise, setting this value to false will improve runtime performance of this application. Set compilation debug=”true” to insert debugging symbols(.pdb information) into the compiled page. Because this creates a larger file that executes more slowly, you should set this value to true only when debugging and to false at all other times. For more information, refer to the documentation about debugging ASP.NET files. –> <compilation defaultLanguage=”c#” debug=”true”> <assemblies> <add assembly=”System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A”/> <add assembly=”System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089″/></assemblies></compilation> <!– CUSTOM ERROR MESSAGES Set customErrors mode=”On” or “RemoteOnly” to enable custom error messages, “Off” to disable. Add <error> tags for each of the errors you want to handle.
“On” Always display custom (friendly) messages. “Off” Always display detailed ASP.NET error information. “RemoteOnly” Display custom (friendly) messages only to users not running on the local Web server. This setting is recommended for security purposes, so that you do not display application detail information to remote clients. –> <customErrors mode=”Off”/> <!– AUTHENTICATION This section sets the authentication policies of the application. Possible modes are “Windows”, “Forms”, “Passport” and “None”
“None” No authentication is performed. “Windows” IIS performs authentication (Basic, Digest, or Integrated Windows) according to its settings for the application. Anonymous access must be disabled in IIS. “Forms” You provide a custom form (Web page) for users to enter their credentials, and then you authenticate them in your application. A user credential token is stored in a cookie. “Passport” Authentication is performed via a centralized authentication service provided by Microsoft that offers a single logon and core profile services for member sites. –> <authentication mode=”Windows”/> <!– AUTHORIZATION This section sets the authorization policies of the application. You can allow or deny access to application resources by user or role. Wildcards: “*” mean everyone, “?” means anonymous (unauthenticated) users. –> <authorization> <allow users=”*”/> <!– Allow all users –> <!– <allow users=”[comma separated list of users]” roles=”[comma separated list of roles]“/> <deny users=”[comma separated list of users]” roles=”[comma separated list of roles]“/> –> </authorization> <!– APPLICATION-LEVEL TRACE LOGGING Application-level tracing enables trace log output for every page within an application. Set trace enabled=”true” to enable application trace logging. If pageOutput=”true”, the trace information will be displayed at the bottom of each page. Otherwise, you can view the application trace log by browsing the “trace.axd” page from your web application root. –> <trace enabled=”false” requestLimit=”10″ pageOutput=”false” traceMode=”SortByTime” localOnly=”true”/> <!– SESSION STATE SETTINGS By default ASP.NET uses cookies to identify which requests belong to a particular session. If cookies are not available, a session can be tracked by adding a session identifier to the URL. To disable cookies, set sessionState cookieless=”true”. –> <sessionState mode=”InProc” stateConnectionString=”tcpip=127.0.0.1:42424″ sqlConnectionString=”data source=127.0.0.1;Trusted_Connection=yes”
cookieless=”false” timeout=”20″/> <!– GLOBALIZATION This section sets the globalization settings of the application. –> <globalization requestEncoding=”utf-8″ responseEncoding=”utf-8″/> </system.web> </configuration>
Ya tenemos la aplicación web vulnerable, mas adelante haremos prueba de intrusión.
Saludos cordiales
Buscador
- ¿SPAM dirigido? wp.me/p6blk-16S 24 minutes ago
- Nuevas versiones del malware de la policía y cómo eludirlas j.mp/KIGXyF 10 hours ago
- Utilidad para vigilar el uso del Modo Protegido en Internet Explorer j.mp/KIGE71 10 hours ago
- Nuevas versiones de SpyEye graban imágenes de sus víctimas j.mp/JS2vPt 10 hours ago
- Salto de restricciones en sudo (en multitud de distribuciones) j.mp/KpZwsQ 10 hours ago