
Libreria di scansione di rete veloce ed estensibile con multithreading, ping probing e scan fetchers.
La libreria Forerunner è una libreria di rete veloce, leggera ed estensibile creata per facilitare lo sviluppo di applicazioni robuste incentrate sulla rete, come: Scanner IP, Port Knockers, Client, Server, ecc. Nello stato attuale, la libreria Forerunner è in grado di scansionare e fare port knocking sia in modo sincrono che asincrono su indirizzi IP per ottenere informazioni sul dispositivo situato a quell'endpoint, come: se l'IP è online, l'indirizzo MAC fisico, ecc. La libreria è completamente orientata agli oggetti e basata su eventi, il che significa che i dati di scansione sono contenuti in oggetti "scan" appositamente progettati per gestire tutti i dati, dai risultati alle eccezioni.
| Metodo | Descrizione | Utilizzo |
|---|---|---|
| Scan | Scansiona un singolo IP per ottenere informazioni | Scan("192.168.1.1"); |
| ScanRange | Scansiona un intervallo di IP per ottenere informazioni | ScanRange("192.168.1.1", "192.168.1.255") |
| ScanList | Scansiona una lista di IP per ottenere informazioni | ScanList("192.168.1.1, 192.168.1.2, 192.168.1.3") |
| PortKnock | Ping su ogni porta di un singolo IP | PortKnock("192.168.1.1"); |
| PortKnockRange | Ping su ogni porta in un intervallo di IP | PortKnockRange("192.168.1.1", "192.168.1.255"); |
| PortKnockList | Ping su ogni porta usando una lista di IP | PortKnockList("192.198.1.1, 192.168.1.2, 192.168.1.3"); |
| IsHostAlive | Pinga un host N volte per X millisecondi | IsHostAlive("192.168.1.1", 5, 1000); |
| GetAveragePingResponse | Ottieni la risposta media del ping per un host | GetAveragePingResponse("192.168.1.1", 5, 1000); |
| IsPortOpen | Pinga singole porte via TCP e UDP | IsPortOpen("192.168.1.1", 45000, new TimeSpan(1000), false); |
Scansionare una rete è un compito comune in questa era digitale e quindi ho preso la libertà di renderlo il più semplice possibile per qualsiasi futuro programmatore che possa desiderare di fare una cosa del genere in modo facile. La libreria Forerunner è completamente orientata agli oggetti, rendendola ideale per situazioni plug and play; l'oggetto per la scansione IP si chiama IPScanObject e contiene in realtà diverse proprietà:
Tenendo presente l'oggetto, proviamo a creare un nuovo oggetto ed eseguire una scansione. Ci sono diversi modi per farlo, tuttavia il modo più semplice per iniziare è creare prima un nuovo oggetto Scanner in modo da poter accedere ai nostri metodi di scansione. Successivamente, crea un IPScanObject e impostalo sul metodo Scan con l'IP che desideri enumerare; per esempio:
using System;
using Forerunner; // Remember to import our library.
namespace Example
{
class Program
{
static void Main(string[] args)
{
// Our IP we would like to scan.
string ip = "192.168.1.1";
// Create a new scanner object.
Scanner s = new Scanner();
// Create a new scan object and perform a scan.
IPScanObject result = s.Scan(ip);
// Output that we have finished the scan.
if (result.Errors != null)
Console.WriteLine("[x] An error occurred during the scan.");
else
Console.WriteLine("[+] " + ip + " has been successfully scanned!")
// Allow the user to exit at any time.
Console.Read();
}
}
}
Un altro modo, che è il mio metodo preferito di funzionamento, è creare un oggetto Scanner e iscriversi ai gestori di eventi (Event Handlers) come ScanAsyncProgressChanged o ScanAsyncComplete, in modo da avere il pieno controllo sui miei metodi asincroni; posso controllare come i loro stati di avanzamento influenzano la mia applicazione e così via; per esempio:
using System;
using System.Threading.Tasks;
using Forerunner; // Remember to import our library.
namespace Example
{
class Program
{
static void Main(string[] args)
{
// Our IP we would like to scan.
string ip = "192.168.1.1";
// Setup our scanner object.
Scanner s = new Scanner();
s.ScanAsyncProgressChanged += new ScanAsyncProgressChangedHandler(ScanAsyncProgressChanged);
s.ScanAsyncComplete += new ScanAsyncCompleteHandler(ScanAsyncComplete);
// Start a new scan task with our ip.
TaskFactory task = new TaskFactory();
task.StartNew(() => s.ScanAsync(ip));
// Allow the user to exit at any time.
Console.Read();
}
static void ScanAsyncProgressChanged(object sender, ScanAsyncProgressChangedEventArgs e)
{
// Do something here with e.Progress, or you could leave this event
// unsubscribed so you wouldn't have to do anything.
}
static void ScanAsyncComplete(object sender, ScanAsyncCompleteEventArgs e)
{
// Do something with the IPScanObject aka e.Result.
if (e.Result.Errors != null)
Console.WriteLine("[x] An error occurred during the scan.");
else
Console.WriteLine("[+] " + e.Result.IP + " has been successfully scanned!")
}
}
}
So cosa stai pensando. Port knocking? Sì e no. Il termine non significa port knocking nel senso tradizionale di connettersi attraverso un insieme predefinito di porte, ma piuttosto controllare se alcune porte sono effettivamente aperte. È letteralmente "bussare" a una porta in ogni senso della parola, provando a connettersi a ciascuna porta e inviando dati. Proprio come per la scansione IP, il port knocking utilizza un oggetto personalizzato chiamato "Port Knock Scan Object" o PKScanObject in breve. Il PKScanObject contiene in realtà una lista di PKServiceObject che a loro volta contengono i nostri dati sulle porte; l'oggetto servizio contiene le seguenti proprietà:
Il port knocking è simile alla scansione IP. Per prima cosa, crea un oggetto Scanner. Successivamente, crea un nuovo PKScanObject e impostalo sul metodo PortKnock con l'IP di tua scelta, poi visualizza i risultati; per esempio:
using System;
using Forerunner; // Remember to import our library.
namespace Example
{
class Program
{
static void Main(string[] args)
{
// Our IP we would like to scan.
string ip = "192.168.1.1";
// Create a new scanner object.
Scanner s = new Scanner();
// Create a new scan object and perform a scan.
PKScanObject result = s.PortKnock(ip);
// Output that we have finished the scan.
if (result.Errors != null)
Console.WriteLine("[x] An error occurred during the scan.");
else
Console.WriteLine("[+] " + ip + " has been successfully scanned!")
// Display our results.
foreach (PKServiceObject port in result.Services)
{
Console.WriteLine("[+] IP: " + port.IP + " | " +
"Port: " + port.Port.ToString() + " | " +
"Protocol: " + port.Protocol.ToString() + " | " +
"Status: " + port.Status.ToString());
}
// Allow the user to exit at any time.
Console.Read();
}
}
}
Infine, ti mostrerò un semplice esempio di port knocking asincrono. È essenzialmente lo stesso del port knocking sincrono, tranne per il fatto che puoi sfruttare gli eventi a tuo vantaggio. Puoi ottenere aggiornamenti sull'avanzamento senza doverti preoccupare del crash dell'interfaccia utente o di sistemi in stato di blocco; per esempio:
using System;
using System.Threading.Tasks;
using Forerunner; // Remember to import our library.
namespace Example
{
class Program
{
static void Main(string[] args)
{
// Our IP we would like to scan.
string ip = "192.168.1.1";
// Setup our scanner object.
Scanner s = new Scanner();
s.PortKnockAsyncProgressChanged += new PortKnockAsyncProgressChangedHandler(PortKnockAsyncProgressChanged);
s.PortKnockAsyncComplete += new PortKnockAsyncCompleteHandler(PortKnockAsyncComplete);
// Start a new scan task with our ip.
TaskFactory task = new TaskFactory();
task.StartNew(() => s.PortKnockAsync(ip));
// Allow the user to exit at any time.
Console.Read();
}
static void PortKnockAsyncProgressChanged(object sender, PortKnockAsyncProgressChangedEventArgs e)
{
// Display our progress so we know the ETA.
if (e.Progress == 99)
{
Console.Write(e.Progress.ToString() + "%...");
Console.WriteLine("100%!");
}
else
Console.Write(e.Progress.ToString() + "%...");
}
static void PortKnockAsyncComplete(object sender, PortKnockAsyncCompleteEventArgs e)
{
// Tell the user that the port knock was complete.
Console.WriteLine("[+] Port Knock Complete!");
// Check if we resolved an error.
if (e.Result == null)
Console.WriteLine("[X] The port knock did not return any data!");
else
{
// Check if we have any ports recorded.
if (e.Result.Services.Count == 0)
Console.WriteLine("[!] No ports were open during the knock.");
else
{
// Display our ports and their details.
foreach (PKServiceObject port in e.Result.Services)
{
Console.WriteLine("[+] IP: " + port.IP + " | " +
"Port: " + port.Port.ToString() + " | " +
"Protocol: " + port.Protocol.ToString() + " | " +
"Status: " + port.Status.ToString());
}
}
}
}
}
}
Icona: monkik
https://www.flaticon.com/authors/monkik
Copyright © ∞ Jason Drawdy
Tutti i diritti riservati.
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Fatti salvi i contenuti di questo avviso, il nome del titolare del copyright di cui sopra non potrà essere utilizzato a fini pubblicitari o per promuovere la vendita, l'uso o altre transazioni relative a questo Software senza previa autorizzazione scritta.