2023-03-01 09:29:32 +00:00
|
|
|
# $OpenBSD: integrity.sh,v 1.25 2023/03/01 09:29:32 dtucker Exp $
|
2012-12-11 23:54:37 +00:00
|
|
|
# Placed in the Public Domain.
|
|
|
|
|
|
|
|
tid="integrity"
|
2014-05-15 05:07:53 +00:00
|
|
|
cp $OBJ/sshd_proxy $OBJ/sshd_proxy_bak
|
2012-12-11 23:54:37 +00:00
|
|
|
|
2013-02-18 22:28:32 +00:00
|
|
|
# start at byte 2900 (i.e. after kex) and corrupt at different offsets
|
2012-12-11 23:54:37 +00:00
|
|
|
tries=10
|
2013-02-18 22:28:32 +00:00
|
|
|
startoffset=2900
|
2013-11-07 04:21:19 +00:00
|
|
|
macs=`${SSH} -Q mac`
|
2013-01-12 11:46:26 +00:00
|
|
|
# The following are not MACs, but ciphers with integrated integrity. They are
|
|
|
|
# handled specially below.
|
2013-11-21 03:26:18 +00:00
|
|
|
macs="$macs `${SSH} -Q cipher-auth`"
|
2012-12-11 23:54:37 +00:00
|
|
|
|
2013-05-17 03:16:59 +00:00
|
|
|
# avoid DH group exchange as the extra traffic makes it harder to get the
|
|
|
|
# offset into the stream right.
|
2019-07-25 08:36:28 +00:00
|
|
|
#echo "KexAlgorithms -diffie-hellman-group*" \
|
|
|
|
# >> $OBJ/ssh_proxy
|
2013-05-17 03:16:59 +00:00
|
|
|
|
2012-12-11 23:54:37 +00:00
|
|
|
# sshd-command for proxy (see test-exec.sh)
|
2023-03-01 09:29:32 +00:00
|
|
|
cmd="$SUDO env SSH_SK_HELPER="$SSH_SK_HELPER" sh ${OBJ}/sshd-log-wrapper.sh -i -f $OBJ/sshd_proxy"
|
2012-12-11 23:54:37 +00:00
|
|
|
|
|
|
|
for m in $macs; do
|
|
|
|
trace "test $tid: mac $m"
|
|
|
|
elen=0
|
|
|
|
epad=0
|
|
|
|
emac=0
|
2017-01-06 02:26:10 +00:00
|
|
|
etmo=0
|
2012-12-11 23:54:37 +00:00
|
|
|
ecnt=0
|
|
|
|
skip=0
|
2013-02-27 04:27:29 +00:00
|
|
|
for off in `jot $tries $startoffset`; do
|
|
|
|
skip=`expr $skip - 1`
|
2012-12-12 01:10:10 +00:00
|
|
|
if [ $skip -gt 0 ]; then
|
2012-12-11 23:54:37 +00:00
|
|
|
# avoid modifying the high bytes of the length
|
|
|
|
continue
|
|
|
|
fi
|
2014-05-15 05:07:53 +00:00
|
|
|
cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
|
2012-12-11 23:54:37 +00:00
|
|
|
# modify output from sshd at offset $off
|
2013-02-26 07:58:06 +00:00
|
|
|
pxy="proxycommand=$cmd | $OBJ/modpipe -wm xor:$off:1"
|
2015-03-24 20:19:15 +00:00
|
|
|
if ${SSH} -Q cipher-auth | grep "^${m}\$" >/dev/null 2>&1 ; then
|
2014-05-15 05:07:53 +00:00
|
|
|
echo "Ciphers=$m" >> $OBJ/sshd_proxy
|
2013-11-21 03:26:18 +00:00
|
|
|
macopt="-c $m"
|
|
|
|
else
|
2014-05-15 05:07:53 +00:00
|
|
|
echo "Ciphers=aes128-ctr" >> $OBJ/sshd_proxy
|
|
|
|
echo "MACs=$m" >> $OBJ/sshd_proxy
|
2013-11-21 03:26:18 +00:00
|
|
|
macopt="-m $m -c aes128-ctr"
|
|
|
|
fi
|
2013-05-17 04:47:51 +00:00
|
|
|
verbose "test $tid: $m @$off"
|
2017-04-30 23:34:55 +00:00
|
|
|
${SSH} $macopt -F $OBJ/ssh_proxy -o "$pxy" \
|
2013-11-21 03:26:18 +00:00
|
|
|
-oServerAliveInterval=1 -oServerAliveCountMax=30 \
|
2013-05-16 23:31:39 +00:00
|
|
|
999.999.999.999 'printf "%4096s" " "' >/dev/null
|
2012-12-11 23:54:37 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
fail "ssh -m $m succeeds with bit-flip at $off"
|
|
|
|
fi
|
2013-02-27 04:27:29 +00:00
|
|
|
ecnt=`expr $ecnt + 1`
|
2016-03-04 02:48:06 +00:00
|
|
|
out=$(egrep -v "^debug" $TEST_SSH_LOGFILE | tail -2 | \
|
2013-05-16 23:31:39 +00:00
|
|
|
tr -s '\r\n' '.')
|
2014-07-02 07:01:08 +00:00
|
|
|
case "$out" in
|
2013-02-27 04:27:29 +00:00
|
|
|
Bad?packet*) elen=`expr $elen + 1`; skip=3;;
|
2015-01-19 20:42:31 +00:00
|
|
|
Corrupted?MAC* | *message?authentication?code?incorrect*)
|
2013-02-27 04:27:29 +00:00
|
|
|
emac=`expr $emac + 1`; skip=0;;
|
|
|
|
padding*) epad=`expr $epad + 1`; skip=0;;
|
2017-04-28 04:33:43 +00:00
|
|
|
*Timeout,?server*)
|
|
|
|
etmo=`expr $etmo + 1`; skip=0;;
|
2014-07-02 07:01:08 +00:00
|
|
|
*) fail "unexpected error mac $m at $off: $out";;
|
2012-12-11 23:54:37 +00:00
|
|
|
esac
|
|
|
|
done
|
2017-04-28 04:33:43 +00:00
|
|
|
verbose "test $tid: $ecnt errors: mac $emac padding $epad length $elen timeout $etmo"
|
2012-12-11 23:54:37 +00:00
|
|
|
if [ $emac -eq 0 ]; then
|
|
|
|
fail "$m: no mac errors"
|
|
|
|
fi
|
2017-04-28 04:33:43 +00:00
|
|
|
expect=`expr $ecnt - $epad - $elen - $etmo`
|
2012-12-11 23:54:37 +00:00
|
|
|
if [ $emac -ne $expect ]; then
|
|
|
|
fail "$m: expected $expect mac errors, got $emac"
|
|
|
|
fi
|
|
|
|
done
|