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
This commit is contained in:
parent
0d8462cfe7
commit
a8f85f5027
@ -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
|
||||
```
|
||||
```
|
||||
|
6
ssh.go
6
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user