Created
January 26, 2014 23:37
-
-
Save xpn/8640962 to your computer and use it in GitHub Desktop.
Metasploit capture/mssql .Net Client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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