From f48b0c17ed0c5768436c4675cb648e5b93fe063a Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Wed, 18 Jul 2018 22:32:49 -0700 Subject: [PATCH] Prep for hkexsh alternate op mode via symlink/exe name: hkexcp - a secure remote file copier --- hkexsh/hkexcp | 1 + hkexsh/hkexsh.go | 50 +++++++++++++++++++++++++++++++--------------- hkexshd/hkexshd.go | 8 ++++---- 3 files changed, 39 insertions(+), 20 deletions(-) create mode 120000 hkexsh/hkexcp mode change 100644 => 100755 hkexsh/hkexsh.go mode change 100644 => 100755 hkexshd/hkexshd.go diff --git a/hkexsh/hkexcp b/hkexsh/hkexcp new file mode 120000 index 0000000..cf0eb1c --- /dev/null +++ b/hkexsh/hkexcp @@ -0,0 +1 @@ +hkexsh \ No newline at end of file diff --git a/hkexsh/hkexsh.go b/hkexsh/hkexsh.go old mode 100644 new mode 100755 index daca62b..4f9ca23 --- a/hkexsh/hkexsh.go +++ b/hkexsh/hkexsh.go @@ -72,6 +72,10 @@ func main() { var hAlg string var server string var cmdStr string + + var copySrc string + var copyDst string + var altUser string var authCookie string var chaffEnabled bool @@ -79,27 +83,49 @@ func main() { var chaffFreqMax uint var chaffBytesMax uint + var op []byte isInteractive := false flag.BoolVar(&vopt, "v", false, "show version") + flag.BoolVar(&dbg, "d", false, "debug logging") flag.StringVar(&cAlg, "c", "C_AES_256", "cipher [\"C_AES_256\" | \"C_TWOFISH_128\" | \"C_BLOWFISH_64\"]") - flag.StringVar(&hAlg, "h", "H_SHA256", "hmac [\"H_SHA256\"]") + flag.StringVar(&hAlg, "m", "H_SHA256", "hmac [\"H_SHA256\"]") flag.StringVar(&server, "s", "localhost:2000", "server hostname/address[:port]") - flag.StringVar(&cmdStr, "x", "", "command to run (default empty - interactive shell)") flag.StringVar(&altUser, "u", "", "specify alternate user") flag.StringVar(&authCookie, "a", "", "auth cookie") - flag.BoolVar(&chaffEnabled, "cE", true, "enabled chaff pkts (default true)") - flag.UintVar(&chaffFreqMin, "cfm", 100, "chaff pkt freq min (msecs)") - flag.UintVar(&chaffFreqMax, "cfM", 5000, "chaff pkt freq max (msecs)") - flag.UintVar(&chaffBytesMax, "cbM", 64, "chaff pkt size max (bytes)") - flag.BoolVar(&dbg, "d", false, "debug logging") - flag.Parse() + flag.BoolVar(&chaffEnabled, "e", true, "enabled chaff pkts (default true)") + flag.UintVar(&chaffFreqMin, "f", 100, "chaff pkt freq min (msecs)") + flag.UintVar(&chaffFreqMax, "F", 5000, "chaff pkt freq max (msecs)") + flag.UintVar(&chaffBytesMax, "B", 64, "chaff pkt size max (bytes)") + + // Find out what program we are (shell or copier) + myPath := strings.Split(os.Args[0], string(os.PathSeparator)) + if myPath[len(myPath)-1] != "hkexcp" { + // hkexsh accepts a command (-x) but not + // a srcpath (-r) or dstpath (-t) + flag.StringVar(&cmdStr, "x", "", "command to run (default empty - interactive shell)") + flag.Parse() + } else { + // hkexcp accepts srcpath (-r) and dstpath (-t), but not + // a command (-x) + flag.StringVar(©Src, "r", "", "copy srcpath") + flag.StringVar(©Dst, "t", "", "copy dstpath") + } + + if flag.NFlag() == 0 { + flag.Usage() + os.Exit(0) + } if vopt { fmt.Printf("version v%s\n", version) os.Exit(0) } + if len(cmdStr) != 0 && (len(copySrc) != 0 || len(copyDst) != 0) { + log.Fatal("incompatible options -- either cmd (-x) or copy ops (-r,-t), but not both") + } + if dbg { log.SetOutput(os.Stdout) } else { @@ -136,17 +162,9 @@ func main() { uname = altUser } - var op []byte if len(cmdStr) == 0 { op = []byte{'s'} isInteractive = true - } else if cmdStr == "-" { - op = []byte{'c'} - cmdStdin, err := ioutil.ReadAll(os.Stdin) - if err != nil { - panic(err) - } - cmdStr = strings.Trim(string(cmdStdin), "\r\n") } else { op = []byte{'c'} // non-interactive cmds may complete quickly, so chaff earlier/faster diff --git a/hkexshd/hkexshd.go b/hkexshd/hkexshd.go old mode 100644 new mode 100755 index 97a624e..6a823bf --- a/hkexshd/hkexshd.go +++ b/hkexshd/hkexshd.go @@ -202,10 +202,10 @@ func main() { flag.BoolVar(&vopt, "v", false, "show version") flag.StringVar(&laddr, "l", ":2000", "interface[:port] to listen") - flag.BoolVar(&chaffEnabled, "cE", true, "enabled chaff pkts") - flag.UintVar(&chaffFreqMin, "cfm", 100, "chaff pkt freq min (msecs)") - flag.UintVar(&chaffFreqMax, "cfM", 5000, "chaff pkt freq max (msecs)") - flag.UintVar(&chaffBytesMax, "cbM", 64, "chaff pkt size max (bytes)") + flag.BoolVar(&chaffEnabled, "e", true, "enabled chaff pkts") + flag.UintVar(&chaffFreqMin, "f", 100, "chaff pkt freq min (msecs)") + flag.UintVar(&chaffFreqMax, "F", 5000, "chaff pkt freq max (msecs)") + flag.UintVar(&chaffBytesMax, "B", 64, "chaff pkt size max (bytes)") flag.BoolVar(&dbg, "d", false, "debug logging") flag.Parse()