Advertisement
opexxx

OSSL_CCS_InjectTest.py

Jul 8th, 2014
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 21.81 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. import socket
  5. import time
  6. import struct
  7.  
  8. if len(sys.argv)<2:
  9.     print "Tripwire VERT CVE-2014-0224 Detection Tool (OpenSSL Change Cipher Spec Injection) v0.3 by Tripwire VERT (@TripwireVERT)\nUsage: %s <host> [port=443]" % (sys.argv[0])
  10.     quit()
  11. else:
  12.     strHost = sys.argv[1]
  13.     if len(sys.argv)>2:
  14.         try:
  15.             iPort = int(sys.argv[2])
  16.         except:
  17.             print "Tripwire VERT CVE-2014-0224 Detection Tool (OpenSSL Change Cipher Spec Injection) v0.3\nUsage: %s <host> [port=443]" % (sys.argv[0])
  18.             quit()
  19.     else:
  20.         iPort = 443
  21.  
  22. print "***CVE-2014-0224 Detection Tool v0.3***\nBrought to you by Tripwire VERT (@TripwireVERT)"
  23.        
  24. dSSL = {
  25.     "SSLv3" : "\x03\x00",
  26.     "TLSv1" : "\x03\x01",
  27.     "TLSv1.1" : "\x03\x02",
  28.     "TLSv1.2" : "\x03\x03",
  29. }
  30.  
  31. # The following is a complete list of ciphers for the SSLv3 family up to TLSv1.2
  32. ssl3_cipher = dict()
  33. ssl3_cipher['\x00\x00'] = "TLS_NULL_WITH_NULL_NULL"
  34. ssl3_cipher['\x00\x01'] = "TLS_RSA_WITH_NULL_MD5"
  35. ssl3_cipher['\x00\x02'] = "TLS_RSA_WITH_NULL_SHA"
  36. ssl3_cipher['\x00\x03'] = "TLS_RSA_EXPORT_WITH_RC4_40_MD5"
  37. ssl3_cipher['\x00\x04'] = "TLS_RSA_WITH_RC4_128_MD5"
  38. ssl3_cipher['\x00\x05'] = "TLS_RSA_WITH_RC4_128_SHA"
  39. ssl3_cipher['\x00\x06'] = "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5"
  40. ssl3_cipher['\x00\x07'] = "TLS_RSA_WITH_IDEA_CBC_SHA"
  41. ssl3_cipher['\x00\x08'] = "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA"
  42. ssl3_cipher['\x00\x09'] = "TLS_RSA_WITH_DES_CBC_SHA"
  43. ssl3_cipher['\x00\x0a'] = "TLS_RSA_WITH_3DES_EDE_CBC_SHA"
  44. ssl3_cipher['\x00\x0b'] = "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA"
  45. ssl3_cipher['\x00\x0c'] = "TLS_DH_DSS_WITH_DES_CBC_SHA"
  46. ssl3_cipher['\x00\x0d'] = "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA"
  47. ssl3_cipher['\x00\x0e'] = "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA"
  48. ssl3_cipher['\x00\x0f'] = "TLS_DH_RSA_WITH_DES_CBC_SHA"
  49. ssl3_cipher['\x00\x10'] = "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA"
  50. ssl3_cipher['\x00\x11'] = "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"
  51. ssl3_cipher['\x00\x12'] = "TLS_DHE_DSS_WITH_DES_CBC_SHA"
  52. ssl3_cipher['\x00\x13'] = "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA"
  53. ssl3_cipher['\x00\x14'] = "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA"
  54. ssl3_cipher['\x00\x15'] = "TLS_DHE_RSA_WITH_DES_CBC_SHA"
  55. ssl3_cipher['\x00\x16'] = "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA"
  56. ssl3_cipher['\x00\x17'] = "TLS_DH_anon_EXPORT_WITH_RC4_40_MD5"
  57. ssl3_cipher['\x00\x18'] = "TLS_DH_anon_WITH_RC4_128_MD5"
  58. ssl3_cipher['\x00\x19'] = "TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA"
  59. ssl3_cipher['\x00\x1a'] = "TLS_DH_anon_WITH_DES_CBC_SHA"
  60. ssl3_cipher['\x00\x1b'] = "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA"
  61. ssl3_cipher['\x00\x1c'] = "SSL_FORTEZZA_KEA_WITH_NULL_SHA"
  62. ssl3_cipher['\x00\x1d'] = "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA"
  63. ssl3_cipher['\x00\x1e'] = "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA"
  64. ssl3_cipher['\x00\x1E'] = "TLS_KRB5_WITH_DES_CBC_SHA"
  65. ssl3_cipher['\x00\x1F'] = "TLS_KRB5_WITH_3DES_EDE_CBC_SHA"
  66. ssl3_cipher['\x00\x20'] = "TLS_KRB5_WITH_RC4_128_SHA"
  67. ssl3_cipher['\x00\x21'] = "TLS_KRB5_WITH_IDEA_CBC_SHA"
  68. ssl3_cipher['\x00\x22'] = "TLS_KRB5_WITH_DES_CBC_MD5"
  69. ssl3_cipher['\x00\x23'] = "TLS_KRB5_WITH_3DES_EDE_CBC_MD5"
  70. ssl3_cipher['\x00\x24'] = "TLS_KRB5_WITH_RC4_128_MD5"
  71. ssl3_cipher['\x00\x25'] = "TLS_KRB5_WITH_IDEA_CBC_MD5"
  72. ssl3_cipher['\x00\x26'] = "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA"
  73. ssl3_cipher['\x00\x27'] = "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA"
  74. ssl3_cipher['\x00\x28'] = "TLS_KRB5_EXPORT_WITH_RC4_40_SHA"
  75. ssl3_cipher['\x00\x29'] = "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5"
  76. ssl3_cipher['\x00\x2A'] = "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5"
  77. ssl3_cipher['\x00\x2B'] = "TLS_KRB5_EXPORT_WITH_RC4_40_MD5"
  78. ssl3_cipher['\x00\x2C'] = "TLS_PSK_WITH_NULL_SHA"
  79. ssl3_cipher['\x00\x2D'] = "TLS_DHE_PSK_WITH_NULL_SHA"
  80. ssl3_cipher['\x00\x2E'] = "TLS_RSA_PSK_WITH_NULL_SHA"
  81. ssl3_cipher['\x00\x2F'] = "TLS_RSA_WITH_AES_128_CBC_SHA"
  82. ssl3_cipher['\x00\x30'] = "TLS_DH_DSS_WITH_AES_128_CBC_SHA"
  83. ssl3_cipher['\x00\x31'] = "TLS_DH_RSA_WITH_AES_128_CBC_SHA"
  84. ssl3_cipher['\x00\x32'] = "TLS_DHE_DSS_WITH_AES_128_CBC_SHA"
  85. ssl3_cipher['\x00\x33'] = "TLS_DHE_RSA_WITH_AES_128_CBC_SHA"
  86. ssl3_cipher['\x00\x34'] = "TLS_DH_anon_WITH_AES_128_CBC_SHA"
  87. ssl3_cipher['\x00\x35'] = "TLS_RSA_WITH_AES_256_CBC_SHA"
  88. ssl3_cipher['\x00\x36'] = "TLS_DH_DSS_WITH_AES_256_CBC_SHA"
  89. ssl3_cipher['\x00\x37'] = "TLS_DH_RSA_WITH_AES_256_CBC_SHA"
  90. ssl3_cipher['\x00\x38'] = "TLS_DHE_DSS_WITH_AES_256_CBC_SHA"
  91. ssl3_cipher['\x00\x39'] = "TLS_DHE_RSA_WITH_AES_256_CBC_SHA"
  92. ssl3_cipher['\x00\x3A'] = "TLS_DH_anon_WITH_AES_256_CBC_SHA"
  93. ssl3_cipher['\x00\x3B'] = "TLS_RSA_WITH_NULL_SHA256"
  94. ssl3_cipher['\x00\x3C'] = "TLS_RSA_WITH_AES_128_CBC_SHA256"
  95. ssl3_cipher['\x00\x3D'] = "TLS_RSA_WITH_AES_256_CBC_SHA256"
  96. ssl3_cipher['\x00\x3E'] = "TLS_DH_DSS_WITH_AES_128_CBC_SHA256"
  97. ssl3_cipher['\x00\x3F'] = "TLS_DH_RSA_WITH_AES_128_CBC_SHA256"
  98. ssl3_cipher['\x00\x40'] = "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256"
  99. ssl3_cipher['\x00\x41'] = "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA"
  100. ssl3_cipher['\x00\x42'] = "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA"
  101. ssl3_cipher['\x00\x43'] = "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA"
  102. ssl3_cipher['\x00\x44'] = "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA"
  103. ssl3_cipher['\x00\x45'] = "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA"
  104. ssl3_cipher['\x00\x46'] = "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA"
  105. ssl3_cipher['\x00\x60'] = "TLS_RSA_EXPORT1024_WITH_RC4_56_MD5"
  106. ssl3_cipher['\x00\x61'] = "TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5"
  107. ssl3_cipher['\x00\x62'] = "TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA"
  108. ssl3_cipher['\x00\x63'] = "TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA"
  109. ssl3_cipher['\x00\x64'] = "TLS_RSA_EXPORT1024_WITH_RC4_56_SHA"
  110. ssl3_cipher['\x00\x65'] = "TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA"
  111. ssl3_cipher['\x00\x66'] = "TLS_DHE_DSS_WITH_RC4_128_SHA"
  112. ssl3_cipher['\x00\x67'] = "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256"
  113. ssl3_cipher['\x00\x68'] = "TLS_DH_DSS_WITH_AES_256_CBC_SHA256"
  114. ssl3_cipher['\x00\x69'] = "TLS_DH_RSA_WITH_AES_256_CBC_SHA256"
  115. ssl3_cipher['\x00\x6A'] = "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256"
  116. ssl3_cipher['\x00\x6B'] = "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256"
  117. ssl3_cipher['\x00\x6C'] = "TLS_DH_anon_WITH_AES_128_CBC_SHA256"
  118. ssl3_cipher['\x00\x6D'] = "TLS_DH_anon_WITH_AES_256_CBC_SHA256"
  119. ssl3_cipher['\x00\x80'] = "TLS_GOSTR341094_WITH_28147_CNT_IMIT"
  120. ssl3_cipher['\x00\x81'] = "TLS_GOSTR341001_WITH_28147_CNT_IMIT"
  121. ssl3_cipher['\x00\x82'] = "TLS_GOSTR341094_WITH_NULL_GOSTR3411"
  122. ssl3_cipher['\x00\x83'] = "TLS_GOSTR341001_WITH_NULL_GOSTR3411"
  123. ssl3_cipher['\x00\x84'] = "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA"
  124. ssl3_cipher['\x00\x85'] = "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA"
  125. ssl3_cipher['\x00\x86'] = "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA"
  126. ssl3_cipher['\x00\x87'] = "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA"
  127. ssl3_cipher['\x00\x88'] = "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA"
  128. ssl3_cipher['\x00\x89'] = "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA"
  129. ssl3_cipher['\x00\x8A'] = "TLS_PSK_WITH_RC4_128_SHA"
  130. ssl3_cipher['\x00\x8B'] = "TLS_PSK_WITH_3DES_EDE_CBC_SHA"
  131. ssl3_cipher['\x00\x8C'] = "TLS_PSK_WITH_AES_128_CBC_SHA"
  132. ssl3_cipher['\x00\x8D'] = "TLS_PSK_WITH_AES_256_CBC_SHA"
  133. ssl3_cipher['\x00\x8E'] = "TLS_DHE_PSK_WITH_RC4_128_SHA"
  134. ssl3_cipher['\x00\x8F'] = "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA"
  135. ssl3_cipher['\x00\x90'] = "TLS_DHE_PSK_WITH_AES_128_CBC_SHA"
  136. ssl3_cipher['\x00\x91'] = "TLS_DHE_PSK_WITH_AES_256_CBC_SHA"
  137. ssl3_cipher['\x00\x92'] = "TLS_RSA_PSK_WITH_RC4_128_SHA"
  138. ssl3_cipher['\x00\x93'] = "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA"
  139. ssl3_cipher['\x00\x94'] = "TLS_RSA_PSK_WITH_AES_128_CBC_SHA"
  140. ssl3_cipher['\x00\x95'] = "TLS_RSA_PSK_WITH_AES_256_CBC_SHA"
  141. ssl3_cipher['\x00\x96'] = "TLS_RSA_WITH_SEED_CBC_SHA"
  142. ssl3_cipher['\x00\x97'] = "TLS_DH_DSS_WITH_SEED_CBC_SHA"
  143. ssl3_cipher['\x00\x98'] = "TLS_DH_RSA_WITH_SEED_CBC_SHA"
  144. ssl3_cipher['\x00\x99'] = "TLS_DHE_DSS_WITH_SEED_CBC_SHA"
  145. ssl3_cipher['\x00\x9A'] = "TLS_DHE_RSA_WITH_SEED_CBC_SHA"
  146. ssl3_cipher['\x00\x9B'] = "TLS_DH_anon_WITH_SEED_CBC_SHA"
  147. ssl3_cipher['\x00\x9C'] = "TLS_RSA_WITH_AES_128_GCM_SHA256"
  148. ssl3_cipher['\x00\x9D'] = "TLS_RSA_WITH_AES_256_GCM_SHA384"
  149. ssl3_cipher['\x00\x9E'] = "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256"
  150. ssl3_cipher['\x00\x9F'] = "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384"
  151. ssl3_cipher['\x00\xA0'] = "TLS_DH_RSA_WITH_AES_128_GCM_SHA256"
  152. ssl3_cipher['\x00\xA1'] = "TLS_DH_RSA_WITH_AES_256_GCM_SHA384"
  153. ssl3_cipher['\x00\xA2'] = "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256"
  154. ssl3_cipher['\x00\xA3'] = "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384"
  155. ssl3_cipher['\x00\xA4'] = "TLS_DH_DSS_WITH_AES_128_GCM_SHA256"
  156. ssl3_cipher['\x00\xA5'] = "TLS_DH_DSS_WITH_AES_256_GCM_SHA384"
  157. ssl3_cipher['\x00\xA6'] = "TLS_DH_anon_WITH_AES_128_GCM_SHA256"
  158. ssl3_cipher['\x00\xA7'] = "TLS_DH_anon_WITH_AES_256_GCM_SHA384"
  159. ssl3_cipher['\x00\xA8'] = "TLS_PSK_WITH_AES_128_GCM_SHA256"
  160. ssl3_cipher['\x00\xA9'] = "TLS_PSK_WITH_AES_256_GCM_SHA384"
  161. ssl3_cipher['\x00\xAA'] = "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256"
  162. ssl3_cipher['\x00\xAB'] = "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384"
  163. ssl3_cipher['\x00\xAC'] = "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256"
  164. ssl3_cipher['\x00\xAD'] = "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384"
  165. ssl3_cipher['\x00\xAE'] = "TLS_PSK_WITH_AES_128_CBC_SHA256"
  166. ssl3_cipher['\x00\xAF'] = "TLS_PSK_WITH_AES_256_CBC_SHA384"
  167. ssl3_cipher['\x00\xB0'] = "TLS_PSK_WITH_NULL_SHA256"
  168. ssl3_cipher['\x00\xB1'] = "TLS_PSK_WITH_NULL_SHA384"
  169. ssl3_cipher['\x00\xB2'] = "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256"
  170. ssl3_cipher['\x00\xB3'] = "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384"
  171. ssl3_cipher['\x00\xB4'] = "TLS_DHE_PSK_WITH_NULL_SHA256"
  172. ssl3_cipher['\x00\xB5'] = "TLS_DHE_PSK_WITH_NULL_SHA384"
  173. ssl3_cipher['\x00\xB6'] = "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256"
  174. ssl3_cipher['\x00\xB7'] = "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384"
  175. ssl3_cipher['\x00\xB8'] = "TLS_RSA_PSK_WITH_NULL_SHA256"
  176. ssl3_cipher['\x00\xB9'] = "TLS_RSA_PSK_WITH_NULL_SHA384"
  177. ssl3_cipher['\x00\xBA'] = "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256"
  178. ssl3_cipher['\x00\xBB'] = "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256"
  179. ssl3_cipher['\x00\xBC'] = "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256"
  180. ssl3_cipher['\x00\xBD'] = "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256"
  181. ssl3_cipher['\x00\xBE'] = "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256"
  182. ssl3_cipher['\x00\xBF'] = "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256"
  183. ssl3_cipher['\x00\xC0'] = "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256"
  184. ssl3_cipher['\x00\xC1'] = "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256"
  185. ssl3_cipher['\x00\xC2'] = "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256"
  186. ssl3_cipher['\x00\xC3'] = "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256"
  187. ssl3_cipher['\x00\xC4'] = "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256"
  188. ssl3_cipher['\x00\xC5'] = "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256"
  189. ssl3_cipher['\x00\x00'] = "TLS_EMPTY_RENEGOTIATION_INFO_SCSV"
  190. ssl3_cipher['\xc0\x01'] = "TLS_ECDH_ECDSA_WITH_NULL_SHA"
  191. ssl3_cipher['\xc0\x02'] = "TLS_ECDH_ECDSA_WITH_RC4_128_SHA"
  192. ssl3_cipher['\xc0\x03'] = "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA"
  193. ssl3_cipher['\xc0\x04'] = "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA"
  194. ssl3_cipher['\xc0\x05'] = "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA"
  195. ssl3_cipher['\xc0\x06'] = "TLS_ECDHE_ECDSA_WITH_NULL_SHA"
  196. ssl3_cipher['\xc0\x07'] = "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA"
  197. ssl3_cipher['\xc0\x08'] = "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA"
  198. ssl3_cipher['\xc0\x09'] = "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA"
  199. ssl3_cipher['\xc0\x0a'] = "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA"
  200. ssl3_cipher['\xc0\x0b'] = "TLS_ECDH_RSA_WITH_NULL_SHA"
  201. ssl3_cipher['\xc0\x0c'] = "TLS_ECDH_RSA_WITH_RC4_128_SHA"
  202. ssl3_cipher['\xc0\x0d'] = "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA"
  203. ssl3_cipher['\xc0\x0e'] = "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA"
  204. ssl3_cipher['\xc0\x0f'] = "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA"
  205. ssl3_cipher['\xc0\x10'] = "TLS_ECDHE_RSA_WITH_NULL_SHA"
  206. ssl3_cipher['\xc0\x11'] = "TLS_ECDHE_RSA_WITH_RC4_128_SHA"
  207. ssl3_cipher['\xc0\x12'] = "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA"
  208. ssl3_cipher['\xc0\x13'] = "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"
  209. ssl3_cipher['\xc0\x14'] = "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"
  210. ssl3_cipher['\xc0\x15'] = "TLS_ECDH_anon_WITH_NULL_SHA"
  211. ssl3_cipher['\xc0\x16'] = "TLS_ECDH_anon_WITH_RC4_128_SHA"
  212. ssl3_cipher['\xc0\x17'] = "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA"
  213. ssl3_cipher['\xc0\x18'] = "TLS_ECDH_anon_WITH_AES_128_CBC_SHA"
  214. ssl3_cipher['\xc0\x19'] = "TLS_ECDH_anon_WITH_AES_256_CBC_SHA"
  215. ssl3_cipher['\xC0\x1A'] = "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA"
  216. ssl3_cipher['\xC0\x1B'] = "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA"
  217. ssl3_cipher['\xC0\x1C'] = "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA"
  218. ssl3_cipher['\xC0\x1D'] = "TLS_SRP_SHA_WITH_AES_128_CBC_SHA"
  219. ssl3_cipher['\xC0\x1E'] = "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA"
  220. ssl3_cipher['\xC0\x1F'] = "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA"
  221. ssl3_cipher['\xC0\x20'] = "TLS_SRP_SHA_WITH_AES_256_CBC_SHA"
  222. ssl3_cipher['\xC0\x21'] = "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA"
  223. ssl3_cipher['\xC0\x22'] = "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA"
  224. ssl3_cipher['\xC0\x23'] = "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256"
  225. ssl3_cipher['\xC0\x24'] = "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384"
  226. ssl3_cipher['\xC0\x25'] = "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256"
  227. ssl3_cipher['\xC0\x26'] = "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384"
  228. ssl3_cipher['\xC0\x27'] = "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"
  229. ssl3_cipher['\xC0\x28'] = "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384"
  230. ssl3_cipher['\xC0\x29'] = "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256"
  231. ssl3_cipher['\xC0\x2A'] = "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384"
  232. ssl3_cipher['\xC0\x2B'] = "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"
  233. ssl3_cipher['\xC0\x2C'] = "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"
  234. ssl3_cipher['\xC0\x2D'] = "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256"
  235. ssl3_cipher['\xC0\x2E'] = "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384"
  236. ssl3_cipher['\xC0\x2F'] = "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
  237. ssl3_cipher['\xC0\x30'] = "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
  238. ssl3_cipher['\xC0\x31'] = "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256"
  239. ssl3_cipher['\xC0\x32'] = "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384"
  240. ssl3_cipher['\xC0\x33'] = "TLS_ECDHE_PSK_WITH_RC4_128_SHA"
  241. ssl3_cipher['\xC0\x34'] = "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA"
  242. ssl3_cipher['\xC0\x35'] = "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA"
  243. ssl3_cipher['\xC0\x36'] = "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA"
  244. ssl3_cipher['\xC0\x37'] = "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256"
  245. ssl3_cipher['\xC0\x38'] = "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384"
  246. ssl3_cipher['\xC0\x39'] = "TLS_ECDHE_PSK_WITH_NULL_SHA"
  247. ssl3_cipher['\xC0\x3A'] = "TLS_ECDHE_PSK_WITH_NULL_SHA256"
  248. ssl3_cipher['\xC0\x3B'] = "TLS_ECDHE_PSK_WITH_NULL_SHA384"
  249. ssl3_cipher['\xfe\xfe'] = "SSL_RSA_FIPS_WITH_DES_CBC_SHA"
  250. ssl3_cipher['\xfe\xff'] = "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA"
  251. ssl3_cipher['\xff\xe0'] = "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA"
  252. ssl3_cipher['\xff\xe1'] = "SSL_RSA_FIPS_WITH_DES_CBC_SHA"
  253.  
  254. def getSSLRecords(strBuf):
  255.     lstRecords = []
  256.     if len(strBuf)>=9:
  257.         sslStatus = struct.unpack('>BHHI', strBuf[0:9])
  258.         iType = (sslStatus[3] & (0xFF000000))>>24
  259.         iRecordLen = sslStatus[3] & (0x00FFFFFF)
  260.         iShakeProtocol = sslStatus[0]
  261.         iSSLLen = sslStatus[2]
  262.         #log(2,"iSSLLen == %d, len(strBuf) == %d, iRecordLen == %d",iSSLLen,len(strBuf),iRecordLen)
  263.         if (iRecordLen + 5 < iSSLLen):
  264.             #log(2,"Multiple Handshakes")
  265.             lstRecords.append((iShakeProtocol,iType))
  266.             iLoopStopper = 0
  267.             iNextOffset = iRecordLen + 9
  268.             while iNextOffset < len(strBuf):
  269.                 iLoopStopper += 1
  270.                 iCount = 0
  271.                 while ((iNextOffset+4) > len(strBuf) and iCount < 5):
  272.                     #log(2,"Need more data to fill buffer")
  273.                     iCount += 1
  274.                     rule.waitForData()
  275.                     if len(rule.buffer) > 0:
  276.                         strBuf += rule.buffer
  277.                 if ((iNextOffset+4) > len(strBuf)):
  278.                     #log(2,"End of message")
  279.                     break
  280.                 iTypeAndLen = struct.unpack(">I",strBuf[iNextOffset:iNextOffset+4])[0]
  281.                 iRecordLen = iTypeAndLen & (0x00FFFFFF)
  282.                 iType = (iTypeAndLen & (0xFF000000))>>24
  283.                 lstRecords.append((iShakeProtocol,iType))
  284.                 iNextOffset += (iRecordLen + 4)
  285.                 if iLoopStopper > 8:
  286.                     break
  287.             return lstRecords
  288.         elif (iRecordLen + 9 < len(strBuf)):
  289.             #log(2,"Multiple Records")
  290.             lstRecords.append((iShakeProtocol,iType))
  291.             iNextOffset = iRecordLen + 9
  292.             iLoopStopper = 0
  293.             while iNextOffset+6 < len(strBuf):
  294.                 iLoopStopper += 1
  295.                 iShakeProtocol = struct.unpack(">B",strBuf[iNextOffset])[0]
  296.                 iRecordLen = struct.unpack(">H",strBuf[iNextOffset+3:iNextOffset+5])[0]
  297.                 iType = struct.unpack(">B",strBuf[iNextOffset+5])[0]
  298.                 #log(2,"iShakeProto == %d, iRecordLen == %d, iType == %d",iShakeProtocol,iRecordLen,iType)
  299.                 lstRecords.append((iShakeProtocol,iType))
  300.                 iNextOffset += iRecordLen + 5
  301.                 if iLoopStopper > 8:
  302.                     break
  303.             return lstRecords
  304.         elif (iRecordLen + 9 == len(strBuf)):
  305.             #log(2,"Single record")
  306.             sslStatus = checkSSLHeader(strBuf)
  307.             lstRecords.append((sslStatus[0],sslStatus[2]))
  308.             return lstRecords
  309.     return None
  310.    
  311. def checkSSLHeader(strBuf):
  312.     if len(strBuf)>=6:
  313.         sslStatus = struct.unpack('>BHHI', strBuf[0:9])
  314.         iType = (sslStatus[3] & (0xFF000000))>>24
  315.         iRecordLen = sslStatus[3] & (0x00FFFFFF)
  316.         iShakeProtocol = sslStatus[0]
  317.         iSSLLen = sslStatus[2]
  318.         return (iShakeProtocol,iSSLLen,iType,iRecordLen)
  319.     return None
  320.  
  321. def makeHello(strSSLVer):
  322.     r = "\x16" # Message Type 22
  323.     r += dSSL[strSSLVer]
  324.     strCiphers = ""
  325.     for c in ssl3_cipher.keys():
  326.         strCiphers += c
  327.     dLen = 43 + len(strCiphers)
  328.     r += struct.pack("!H",dLen)
  329.     h = "\x01"
  330.     strPlen = struct.pack("!L",dLen-4)
  331.     h+=strPlen[1:]
  332.     h+= dSSL[strSSLVer]
  333.     rand = struct.pack("!L", int(time.time()))
  334.     rand += "\x36\x24\x34\x16\x27\x09\x22\x07\xd7\xbe\xef\x69\xa1\xb2"
  335.     rand += "\x37\x23\x14\x96\x27\xa9\x12\x04\xe7\xce\xff\xd9\xae\xbb"
  336.     h+=rand
  337.     h+= "\x00" # No Session ID
  338.     h+=struct.pack("!H",len(strCiphers))
  339.     h+=strCiphers
  340.     h+= "\x01\x00"
  341.     return r+h
  342.  
  343. iVulnCount = 0
  344. for strVer in ["TLSv1.2","TLSv1.1","TLSv1","SSLv3"]:
  345.     strHello = makeHello(strVer)
  346.     strLogPre = "[%s] %s:%d" % (strVer,strHost,iPort)
  347.     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  348.     try:
  349.         s.connect((strHost,iPort))
  350.         s.settimeout(5)
  351.     except:
  352.         print "Failure connecting to %s:%d." % (strHost,iPort)
  353.         quit()
  354.     s.send(strHello)
  355.     #print "Sending %s Client Hello" % (strVer)
  356.     iCount = 0
  357.     fServerHello = False
  358.     fCert = False
  359.     fKex = False
  360.     fHelloDone = False
  361.     while iCount<5:
  362.         iCount += 1
  363.         try:
  364.             recv = s.recv(2048)
  365.         except:
  366.             continue
  367.         lstRecords = getSSLRecords(recv)
  368.         #strLogMessage = "iCount = %d; lstRecords = %s" % (iCount,lstRecords)
  369.         #log(2,strLogMessage)
  370.         if lstRecords != None and len(lstRecords) > 0:
  371.             for (iShakeProtocol,iType) in lstRecords:
  372.                 if iShakeProtocol == 22:
  373.                     if iType == 2:
  374.                         fServerHello = True
  375.                     elif iType == 11:
  376.                         fCert = True
  377.                     elif iType == 12:
  378.                         fKex = True
  379.                     elif iType == 14:
  380.                         fHelloDone = True
  381.             if (fServerHello and fCert):
  382.                 break
  383.         else:
  384.             #log(2, "Handshake missing or invalid. Aborting.")
  385.             continue
  386.     if not (fServerHello and fCert):
  387.         print "%s Invalid handhsake." % (strLogPre)
  388.     elif len(recv)>0:
  389.         #print "Received %d bytes. (%d)" % (len(recv),ord(recv[0]))
  390.         if ord(recv[0])==22:
  391.             iCount = 0
  392.             strChangeCipherSpec = "\x14"
  393.             strChangeCipherSpec += dSSL[strVer]
  394.             strChangeCipherSpec += "\x00\x01" # Len
  395.             strChangeCipherSpec += "\x01" # Payload CCS
  396.             #print "Sending Change Cipher Spec"
  397.             s.send(strChangeCipherSpec)
  398.             fVuln = True
  399.             strLastMessage = ""
  400.             while iCount < 5:
  401.                 iCount += 1
  402.                 s.settimeout(0.5)
  403.                 try:
  404.                     recv = s.recv(2048)
  405.                 except socket.timeout:
  406.                     #print "Timeout waiting for CCS reply."
  407.                     continue
  408.                 except socket.error:
  409.                     print "Connection closed unexpectedly."
  410.                     fVuln=False
  411.                     break
  412.                 if (len(recv)>0):
  413.                     strLastMessage = recv
  414.                     if (ord(recv[0])==21):
  415.                         fVuln = False
  416.                         break
  417.             try:
  418.                 if ord(strLastMessage[-7]) == 21: # Check if an alert was at the end of the last message.
  419.                     fVuln=False
  420.             except IndexError:
  421.                 pass
  422.             if fVuln:
  423.                 try:
  424.                     s.send('\x15' + dSSL[strVer] + '\x00\x02\x01\x00')
  425.                     f = s.recv(1024)
  426.                     if len(f) == 0:
  427.                         fVuln = False
  428.                 except socket.error:
  429.                     fVuln = False
  430.             if fVuln:
  431.                 print "[%s] %s:%d may allow early CCS" % (strVer,strHost,iPort)
  432.                 iVulnCount += 1
  433.             else:
  434.                 print "[%s] %s:%d rejected early CCS" % (strVer,strHost,iPort)
  435.     else:
  436.         print "[%s] No response from %s:%d" % (strVer,strHost,iPort)
  437.     try:
  438.         s.close()
  439.     except:
  440.         pass
  441. if iVulnCount > 0:
  442.     print "***This System Exhibits Potentially Vulnerable Behavior***\nIf this system is using OpenSSL, it should be upgraded.\nNote: This is an experimental detection script and does not definitively determine vulnerable server status."
  443.     quit(1)
  444. else:
  445.     print "No need to patch."
  446.     quit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement