3

WireShark黑客发现之旅(5)—扫描探测 | WooYun知识库

 6 years ago
source link:
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

WireShark黑客发现之旅(5)—扫描探测

作者:Mr.Right、K0r4dji 申明:文中提到的攻击方式仅为曝光、打击恶意网络攻击行为,切勿模仿,否则后果自负。

0x00 简单介绍


“知己知彼,百战不殆。”扫描探测,目的就是“知彼”,为了提高攻击命中率和效率,基本上常见的攻击行为都会用到扫描探测。

扫描探测的种类和工具太多了,攻击者可以选择现有工具或自行开发工具进行扫描,也可以根据攻击需求采用不同的扫描方式。本文仅对Nmap常见的几种扫描探测方式进行分析。如:地址扫描探测、端口扫描探测、操作系统扫描探测、漏洞扫描探测(不包括Web漏洞,后面会有单独文章介绍Web漏洞扫描分析)。

0x01 地址扫描探测


地址扫描探测是指利用ARPICMP请求目标网段,如果目标网段没有过滤规则,则可以通过回应消息获取目标网段中存活机器的IP地址和MAC地址,进而掌握拓扑结构。

如:192.1.14.235向指定网段发起ARP请求,如果IP不存在,则无回应。

enter image description here

如果IP存在,该IP会通过ARP回应攻击IP,发送自己的MAC地址与对应的IP

enter image description here

ARP欺骗适用范围多限于内网,通过互联网进行地址扫描一般基于Ping请求。

如:192.1.14.235向指定网段发起Ping请求,如果IP存在,则返回Ping reply

enter image description here

enter image description here

0x02 端口扫描探测


端口扫描是扫描行为中用得最多的,它能快速获取目的机器开启端口和服务的情况。常见的端口扫描类型有全连接扫描、半连接扫描、秘密扫描和UDP扫描。

1、全连接扫描

全连接扫描调用操作系统提供的connect()函数,通过完整的三次TCP连接来尝试目标端口是否开启。全连接扫描是一次完整的TCP连接。

1)如果目标端口开启 攻击方:首先发起SYN包;

目标:返回SYN ACK

攻击方:发起ACK

攻击方:发起RST ACK结束会话。

2)如果端口未开启 攻击方:发起SYN包;

目标:返回RST ACK结束会话。

如:192.1.14.235172.16.33.162进行全连接端口扫描,首先发起Ping消息确认主机是否存在,然后对端口进行扫描。

enter image description here

下图为扫描到TCP3389端口开启的情况。

enter image description here

下图为扫描到TCP1723端口未开启的情况。

enter image description here

2、半连接扫描

半连接扫描不使用完整的TCP连接。攻击方发起SYN请求包;如果端口开启,目标主机回应SYN ACK包,攻击方再发送RST包。如果端口未开启,目标主机直接返回RST包结束会话。

如:192.1.14.235172.16.33.162进行半连接端口扫描,首先发起Ping消息确认主机是否存在,然后对端口进行扫描。

enter image description here

扫描到TCP80端口开启。

enter image description here

TCP23端口未开启。

enter image description here

3、秘密扫描TCPFIN

TCP FIN扫描是指攻击者发送虚假信息,目标主机没有任何响应时认为端口是开放的,返回数据包认为是关闭的。

如下图,扫描方发送FIN包,如果端口关闭则返回RST ACK包。

enter image description here

4、秘密扫描TCPACK

TCP ACK扫描是利用标志位ACK,而ACK标志在TCP协议中表示确认序号有效,它表示确认一个正常的TCP连接。但是在TCP ACK扫描中没有进行正常的TCP连接过程,实际上是没有真正的TCP连接。所以使用TCP ACK扫描不能够确定端口的关闭或者开启,因为当发送给对方一个含有ACK表示的TCP报文的时候,都返回含有RST标志的报文,无论端口是开启或者关闭。但是可以利用它来扫描防火墙的配置和规则等。

enter image description here

5、UDP端口扫描

前面的扫描方法都是针对TCP端口,针对UDP端口一般采用UDP ICMP端口不可达扫描。

如:192.1.14.235172.16.2.4发送大量UDP端口请求,扫描其开启UDP端口的情况。

enter image description here

如果对应的UDP端口开启,则会返回UDP数据包。

enter image description here

