mod min
parent
4bf0c12507
commit
872c4f2c10
96
Program.cs
96
Program.cs
|
|
@ -14,33 +14,33 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace SharpScan
|
||||
{
|
||||
public class Options
|
||||
{
|
||||
[Option('h', "hosts", Required = true, Separator = ',', HelpText = "Hosts to scan, coma separated. CIDR accepted")]
|
||||
public IEnumerable<string> Hosts { get; set; }
|
||||
|
||||
[Option('p', "ports", Required = false, Separator = ',', HelpText = "TCP port to scan, coma separated")]
|
||||
public IEnumerable<string> Ports { get; set; }
|
||||
|
||||
[Option('t', "timeout", Required = false, Default = 500, HelpText = "Timeout in milliseconds to check a port")]
|
||||
public int Timeout { get; set; }
|
||||
|
||||
[Option('d', "delay", Required = false, Default = 0, HelpText = "Delay in milliseconds between 2 scan request")]
|
||||
public int Delay { get; set; }
|
||||
|
||||
[Option('j', "jittler", Required = false, Default = 0, HelpText = "Jittler to apply to delay, in percent, new evalutation for each request")]
|
||||
public int Jittler { get; set; }
|
||||
|
||||
[Option('r', "randomize", Required = false, Default = false, HelpText = "Randomize hosts/ports scan order. Results will be printed in normal order")]
|
||||
public bool Randomize { get; set; }
|
||||
|
||||
[Option('f', "top-ports", Required = false, Default = 0, HelpText = "Equivalent of nmap --top-ports option")]
|
||||
public int TopPorts { get; set; }
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
public class Options
|
||||
{
|
||||
[Option('h', "hosts", Required = true, Separator = ',', HelpText = "Hosts to scan, coma separated. CIDR accepted")]
|
||||
public IEnumerable<string> Hosts { get; set; }
|
||||
|
||||
[Option('p', "ports", Required = false, Separator = ',', HelpText = "TCP port to scan, coma separated")]
|
||||
public IEnumerable<int> Ports { get; set; }
|
||||
|
||||
[Option('t', "timeout", Required = false, Default = 500, HelpText = "Timeout in milliseconds to check a port")]
|
||||
public int Timeout { get; set; }
|
||||
|
||||
[Option('d', "delay", Required = false, Default = 0, HelpText = "Delay in milliseconds between 2 scan request")]
|
||||
public int Delay { get; set; }
|
||||
|
||||
[Option('j', "jittler", Required = false, Default = 0, HelpText = "Jittler to apply to delay, in percent, new evalutation for each request")]
|
||||
public int Jittler { get; set; }
|
||||
|
||||
[Option('r', "randomize", Required = false, Default = false, HelpText = "Randomize hosts/ports scan order. Results will be printed in normal order")]
|
||||
public bool Randomize { get; set; }
|
||||
|
||||
[Option('f', "top-ports", Required = false, Default = 0, HelpText = "Equivalent of nmap --top-ports option")]
|
||||
public int TopPorts { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public static List<string> GetIpsFromCidr(string cidr)
|
||||
|
|
@ -165,7 +165,7 @@ namespace SharpScan
|
|||
// Gestion des ports
|
||||
if (o.Ports.Count() > 0)
|
||||
{
|
||||
if (o.Ports.Count() == 1 && o.Ports.First() == -1)
|
||||
if (o.Ports.Count() == 1 && o.Ports.First() == "-")
|
||||
{
|
||||
foreach (int port in Enumerable.Range(0, 65536))
|
||||
{
|
||||
|
|
@ -174,9 +174,23 @@ namespace SharpScan
|
|||
}
|
||||
else
|
||||
{
|
||||
foreach (int port in o.Ports)
|
||||
foreach (string port in o.Ports)
|
||||
{
|
||||
ports.Add(port);
|
||||
if (port.Contains("-"))
|
||||
{
|
||||
int start = Int32.Parse(port.Split('-')[0]);
|
||||
int end = Int32.Parse(port.Split('-')[1]);
|
||||
int nb = end - start + 1;
|
||||
foreach (int i in Enumerable.Range(start, nb))
|
||||
{
|
||||
ports.Add(i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ports.Add(Int32.Parse(port));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -211,6 +225,7 @@ namespace SharpScan
|
|||
{
|
||||
foreach (int port in ports)
|
||||
{
|
||||
|
||||
cibles.Add((address, port));
|
||||
}
|
||||
}
|
||||
|
|
@ -220,8 +235,9 @@ namespace SharpScan
|
|||
Shuffle(cibles);
|
||||
}
|
||||
|
||||
// Check wich ports are available
|
||||
Random r;
|
||||
|
||||
// Check wich ports are available
|
||||
Random r;
|
||||
int sleep_value;
|
||||
Console.WriteLine($"There is {cibles.Count} requests to send !!!");
|
||||
|
||||
|
|
@ -230,26 +246,12 @@ namespace SharpScan
|
|||
chronometre.Start();
|
||||
|
||||
|
||||
int fraction = cibles.Count / 10;
|
||||
int cpt_fraction = 0;
|
||||
|
||||
// Estimation de la durée du scan
|
||||
int total = 0;
|
||||
total += ((delay + (jittler * delay / 100)) * cibles.Count) / 1000;
|
||||
total += (timeout * cibles.Count) / 1000;
|
||||
total += (2 * 100) / total; // On rajoute un chouilla pour le temps de traitement.
|
||||
TimeSpan temps = TimeSpan.FromSeconds(total);
|
||||
string total_formatee = temps.ToString(@"hh\:mm\:ss");
|
||||
Console.WriteLine($"Duree estimée: {total_formatee}");
|
||||
|
||||
|
||||
int percent = 0;
|
||||
foreach ((string address, int port) in cibles)
|
||||
{
|
||||
if (cpt % fraction == 0)
|
||||
{
|
||||
cpt_fraction += 10;
|
||||
Console.WriteLine($"Request {cpt}/{cibles.Count} ({cpt_fraction})%");
|
||||
}
|
||||
percent = (cpt * 100) / cibles.Count;
|
||||
Console.Write($"\rRequest {cpt}/{cibles.Count} ({percent}%)");
|
||||
|
||||
|
||||
if (IsPortOpen(address, port, timeout))
|
||||
{
|
||||
|
|
@ -260,7 +262,6 @@ namespace SharpScan
|
|||
r = new Random();
|
||||
sleep_value = r.Next(delay, delay + (jittler * delay / 100));
|
||||
|
||||
|
||||
Thread.Sleep(sleep_value);
|
||||
cpt += 1;
|
||||
}
|
||||
|
|
@ -269,7 +270,8 @@ namespace SharpScan
|
|||
TimeSpan duree = chronometre.Elapsed;
|
||||
string dureeFormatee = duree.ToString(@"hh\:mm\:ss"); // Format : heures:minutes
|
||||
|
||||
Console.WriteLine($"Durée (heures:minutes) : {dureeFormatee}");
|
||||
|
||||
Console.WriteLine($"\nDurée (heures:minutes) : {dureeFormatee}");
|
||||
|
||||
|
||||
// Affichage des résultats
|
||||
|
|
|
|||
Loading…
Reference in New Issue