compat.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* $OpenBSD: compat.c,v 1.115 2020/07/05 23:59:45 djm Exp $ */
  2. /*
  3. * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "includes.h"
  26. #include <sys/types.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <stdarg.h>
  30. #include "xmalloc.h"
  31. #include "packet.h"
  32. #include "compat.h"
  33. #include "log.h"
  34. #include "match.h"
  35. #include "kex.h"
  36. /* determine bug flags from SSH protocol banner */
  37. void
  38. compat_banner(struct ssh *ssh, const char *version)
  39. {
  40. int i;
  41. static struct {
  42. char *pat;
  43. int bugs;
  44. } check[] = {
  45. { "OpenSSH_2.*,"
  46. "OpenSSH_3.0*,"
  47. "OpenSSH_3.1*", SSH_BUG_EXTEOF|SSH_OLD_FORWARD_ADDR|
  48. SSH_BUG_SIGTYPE},
  49. { "OpenSSH_3.*", SSH_OLD_FORWARD_ADDR|SSH_BUG_SIGTYPE },
  50. { "Sun_SSH_1.0*", SSH_BUG_NOREKEY|SSH_BUG_EXTEOF|
  51. SSH_BUG_SIGTYPE},
  52. { "OpenSSH_2*,"
  53. "OpenSSH_3*,"
  54. "OpenSSH_4*", SSH_BUG_SIGTYPE },
  55. { "OpenSSH_5*", SSH_NEW_OPENSSH|SSH_BUG_DYNAMIC_RPORT|
  56. SSH_BUG_SIGTYPE},
  57. { "OpenSSH_6.6.1*", SSH_NEW_OPENSSH|SSH_BUG_SIGTYPE},
  58. { "OpenSSH_6.5*,"
  59. "OpenSSH_6.6*", SSH_NEW_OPENSSH|SSH_BUG_CURVE25519PAD|
  60. SSH_BUG_SIGTYPE},
  61. { "OpenSSH_7.0*,"
  62. "OpenSSH_7.1*,"
  63. "OpenSSH_7.2*,"
  64. "OpenSSH_7.3*,"
  65. "OpenSSH_7.4*,"
  66. "OpenSSH_7.5*,"
  67. "OpenSSH_7.6*,"
  68. "OpenSSH_7.7*", SSH_NEW_OPENSSH|SSH_BUG_SIGTYPE},
  69. { "OpenSSH*", SSH_NEW_OPENSSH },
  70. { "*MindTerm*", 0 },
  71. { "3.0.*", SSH_BUG_DEBUG },
  72. { "3.0 SecureCRT*", SSH_OLD_SESSIONID },
  73. { "1.7 SecureFX*", SSH_OLD_SESSIONID },
  74. { "1.2.18*,"
  75. "1.2.19*,"
  76. "1.2.20*,"
  77. "1.2.21*,"
  78. "1.2.22*", SSH_BUG_IGNOREMSG },
  79. { "1.3.2*", /* F-Secure */
  80. SSH_BUG_IGNOREMSG },
  81. { "Cisco-1.*", SSH_BUG_DHGEX_LARGE|
  82. SSH_BUG_HOSTKEYS },
  83. { "*SSH Compatible Server*", /* Netscreen */
  84. SSH_BUG_PASSWORDPAD },
  85. { "*OSU_0*,"
  86. "OSU_1.0*,"
  87. "OSU_1.1*,"
  88. "OSU_1.2*,"
  89. "OSU_1.3*,"
  90. "OSU_1.4*,"
  91. "OSU_1.5alpha1*,"
  92. "OSU_1.5alpha2*,"
  93. "OSU_1.5alpha3*", SSH_BUG_PASSWORDPAD },
  94. { "*SSH_Version_Mapper*",
  95. SSH_BUG_SCANNER },
  96. { "PuTTY_Local:*," /* dev versions < Sep 2014 */
  97. "PuTTY-Release-0.5*," /* 0.50-0.57, DH-GEX in >=0.52 */
  98. "PuTTY_Release_0.5*," /* 0.58-0.59 */
  99. "PuTTY_Release_0.60*,"
  100. "PuTTY_Release_0.61*,"
  101. "PuTTY_Release_0.62*,"
  102. "PuTTY_Release_0.63*,"
  103. "PuTTY_Release_0.64*",
  104. SSH_OLD_DHGEX },
  105. { "FuTTY*", SSH_OLD_DHGEX }, /* Putty Fork */
  106. { "Probe-*",
  107. SSH_BUG_PROBE },
  108. { "TeraTerm SSH*,"
  109. "TTSSH/1.5.*,"
  110. "TTSSH/2.1*,"
  111. "TTSSH/2.2*,"
  112. "TTSSH/2.3*,"
  113. "TTSSH/2.4*,"
  114. "TTSSH/2.5*,"
  115. "TTSSH/2.6*,"
  116. "TTSSH/2.70*,"
  117. "TTSSH/2.71*,"
  118. "TTSSH/2.72*", SSH_BUG_HOSTKEYS },
  119. { "WinSCP_release_4*,"
  120. "WinSCP_release_5.0*,"
  121. "WinSCP_release_5.1,"
  122. "WinSCP_release_5.1.*,"
  123. "WinSCP_release_5.5,"
  124. "WinSCP_release_5.5.*,"
  125. "WinSCP_release_5.6,"
  126. "WinSCP_release_5.6.*,"
  127. "WinSCP_release_5.7,"
  128. "WinSCP_release_5.7.1,"
  129. "WinSCP_release_5.7.2,"
  130. "WinSCP_release_5.7.3,"
  131. "WinSCP_release_5.7.4",
  132. SSH_OLD_DHGEX },
  133. { "ConfD-*",
  134. SSH_BUG_UTF8TTYMODE },
  135. { "Twisted_*", 0 },
  136. { "Twisted*", SSH_BUG_DEBUG },
  137. { NULL, 0 }
  138. };
  139. /* process table, return first match */
  140. ssh->compat = 0;
  141. for (i = 0; check[i].pat; i++) {
  142. if (match_pattern_list(version, check[i].pat, 0) == 1) {
  143. debug("match: %s pat %s compat 0x%08x",
  144. version, check[i].pat, check[i].bugs);
  145. /* Check to see if the remote side is OpenSSH and not HPN */
  146. if (strstr(version, "OpenSSH") != NULL) {
  147. if (strstr(version, "hpn") == NULL) {
  148. // datafellows |= SSH_BUG_LARGEWINDOW;
  149. // ssh->compat |= SSH_BUG_LARGEWINDOW;
  150. debug("Remote is NOT HPN enabled");
  151. } else {
  152. debug("Remote is HPN Enabled");
  153. }
  154. }
  155. ssh->compat = check[i].bugs;
  156. return;
  157. }
  158. }
  159. debug("no match: %s", version);
  160. }
  161. char *
  162. compat_cipher_proposal(struct ssh *ssh, char *cipher_prop)
  163. {
  164. if (!(ssh->compat & SSH_BUG_BIGENDIANAES))
  165. return cipher_prop;
  166. debug2("%s: original cipher proposal: %s", __func__, cipher_prop);
  167. if ((cipher_prop = match_filter_denylist(cipher_prop, "aes*")) == NULL)
  168. fatal("match_filter_denylist failed");
  169. debug2("%s: compat cipher proposal: %s", __func__, cipher_prop);
  170. if (*cipher_prop == '\0')
  171. fatal("No supported ciphers found");
  172. return cipher_prop;
  173. }
  174. char *
  175. compat_pkalg_proposal(struct ssh *ssh, char *pkalg_prop)
  176. {
  177. if (!(ssh->compat & SSH_BUG_RSASIGMD5))
  178. return pkalg_prop;
  179. debug2("%s: original public key proposal: %s", __func__, pkalg_prop);
  180. if ((pkalg_prop = match_filter_denylist(pkalg_prop, "ssh-rsa")) == NULL)
  181. fatal("match_filter_denylist failed");
  182. debug2("%s: compat public key proposal: %s", __func__, pkalg_prop);
  183. if (*pkalg_prop == '\0')
  184. fatal("No supported PK algorithms found");
  185. return pkalg_prop;
  186. }
  187. char *
  188. compat_kex_proposal(struct ssh *ssh, char *p)
  189. {
  190. if ((ssh->compat & (SSH_BUG_CURVE25519PAD|SSH_OLD_DHGEX)) == 0)
  191. return p;
  192. debug2("%s: original KEX proposal: %s", __func__, p);
  193. if ((ssh->compat & SSH_BUG_CURVE25519PAD) != 0)
  194. if ((p = match_filter_denylist(p,
  195. "curve25519-sha256@libssh.org")) == NULL)
  196. fatal("match_filter_denylist failed");
  197. if ((ssh->compat & SSH_OLD_DHGEX) != 0) {
  198. if ((p = match_filter_denylist(p,
  199. "diffie-hellman-group-exchange-sha256,"
  200. "diffie-hellman-group-exchange-sha1")) == NULL)
  201. fatal("match_filter_denylist failed");
  202. }
  203. debug2("%s: compat KEX proposal: %s", __func__, p);
  204. if (*p == '\0')
  205. fatal("No supported key exchange algorithms found");
  206. return p;
  207. }