Skip to content

Instantly share code, notes, and snippets.

@xpn
Created January 26, 2014 23:37
Show Gist options
  • Save xpn/8640962 to your computer and use it in GitHub Desktop.
Save xpn/8640962 to your computer and use it in GitHub Desktop.
Metasploit capture/mssql .Net Client
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace metasploit_sql_test
{
class Program
{
static void Main(string[] args)
{
SqlConnectionTest.CreateConnection();
}
}
static class SqlConnectionTest
{
public static void CreateConnection()
{
const string SQL_CONNECTION_STRING = @"Server=192.168.0.254;Database=testdb;User Id=metasploit_test;Password=ubersecretpw123;";
using (SqlConnection conn = new SqlConnection(SQL_CONNECTION_STRING))
{
try
{
conn.Open();
using (SqlCommand c = new SqlCommand("SELECT Secret FROM SecretTable", conn))
{
object secretVal = c.ExecuteScalar();
if (secretVal != null && secretVal is int)
{
// We got our uber secret value
Console.WriteLine("Secret Data Retrieved, value was {0}", secretVal);
}
else
{
// Value was not what we expected
Console.WriteLine("Error Retrieving Secret Value");
}
}
}
catch (SqlException e)
{
// SQL exception occured
Console.WriteLine("SQL Exception Occured: {0}", e.Message);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment