zoukankan      html  css  js  c++  java
  • Masscan操作配置

    Masscan号称是最快的互联网端口扫描器,最快可以在六分钟内扫遍互联网。

    masscan的扫描结果类似于nmap(一个很著名的端口扫描器),在内部,它更像scanrand, unicornscan, and ZMap,采用了异步传输的方式。它和这些扫描器最主要的区别是,它比这些扫描器更快。而且,masscan更加灵活,它允许自定义任意的地址范和端口范围。

    安装配置

    在Debian/Ubuntu系统中,安装方法如下:

    sudo apt-get install git gcc make libpcap-dev
    git clone https://github.com/robertdavidgraham/masscan
    cd masscan
    make

    注:安装完成后的可执行程序在masscan/bin中

    您也可以使用多线程加快编译速度 make -j

    PF_RING

    如果您想获得超过两百万每秒的速度,您需要一个英特尔10-Gbps网卡和一个被称为PF_RING DNA(http://www.ntop.org/products/pf_ring/)的特殊驱动程序。masscan使用PF_RING不要进行重建,你只需要建立以下组件即可:

    libpfring.so (安装于 /usr/lib/libpfring.so)
    pf_ring.ko (pf_ring自己的内核驱动)
    ixgbe.ko (英特尔10-gbps网卡驱动)
    你不要建立自己的libpcap.so

    当masscan检测到网卡为dna0时,将自动切换为PF_RING模式

    自我测试

    当安装完成是可以测试一下是否安装成功:

    make regress
    bin/masscan --regress
    selftest: success!

    使用方法

    使用方法类似于nmap,扫描指定网段范围的指定端口

    # masscan -p80,8080-8100 10.0.0.0/8

    这条命令将完成如下工作:

    1、扫描10.x.x.x子网,大约有1600万个地址

    2、扫描端口80和8000-8100范围的端口段

    3、打印结果到标准输出,也可以重定向到一个文件

    也可以 –echo 将当前的配置输出到一个配置文件,利用 -c 来制定配置文件进行扫描

    # masscan -p80,8000-8100 10.0.0.0/8 --echo > xxx.conf
    # masscan -c xxx.conf --rate 1000

    Banner获取

    masscan不仅仅只是测试端口是否开放,它还能在完成TCP连接的同时获取目标应用程序的Banner信息(--banners选项值旗标,或者指纹)。

    # masscan 10.0.0.0/8 -p80 --banners --source-ip x.x.x.x

    这条命令的意思是扫描10.x.x.x网段80端口的开放信息,并且获取banner信息。–source-ip 是指定源IP,这个ip必须指定独立有效的IP地址。

    您可以通过配置防火墙来防止masscan的返回不了信息的情况

    Linux可以在这样配置

    # iptables -A INPUT -p tcp --dport 60000 -j DROP
    # masscan 10.0.0.0/8 -p80 --banners --source-port 60000

    MAC OS X和BSD可以这样配置

    # sudo ipfw add 1 deny tcp from any to any 60000 in
    # masscan 10.0.0.0/8 -p80 --banners --source-port 60000

    您也可以检查其他类型的信息,例如Linux-HA工程的一个组件 –-heartbleed,方法和获取banner是一样的

    扫描全网

    您可以对整个互联网发起扫描,使用的命令如下

    # masscan 0.0.0.0/0 -p0-65535

    有时候对这个互联网扫描可能会对你造成一些麻烦,你可能会被请去喝茶。所以,我们可以通过设置黑名单来让扫描器扫描时忽略一些网段。语法如下:

    # masscan 0.0.0.0/0 -p0-65535 --excludefile exclude.txt

    你也可以把扫描的结果不输出到命令行,输出到指定文件中

    # masscan 0.0.0.0/0 -p0-65535 -oX scan.xml

    这条命令把扫描的结果保存在一个XML文件中

    当前的扫描器使用的是默认的速率100包/秒,如果是扫描全网的话,需要提高速度。

    # masscan 0.0.0.0/0 -p0-65535 --max-rate 100000

    这条命令将以每秒10万包的速率进行扫描

    上述的这些命令可能输入起来有点麻烦,我们可以通过创建配置文件,然后用加载配置文件的方式运行。配置文件的内容如下所示:

    rate = 100000
    output-format = xxx
    output-status = all
    output-filename = xxx.xxx
    ports = 0-65535
    range = 0.0.0.0-255.255.255.255
    excludefile = exclude.txt

    扫描时,用 -c 加载配置文件,这样的话,你进行重复扫描会省很多的力气。

    结果输出

    主要有5种输出的格式

    1、XML 默认格式 使用-oX <filename> 或者使用 –output-format xml 和 –output-filename <filename>进行指定
    2、binary masscan内置格式
    masscan --open --banners --readscan output.txt -oX 2.txt 打开显示模式,读取output.txt中的数据,并以xml的格式写到2.txt中
    3、grepable nmap格式 使用
    -oG <filename> 或者 –output-format grepable 和 –output-filename <filename>进行指定 4、json 使用 -oJ <filename> 或者 –output-format json 和 –output-filename <filename>进行指定 5、list 简单的列表,每行一个主机端口对。使用-oL <filename> 或者 –output-format list 和 –output-filename <filename>进行指定

    By default, masscan produces fairly large text files, but it's easy to convert them into any other format. There are five supported output formats:

    1. xml: Just use the parameter -oX <filename>. Or, use the parameters --output-format xml and --output-filename <filename>.

    2. binary: This is the masscan builtin format. It produces much smaller files, so that when I scan the Internet my disk doesn't fill up. They need to be parsed, though. The command line option --readscanwill read binary scan files. Using --readscan with the -oX option will produce a XML version of the results file.

    3. grepable: This is an implementation of the Nmap -oG output that can be easily parsed by command-line tools. Just use the parameter -oG <filename>. Or, use the parameters --output-format grepable and --output-filename <filename>.

    4. json: This saves the results in JSON format. Just use the parameter -oJ <filename>. Or, use the parameters --output-format json and --output-filename <filename>.

    5. list: This is a simple list with one host and port pair per line. Just use the parameter -oL <filename>. Or, use the parameters --output-format list and --output-filename <filename>. The format is: 

    masscan --includefile fujian.txt -p0-1234 -oL scan.list  --max-rate 100000   #  --includefile fujian.txt读取一个范围列表进行扫描

    masscan -iL fujian.txt-p0-1234 -oL scan.list  --max-rate 100000   #  -iL fujian.txt读取一个范围列表进行扫描

    masscan ip/range  -p0-1234 --append-output  -oL scan.list  --max-rate 100000   #  将扫描结果追加进scan.list文件

    <port state> <protocol> <port number> <IP address> <POSIX timestamp>  
    open tcp 80 XXX.XXX.XXX.XXX 1390380064

    传输速度

    masscan的发包速度非常快,在windows中,它的发包速度可以达到每秒30万包;在Linux中,速度可以达到每秒160万。masscan在扫描时会随机选择目标IP,所以不会对远程的主机造成压力。

    默认情况下,masscan的发包速度为每秒100包,为了提高速度,可以设置为 –rate 100000

    我们注意到zmap和masscan都有一个控制发包速率的参数,为什么需要这个参数呢?不是越高越好吗?不是的,这个参数的设置直接影响漏报。
    一般家用adsl的上行速度在100kb/s-300kb/s 之间,以互联网最小包60byte计算,100kb/s =1746 pps,也就是说每秒发送数据包约2000个,超出就容易丢包漏报。通过这个公式不难得出在一个家庭adsl环境下且保证准确度,用zmap扫描全部互联网需要255*255*255*255/2000/3600/24=24天。

    详细参数

    <ip/range> IP地址范围,有三种有效格式,1、单独的IPv4地址 2、类似"10.0.0.1-10.0.0.233"的范围地址 3、CIDR地址 类似于"0.0.0.0/0",多个目标可以用都好隔开
    
    -p <ports,--ports <ports>> 指定端口进行扫描
    
    --banners 获取banner信息,支持少量的协议
    
    --rate <packets-per-second> 指定发包的速率
    
    -c <filename>, --conf <filename> 读取配置文件进行扫描
    
    --echo 将当前的配置重定向到一个配置文件中
    
    -e <ifname> , --adapter <ifname> 指定用来发包的网卡接口名称
    
    --adapter-ip <ip-address> 指定发包的IP地址
    
    --adapter-port <port> 指定发包的源端口
    
    --adapter-mac <mac-address> 指定发包的源MAC地址
    
    --router-mac <mac address> 指定网关的MAC地址
    
    --exclude <ip/range> IP地址范围黑名单,防止masscan扫描
    
    --excludefile <filename> 指定IP地址范围黑名单文件
    
    --includefile,-iL <filename> 读取一个范围列表进行扫描
    
    --ping 扫描应该包含ICMP回应请求
    
    --append-output 以附加的形式输出到文件
    
    --iflist 列出可用的网络接口,然后退出
    
    --retries 发送重试的次数,以1秒为间隔
    
    --nmap 打印与nmap兼容的相关信息
    
    --http-user-agent <user-agent> 设置user-agent字段的值
    
    --show [open,close] 告诉要显示的端口状态,默认是显示开放端口
    
    --noshow [open,close] 禁用端口状态显示
    
    --pcap <filename> 将接收到的数据包以libpcap格式存储
    
    --regress 运行回归测试,测试扫描器是否正常运行
    
    --ttl <num> 指定传出数据包的TTL值,默认为255
    
    --wait <seconds> 指定发送完包之后的等待时间,默认为10秒
    
    --offline 没有实际的发包,主要用来测试开销
    
    -sL 不执行扫描,主要是生成一个随机地址列表
    
    --readscan <binary-files> 读取从-oB生成的二进制文件,可以转化为XML或者JSON格式.
    
    --connection-timeout <secs> 抓取banners时指定保持TCP连接的最大秒数,默认是30秒。

     参考资料:

    http://www.freebuf.com/sectool/112583.html

    https://www.ctolib.com/masscan.html

  • 相关阅读:
    ActiveMQ 即时通讯服务 浅析
    Asp.net Mvc (Filter及其执行顺序)
    ActiveMQ基本介绍
    ActiveMQ持久化消息的三种方式
    Windows Azure Virtual Machine (27) 使用psping工具,测试Azure VM网络连通性
    Azure China (10) 使用Azure China SAS Token
    Windows Azure Affinity Groups (3) 修改虚拟网络地缘组(Affinity Group)的配置
    Windows Azure Storage (22) Azure Storage如何支持多级目录
    Windows Azure Virtual Machine (26) 使用高级存储(SSD)和DS系列VM
    Azure Redis Cache (2) 创建和使用Azure Redis Cache
  • 原文地址:https://www.cnblogs.com/domestique/p/8215020.html
Copyright © 2011-2022 走看看