public static bool IsIPAlive(IPAddress ip) { //Ignora las Ips privadas if (DNSUtil.IsPrivateIP(ip)) { return(false); } return(PingIt(ip)); }
public bool IsInRangeLimit(string ip) { if (DNSUtil.IsIPv4(ip)) { string r = ip.Split(new char[] { '.' })[0] + "." + ip.Split(new char[] { '.' })[1] + "." + ip.Split(new char[] { '.' })[2]; int lastOct = int.Parse(ip.Split(new char[] { '.' })[3]); /* * Se comprueba si hay alguna IP en el limite Higher +1 y en el limite Lower -1. * En caso de que exista, y esta no tenga asociado ningun dominio, se modifica el limite * Lower a Lower-1 y/o el Higher a Higher+1. */ { if ((lastOct == Lower - 1) && (lastOct > 0)) { string ipLimitInferior = ip.Split(new char[] { '.' })[0] + "." + ip.Split(new char[] { '.' })[1] + "." + ip.Split(new char[] { '.' })[2] + "." + (lastOct - 1).ToString(); int count = Program.data.GetRelationsOfIP(ipLimitInferior).Count(); if (count == 0) { this.Lower--; } } if ((lastOct == Higher + 1) && (lastOct < 254)) { string ipLimitSuperior = ip.Split(new char[] { '.' })[0] + "." + ip.Split(new char[] { '.' })[1] + "." + ip.Split(new char[] { '.' })[2] + "." + (lastOct + 1).ToString(); int count = Program.data.GetRelationsOfIP(ipLimitSuperior).Count(); if (count == 0) { this.Higher++; } } } if (r == this.Range) { if ((lastOct >= Lower) && (lastOct <= Higher)) { return(true); } } } return(false); }
public bool IsIpInLimitRange(string ip) { var result = false; if (DNSUtil.IsIPv4(ip)) { foreach (var limit in lstLimits) { result = limit.IsInRangeLimit(ip); if (result) { return(true); } } } return(false); }
/// <summary> /// Allows a plugin to add URLs to the project /// </summary> /// <param name="url"></param> private static void AddUrl(string url) { var uri = new Uri(url); var domain = Program.data.GetDomain(uri.Host); if (domain == null) { Program.data.AddDomain(uri.Host, "Plugins", Program.cfgCurrent.MaxRecursion, Program.cfgCurrent); } else { domain = Program.data.GetDomain(uri.Host); // If URL could not be added, return if (domain == null) { return; } } if (domain == null) { return; } domain.map.AddUrl(url); if (Program.data.relations.Items.Any(r => r.Domain.Domain == domain.Domain && r.Ip != null)) { return; } var listIpsOfDomain = DNSUtil.GetHostAddresses(domain.Domain); foreach (var ip in listIpsOfDomain) { Program.data.AddResolution(domain.Domain, ip.ToString(), "Plugins", Program.cfgCurrent.MaxRecursion, Program.cfgCurrent, true); } }
/// <summary> /// Process Network nodes. /// </summary> static private void NodeNetworkProcess() { if (Program.data == null) { return; } var nServers = 0; var tnPCServers = Program.FormMainInstance.TreeView.Nodes[TreeViewKeys.KProject.ToString()].Nodes[TreeViewKeys.KPCServers.ToString()]; if (tnPCServers != null) { var lst = new ThreadSafeList <ComputersItem>(Program.data.computers.Items); foreach (var computer in lst) { Application.DoEvents(); TreeNode tn = null; switch (computer.type) { case ComputersItem.Tipo.ClientPC: { tn = tnPCServers.Nodes["Clients"].Nodes[computer.name]; if (tn == null) { var insertAtIndex = Program.FormMainInstance.SearchTextInNodes(tnPCServers.Nodes["Clients"].Nodes, computer.name); tn = tnPCServers.Nodes["Clients"].Nodes.Insert(insertAtIndex, computer.name, computer.name); tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } else { tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } } break; case ComputersItem.Tipo.Server: { //Si no tiene una IP asociada añadir al nodo de servidores desconocidos if (!Program.data.computerIPs.Items.Any(C => C.Computer.name == computer.name)) { Object x = Program.FormMainInstance.TreeView; if (tnPCServers.Nodes["Servers"].Nodes["Unknown Servers"].Nodes[computer.name] != null) { tn = tnPCServers.Nodes["Servers"].Nodes["Unknown Servers"].Nodes[computer.name]; } else { int insertAtIndex = Program.FormMainInstance.SearchTextInNodes(tnPCServers.Nodes["Servers"].Nodes["Unknown Servers"].Nodes, computer.name); tn = tnPCServers.Nodes["Servers"].Nodes["Unknown Servers"].Nodes.Insert(insertAtIndex, computer.name, computer.name); tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } if (tn == null) { return; } } else //Como tiene una IP asociada insertar en su rango { string strIP = Program.data.computerIPs.Items.First(C => C.Computer.name == computer.name).Ip.Ip; if (Program.data.Project.IsIpInNetrange(strIP) == false) { continue; } bool found = false; foreach (RelationsItem relation in Program.data.relations.Items.Where(S => S.Ip.Ip == strIP)) { if (relation.Domain.Domain.Contains(Program.data.Project.Domain) == true) { found = true; } foreach (string auxDom in Program.data.Project.AlternativeDomains) { if (relation.Domain.Domain.Contains(auxDom)) { found = true; } } } if ((found == false) && (DNSUtil.IsIPv4(strIP))) { if (Program.data.IsIpInLimitRange(strIP)) { found = true; } } if (found == false) { continue; } //Comprobar que existe el rango if (DNSUtil.IsIPv4(strIP)) { byte[] IPBytes = DNSUtil.IPToByte(strIP); //Dependiendo de la calse de Ip que sea tiene que dibujarla a una profundidad u otra //IP de clase A if (IPBytes[0] >= 1 && IPBytes[0] < 128) { TreeNode tnIP = null; string iprange = string.Format("{0}.0.0.0", IPBytes[0]); if (tnPCServers.Nodes["Servers"].Nodes[iprange] != null) { tnIP = tnPCServers.Nodes["Servers"].Nodes[iprange]; } else { tnIP = tnPCServers.Nodes["Servers"].Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnPCServers.Nodes["Servers"].Nodes, iprange), iprange, iprange); tnIP.ContextMenuStrip = Program.FormMainInstance.contextMenu; tnIP.ImageIndex = tnIP.SelectedImageIndex = 18; tnIP.Tag = "iprange"; } if (tnIP == null) { return; } iprange = string.Format("{0}.{1}.0.0", IPBytes[0], IPBytes[1]); if (tnIP.Nodes[iprange] != null) { tnIP = tnIP.Nodes[iprange]; } else { tnIP = tnIP.Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnIP.Nodes, iprange), iprange, iprange); tnIP.ContextMenuStrip = Program.FormMainInstance.contextMenu; tnIP.ImageIndex = tnIP.SelectedImageIndex = 18; tnIP.Tag = "iprange"; } if (tnIP == null) { return; } iprange = string.Format("{0}.{1}.{2}.0", IPBytes[0], IPBytes[1], IPBytes[2]); if (tnIP.Nodes[iprange] != null) { tnIP = tnIP.Nodes[iprange]; } else { tnIP = tnIP.Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnIP.Nodes, iprange), iprange, iprange); tnIP.ContextMenuStrip = Program.FormMainInstance.contextMenu; tnIP.ImageIndex = tnIP.SelectedImageIndex = 18; tnIP.Tag = "iprange"; } iprange = string.Format("{0}.{1}.{2}.{3}", IPBytes[0], IPBytes[1], IPBytes[2], IPBytes[3]); if (tnIP.Nodes[iprange] != null) { tn = tnIP.Nodes[iprange]; } else { tn = tnIP.Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnIP.Nodes, iprange), iprange, computer.name); tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } if (tn == null) { return; } } //IP de clase B else if (IPBytes[0] >= 128 && IPBytes[0] < 192) { TreeNode tnIP = null; string iprange = string.Format("{0}.{1}.0.0", IPBytes[0], IPBytes[1]); if (tnPCServers.Nodes["Servers"].Nodes[iprange] != null) { tnIP = tnPCServers.Nodes["Servers"].Nodes[iprange]; } else { tnIP = tnPCServers.Nodes["Servers"].Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnPCServers.Nodes["Servers"].Nodes, iprange), iprange, iprange); tnIP.ContextMenuStrip = Program.FormMainInstance.contextMenu; tnIP.ImageIndex = tnIP.SelectedImageIndex = 18; tnIP.Tag = "iprange"; } if (tnIP == null) { return; } iprange = string.Format("{0}.{1}.{2}.0", IPBytes[0], IPBytes[1], IPBytes[2]); if (tnIP.Nodes[iprange] != null) { tnIP = tnIP.Nodes[iprange]; } else { tnIP = tnIP.Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnIP.Nodes, iprange), iprange, iprange); tnIP.ContextMenuStrip = Program.FormMainInstance.contextMenu; tnIP.ImageIndex = tnIP.SelectedImageIndex = 18; tnIP.Tag = "iprange"; } iprange = string.Format("{0}.{1}.{2}.{3}", IPBytes[0], IPBytes[1], IPBytes[2], IPBytes[3]); if (tnIP.Nodes[iprange] != null) { tn = tnIP.Nodes[iprange]; } else { tn = tnIP.Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnIP.Nodes, iprange), iprange, computer.name); tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } } //IP de clase C else if (IPBytes[0] >= 192 && IPBytes[0] < 240) { TreeNode tnIP = null; string iprange = string.Format("{0}.{1}.{2}.0", IPBytes[0], IPBytes[1], IPBytes[2]); if (tnPCServers.Nodes["Servers"].Nodes[iprange] != null) { tnIP = tnPCServers.Nodes["Servers"].Nodes[iprange]; } else { tnIP = tnPCServers.Nodes["Servers"].Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnPCServers.Nodes["Servers"].Nodes, iprange), iprange, iprange); tnIP.ContextMenuStrip = Program.FormMainInstance.contextMenu; tnIP.ImageIndex = tnIP.SelectedImageIndex = 18; tnIP.Tag = "iprange"; } if (tnIP == null) { return; } iprange = string.Format("{0}.{1}.{2}.{3}", IPBytes[0], IPBytes[1], IPBytes[2], IPBytes[3]); if (tnIP.Nodes[iprange] != null) { tn = tnIP.Nodes[iprange]; } else { tn = tnIP.Nodes.Insert(Program.FormMainInstance.SearchTextInNodes(tnIP.Nodes, iprange), iprange, computer.name); tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } } nServers++; } else { //ipv6 } } } break; } Program.FormMainInstance.TreeView.Invoke(new MethodInvoker(delegate { if (tn == null) { return; } tn.Tag = computer; if (computer.os != OperatingSystem.OS.Unknown) { tn.ImageIndex = tn.SelectedImageIndex = OperatingSystemUtils.OSToIconNumber(computer.os); } else { tn.ImageIndex = tn.SelectedImageIndex = computer.type == ComputersItem.Tipo.ClientPC ? 111 : 45; } var computersDomain = Program.data.computerDomains.Items; foreach (var cdi in computersDomain.Where(x => x.Computer == computer)) { if (cdi.Domain == null) { continue; } if (!(tn.Nodes.ContainsKey(cdi.Domain.Domain))) { var newTn = new TreeNode(cdi.Domain.Domain); newTn.Text = cdi.Domain.Domain; newTn.Name = cdi.Domain.Domain; newTn.Tag = cdi; if (cdi.Domain.os == OperatingSystem.OS.Unknown) { newTn.SelectedImageIndex = newTn.ImageIndex = 90; } else { newTn.SelectedImageIndex = newTn.ImageIndex = OperatingSystemUtils.OSToIconNumber(cdi.Domain.os); } tn.Nodes.Add(newTn); } } foreach (var cdi in Program.data.computerDomains.Items) { if (cdi.Domain == null) { return; } var oldTn = tn.Nodes[cdi.Domain.Domain]; if (oldTn == null) { continue; } if (cdi.Domain == null) { continue; } oldTn.ImageIndex = OperatingSystemUtils.OSToIconNumber(cdi.Domain.os); oldTn.SelectedImageIndex = oldTn.ImageIndex; OperatingSystem.OS lastOsDom = OperatingSystem.OS.Unknown; var networkDevice = false; lastOsDom = OperatingSystem.OS.Unknown; foreach (ComputerDomainsItem cdiDom in from TreeNode tnDom in tn.Nodes where tnDom.Tag is ComputerDomainsItem select(ComputerDomainsItem) tnDom.Tag) { if ((cdiDom.Domain.os != lastOsDom) && (cdiDom.Domain.os != OperatingSystem.OS.Unknown) && (lastOsDom != OperatingSystem.OS.Unknown)) { networkDevice = true; break; } if (cdiDom.Domain.os != OperatingSystem.OS.Unknown) { lastOsDom = cdiDom.Domain.os; } } if (networkDevice) { tn.ImageIndex = tn.SelectedImageIndex = 100; } else if (lastOsDom != OperatingSystem.OS.Unknown) { tn.ImageIndex = tn.SelectedImageIndex = OperatingSystemUtils.OSToIconNumber(lastOsDom); } } if (computer.Users.Items.Count > 0) { TreeNode tnUsers; if (tn.Nodes["Users"] == null) { tnUsers = tn.Nodes.Add("Users", "Users"); tnUsers.ImageIndex = tnUsers.SelectedImageIndex = 14; } else { tnUsers = tn.Nodes["Users"]; } tnUsers.Tag = computer.Users; } else if (tn.Nodes["Users"] != null) { tn.Nodes["Users"].Remove(); } if (computer.Description.Items.Count > 0) { TreeNode tnDescription; if (tn.Nodes["Description"] == null) { tnDescription = tn.Nodes.Add("Description", "Description"); } else { tnDescription = tn.Nodes["Description"]; } tnDescription.Tag = computer.Description; } else if (tn.Nodes["Description"] != null) { tn.Nodes["Description"].Remove(); } if (computer.RemotePasswords.Items.Count > 0) { TreeNode tnPasswords; if (tn.Nodes["Passwords"] == null) { tnPasswords = tn.Nodes.Add("Passwords", "Passwords"); tnPasswords.ImageIndex = tnPasswords.SelectedImageIndex = 121; } else { tnPasswords = tn.Nodes["Passwords"]; } tnPasswords.Tag = computer.RemotePasswords; } else if (tn.Nodes["Passwords"] != null) { tn.Nodes["Passwords"].Remove(); } if (computer.Folders.Items.Count > 0) { TreeNode tnFolders; if (tn.Nodes["Folders"] == null) { tnFolders = tn.Nodes.Add("Folders", "Folders"); tnFolders.ImageIndex = tnFolders.SelectedImageIndex = 117; } else { tnFolders = tn.Nodes["Folders"]; } tnFolders.Tag = computer.Folders; } else if (tn.Nodes["Folders"] != null) { tn.Nodes["Folders"].Remove(); } if (computer.Printers.Items.Count > 0) { TreeNode tnPrinters; if (tn.Nodes["Printers"] == null) { tnPrinters = tn.Nodes.Add("Printers", "Printers"); tnPrinters.ImageIndex = tnPrinters.SelectedImageIndex = 118; } else { tnPrinters = tn.Nodes["Printers"]; } tnPrinters.Tag = computer.Printers; } else if (tn.Nodes["Printers"] != null) { tn.Nodes["Printers"].Remove(); } if (computer.RemoteUsers.Items.Count > 0) { TreeNode tnRemoteUsers; if (tn.Nodes["Users with access"] == null) { tnRemoteUsers = tn.Nodes.Add("Users with access", "Users with access"); tnRemoteUsers.ImageIndex = tnRemoteUsers.SelectedImageIndex = 43; } else { tnRemoteUsers = tn.Nodes["Users with access"]; } tnRemoteUsers.Tag = computer.RemoteUsers; } else if (tn.Nodes["Users with access"] != null) { tn.Nodes["Users with access"].Remove(); } if (computer.RemoteFolders.Items.Count > 0) { TreeNode tnRemoteFolders; if (tn.Nodes["Remote Folders"] == null) { tnRemoteFolders = tn.Nodes.Add("Remote Folders", "Remote Folders"); tnRemoteFolders.ImageIndex = tnRemoteFolders.SelectedImageIndex = 42; } else { tnRemoteFolders = tn.Nodes["Remote Folders"]; } tnRemoteFolders.Tag = computer.RemoteFolders; } else if (tn.Nodes["Remote Folders"] != null) { tn.Nodes["Remote Folders"].Remove(); } if (computer.RemotePrinters.Items.Count > 0) { TreeNode tnRemotePrinters; if (tn.Nodes["Remote Printers"] == null) { tnRemotePrinters = tn.Nodes.Add("Remote Printers", "Remote Printers"); tnRemotePrinters.ImageIndex = tnRemotePrinters.SelectedImageIndex = 44; } else { tnRemotePrinters = tn.Nodes["Remote Printers"]; } tnRemotePrinters.Tag = computer.RemotePrinters; } else if (tn.Nodes["Remote Printers"] != null) { tn.Nodes["Remote Printers"].Remove(); } })); } } if (tnPCServers != null) { for (var i = tnPCServers.Nodes["Clients"].Nodes.Count; i > 0; i--) { var tn = tnPCServers.Nodes["Clients"].Nodes[i - 1]; if (!Program.data.computers.Items.Any(C => C.type == ComputersItem.Tipo.ClientPC && C.name.ToLower() == tn.Text.ToLower())) { Program.FormMainInstance.TreeView.Invoke(new MethodInvoker(delegate { tn.Remove(); })); } } Program.FormMainInstance.DeleteNodesServers(tnPCServers.Nodes["Servers"].Nodes); Program.FormMainInstance.TreeView.Invoke(new MethodInvoker(delegate { tnPCServers.Nodes["Clients"].Text = string.Format("Clients ({0})", tnPCServers.Nodes["Clients"].Nodes.Count); })); tnPCServers.Nodes["Servers"].Text = string.Format("Servers ({0})", nServers); } }
/// <summary> /// Process Network nodes. /// </summary> private static void NodeNetworkProcess() { if (Program.data == null) { return; } TreeNode tnPCServers = Program.FormMainInstance.TreeView.GetNode(Navigation.Project.Network.ToNavigationPath()); int nServers = 0; if (tnPCServers != null) { List <ComputersItem> lst = new List <ComputersItem>(Program.data.computers.Items); foreach (ComputersItem computer in lst) { System.Windows.Forms.Application.DoEvents(); TreeNode tn = null; switch (computer.type) { case ComputersItem.Tipo.ClientPC: { tn = tnPCServers.Nodes[Navigation.Project.Network.Clients.Key].Nodes[computer.name]; if (tn == null) { int insertAtIndex = Program.FormMainInstance.SearchTextInNodes(tnPCServers.Nodes[Navigation.Project.Network.Clients.Key].Nodes, computer.name); tn = tnPCServers.Nodes[Navigation.Project.Network.Clients.Key].Nodes.Insert(insertAtIndex, computer.name, computer.name); tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } else { tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } } break; case ComputersItem.Tipo.Server: { //Si no tiene una IP asociada añadir al nodo de servidores desconocidos if (!Program.data.computerIPs.Items.Any(C => C.Computer.name == computer.name)) { TreeNode unknownServers = tnPCServers.Nodes[Navigation.Project.Network.Servers.Key].Nodes[Navigation.Project.Network.Servers.Unknown.Key]; if (unknownServers.Nodes[computer.name] != null) { tn = unknownServers.Nodes[computer.name]; } else { int insertAtIndex = Program.FormMainInstance.SearchTextInNodes(unknownServers.Nodes, computer.name); tn = unknownServers.Nodes.Insert(insertAtIndex, computer.name, computer.name); tn.ContextMenuStrip = Program.FormMainInstance.contextMenu; } } else //Como tiene una IP asociada insertar en su rango { string strIP = Program.data.computerIPs.Items.First(C => C.Computer.name == computer.name).Ip.Ip; if (Program.data.Project.IsIpInNetrange(strIP) == false) { continue; } bool found = false; foreach (RelationsItem relation in Program.data.relations.Items.Where(S => S.Ip.Ip == strIP)) { if (relation.Domain.Domain.Contains(Program.data.Project.Domain)) { found = true; break; } foreach (string auxDom in Program.data.Project.AlternativeDomains) { if (relation.Domain.Domain.Contains(auxDom)) { found = true; break; } } } if (!found && DNSUtil.IsIPv4(strIP)) { if (Program.data.IsIpInLimitRange(strIP)) { found = true; } } if (!found) { continue; } //Comprobar que existe el rango if (DNSUtil.IsIPv4(strIP)) { byte[] IPBytes = DNSUtil.IPToByte(strIP); int indexFirstSegment = -1; //IPAddress class A if (IPBytes[0] >= 1 && IPBytes[0] < 128) { indexFirstSegment = 0; } //IPAddress class B else if (IPBytes[0] >= 128 && IPBytes[0] < 192) { indexFirstSegment = 1; } //IPAddress class C else if (IPBytes[0] >= 192 && IPBytes[0] < 240) { indexFirstSegment = 2; } else { return; } tn = GenerateIPRangesNodes(IPBytes, tnPCServers.Nodes[Navigation.Project.Network.Servers.Key], indexFirstSegment); nServers++; } else { //ipv6 } } } break; } if (tn == null) { return; } tn.Text = computer.name; tn.Tag = computer; if (computer.os != OperatingSystem.OS.Unknown) { tn.ImageIndex = tn.SelectedImageIndex = OperatingSystemUtils.OSToIconNumber(computer.os); } else { tn.ImageIndex = tn.SelectedImageIndex = computer.type == ComputersItem.Tipo.ClientPC ? 111 : 45; } foreach (ComputerDomainsItem cdi in Program.data.computerDomains.Items) { if (cdi.Domain == null) { continue; } if (cdi.Computer == computer) { if (!tn.Nodes.ContainsKey(cdi.Domain.Domain)) { TreeNode newTn = new TreeNode(cdi.Domain.Domain); newTn.Text = cdi.Domain.Domain; newTn.Name = cdi.Domain.Domain; newTn.Tag = cdi; if (cdi.Domain.os == OperatingSystem.OS.Unknown) { newTn.SelectedImageIndex = newTn.ImageIndex = 90; } else { newTn.SelectedImageIndex = newTn.ImageIndex = OperatingSystemUtils.OSToIconNumber(cdi.Domain.os); } tn.Nodes.Add(newTn); } } TreeNode oldTn = tn.Nodes[cdi.Domain.Domain]; if (oldTn == null) { continue; } oldTn.ImageIndex = OperatingSystemUtils.OSToIconNumber(cdi.Domain.os); oldTn.SelectedImageIndex = oldTn.ImageIndex; OperatingSystem.OS lastOsDom = OperatingSystem.OS.Unknown; bool networkDevice = false; foreach (ComputerDomainsItem cdiDom in from TreeNode tnDom in tn.Nodes where tnDom.Tag is ComputerDomainsItem select(ComputerDomainsItem) tnDom.Tag) { if ((cdiDom.Domain.os != lastOsDom) && (cdiDom.Domain.os != OperatingSystem.OS.Unknown) && (lastOsDom != OperatingSystem.OS.Unknown)) { networkDevice = true; break; } if (cdiDom.Domain.os != OperatingSystem.OS.Unknown) { lastOsDom = cdiDom.Domain.os; } } if (networkDevice) { tn.ImageIndex = tn.SelectedImageIndex = 100; } else if (lastOsDom != OperatingSystem.OS.Unknown) { tn.ImageIndex = tn.SelectedImageIndex = OperatingSystemUtils.OSToIconNumber(lastOsDom); } } if (computer.Users.Items.Count > 0) { TreeNode tnUsers; if (tn.Nodes["Users"] == null) { tnUsers = tn.Nodes.Add("Users", "Users"); tnUsers.ImageIndex = tnUsers.SelectedImageIndex = 14; } else { tnUsers = tn.Nodes["Users"]; } tnUsers.Tag = computer.Users; } else if (tn.Nodes["Users"] != null) { tn.Nodes["Users"].Remove(); } if (computer.Description.Items.Count > 0) { TreeNode tnDescription; if (tn.Nodes["Description"] == null) { tnDescription = tn.Nodes.Add("Description", "Description"); } else { tnDescription = tn.Nodes["Description"]; } tnDescription.Tag = computer.Description; } else if (tn.Nodes["Description"] != null) { tn.Nodes["Description"].Remove(); } if (computer.RemotePasswords.Items.Count > 0) { TreeNode tnPasswords; if (tn.Nodes["Passwords"] == null) { tnPasswords = tn.Nodes.Add("Passwords", "Passwords"); tnPasswords.ImageIndex = tnPasswords.SelectedImageIndex = 121; } else { tnPasswords = tn.Nodes["Passwords"]; } tnPasswords.Tag = computer.RemotePasswords; } else if (tn.Nodes["Passwords"] != null) { tn.Nodes["Passwords"].Remove(); } if (computer.Folders.Items.Count > 0) { TreeNode tnFolders; if (tn.Nodes["Folders"] == null) { tnFolders = tn.Nodes.Add("Folders", "Folders"); tnFolders.ImageIndex = tnFolders.SelectedImageIndex = 117; } else { tnFolders = tn.Nodes["Folders"]; } tnFolders.Tag = computer.Folders; } else if (tn.Nodes["Folders"] != null) { tn.Nodes["Folders"].Remove(); } if (computer.Printers.Items.Count > 0) { TreeNode tnPrinters; if (tn.Nodes["Printers"] == null) { tnPrinters = tn.Nodes.Add("Printers", "Printers"); tnPrinters.ImageIndex = tnPrinters.SelectedImageIndex = 118; } else { tnPrinters = tn.Nodes["Printers"]; } tnPrinters.Tag = computer.Printers; } else if (tn.Nodes["Printers"] != null) { tn.Nodes["Printers"].Remove(); } if (computer.RemoteUsers.Items.Count > 0) { TreeNode tnRemoteUsers; if (tn.Nodes["Users with access"] == null) { tnRemoteUsers = tn.Nodes.Add("Users with access", "Users with access"); tnRemoteUsers.ImageIndex = tnRemoteUsers.SelectedImageIndex = 43; } else { tnRemoteUsers = tn.Nodes["Users with access"]; } tnRemoteUsers.Tag = computer.RemoteUsers; } else if (tn.Nodes["Users with access"] != null) { tn.Nodes["Users with access"].Remove(); } if (computer.RemoteFolders.Items.Count > 0) { TreeNode tnRemoteFolders; if (tn.Nodes["Remote Folders"] == null) { tnRemoteFolders = tn.Nodes.Add("Remote Folders", "Remote Folders"); tnRemoteFolders.ImageIndex = tnRemoteFolders.SelectedImageIndex = 42; } else { tnRemoteFolders = tn.Nodes["Remote Folders"]; } tnRemoteFolders.Tag = computer.RemoteFolders; } else if (tn.Nodes["Remote Folders"] != null) { tn.Nodes["Remote Folders"].Remove(); } if (computer.RemotePrinters.Items.Count > 0) { TreeNode tnRemotePrinters; if (tn.Nodes["Remote Printers"] == null) { tnRemotePrinters = tn.Nodes.Add("Remote Printers", "Remote Printers"); tnRemotePrinters.ImageIndex = tnRemotePrinters.SelectedImageIndex = 44; } else { tnRemotePrinters = tn.Nodes["Remote Printers"]; } tnRemotePrinters.Tag = computer.RemotePrinters; } else if (tn.Nodes["Remote Printers"] != null) { tn.Nodes["Remote Printers"].Remove(); } } } if (tnPCServers != null) { for (int i = tnPCServers.Nodes["Clients"].Nodes.Count; i > 0; i--) { TreeNode tn = tnPCServers.Nodes["Clients"].Nodes[i - 1]; if (!Program.data.computers.Items.Any(C => C.type == ComputersItem.Tipo.ClientPC && C.name.ToLower() == tn.Text.ToLower())) { tn.Remove(); } } Program.FormMainInstance.DeleteNodesServers(tnPCServers.Nodes["Servers"].Nodes); tnPCServers.Nodes["Clients"].Text = string.Format("Clients ({0})", tnPCServers.Nodes["Clients"].Nodes.Count); tnPCServers.Nodes["Servers"].Text = string.Format("Servers ({0})", nServers); } }
/// <summary> /// Add Ip. /// </summary> /// <param name="ip"></param> /// <param name="source"></param> /// <param name="domainSource"></param> public void AddIP(string ip, string source, string domainSource, int MaxRecursion, bool doptr) { ip = ip.Trim(); if (isIPv6(ip)) { ip = ParseIPV6(ip); } if (!Ips.Items.Any(I => I.Ip.ToLower() == ip.ToLower())) { if (isPublicIP(ip)) { var isInNetrange = Project.IsIpInNetrange(ip); if (!isInNetrange) { var host = string.Empty; try { host = Dns.GetHostEntry(ip).HostName; if (Program.data.Project.LstNetRange.Count == 0) { if (Program.data.Project.Domain != null) { if (!IsMainDomainOrAlternative(host)) { if (Program.data.Project.AlternativeDomains.Select(S => host.Contains(S.ToString())).Count() == 0) { string[] arrDom = host.Split(new char[] { '.' }); if (arrDom.Count() > 1) { string auxFinalDom = arrDom[arrDom.Length - 2] + "." + arrDom[arrDom.Length - 1]; Program.data.Project.AlternativeDomains.Add(auxFinalDom); Program.LogThis(new Log(Log.ModuleType.FOCA, "IP address associated to " + Program.data.Project.Domain + " belongs to a Netrange of " + auxFinalDom + ". It is going to be added as an alternative domain.", Log.LogType.low)); } } } } } } catch (Exception) { } if (IsMainDomainOrAlternative(host)) { var netrange = Project.GetNetrange(ip); if (netrange != null) { Project.LstNetRange.Add(netrange); #if PLUGINS Thread tPluginOnNetrange = new Thread(new ParameterizedThreadStart(Program.data.plugins.OnNewNetrange)); tPluginOnNetrange.IsBackground = true; object[] oNetRange = new object[] { new object[] { netrange.from, netrange.to } }; tPluginOnNetrange.Start(oNetRange); #endif if (!Program.cfgCurrent.ScanNetranges255 || Project.GetIpsOfNetrange(netrange) <= 255) { List <string> lstIps = netrange.GenerateIpsOfNetrange(); Program.LogThis(new Log(Log.ModuleType.IPRangeSearch, "Netrange with " + lstIps.Count.ToString() + " IPs", Log.LogType.low)); Thread tAddIps = new Thread(new ParameterizedThreadStart(AddIpListAsync)); tAddIps.IsBackground = true; tAddIps.Priority = ThreadPriority.Lowest; tAddIps.Start(lstIps); } } } } } var ipItem = new IPsItem(ip, source); Ips.Items.Add(ipItem); // OnNewIP #if PLUGINS Thread tPluginOnIP = new Thread(new ParameterizedThreadStart(Program.data.plugins.OnNewIP)); tPluginOnIP.IsBackground = true; object[] oIP = new object[] { new object[] { ip } }; tPluginOnIP.Start(oIP); #endif if (MaxRecursion <= 0) { OnChangeEvent(null); return; } List <string> domains; if (doptr) { if (domainSource != null) { if (Program.cfgCurrent.UseAllDns) { domains = new List <string>(); List <string> dnsServers = DNSUtil.GetNSServer(resolver, domainSource, DNSUtil.GetLocalNSServer().First().ToString()); foreach (string dns in dnsServers) { OnLog(null, new EventsThreads.ThreadStringEventArgs(string.Format("Making reverse resolution to IP: {0} Using DNS server: {1}", ip, dns))); foreach (var domain in DNSUtil.GetHostNames(resolver, ip, dns).Where(domain => !domains.Contains(domain))) { domains.Add(domain); } } } else { var dnsserver = DNSUtil.GetNSServer(resolver, domainSource); OnLog(null, new EventsThreads.ThreadStringEventArgs(string.Format("Making reverse resolution to IP: {0} Using DNS server: {1}", ip, dnsserver))); domains = DNSUtil.GetHostNames(resolver, ip, dnsserver); } } else { domains = DNSUtil.GetHostNames(resolver, ip); } foreach (var domain in domains) { AddResolution(domain, ip, string.Format("{0} > DNS reverse resolution [{1}]", GetIpSource(ip), domain), MaxRecursion - 1, Program.cfgCurrent, true); } } OnChangeEvent(null); } }
/// <summary> /// Add domain if this not exist in the list. /// </summary> /// <param name="domain"></param> /// <param name="source"></param> /// <param name="maxRecursion"></param> /// <param name="cfgCurrent"></param> public void AddDomain(string domain, string source, int maxRecursion, Configuration cfgCurrent) { domain = domain.Trim(); if (domains.Items.Any(S => S.Domain.ToLower() == domain.ToLower())) { return; } var dItem = new DomainsItem(domain, source); domains.Items.Add(dItem); #if PLUGINS Thread tPluginOnDomain = new Thread(new ParameterizedThreadStart(Program.data.plugins.OnNewDomain)); tPluginOnDomain.IsBackground = true; object[] oDomain = new object[] { new object[] { domain } }; tPluginOnDomain.Start(oDomain); #endif var domainParts = domain.Split('.'); var currentdomain = domainParts[domainParts.Length - 1]; for (var i = 2; i < domainParts.Length; i++) { currentdomain = domainParts[domainParts.Length - i] + "." + currentdomain; AddDomain(currentdomain, string.Format("{0} > Inferred by {2} [{1}]", GetDomainSource(domain), currentdomain, domain), maxRecursion - 1, cfgCurrent); } if (maxRecursion <= 0) { OnChangeEvent(null); return; } //OnLog(null, new EventsThreads.ThreadStringEventArgs(string.Format("Resolving domain: {0}", domain))); var listIpsOfDomain = DNSUtil.GetHostAddresses(domain); if (listIpsOfDomain.Count == 0) { var computer = new ComputersItem(); computer.type = ComputersItem.Tipo.Server; computer.name = domain; computer.NotOS = true; computer.os = OperatingSystem.OS.Unknown; if (!computers.Items.Any(S => S.name == domain)) { computers.Items.Add(computer); } } foreach (var IP in listIpsOfDomain) { if (Program.data.IsMainDomainOrAlternative(domain)) { var limit = Program.data.GetLimitFromIp(IP.ToString()); if (limit == null) { Program.data.AddLimit(new Limits(IP.ToString())); } else { var lastOct = int.Parse(IP.ToString().Split(new char[] { '.' })[3]); if (lastOct < limit.Lower) { limit.Lower = lastOct; } else if (lastOct > limit.Higher) { limit.Higher = lastOct; } } } AddResolution(domain, IP.ToString(), string.Format("{0} > DNS resolution [{1}]", GetDomainSource(domain), IP.ToString()), maxRecursion - 1, Program.cfgCurrent, false); } // Fingerprinting HTTP if (cfgCurrent.PassiveFingerPrintingHttp && cfgCurrent.FingerPrintingAllHttp) { if (NewDomainByHTTPServer != null) { NewDomainByHTTPServer(dItem, null); } } else if ((cfgCurrent.PassiveFingerPrintingHttp) && (source.ToLower() == "documents search" || source.ToLower().Contains("websearch") || source.ToLower().Contains("bing ip search") || source.ToLower().Contains("technologyrecognition") || source.ToLower().Contains("fingerprinting") || source.ToLower().Contains("certificate fingerprinting"))) { if (NewDomainByHTTPServer != null) { NewDomainByHTTPServer(dItem, null); } } // Fingerprinting SMTP if (cfgCurrent.PasiveFingerPrintingSmtp && cfgCurrent.FingerPrintingAllSmtp) { if (NewDomainByMXServer != null) { NewDomainByMXServer(dItem, null); } } else if ((cfgCurrent.PasiveFingerPrintingSmtp) && (source.ToLower().Contains("mx server"))) { if (NewDomainByMXServer != null) { NewDomainByMXServer(dItem, null); } } // Fingerprinting FTP if (cfgCurrent.FingerPrintingAllFtp) { if (NewDomainByFTPServer != null) { NewDomainByFTPServer(dItem, null); } } OnChangeEvent(null); }