Skip to content

Commit

Permalink
Minor fixes (#81)
Browse files Browse the repository at this point in the history
* Minor fixes

* Fix bug in PanelMetadataSearch.JoinComputers()
* Fix possible bug in DuckduckgoWebSearcher.GetPostData() (please review)
* Minor fixes and refactorings

Note how there's something wrong in OpenOfficeDocumment.analizeFileSettings

* Fix compilation, reverting minor change.
  • Loading branch information
eduherminio authored and Ioseba Palop committed Oct 7, 2019
1 parent d8bab10 commit 01a7ff1
Show file tree
Hide file tree
Showing 19 changed files with 809 additions and 846 deletions.
38 changes: 13 additions & 25 deletions FOCA/Analysis/FingerPrinting/FingerPrintingEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ public static void fprinting_FingerPrintingError(object sender, EventArgs e)
static public void data_NewWebDomain(object sender, EventArgs e)
{
// Nuevo dominio web extraido
if (sender is DomainsItem)
if (sender is DomainsItem domain)
{
DomainsItem domain = (DomainsItem)sender;
//Solo se hace fingerPrinting a los dominios principales y alternativos
List<string> mainDomains = new List<string>();

Expand All @@ -35,7 +34,7 @@ static public void data_NewWebDomain(object sender, EventArgs e)
return;

bool existeFP = false;
for (int fpI = 0; fpI < domain.fingerPrinting.Count(); fpI++)
for (int fpI = 0; fpI < domain.fingerPrinting.Count; fpI++)
{
FingerPrinting fp = domain.fingerPrinting[fpI];

Expand Down Expand Up @@ -101,9 +100,8 @@ static public void data_NewWebDomain(object sender)
static public void data_NewMXDomain(object sender, EventArgs e)
{
// Nuevo dominio MX extraido
if (sender is DomainsItem)
if (sender is DomainsItem domain)
{
DomainsItem domain = (DomainsItem)sender;
//Solo se hace fingerPrinting a los dominios principales y alternativos
List<string> mainDomains = new List<string>();
if (string.IsNullOrEmpty(Program.data.Project.Domain))
Expand All @@ -115,7 +113,7 @@ static public void data_NewMXDomain(object sender, EventArgs e)
return;

bool existeFP = false;
for (int fpI = 0; fpI < domain.fingerPrinting.Count(); fpI++)
for (int fpI = 0; fpI < domain.fingerPrinting.Count; fpI++)
{
FingerPrinting fp = domain.fingerPrinting[fpI];

Expand Down Expand Up @@ -143,9 +141,8 @@ static public void data_NewMXDomain(object sender)
static public void data_NewFTPDomain(object sender, EventArgs e)
{
// Nuevo dominio FTP extraido
if (sender is DomainsItem)
if (sender is DomainsItem domain)
{
DomainsItem domain = (DomainsItem)sender;
//Solo se hace fingerPrinting a los dominios principales y alternativos
List<string> mainDomains = new List<string>();
if (string.IsNullOrEmpty(Program.data.Project.Domain))
Expand All @@ -156,7 +153,7 @@ static public void data_NewFTPDomain(object sender, EventArgs e)
return;

bool existeFP = false;
for (int fpI = 0; fpI < domain.fingerPrinting.Count(); fpI++)
for (int fpI = 0; fpI < domain.fingerPrinting.Count; fpI++)
{
FingerPrinting fp = domain.fingerPrinting[fpI];

Expand Down Expand Up @@ -184,16 +181,15 @@ static public void data_NewFTPDomain(object sender)
static public void data_NewDNSDomain(object sender, EventArgs e)
{
// Nuevo dominio DNS extraido
if (sender is DomainsItem)
if (sender is DomainsItem domain)
{
DomainsItem domain = (DomainsItem)sender;
//Solo se hace fingerPrinting a los dominios principales y alternativos
List<string> mainDomains = new List<string>();
if (string.IsNullOrEmpty(Program.data.Project.Domain))
return;

bool existeFP = false;
for (int fpI = 0; fpI < domain.fingerPrinting.Count(); fpI++)
for (int fpI = 0; fpI < domain.fingerPrinting.Count; fpI++)
{
FingerPrinting fp = domain.fingerPrinting[fpI];

Expand Down Expand Up @@ -223,10 +219,8 @@ static public void AsociateFingerPrinting(object sender, EventArgs e)
if (sender == null)
return;
DomainsItem domain = null;
if (sender is HTTP)
if (sender is HTTP http)
{
HTTP http = (HTTP)sender;

domain = Program.data.GetDomain(http.Host);
if (domain != null)
domain.fingerPrinting.Add(http);
Expand All @@ -242,28 +236,22 @@ static public void AsociateFingerPrinting(object sender, EventArgs e)
}
}
}
else if (sender is SMTP)
else if (sender is SMTP smtp)
{
SMTP smtp = (SMTP)sender;

domain = Program.data.GetDomain(smtp.Host);
{
domain.fingerPrinting.Add(smtp);
}
}
else if (sender is FTP)
else if (sender is FTP ftp)
{
FTP ftp = (FTP)sender;

domain = Program.data.GetDomain(ftp.Host);
{
domain.fingerPrinting.Add(ftp);
}
}
else if (sender is DNS)
else if (sender is DNS dns)
{
DNS dns = (DNS)sender;

domain = Program.data.GetDomain(dns.Host);
{
domain.fingerPrinting.Add(dns);
Expand All @@ -286,7 +274,7 @@ private static void ActualizaSOServidores(DomainsItem di)
i++;
{
//Se usa el fingerPrint del dominio para asignar un SO al servidor
for (int fpI = 0; fpI < di.fingerPrinting.Count(); fpI++)
for (int fpI = 0; fpI < di.fingerPrinting.Count; fpI++)
{
Analysis.FingerPrinting.FingerPrinting fp = di.fingerPrinting[fpI];
//Nos fiamos mas del so obtenido mediante fingerprinting que el que pueda haber sido obtenido en Shodan
Expand Down
8 changes: 4 additions & 4 deletions FOCA/Analysis/HttpMap/HttpMap.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using FOCA.Analysis.FingerPrinting;
using FOCA.Analysis.FingerPrinting;
using FOCA.Analysis.Technology;
using FOCA.Database.Entities;
using FOCA.ModifiedComponents;
Expand Down Expand Up @@ -147,7 +147,7 @@ public static void CheckRobots(string host, int port)
string line;
while ((line = sr.ReadLine()) != null)
{
if (line.Split(' ').Count() <= 1)
if (line.Split(' ').Length <= 1)
continue;
var path = line.Split(' ')[1];
if (path.Contains("*"))
Expand Down Expand Up @@ -434,7 +434,7 @@ private static ThreadSafeList<string> _MutexFileRuntime(string path, string file

foreach (var newFile in (from newExt in backupExt.Concat(oldVersions)
let aux = path.Split(new[] { "/" }, StringSplitOptions.None)
let realPath = string.Join("/", aux.Take(aux.Count() - 1)) + "/"
let realPath = string.Join("/", aux.Take(aux.Length - 1)) + "/"
select (string.Equals(newExt, "~"))
? realPath + fileName + "." + fileExtension + newExt
: realPath + fileName + "." + fileExtension + "." + newExt).Where(
Expand Down Expand Up @@ -647,4 +647,4 @@ public void Dispose()

#endregion
}
}
}
39 changes: 18 additions & 21 deletions FOCA/DNSEnumeration/DNSUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static List<string> GetHostNames(Resolver r, string ip, string NSServer)
}
}
}
catch {}
catch { }
finally
{
r.DnsServers = lastNSServers.ToArray();
Expand Down Expand Up @@ -185,20 +185,17 @@ public static List<string> GetNSServer(Resolver r, string domain, string NSServe
//No es autoritativa, volver a preguntar
if (!response.header.AA)
{
if (response.RecordsNS.Length > 0)
foreach (RecordNS rNS in response.RecordsNS)
{
foreach (RecordNS rNS in response.RecordsNS)
if (NSServer != rNS.NSDNAME)
{
if (NSServer != rNS.NSDNAME)
{
foreach (string ns in GetNSServer(r, domain, rNS.NSDNAME))
if (!lst.Contains(ns, StringComparer.OrdinalIgnoreCase))
lst.Add(ns);
}
else
{
lst.Add(NSServer);
}
foreach (string ns in GetNSServer(r, domain, rNS.NSDNAME))
if (!lst.Contains(ns, StringComparer.OrdinalIgnoreCase))
lst.Add(ns);
}
else
{
lst.Add(NSServer);
}
}
}
Expand Down Expand Up @@ -228,19 +225,19 @@ public static List<string> GetNSServer(Resolver r, string domain, string NSServe
try
{
//Se devuelve el servidor DNS autoritativo
if (((RR)response.Authorities[0]).RECORD is RecordSOA)
if (response.Authorities[0].RECORD is RecordSOA recordSOA)
{
string dns = RemoveLastPoint(((RecordSOA)((RR)response.Authorities[0]).RECORD).MNAME);
string dns = RemoveLastPoint(recordSOA.MNAME);
if (TestDNS(dns))
{
List<string> lst = new List<string>();
lst.Add(dns);
return lst;
}
}
if (((RR)response.Authorities[0]).RECORD is RecordNS)
if (response.Authorities[0].RECORD is RecordNS recordNS)
{
string dns = RemoveLastPoint(((RecordNS)((RR)response.Authorities[0]).RECORD).NSDNAME);
string dns = RemoveLastPoint(recordNS.NSDNAME);
if (TestDNS(dns))
{
List<string> lst = new List<string>();
Expand Down Expand Up @@ -307,15 +304,15 @@ public static string GetNSServer(Resolver r, string domain)
try
{
//Se devuelve el servidor DNS autoritativo
if (((RR)response.Authorities[0]).RECORD is RecordSOA)
if ((response.Authorities[0]).RECORD is RecordSOA recordSOA)
{
string dns = RemoveLastPoint(((RecordSOA)((RR)response.Authorities[0]).RECORD).MNAME);
string dns = RemoveLastPoint(recordSOA.MNAME);
if (TestDNS(dns))
return dns;
}
if (((RR)response.Authorities[0]).RECORD is RecordNS)
if ((response.Authorities[0]).RECORD is RecordNS recordNS)
{
string dns = RemoveLastPoint(((RecordNS)((RR)response.Authorities[0]).RECORD).NSDNAME);
string dns = RemoveLastPoint(recordNS.NSDNAME);
if (TestDNS(dns))
return dns;
}
Expand Down
16 changes: 8 additions & 8 deletions FOCA/Database/Entities/Data.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using FOCA.Analysis.FingerPrinting;
using FOCA.Analysis.FingerPrinting;
using FOCA.ModifiedComponents;
using FOCA.Plugins;
using FOCA.TaskManager;
Expand Down Expand Up @@ -398,7 +398,7 @@ public static string ParseIPV6(string ip)
ip = ip + "0";

var sbIp = new StringBuilder();
for (var bloque = 0; bloque < ip.Split(new char[] { ':' }).Count(); bloque++)
for (var bloque = 0; bloque < ip.Split(new char[] { ':' }).Length; bloque++)
{
var sBloque = ip.Split(new char[] { ':' })[bloque];

Expand All @@ -416,12 +416,12 @@ public static string ParseIPV6(string ip)
}

sbIp.Append(sBloque);
if (bloque < ip.Split(new char[] { ':' }).Count() - 1)
if (bloque < ip.Split(new char[] { ':' }).Length - 1)
sbIp.Append(":");
}

var nBloquesReales = 8;
var nBloquesPadding = nBloquesReales - ip.Split(new char[] { ':' }).Count();
var nBloquesPadding = nBloquesReales - ip.Split(new char[] { ':' }).Length;

if (nBloquesPadding >= 0)
{
Expand All @@ -435,7 +435,7 @@ public static string ParseIPV6(string ip)
sbIp.Replace("[PADDING]", sbPadding.ToString());
}

if (sbIp.ToString().Split(new char[] { ':' }).Count() == 8 && sbIp.ToString().Length == 39)
if (sbIp.ToString().Split(new char[] { ':' }).Length == 8 && sbIp.ToString().Length == 39)
return sbIp.ToString();
return null;
}
Expand Down Expand Up @@ -497,7 +497,7 @@ public void AddIP(string ip, string source, string domainSource, int MaxRecursio
if (Program.data.Project.AlternativeDomains.Select(S => host.Contains(S.ToString())).Count() == 0)
{
string[] arrDom = host.Split(new char[] { '.' });
if (arrDom.Count() > 1)
if (arrDom.Length > 1)
{
string auxFinalDom = arrDom[arrDom.Length - 2] + "." + arrDom[arrDom.Length - 1];
Program.data.Project.AlternativeDomains.Add(auxFinalDom);
Expand Down Expand Up @@ -760,7 +760,7 @@ public ThreadSafeList<DomainsItem> GetResolutionDomains(string ip)
}

/// <summary>
///
///
/// </summary>
public void GetServersFromIPs()
{
Expand Down Expand Up @@ -823,7 +823,7 @@ public void GetServersFromIPs()
if (!computerDomains.Items.Any(C => C.Computer.name == ci.name && C.Domain.Domain == di.Domain))
computerDomains.Items.Add(new ComputerDomainsItem(ci, di, di.Source));
for (var fpI = 0; fpI < di.fingerPrinting.Count(); fpI++)
for (var fpI = 0; fpI < di.fingerPrinting.Count; fpI++)
{
var fp = di.fingerPrinting[fpI];
Expand Down
4 changes: 2 additions & 2 deletions FOCA/Database/Entities/Limits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Lower a Lower-1 y/o el Higher a Higher+1.
ip.Split(new char[] { '.' })[2] + "." +
(lastOct - 1).ToString();

int count = Program.data.GetRelationsOfIP(ipLimitInferior).Count();
int count = Program.data.GetRelationsOfIP(ipLimitInferior).Count;
if (count == 0)
this.Lower--;
}
Expand All @@ -66,7 +66,7 @@ Lower a Lower-1 y/o el Higher a Higher+1.
ip.Split(new char[] { '.' })[2] + "." +
(lastOct + 1).ToString();

int count = Program.data.GetRelationsOfIP(ipLimitSuperior).Count();
int count = Program.data.GetRelationsOfIP(ipLimitSuperior).Count;
if (count == 0)
this.Higher++;
}
Expand Down
Loading

0 comments on commit 01a7ff1

Please sign in to comment.