如果端口未开启,则返回“ICMP端口不可达”消息。

enter image description here

0x03 操作系统的探测


NMAP进行操作系统的探测主要用到的是OS探测模块,使用TCP/IP协议栈指纹来识别不同的操作系统和设备。Nmap内部包含了2600多种已知操作系统的指纹特征,根据扫描返回的数据包生成一份系统指纹,将探测生成的指纹与nmap-os-db中指纹进行对比,查找匹配的操作系统。如果无法匹配,则以概率形式列举出可能的系统。

如:192.168.1.50192.168.1.90进行操作系统的扫描探测。首先发起Ping请求,确认主机是否存在。

enter image description here

发起ARP请求,获取主机MAC地址。

enter image description here

进行端口扫描。

enter image description here

根据综合扫描情况,判断操作系统类型。

enter image description here

0x04 漏洞扫描


操作系统的漏洞探测种类很多,本文针对“smb-check-vulns”参数就MS08-067CVE2009-3103MS06-025MS07-029四个漏洞扫描行为进行分析。

攻击主机:192.168.1.200(Win7),目标主机:192.168.1.40(WinServer 03);

Nmap扫描命令:nmap --script=smb-check-vulns.nse --script-args=unsafe=1 192.168.1.40

enter image description here

1、端口扫描

漏洞扫描前,开始对目标主机进行端口扫描。

enter image description here

2、SMB协议简单分析

由于这几个漏洞多针对SMB服务,下面我们简单了解一下NAMP扫描行为中的SMB命令。

SMB Command:Negotiate Protocol(0x72):SMB协议磋商

SMB Command: Session Setup AndX(0x73):建立会话,用户登录

SMB Command: Tree Connect AndX (0x75):遍历共享文件夹的目录及文件

SMB Command: NT Create AndX (0xa2):打开文件,获取文件名,获得读取文件的总长度

SMB Command: Write AndX (0x2f):写入文件,获得写入的文件内容

SMB Command:Read AndX(0x2e):读取文件,获得读取文件内容

SMB Command: Tree Disconnect(0x71):客户端断开

SMB Command: Logoff AndX(0x74):退出登录

enter image description here

3、MS08-067漏洞

(1)MS08-067漏洞扫描部分源码如下:

function check_ms08_067(host)
    if(nmap.registry.args.safe ~= nil) then
        return true, NOTRUN
    end
    if(nmap.registry.args.unsafe == nil) then
        return true, NOTRUN
    end
    local status, smbstate
    local bind_result, netpathcompare_result

    -- Create the SMB session  \\创建SMB会话
    status, smbstate = msrpc.start_smb(host, "\\\\BROWSER")
    if(status == false) then
        return false, smbstate
    end

    -- Bind to SRVSVC service
    status, bind_result = msrpc.bind(smbstate, msrpc.SRVSVC_UUID, msrpc.SRVSVC_VERSION, nil)
    if(status == false) then
        msrpc.stop_smb(smbstate)
        return false, bind_result
    end

    -- Call netpathcanonicalize
--  status, netpathcanonicalize_result = msrpc.srvsvc_netpathcanonicalize(smbstate, host.ip, "\\a", "\\test\\")

    local path1 = "\\AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\..\\n"
    local path2 = "\\n"
    status, netpathcompare_result = msrpc.srvsvc_netpathcompare(smbstate, host.ip, path1, path2, 1, 0)

    -- Stop the SMB session
    msrpc.stop_smb(smbstate)

(2)分析

尝试打开“\\BROWSER”目录,下一包返回成功。

enter image description here

同时还有其它尝试,均成功,综合判断目标存在MS08-067漏洞。通过Metasploit进行漏洞验证,成功溢出,获取Shell。

enter image description here

4、CVE-2009-3103漏洞

(1)CVE-2009-3103漏洞扫描部分源码如下:

