"""
   The MIT License (MIT)

   Copyright (C) 2017-2026 Joe Testa (jtesta@positronsecurity.com)

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE.
"""
# The version to display.
VERSION = 'v3.9.0'

# SSH software to impersonate
SSH_HEADER = 'SSH-{0}-OpenSSH_10.3'

# The URL to the Github issues tracker.
GITHUB_ISSUES_URL = 'https://github.com/jtesta/ssh-audit/issues'

# The man page.  Only filled in on Docker, PyPI, Snap, and Windows builds.

# True when installed from a Snap package, otherwise False.
SNAP_PACKAGE = False

# Error message when installed as a Snap package and a file access fails.
SNAP_PERMISSIONS_ERROR = 'Error while accessing file.  It appears that ssh-audit was installed as a Snap package.  In that case, there are two options:  1.) only try to read & write files in the $HOME/snap/ssh-audit/common/ directory, or 2.) grant permissions to read & write files in $HOME using the following command: "sudo snap connect ssh-audit:home :home"'
BUILTIN_MAN_PAGE = """
[4mSSH-AUDIT[24m(1)                General Commands Manual                [4mSSH-AUDIT[24m(1)

[1mNAME[0m
       [1mssh-audit [22m- SSH server & client configuration auditor

[1mSYNOPSIS[0m
       [1mssh-audit [22m[[4moptions[24m] [4m<target_host>[0m

[1mDESCRIPTION[0m
       [1mssh-audit  [22manalyzes  the  configuration  of  SSH servers & clients, then
       warns the user of weak, obsolete, and/or untested  cryptographic  primi-
       tives.   It  is  very useful for hardening SSH tunnels, which by default
       tend to be optimized for compatibility, not security.

       See <https://www.ssh-audit.com/> for official hardening guides for  com-
       mon platforms.

[1mOPTIONS[0m
       [1m-h, --help[0m
              Print short summary of options.

       [1m-4, --ipv4[0m
              Prioritize the usage of IPv4.

       [1m-6, --ipv6[0m
              Prioritize the usage of IPv6.

       [1m-b, --batch[0m
              Enables grepable output.

       [1m-c, --client-audit[0m
              Starts  a server on port 2222 to audit client software configura-
              tion.   Use  -p/--port=<port>  to  change  port  and   -t/--time-
              out=<secs> to change listen timeout.

       [1m--conn-rate-test=N[:max_rate][0m
              Performs  a  connection  rate test (useful for collecting metrics
              related   to   susceptibility   of   the   DHEat    vulnerability
              [CVE-2002-20001]).   A  successful connection is counted when the
              server returns a valid SSH banner.  Testing is conducted  with  N
              concurrent  sockets  with an optional maximum rate of connections
              per second.

       [1m-d, --debug[0m
              Enable debug output.

       [1m--dheat=N[:kex[:e_len]][0m
              Run the DHEat DoS  attack  (CVE-2002-20001)  against  the  target
              server  (which  will  consume  all available CPU resources).  The
              number of concurrent sockets, N, needed to  achieve  this  effect
              will  be  highly  dependent on the CPU resources available on the
              target, as well as the latency between the source and target  ma-
              chines.   The key exchange is automatically chosen based on which
              would cause maximum effect, unless explicitly chosen in the  sec-
              ond field.  Lastly, an (experimental) option allows the length in
              bytes  of  the fake e value sent to the server to be specified in
              the third field.  Normally, the length of e is roughly the length
              of the modulus of the Diffie-Hellman exchange (hence, an 8192-bit
              / 1024-byte value of e is sent in each connection when  targeting
              the  diffie-hellman-group18-sha512  algorithm).   Instead, it was
              observed that many SSH implementations accept small values,  such
              as 4 bytes; this results in a much more network-efficient attack.

       [1m--get-hardening-guide=<platform_name>[0m
              Retrieves  the  hardening  guide  for the specified platform name
              (use --list-hardening-guides to see list of available guides).

       [1m-g, --gex-test=<x[,y,...] | min1:pref1:max1[,min2:pref2:max2,...] | x-[0m
       [1my[:step]>[0m
              Runs a Diffie-Hellman Group Exchange modulus size test against  a
              server.

              Diffie-Hellman  requires the client and server to agree on a gen-
              erator value and a modulus value.  In the "Group Exchange" imple-
              mentation of Diffie-Hellman, the client specifies the size of the
              modulus in bits by providing the server with  minimum,  preferred
              and  maximum  values.  The  server  then  finds a group that best
              matches the client's request, returning the corresponding genera-
              tor and modulus.  For a full explanation of this process see  RFC
              4419 and its successors.

              This  test  acts  as a client by providing an SSH server with the
              size of a modulus and then obtains the size of  the  modulus  re-
              turned by the server.

              Three types of syntax are supported:

                1. <x[,y,...]>

                   A comma delimited list of modulus sizes.
                   A  test is performed against each value in the list where it
              acts as the minimum, preferred and maximum modulus size.

                2. <min:pref:max[,min:pref:max,...]>

                   A set of three colon delimited values denoting minimum, pre-
              ferred and maximum modulus size.
                   A test is performed against each set.
                   Multiple sets can specified as a comma separated list.

                3. <x-y[:step]>

                   A range of modulus sizes with an optional step  value.  Step
              defaults to 1 if omitted.
                   If  the left value is greater than the right value, then the
              sequence operates from right to left.
                   A test is performed against each value in the range where it
              acts as the minimum, preferred and maximum modulus size.

              Duplicates are excluded from the return value.

       [1m-j, --json[0m
              Output results in JSON format.  Specify twice (-jj) to enable in-
              dent printing (useful for debugging).

       [1m-l, --level=<info|warn|fail>[0m
              Specify the minimum output level.  Default is info.

       [1m--list-hardening-guides[0m
              List all official, built-in hardening guides for common  systems.
              Their  full  names  can  then be passed to --get-hardening-guide.
              Add -v to this option to view hardening  guide  change  logs  and
              prior versions.

       [1m-L, --list-policies[0m
              List  all  official, built-in policies for common systems.  Their
              full names can then be passed to -P/--policy.  Add -v  to  -L  to
              view policy change logs.

       [1m--lookup=<alg1,alg2,...>[0m
              Look up the security information of an algorithm(s) in the inter-
              nal database.  Does not connect to a server.

       [1m-m, --manual[0m
              Print the man page (Docker, PyPI, Snap, and Windows builds only).

       [1m-M, --make-policy=<custom_policy.txt>[0m
              Creates  a  policy based on the target server.  Useful when other
              servers should be compared to the target server's custom configu-
              ration (i.e.: a cluster environment).  Note  that  the  resulting
              policy can be edited manually.

       [1m-n, --no-colors[0m
              Disable  color output.  Automatically set when the NO_COLOR envi-
              ronment variable is set.

       [1m-p, --port=<port>[0m
              The TCP port to connect to when auditing a server, or the port to
              listen on when auditing a client.

       [1m-P, --policy=<"built-in policy name" | path/to/custom_policy.txt>[0m
              Runs a policy audit against a target using the  specified  policy
              (see  [1mPOLICY  AUDIT [22msection for detailed description of this mode
              of operation).  Combine with -c/--client-audit to audit a  client
              configuration  instead  of  a  server.  Use -L/--list-policies to
              list all official, built-in policies for common systems.

       [1m--skip-rate-test[0m
              Skips the connection rate test during standard  audits.   By  de-
              fault,  a  few  dozen TCP connections are created with the target
              host to see if connection throttling  is  implemented  (this  can
              safely  infer  whether  the target is vulnerable to the DHEat at-
              tack; see CVE-2002-20001).

       [1m--socks5 host:port[0m
              Connects through a SOCKS5 proxy.  Rate  tests  are  automatically
              skipped (i.e.: implies --skip-rate-test).

       [1m-t, --timeout=<secs>[0m
              The  timeout,  in  seconds,  for creating connections and reading
              data from the socket.  Default is 5.

       [1m-T, --targets=<hosts.txt>[0m
              A file containing a list of target hosts.  Each  line  must  have
              one  host, in the format of HOST[:PORT] (or for UNIX sockets, use
              "unix://path/to/socket").  Use -p/--port to set the default  port
              for all hosts.  Use --threads to control concurrent scans.

       [1m--threads=<threads>[0m
              The number of threads to use when scanning multiple targets (with
              -T/--targets).  Default is 32.

       [1m-v, --verbose[0m
              Enable verbose output.

[1mSTANDARD AUDIT[0m
       By default, [1mssh-audit [22mperforms a standard audit.  That is, it enumerates
       all host key types, key exchanges, ciphers, MACs, and other information,
       then  color-codes  them in output to the user.  Cryptographic primitives
       with potential issues are displayed in yellow; primitives  with  serious
       flaws are displayed in red.

[1mPOLICY AUDIT[0m
       When  the -P/--policy option is used, [1mssh-audit [22mperforms a policy audit.
       The target's host key types, key exchanges, ciphers, MACs, and other in-
       formation is compared to a set of expected values defined in the  speci-
       fied policy file.  If everything matches, only a short message stating a
       passing  result is reported.  Otherwise, the field(s) that did not match
       are reported.

       Policy auditing is helpful for ensuring a group of related  servers  are
       properly hardened to an exact specification.

       The set of official built-in policies can be viewed with -L/--list-poli-
       cies.   Multiple servers can be audited with -T/--targets=<servers.txt>.
       Custom policies can be made from an ideal target server with  -M/--make-
       policy=<custom_policy.txt>.

[1mEXAMPLES[0m
       Basic server auditing:
              ssh-audit localhost
              ssh-audit 127.0.0.1
              ssh-audit 127.0.0.1:222
              ssh-audit ::1
              ssh-audit [::1]:222
              ssh-audit unix:///run/ssh-unix-local/socket

       To  run  a  standard  audit  against  many  servers  (place targets into
       servers.txt, one on each line in the format of HOST[:PORT]):
              ssh-audit -T servers.txt

       To audit a client configuration (listens on port 2222 by  default;  con-
       nect using "ssh -p 2222 anything@localhost"):
              ssh-audit -c

       To audit a client configuration, with a listener on port 4567:
              ssh-audit -c -p 4567

       To  list all official built-in policies (hint: use their full names with
       -P/--policy):
              ssh-audit -L

       To run a built-in policy audit against a server (hint:  use  -L  to  see
       list of built-in policies):
              ssh-audit -P "Hardened Ubuntu Server 20.04 LTS (version 1)" targetserver

       To  run a custom policy audit against a server (hint: use -M/--make-pol-
       icy to create a custom policy file):
              ssh-audit -P path/to/server_policy.txt targetserver

       To run a policy audit against a client:
              ssh-audit -c -P ["policy name" | path/to/client_policy.txt]

       To run a policy audit against many servers:
              ssh-audit -T servers.txt -P ["policy name" | path/to/server_policy.txt]

       To create a policy based on a  target  server  (which  can  be  manually
       edited; see official built-in policies for syntax examples):
              ssh-audit -M new_policy.txt targetserver

       To  run a Diffie-Hellman Group Exchange modulus size test using the val-
       ues 2000 bits, 3000 bits, 4000 bits and 5000 bits:
              ssh-audit targetserver --gex-test=2000,3000,4000,5000

       To run a Diffie-Hellman Group Exchange modulus size test where 2048 bits
       is the minimum, 3072 bits is the preferred and 5000 bits is the maximum:
              ssh-audit targetserver --gex-test=2048:3072:5000

       To run a Diffie-Hellman Group Exchange modulus size test from 0 bits  to
       5120 bits in increments of 1024 bits:
              ssh-audit targetserver --gex-test=0-5120:1024

       To  run  the  DHEat DoS attack (monitor the target server's CPU usage to
       determine the optimal number of concurrent sockets):
              ssh-audit targetserver --dheat=10

       To run the DHEat attack and manually target the diffie-hellman-group-ex-
       change-sha256 algorithm:
              ssh-audit targetserver --dheat=10:diffie-hellman-group-exchange-sha256

       To run the DHEat attack and manually target the diffie-hellman-group-ex-
       change-sha256 algorithm with a very small length of e (resulting in  the
       same effect but without having to send large packets):
              ssh-audit targetserver --dheat=10:diffie-hellman-group-exchange-sha256:4

       To test the number of successful connections per second that can be cre-
       ated  with  the  target  using  8 parallel threads (useful for detecting
       whether connection throttling is implemented by the target):
              ssh-audit targetserver --conn-rate-test=8

       To use 8 parallel threads to create up to  100  connections  per  second
       with the target (useful for understanding how much CPU load is caused on
       the  target simply from handling new connections vs excess modular expo-
       nentiation when performing the DHEat attack):
              ssh-audit targetserver --conn-rate-test=8:100

[1mRETURN VALUES[0m
       When a successful connection is made and all  algorithms  are  rated  as
       "good", [1mssh-audit [22mreturns 0.  Other possible return values are:

              1 = connection error
              2 = at least one algorithm warning was found
              3 = at least one algorithm failure was found
              <any other non-zero value> = unknown error

[1mSSH HARDENING GUIDES[0m
       Hardening    guides    for   common   platforms   can   be   found   at:
       <https://www.ssh-audit.com/>

[1mBUG REPORTS[0m
       Please    file    bug    reports    as    a     Github     Issue     at:
       <https://github.com/jtesta/ssh-audit/issues>

[1mAUTHOR[0m
       [1mssh-audit  [22mwas  originally written by Andris Raugulis <moo@arthepsy.eu>,
       and maintained from 2015 to 2017.

       Maintainership was assumed and development was resumed in  2017  by  Joe
       Testa <jtesta@positronsecurity.com>.

                                 June 20, 2026                     [4mSSH-AUDIT[24m(1)
"""
