示例#1
0
        private bool ImportFileIntoMetasploitPro(string filename, 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 <string, object> options = new Dictionary <string, object> ();
                    options.Add("workspace", workspace);
                    options.Add("DS_PATH", filename);
                    options.Add("preserve_hosts", true);

                    Dictionary <string, object> response = manager.StartImport(options);

                    foreach (var pair in response)
                    {
                        Console.WriteLine(pair.Key + ": " + pair.Value);
                    }

                    Dictionary <string, object> taskResponse = manager.GetProTaskStatus(response ["task_id"] as string);

                    taskResponse = taskResponse.First().Value as Dictionary <string, object>;

                    while (taskResponse["status"] as string == "running")
                    {
                        Console.WriteLine("Waiting on file import: " + filename);
                        Thread.Sleep(new TimeSpan(0, 0, 60));
                        taskResponse = manager.GetProTaskStatus(response ["task_id"] as string);
                        taskResponse = taskResponse.First().Value as Dictionary <string, object>;
                    }

                    return(true);
                }
            }
        }
示例#2
0
        public static void Main(string[] args)
        {
            using (MetasploitSession session = new MetasploitSession("metasploit", "2c8X|a2!", "https://192.168.1.148:3790/api/1.1"))
            {
                using (MetasploitProManager manager = new MetasploitProManager(session))
                {
                    Dictionary <string, object> options = new Dictionary <string, object>();
                    options.Add("workspace", "default");
                    options.Add("DS_PATH", "/tmp/efc63839-ae8d-4caf-92f5-3f3ff7b6e306");

                    Dictionary <string, object> response = manager.StartImport(options);

                    foreach (var pair in response)
                    {
                        Console.WriteLine(pair.Key + ": " + pair.Value);
                    }

                    response = manager.GetProTaskStatus(response["task_id"] as string);

                    foreach (var pair in response)
                    {
                        string stat = (pair.Value as Dictionary <string, object>)["status"] as string;

                        while (stat == "running")
                        {
                            System.Threading.Thread.Sleep(500);

                            response = manager.GetProTaskStatus(response["task_id"] as string);

                            foreach (var p in response)
                            {
                                stat = (p.Value as Dictionary <string, object>)["status"] as string;
                            }
                        }
                    }
                }
            }
        }