host = "IP_ADDR", 445
buff = (
"\x00\x00\x00\x90" # Begin SMB header: Session message
"\xff\x53\x4d\x42" # Server Component: SMB
"\x72\x00\x00\x00" # Negociate Protocol
"\x00\x18\x53\xc8" # Operation 0x18 & sub 0xc853
"\x00\x26"# Process ID High: --> :) normal value should be "\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xfe"
"\x00\x00\x00\x00\x00\x6d\x00\x02\x50\x43\x20\x4e\x45\x54"
"\x57\x4f\x52\x4b\x20\x50\x52\x4f\x47\x52\x41\x4d\x20\x31"
"\x2e\x30\x00\x02\x4c\x41\x4e\x4d\x41\x4e\x31\x2e\x30\x00"
"\x02\x57\x69\x6e\x64\x6f\x77\x73\x20\x66\x6f\x72\x20\x57"
"\x6f\x72\x6b\x67\x72\x6f\x75\x70\x73\x20\x33\x2e\x31\x61"
"\x00\x02\x4c\x4d\x31\x2e\x32\x58\x30\x30\x32\x00\x02\x4c"
"\x41\x4e\x4d\x41\x4e\x32\x2e\x31\x00\x02\x4e\x54\x20\x4c"
"\x4d\x20\x30\x2e\x31\x32\x00\x02\x53\x4d\x42\x20\x32\x2e"
"\x30\x30\x32\x00"
)

(2)分析

十六进制字符串“0x00000000202e30303200”请求,通过ASCII编码可以看出是在探测NTLMSMB协议的版本。无响应,无此漏洞。

enter image description here

5、MS06-025漏洞

(1)MS06-025漏洞扫描部分源码如下:

--create the SMB session
--first we try with the "\router" pipe, then the "\srvsvc" pipe.
local status, smb_result, smbstate, err_msg
status, smb_result = msrpc.start_smb(host, msrpc.ROUTER_PATH)
if(status == false) then
err_msg = smb_result
status, smb_result = msrpc.start_smb(host, msrpc.SRVSVC_PATH) --rras is also accessible across SRVSVC pipe
if(status == false) then
    return false, NOTUP --if not accessible across both pipes then service is inactive
end
end
smbstate = smb_result
--bind to RRAS service
local bind_result
status, bind_result = msrpc.bind(smbstate, msrpc.RASRPC_UUID, msrpc.RASRPC_VERSION, nil)
if(status == false) then 
msrpc.stop_smb(smbstate)
return false, UNKNOWN --if bind operation results with a false status we can't conclude anything.
End

(2)分析

先后尝试去连接“\router”、“ \srvsvc”路径,均报错,无RAS RPC服务。

enter image description here

enter image description here

6、MS07-029漏洞

(1)MS07-029漏洞扫描部分源码如下:

function check_ms07_029(host)
    --check for safety flag  
if(nmap.registry.args.safe ~= nil) then
        return true, NOTRUN
end
if(nmap.registry.args.unsafe == nil) then
return true, NOTRUN
end
    --create the SMB session
    local status, smbstate
    status, smbstate = msrpc.start_smb(host, msrpc.DNSSERVER_PATH)
    if(status == false) then
        return false, NOTUP --if not accessible across pipe then the service is inactive
    end
    --bind to DNSSERVER service
    local bind_result
    status, bind_result = msrpc.bind(smbstate, msrpc.DNSSERVER_UUID, msrpc.DNSSERVER_VERSION)
    if(status == false) then
        msrpc.stop_smb(smbstate)
        return false, UNKNOWN --if bind operation results with a false status we can't conclude anything.
    end
    --call
    local req_blob, q_result
    status, q_result = msrpc.DNSSERVER_Query(
        smbstate, 
        "VULNSRV", 
        string.rep("\\\13", 1000), 
        1)--any op num will do
    --sanity check
    msrpc.stop_smb(smbstate)
    if(status == false) then
        stdnse.print_debug(
            3,
            "check_ms07_029: DNSSERVER_Query failed")
        if(q_result == "NT_STATUS_PIPE_BROKEN") then
            return true, VULNERABLE
        else
            return true, PATCHED
        end
    else
        return true, PATCHED
    end
end

(2)分析

尝试打开“\DNSSERVER”,报错,未开启DNS RPC服务。

enter image description here

0x05 总结


1、扫描探测可以说是所有网络中遇到最多的攻击,因其仅仅是信息搜集而无实质性入侵,所以往往不被重视。但扫描一定是有目的的,一般都是攻击入侵的前兆。

2、修补漏洞很重要,但如果在扫描层面进行防御,攻击者就无从知晓你是否存在漏洞。

3、扫描探测一般都无实质性通信行为,同时大量重复性动作,所以在流量监测上完全可以做到阻止防御。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK