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

cs 4.1使用cross c2写插件时bls命令无法正常运行 #81

Closed
Echocipher opened this issue May 13, 2021 · 5 comments
Closed

cs 4.1使用cross c2写插件时bls命令无法正常运行 #81

Echocipher opened this issue May 13, 2021 · 5 comments

Comments

@Echocipher
Copy link

环境 cs4.1 cross c2

编写如下判断文件是否存在函数

$filename_linux = "prf-linux";
$filepath = "/tmp/"
sub file_exists {
println($bid);
bls($bid, $filepath, lambda({
if (indexOf($3, $filename) != 0) {
println($filename . " exists");
} else {
println($filename . " not exists");
}
}));
}

通过下面函数调用可正常判断文件是否存在
file_exists($bid, $filepath);

image

但是如果在调用该函数前调用其他函数,就不能正常执行了,比如

bcd($bid, $3['UploadPath']);
bupload($bid, script_resource("scripts/".$filename));

file_exists($bid, $filepath);

就只能调用cd命令和upload,但是file_exists没反应了,跟了一下发现file_exists也调用了,但是bls没有跑起来

image

但是同样的命令在windows下可以正常运行

image

@gloxec
Copy link
Owner

gloxec commented May 14, 2021

环境 cs4.1 cross c2
...
通过下面函数调用可正常判断文件是否存在
file_exists($bid, $filepath);
...
但是如果在调用该函数前调用其他函数,就不能正常执行了,比如

bcd($bid, $3['UploadPath']);
bupload($bid, script_resource("scripts/".$filename));
  1. 应该是cs下发任务时将指令合并导致的问题,如果测试是该问题的话稍后会调试修复推送新版。

bupload($bid, script_resource("scripts/".$filename));

  1. 这里建议先使用 bupload_raw() 函数编写整个插件,因为bupload函数会被本地的cs客户端限制上传文件大小,所以在设计linux beacon时弃用了该函数
$handle = openf($loadFilePath);
$fileData = readb($handle, -1);
closef($handle);
bupload_raw($beaconid,$fileSavePath,$fileData);

@Echocipher
Copy link
Author

Echocipher commented May 14, 2021

环境 cs4.1 cross c2
...
通过下面函数调用可正常判断文件是否存在
file_exists($bid, $filepath);
...
但是如果在调用该函数前调用其他函数,就不能正常执行了,比如

bcd($bid, $3['UploadPath']);
bupload($bid, script_resource("scripts/".$filename));
  1. 应该是cs下发任务时将指令合并导致的问题,如果测试是该问题的话稍后会调试修复推送新版。

bupload($bid, script_resource("scripts/".$filename));

  1. 这里建议先使用 bupload_raw() 函数编写整个插件,因为bupload函数会被本地的cs客户端限制上传文件大小,所以在设计linux beacon时弃用了该函数
$handle = openf($loadFilePath);
$fileData = readb($handle, -1);
closef($handle);
bupload_raw($beaconid,$fileSavePath,$fileData);

我这边又测试了一下发现好像不是上传的原因,上传是没有问题的(其实确实是被切割了,比如9m的文件确实会先切割上传,然后没上传完就执行后面的命令了),但是前面不管是什么命令都无法调用后面的file_exists,比如只调用bcd不调用upload同样不能正常调用file_exists,改为bupload_raw同理,如果将后面的file_exists换成println就能正常执行,但是不会等到上传结束,而是立刻执行

    bcd($bid, $3['UploadPath']);
    file_exists($bid, $filepath);

by the way其实我最终想实现的就是在文件上传完成前不执行后面的语句,因此才想出自己实现一个判断文件是否存在并持续递归,直到上传完成再执行后面的命令,我看了官方文档好像没有判断文件是否存在的方法,本来想利用bshell将ls的结果保存到一个tmp.txt,再通过cna脚本去读来实现查找文件是否存在,但是似乎官网也没有直接读文件的函数,您有什么好的建议么,感谢您百忙之中的回复

@gloxec
Copy link
Owner

gloxec commented May 15, 2021

bls的回调是可以获取到文件的详细信息的,比如大小,日期之类的,可以通过这个来判断文件是否存在或者说文件是否上传完毕。

bls($bid, $filepath, lambda({
println($3);
}));

@gloxec
Copy link
Owner

gloxec commented May 15, 2021

linux所使用的bupload_raw()是非阻塞的,目前没法解决,鉴于该问题需要调用bupload的阻塞特性,下个版本会考虑支持此函数。

@gloxec gloxec added the New label May 15, 2021
@gloxec
Copy link
Owner

gloxec commented May 28, 2021

上述该问题已解决,且bupload函数也已添加

@gloxec gloxec added the Fixed label May 28, 2021
@gloxec gloxec closed this as completed Oct 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants