-
Notifications
You must be signed in to change notification settings - Fork 121
wolfsshd: refuse sessions it cannot serve #1237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b22da33
internal: log a subsystem request as a subsystem
ejohnstown 7a8ff75
wolfsshd: refuse sessions it cannot serve
ejohnstown c995db9
scp: match the scp command as a whole token
ejohnstown f31d9c5
ssh: add a channel session-granted accessor
ejohnstown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| #!/bin/sh | ||
|
|
||
| # sshd local test: a subsystem the daemon does not serve is refused at the | ||
| # request, so the client sees CHANNEL_FAILURE rather than a session that | ||
| # is accepted and then dropped. Uses the system OpenSSH client, since the | ||
| # in-tree clients only ask for sftp. | ||
|
|
||
| # Not named PWD: the shell rewrites that variable on every cd, so a saved | ||
| # copy would not survive the cd to the repository root below. | ||
| TESTDIR=`pwd` | ||
| cd ../../.. | ||
|
|
||
| USER="$3" | ||
| if [ -z "$USER" ]; then | ||
| USER=`whoami` | ||
| fi | ||
| PRIVATE_KEY="./keys/hansel-key-ecc.pem" | ||
|
|
||
| if [ -z "$1" ] || [ -z "$2" ]; then | ||
| echo "expecting host and port as arguments" | ||
| echo "./sshd_bad_subsystem_test.sh 127.0.0.1 22222" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! command -v ssh >/dev/null 2>&1; then | ||
| echo "OpenSSH client not found, skipping" | ||
| exit 77 | ||
| fi | ||
|
|
||
| # The regression this test looks for is a request the daemon never answers, | ||
| # which leaves the client waiting. Bound every call so that hangs the test | ||
| # rather than the suite. | ||
| if ! command -v timeout >/dev/null 2>&1; then | ||
| echo "timeout not found, skipping" | ||
| exit 77 | ||
| fi | ||
| TIMEOUT="timeout 20" | ||
|
|
||
| # OpenSSH refuses a key file other users can read. | ||
| KEY=`mktemp 2>/dev/null` || KEY=`mktemp -t sshdbadsubsys` | ||
| OUT=`mktemp 2>/dev/null` || OUT=`mktemp -t sshdbadsubsysout` | ||
| if [ -z "$KEY" ] || [ ! -f "$KEY" ] || [ -z "$OUT" ] || [ ! -f "$OUT" ]; then | ||
| echo "could not create temp files" | ||
| rm -f "$KEY" "$OUT" | ||
| exit 1 | ||
| fi | ||
| trap 'rm -f "$KEY" "$OUT"' EXIT | ||
|
|
||
| cat "$PRIVATE_KEY" > "$KEY" || exit 1 | ||
| chmod 600 "$KEY" | ||
|
|
||
| ssh_to_sshd() { | ||
| $TIMEOUT ssh -p "$2" -i "$KEY" -o IdentitiesOnly=yes \ | ||
| -o StrictHostKeyChecking=no \ | ||
| -o UserKnownHostsFile=/dev/null -o PreferredAuthentications=publickey \ | ||
| -o BatchMode=yes -o ConnectTimeout=5 "$USER@$1" "$3" "$4" | ||
| } | ||
|
|
||
| # Control: the same client and key can run a command. | ||
| ssh_to_sshd "$1" "$2" "echo ok" > "$OUT" 2>&1 | ||
| RESULT=$? | ||
| if [ "$RESULT" != "0" ] || ! grep -q "^ok" "$OUT"; then | ||
| echo "Control exec through OpenSSH failed ($RESULT):" | ||
| cat "$OUT" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # A subsystem nothing serves: the client reports the refusal and exits | ||
| # non-zero. Check the timeout first, its 124 is non-zero too but means the | ||
| # request went unanswered, the opposite of what this test wants. | ||
| ssh_to_sshd "$1" "$2" -s no-such-subsystem > "$OUT" 2>&1 | ||
| RESULT=$? | ||
| if [ "$RESULT" = "124" ]; then | ||
| echo "The unknown subsystem request went unanswered:" | ||
| cat "$OUT" | ||
| exit 1 | ||
| fi | ||
| if [ "$RESULT" = "0" ]; then | ||
| echo "Expecting the unknown subsystem request to fail" | ||
| cat "$OUT" | ||
| exit 1 | ||
| fi | ||
| if ! grep -q "subsystem request failed" "$OUT"; then | ||
| echo "Expecting the client to report the refused subsystem request:" | ||
| cat "$OUT" | ||
| exit 1 | ||
| fi | ||
|
|
||
| cd "$TESTDIR" | ||
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.