Skip to content

Commit 54df2db

Browse files
committed
compression
1 parent b63f5eb commit 54df2db

File tree

3 files changed

+62
-17
lines changed

3 files changed

+62
-17
lines changed

c2/msg.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package c2
22

33
import (
44
"bytes"
5+
"compress/gzip"
56
"errors"
67
"math/rand"
78
"sort"
@@ -10,6 +11,7 @@ import (
1011

1112
"github.com/lunixbochs/struc"
1213
"github.com/miekg/dns"
14+
"github.com/mosajjal/dnspot/conf"
1315
"github.com/mosajjal/dnspot/cryptography"
1416
)
1517

@@ -96,8 +98,27 @@ func split(buf []byte, lim int) [][]byte {
9698
return chunks
9799
}
98100

101+
// Gets a big payload that needs to be sent over the wire, chops it up into smaller limbs and creates a list of messages to be sent. It also sends the parentPartID to make sure the series
102+
// of messages are not lost
99103
func PreparePartitionedPayload(msg MessagePacket, payload []byte, dnsSuffix string, privateKey *cryptography.PrivateKey, serverPublicKey *cryptography.PublicKey) ([]string, uint16, error) {
100104
// TODO: fix duplicate sending
105+
106+
// handle compression
107+
if len(payload) > conf.CompressionThreshold {
108+
var b bytes.Buffer
109+
gz, _ := gzip.NewWriterLevel(&b, gzip.BestCompression)
110+
if _, err := gz.Write(payload); err != nil {
111+
panic(err)
112+
}
113+
if err := gz.Flush(); err != nil {
114+
panic(err)
115+
}
116+
if err := gz.Close(); err != nil {
117+
panic(err)
118+
}
119+
payload = b.Bytes()
120+
}
121+
101122
var err error
102123
var response []string
103124
var parentPartID uint16 = 0

conf/conf.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,31 @@ import (
66
"github.com/mosajjal/dnspot/cryptography"
77
)
88

9+
const (
10+
CompressionThreshold = 1024 * 2 // 2KB
11+
)
12+
913
var GlobalServerConfig struct {
10-
LogFile string
11-
LogLevel uint8
12-
PrivateKeyB32 string
13-
PrivateKey *cryptography.PrivateKey
14-
ListenAddress string
15-
EnforceClientKeys bool
16-
AcceptedClientKeysB32 []string
17-
AcceptedClientKeys *[]cryptography.PublicKey
18-
DnsSuffix string
14+
LogFile string
15+
LogLevel uint8
16+
PrivateKeyBasexx string
17+
PrivateKey *cryptography.PrivateKey
18+
ListenAddress string
19+
EnforceClientKeys bool
20+
AcceptedClientKeysBasexx []string
21+
AcceptedClientKeys *[]cryptography.PublicKey
22+
DnsSuffix string
1923
}
2024

2125
var GlobalAgentConfig struct {
22-
CommandTimeout time.Duration
23-
LogLevel uint8
24-
PrivateKeyB32 string
25-
PrivateKey *cryptography.PrivateKey
26-
ServerAddress string
27-
ServerPublicKeyB32 string
28-
ServerPublicKey *cryptography.PublicKey
29-
DnsSuffix string
26+
CommandTimeout time.Duration
27+
LogLevel uint8
28+
PrivateKeyBasexx string
29+
PrivateKey *cryptography.PrivateKey
30+
ServerAddress string
31+
ServerPublicKeyBasexx string
32+
ServerPublicKey *cryptography.PublicKey
33+
DnsSuffix string
3034
}
3135

3236
type Runmode uint8

server/ui.go renamed to server/tui.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package server
22

33
import (
44
"fmt"
5+
"time"
56

67
"github.com/mosajjal/dnspot/cryptography"
78
"github.com/rivo/tview"
@@ -25,6 +26,21 @@ var UiLog = tview.NewTextView()
2526

2627
var UiRoot = tview.NewApplication()
2728

29+
func uiUpdater() {
30+
timeticker := time.NewTicker(1 * time.Second)
31+
idleAgentRemovalTicker := time.NewTicker(60 * time.Second)
32+
// runCmdTicker := time.NewTicker(30 * time.Second)
33+
for {
34+
select {
35+
case <-timeticker.C:
36+
UiRoot.Draw()
37+
38+
case <-idleAgentRemovalTicker.C:
39+
RemoveIdleAgents()
40+
}
41+
}
42+
}
43+
2844
func RunTui() {
2945
UiAgentList.SetTitle("Agents").SetBorder(true)
3046
UiCmd.SetTitle("Command").SetBorder(true)
@@ -53,7 +69,11 @@ func RunTui() {
5369
AddItem(UiLog, 0, 1, 1, 1, 0, 100, false).
5470
AddItem(UiCmd, 1, 0, 1, 2, 0, 100, true)
5571

72+
// refresh UI and remove idle nodes as a goroutine
73+
go uiUpdater()
74+
5675
if err := UiRoot.SetRoot(grid, true).SetFocus(grid).EnableMouse(true).Run(); err != nil {
5776
panic(err)
5877
}
78+
5979
}

0 commit comments

Comments
 (0)