渗透测试实践-扫描

本文是我阅读《渗透测试实践指南·第三章·扫描》所做的笔记。

零、开始

扫描的四个阶段:

  • 用Ping数据包验证系统是否正在运行
  • 用Nmap扫描系统的端口
  • 用Nmap脚本引擎(NSE)进一步查询目标
  • 用Nessus扫描系统漏洞

扫描的主要任务:

  • 建立IP地址与开放端口和服务的映射关系
  • 建立开放端口与服务和漏洞的映射关系

一、Ping

Ping单个主机用ping,多个主机用fping

    fping -a -g 172.16.45.1 172.16.45.254 > host.txt
  • -a 只显示活动主机
  • -g 其中是要ping的IP地址范围
  • > 将输出重定向到文件

二、端口扫描

使用Nmap进行端口扫描。

0.题外话:使用命令行的好处

  • 往往可以进行更精细的控制
  • 便于脚本化自动化(最本质优势!)
  • 入侵计算机后得到的往往是shell而不是远程桌面

1.TCP连接扫描

  • 参数:“-sT”
  • 会完成完整的三次握手建立连接并且友好地断开连接
  • 默认只扫描一千个常用端口(可用参数“-p-”指定扫描所有端口)
  • 使用参数“-Pn”禁用主机发现功能,对不响应ICMP的主机也进行扫描
  • 使用参数“-iL”从一行一个IP的文本文件中载入扫描目标
    nmap -sT -p- -Pn 192.168.1.132
    nmap -sT -p- -Pn 192.168.1.1-254
    nmap -sT -p- -Pn -iL path_to_the_text_file
    

2.SYN扫描

  • 参数:“-sS”(是Nmap的默认扫描方式)
  • 不完成三次握手,速度快(SYN、SYN/ACK、RST)
  • 对某些老系统隐身(现在往往不隐身了)
    nmap -sS -p- -Pn 192.168.1.132
    

3.UDP扫描

  • 参数:“-sU”
  • 速度很慢
  • 有时无法判断服务没有开启还是数据包被过滤了,此时显示“open|filtered”
  • 添加版本扫描“-sV”可以使扫描结果更准确些(参数合并后为“-sUV”)
    nmap -sUV 192.168.1.132
    

4.Xmas扫描

  • 参数:“-sX”
  • 是对TCP端口的扫描
  • 只对Unix/Linux有效,对Windows无效
  • 准确地说是只对严格遵循TCP RFC文档的系统有效
  • Xmas是圣诞节英文Christmas的缩写
  • 该扫描会打开很多标志(FIN、PSH和URG),“就像一颗点亮了的圣诞树”
  • 可透过简单的防火墙(只丢弃SYN数据包的防火墙)
    nmap -sX -p- -Pn 192.168.1.132
    

5.Null扫描

  • 参数:“-sN”
  • 是对TCP端口的扫描
  • 只对Unix/Linux有效,对Windows无效
  • 准确地说是只对严格遵循TCP RFC文档的系统有效
  • 使用没有任何标记的数据包
  • 可透过简单的防火墙(只丢弃SYN数据包的防火墙)
    nmap -sN -p- -Pn 192.168.1.132
    

三、NSE扫描

  • 参数:“–script”,后可跟具体脚本名或脚本类别名
  • NSE是Nmap脚本引擎的缩写
    nmap --script banner 192.168.18.132
    nmap --script vuln 192.168.18.132
    

四、Nmap参数总结与补充

  • -sT TCP连接扫描
  • -sS SYN扫描
  • -sX Xmas扫描
  • -sN Null扫描
  • -sU UDP扫描
  • -p- 扫描所有端口
  • -Pn 禁用主机发现
  • -iL 载入一行一个IP的文本文件中的IP作为扫描目标
  • -T 扫描速度控制,0~5,0最慢,5最快,速度越快越不准确
  • -O 识别操作系统
  • 对于远程访问服务花些时间尝试登录,万一成功了呢

五、漏洞扫描

  • 漏洞:在于软件或系统配置中可以被利用的弱点
  • 常用漏洞扫描器:Nessus、OpenVAS

安装Nessus

    root@kali:~/Desktop# dpkg -i Nessus-6.11.1-debian6_amd64.deb 
    Selecting previously unselected package nessus.
    (Reading database ... 349961 files and directories currently installed.)
    Preparing to unpack Nessus-6.11.1-debian6_amd64.deb ...
    Unpacking nessus (6.11.1) ...
    Setting up nessus (6.11.1) ...
    Unpacking Nessus Core Components...
    nessusd (Nessus) 6.11.1 [build M20101] for Linux
    Copyright (C) 1998 - 2017 Tenable Network Security, Inc

    Processing the Nessus plugins...
    [##################################################]

    All plugins loaded (1sec)

     - You can start Nessus by typing /etc/init.d/nessusd start
     - Then go to https://kali:8834/ to configure your scanner

    Processing triggers for systemd (233-9) ...
  • 新建管理员用户:/opt/nessus/sbin/nessuscli adduser
    root@kali:~/Desktop# /opt/nessus/sbin/nessuscli adduser 
    Login: admin
    Login password: 
    Login password (again): 
    Do you want this user to be a Nessus 'system administrator' user (can upload plugins, etc.)? (y/n) [n]: y
    User rules
    ----------
    nessusd has a rules system which allows you to restrict the hosts
    that admin has the right to test. For instance, you may want
    him to be able to scan his own host only.

    Please see the Nessus Command Line Reference for the rules syntax

    Enter the rules for this user, and enter a BLANK LINE once you are done : 
    (the user can have an empty rules set)



    Login    : admin
    Password : ***********
    This user will have 'system administrator' privileges within the Nessus server
    Is that ok? (y/n) [n]: y
    User added
  • 激活:/opt/nessus/sbin/nessuscli fetch –register 14XX-XXXX-XXXX-XXXX-XX35
    root@kali:~/Desktop# /opt/nessus/sbin/nessuscli fetch --register 14XX-XXXX-XXXX-XXXX-XX35
    Your Activation Code has been registered properly - thank you.

    ----- Fetching the newest updates from nessus.org -----

    Nessus Plugins: Downloading (0%)    
    ...
    Nessus Plugins: Downloading (98%)   
    Nessus Plugins: Unpacking (0%)  
    ...
    Nessus Plugins: Unpacking (81%) 
    Nessus Plugins: Complete    

    Nessus Core Components: Downloading (0%)    
    Nessus Core Components: Complete    

     * Nessus Plugins are now up-to-date and the changes will be automatically processed by Nessus.
     * Nessus Core Components are now up-to-date and the changes will be automatically processed by Nessus.
  • 启动服务:/etc/init.d/nessusd start
  • 在浏览器中输入:https://127.0.0.1:8834 打开Nessus
  • 可参考:《Kali安装Nessus详细过程》,这是个老版的Nessus安装教程

六、结束

  • 进一步学习Nmap和Nessus的高级用法
  • 研究每个Nmap脚本
  • 学习编写Nmap脚本

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

1 × 2 =