/// <summary> /// Bu fonksiyon Taramaları ekrana yazar. /// This function writes the Scans to screen. /// </summary> /// <param name="manager">W3afManager Object</param> public static void GetScans(NexposeManager manager) { try { ScanController = new ScanController(); ScanModel scans = ScanController.GetScan(manager); if (scans.Resources.Length > 0) { int counter = 1; foreach (var item in scans.Resources) { Console.WriteLine(counter + ") ID: " + item.ID + " " + "Tarama Adı: " + item.ScanName); counter += 1; } int selected = ScanView.SelectScan(); ScanInformations(selected - 1, scans); } else { Console.WriteLine("Herhangi bir tarama mevcut değildir."); } } catch (Exception ex) { Console.WriteLine("ScanView::GetScans Error Message:" + ex.Message); } }
/// <summary> /// Bu fonksiyon Taramaları döndürür. /// This function returns the scans. /// </summary> /// <param name="manager">Nexpose Instance</param> /// <returns></returns> public ScanModel GetScan(NexposeManager manager) { try { string json = manager.GetScans(); var scans = JsonConvert.DeserializeObject <ScanModel>(json); return(scans); } catch (Exception ex) { throw ex; } }
/// <summary> /// Bu fonksiyon yeni bir Site (Varlık) oluşturur. /// This function creates a new Site. /// </summary> /// <param name="manager">NexposeManager instance</param> /// <param name="site">SiteCreateModel object</param> /// <returns></returns> public string CreateSite(NexposeManager manager, SiteCreateModel site) { try { string json = JsonConvert.SerializeObject(site); string responseJson = manager.CreateSite(json); SiteCreateResponse siteCreateResponse = JsonConvert.DeserializeObject <SiteCreateResponse>(responseJson); return(siteCreateResponse.Id); } catch (Exception ex) { Console.WriteLine("ScanController::CreateSite \nException: " + ex.Message); return(null); } }
/// <summary> /// /// </summary> /// <param name="manager"></param> /// <returns></returns> public TemplateModel GetScanTemplates(NexposeManager manager) { try { string jsonResponse = manager.GetScanTemplates(); TemplateModel model = JsonConvert.DeserializeObject <TemplateModel>(jsonResponse); return(model); } catch (Exception ex) { Console.WriteLine("ScanController::GetScanTEmplates \n\tException: " + ex.Message); return(null); //throw; } }
public SitesModel GetSites(NexposeManager manager) { try { string jsonResponse = manager.GetSites(); SitesModel sitesModel = new SitesModel(); sitesModel = JsonConvert.DeserializeObject <SitesModel>(jsonResponse); return(sitesModel); } catch (Exception ex) { Console.WriteLine("ScanController::GetSites \nException: " + ex.Message); return(null); } }
/// <summary> /// Bu fonksiyon yeni bir Tarama oluşturur. /// This function creates a new Scan. /// </summary> /// <param name="manager">NexposeManager Instance</param> /// <param name="json">String in valid JSON type</param> /// <returns></returns> public ScanCreateResponse CreateScan(NexposeManager manager, string id, ScanCreate scanCreate) { try { string json = JsonConvert.SerializeObject(scanCreate); string jsonResponse = manager.CreateScan(id, json); ScanCreateResponse scanCreateResponse = new ScanCreateResponse(); scanCreateResponse = JsonConvert.DeserializeObject <ScanCreateResponse>(jsonResponse); return(scanCreateResponse); } catch (Exception ex) { throw ex; } }
/// <summary> /// Bu fonksiyon tarama template'lerini (policy) listeler. /// This function lists scan templates (policy). /// </summary> /// <returns></returns> private static string ListAndSelectTemplate(NexposeManager manager) { TemplateModel model = ScanController.GetScanTemplates(manager); int counter = 1; Console.Write("\n"); foreach (var item in model.Resources) { Console.WriteLine(counter + ") " + item.Name.ToString()); counter += 1; } Console.Write("\n Policy Seçiniz: "); int policyId = Convert.ToInt32(Console.ReadLine()); return(model.Resources[policyId - 1].ID); }
static void Main(string[] args) { try { ScanView.SetIPAndPort(); using (NexposeSession session = new NexposeSession(ScanView.IP, ScanView.Port, ScanView.Username, ScanView.Password)) { using (NexposeManager manager = new NexposeManager(session)) { if (session.W3afServiceState()) { string inputSelection = ""; do { Console.Write("\nYapmak istediğiniz işlemi seçiniz." + "\nA: Tarama Oluşturmak İçin" + "\nB: Taramaları listelemek için " + //"\nC: Tarama Durumunu Görüntülemek İçin" + //"\nD: Tarama Silmek İçin" + //"\nE: Zafiyetleri Görmek İçin" + //"\nF: Zafiyetleri XML Olarak Masaüstüne Kaydet" + "\nQ: Çıkış İçin" + "\nSeçiminiz: "); inputSelection = Console.ReadLine().ToUpper(); switch (inputSelection) { case "A": ScanView.CreateScan(manager); break; case "B": ScanView.GetScans(manager); break; case "C": //ScanView.GetScanStatus(manager); break; case "D": //ScanView.DeleteScan(manager); break; case "E": //ScanView.ShowScanVulnerabilities(manager); break; case "F": //ScanView.SaveScanVulnerabilitiesAsXML(manager); break; case "Q": break; default: Console.WriteLine("\n***Hatalı Seçim. Lütfen Seçiminizi kontrol ediniz.***\n"); break; } } while (inputSelection != "Q"); } else { Console.WriteLine("Not OKEY"); } Console.Read(); } } } catch (Exception ex) { throw ex; } }
/// <summary> /// Bu fonksiyon yeni bir Tarama oluşturur ve oluşturulan ID'yi ekrana yazar. /// This function creates a new Scan and created ID writes to the screen. /// </summary> /// <param name="manager"></param> public static void CreateScan(NexposeManager manager) { ScanController = new ScanController(); try { string selected = ""; do { Console.Write("Yeni Varlık Oluşturmak İstiyor musunuz? (E/H)"); selected = Console.ReadLine(); string responseId = ""; if (selected.ToUpper() == "E") { //Profile Name is scan settings namely it is policy. Profile Adı tarama ayarlarıdır yani policydir. Console.WriteLine("Varlık Adı Giriniz."); string siteName = Console.ReadLine(); string scanProfileName = ListAndSelectTemplate(manager); string targetURL = SelectTargetURL(); SiteCreateModel siteCreate = new SiteCreateModel(siteName, targetURL, scanProfileName); responseId = ScanController.CreateSite(manager, siteCreate); } else if (selected.ToUpper() == "H") { //Varlıkları Listele SitesModel sitesModel = ScanController.GetSites(manager); int counter = 1; if (sitesModel.Resources.Length == 0) { Console.WriteLine("Herhangi bir varlık bulunmamaktadır. Öncelikle yeni bir varlık oluşturunuz."); break; } foreach (var item in sitesModel.Resources) { Console.WriteLine(counter + ") " + item.Name); counter += 1; } Console.WriteLine("Site Numarasını giriniz: "); int id = Convert.ToInt32(Console.ReadLine()); ScanCreate scanCreate = new ScanCreate(null, sitesModel.Resources[id - 1].ScanTemplate); ScanCreateResponse scanCreateResponse = ScanController.CreateScan(manager, id.ToString(), scanCreate); if (scanCreateResponse.Id > 0) { Console.WriteLine("Tarama Oluşturuldu. Tarama ID: " + scanCreateResponse.Id); break; } } else { Console.WriteLine("Geçersiz Seçim"); } } while (selected != "E" & selected != "H"); //ScanCreate scanCreate = new ScanCreate(scanProfileName, targetURL); //string json = JsonConvert.SerializeObject(scanCreate); //if (responseJson == null) //{ // Console.WriteLine("Sistemde herhangi bir tarama mevcut ise öncelikle onu siliniz."); // return; //} //ScanCreateResponse scanCreateResponse = JsonConvert.DeserializeObject<ScanCreateResponse>(responseJson); //Console.WriteLine("Oluşturulan Tarama ID: " + scanCreateResponse.ID); } catch (Exception ex) { Console.WriteLine("ScanView::CreateScan Exception: " + ex.Message); } }