freeBuf
主站

分类

漏洞 工具 极客 Web安全 系统安全 网络安全 无线安全 设备/客户端安全 数据安全 安全管理 企业安全 工控安全

特色

头条 人物志 活动 视频 观点 招聘 报告 资讯 区块链安全 标准与合规 容器安全 公开课

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

Forerunner:一款支持多线程、Ping探测和数据提取的快速可扩展网络扫描库
2020-07-02 15:00:42

图片1.png

Forerunner

Forerunner是一个快速的、轻量级的并且可扩展的网络库,它可以帮助研究人员开发一个以网络为中心的健壮的应用程序,比如说IP扫描器、端口扫描器、客户端以及服务器等等。当前版本的Forerunner,能够支持针对端口和IP地址进行同步或异步扫描,并收集关于目标设备的地理位置信息和终端信息,比如说IP地址是否在线以及设备的物理MAC地址等等。这个库是一个完全面向对象和基于事件的库,这意味着扫描数据都将包含在精心编制的“scan”对象之中,而这些对象旨在处理涵盖从结果到异常的所有数据。

工具依赖

1、.NET Framework v4.6.1

功能介绍

方法名描述使用样例
Scan扫描IP地址并收集信息Scan("192.168.1.1");
ScanRange扫描IP地址范围并收集信息ScanRange("192.168.1.1", "192.168.1.255")
ScanList扫描IP地址列表并收集信息ScanList("192.168.1.1, 192.168.1.2, 192.168.1.3")
PortKnock扫描单个IP地址的所有端口PortKnock("192.168.1.1");
PortKnockRange扫描IP地址范围内的所有端口PortKnockRange("192.168.1.1", "192.168.1.255");
PortKnockList扫描IP地址列表中的所有端口PortKnockList("192.198.1.1, 192.168.1.2, 192.168.1.3");
IsHostAlive多少毫秒扫描主机N次IsHostAlive("192.168.1.1", 5, 1000);
GetAveragePingResponse获取目标主机平均ping响应GetAveragePingResponse("192.168.1.1", 5, 1000);
IsPortOpen通过TCP&UDP来ping单个端口IsPortOpen("192.168.1.1", 45000, new TimeSpan(1000), false);

工具下载

广大研究人员可以使用下列命令将项目源码克隆至本地:

git clone https://github.com/jasondrawdy/Forerunner.git

工具使用样例

IP扫描

在网络安全研究过程中,扫描一个网络是一种非常常见的任务了,因此我们应该通过尽可能简单的方法来实现这个目标,以方便未来的安全研究人员去做同样的事情。Forerunner是一个完全面向对象的功能库,因此非常适合所谓“即插即用”的情况。其中,用于IP扫描的对象被称之为IPScanObject,这个对象包含了下列几种参数属性:

Address (String)

IP (IPAddress)

Ping (Long)

Hostname (String)

MAC (String)

isOnline (Bool)

Errors (Exception)

有了对象的概念之后,我们可以尝试创建一个新的对象,并使用它来执行一次扫描任务。最简单的方法就是先创建一个新的Scanner对象,并通过它来访问我们的扫描方法。接下来,创建一个IPScanObject对象,并使用目标IP地址来设置其Scan方法。

同步扫描:

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();

        }

    }

}

另一种方法是创建Scanner对象并订阅ScanAsyncProgressChangedScanAsyncComplete之类的事件处理程序,这样我可以完全控制异步方法,我可以控制它们影响应用程序的进度状态等等。

异步扫描:

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!")

        }

    }

}

端口扫描

跟IP地址扫描一样,端口扫描可以通过一组预定义的端口来尝试进行端口连接,并检查目标端口是否真正开启。它将尝试通过与每个端口进行连接并发送数据包来进行端口探测。这个功能同样是通过一个自定义对象来实现的,即"Port Knock Scan Object",简称为“PKScanObject”。 PKScanObject对象实际上包含一个PKServiceObjects列表,该列表将保存返回的全部端口数据,该服务对象包含下列参数属性:

IP (String)

Port (Int)

Protocol (PortType)

Status (Bool)

首先,我们需要创建一个Scanner对象,然后创建一个新的PKScanObject对象并使用目标IP来设置PortKnock方法,然后工具将显示扫描结果给我们。

同步扫描:

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();

        }

    }

}

异步扫描:

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());

                    }

                }

            }

        }

    }

}

许可证协议

Forerunner项目的开发和发布遵循MIT开源许可证协议。

项目地址

Forerunner:【GitHub传送门

参考来源

jasondrawdy

# 网络安全 # 网络扫描库
本文为 独立观点,未经允许不得转载,授权请联系FreeBuf客服小蜜蜂,微信:freebee2022
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
  • 0 文章数
  • 0 关注者