mirror of
				https://github.com/drwetter/testssl.sh.git
				synced 2025-10-30 21:35:26 +01:00 
			
		
		
		
	Last polishing to include DH groups in logjam and pfs
This commit finalizes #1139. It displays the DH groups in both run_logjam() and run_pfs() in a simlilar manner (except the FFDHE groups). A common small function pr_dh() was introduced which prints out the dh group and in round brackets colored DH bits.
This commit is contained in:
		
							
								
								
									
										75
									
								
								testssl.sh
									
									
									
									
									
								
							
							
						
						
									
										75
									
								
								testssl.sh
									
									
									
									
									
								
							| @@ -5444,6 +5444,19 @@ pr_dh_quality() { | |||||||
|      fi |      fi | ||||||
| } | } | ||||||
|  |  | ||||||
|  | # prints out dh group=prime and in round brackets DH bits and labels it accordingly | ||||||
|  | # arg1: name of dh group, arg2=bit length | ||||||
|  | pr_dh() { | ||||||
|  |      local -i quality=0 | ||||||
|  |  | ||||||
|  |      pr_italic "$1" | ||||||
|  |      out " (" | ||||||
|  |      pr_dh_quality "$2" "$2 bits" | ||||||
|  |      quality=$? | ||||||
|  |      out ")" | ||||||
|  |      return $quality | ||||||
|  | } | ||||||
|  |  | ||||||
| pr_ecdh_quality() { | pr_ecdh_quality() { | ||||||
|      local bits="$1" |      local bits="$1" | ||||||
|      local string="$2" |      local string="$2" | ||||||
| @@ -8795,8 +8808,9 @@ run_pfs() { | |||||||
|                fi |                fi | ||||||
|           fi |           fi | ||||||
|      fi |      fi | ||||||
|      if "$using_sockets" && ( "$pfs_tls13_offered" || "$ffdhe_offered" ); then |  | ||||||
|      # find out what groups are supported. |      # find out what groups are supported. | ||||||
|  |      if "$using_sockets" && ( "$pfs_tls13_offered" || "$ffdhe_offered" ); then | ||||||
|           nr_curves=0 |           nr_curves=0 | ||||||
|           for curve in "${ffdhe_groups_output[@]}"; do |           for curve in "${ffdhe_groups_output[@]}"; do | ||||||
|                supported_curve[nr_curves]=false |                supported_curve[nr_curves]=false | ||||||
| @@ -8857,26 +8871,29 @@ run_pfs() { | |||||||
|           fi |           fi | ||||||
|           if [[ -z "$curves_offered" ]] && [[ -n "$curve_found" ]]; then |           if [[ -z "$curves_offered" ]] && [[ -n "$curve_found" ]]; then | ||||||
|                # The server is not using one of the groups from RFC 7919. |                # The server is not using one of the groups from RFC 7919. | ||||||
|  |                if [[ -z "$DH_GROUP_OFFERED" ]]; then | ||||||
|  |                     # this global will get athe name of the group eithe here or in run_logjam() | ||||||
|                     key_bitstring="$(awk '/-----BEGIN PUBLIC KEY/,/-----END PUBLIC KEY/ { print $0 }' $TEMPDIR/$NODEIP.parse_tls_serverhello.txt)" |                     key_bitstring="$(awk '/-----BEGIN PUBLIC KEY/,/-----END PUBLIC KEY/ { print $0 }' $TEMPDIR/$NODEIP.parse_tls_serverhello.txt)" | ||||||
|                     get_common_prime "$jsonID" "$key_bitstring" "" |                     get_common_prime "$jsonID" "$key_bitstring" "" | ||||||
|                     [[ $? -eq 0 ]] && curves_offered="$DH_GROUP_OFFERED" && len_dh_p=$DH_GROUP_LEN_P |                     [[ $? -eq 0 ]] && curves_offered="$DH_GROUP_OFFERED" && len_dh_p=$DH_GROUP_LEN_P | ||||||
|  |                else | ||||||
|  |                     curves_offered="$DH_GROUP_OFFERED" | ||||||
|  |                     len_dh_p=$DH_GROUP_LEN_P | ||||||
|  |                fi | ||||||
|           fi |           fi | ||||||
|           if [[ -n "$curves_offered" ]]; then |           if [[ -n "$curves_offered" ]]; then | ||||||
|                if [[ ! "$curves_offered" =~ ffdhe ]] || [[ ! "$curves_offered" =~ \  ]]; then |                if [[ ! "$curves_offered" =~ ffdhe ]] || [[ ! "$curves_offered" =~ \  ]]; then | ||||||
|                     pr_bold " DH group offered:            " |                     pr_bold " DH group offered:            " | ||||||
|                else |                else | ||||||
|                     pr_bold " DH group offered:            " |                     pr_bold " Finite field group:          " | ||||||
|                fi |                fi | ||||||
|                if [[ "$curves_offered" =~ ffdhe ]]; then |                if [[ "$curves_offered" =~ ffdhe ]]; then | ||||||
|                     # ok not to display them in italics: |                     # ok not to display them in italics: | ||||||
|                     pr_svrty_good "$curves_offered" |                     pr_svrty_good "$curves_offered" | ||||||
|                     quality=6 |                     quality=6 | ||||||
|                else |                else | ||||||
|                     pr_italic "$curves_offered" |                     pr_dh "$curves_offered" "$len_dh_p" | ||||||
|                     out " (" |  | ||||||
|                     pr_dh_quality "$len_dh_p" "$len_dh_p bits" |  | ||||||
|                     quality=$? |                     quality=$? | ||||||
|                     out ")" |  | ||||||
|                fi |                fi | ||||||
|                case "$quality" in |                case "$quality" in | ||||||
|                     1) quality_str="CRITICAL" ;; |                     1) quality_str="CRITICAL" ;; | ||||||
| @@ -13919,33 +13936,37 @@ get_common_prime() { | |||||||
|      fi |      fi | ||||||
| } | } | ||||||
|  |  | ||||||
| # helper function for run_logjam, see below |  | ||||||
|  | # helper function for run_logjam see below | ||||||
| # | # | ||||||
| out_common_prime() { | out_common_prime() { | ||||||
|      local jsonID2="$1" |      local jsonID2="$1" | ||||||
|      local cve="$2" |      local cve="$2" | ||||||
|      local cwe="$3" |      local cwe="$3" | ||||||
|  |  | ||||||
|      # now size matters -- i.e. the bit size ;-) |      if [[ "$DH_GROUP_OFFERED" =~ ffdhe ]]; then | ||||||
|      [[ "$DH_GROUP_OFFERED" == ffdhe* ]] && [[ ! "$DH_GROUP_OFFERED" =~ \  ]] && DH_GROUP_OFFERED="RFC7919/$DH_GROUP_OFFERED" |           : | ||||||
|      if [[ "$DH_GROUP_OFFERED" =~ ffdhe ]] && [[ "$DH_GROUP_OFFERED" =~ \  ]]; then |      # now size matters -- i.e. the bit size. As this is about a known prime we label it more strict. | ||||||
|           out "common primes detected: "; pr_italic "$DH_GROUP_OFFERED" |      # This needs maybe needs a another thought as it could appear inconsitent with run_pfs and elsewhere. | ||||||
|           fileout "$jsonID2" "INFO" "$DH_GROUP_OFFERED" "$cve" "$cwe" |      # for now we label the bit size similar in the screen, but distiguish the leading text for logjam before | ||||||
|      elif [[ $DH_GROUP_LEN_P -le 512 ]]; then |      elif [[ $DH_GROUP_LEN_P -le 800 ]]; then | ||||||
|           pr_svrty_critical "VULNERABLE (NOT ok):"; out " common prime "; pr_italic "$DH_GROUP_OFFERED"; out " detected ($DH_GROUP_LEN_P bits)" |           pr_svrty_critical "VULNERABLE (NOT ok):"; out " common prime: " | ||||||
|           fileout "$jsonID2" "CRITICAL" "$DH_GROUP_OFFERED" "$cve" "$cwe" |           fileout "$jsonID2" "CRITICAL" "$DH_GROUP_OFFERED" "$cve" "$cwe" | ||||||
|  |           pr_dh "$DH_GROUP_OFFERED" $DH_GROUP_LEN_P | ||||||
|      elif [[ $DH_GROUP_LEN_P -le 1024 ]]; then |      elif [[ $DH_GROUP_LEN_P -le 1024 ]]; then | ||||||
|           pr_svrty_high "VULNERABLE (NOT ok):"; out " common prime "; pr_italic "$DH_GROUP_OFFERED"; out " detected ($DH_GROUP_LEN_P bits)" |           # really? Here we assume that 1024bit common prime for nation states are worth and possible to precompute (TBC) | ||||||
|  |           # otherwise 1024 are just medium | ||||||
|  |           pr_svrty_high "VULNERABLE (NOT ok):"; out " common prime: " | ||||||
|           fileout "$jsonID2" "HIGH" "$DH_GROUP_OFFERED" "$cve" "$cwe" |           fileout "$jsonID2" "HIGH" "$DH_GROUP_OFFERED" "$cve" "$cwe" | ||||||
|  |           pr_dh "$DH_GROUP_OFFERED" $DH_GROUP_LEN_P | ||||||
|      elif [[ $DH_GROUP_LEN_P -le 1536 ]]; then |      elif [[ $DH_GROUP_LEN_P -le 1536 ]]; then | ||||||
|           pr_svrty_medium "common prime with $DH_GROUP_LEN_P bits detected: "; pr_italic "$DH_GROUP_OFFERED" |           pr_svrty_low "common prime: " | ||||||
|           fileout "$jsonID2" "MEDIUM" "$DH_GROUP_OFFERED" "$cve" "$cwe" |  | ||||||
|      elif [[ $DH_GROUP_LEN_P -lt 2048 ]]; then |  | ||||||
|           pr_svrty_low "common prime with $DH_GROUP_LEN_P bits detected: "; pr_italic "$DH_GROUP_OFFERED" |  | ||||||
|           fileout "$jsonID2" "LOW" "$DH_GROUP_OFFERED" "$cve" "$cwe" |           fileout "$jsonID2" "LOW" "$DH_GROUP_OFFERED" "$cve" "$cwe" | ||||||
|  |           pr_dh "$DH_GROUP_OFFERED" $DH_GROUP_LEN_P | ||||||
|      else |      else | ||||||
|           out "common prime with $DH_GROUP_LEN_P bits detected: "; pr_italic "$DH_GROUP_OFFERED" |           out "common prime with $DH_GROUP_LEN_P bits detected: " | ||||||
|           fileout "$jsonID2" "INFO" "$DH_GROUP_OFFERED" "$cve" "$cwe" |           fileout "$jsonID2" "INFO" "$DH_GROUP_OFFERED" "$cve" "$cwe" | ||||||
|  |           pr_dh "$DH_GROUP_OFFERED" $DH_GROUP_LEN_P | ||||||
|      fi |      fi | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -14105,13 +14126,25 @@ run_logjam() { | |||||||
|           elif [[ $subret -eq 0 ]]; then |           elif [[ $subret -eq 0 ]]; then | ||||||
|                pr_svrty_good "not vulnerable (OK):"; out " no DH EXPORT ciphers${addtl_warning}" |                pr_svrty_good "not vulnerable (OK):"; out " no DH EXPORT ciphers${addtl_warning}" | ||||||
|                fileout "$jsonID" "OK" "not vulnerable, no DH EXPORT ciphers,$addtl_warning" "$cve" "$cwe" |                fileout "$jsonID" "OK" "not vulnerable, no DH EXPORT ciphers,$addtl_warning" "$cve" "$cwe" | ||||||
|                out ", no common primes detected" |                # we issue a special warning if there's no common prime but the bit length is too low | ||||||
|  |                if [[ $DH_GROUP_LEN_P -le 1024 ]]; then | ||||||
|  |                     out "\n${spaces}But: " | ||||||
|  |                     pr_dh "$DH_GROUP_OFFERED" $DH_GROUP_LEN_P | ||||||
|  |                     case $? in | ||||||
|  |                          1) fileout "$jsonID" "CRITICAL" "no DH EXPORT ciphers, no common prime but $DH_GROUP_OFFERED has only $DH_GROUP_LEN_P bits,  $addtl_warning" "$cve" "$cwe" ;; | ||||||
|  |                          2) fileout "$jsonID" "HIGH" "no DH EXPORT ciphers, no common prime but $DH_GROUP_OFFERED has only $DH_GROUP_LEN_P bits,  $addtl_warning" "$cve" "$cwe";; | ||||||
|  |                          3) fileout "$jsonID" "MEDIUM" "no DH EXPORT ciphers, no common prime but $DH_GROUP_OFFERED has only $DH_GROUP_LEN_P bits,  $addtl_warning" "$cve" "$cwe";; | ||||||
|  |                     esac | ||||||
|  |                else | ||||||
|  |                     out ", no common prime detected" | ||||||
|                     fileout "$jsonID2" "OK" "--" "$cve" "$cwe" |                     fileout "$jsonID2" "OK" "--" "$cve" "$cwe" | ||||||
|  |                fi | ||||||
|           elif [[ $ret -eq 1 ]]; then |           elif [[ $ret -eq 1 ]]; then | ||||||
|                pr_svrty_good "partly not vulnerable:"; out " no DH EXPORT ciphers${addtl_warning}" |                pr_svrty_good "partly not vulnerable:"; out " no DH EXPORT ciphers${addtl_warning}" | ||||||
|                fileout "$jsonID" "OK" "not vulnerable, no DH EXPORT ciphers,$addtl_warning" "$cve" "$cwe" |                fileout "$jsonID" "OK" "not vulnerable, no DH EXPORT ciphers,$addtl_warning" "$cve" "$cwe" | ||||||
|           fi |           fi | ||||||
|      fi |      fi | ||||||
|  |  | ||||||
|      outln |      outln | ||||||
|      tmpfile_handle ${FUNCNAME[0]}.txt |      tmpfile_handle ${FUNCNAME[0]}.txt | ||||||
|      return $ret |      return $ret | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Dirk
					Dirk