From a8f85f5027505f35cc69a9fe85b50e0a0ec9f515 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 23 Jun 2018 15:43:08 +0200 Subject: [PATCH] ssh: default to starting "sh" on shell requests instead of erroring This may still result in an error if sh is not present, but in case sh *is* present, it results in the user just getting a shell without having to use e.g. ssh -t gokrazy ./busybox sh --- README.md | 7 ++++--- ssh.go | 6 ++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index fbc1bc0..379ad3e 100644 --- a/README.md +++ b/README.md @@ -50,9 +50,10 @@ $ cd /tmp/busybox-1.22.0 $ file busybox busybox: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, for GNU/Linux 3.7.0, BuildID[sha1]=c9e20e9849ed0ca3c2bd058427ac31a27c008efe, stripped -$ tar cf breakglass.tar busybox +$ ln -s busybox sh +$ tar cf breakglass.tar --dereference sh $ scp breakglass.tar gokrazy: -$ ssh gokrazy -t ./busybox sh +$ ssh gokrazy /tmp/breakglass564067692 # df -h Filesystem Size Used Available Use% Mounted on /dev/root 60.5M 60.5M 0 100% / @@ -60,4 +61,4 @@ devtmpfs 445.3M 0 445.3M 0% /dev tmpfs 50.0M 1.8M 48.2M 4% /tmp tmpfs 1.0M 8.0K 1016.0K 1% /etc /dev/mmcblk0p4 28.2G 44.1M 26.7G 0% /perm -``` \ No newline at end of file +``` diff --git a/ssh.go b/ssh.go index 4253934..efad8fe 100644 --- a/ssh.go +++ b/ssh.go @@ -106,10 +106,8 @@ func (s *session) request(req *ssh.Request) error { s.env = append(s.env, fmt.Sprintf("%s=%s", name, value)) case "shell": - // as per https://tools.ietf.org/html/rfc4254#section-6.5, - // shell requests don’t carry a payload, and we don’t have a - // default shell, so decline the request - return fmt.Errorf("shell requests unsupported, use exec") + req.Payload = []byte("\x00\x00\x00\x00sh") + fallthrough case "exec": if got, want := len(req.Payload), 4; got < want {