Skip to content

Commit

Permalink
fixed spaces issue on windows & generating keys on build
Browse files Browse the repository at this point in the history
  • Loading branch information
xct committed Aug 29, 2020
1 parent d847a07 commit 3e08aa4
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ plugins/*
!plugins/plugins.go
shell/keys.go
meter/sc.go
keys/*
files/keys/*
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ BUILD=go build
GENERATE=go generate
OUT_LINUX=xc
OUT_WINDOWS=xc.exe
OUT_WINDOWS_ARM=xc_arm.exe
SRC=xc.go

all: clean linux64 windows64
AUTH_KEY =

all: clean linux64 windows64 windowsArm64

linux64:
GOOS=linux GOARCH=amd64 ${GENERATE}
Expand All @@ -14,5 +17,12 @@ windows64:
GOOS=linux GOARCH=amd64 ${GENERATE}
GOOS=windows GOARCH=amd64 ${BUILD} -o ${OUT_WINDOWS} ${SRC}

windowsArm64:
GOOS=linux GOARCH=arm ${GENERATE}
GOOS=windows GOARCH=arm ${BUILD} -o ${OUT_WINDOWS_ARM} ${SRC}

clean:
rm -f ${OUT_LINUX} ${OUT_WINDOWS} shell/keys.go meter/sc.go
yes 'y' | ssh-keygen -t ed25519 -f files/keys/key -q -N ""
yes 'y' | ssh-keygen -f host_dsa -N '' -t dsa -f files/keys/host_dsa -q -N ""
yes 'y' | ssh-keygen -f host_rsa -N '' -t rsa -f files/keys/host_rsa -q -N ""
rm -f ${OUT_LINUX} ${OUT_WINDOWS} ${OUT_WINDOWS_ARM} shell/keys.go meter/sc.go
40 changes: 40 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,44 @@ import (
"github.com/hashicorp/yamux"
)


// splitArgs : don't split on spaces inside quoted strings
func splitArgs(cmd string) []string{
args := []string{}
current := ""
squote := 0
dquote := 0
last := ""
for _, rune := range cmd {
char := string(rune)
if char == "'" {
squote += 1
if squote == 2 {
squote = 0
}
} else if char == "\"" {
dquote += 1
if dquote == 2 {
dquote = 0
}
} else if char == " " && squote == 0 && dquote == 0 && last != "\\" {
args = append(args, current)
current = ""
} else {
if char != "\\" {
current += char
}
last = char
}
}
if len(args) == 0 {
args = append(args, cmd)
} else {
args = append(args, current)
}
return args
}

func prompt(c net.Conn) {
cwd, err := os.Getwd()
if err != nil {
Expand All @@ -18,6 +56,7 @@ func prompt(c net.Conn) {
fmt.Fprintf(c, fmt.Sprintf("[xc: %s]: ", cwd))
}


func lfwd(host string, port string, s *yamux.Session, c net.Conn) {
for {
proxy, err := s.Accept()
Expand All @@ -36,6 +75,7 @@ func lfwd(host string, port string, s *yamux.Session, c net.Conn) {
}
}


// opens the listening socket on the client side
func rfwd(port string, session *yamux.Session, c net.Conn) {
ln, err := net.Listen("tcp", fmt.Sprintf(":%s", port))
Expand Down
2 changes: 1 addition & 1 deletion client/client_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Run(s *yamux.Session, c net.Conn) {
for scanner.Scan() {
command := scanner.Text()
if len(command) > 1 {
argv := strings.Split(command, " ")
argv := splitArgs(command)
// we only handle commands here that do something on the client side
switch argv[0] {
case "!help":
Expand Down
2 changes: 1 addition & 1 deletion client/client_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Run(s *yamux.Session, c net.Conn) {
for scanner.Scan() {
command := scanner.Text()
if len(command) > 1 {
argv := strings.Split(command, " ")
argv := splitArgs(command)
// we only handle commands here that do something on the client side
switch argv[0] {
case "!help":
Expand Down
21 changes: 0 additions & 21 deletions files/keys/host_dsa

This file was deleted.

1 change: 0 additions & 1 deletion files/keys/host_dsa.pub

This file was deleted.

38 changes: 0 additions & 38 deletions files/keys/host_rsa

This file was deleted.

1 change: 0 additions & 1 deletion files/keys/host_rsa.pub

This file was deleted.

7 changes: 0 additions & 7 deletions files/keys/key

This file was deleted.

1 change: 0 additions & 1 deletion files/keys/key.pub

This file was deleted.

6 changes: 5 additions & 1 deletion plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ func Init(c net.Conn) {

// Execute ...
func Execute(pluginName string, c net.Conn) {
plugins[pluginName].Execute(c)
if _, ok := plugins[pluginName]; ok {
plugins[pluginName].Execute(c)
} else {
c.Write([]byte("[!] Plugin does not exist\n"))
}
}

// List ...
Expand Down
2 changes: 1 addition & 1 deletion xc.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func main() {
\ \/ / __|
> < (__
/_/\_\___| by @xct_de
build: 0000000000000000
build: GLvLrMgcikmgHFyx
`
fmt.Println(banner)

Expand Down

0 comments on commit 3e08aa4

Please sign in to comment.