
Bibliothèque de scan réseau rapide et extensible, avec multithreading, sondage ping et récupérateurs de scan.
La bibliothèque Forerunner est une bibliothèque réseau rapide, légère et extensible créée pour faciliter le développement d'applications robustes centrées sur le réseau telles que : scanners IP, port knockers, clients, serveurs, etc. Dans son état actuel, la bibliothèque Forerunner est capable de scanner et de effectuer du port knocking de manière synchrone et asynchrone sur des adresses IP afin d'obtenir des informations sur le périphérique situé à ce point de terminaison, comme : si l'IP est en ligne, l'adresse MAC physique, etc. La bibliothèque est entièrement orientée objet et basée sur les événements, ce qui signifie que les données de scan sont contenues dans des objets "scan" spécialement conçus pour gérer toutes les données, des résultats aux exceptions.
| Méthode | Description | Utilisation |
|---|---|---|
| Scan | Scanner une seule IP pour obtenir des informations | Scan("192.168.1.1"); |
| ScanRange | Scanner une plage d'IP pour obtenir des informations | ScanRange("192.168.1.1", "192.168.1.255") |
| ScanList | Scanner une liste d'IP pour obtenir des informations | ScanList("192.168.1.1, 192.168.1.2, 192.168.1.3") |
| PortKnock | Pinger chaque port d'une seule IP | PortKnock("192.168.1.1"); |
| PortKnockRange | Pinger chaque port d'une plage d'IP | PortKnockRange("192.168.1.1", "192.168.1.255"); |
| PortKnockList | Pinger chaque port en utilisant une liste d'IP | PortKnockList("192.198.1.1, 192.168.1.2, 192.168.1.3"); |
| IsHostAlive | Pinger un hôte N fois pendant X millisecondes | IsHostAlive("192.168.1.1", 5, 1000); |
| GetAveragePingResponse | Obtenir la réponse ping moyenne pour un hôte | GetAveragePingResponse("192.168.1.1", 5, 1000); |
| IsPortOpen | Pinger des ports individuels via TCP et UDP | IsPortOpen("192.168.1.1", 45000, new TimeSpan(1000), false); |
Scanner un réseau est une tâche courante à l'ère numérique et j'ai donc pris la liberté de rendre cela aussi simple que possible pour tout futur programmeur qui souhaiterait faire une telle chose de manière facile. La bibliothèque Forerunner est entièrement orientée objet, ce qui la rend idéale pour les situations de type plug and play ; l'objet pour le scan IP s'appelle IPScanObject et il contient en fait plusieurs propriétés :
Avec cet objet en tête, essayons de créer un nouvel objet et d'effectuer un scan en l'utilisant. Il existe plusieurs façons de procéder, mais la manière la plus simple pour commencer est d'abord de créer un nouvel objet Scanner afin d'accéder à nos méthodes de scan. Ensuite, créez un IPScanObject puis affectez-le à la méthode Scan avec l'IP que vous souhaitez énumérer ; par exemple :
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();
}
}
}
Une autre manière, qui est ma méthode de prédilection, est de créer un objet Scanner et de s'abonner aux gestionnaires d'événements comme ScanAsyncProgressChanged ou ScanAsyncComplete, afin d'avoir un contrôle total sur mes méthodes asynchrones ; je peux contrôler comment leurs états de progression affectent mon application, etc. ; par exemple :
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!")
}
}
}
Je sais ce que vous pensez. Port knocking ? Oui, et non. Le terme ne signifie pas port knocking dans le sens traditionnel de se connecter via un ensemble prédéfini de ports, mais plutôt de simplement vérifier si des ports sont réellement ouverts. C'est littéralement "frapper" à un port dans tous les sens du terme en essayant de se connecter à chaque port et en envoyant des données. Tout comme pour le scan IP, le port knocking utilise un objet personnalisé appelé "Port Knock Scan Object" ou PKScanObject en abrégé. Le PKScanObject contient en fait une liste de PKServiceObject qui contiennent à leur tour nos données de port ; l'objet de service possède les propriétés suivantes :
Le port knocking se déroule de manière similaire au scan IP. D'abord, créez un objet Scanner. Ensuite, créez un nouveau PKScanObject et affectez-le à la méthode PortKnock avec l'IP de votre choix, puis affichez vos résultats ; par exemple :
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();
}
}
}
Enfin, je vais vous montrer un exemple simple de port knocking asynchrone. C'est essentiellement la même chose que le port knocking synchrone, à l'exception du fait que vous pouvez utiliser les événements à votre avantage. Vous pouvez obtenir des mises à jour de progression sans avoir à vous soucier du crash des interfaces utilisateur ou du verrouillage des systèmes ; par exemple :
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());
}
}
}
}
}
}
Icône : monkik
https://www.flaticon.com/authors/monkik
Copyright © ∞ Jason Drawdy
Tous droits réservés.
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.
Sauf indication contraire dans le présent avis, le nom du titulaire du droit d'auteur ci-dessus ne pourra être utilisé à des fins publicitaires ou pour promouvoir la vente, l'utilisation ou autre exploitation de ce logiciel sans autorisation écrite préalable.