โดยปกติใน Metasploit นั้นมี module cmd/powershell_base64 แต่การทำงานของมันไม่ได้เป็นการทำงานให้ออกมาในรูปแบบของ oneline powershell ทำให้นำไปใช้ต่อมันยากกว่าของพวก Powershell Empire ดังนั้นเราจึงต้องสร้าง powershell base64 oneline ขึ้นมาเอง โดยในที่นี้เราจะสร้าง encoder module ขึ้นมาใหม่ โดยทำดังนี้
1. สร้าง folder ใหม่ที่ /usr/share/metasploit-framework/modules/encoders/powershell/
1 |
mkdir /usr/share/metasploit-framework/modules/encoders/powershell/ |
2. สร้างไฟล์ base64.rb ขึ้นมา โดยภายในนั้นให้ใส่เป็น
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
## # This module requires Metasploit: https://metasploit.com/download # Current source: https://github.com/rapid7/metasploit-framework ## class MetasploitModule < Msf::Encoder Rank = NormalRanking def initialize super( 'Name' => 'Powershell Base64 Script Encoder', 'Description' => %q{ This encodes a PowerShell script as a base64 encoded script for PowerShell. }, 'Author' => 'Didier Stevens', 'Arch' => ARCH_CMD, 'Platform' => 'win') register_options([ OptBool.new('NOEXIT', [ false, 'Add -noexit option', false ]), OptBool.new('SYSWOW64', [ false, 'Call syswow64 powershell', false ]) ]) end # # Encodes the payload # def encode_block(state, buf) base64 = Rex::Text.encode_base64(Rex::Text.to_unicode(buf)) cmd = '' if datastore['SYSWOW64'] cmd += 'c:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe ' else cmd += 'powershell.exe ' end if datastore['NOEXIT'] cmd += '-NoExit ' end cmd += "-EncodedCommand #{base64}" end end |
3. save
4. ทดสอบ list module ต่างๆออกมาจะพบว่ามี powershell/base64 อยู่ในส่วนของ encoders ด้วย
5. ทดสอบใช้งาน
Source:: Didierstevens