master 048a8a7e4c9a cached
11 files
336.4 KB
102.5k tokens
1 requests
Download .txt
Showing preview only (349K chars total). Download the full file or copy to clipboard to get everything.
Repository: chroblert/SecurityBaselineCheck
Branch: master
Commit: 048a8a7e4c9a
Files: 11
Total size: 336.4 KB

Directory structure:
gitextract_nnm6_la9/

├── .gitattributes
├── LICENSE
├── README/
│   └── 77766a601331a6c9ef597b778706fd9c.png-quanzi
├── README.md
├── baseline_check_JC0o0l.sh
├── baseline_check_v2.1_JC0o0l.sh
├── baseline_check_v2.2_JC0o0l.sh
├── baseline_check_v2_JC0o0l.sh
├── linux_baseline_check.sh
├── sec.inf
└── win2012_baseline_check.ps1

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitattributes
================================================
# Auto detect text files and perform LF normalization
* text=auto


================================================
FILE: LICENSE
================================================
GNU GENERAL PUBLIC LICENSE
                       Version 3, 29 June 2007

 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

                            Preamble

  The GNU General Public License is a free, copyleft license for
software and other kinds of works.

  The licenses for most software and other practical works are designed
to take away your freedom to share and change the works.  By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.  We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors.  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.

  To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights.  Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received.  You must make sure that they, too, receive
or can get the source code.  And you must show them these terms so they
know their rights.

  Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.

  For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software.  For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.

  Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so.  This is fundamentally incompatible with the aim of
protecting users' freedom to change the software.  The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable.  Therefore, we
have designed this version of the GPL to prohibit the practice for those
products.  If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.

  Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary.  To prevent this, the GPL assures that
patents cannot be used to render the program non-free.

  The precise terms and conditions for copying, distribution and
modification follow.

                       TERMS AND CONDITIONS

  0. Definitions.

  "This License" refers to version 3 of the GNU General Public License.

  "Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.

  "The Program" refers to any copyrightable work licensed under this
License.  Each licensee is addressed as "you".  "Licensees" and
"recipients" may be individuals or organizations.

  To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy.  The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.

  A "covered work" means either the unmodified Program or a work based
on the Program.

  To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy.  Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.

  To "convey" a work means any kind of propagation that enables other
parties to make or receive copies.  Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.

  An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License.  If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.

  1. Source Code.

  The "source code" for a work means the preferred form of the work
for making modifications to it.  "Object code" means any non-source
form of a work.

  A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.

  The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form.  A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.

  The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities.  However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work.  For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.

  The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.

  The Corresponding Source for a work in source code form is that
same work.

  2. Basic Permissions.

  All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met.  This License explicitly affirms your unlimited
permission to run the unmodified Program.  The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work.  This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.

  You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force.  You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright.  Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.

  Conveying under any other circumstances is permitted solely under
the conditions stated below.  Sublicensing is not allowed; section 10
makes it unnecessary.

  3. Protecting Users' Legal Rights From Anti-Circumvention Law.

  No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.

  When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.

  4. Conveying Verbatim Copies.

  You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.

  You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.

  5. Conveying Modified Source Versions.

  You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:

    a) The work must carry prominent notices stating that you modified
    it, and giving a relevant date.

    b) The work must carry prominent notices stating that it is
    released under this License and any conditions added under section
    7.  This requirement modifies the requirement in section 4 to
    "keep intact all notices".

    c) You must license the entire work, as a whole, under this
    License to anyone who comes into possession of a copy.  This
    License will therefore apply, along with any applicable section 7
    additional terms, to the whole of the work, and all its parts,
    regardless of how they are packaged.  This License gives no
    permission to license the work in any other way, but it does not
    invalidate such permission if you have separately received it.

    d) If the work has interactive user interfaces, each must display
    Appropriate Legal Notices; however, if the Program has interactive
    interfaces that do not display Appropriate Legal Notices, your
    work need not make them do so.

  A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit.  Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.

  6. Conveying Non-Source Forms.

  You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:

    a) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by the
    Corresponding Source fixed on a durable physical medium
    customarily used for software interchange.

    b) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by a
    written offer, valid for at least three years and valid for as
    long as you offer spare parts or customer support for that product
    model, to give anyone who possesses the object code either (1) a
    copy of the Corresponding Source for all the software in the
    product that is covered by this License, on a durable physical
    medium customarily used for software interchange, for a price no
    more than your reasonable cost of physically performing this
    conveying of source, or (2) access to copy the
    Corresponding Source from a network server at no charge.

    c) Convey individual copies of the object code with a copy of the
    written offer to provide the Corresponding Source.  This
    alternative is allowed only occasionally and noncommercially, and
    only if you received the object code with such an offer, in accord
    with subsection 6b.

    d) Convey the object code by offering access from a designated
    place (gratis or for a charge), and offer equivalent access to the
    Corresponding Source in the same way through the same place at no
    further charge.  You need not require recipients to copy the
    Corresponding Source along with the object code.  If the place to
    copy the object code is a network server, the Corresponding Source
    may be on a different server (operated by you or a third party)
    that supports equivalent copying facilities, provided you maintain
    clear directions next to the object code saying where to find the
    Corresponding Source.  Regardless of what server hosts the
    Corresponding Source, you remain obligated to ensure that it is
    available for as long as needed to satisfy these requirements.

    e) Convey the object code using peer-to-peer transmission, provided
    you inform other peers where the object code and Corresponding
    Source of the work are being offered to the general public at no
    charge under subsection 6d.

  A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.

  A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling.  In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage.  For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product.  A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.

  "Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source.  The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.

  If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information.  But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).

  The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed.  Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.

  Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.

  7. Additional Terms.

  "Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law.  If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.

  When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it.  (Additional permissions may be written to require their own
removal in certain cases when you modify the work.)  You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.

  Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:

    a) Disclaiming warranty or limiting liability differently from the
    terms of sections 15 and 16 of this License; or

    b) Requiring preservation of specified reasonable legal notices or
    author attributions in that material or in the Appropriate Legal
    Notices displayed by works containing it; or

    c) Prohibiting misrepresentation of the origin of that material, or
    requiring that modified versions of such material be marked in
    reasonable ways as different from the original version; or

    d) Limiting the use for publicity purposes of names of licensors or
    authors of the material; or

    e) Declining to grant rights under trademark law for use of some
    trade names, trademarks, or service marks; or

    f) Requiring indemnification of licensors and authors of that
    material by anyone who conveys the material (or modified versions of
    it) with contractual assumptions of liability to the recipient, for
    any liability that these contractual assumptions directly impose on
    those licensors and authors.

  All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10.  If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term.  If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.

  If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.

  Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.

  8. Termination.

  You may not propagate or modify a covered work except as expressly
provided under this License.  Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).

  However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.

  Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.

  Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License.  If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.

  9. Acceptance Not Required for Having Copies.

  You are not required to accept this License in order to receive or
run a copy of the Program.  Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance.  However,
nothing other than this License grants you permission to propagate or
modify any covered work.  These actions infringe copyright if you do
not accept this License.  Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.

  10. Automatic Licensing of Downstream Recipients.

  Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License.  You are not responsible
for enforcing compliance by third parties with this License.

  An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations.  If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.

  You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License.  For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.

  11. Patents.

  A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based.  The
work thus licensed is called the contributor's "contributor version".

  A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version.  For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.

  Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.

  In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement).  To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.

  If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients.  "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.

  If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.

  A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License.  You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.

  Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.

  12. No Surrender of Others' Freedom.

  If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all.  For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.

  13. Use with the GNU Affero General Public License.

  Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work.  The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.

  14. Revised Versions of this License.

  The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

  Each version is given a distinguishing version number.  If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation.  If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.

  If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.

  Later license versions may give you additional or different
permissions.  However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.

  15. Disclaimer of Warranty.

  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

  16. Limitation of Liability.

  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.

  17. Interpretation of Sections 15 and 16.

  If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.

                     END OF TERMS AND CONDITIONS

            How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

  If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

    <program>  Copyright (C) <year>  <name of author>
    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License.  Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".

  You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.

  The GNU General Public License does not permit incorporating your program
into proprietary programs.  If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library.  If this is what you want to do, use the GNU Lesser General
Public License instead of this License.  But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.


================================================
FILE: README.md
================================================
# SecurityBaselineCheck

[<h1>脚本请到AssetManage项目下的Agent目录下去下载<h1>](https://github.com/chroblert/AssetManage/tree/master/Agent)

## 0x01 介绍

这个项目准备打造一个安全基线检查平台,期望能够以最简单的方式在需要进行检查的服务器上运行。能够达到这么一种效果:基线检查脚本(以后称之为agent)可以单独在目标服务器上运行,并展示出相应不符合基线的地方,并且可以将检查时搜集到的信息以json串的形式上传到后端处理服务器上,后端服务器可以进行统计并进行可视化展示。

Agent用到的技术:

- Shell脚本
- Powershell脚本

后端服务器用到的技术:

- python
- django
- bootstrap
- html

存储所用:

- sqlite3

Linux Agent:

![img](README/77766a601331a6c9ef597b778706fd9c.png-quanzi)

Windows Agent:

![1578038482637](README/1578038482637.png)

后端:

基线扫描记录:

![1578447807497](README/1578447807497.png)

基线扫描详情与检查结果:

![1578447840658](README/1578447840658.png)

## 0x02 项目进展

- 20191215 根据CIS制定Centos7检查基线
- 20191228 发布LinuxAgent v1.0
  - 只能本地运行展示结果,无法上传JSON串
  - 只能对Centos7系统进行基线检查
- 20191230 更新LinuxAgent v2.0
  - 重构代码,增加上传JSON串功能
- 20191231 根据CIS制定Window2012检查基线
- 20200103 发布WindowsAgent v1.0
  - 只能在本地运行,无法上传JSON串
- 20200105 发布WindowsAgent v2.0
  - 修改部分代码
  - 可以上传json串
- 20200108 更新AssetManage
  - 增加Windows基线检查图形展示界面
- 20200110 更新AssetManage,更新Linux基线检查脚本
  - 增加完善Linux基线检查图形展示界面
- 20200113 发布后端图形展示界面 
  - 后端展示界面源代码位于:`github.com/chroblert/assetmanage`
  - 后端展示界面docker镜像位于:

## 0x03 使用步骤

1\. 下载AssetManage这个后端展示项目,

源码地址位于:[AssetManage](https://github.com/chroblert/AssetManage)

docker镜像位于:`registry.cn-hangzhou.aliyuncs.com/jc0o0l/assetmanage:2.0`

```shell
# 提前安装最新版SQLite3.30,python3.6
# git clone项目
git clone https://github.com/chroblert/assetmanage.git
cd AssetManage
# 使用python3安装依赖包
python3 -m pip install -r requirements
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py runserver 0.0.0.0:8888
# 假定该服务器的IP未112.112.112.112
```

2\. 更改agent中后端服务器的ip和端口为上一步中服务器的IP`112.112.112.112`和端口`8888`

**对于Windows:**

![1578895428321](README/1578895428321.png)

**对于Linux:**

![1578895474191](README/1578895474191.png)

3\. 将Agent拖到要进行基线检查的服务器上,以管理员权限运行agent

4\. 访问后端服务器可视化展示界面:`http://112.112.112.112:8888`,

**点击基线检查,查看扫描记录**

![1578447807497](README/1578447807497.png)

**点击`Click Me`查看检查结果**

![1578447840658](README/1578447840658.png)

最后,希望大家多多关注下`信安札记`,给点支持@~@

![大佬关注个公众号吧](README/qrcode_for_gh_fd932f67cd7f_258.jpg)

---

参考资料:[在Django 2.2中启动开发服务器时处理SQLite3错误](https://cloud.tencent.com/developer/article/1439327)


================================================
FILE: baseline_check_JC0o0l.sh
================================================
#!/bin/bash
function get_ip_info {
    local ipList=`ifconfig | grep inet |grep -v inet6|grep -v 127|sed 's/^[ ]*//g'|cut -d" " -f2`
    echo $ipList
}
function get_basic_info {
    echo [·] collect basic info
    hostname=`hostname`
    ipList=`get_ip_info`
    kernelVersion=`uname -r`
    if [[ $(cat /proc/version) =~ "Red Hat" ]]; then
        osVersion=`cat /etc/redhat-release|cut -f1,4 -d" "`
    fi
    basic_info={\"hostname\":\"$hostname\",\"ipList\":\"$ipList\",\"kernelVersion\":\"$kernelVersion\",\"osVersion\":\"$osVersion\"}
    echo -e "\033[32m$basic_info \033[0m"
}

function init_check {
    # 1. init configuration
    echo [·] check init configuration
    # 1.1 file system configuration
    # 1.1.1 /tmp separate mount
    mount|grep /tmp |while read res;do
    if [[ -z $res ]]; then
        echo -e "\033[31m[-] /tmp/ not mounted on separate dick\033[0m"
    # 1.1.2 /tmp noexec nosuid
    elif [[ ! $res =~ "noexec" ]];then
        echo -e "\033[31m[-] no noexec option on /tmp partion\033[0m"
        if [[ ! $res =~ "nosuid" ]];then
            echo -e "\033[31m[-] no nosuid option on /tmp partion\033[0m"
        fi
    elif [[ ! $res =~ "nosuid" ]];then
        echo -e "\033[31m[-] no nosuid option on /tmp partion\033[0m"
    fi
    done
    # 1.2 secure boot configuration
    # 1.2.1 /boot/grub2/grub.cfg permission /boot/grub2/user.cfg permission 0600 root:root
    if [[ -f /boot/grub2/grub.cfg ]];then
        res=`stat /boot/grub2/grub.cfg |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4`
        if [[ `echo $res|cut -d"/" -f1` = "0600" ]]; then
            echo -e "\033[32m[+] /boot/grub2/grub.cfg permission is 0600 \033[0m"
        else
            echo -e "\033[31m[-] /boot/grub2/grub.cfg permission is not 0600 \033[0m"
        fi
    fi
    # 1.2.2 Ensure bootloader password is set
    if [[ -f /boot/grub2/grub.cfg ]];then
        res=`grep "^GRUB2 PASSWORD" /boot/grub2/grub.cfg`
        if [[ -n $res ]]; then
            echo -e "\033[32m[+] /boot/grub2/grub.cfg seted password \033[0m"
        else
            echo -e "\033[31m[-] /boot/grub2/grub.cfg not set password \033[0m"
        fi
        
    fi
    # 1.2.3 single user mode need authentication
    if [[ -f /usr/lib/systemd/system/rescue.service ]] && [[ -f /usr/lib/systemd/system/emergency.service ]]; then
        res1=`grep /sbin/sulogin /usr/lib/systemd/system/rescue.service`
        res2=`grep /sbin/sulogin /usr/lib/systemd/system/emergency.service`
        if [[ $res1 = "ExecStart=-/bin/sh -c \"/usr/sbin/sulogin; /usr/bin/systemctl --fail --no-block default\"" ]] && [[ $res2 = "ExecStart=-/bin/sh -c \"/usr/sbin/sulogin; /usr/bin/systemctl --fail --no-block default\"" ]]; then
            echo -e "\033[32m[+] single user mode need authentication \033[0m"
        else
            echo -e "\033[31m[+] single user mode does not need authentication \033[0m"
        fi
    fi
    # 1.3 Mantary Access Control
    # 1.3.1 ensure the SELinux state is enforcing
    if [[ -f /etc/selinux/config ]]; then
        local num=$(sestatus|grep -c enforcing)
        if [[ $num -gt 1 ]]; then
            echo -e "\033[32m[+] SELinux state is enforcing \033[0m"
        else
            echo -e "\033[31m[-] SELinux state is not enforcing \033[0m"
        fi
    fi
    # 1.3.2 ensure selinux policy is configured
    if [[ -f /etc/selinux/config ]]; then
        res=$(sestatus|grep targeted)
        if [[ -n $res ]]; then
            echo -e "\033[32m[+] SELinux policy is configured \033[0m"
        else
            echo -e "\033[31m[-] SELinux policy is not configure to targeted \033[0m"
        fi

    fi
}
function service_check {
    # 2. service configuration
    echo [·] check service configuration
    # 2.1 time sync
    # 2.1.1 time sync service is installed
    if $(rpm -q ntp 1>/dev/null||rpm -q chrony 1>/dev/null) ; then
        if $(rpm -q ntp 1>/dev/null) ; then
            if [[ -f /etc/ntp.conf ]]; then
                local res=$(egrep "^(server|pool)" /etc/ntp.conf)
                if [[ -n $res ]]; then
                    echo -e "\033[32m[+] remote ntp server is configured \033[0m"
                else
                    echo -e "\033[31m[-] remote ntp server is not configured \033[0m"
                fi
            fi
        fi
        if $(rpm -q chrony 1>/dev/null); then
            if [[ -f /etc/chrony.conf ]]; then
                local res=$(egrep "^(server|pool)" /etc/chrony.conf)
                if [[ -n $res ]]; then
                    echo -e "\033[32m[+] remote chrony server is configured \033[0m"
                else
                    echo -e "\033[31m[-] remote chrony server is not configured \033[0m"
                fi
                
            fi
        fi
    fi        
    # 2.1.2 x-window
    local res=$(rpm -qa xorg-x11*)
    if [[ -z $res ]]; then
        echo -e "\033[32m[+] x11-windows is not installed \033[0m"
    else
        echo -e "\033[31m[-] x11-windows is installed \033[0m"
    fi
}
function network_check {
    # 3. network configuration
    echo [·] check network configuration
    # 3.1 hosts file configuration
    # 3.1.1 check /etc/hosts.deny file
    if [[ -f /etc/hosts.deny ]]; then
        echo -e "\033[32m[+] file /etc/hosts.deny exists \033[0m"
        local res=`stat /etc/hosts.deny |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4`
        if [[ $(echo $res|cut -d"/" -f1) = "0644" ]];then
            echo -e "\033[32m[+] file /etc/hosts.deny permission is 0644 \033[0m"
        else
            echo -e "\033[31m[-] file /etc/hosts.deny permission is not 0644 \033[0m"
        fi

        local res=$(egrep "^[^#].+" /etc/hosts.deny)
        if [[ -n $res ]]; then
            echo -e "\033[32m[+] file /etc/hosts.deny is configured \033[0m"
        else
            echo -e "\033[31m[-] file /etc/hosts.deny is not configured \033[0m"
        fi
    else
        echo -e "\033[31m[-] file /etc/hosts.deny does not exists \033[0m"
    fi
    # 3.1.2 check /etc/hosts.allow file
    if [[ -f /etc/hosts.allow ]]; then
        echo -e "\033[32m[+] file /etc/hosts.allow exists \033[0m"
        local res=`stat /etc/hosts.allow |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4`
        if [[ $(echo $res|cut -d"/" -f1) = "0644" ]];then
            echo -e "\033[32m[+] file /etc/hosts.allow permission is 0644 \033[0m"
        else
            echo -e "\033[31m[-] file /etc/hosts.allow permission is not 0644 \033[0m"
        fi

        local res=$(egrep "^[^#].+" /etc/hosts.deny)
        if [[ -n $res ]]; then
            echo -e "\033[32m[+] file /etc/hosts.allow is configured \033[0m"
        else
            echo -e "\033[31m[-] file /etc/hosts.allow is not configured \033[0m"
        fi
    else
        echo -e "\033[31m[-] file /etc/hosts.allow does not exists \033[0m"
    fi

    # 3.2 firewall configuration
    # 3.2.1 ensure iptables is installed
    if $(rpm -q iptables 1>/dev/null); then
        echo -e "\033[32m[+] iptables is installed \033[0m"
        # 3.2.2 ensure INPUT OUTPUT chain policy is DROP
        iptables -L|grep policy|while read x;do
            if [[ $x =~ "INPUT" ]] && [[ $x =~ "DROP" ]]; then
                echo -e "\033[32m[+] INPUT chain policy is DROP \033[0m"
            elif [[ $x =~ "INPUT" ]] && [[ ! $x =~ "DROP" ]]; then
                echo -e "\033[31m[-] INPUT chain policy is not DROP \033[0m"
            fi
            if [[ $x =~ "OUTPUT" ]] && [[ $x =~ "DROP" ]]; then
                echo -e "\033[32m[+] OUTPUT chain policy is DROP \033[0m"
            elif [[ $x =~ "OUTPUT" ]] && [[ ! $x =~ "DROP" ]]; then
                echo -e "\033[31m[-] OUTPUT chain policy is not DROP \033[0m"
            fi
        done
    else
        echo -e "\033[31m[-] iptables is not installed \033[0m"
    fi
}

function auditd_check {
	# 4. auditd configuration
	echo [·] check auditd configuration
	# 4.1 ensure auditd is enabled
    echo "-[·] check auditd if is enabled"
	if [[ $(systemctl is-enabled auditd) = "enabled" ]]; then
		echo -e "\033[32m-[+] auditd is enabled \033[0m"
	else
		echo -e "\033[31m-[-] auditd is not enabled \033[0m"
	fi
	# 4.2 some settings in /etc/audit/auditd.conf
    echo "-[·] settings in /etc/audit/auditd.conf"	
    if [[ -f /etc/audit/auditd.conf ]]; then
        maxLogFile=$(grep "^max_log_file[[:blank:]]=" /etc/audit/auditd.conf|sed "s/ //g"|cut -d"=" -f 2)
        maxLogFileAction=$(grep "^max_log_file_action" /etc/audit/auditd.conf|sed "s/ //g"|cut -d"=" -f 2)
        spaceLeftAction=$(grep "^space_left_action" /etc/audit/auditd.conf|sed "s/ //g"|cut -d"=" -f 2)
        numLogs=$(grep "^num_logs" /etc/audit/auditd.conf|sed "s/ //g"|cut -d"=" -f 2)
        if [[ -n $maxLogFile ]]; then
            echo -e "\033[32m-[+] max_log_file size is ${maxLogFile} M \033[0m"
        else
            echo -e "\033[31m-[-] max_log_file size is not setted \033[0m"
        fi
        if [[ -n $maxLogFileAction ]]; then
            echo -e "\033[32m-[+] max_log_file_action is ${maxLogFileAction}\033[0m"
        else
            echo -e "\033[31m-[-] max_log_file_action is not setted \033[0m"
        fi
        if [[ -n $spaceLeftAction ]]; then
            echo -e "\033[32m-[+] space_left_action is ${spaceLeftAction}\033[0m"
        else
            echo -e "\033[31m-[-] space_left_action is not setted \033[0m"
        fi
        if [[ -n $numLogs ]]; then
            echo -e "\033[32m-[+] the num of logs is ${numLogs} \033[0m"
        else
            echo -e "\033[31m-[-] num_logs is not setted \033[0m"
        fi
    fi
    # 4.3 rules in /etc/audit/audit.rules
    # arch 64
    echo "-[·] time-change" 
    if [[ -f /etc/audit/audit.rules ]]; then
        echo -e "\033[32m-[+] /etc/audit/audit.rules is exist \033[0m"
        # 4.3.1 time-change
        if [[ -n $(grep time /etc/audit/audit.rules) ]]; then
            local timeChangeList=$(egrep "(stime|clock_settime|adjtimex|settimeofday|/etc/localtime)" /etc/audit/audit.rules|wc -l)
            if [[ ${timeChangeList} -gt 3 ]]; then
                echo -e "\033[32m-[+] audith the change of date and time \033[0m"
            elif [[ ${timeChangeList} -gt 1 ]]; then
                echo -e "\033[31m-[-] not fully set rule about audit the change of date and time \033[0m"
            else 
                echo -e "\033[31m-[-] not set rule about audit the change of date and time \033[0m"
            fi
        else
            echo -e "\033[31m-[-] not set rule about audit the change of date and time \033[0m"
        fi
        # 4.3.2 user and group change
        echo "-[·] user and group change"
        local keyArray=("/etc/passwd" "/etc/group" "/etc/gshadow" "/etc/shadow" "/etc/security/opasswd")
        for i in ${keyArray[@]} ; do
            if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then
                echo -e "\033[32m-[+] audit the change of $i \033[0m"
            else
                echo -e "\033[31m-[-] not audit the change of $i \033[0m"
            fi
        done
        # 4.3.3 system's network environment change
        echo "-[·] system's network environment change"
        local keyArray=("/etc/issue" "/etc/issue.net" "/etc/hosts" "/etc/sysconfig/network" "/etc/sysconfig/network-scripts/" )
        for i in ${keyArray[@]} ; do
                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then
                echo -e "\033[32m-[+] audit the change of $i \033[0m"
            else
                echo -e "\033[31m-[-] not audit the change of $i \033[0m"
            fi
        done
        local keyArray=("sethostname" "setdomainname")
        for i in ${keyArray[@]} ; do
                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then
                echo -e "\033[32m-[+] audit the use of syscall  $i \033[0m"
            else
                echo -e "\033[31m-[-] not audit the use of syscall $i \033[0m"
            fi
        done
        # 4.3.4 system's Mandatory Access Controls change
        echo "-[·] system's Mandatory Access Controls change"
        local keyArray=("/etc/selinux" "/usr/share/selinux")
        for i in ${keyArray[@]} ; do
                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then
                echo -e "\033[32m-[+] audit the change of   $i \033[0m"
            else
                echo -e "\033[31m-[-] not audit the change of $i \033[0m"
            fi
        done
        # 4.3.5 audit events of login and logout
        echo "-[·] audit events of login and logout"
        local keyArray=("/var/log/lastlog" "/var/run/faillock/")
        for i in ${keyArray[@]} ; do
                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then
                echo -e "\033[32m-[+] audit the change of   $i \033[0m"
            else
                echo -e "\033[31m-[-] not audit the change of $i \033[0m"
            fi
        done
        # 4.3.6 audit the change of discretionary access control
        echo "-[·] audit the change of discretionary access control"
        local keyArray=("(chmod|fchmod|fchmodat)" "(chown|fchown|fchownat)" "(setxattr|lsetxattr|removexattr)" "(lock|time)")
        for i in ${keyArray[@]} ; do
            if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then
                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')
                echo -e "\033[32m-[+] audit the use of systemcall  $i \033[0m"
            else
                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')
                echo -e "\033[31m-[-] not audit the use of systemcall $i \033[0m"
            fi
        done
        # 4.3.7 audit the events of unsuccessful unauthorized file access attempts
        echo "-[·] audit the events of unsuccessful unauthorized file access attempts"
        local keyArray=("(create|open|openat|truncate|ftruncate).*?exit=-EACCESS" "(create|open|openat|truncate|ftruncate).*?exit=-EPERM" )
        for i in ${keyArray[@]} ; do
            if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then
                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                echo -e "\033[32m-[+] audit the use of systemcall  $i \033[0m"
            else
                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                echo -e "\033[31m-[-] not audit the use of systemcall $i \033[0m"
            fi
        done
        # 4.3.8 audit the use of privileged commands
        echo "-[·] audit the use of privileged commands"
        #find / -name "passwd"
        local res=$(find / -xdev \( -perm -4000 -o -perm -2000 \) -type f) #|awk '{print "-a always,exit -F path="$1"-F perm=x -F auid>=1000 -F auid!=4294967295 -k privileged"}'
        for i in ${res[@]} ; do
            if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then
                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                echo -e "\033[32m-[+] audit the use of command  $i \033[0m"
            else
                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                echo -e "\033[31m-[-] not audit the use of command $i \033[0m"
            fi
        done
        # 4.3.9 audit the change of file sudoer
        echo "-[·] audit the change of file sudoer"
        local keyArray=("/etc/sudoers" "/etc/sudoers.d/")
        for i in ${keyArray[@]} ; do
            if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then
                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                echo -e "\033[32m-[+] audit the change of file  $i \033[0m"
            else
                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                echo -e "\033[31m-[-] not audit the change of file $i \033[0m"
            fi
        done
        # 4.3.10 check the audit configuration is setted to immutable unless reboot the server
        echo "-[·] check the audit configuration is setted to immutable unless reboot the server"
        local res=$(grep "^\s*[^#]" /etc/audit/audit.rules|tail -1|egrep "-e.*?2")
        if [[ -n $res ]]; then
            echo -e "\033[32m-[+] auditd setted -e 2 \033[0m"
        else
            echo -e "\033[31m-[-] auditd not setted -e 2 \033[0m"
        fi
    else
        echo -e "\033[32m[+] /etc/audit/audit.rules is not exist \033[0m"
    fi
}

function log_check {
    echo "[·] check log configuration"
	# 5.1 ensure auditd is enabled
    echo "-[·] check rsyslog if is enabled"
	if [[ $(systemctl is-enabled rsyslog) = "enabled" ]]; then
		echo -e "\033[32m-[+] rsyslog is enabled \033[0m"
	else
		echo -e "\033[31m-[-] rsyslog is not enabled \033[0m"
	fi
    

}

function authentication_check {
    echo "[·] check cron ssh pam and env configuration"
    # 6.1 cron configuration
    echo "-[·] check cron configuration"
    # 6.1.1 check cron service is enabled
    echo "-[·] check crond if is enabled"
	if [[ $(systemctl is-enabled crond) = "enabled" ]]; then
		echo -e "\033[32m-[+] crond is enabled \033[0m"
	else
		echo -e "\033[31m-[-] crond is not enabled \033[0m"
	fi
    # 6.1.2 check cron's configuration file permission
    echo "-[·] check cron's configuration file permission"
    local keyArray=("/etc/crontab" "/etc/cron.hourly" "/etc/cron.daily" "/etc/cron.weekly" "/etc/cron.monthly" "/etc/cron.d")
    for i in ${keyArray[@]} ; do
        local res=$(stat $i |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4|cut -d"/" -f1)
        if [[ $res = "0600" ]] || [[ $res = "0700" ]]; then
            echo -e "\033[32m-[+] file $i's permission is $res \033[0m"
        else
            echo -e "\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \033[0m"
        fi
    done
    # 6.1.3 check cron.allow cron.deny permission and owner
    echo "-[·] check cron.allow cron.deny configuration file permission"
    local keyArray=("/etc/cron.allow" "/etc/cron.deny")
    for i in ${keyArray[@]} ; do
        if [[ ! -f $i ]]; then
            echo -e "\033[31m-[-] file $i not exist \033[0m"
            continue
        fi
        local res1=$(stat $i |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4|cut -d"/" -f1)
        local res2=$(stat $i |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f3,4|sed 's/)//g'|cut -d" " -f3,6)
        if [[ $res1 = "0600" ]] || [[ $res1 = "0700" ]]; then
            echo -e "\033[32m-[+] file $i's permission is $res \033[0m"
        else
            echo -e "\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \033[0m"
        fi
        if [[ $res2 = "root root" ]]; then
            echo -e "\033[32m-[+] file $i's owner is $res2 \033[0m"
        else
            echo -e "\033[31m-[-] file $i's owner is not root \033[0m"
        fi
    done
    
    # 6.2 SSH configuration
    echo "-[·] check ssh configuration"
	if [[ $(systemctl is-enabled sshd) = "enabled" ]]; then
        # 6.2.1 /etc/ssh/sshd_config permission 0600
        local file="/etc/ssh/sshd_config"
        local res=$(stat $file |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4|cut -d"/" -f1)
        if [[ $res = "0600" ]]; then
            echo -e "\033[32m-[+] file $file's access permission is $res \033[0m"
        else
            echo -e "\033[3-m-[-] file $file's access permission is $res \033[0m"
        fi
        # 6.2.2 check ssh x11 forwarding if is disabled
        local res=$(grep "^X11Forwaring" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep no) ]]; then
            echo -e "\033[32m-[+] X11Forwarding no \033[0m"
        else
            echo -e "\033[31m-[-] not set X11Forwarding no \033[0m"
        fi
        # 6.2.3 check ssh MaxAUTHTries if is 4
        local res=$(grep "^MaxAuthTries" /etc/ssh/sshd_config)
        if [[ -n $res ]]; then
            echo -e "\033[32m-[+] $res \033[0m"
        else
            echo -e "\033[31m-[-] not set MaxAuthTries \033[0m"
        fi
        # 6.2.4 check ssh IgnoreRhosts if is enabled
        local res=$(grep "^IgnoreRhosts" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep yes) ]]; then
            echo -e "\033[32m-[+] IgnoreRhosts yes \033[0m"
        else
            echo -e "\033[31m-[-] not set IgnoreRhosts no\033[0m"
        fi
        # 6.2.5 check ssh HostbasedAuthentication if is disabled
        local res=$(grep "^HostbasedAuthentication" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep no) ]]; then
            echo -e "\033[32m-[+] HostbasedAuthentication no \033[0m"
        else
            echo -e "\033[31m-[-] not set HostbasedAuthentication no\033[0m"
        fi
        # 6.2.6 check ssh root login if is diabled
        local res=$(grep "^PermitRootLogin" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep no) ]]; then
            echo -e "\033[32m-[+] PermitRootLogin no \033[0m"
        else
            echo -e "\033[31m-[-] not set PermitRootLogin no\033[0m"
        fi
        # 6.2.7 check ssh PermitEmptyPasswords if is diabled
        local res=$(grep "^PermitEmptyPasswords" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep no) ]]; then
            echo -e "\033[32m-[+] PermitEmptyPasswords no \033[0m"
        else
            echo -e "\033[31m-[-] not set PermitEmptyPasswords no\033[0m"
        fi
        # 6.2.8 check ssh PermitUserEnvironment if is diabled
        local res=$(grep "^PermitUserEnvironment" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep no) ]]; then
            echo -e "\033[32m-[+] PermitUserEnvironment no \033[0m"
        else
            echo -e "\033[31m-[-] not set PermitUserEnvironment no\033[0m"
        fi
        # 6.2.9 check if set specific MAC algorithms
        local res=$(grep "^MACs" /etc/ssh/sshd_config)
        if [[ -n $res ]]; then
            echo -e "\033[32m-[+] will use specific MAC algorithms $res \033[0m"
        else
            echo -e "\033[31m-[-] not set specific MAC algorithms\033[0m"
        fi
        # 6.2.10 check SSH idle Timeout Interval if is configured
        local res=$(grep "^ClientAliveInterval" /etc/ssh/sshd_config)
        if [[ -n $res ]]; then
            echo -e "\033[32m-[+] $res \033[0m"
        else
            echo -e "\033[31m-[-] not set ClientAliveInterval \033[0m"
        fi
        # 6.2.11 check SSH LoginGrace Time
        local res=$(grep "^LoginGraceTime" /etc/ssh/sshd_config)
        if [[ -n $res ]]; then
            echo -e "\033[32m-[+] $res \033[0m"
        else
            echo -e "\033[31m-[-] not set LoginGraceTime \033[0m"
        fi
	else
		echo -e "\033[32m-[+] sshd is not enabled \033[0m"
	fi

    # 6.3 PAM configuration
    echo "-[·] check pam configuration"
    # 6.3.1 password creation policy
    if [[ -f /etc/security/pwquality.conf ]]; then
        local minlen=$(grep ^minlen /etc/security/pwquality.conf | sed 's/ //g')
        local minclass=$(grep ^minclass /etc/security/pwquality.conf |sed 's/ //g')
        if [[ -n $minlen ]]; then
            echo -e "\033[32m-[+] minimime length of password is $(echo $minlen|cut -d= -f2) \033[0m"
        else
            echo -e "\033[31m-[-] not set minlen \033[0m"
        fi
        if [[ -n $minclass ]]; then
            echo -e "\033[32m-[+] minclass of password is $(echo $minclass|cut -d= -f2) \033[0m"
        else
            local keyArray=("^dcredit" "^lcredit" "^ocredit" "^ucredit")
            local tmpCount=0
            for i in ${keyArray[@]}; do
                if [[ -n  $(grep $i /etc/security/pwquality.conf) ]]; then
                    tmpCount=$(expr 1 + $tmpCount)
                fi
            done
            if [[ tmpCount -ge 2 ]]; then
                echo -e "\033[32m-[+] minclass of passwd is $tmpCount \033[0m"
            else
                echo -e "\033[31m-[-] not set minclass \033[0m"
            fi
        fi
    fi
    # 6.3.2 lock account and unlock time
    local files=("/etc/pam.d/password-auth" "/etc/pam.d/system-auth")
    local keyArray=("pam_faillock\.so.*?unlock_time")
    for i in ${files[@]}; do
        for k in ${keyArray[@]}; do
            if [[ -n $(egrep $k $i ) ]]; then
                echo -e "\033[32m-[+] set lock and unlock_time in $i \033[0m"
            else
                echo -e "\033[31m-[-] not set lock and unlock_time in $i \033[0m"
            fi
        done
    done
    # 6.3.3 check password reuse if is limited
    for i in ${files[@]}; do
        local res=$(egrep '^password\s+sufficient\s+pam_unix.so' $i)
        if [[ -n $res ]] && [[ $res =~ "remember=" ]]; then
            local tmp=$(echo $res|sed 's/.*\(remember=[[:digit:]]\).*/\1/g'|sed 's/ //g'|cut -d= -f2)
            echo -e "\033[32m-[+] password reuse limit is $tmp in $i \033[0m"
        else
            echo -e "\033[31m-[-] passowrd reuse limit not set in $i \033[0m"
        fi
    done
    # 6.3.4 check the algorithm of store password if is sha512
    for i in ${files[@]}; do
        local res=$(egrep '^password\s+sufficient\s+pam_unix.so' $i)
        if [[ -n $res ]] && [[ $res =~ "sha512" ]]; then
            echo -e "\033[32m-[+] password storage algorithm is set to sha512 in $i \033[0m"
        else
            echo -e "\033[31m-[-] password storage algorithm is not specific to sha512 in $i \033[0m"
        fi
    done
    # 6.4 user accounts and environment
    echo "-[·] check user accounts and environment"
    if [[ -f /etc/login.defs ]]; then
        # 6.4.1 basic settings
        local file='/etc/login.defs'
        passMaxDays=$(grep ^PASS_MAX_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\1/g')
        passMinDays=$(grep ^PASS_MIN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\1/g')
        passWarnAge=$(grep ^PASS_WARN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\1/g')
        inactive=$(useradd -D|grep INACTIVE|sed 's/ //g'|cut -d= -f2)
        if [[ $passMaxDays -le 90 ]]; then
            echo -e "\033[32m-[+] the maximume days of password have to change is $passMaxDays \033[0m"
        else
            echo -e "\033[31m-[-] the maximume days of password have to change is $passMaxDays ,should less than 90 day\033[0m"
        fi
        if [[ $passMinDays -ge 7 ]]; then
            echo -e "\033[32m-[+] the minimume days of password have to change is $passMinDays \033[0m"
        else
            echo -e "\033[31m-[-] the minimume days of password have to change is $passMinDays ,should great than 7 day\033[0m"
        fi
        if [[ $passWarnAge -ge 7 ]]; then
            echo -e "\033[32m-[+] the minimume days of warn password need to change is $passWarnAge \033[0m"
        else
            echo -e "\033[31m-[-] the minimume days of warn password need to change is $passWarnAge ,should greate than 7 day\033[0m"
        fi
        if [[ $inactive != -1 ]]; then
            echo -e "\033[32m-[+] auto lock account when the  $inactive day haven't login \033[0m"
        else
            echo -e "\033[31m-[-] haven't set day of auto lock accounts \033[0m"
        fi
        # 6.4.2 check system's account if is unlogin
        local res=$(egrep -v "^\+" /etc/passwd | awk -F: '($1!="root" && $1!="sync" && $1!="shutdown" && $1!="halt" && $3<1000 && $7!="/sbin/nologin" && $7!="/bin/false") {print}')
        if [[ -z $res ]]; then
            echo -e "\033[32m-[+] system account can't login \033[0m"
        else
            echo -e "\033[31m-[-] the below user's shell need set to /sbin/nologin \033[0m"
        fi
        # 6.4.3 check default group for the root account if is GID 0
        local res=$(grep "^root:" /etc/passwd|cut -d: -f4)
        if [[ $res = 0 ]]; then
            echo -e "\033[32m-[+] default group for the root account is GID 0 \033[0m"
        else
            echo -e "\033[31m-[-]] default group for the root account is is GID $res,not GID 0 \033[0m"
        fi
        # 6.4.4 check default user shell timeout if is 900 seconds or less
        local files=("/etc/bashrc" "/etc/profile")
        for file in ${files[@]}; do
            if [[ ! -f $file ]]; then
                continue
            fi
            local res=$(grep "^TMOUT" $file|sed 's/ //g'|cut -d= -f2)
            if [[ -z $res ]]; then
                echo -e "\033[31m-[-] not set TMOUT in file $file \033[0m"
                continue
            fi
            if [[ $res -le 900 ]]; then
                echo -e "\033[32m-[+] when idle time great then $res seconds will close connection \033[0m"
            else
                echo -e "\033[31m-[-] when idle time great then $res seconds will close connection,the time should less than 900 seconds \033[0m"
            fi
        done
        # 6.4.5 check access to su command if is restricted
        local res=$(grep pam_wheel.so /etc/pam.d/su)
        if [[ -n $res ]]; then
            local res=$(grep wheel /etc/group|cut -d: -f4)
            if [[ -n $res ]]; then
                echo -e "\033[32m-[+] access to su command is specific to $res \033[0m"
            else
                echo -e "\033[31m-[-] access to su command is not restricted \033[0m"
            fi
        else
            echo -e "\033[31m-[-] access to su command is not restricted \033[0m"
        fi
    else
        echo -e "\033[31m-[-] file /etc/login.defs is not exist \033[0m"
    fi
}

function system_check {
    echo "[·] check permission of important file and configuration of user and group"
    # 7.1 check permission of important file and uid gid
    echo "-[·] check permission of important file"
    local files=("/etc/passwd" "/etc/shadow" "/etc/group" "/etc/gshadow" "/etc/passwd-" "/etc/shadow-" "/etc/group-" "/etc/gshadow-")
    for file in ${files[@]}; do
        local perm=$(stat $file |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4|cut -d"/" -f1)
        local uidGid=$(stat /etc/passwd |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f3,4|sed 's/ //g'|sed -r 's/([[:digit:]]{1,}).*([[:digit:]]{1,}).*/\1 \2/g'|cut -d" " -f1,2)
        if [[ $file =~ "shadow" ]]; then
            if [[ $perm = "0000" ]]; then
                echo -e "\033[32m-[+] file $file's permission is $perm \033[0m"
            else
                echo -e "\033[31m-[-] file $file's permission is $perm,should set to 0000 \033[0m"
            fi
        else
            if [[ $perm = "0644" ]]; then
                echo -e "\033[32m-[+] file $file's permission is $perm \033[0m"
            else
                echo -e "\033[31m-[-] file $file's permission is $perm,should set to 0644 \033[0m"

            fi
        fi
        if [[ $uidGid = "0 0" ]]; then
            echo -e "\033[32m-[+] file $file's uid gid is $uidGid \033[0m"
        else
            echo -e "\033[31m-[-] file $file's uid gid is $uidGid,should set to 0 0 \033[0m"
        fi
    done
    # 7.2 check configuration of user and group
    echo "-[·] check configuration of user and group"
    # 7.2.1 check if user's password is empty
    users=$(cat /etc/shadow |awk -F: '($2=="!!"){print $1}'|while read x;do 
        res=$(grep ${x} /etc/passwd|cut -d: -f7); if [[ $res != "/sbin/nologin" ]] && [[ $res != "/sbin/shutdon" ]] && [[ $res != "/sbin/halt" ]]; then 
            echo $x
            #echo -e "\033[31m-[-] $x should have a passwd,not empty \033[0m"; 
            fi;
        done)
    if [[ -z $users ]]; then
        echo -e "\033[32m-[+] all user account have set password \033[0m"
    else
        echo -e "\033[31m-[-] user:$(echo $users|sed 's/\n/ /g') should set a password ,rather than empty \033[0m"
    fi
    # 7.2.2 check if root is the only UID 0 account
    local users=$(cat /etc/passwd|awk -F: '($3==0){print $1}')
    if [[ $users = 'root' ]]; then
        echo -e "\033[32m-[+] root is the only account that uid is 0 \033[0m"
    else
        echo -e "\033[31m-[-] $(echo $users|sed 's/root//g') uid should not be 0 \033[0m"
    fi
    # 7.2.3 check root PATH integrith
    if [ "$(echo $PATH|grep ::)" != "" ]; then
        echo -e "\033[31m-[-] Empty Directory in PATH (::) \033[0m"
    fi
    if [ "$(echo $PATH|grep :$)" != "" ]; then
        echo -e "\033[31m-[-] Trailing : in PATH \033[0m"
    fi
    path=$( echo $PATH|sed -e 's/::/:/' -e 's/:$//' -e 's/:/ /g')
    set -- $path
    while [[ $1 != "" ]]; do
        if [[ $1 = "." ]]; then
            echo -e "\033[31m-[-] PATH contains . \033[0m"
            shift
            continue
        fi
        if [[ -d $1 ]]; then
            local dirperm=$(ls -ldH $1|cut -d" " -f1)
            if [[ $(echo $dirperm|cut -c6) != "-" ]]; then
                echo -e "\033[31m-[-] Group Write permission should not set on directory $1 \033[0m"
            fi
            if [[ $(echo $dirperm|cut -c9) != "-" ]]; then
                echo -e "\033[31m-[-] Other Write permission should not set on directory $1 \033[0m"
            fi
            local dirown=$(ls -ldH $1|awk '{print $3}')
            if [[ $dirown != "root" ]]; then
                echo -e "\033[31m-[-] dir $1's owner is $dirown,should be root \033[0m"
            fi
        else
            echo -e "\033[31m-[-] $1 is not a directory or not exist \033[0m"
        fi
        shift
    done
    # 7.2.4 check if is all users' home directories exist
    cat /etc/passwd|egrep -v '^(root|halt|sync|shutdown)'|awk -F: '($7 != "/sbin/nologin" && $7 != "/bin/false"){print $1 " " $6}'|while read user dir; do
        if [[ ! -d $dir ]]; then
            echo -e "\033[31m-[-] the home directory ($dir) of user $user does not exist \033[0m"
        else
            # 7.2.5 check if users' home directories permissions are 750 or more restrictive
            local dirperm=$(ls -ld $dir|cut -d" " -f1)
            if [[ $(echo $dirperm |cut -c6) != "-" ]]; then
                echo -e "\033[31m-[-] Group Write permission set on the home directory ($dir) of user $user \033[0m"
            fi
            if [[ $(echo $dirperm |cut -c8) != "-" ]]; then
                echo -e "\033[31m-[-] Other Read permission set on the home directory ($dir) of user $user \033[0m"
            fi
            if [[ $(echo $dirperm |cut -c9) != "-" ]]; then
                echo -e "\033[31m-[-] Other Write permission set on the home directory ($dir) of user $user \033[0m"
            fi
            if [[ $(echo $dirperm |cut -c10) != "-" ]]; then
                echo -e "\033[31m-[-] Other Execute permission set on the home directory ($dir) of user $user \033[0m"
            fi
            # 7.2.6 check if is users own their home directory
            local owner=$(stat -L -c "%U" $dir)
            if [[ $owner != $user ]]; then
                echo -e "\033[31m-[-]The home directory ($dir) of user $user is owned by $owner \033[0m"
            fi
            # 7.2.7 check users' dot files are not group or world  writable
            for file in $dir/.[A-Za-z0-9]*; do
                if [[ ! -h $file ]] && [[ -f $file ]]; then
                    local fileperm=$(ls -ld $file|cut -d" " -f1)
                    if [[ $(echo $fileperm|cut -c6) != "-" ]]; then
                        echo -e "\033[31m-[-] Group Write permission set on file $file \033[0m"
                    fi
                    if [[ $(echo $fileperm|cut -c9) != "-" ]]; then
                        echo -e "\033[31m-[-] Other Write permission set on file $file \033[0m"
                    fi
                fi
            done
            # 7.2.8 check if no usrs have .netrc .rhosts .forward file
            if [[ ! -h $dir/.netrc ]] && [[ -f $dir/.netrc ]]; then
                echo -e "\033[31m-[-] .netrc file $dir/.netrc exists \033[0m"
            fi
            if [[ ! -h $dir/.rhosts ]] && [[ -f $dir/.rhosts ]]; then
                echo -e "\033[31m-[-] .rhosts file $dir/.rhosts exists \033[0m"
            fi
            if [[ ! -h $dir/.forward ]] && [[ -f $dir/.forward ]]; then
                echo -e "\033[31m-[-] .forward file $dir/.forward exists \033[0m"
            fi
        fi
        # 7.2.9 check if all groups in /etc/passwd exist in /etc/group
        for i in $(cut -d: -s -f4 /etc/passwd|sort -u); do
            grep -q -P "^.*?:[^:]*:$i" /etc/group
            if [[ $? -ne 0 ]]; then
                echo -e "\033[31m-[-] Group $i is referenced by /etc/passwd but does not exist in /etc/group \033[0m"
            fi
        done
    done
    # 7.2.10 check if every user has a unique UID
    cat /etc/passwd|cut -d":" -f3|sort -n|uniq -c|while read x; do
        [[ -z $x ]] && break
        set - $x
        if [[ $1 -gt 1 ]]; then
            local users=$(awk -F: '($3==n){print $1}' n=$2 /etc/passwd|xargs)
            echo -e "\033[31m-[-] Duplicate UID $2 : $users \033[0m"
        fi
    done
    # 7.2.11 check if every group has a unique GID
    cat /etc/group|cut -d":" -f3|sort -n|uniq -c|while read x; do
        [[ -z $x ]] && break
        set - $x
        if [[ $1 -gt 1 ]]; then
            local groups=$(awk -F: '($3==n){print $1}' n=$2 /etc/group|xargs)
            echo -e "\033[31m-[-] Duplicate GID $2 : $groups \033[0m"
        fi
    done
    # 7.2.12 check if user name is unique
    cat /etc/passwd|cut -d":" -f1|sort -n|uniq -c|while read x; do
        [[ -z $x ]] && break
        set - $x11
        if [[ $1 -gt 1 ]]; then
            local uids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/passwd|xargs)
            echo -e "\033[31m-[-] Duplicate user name $2 : $uids \033[0m"
        fi
        done
    # 7.2.13 check if group name is unique
    cat /etc/group|cut -d":" -f1|sort -n|uniq -c|while read x; do
        [[ -z $x ]] && break
        set - $x11
        if [[ $1 -gt 1 ]]; then
            local gids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/group|xargs)
            echo -e "\033[31m-[-] Duplicate group name $2 : $gids \033[0m"
        fi
        done
    

}

echo """
==================================
|        Linux 基线检查工具      |
|        author:JC0o0l           |
|        version:1.0             |
==================================
"""
#get_basic_info
#init_check
#service_check
#network_check
#auditd_check
#log_check
#authentication_check
system_check

================================================
FILE: baseline_check_v2.1_JC0o0l.sh
================================================
#!/bin/bash
function get_ip_info {
    local ipList=`ifconfig | grep inet |grep -v inet6|grep -v 127|sed 's/^[ ]*//g'|cut -d" " -f2`
    echo $ipList
}
function get_basic_info {
    echo [·] collect basic info
    hostname=`hostname`
    ipList=`get_ip_info`
    kernelVersion=`uname -r`
    if [[ $(cat /proc/version) =~ "Red Hat" ]]; then
        osVersion=`cat /etc/redhat-release|cut -f1,4 -d" "`
    fi
    basic_info={\"hostname\":\"$hostname\",\"ipList\":\"$ipList\",\"kernelVersion\":\"$kernelVersion\",\"osVersion\":\"$osVersion\"}
    echo $basic_info
}

function init_check {
    # 1. init configuration
    echo [·] check init configuration
    # 1.1 file system configuration
    # 1.1.1 /tmp separate mount
    local tmpIfSeparate #=""
    local tmpIfNoexec #=""
    local tmpIfNosuid #=""
    local res=$(mount|grep "/tmp ") 
    if [[ -z $res ]]; then
        echo -e "\033[31m-[-] /tmp/ not mounted on separate dick\033[0m"
        tmpIfSeparate="false"
        tmpIfNoexec="false"
        tmpIfNosuid="false"
    else
        tmpIfSeparate="true"
        tmpIfNoexec="true"
        tmpIfNosuid="true"
    fi
    if $tmpIfSeparate; then
        #mount|grep "/sys/kernel/debug " |while read res;do
        while read res;do
            #echo "mount | grep /sys --result-->" $res
            # 1.1.2 /tmp noexec nosuid
            local diskPart=$(echo $res|cut -d" " -f3)
            if [[ ! $res =~ "noexec" ]];then
                echo -e "\033[31m-[-] no noexec option on $diskPart partion\033[0m"
                tmpIfNoexec="false"
                if [[ ! $res =~ "nosuid" ]];then
                    echo -e "\033[31m-[-] no nosuid option on $diskPart partion\033[0m"
                    tmpIfNosuid="false"
                fi
            elif [[ ! $res =~ "nosuid" ]];then
                echo -e "\033[31m-[-] no nosuid option on $diskPart partion\033[0m"
                tmpIfNosuid="false"
            fi
        done < <(mount | grep "/tmp ")
    fi
    tmp_partition_info={\"tmpIfSeparate\":\"$tmpIfSeparate\",\"tmpIfNoexec\":\"$tmpIfNoexec\",\"tmpIfNosuid\":\"$tmpIfNosuid\"}
    #echo $tmp_partition_info
    # 1.2 secure boot configuration
    if [[ -f /boot/grub2/grub.cfg ]];then
        grubcfgIfExist="true"
        grubcfgPermission="0600"
        grubcfgIfSetPasswd="true"
    else
        grubcfgIfExist="false"
        grubcfgPermission="0000"
        grubcfgIfSetPasswd="false"
    fi
    if $grubcfgIfExist; then
        # 1.2.1 /boot/grub2/grub.cfg permission /boot/grub2/user.cfg permission 0600 root:root
        res=$(stat /boot/grub2/grub.cfg |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4)
        grubcfgPermission=$(echo $res|cut -d"/" -f1)
        if [[ $(echo $res|cut -d"/" -f1) = "0600" ]]; then
            echo -e "\033[32m-[+] /boot/grub2/grub.cfg permission is 0600 \033[0m"
        else
            echo -e "\033[31m-[-] /boot/grub2/grub.cfg permission is not 0600 \033[0m"
        fi
        # 1.2.2 Ensure bootloader password is set
        res=$(grep "^GRUB2 PASSWORD" /boot/grub2/grub.cfg)
        if [[ -n $res ]]; then
            echo -e "\033[32m-[+] /boot/grub2/grub.cfg seted password \033[0m"
            grubcfgIfSetPasswd="true"
        else
            echo -e "\033[31m-[-] /boot/grub2/grub.cfg not set password \033[0m"
            grubcfgIfSetPasswd="false"
        fi
    fi
        
    # 1.2.3 single user mode need authentication
    if [[ -f /usr/lib/systemd/system/rescue.service ]] && [[ -f /usr/lib/systemd/system/emergency.service ]]; then
        res1=`grep /sbin/sulogin /usr/lib/systemd/system/rescue.service`
        res2=`grep /sbin/sulogin /usr/lib/systemd/system/emergency.service`
        if [[ $res1 = "ExecStart=-/bin/sh -c \"/usr/sbin/sulogin; /usr/bin/systemctl --fail --no-block default\"" ]] && [[ $res2 = "ExecStart=-/bin/sh -c \"/usr/sbin/sulogin; /usr/bin/systemctl --fail --no-block default\"" ]]; then
            echo -e "\033[32m-[+] single user mode need authentication \033[0m"
            singleUserModeIfNeedAuth="true"
        else
            echo -e "\033[31m-[+] single user mode does not need authentication \033[0m"
            singleUserModeIfNeedAuth="false"
        fi
    fi
    # 1.3 Mantary Access Control
    # 1.3.1 ensure the SELinux state is enforcing
    if [[ -f /etc/selinux/config ]]; then
        local num=$(sestatus|grep -c enforcing)
        if [[ $num -gt 1 ]]; then
            echo -e "\033[32m-[+] SELinux state is enforcing \033[0m"
            selinuxStateIfEnforcing="true"
        else
            echo -e "\033[31m-[-] SELinux state is not enforcing \033[0m"
            selinuxStateIfEnforcing="false"
        fi
    fi
    # 1.3.2 ensure selinux policy is configured
    if [[ -f /etc/selinux/config ]]; then
        res=$(sestatus|grep targeted)
        if [[ -n $res ]]; then
            echo -e "\033[32m-[+] SELinux policy is configured \033[0m"
            selinuxPolicyIfConfigured="true"
        else
            echo -e "\033[31m-[-] SELinux policy is not configure to targeted \033[0m"
            selinuxPolicyIfConfigured="false"
        fi
    fi
    boot_secure_info={\"grubcfgIfExist\":\"$grubcfgIfExist\",\"grubcfgPermission\":\"$grubcfgPermission\",\"grubcfgIfSetPasswd\":\"$grubcfgIfSetPasswd\",\"singleUserModeIfNeedAuth\":\"$singleUserModeIfNeedAuth\",\"selinuxStateIfEnforcing\":\"$selinuxStateIfEnforcing\",\"selinuxPolicyIfConfigured\":\"$selinuxPolicyIfConfigured\"}
    #echo $boot_secure_info
    init_check_res={\"tmp_partition_info\":$tmp_partition_info,\"boot_secure_info\":$boot_secure_info}
}
function service_check {
    # 2. service configuration
    echo [·] check service configuration
    # 2.1 time sync
    # 2.1.1 time sync service is installed
    if $(rpm -q ntp 1>/dev/null||rpm -q chrony 1>/dev/null) ; then
        if $(rpm -q ntp 1>/dev/null) ; then
            if [[ -f /etc/ntp.conf ]]; then
                local res=$(egrep "^(server|pool)" /etc/ntp.conf)
                if [[ -n $res ]]; then
                    echo -e "\033[32m-[+] remote ntp server is configured \033[0m"
                    timeSyncServerIfConfigured="true"
                else
                    echo -e "\033[31m-[-] remote ntp server is not configured \033[0m"
                    timeSyncServerIfConfigured="false"
                fi
            fi
        fi
        if $(rpm -q chrony 1>/dev/null); then
            if [[ -f /etc/chrony.conf ]]; then
                local res=$(egrep "^(server|pool)" /etc/chrony.conf)
                if [[ -n $res ]]; then
                    echo -e "\033[32m-[+] remote chrony server is configured \033[0m"
                    timeSyncServerIfConfigured="true"
                else
                    echo -e "\033[31m-[-] remote chrony server is not configured \033[0m"
                    timeSyncServerIfConfigured="false"
                fi
                
            fi
        fi
    fi        
    # 2.1.2 x-window
    local res=$(rpm -qa xorg-x11*)
    if [[ -z $res ]]; then
        echo -e "\033[32m-[+] x11-windows is not installed \033[0m"
        x11windowIfNotInstalled="true"
    else
        echo -e "\033[31m-[-] x11-windows is installed \033[0m"
        x11windowIfNotInstalled="false"
    fi
    service_check_res={\"timeSyncServerIfConfigured\":\"$timeSyncServerIfConfigured\",\"x11windowIfNotInstalled\":\"$x11windowIfNotInstalled\"}
}
function network_check {
    # 3. network configuration
    echo [·] check network configuration
    # 3.1 hosts file configuration
    # 3.1.1 check /etc/hosts.deny file
    if [[ -f /etc/hosts.deny ]]; then
        hostsDenyFileIfExist="true"
        echo -e "\033[32m-[+] file /etc/hosts.deny exists \033[0m"
        local res=$(stat /etc/hosts.deny |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4)
        hostsDenyFilePermission=$(echo $res|cut -d"/" -f1)
        if [[ $(echo $res|cut -d"/" -f1) = "0644" ]];then
            echo -e "\033[32m-[+] file /etc/hosts.deny permission is 0644 \033[0m"
        else
            echo -e "\033[31m-[-] file /etc/hosts.deny permission is not 0644 \033[0m"
        fi

        local res=$(egrep "^[^#].+" /etc/hosts.deny)
        if [[ -n $res ]]; then
            hostsDenyFileIfConfigured="true"
            echo -e "\033[32m-[+] file /etc/hosts.deny is configured \033[0m"
        else
            hostsDenyFileIfConfigured="false"
            echo -e "\033[31m-[-] file /etc/hosts.deny is not configured \033[0m"
        fi
    else
        hostsDenyFileIfExist="false"
        echo -e "\033[31m-[-] file /etc/hosts.deny does not exists \033[0m"
    fi
    # 3.1.2 check /etc/hosts.allow file
    if [[ -f /etc/hosts.allow ]]; then
        hostsAllowFileIfExist="true"
        echo -e "\033[32m-[+] file /etc/hosts.allow exists \033[0m"
        local res=`stat /etc/hosts.allow |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4`
        hostsAllowFilePermission=$(echo $res|cut -d"/" -f1)
        if [[ $(echo $res|cut -d"/" -f1) = "0644" ]];then
            echo -e "\033[32m-[+] file /etc/hosts.allow permission is 0644 \033[0m"
        else
            echo -e "\033[31m-[-] file /etc/hosts.allow permission is not 0644 \033[0m"
        fi

        local res=$(egrep "^[^#].+" /etc/hosts.deny)
        if [[ -n $res ]]; then
            hostsAllowFileIfConfigured="true"
            echo -e "\033[32m-[+] file /etc/hosts.allow is configured \033[0m"
        else
            hostsAllowFileIfConfigured="false"
            echo -e "\033[31m-[-] file /etc/hosts.allow is not configured \033[0m"
        fi
    else
        hostsAllowFileIfExist="false"
        echo -e "\033[31m-[-] file /etc/hosts.allow does not exists \033[0m"
    fi

    # 3.2 firewall configuration
    # 3.2.1 ensure iptables is installed
    if $(rpm -q iptables 1>/dev/null); then
        iptablesIfInstalled="true"
        echo -e "\033[32m-[+] iptables is installed \033[0m"
        # 3.2.2 ensure INPUT OUTPUT chain policy is DROP
        #iptables -L|grep policy|while read x;do
        while read x;do
            if [[ $x =~ "INPUT" ]] && [[ $x =~ "DROP" ]]; then
                iptablesInputPolicyIfDrop="true"
                echo -e "\033[32m-[+] INPUT chain policy is DROP \033[0m"
            elif [[ $x =~ "INPUT" ]] && [[ ! $x =~ "DROP" ]]; then
                iptablesInputPolicyIfDrop="false"
                echo -e "\033[31m-[-] INPUT chain policy is not DROP \033[0m"
            fi
            if [[ $x =~ "OUTPUT" ]] && [[ $x =~ "DROP" ]]; then
                iptablesOutputPolicyIfDrop="true"
                echo -e "\033[32m-[+] OUTPUT chain policy is DROP \033[0m"
            elif [[ $x =~ "OUTPUT" ]] && [[ ! $x =~ "DROP" ]]; then
                iptablesOutputPolicyIfDrop="false"
                echo -e "\033[31m-[-] OUTPUT chain policy is not DROP \033[0m"
            fi
        done < <(iptables -L|grep policy)
    else
        iptablesIfInstalled="false"
        echo -e "\033[31m-[-] iptables is not installed \033[0m"
    fi
    network_check_res={\"hostsAllowFileIfExist\":\"$hostsAllowFileIfExist\",\"hostsAllowFilePermission\":\"$hostsAllowFilePermission\",\"hostsAllowFileIfConfigured\":\"$hostsAllowFileIfConfigured\",\"hostsDenyFileIfExist\":\"$hostsDenyFileIfExist\",\"hostsDenyFilePermission\":\"$hostsDenyFilePermission\",\"hostsDenyFileIfConfigured\":\"$hostsDenyFileIfConfigured\",\"iptablesIfInstalled\":\"$iptablesIfInstalled\",\"iptablesInputPolicyIfDrop\":\"$iptablesInputPolicyIfDrop\",\"iptablesOutputPolicyIfDrop\":\"$iptablesOutputPolicyIfDrop\"}
}

function auditd_check {
	# 4. auditd configuration
	echo [·] check auditd configuration
	# 4.1 ensure auditd is enabled
    echo "-[·] check auditd if is enabled"
	if [[ $(systemctl is-enabled auditd) = "enabled" ]]; then
		echo -e "\033[32m-[+] auditd is enabled \033[0m"
        auditdIfEnabled="true"
	else
        auditdIfEnabled="false"
		echo -e "\033[31m-[-] auditd is not enabled \033[0m"
	fi
	# 4.2 some settings in /etc/audit/auditd.conf
    echo "-[·] settings in /etc/audit/auditd.conf"	
    if [[ -f /etc/audit/auditd.conf ]]; then
        auditdconfIfExist="true"
        maxLogFile=$(grep "^max_log_file[[:blank:]]=" /etc/audit/auditd.conf|sed "s/ //g"|cut -d"=" -f 2)
        maxLogFileAction=$(grep "^max_log_file_action" /etc/audit/auditd.conf|sed "s/ //g"|cut -d"=" -f 2)
        spaceLeftAction=$(grep "^space_left_action" /etc/audit/auditd.conf|sed "s/ //g"|cut -d"=" -f 2)
        numLogs=$(grep "^num_logs" /etc/audit/auditd.conf|sed "s/ //g"|cut -d"=" -f 2)
        if [[ -n $maxLogFile ]]; then
            auditdIfSetMaxLogFile=$maxLogFile
            echo -e "\033[32m-[+] max_log_file size is ${maxLogFile} M \033[0m"
        else
            auditdIfSetMaxLogFile="false"
            echo -e "\033[31m-[-] max_log_file size is not setted \033[0m"
        fi
        if [[ -n $maxLogFileAction ]]; then
            auditdIfSetMaxLogFileAction="$maxLogFileAction"
            echo -e "\033[32m-[+] max_log_file_action is ${maxLogFileAction}\033[0m"
        else
            auditdIfSetMaxLogFileAction="false"
            echo -e "\033[31m-[-] max_log_file_action is not setted \033[0m"
        fi
        if [[ -n $spaceLeftAction ]]; then
            auditdIfSetSpaceLeftAction="$spaceLeftAction"
            echo -e "\033[32m-[+] space_left_action is ${spaceLeftAction}\033[0m"
        else
            auditdIfSetSpaceLeftAction="false"
            echo -e "\033[31m-[-] space_left_action is not setted \033[0m"
        fi
        if [[ -n $numLogs ]]; then
            auditdIfSetNumLogs="$numLogs"
            echo -e "\033[32m-[+] the num of logs is ${numLogs} \033[0m"
        else
            auditdIfSetNumLogs="false"
            echo -e "\033[31m-[-] num_logs is not setted \033[0m"
        fi
    else
        auditdconfIfExist="false"
    fi
    auditd_config_info={\"auditdIfEnabled\":\"$auditdIfEnabled\",\"auditdconfIfExist\":\"$auditdconfIfExist\",\"auditdIfSetMaxLogFile\":\"$auditdIfSetMaxLogFile\",\"auditdIfSetMaxLogFileAction\":\"$auditdIfSetMaxLogFileAction\",\"auditdIfSetSpaceLeftAction\":\"$auditdIfSetSpaceLeftAction\",\"auditdIfSetNumLogs\":\"$auditdIfSetNumLogs\"}
    echo $auditd_config_info
    # 4.3 rules in /etc/audit/audit.rules
    # arch 64
    echo "-[·] time-change" 
    if [[ -f /etc/audit/audit.rules ]]; then
        auditdrulesIfExist="true"
        echo -e "\033[32m-[+] /etc/audit/audit.rules is exist \033[0m"
        if [[ ! -n $(grep time /etc/audit/audit.rules) ]]; then
            auditdRulesIfNotNull="false"
            echo -e "\033[31m-[-] not set rule about audit the change of date and time \033[0m"
        else
            auditdRulesIfNotNull="true"
            # 4.3.1 time-change
            local timeChangeList=$(egrep "(stime|clock_settime|adjtimex|settimeofday|/etc/localtime)" /etc/audit/audit.rules|wc -l)
            if [[ ${timeChangeList} -gt 3 ]]; then
                auditdIfCheckTimechange="true"
                echo -e "\033[32m-[+] audith the change of date and time \033[0m"
            elif [[ ${timeChangeList} -gt 1 ]]; then
                auditdIfCheckTimechange="false"
                echo -e "\033[31m-[-] not fully set rule about audit the change of date and time \033[0m"
            else 
                auditdIfCheckTimechange="false"
                echo -e "\033[31m-[-] not set rule about audit the change of date and time \033[0m"
            fi
            # 4.3.2 user and group change
            echo "-[·] user and group change"
            local keyArray=("/etc/passwd" "/etc/group" "/etc/gshadow" "/etc/shadow" "/etc/security/opasswd")
            tmpArray1=()
            tmpArray2=()
            for i in ${keyArray[@]} ; do
                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i)
                    echo -e "\033[32m-[+] audit the change of $i \033[0m"
                else
                    tmpArray2+=($i)
                    echo -e "\033[31m-[-] not audit the change of $i \033[0m"
                fi
            done
            auditdRulesCheckedUserandgroupfile=${tmpArray1[@]}
            auditdRulesNotCheckedUserandgroupfile=${tmpArray2[@]}
            # 4.3.3 system's network environment change
            echo "-[·] system's network environment change"
            local keyArray=("/etc/issue" "/etc/issue.net" "/etc/hosts" "/etc/sysconfig/network" "/etc/sysconfig/network-scripts/" )
            tmpArray1=()
            tmpArray2=()
            for i in ${keyArray[@]} ; do
                    if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i)
                    echo -e "\033[32m-[+] audit the change of $i \033[0m"
                else
                    tmpArray2+=($i)
                    echo -e "\033[31m-[-] not audit the change of $i \033[0m"
                fi
            done
            local keyArray=("sethostname" "setdomainname")
            for i in ${keyArray[@]} ; do
                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i)
                    echo -e "\033[32m-[+] audit the use of syscall  $i \033[0m"
                else
                    echo -e "\033[31m-[-] not audit the use of syscall $i \033[0m"
                    tmpArray2+=($i)
                fi
            done
            auditdRulesCheckedNetworkenv=${tmpArray1[@]}
            auditdRulesNotCheckedNetworkenv=${tmpArray2[@]}
            # 4.3.4 system's Mandatory Access Controls change
            echo "-[·] system's Mandatory Access Controls change"
            local keyArray=("/etc/selinux" "/usr/share/selinux")
            tmpArray1=()
            tmpArray2=()
            for i in ${keyArray[@]} ; do
                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i)
                    echo -e "\033[32m-[+] audit the change of   $i \033[0m"
                else
                    tmpArray2+=($i)
                    echo -e "\033[31m-[-] not audit the change of $i \033[0m"
                fi
            done
            auditdRulesCheckedMACchange=${tmpArray1[@]}
            auditdRulesNotCheckedMACchange=${tmpArray2[@]}
            # 4.3.5 audit events of login and logout
            echo "-[·] audit events of login and logout"
            local keyArray=("/var/log/lastlog" "/var/run/faillock/")
            tmpArray1=()
            tmpArray2=()
            for i in ${keyArray[@]} ; do
                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i)
                    echo -e "\033[32m-[+] audit the change of   $i \033[0m"
                else
                    tmpArray2+=($i)
                    echo -e "\033[31m-[-] not audit the change of $i \033[0m"
                fi
            done
            auditdRulesCheckedLoginoutEvents=${tmpArray1[@]}
            auditdRulesNotCheckedLoginoutEvents=${tmpArray2[@]}
            # 4.3.6 audit the change of discretionary access control
            echo "-[·] audit the change of discretionary access control"
            local keyArray=("(chmod|fchmod|fchmodat)" "(chown|fchown|fchownat)" "(setxattr|lsetxattr|removexattr)" "(lock|time)")
            tmpArray1=()
            tmpArray2=()
            for i in ${keyArray[@]} ; do
                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')
                    echo -e "\033[32m-[+] audit the use of systemcall  $i \033[0m"
                    tmpArray1+=($i)
                else
                    tmpArray2+=($i)
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')
                    echo -e "\033[31m-[-] not audit the use of systemcall $i \033[0m"
                fi
            done
            auditdRulesCheckedDACChangeSyscall=${tmpArray1[@]}
            auditdRulesNotCheckedDACChangeSyscall=${tmpArray2[@]}
            # 4.3.7 audit the events of unsuccessful unauthorized file access attempts
            echo "-[·] audit the events of unsuccessful unauthorized file access attempts"
            local keyArray=("(create|open|openat|truncate|ftruncate).*?exit=-EACCESS" "(create|open|openat|truncate|ftruncate).*?exit=-EPERM" )
            tmpArray1=()
            tmpArray2=()
            for i in ${keyArray[@]} ; do
                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i)
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                    echo -e "\033[32m-[+] audit the use of systemcall  $i \033[0m"
                else
                    tmpArray2+=($i)
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                    echo -e "\033[31m-[-] not audit the use of systemcall $i \033[0m"
                fi
            done
            auditdRulesCheckedFileAccessAttemptSyscall=${tmpArray1[@]}
            auditdRulesNotCheckedFileAccessAttemptSyscall=${tmpArray2[@]}
            # 4.3.8 audit the use of privileged commands
            echo "-[·] audit the use of privileged commands"
            #find / -name "passwd"
            local res=$(find / -xdev \( -perm -4000 -o -perm -2000 \) -type f) #|awk '{print "-a always,exit -F path="$1"-F perm=x -F auid>=1000 -F auid!=4294967295 -k privileged"}'
            tmpArray1=()
            tmpArray2=()
            for i in ${res[@]} ; do
                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i)
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                    echo -e "\033[32m-[+] audit the use of command  $i \033[0m"
                else
                    tmpArray2+=($i)
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                    echo -e "\033[31m-[-] not audit the use of command $i \033[0m"
                fi
            done
            auditdRulesCheckedPrivilegedCommand=${tmpArray1[@]}
            auditdRulesNotCheckedPrivilegedCommand=${tmpArray2[@]}
            # 4.3.9 audit the change of file sudoer
            echo "-[·] audit the change of file sudoer"
            local keyArray=("/etc/sudoers" "/etc/sudoers.d/")
            tmpArray1=()
            tmpArray2=()
            for i in ${keyArray[@]} ; do
                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i)
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                    echo -e "\033[32m-[+] audit the change of file  $i \033[0m"
                else
                    tmpArray2+=($i)
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                    echo -e "\033[31m-[-] not audit the change of file $i \033[0m"
                fi
            done
            auditdRulesCheckedSudoerFile=${tmpArray1[@]}
            auditdRulesNotCheckedSudoerFile=${tmpArray2[@]}
            # 4.3.10 check the audit configuration is setted to immutable unless reboot the server
            echo "-[·] check the audit configuration is setted to immutable unless reboot the server"
            local res=$(grep "^\s*[^#]" /etc/audit/audit.rules|tail -1|egrep "-e.*?2")
            if [[ -n $res ]]; then
                auditdRulesIfImmutable="true"
                echo -e "\033[32m-[+] auditd setted -e 2 \033[0m"
            else
                auditdRulesIfImmutable="false"
                echo -e "\033[31m-[-] auditd not setted -e 2 \033[0m"
            fi
        fi
    else
        auditdrulesIfExist="false"
        echo -e "\033[32m-[+] /etc/audit/audit.rules is not exist \033[0m"
    fi
    auditd_rules_info={\"auditdrulesIfExist\":\"$auditdrulesIfExist\",\"auditdRulesIfNotNull\":\"$auditdRulesIfNotNull\",\"auditdIfCheckTimechange\":\"$auditdIfCheckTimechange\",\"auditdRulesCheckedUserandgroupfile\":\"$auditdRulesCheckedUserandgroupfile\",\"auditdRulesNotCheckedUserandgroupfile\":\"$auditdRulesNotCheckedUserandgroupfile\",\"auditdRulesCheckedNetworkenv\":\"$auditdRulesCheckedNetworkenv\",\"auditdRulesNotCheckedNetworkenv\":\"$auditdRulesNotCheckedNetworkenv\",\"auditdRulesCheckedMACchange\":\"$auditdRulesCheckedMACchange\",\"auditdRulesNotCheckedMACchange\":\"$auditdRulesNotCheckedMACchange\",\"auditdRulesCheckedLoginoutEvents\":\"$auditdRulesCheckedLoginoutEvents\",\"auditdRulesNotCheckedLoginoutEvents\":\"$auditdRulesNotCheckedLoginoutEvents\",\"auditdRulesCheckedDACChangeSyscall\":\"$auditdRulesCheckedDACChangeSyscall\",\"auditdRulesNotCheckedDACChangeSyscall\":\"$auditdRulesNotCheckedDACChangeSyscall\",\"auditdRulesCheckedFileAccessAttemptSyscall\":\"$auditdRulesCheckedFileAccessAttemptSyscall\",\"auditdRulesNotCheckedFileAccessAttemptSyscall\":\"$auditdRulesNotCheckedFileAccessAttemptSyscall\",\"auditdRulesCheckedPrivilegedCommand\":\"$auditdRulesCheckedPrivilegedCommand\",\"auditdRulesNotCheckedPrivilegedCommand\":\"$auditdRulesNotCheckedPrivilegedCommand\",\"auditdRulesCheckedSudoerFile\":\"$auditdRulesCheckedSudoerFile\",\"auditdRulesNotCheckedSudoerFile\":\"$auditdRulesNotCheckedSudoerFile\",\"auditdRulesIfImmutable\":\"$auditdRulesIfImmutable\"}
    auditd_check_res={\"auditd_config_info\":$auditd_config_info,\"auditd_rules_info\":$auditd_rules_info}
}

function log_check {
    echo "[·] check log configuration"
	# 5.1 ensure auditd is enabled
    echo "-[·] check rsyslog if is enabled"
	if [[ $(systemctl is-enabled rsyslog) = "enabled" ]]; then
        rsyslogIfEnabled="true"
		echo -e "\033[32m-[+] rsyslog is enabled \033[0m"
	else
        rsyslogIfEnabled="false"
		echo -e "\033[31m-[-] rsyslog is not enabled \033[0m"
	fi
    
    log_check_res={\"rsyslogIfEnabled\":\"$rsyslogIfEnabled\"}

}

function authentication_check {
    echo "[·] check cron ssh pam and env configuration"
    # 6.1 cron configuration
    echo "-[·] check cron configuration"
    # 6.1.1 check cron service is enabled
    echo "-[·] check crond if is enabled"
	if [[ $(systemctl is-enabled crond) = "enabled" ]]; then
		echo -e "\033[32m-[+] crond is enabled \033[0m"
        crondIfEnabled="true"
	else
        crondIfEnabled="false"
		echo -e "\033[31m-[-] crond is not enabled \033[0m"
	fi
    # 6.1.2 check cron's configuration file permission
    echo "-[·] check cron's configuration file permission"
    local keyArray=("/etc/crontab" "/etc/cron.hourly" "/etc/cron.daily" "/etc/cron.weekly" "/etc/cron.monthly" "/etc/cron.d")
    crondConfigFilenameArray=$keyArray
    tmpArray=()
    for i in ${keyArray[@]} ; do
        local res=$(stat $i |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4|cut -d"/" -f1)
        tmpArray+=($res)
        if [[ $res = "0600" ]] || [[ $res = "0700" ]]; then
            echo -e "\033[32m-[+] file $i's permission is $res \033[0m"
        else
            echo -e "\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \033[0m"
        fi
    done
    crondConfigFilePermission=${tmpArray[@]}
    # 6.1.3 check cron.allow cron.deny permission and owner
    echo "-[·] check cron.allow cron.deny configuration file permission"
    local keyArray=("/etc/cron.allow" "/etc/cron.deny")
    crondallowdenyFilenameArray=$keyArray
    tmpArray1=()
    tmpArray2=()
    tmpArray3=()
    for i in ${keyArray[@]} ; do
        if [[ ! -f $i ]]; then
            tmpArray1+=("false")
            echo -e "\033[31m-[-] file $i not exist \033[0m"
            continue
        else
            tmpArray1+=("true")
        fi
        local res1=$(stat $i |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4|cut -d"/" -f1)
        tmpArray2+=($res1)
        local res2=$(stat $i |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f3,4|sed 's/)//g'|cut -d" " -f3,6)
        tmpArray3+=("$res2")
        if [[ $res1 = "0600" ]] || [[ $res1 = "0700" ]]; then
            echo -e "\033[32m-[+] file $i's permission is $res \033[0m"
        else
            echo -e "\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \033[0m"
        fi
        if [[ $res2 = "root root" ]]; then
            echo -e "\033[32m-[+] file $i's owner is $res2 \033[0m"
        else
            echo -e "\033[31m-[-] file $i's owner is not root \033[0m"
        fi
    done
    crondallowdenyFileIfExistArray=${tmpArray1[@]}
    crondallowdenyFilePermissionArray=${tmpArray2[@]}
    crondallowdenyFileOwnerArray=${tmpArray3[@]}
    crond_config_info={\"crondIfEnabled\":\"$crondIfEnabled\",\"crondConfigFilenameArray\":\"$crondConfigFilenameArray\",\"crondConfigFilePermissionArray\":\"$crondConfigFilePermissionArray\",\"crondallowdenyFilenameArray\":\"$crondallowdenyFilenameArray\",\"crondallowdenyFileIfExistArray\":\"$crondallowdenyFileIfExistArray\",\"crondallowdenyFilePermissionArray\":\"$crondallowdenyFilePermissionArray\",\"crondallowdenyFileOwnerArray\":\"$crondallowdenyFileOwnerArray\"}
    # 6.2 SSH configuration
    echo "-[·] check ssh configuration"
	if [[ $(systemctl is-enabled sshd) = "enabled" ]]; then
        sshdIfEnabled="true"
        # 6.2.1 /etc/ssh/sshd_config permission 0600
        local file="/etc/ssh/sshd_config"
        local res=$(stat $file |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4|cut -d"/" -f1)
        if [[ $res = "0600" ]]; then
            sshdConfigFilePermission=$res
            echo -e "\033[32m-[+] file $file's access permission is $res \033[0m"
        else
            sshdConfigFilePermission="false"
            echo -e "\033[3-m-[-] file $file's access permission is $res \033[0m"
        fi
        # 6.2.2 check ssh x11 forwarding if is disabled
        local res=$(grep "^X11Forwaring" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep no) ]]; then
            sshdIfDisableX11forwarding="true"
            echo -e "\033[32m-[+] X11Forwarding no \033[0m"
        else
            sshdIfDisableX11forwarding="false"
            echo -e "\033[31m-[-] not set X11Forwarding no \033[0m"
        fi
        # 6.2.3 check ssh MaxAUTHTries if is 4
        local res=$(grep "^MaxAuthTries" /etc/ssh/sshd_config)
        if [[ -n $res ]]; then
            sshdIfSetMaxAuthTries=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\2/')
            echo -e "\033[32m-[+] $res \033[0m"
        else
            sshdIfSetMaxAuthTries="false"
            echo -e "\033[31m-[-] not set MaxAuthTries \033[0m"
        fi
        # 6.2.4 check ssh IgnoreRhosts if is enabled
        local res=$(grep "^IgnoreRhosts" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep yes) ]]; then
            sshdIfEnableIgnoreRhosts="true"
            echo -e "\033[32m-[+] IgnoreRhosts yes \033[0m"
        else
            sshdIfEnableIgnoreRhosts="false"
            echo -e "\033[31m-[-] not set IgnoreRhosts no\033[0m"
        fi
        # 6.2.5 check ssh HostbasedAuthentication if is disabled
        local res=$(grep "^HostbasedAuthentication" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep no) ]]; then
            sshdIfDisableHostbasedAuthentication="true"
            echo -e "\033[32m-[+] HostbasedAuthentication no \033[0m"
        else
            sshdIfDisableHostbasedAuthentication="false"
            echo -e "\033[31m-[-] not set HostbasedAuthentication no\033[0m"
        fi
        # 6.2.6 check ssh root login if is diabled
        local res=$(grep "^PermitRootLogin" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep no) ]]; then
            sshdIfDisablePermitRootLogin="true"
            echo -e "\033[32m-[+] PermitRootLogin no \033[0m"
        else
            sshdIfDisablePermitRootLogin="false"
            echo -e "\033[31m-[-] not set PermitRootLogin no\033[0m"
        fi
        # 6.2.7 check ssh PermitEmptyPasswords if is diabled
        local res=$(grep "^PermitEmptyPasswords" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep no) ]]; then
            sshdIfDisablePermitEmptyPasswords="true"
            echo -e "\033[32m-[+] PermitEmptyPasswords no \033[0m"
        else
            sshdIfDisablePermitEmptyPasswords="false"
            echo -e "\033[31m-[-] not set PermitEmptyPasswords no\033[0m"
        fi
        # 6.2.8 check ssh PermitUserEnvironment if is diabled
        local res=$(grep "^PermitUserEnvironment" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep no) ]]; then
            sshdIfDisablePermitUserEnvironment="true"
            echo -e "\033[32m-[+] PermitUserEnvironment no \033[0m"
        else
            sshdIfDisablePermitUserEnvironment="false"
            echo -e "\033[31m-[-] not set PermitUserEnvironment no\033[0m"
        fi
        # 6.2.9 check if set specific MAC algorithms
        local res=$(grep "^MACs" /etc/ssh/sshd_config)
        if [[ -n $res ]]; then
            sshdIfSpecificMACs="true"
            echo -e "\033[32m-[+] will use specific MAC algorithms $res \033[0m"
        else
            sshdIfSpecificMACs="false"
            echo -e "\033[31m-[-] not set specific MAC algorithms\033[0m"
        fi
        # 6.2.10 check SSH idle Timeout Interval if is configured
        local res=$(grep "^ClientAliveInterval" /etc/ssh/sshd_config)
        if [[ -n $res ]]; then
            sshdIfSetClientAliveInterval=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\2/')
            echo -e "\033[32m-[+] $res \033[0m"
        else
            sshdIfSetClientAliveInterval="false"
            echo -e "\033[31m-[-] not set ClientAliveInterval \033[0m"
        fi
        # 6.2.11 check SSH LoginGrace Time
        local res=$(grep "^LoginGraceTime" /etc/ssh/sshd_config)
        if [[ -n $res ]]; then
            sshdIfSetLoginGraceTime=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\2/')
            echo -e "\033[32m-[+] $res \033[0m"
        else
            sshdIfSetLoginGraceTime="false"
            echo -e "\033[31m-[-] not set LoginGraceTime \033[0m"
        fi
	else
        sshdIfEnabled="false"
		echo -e "\033[32m-[+] sshd is not enabled \033[0m"
	fi
    sshd_config_info={\"sshdIfEnabled\":\"$sshdIfEnabled\",\"sshdConfigFilePermission\":\"$sshdConfigFilePermission\",\"sshdIfDisableX11forwarding\":\"$sshdIfDisableX11forwarding\",\"sshdIfSetMaxAuthTries\":\"$sshdIfSetMaxAuthTries\",\"sshdIfEnableIgnoreRhosts\":\"$sshdIfEnableIgnoreRhosts\",\"sshdIfDisableHostbasedAuthentication\":\"$sshdIfDisableHostbasedAuthentication\",\"sshdIfDisablePermitRootLogin\":\"$sshdIfDisablePermitRootLogin\",\"sshdIfDisablePermitEmptyPasswords\":\"$sshdIfDisablePermitEmptyPasswords\",\"sshdIfDisablePermitUserEnvironment\":\"$sshdIfDisablePermitUserEnvironment\",\"sshdIfSpecificMACs\":\"$sshdIfSpecificMACs\",\"sshdIfSetClientAliveInterval\":\"$sshdIfSetClientAliveInterval\",\"sshdIfSetLoginGraceTime\":\"$sshdIfSetLoginGraceTime\"}

    # 6.3 PAM configuration
    echo "-[·] check pam configuration"
    # 6.3.1 password creation policy
    if [[ -f /etc/security/pwquality.conf ]]; then
        pamPwqualityconfIfExist="true"
        local minlen=$(grep ^minlen /etc/security/pwquality.conf | sed 's/ //g')
        local minclass=$(grep ^minclass /etc/security/pwquality.conf |sed 's/ //g')
        if [[ -n $minlen ]]; then
            pamIfSetMinlen=$(echo $minlen|cut -d= -f2)
            echo -e "\033[32m-[+] minimime length of password is $(echo $minlen|cut -d= -f2) \033[0m"
        else
            pamIfSetMinlen="false"
            echo -e "\033[31m-[-] not set minlen \033[0m"
        fi
        if [[ -n $minclass ]]; then
            pamIfSetMinclass=$(echo $minclass|cut -d= -f2)
            echo -e "\033[32m-[+] minclass of password is $(echo $minclass|cut -d= -f2) \033[0m"
        else
            local keyArray=("^dcredit" "^lcredit" "^ocredit" "^ucredit")
            local tmpCount=0
            for i in ${keyArray[@]}; do
                if [[ -n  $(grep $i /etc/security/pwquality.conf) ]]; then
                    tmpCount=$(expr 1 + $tmpCount)
                fi
            done
            if [[ $tmpCount = 0 ]]; then
                pamIfSetMinclass="false"
            else
                pamIfSetMinclass=$tmpCount
            fi
            if [[ tmpCount -ge 2 ]]; then
                echo -e "\033[32m-[+] minclass of passwd is $tmpCount \033[0m"
            else
                echo -e "\033[31m-[-] not set minclass \033[0m"
            fi
        fi
    else
        pamPwqualityconfIfExist="false"
    fi
    # 6.3.2 lock account and unlock time
    local files=("/etc/pam.d/password-auth" "/etc/pam.d/system-auth")
    local keyArray=("pam_faillock\.so.*?unlock_time")
    tmpArray1=()
    tmpArray2=()
    for i in ${files[@]}; do
        for k in ${keyArray[@]}; do
            if [[ -n $(egrep $k $i ) ]]; then
                echo -e "\033[32m-[+] set lock and unlock_time in $i \033[0m"
                tmpArray1+=($i)
            else
                tmpArray2+=($i)
                echo -e "\033[31m-[-] not set lock and unlock_time in $i \033[0m"
            fi
        done
    done
    sshdSetedLockAndUnlockTimeFiles=${tmpArray1[@]}
    sshdNotSetedLockAndUnlockTimeFiles=${tmpArray2[@]}
    # 6.3.3 check password reuse if is limited
    sshdPamdFileArray=${files[@]}
    tmpArray=()
    for i in ${files[@]}; do
        local res=$(egrep '^password\s+sufficient\s+pam_unix.so' $i)
        if [[ -n $res ]] && [[ $res =~ "remember=" ]]; then
            local tmp=$(echo $res|sed 's/.*\(remember=[[:digit:]]\).*/\1/g'|sed 's/ //g'|cut -d= -f2)
            tmpArray+=($tmp)
            echo -e "\033[32m-[+] password reuse limit is $tmp in $i \033[0m"
        else
            tmpArray+=("false")
            echo -e "\033[31m-[-] passowrd reuse limit not set in $i \033[0m"
        fi
    done
    sshdPamdFileReuseLimitArray=${tmpArray[@]}
    # 6.3.4 check the algorithm of store password if is sha512
    tmpArray=()
    for i in ${files[@]}; do
        local res=$(egrep '^password\s+sufficient\s+pam_unix.so' $i)
        if [[ -n $res ]] && [[ $res =~ "sha512" ]]; then
            tmpArray+=("true")
            echo -e "\033[32m-[+] password storage algorithm is set to sha512 in $i \033[0m"
        else
            tmpArray+=("false")
            echo -e "\033[31m-[-] password storage algorithm is not specific to sha512 in $i \033[0m"
        fi
    done
    sshdPamdFileIfSetSha512=${tmpArray[@]}
    pam_config_info={\"pamPwqualityconfIfExist\":\"$pamPwqualityconfIfExist\",\"pamIfSetMinlen\":\"$pamIfSetMinlen\",\"pamIfSetMinclass\":\"$pamIfSetMinclass\",\"sshdSetedLockAndUnlockTimeFiles\":\"$sshdSetedLockAndUnlockTimeFiles\",\"sshdNotSetedLockAndUnlockTimeFiles\":\"$sshdNotSetedLockAndUnlockTimeFiles\",\"sshdPamdFileArray\":\"$sshdPamdFileArray\",\"sshdPamdFileReuseLimitArray\":\"$sshdPamdFileReuseLimitArray\",\"sshdPamdFileIfSetSha512\":\"$sshdPamdFileIfSetSha512\"}
    # 6.4 user accounts and environment
    echo "-[·] check user accounts and environment"
    if [[ -f /etc/login.defs ]]; then
        accountLogindefsIfExist="true"
        # 6.4.1 basic settings
        local file='/etc/login.defs'
        passMaxDays=$(grep ^PASS_MAX_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\1/g')
        passMinDays=$(grep ^PASS_MIN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\1/g')
        passWarnAge=$(grep ^PASS_WARN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\1/g')
        inactive=$(useradd -D|grep INACTIVE|sed 's/ //g'|cut -d= -f2)
        accountPassMaxDays=$passMaxDays
        accountPassMinDays=$passMinDays
        accountPassWarnDays=$passWarnAge
        accountPassAutolockInactiveDays=$inactive
        if [[ $passMaxDays -le 90 ]]; then
            echo -e "\033[32m-[+] the maximume days of password have to change is $passMaxDays \033[0m"
        else
            echo -e "\033[31m-[-] the maximume days of password have to change is $passMaxDays ,should less than 90 day\033[0m"
        fi
        if [[ $passMinDays -ge 7 ]]; then
            echo -e "\033[32m-[+] the minimume days of password have to change is $passMinDays \033[0m"
        else
            echo -e "\033[31m-[-] the minimume days of password have to change is $passMinDays ,should great than 7 day\033[0m"
        fi
        if [[ $passWarnAge -ge 7 ]]; then
            echo -e "\033[32m-[+] the minimume days of warn password need to change is $passWarnAge \033[0m"
        else
            echo -e "\033[31m-[-] the minimume days of warn password need to change is $passWarnAge ,should greate than 7 day\033[0m"
        fi
        if [[ $inactive != -1 ]]; then
            echo -e "\033[32m-[+] auto lock account when the  $inactive day haven't login \033[0m"
        else
            echo -e "\033[31m-[-] haven't set day of auto lock accounts \033[0m"
        fi
        # 6.4.2 check system's account if is unlogin
        local res=$(egrep -v "^\+" /etc/passwd | awk -F: '($1!="root" && $1!="sync" && $1!="shutdown" && $1!="halt" && $3<1000 && $7!="/sbin/nologin" && $7!="/bin/false") {print $1}')
        accountShouldUnloginAray=()
        if [[ -z $res ]]; then
            echo -e "\033[32m-[+] system account can't login \033[0m"
        else
            accountShouldUnloginAray=($(echo $res|sed 's/\n/ /g'))
            echo -e "\033[31m-[-]  ($(echo $res|sed 's/\n/ /g'))user's shell need set to /sbin/nologin \033[0m"
        fi
        # 6.4.3 check default group for the root account if is GID 0
        local res=$(grep "^root:" /etc/passwd|cut -d: -f4)
        accountGIDOfRoot=$res
        if [[ $res = 0 ]]; then
            echo -e "\033[32m-[+] default group for the root account is GID 0 \033[0m"
        else
            echo -e "\033[31m-[-]] default group for the root account is is GID $res,not GID 0 \033[0m"
        fi
        # 6.4.4 check default user shell timeout if is 900 seconds or less
        local files=("/etc/bashrc" "/etc/profile")
        tmpArray1=()
        tmpArray2=()
        for file in ${files[@]}; do
            if [[ ! -f $file ]]; then
                continue
            else
                tmpArray1+=($file)
            fi
            local res=$(grep "^TMOUT" $file|sed 's/ //g'|cut -d= -f2)
            tmpArray2+=($res)
            if [[ -z $res ]]; then
                echo -e "\033[31m-[-] not set TMOUT in file $file \033[0m"
                continue
            fi
            if [[ $res -le 900 ]]; then
                echo -e "\033[32m-[+] when idle time great than $res seconds will close connection \033[0m"
            else
                echo -e "\033[31m-[-] when idle time great than $res seconds will close connection,the time should less than 900 seconds \033[0m"
            fi
        done
        accountProfileFileArray=${tmpArray1[@]}
        accountProfileTMOUTArray=${tmpArray2[@]}
        # 6.4.5 check access to su command if is restricted
        local res=$(grep pam_wheel.so /etc/pam.d/su)
        accountIfSetUsersCanAccessSuCommand=
        if [[ -n $res ]]; then
            local res=$(grep wheel /etc/group|cut -d: -f4)
            if [[ -n $res ]]; then
                accountIfSetUsersCanAccessSuCommand=$res
                echo -e "\033[32m-[+] access to su command is specific to $res \033[0m"
            else
                accountIfSetUsersCanAccessSuCommand="false"
                echo -e "\033[31m-[-] access to su command is not restricted \033[0m"
            fi
        else
            accountIfSetUsersCanAccessSuCommand="false"
            echo -e "\033[31m-[-] access to su command is not restricted \033[0m"
        fi
    else
        accountLogindefsIfExist="false"
        echo -e "\033[31m-[-] file /etc/login.defs is not exist \033[0m"
    fi
    account_config_info={\"accountPassMaxDays\":\"$accountPassMaxDays\",\"accountPassMinDays\":\"$accountPassMinDays\",\"accountPassWarnDays\":\"$accountPassWarnDays\",\"accountPassAutolockInactiveDays\":\"$accountPassAutolockInactiveDays\",\"accountShouldUnloginArray\":\"$accountShouldUnloginArray\",\"accountGIDOfRoot\":\"$accountGIDOfRoot\",\"accountProfileFileArray\":\"$accountProfileFileArray\",\"accountProfileTMOUTArray\":\"$accountProfileTMOUTArray\",\"accountIfSetUsersCanAccessSuCommand\":\"$accountIfSetUsersCanAccessSuCommand\"}
    authentication_check_res={\"crond_config_info\":$crond_config_info,\"sshd_config_info\":$sshd_config_info,\"pam_config_info\":$pam_config_info,\"account_config_info\":$account_config_info}
}

function system_check {
    echo "[·] check permission of important file and configuration of user and group"
    # 7.1 check permission of important file and uid gid
    echo "-[·] check permission of important file"
    local files=("/etc/passwd" "/etc/shadow" "/etc/group" "/etc/gshadow" "/etc/passwd-" "/etc/shadow-" "/etc/group-" "/etc/gshadow-")
    importantFilenameArray=${files[@]}
    tmpArray1=()
    tmpArray2=()
    for file in ${files[@]}; do
        local perm=$(stat $file |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4|cut -d"/" -f1)
        local uidGid=$(stat /etc/passwd |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f3,4|sed 's/ //g'|sed -r 's/([[:digit:]]{1,}).*([[:digit:]]{1,}).*/\1 \2/g'|cut -d" " -f1,2)
        tmpArray1+=($perm)
        tmpArray2+=($uidGid)
        if [[ $file =~ "shadow" ]]; then
            if [[ $perm = "0000" ]]; then
                echo -e "\033[32m-[+] file $file's permission is $perm \033[0m"
            else
                echo -e "\033[31m-[-] file $file's permission is $perm,should set to 0000 \033[0m"
            fi
        else
            if [[ $perm = "0644" ]]; then
                echo -e "\033[32m-[+] file $file's permission is $perm \033[0m"
            else
                echo -e "\033[31m-[-] file $file's permission is $perm,should set to 0644 \033[0m"

            fi
        fi
        if [[ $uidGid = "0 0" ]]; then
            echo -e "\033[32m-[+] file $file's uid gid is $uidGid \033[0m"
        else
            echo -e "\033[31m-[-] file $file's uid gid is $uidGid,should set to 0 0 \033[0m"
        fi
    done
    importantFilePermissionArray=${tmpArray1[@]}
    importantFileUidgidArray=${tmpArray2[@]}
    file_permission_info={\"importantFilenameArray\":\"$importantFilenameArray\",\"importantFilePermissionArray\":\"$importantFilePermissionArray\",\"importantFileUidgidArray\":\"$importantFileUidgidArray\"}
    # 7.2 check configuration of user and group
    echo "-[·] check configuration of user and group"
    # 7.2.1 check if user's password is empty
    users=$(cat /etc/shadow |awk -F: '($2=="!!"){print $1}'|while read x;do 
        res=$(grep ${x} /etc/passwd|cut -d: -f7); if [[ $res != "/sbin/nologin" ]] && [[ $res != "/sbin/shutdon" ]] && [[ $res != "/sbin/halt" ]]; then 
            echo $x
            #echo -e "\033[31m-[-] $x should have a passwd,not empty \033[0m"; 
            fi;
        done)
    if [[ -z $users ]]; then
        userIfSetPasswdOrArray="true"
        echo -e "\033[32m-[+] all user account have set password \033[0m"
    else
        userIfSetPasswdOrArray=$(echo $users|sed 's/\n/ /g')
        echo -e "\033[31m-[-] user:$(echo $users|sed 's/\n/ /g') should set a password ,rather than empty \033[0m"
    fi
    # 7.2.2 check if root is the only UID 0 account
    local users=$(cat /etc/passwd|awk -F: '($3==0){print $1}')
    if [[ $users = 'root' ]]; then
        uid0OnlyRootOrArray="true"
        echo -e "\033[32m-[+] root is the only account that uid is 0 \033[0m"
    else
        uid0OnlyRootOrArray=$(echo $users|sed 's/root//g'|sed 's/\n/ /g')
        echo -e "\033[31m-[-] $(echo $users|sed 's/root//g'|sed 's/\n/ /g') uid should not be 0 \033[0m"
    fi
    # 7.2.3 check root PATH integrith
    if [ "$(echo $PATH|grep ::)" != "" ]; then
        echo -e "\033[31m-[-] Empty Directory in PATH (::) \033[0m"
    fi
    if [ "$(echo $PATH|grep :$)" != "" ]; then
        echo -e "\033[31m-[-] Trailing : in PATH \033[0m"
    fi
    path=$( echo $PATH|sed -e 's/::/:/' -e 's/:$//' -e 's/:/ /g')
    tmpArray1=()
    tmpArray2=()
    tmpArray3=()
    tmpArray4=()
    tmpArray5=()
    set -- $path
    while [[ $1 != "" ]]; do
        if [[ $1 = "." ]]; then
            echo -e "\033[31m-[-] PATH contains . \033[0m"
            tmpArray1+=(".")
            shift
            continue
        fi
        if [[ -d $1 ]]; then
            local dirperm=$(ls -ldH $1|cut -d" " -f1)
            if [[ $(echo $dirperm|cut -c6) != "-" ]]; then
                tmpArray2+=($1)
                echo -e "\033[31m-[-] Group Write permission should not set on directory $1 \033[0m"
            fi
            if [[ $(echo $dirperm|cut -c9) != "-" ]]; then
                tmpArray3+=($1)
                echo -e "\033[31m-[-] Other Write permission should not set on directory $1 \033[0m"
            fi
            local dirown=$(ls -ldH $1|awk '{print $3}')
            if [[ $dirown != "root" ]]; then
                tmpArray4+=($1)
                echo -e "\033[31m-[-] dir $1's owner is $dirown,should be root \033[0m"
            fi
        else
            tmpArray5+=($1)
            echo -e "\033[31m-[-] $1 is not a directory or not exist \033[0m"
        fi
        shift
    done
    if [[ ${#tmpArray1[@]} = 0 ]]; then
        pathDirIfNotHasDot="true"
    else
        pathDirIfNotHasDot="false"
    fi
    pathDirPermissionHasGWArray=${tmpArray2[@]}
    pathDirPermissionHasOWArray=${tmpArray2[@]}
    pathDirOwnerIsNotRootArray=${tmpArray4[@]}
    pathDirDoesNotExistOrNotDirArray=${tmpArray5[@]}
    # 7.2.4 check if is all users' home directories exist
    #cat /etc/passwd|egrep -v '^(root|halt|sync|shutdown)'|awk -F: '($7 != "/sbin/nologin" && $7 != "/bin/false"){print $1 " " $6}'|while read user dir; do
    tmpArray1=()
    tmpArray2=()
    tmpArray3=()
    tmpArray4=()
    tmpArray5=()
    tmpArray6=()
    while read user dir; do
        tmpArray1+=($dir)
        if [[ ! -d $dir ]]; then
            tmpArray2+=("false")
            tmpArray3+=("false")
            echo -e "\033[31m-[-] the home directory ($dir) of user $user does not exist \033[0m"

        else
            tmpArray2+=("true")
            # 7.2.5 check if users' home directories permissions are 750 or more restrictive
            local dirperm=$(ls -ld $dir|cut -d" " -f1)
            tmpArray3+=($dirperm)
            if [[ $(echo $dirperm |cut -c6) != "-" ]]; then
                echo -e "\033[31m-[-] Group Write permission set on the home directory ($dir) of user $user \033[0m"
            fi
            if [[ $(echo $dirperm |cut -c8) != "-" ]]; then
                echo -e "\033[31m-[-] Other Read permission set on the home directory ($dir) of user $user \033[0m"
            fi
            if [[ $(echo $dirperm |cut -c9) != "-" ]]; then
                echo -e "\033[31m-[-] Other Write permission set on the home directory ($dir) of user $user \033[0m"
            fi
            if [[ $(echo $dirperm |cut -c10) != "-" ]]; then
                echo -e "\033[31m-[-] Other Execute permission set on the home directory ($dir) of user $user \033[0m"
            fi
            # 7.2.6 check if is users own their home directory
            local owner=$(stat -L -c "%U" $dir)
            if [[ $owner != $user ]]; then
                tmpArray4+=("false")
                echo -e "\033[31m-[-]The home directory ($dir) of user $user is owned by $owner \033[0m"
            else
                tmpArray4+=("true")
            fi
            # 7.2.7 check users' dot files are not group or world  writable
            local tmpc=0
            for file in $dir/.[A-Za-z0-9]*; do
                if [[ ! -h $file ]] && [[ -f $file ]]; then
                    local fileperm=$(ls -ld $file|cut -d" " -f1)
                    if [[ $(echo $fileperm|cut -c6) != "-" ]]; then
                        tmpc=$(expr $tmpc + 1)
                        echo -e "\033[31m-[-] Group Write permission set on file $file \033[0m"
                    fi
                    if [[ $(echo $fileperm|cut -c9) != "-" ]]; then
                        tmpc=$(expr $tmpc + 1)
                        echo -e "\033[31m-[-] Other Write permission set on file $file \033[0m"
                    fi
                fi
            done
            if [[ $tmpc = 0 ]]; then
                tmpArray5+=("true")
            else
                tmpArray5+=("false")
            fi
            # 7.2.8 check if no usrs have .netrc .rhosts .forward file
            tmpc=0
            if [[ ! -h $dir/.netrc ]] && [[ -f $dir/.netrc ]]; then
                tmpc=$(expr $tmpc + 1)
                echo -e "\033[31m-[-] .netrc file $dir/.netrc exists \033[0m"
            fi
            if [[ ! -h $dir/.rhosts ]] && [[ -f $dir/.rhosts ]]; then
                tmpc=$(expr $tmpc + 1)
                echo -e "\033[31m-[-] .rhosts file $dir/.rhosts exists \033[0m"
            fi
            if [[ ! -h $dir/.forward ]] && [[ -f $dir/.forward ]]; then
                tmpc=$(expr $tmpc + 1)
                echo -e "\033[31m-[-] .forward file $dir/.forward exists \033[0m"
            fi
            if [[ $tmpc = 0 ]]; then
                tmpArray6+=("true")
            else
                tmpArray6+=("false")
            fi
        fi
    done < <(cat /etc/passwd|egrep -v '^(root|halt|sync|shutdown)'|awk -F: '($7 != "/sbin/nologin" && $7 != "/bin/false"){print $1 " " $6}')
    userArray=${tmpArray1[@]}
    userHomeDirIfExistArray=${tmpArray2[@]}
    UserHomeDirPermissionArray=${tmpArray3[@]}
    userIfOwnTheirHomeDirArray=${tmpArray4[@]}
    userHomeDirIfHasGWorOWDotFileArray=${tmpArray5[@]}
    userHomeDirIfHasOtherFileArray=${tmpArray6[@]}
    # 7.2.9 check if all groups in /etc/passwd exist in /etc/group
    tmpArray=()
    for i in $(cut -d: -s -f4 /etc/passwd|sort -u); do
        grep -q -P "^.*?:[^:]*:$i" /etc/group
        if [[ $? -ne 0 ]]; then
        tmpArray+=($i)
            echo -e "\033[31m-[-] Group $i is referenced by /etc/passwd but does not exist in /etc/group \033[0m"
        fi
    done
    groupNotExistInetcgroup=${tmpArray[@]}
    # 7.2.10 check if every user has a unique UID
    #cat /etc/passwd|cut -d":" -f3|sort -n|uniq -c|while read x; do
    tmpArray=()
    while read x; do
        [[ -z $x ]] && break
        set - $x
        if [[ $1 -gt 1 ]]; then
            local users=$(awk -F: '($3==n){print $1}' n=$2 /etc/passwd|xargs)
            tmpArray+=($2:$users\;)
            echo -e "\033[31m-[-] Duplicate UID $2 : $users \033[0m"
        fi
    done < <(cat /etc/passwd|cut -d":" -f3|sort -n|uniq -c)
    usersIfHasUniqueUIDArray=${tmpArray[@]}
    # 7.2.11 check if every group has a unique GID
    tmpArray=()
    #cat /etc/group|cut -d":" -f3|sort -n|uniq -c|while read x; do
    while read x; do
        [[ -z $x ]] && break
        set - $x
        if [[ $1 -gt 1 ]]; then
            local groups=$(awk -F: '($3==n){print $1}' n=$2 /etc/group|xargs)
            tmpArray+=($2:$groups\;)
            echo -e "\033[31m-[-] Duplicate GID $2 : $groups \033[0m"
        fi
    done < <(cat /etc/group|cut -d":" -f3|sort -n|uniq -c)
    groupsIfHasUniqueGIDArray=${tmpArray[@]}
    # 7.2.12 check if user name is unique
    tmpArray=()
    #cat /etc/passwd|cut -d":" -f1|sort -n|uniq -c|while read x; do
    while read x; do
        [[ -z $x ]] && break
        set - $x11
        if [[ $1 -gt 1 ]]; then
            local uids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/passwd|xargs)
            tmpArray+=($2:$uids\;)
            echo -e "\033[31m-[-] Duplicate user name $2 : $uids \033[0m"
        fi
    done < <(cat /etc/passwd|cut -d":" -f1|sort -n|uniq -c)
    usersIfHasUniqueNameArray=${tmpArray[@]}
    # 7.2.13 check if group name is unique
    tmpArray=()
    #cat /etc/group|cut -d":" -f1|sort -n|uniq -c|while read x; do
    while read x; do
        [[ -z $x ]] && break
        set - $x11
        if [[ $1 -gt 1 ]]; then
            local gids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/group|xargs)
            tmpArray+=($2:$gids\;)
            echo -e "\033[31m-[-] Duplicate group name $2 : $gids \033[0m"
        fi
    done < <(cat /etc/group|cut -d":" -f1|sort -n|uniq -c)
    groupsIfHasUniqueNameArray=${tmpArray[@]}
    usergroup_config_info={\"userIfSetPasswdOrArray\":\"$userIfSetPasswdOrArray\",\"uid0OnlyRootOrArray\":\"$uid0OnlyRootOrArray\",\"pathDirIfNotHasDot\":\"$pathDirIfNotHasDot\",\"pathDirPermissionHasGWArray\":\"$pathDirPermissionHasGWArray\",\"pathDirPermissionHasOWArray\":\"$pathDirPermissionHasOWArray\",\"pathDirOwnerIsNotRootArray\":\"$pathDirOwnerIsNotRootArray\",\"pathDirDoesNotExistOrNotDirArray\":\"$pathDirDoesNotExistOrNotDirArray\",\"userArray\":\"$userArray\",\"userHomeDirIfExistArray\":\"$userHomeDirIfExistArray\",\"UserHomeDirPermissionArray\":\"$UserHomeDirPermissionArray\",\"userIfOwnTheirHomeDirArray\":\"$userIfOwnTheirHomeDirArray\",\"userHomeDirIfHasGWorOWDotFileArray\":\"$userHomeDirIfHasGWorOWDotFileArray\",\"userHomeDirIfHasOtherFileArray\":\"$userHomeDirIfHasOtherFileArray\",\"groupNotExistInetcgroup\":\"$groupNotExistInetcgroup\",\"usersIfHasUniqueUIDArray\":\"$usersIfHasUniqueUIDArray\",\"groupsIfHasUniqueGIDArray\":\"$groupsIfHasUniqueGIDArray\"}
    system_check_res={\"file_permission_info\":$file_permission_info,\"usergroup_config_info\":$usergroup_config_info}

}

echo """
==================================
|        Linux 基线检查工具      |
|        author:JC0o0l           |
|        version:2.0             |
==================================
"""
get_basic_info
init_check
service_check
network_check
auditd_check
log_check
authentication_check
system_check
if [[ -z $authentication_check_res ]]; then
    authentication_check_res={}
fi
if [[ -z $system_check_res ]]; then
    system_check_res={}
fi
check_result={\"basic_info\":$basic_info,\"init_check_res\":$init_check_res,\"service_check\":$service_check_res,\"network_check_res\":$network_check_res,\"auditd_check_res\":$auditd_check_res,\"log_check_res\":$log_check_res,\"authentication_check_res\":$authentication_check_res,\"system_check_res\":$system_check_res}
curl -X POST "http://192.168.3.24:8888/baseline/show/" -H "accept:application/json" -H "content-type:application/json" -d "$check_result" 1>/dev/null 2>/dev/null
echo $check_result|jq 

================================================
FILE: baseline_check_v2.2_JC0o0l.sh
================================================
#!/bin/bash
function get_ip_info {
    local ipList=`ifconfig | grep inet |grep -v inet6|grep -v 127|sed 's/^[ ]*//g'|cut -d" " -f2`
    echo $ipList
}
function get_basic_info {
    echo [·] collect basic info
    scanTime=$(date "+%Y-%m-%d %H:%M:%S")
    hostname=`hostname`
    macaddr=$(echo $(ifconfig|grep "ether"|sed 's/^[ ]*//g'|cut -d" " -f2)|sed 's/ /;/g')
    ipList=$(get_ip_info|sed 's/ /;/g')
    kernelVersion=`uname -r`
    if [[ $(cat /proc/version) =~ "Red Hat" ]]; then
        osVersion=`cat /etc/redhat-release|cut -f1,4 -d" "`
    fi
    basic_info={\"scanTime\":\"$scanTime\",\"hostname\":\"$hostname\",\"macaddr\":\"$macaddr\",\"ipList\":\"$ipList\",\"kernelVersion\":\"$kernelVersion\",\"osVersion\":\"$osVersion\"}
    echo $basic_info
}

function init_check {
    # 1. init configuration
    echo [·] check init configuration
    # 1.1 file system configuration
    # 1.1.1 /tmp separate mount
    local tmpIfSeparate #=""
    local tmpIfNoexec #=""
    local tmpIfNosuid #=""
    local res=$(mount|grep "/tmp ") 
    if [[ -z $res ]]; then
        echo -e "\033[31m-[-] /tmp/ not mounted on separate dick\033[0m"
        tmpIfSeparate="False"
        tmpIfNoexec="False"
        tmpIfNosuid="False"
    else
        tmpIfSeparate="True"
        tmpIfNoexec="True"
        tmpIfNosuid="True"
    fi
    if [[ $tmpIfSeparate == "True" ]]; then
        #mount|grep "/sys/kernel/debug " |while read res;do
        while read res;do
            #echo "mount | grep /sys --result-->" $res
            # 1.1.2 /tmp noexec nosuid
            local diskPart=$(echo $res|cut -d" " -f3)
            if [[ ! $res =~ "noexec" ]];then
                echo -e "\033[31m-[-] no noexec option on $diskPart partion\033[0m"
                tmpIfNoexec="False"
                if [[ ! $res =~ "nosuid" ]];then
                    echo -e "\033[31m-[-] no nosuid option on $diskPart partion\033[0m"
                    tmpIfNosuid="False"
                fi
            elif [[ ! $res =~ "nosuid" ]];then
                echo -e "\033[31m-[-] no nosuid option on $diskPart partion\033[0m"
                tmpIfNosuid="False"
            fi
        done < <(mount | grep "/tmp ")
    fi
    tmp_partition_info={\"tmpIfSeparate\":\"$tmpIfSeparate\",\"tmpIfNoexec\":\"$tmpIfNoexec\",\"tmpIfNosuid\":\"$tmpIfNosuid\"}
    #echo $tmp_partition_info
    # 1.2 secure boot configuration
    if [[ -f /boot/grub2/grub.cfg ]];then
        grubcfgIfExist="True"
        grubcfgPermission="0600"
        grubcfgIfSetPasswd="True"
    else
        grubcfgIfExist="False"
        grubcfgPermission="0000"
        grubcfgIfSetPasswd="False"
    fi
    if [[ $grubcfgIfExist == "True" ]]; then
        # 1.2.1 /boot/grub2/grub.cfg permission /boot/grub2/user.cfg permission 0600 root:root
        res=$(stat /boot/grub2/grub.cfg |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4)
        grubcfgPermission=$(echo $res|cut -d"/" -f1)
        if [[ $(echo $res|cut -d"/" -f1) = "0600" ]]; then
            echo -e "\033[32m-[+] /boot/grub2/grub.cfg permission is 0600 \033[0m"
        else
            echo -e "\033[31m-[-] /boot/grub2/grub.cfg permission is not 0600 \033[0m"
        fi
        # 1.2.2 Ensure bootloader password is set
        res=$(grep "^GRUB2 PASSWORD" /boot/grub2/grub.cfg)
        if [[ -n $res ]]; then
            echo -e "\033[32m-[+] /boot/grub2/grub.cfg seted password \033[0m"
            grubcfgIfSetPasswd="True"
        else
            echo -e "\033[31m-[-] /boot/grub2/grub.cfg not set password \033[0m"
            grubcfgIfSetPasswd="False"
        fi
    fi
        
    # 1.2.3 single user mode need authentication
    if [[ -f /usr/lib/systemd/system/rescue.service ]] && [[ -f /usr/lib/systemd/system/emergency.service ]]; then
        res1=`grep /sbin/sulogin /usr/lib/systemd/system/rescue.service`
        res2=`grep /sbin/sulogin /usr/lib/systemd/system/emergency.service`
        if [[ $res1 = "ExecStart=-/bin/sh -c \"/usr/sbin/sulogin; /usr/bin/systemctl --fail --no-block default\"" ]] && [[ $res2 = "ExecStart=-/bin/sh -c \"/usr/sbin/sulogin; /usr/bin/systemctl --fail --no-block default\"" ]]; then
            echo -e "\033[32m-[+] single user mode need authentication \033[0m"
            singleUserModeIfNeedAuth="True"
        else
            echo -e "\033[31m-[+] single user mode does not need authentication \033[0m"
            singleUserModeIfNeedAuth="False"
        fi
    fi
    # 1.3 Mantary Access Control
    # 1.3.1 ensure the SELinux state is enforcing
    if [[ -f /etc/selinux/config ]]; then
        local num=$(sestatus|grep -c enforcing)
        if [[ $num -gt 1 ]]; then
            echo -e "\033[32m-[+] SELinux state is enforcing \033[0m"
            selinuxStateIfEnforcing="True"
        else
            echo -e "\033[31m-[-] SELinux state is not enforcing \033[0m"
            selinuxStateIfEnforcing="False"
        fi
    fi
    # 1.3.2 ensure selinux policy is configured
    if [[ -f /etc/selinux/config ]]; then
        res=$(sestatus|grep targeted)
        if [[ -n $res ]]; then
            echo -e "\033[32m-[+] SELinux policy is configured \033[0m"
            selinuxPolicyIfConfigured="True"
        else
            echo -e "\033[31m-[-] SELinux policy is not configure to targeted \033[0m"
            selinuxPolicyIfConfigured="False"
        fi
    fi
    boot_secure_info={\"grubcfgIfExist\":\"$grubcfgIfExist\",\"grubcfgPermission\":\"$grubcfgPermission\",\"grubcfgIfSetPasswd\":\"$grubcfgIfSetPasswd\",\"singleUserModeIfNeedAuth\":\"$singleUserModeIfNeedAuth\",\"selinuxStateIfEnforcing\":\"$selinuxStateIfEnforcing\",\"selinuxPolicyIfConfigured\":\"$selinuxPolicyIfConfigured\"}
    #echo $boot_secure_info
    init_check_res={\"tmp_partition_info\":$tmp_partition_info,\"boot_secure_info\":$boot_secure_info}
}
function service_check {
    # 2. service configuration
    echo [·] check service configuration
    # 2.1 time sync
    # 2.1.1 time sync service is installed
    if $(rpm -q ntp 1>/dev/null||rpm -q chrony 1>/dev/null) ; then
        if $(rpm -q ntp 1>/dev/null) ; then
            if [[ -f /etc/ntp.conf ]]; then
                local res=$(egrep "^(server|pool)" /etc/ntp.conf)
                if [[ -n $res ]]; then
                    echo -e "\033[32m-[+] remote ntp server is configured \033[0m"
                    timeSyncServerIfConfigured="True"
                else
                    echo -e "\033[31m-[-] remote ntp server is not configured \033[0m"
                    timeSyncServerIfConfigured="False"
                fi
            fi
        fi
        if $(rpm -q chrony 1>/dev/null); then
            if [[ -f /etc/chrony.conf ]]; then
                local res=$(egrep "^(server|pool)" /etc/chrony.conf)
                if [[ -n $res ]]; then
                    echo -e "\033[32m-[+] remote chrony server is configured \033[0m"
                    timeSyncServerIfConfigured="True"
                else
                    echo -e "\033[31m-[-] remote chrony server is not configured \033[0m"
                    timeSyncServerIfConfigured="False"
                fi
                
            fi
        fi
    fi        
    # 2.1.2 x-window
    local res=$(rpm -qa xorg-x11*)
    if [[ -z $res ]]; then
        echo -e "\033[32m-[+] x11-windows is not installed \033[0m"
        x11windowIfNotInstalled="True"
    else
        echo -e "\033[31m-[-] x11-windows is installed \033[0m"
        x11windowIfNotInstalled="False"
    fi
    service_check_res={\"timeSyncServerIfConfigured\":\"$timeSyncServerIfConfigured\",\"x11windowIfNotInstalled\":\"$x11windowIfNotInstalled\"}
}
function network_check {
    # 3. network configuration
    echo [·] check network configuration
    # 3.1 hosts file configuration
    # 3.1.1 check /etc/hosts.deny file
    if [[ -f /etc/hosts.deny ]]; then
        hostsDenyFileIfExist="True"
        echo -e "\033[32m-[+] file /etc/hosts.deny exists \033[0m"
        local res=$(stat /etc/hosts.deny |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4)
        hostsDenyFilePermission=$(echo $res|cut -d"/" -f1)
        if [[ $(echo $res|cut -d"/" -f1) = "0644" ]];then
            echo -e "\033[32m-[+] file /etc/hosts.deny permission is 0644 \033[0m"
        else
            echo -e "\033[31m-[-] file /etc/hosts.deny permission is not 0644 \033[0m"
        fi

        local res=$(egrep "^[^#].+" /etc/hosts.deny)
        if [[ -n $res ]]; then
            hostsDenyFileIfConfigured="True"
            echo -e "\033[32m-[+] file /etc/hosts.deny is configured \033[0m"
        else
            hostsDenyFileIfConfigured="False"
            echo -e "\033[31m-[-] file /etc/hosts.deny is not configured \033[0m"
        fi
    else
        hostsDenyFileIfExist="False"
        echo -e "\033[31m-[-] file /etc/hosts.deny does not exists \033[0m"
    fi
    # 3.1.2 check /etc/hosts.allow file
    if [[ -f /etc/hosts.allow ]]; then
        hostsAllowFileIfExist="True"
        echo -e "\033[32m-[+] file /etc/hosts.allow exists \033[0m"
        local res=`stat /etc/hosts.allow |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4`
        hostsAllowFilePermission=$(echo $res|cut -d"/" -f1)
        if [[ $(echo $res|cut -d"/" -f1) = "0644" ]];then
            echo -e "\033[32m-[+] file /etc/hosts.allow permission is 0644 \033[0m"
        else
            echo -e "\033[31m-[-] file /etc/hosts.allow permission is not 0644 \033[0m"
        fi

        local res=$(egrep "^[^#].+" /etc/hosts.deny)
        if [[ -n $res ]]; then
            hostsAllowFileIfConfigured="True"
            echo -e "\033[32m-[+] file /etc/hosts.allow is configured \033[0m"
        else
            hostsAllowFileIfConfigured="False"
            echo -e "\033[31m-[-] file /etc/hosts.allow is not configured \033[0m"
        fi
    else
        hostsAllowFileIfExist="False"
        echo -e "\033[31m-[-] file /etc/hosts.allow does not exists \033[0m"
    fi

    # 3.2 firewall configuration
    # 3.2.1 ensure iptables is installed
    if $(rpm -q iptables 1>/dev/null); then
        iptablesIfInstalled="True"
        echo -e "\033[32m-[+] iptables is installed \033[0m"
        # 3.2.2 ensure INPUT OUTPUT chain policy is DROP
        #iptables -L|grep policy|while read x;do
        while read x;do
            if [[ $x =~ "INPUT" ]] && [[ $x =~ "DROP" ]]; then
                iptablesInputPolicyIfDrop="True"
                echo -e "\033[32m-[+] INPUT chain policy is DROP \033[0m"
            elif [[ $x =~ "INPUT" ]] && [[ ! $x =~ "DROP" ]]; then
                iptablesInputPolicyIfDrop="False"
                echo -e "\033[31m-[-] INPUT chain policy is not DROP \033[0m"
            fi
            if [[ $x =~ "OUTPUT" ]] && [[ $x =~ "DROP" ]]; then
                iptablesOutputPolicyIfDrop="True"
                echo -e "\033[32m-[+] OUTPUT chain policy is DROP \033[0m"
            elif [[ $x =~ "OUTPUT" ]] && [[ ! $x =~ "DROP" ]]; then
                iptablesOutputPolicyIfDrop="False"
                echo -e "\033[31m-[-] OUTPUT chain policy is not DROP \033[0m"
            fi
        done < <(iptables -L|grep policy)
    else
        iptablesIfInstalled="False"
        echo -e "\033[31m-[-] iptables is not installed \033[0m"
    fi
    network_check_res={\"hostsAllowFileIfExist\":\"$hostsAllowFileIfExist\",\"hostsAllowFilePermission\":\"$hostsAllowFilePermission\",\"hostsAllowFileIfConfigured\":\"$hostsAllowFileIfConfigured\",\"hostsDenyFileIfExist\":\"$hostsDenyFileIfExist\",\"hostsDenyFilePermission\":\"$hostsDenyFilePermission\",\"hostsDenyFileIfConfigured\":\"$hostsDenyFileIfConfigured\",\"iptablesIfInstalled\":\"$iptablesIfInstalled\",\"iptablesInputPolicyIfDrop\":\"$iptablesInputPolicyIfDrop\",\"iptablesOutputPolicyIfDrop\":\"$iptablesOutputPolicyIfDrop\"}
}

function auditd_check {
	# 4. auditd configuration
	echo [·] check auditd configuration
	# 4.1 ensure auditd is enabled
    echo "-[·] check auditd if is enabled"
	if [[ $(systemctl is-enabled auditd) = "enabled" ]]; then
		echo -e "\033[32m-[+] auditd is enabled \033[0m"
        auditdIfEnabled="True"
	else
        auditdIfEnabled="False"
		echo -e "\033[31m-[-] auditd is not enabled \033[0m"
	fi
	# 4.2 some settings in /etc/audit/auditd.conf
    echo "-[·] settings in /etc/audit/auditd.conf"	
    if [[ -f /etc/audit/auditd.conf ]]; then
        auditdconfIfExist="True"
        maxLogFile=$(grep "^max_log_file[[:blank:]]=" /etc/audit/auditd.conf|sed "s/ //g"|cut -d"=" -f 2)
        maxLogFileAction=$(grep "^max_log_file_action" /etc/audit/auditd.conf|sed "s/ //g"|cut -d"=" -f 2)
        spaceLeftAction=$(grep "^space_left_action" /etc/audit/auditd.conf|sed "s/ //g"|cut -d"=" -f 2)
        numLogs=$(grep "^num_logs" /etc/audit/auditd.conf|sed "s/ //g"|cut -d"=" -f 2)
        if [[ -n $maxLogFile ]]; then
            auditdIfSetMaxLogFile=$maxLogFile
            echo -e "\033[32m-[+] max_log_file size is ${maxLogFile} M \033[0m"
        else
            auditdIfSetMaxLogFile="False"
            echo -e "\033[31m-[-] max_log_file size is not setted \033[0m"
        fi
        if [[ -n $maxLogFileAction ]]; then
            auditdIfSetMaxLogFileAction="$maxLogFileAction"
            echo -e "\033[32m-[+] max_log_file_action is ${maxLogFileAction}\033[0m"
        else
            auditdIfSetMaxLogFileAction="False"
            echo -e "\033[31m-[-] max_log_file_action is not setted \033[0m"
        fi
        if [[ -n $spaceLeftAction ]]; then
            auditdIfSetSpaceLeftAction="$spaceLeftAction"
            echo -e "\033[32m-[+] space_left_action is ${spaceLeftAction}\033[0m"
        else
            auditdIfSetSpaceLeftAction="False"
            echo -e "\033[31m-[-] space_left_action is not setted \033[0m"
        fi
        if [[ -n $numLogs ]]; then
            auditdIfSetNumLogs="$numLogs"
            echo -e "\033[32m-[+] the num of logs is ${numLogs} \033[0m"
        else
            auditdIfSetNumLogs="False"
            echo -e "\033[31m-[-] num_logs is not setted \033[0m"
        fi
    else
        auditdconfIfExist="False"
    fi
    auditd_config_info={\"auditdIfEnabled\":\"$auditdIfEnabled\",\"auditdconfIfExist\":\"$auditdconfIfExist\",\"auditdIfSetMaxLogFile\":\"$auditdIfSetMaxLogFile\",\"auditdIfSetMaxLogFileAction\":\"$auditdIfSetMaxLogFileAction\",\"auditdIfSetSpaceLeftAction\":\"$auditdIfSetSpaceLeftAction\",\"auditdIfSetNumLogs\":\"$auditdIfSetNumLogs\"}
    #echo $auditd_config_info
    # 4.3 rules in /etc/audit/audit.rules
    # arch 64
    echo "-[·] time-change" 
    if [[ -f /etc/audit/audit.rules ]]; then
        auditdRulesIfExist="True"
        echo -e "\033[32m-[+] /etc/audit/audit.rules is exist \033[0m"
        if [[ ! -n $(grep time /etc/audit/audit.rules) ]]; then
            auditdRulesIfNotNull="False"
            echo -e "\033[31m-[-] not set rule about audit the change of date and time \033[0m"
        else
            auditdRulesIfNotNull="True"
            # 4.3.1 time-change
            local timeChangeList=$(egrep "(stime|clock_settime|adjtimex|settimeofday|/etc/localtime)" /etc/audit/audit.rules|wc -l)
            if [[ ${timeChangeList} -gt 3 ]]; then
                auditdIfCheckTimechange="True"
                echo -e "\033[32m-[+] audith the change of date and time \033[0m"
            elif [[ ${timeChangeList} -gt 1 ]]; then
                auditdIfCheckTimechange="False"
                echo -e "\033[31m-[-] not fully set rule about audit the change of date and time \033[0m"
            else 
                auditdIfCheckTimechange="False"
                echo -e "\033[31m-[-] not set rule about audit the change of date and time \033[0m"
            fi
            # 4.3.2 user and group change
            echo "-[·] user and group change"
            local keyArray=("/etc/passwd" "/etc/group" "/etc/gshadow" "/etc/shadow" "/etc/security/opasswd")
            tmpArray1=()
            tmpArray2=()
            for i in ${keyArray[@]} ; do
                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i\;)
                    echo -e "\033[32m-[+] audit the change of $i \033[0m"
                else
                    tmpArray2+=($i\;)
                    echo -e "\033[31m-[-] not audit the change of $i \033[0m"
                fi
            done
            auditdRulesCheckedUserandgroupfile=$(echo ${tmpArray1[@]}|sed 's/ //g')
            auditdRulesNotCheckedUserandgroupfile=$(echo ${tmpArray2[@]}|sed 's/ //g')
            # 4.3.3 system's network environment change
            echo "-[·] system's network environment change"
            local keyArray=("/etc/issue" "/etc/issue.net" "/etc/hosts" "/etc/sysconfig/network" "/etc/sysconfig/network-scripts/" )
            tmpArray1=()
            tmpArray2=()
            for i in ${keyArray[@]} ; do
                    if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i\;)
                    echo -e "\033[32m-[+] audit the change of $i \033[0m"
                else
                    tmpArray2+=($i\;)
                    echo -e "\033[31m-[-] not audit the change of $i \033[0m"
                fi
            done
            local keyArray=("sethostname" "setdomainname")
            for i in ${keyArray[@]} ; do
                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i\;)
                    echo -e "\033[32m-[+] audit the use of syscall  $i \033[0m"
                else
                    echo -e "\033[31m-[-] not audit the use of syscall $i \033[0m"
                    tmpArray2+=($i\;)
                fi
            done
            auditdRulesCheckedNetworkenv=$(echo ${tmpArray1[@]}|sed 's/ //g')
            auditdRulesNotCheckedNetworkenv=$(echo ${tmpArray2[@]}|sed 's/ //g')
            # 4.3.4 system's Mandatory Access Controls change
            echo "-[·] system's Mandatory Access Controls change"
            local keyArray=("/etc/selinux" "/usr/share/selinux")
            tmpArray1=()
            tmpArray2=()
            for i in ${keyArray[@]} ; do
                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i\;)
                    echo -e "\033[32m-[+] audit the change of   $i \033[0m"
                else
                    tmpArray2+=($i\;)
                    echo -e "\033[31m-[-] not audit the change of $i \033[0m"
                fi
            done
            auditdRulesCheckedMACchange=$(echo ${tmpArray1[@]}|sed 's/ //g')
            auditdRulesNotCheckedMACchange=$(echo ${tmpArray2[@]}|sed 's/ //g')
            # 4.3.5 audit events of login and logout
            echo "-[·] audit events of login and logout"
            local keyArray=("/var/log/lastlog" "/var/run/faillock/")
            tmpArray1=()
            tmpArray2=()
            for i in ${keyArray[@]} ; do
                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i\;)
                    echo -e "\033[32m-[+] audit the change of   $i \033[0m"
                else
                    tmpArray2+=($i\;)
                    echo -e "\033[31m-[-] not audit the change of $i \033[0m"
                fi
            done
            auditdRulesCheckedLoginoutEvents=$(echo ${tmpArray1[@]}|sed 's/ //g')
            auditdRulesNotCheckedLoginoutEvents=$(echo ${tmpArray2[@]}|sed 's/ //g')
            # 4.3.6 audit the change of discretionary access control
            echo "-[·] audit the change of discretionary access control"
            local keyArray=("(chmod|fchmod|fchmodat)" "(chown|fchown|fchownat)" "(setxattr|lsetxattr|removexattr)" "(lock|time)")
            tmpArray1=()
            tmpArray2=()
            for i in ${keyArray[@]} ; do
                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')
                    echo -e "\033[32m-[+] audit the use of systemcall  $i \033[0m"
                    tmpArray1+=($i\;)
                else
                    tmpArray2+=($i\;)
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')
                    echo -e "\033[31m-[-] not audit the use of systemcall $i \033[0m"
                fi
            done
            auditdRulesCheckedDACChangeSyscall=$(echo ${tmpArray1[@]}|sed 's/ //g')
            auditdRulesNotCheckedDACChangeSyscall=$(echo ${tmpArray2[@]}|sed 's/ //g')
            # 4.3.7 audit the events of unsuccessful unauthorized file access attempts
            echo "-[·] audit the events of unsuccessful unauthorized file access attempts"
            local keyArray=("(create|open|openat|truncate|ftruncate).*?exit=-EACCESS" "(create|open|openat|truncate|ftruncate).*?exit=-EPERM" )
            tmpArray1=()
            tmpArray2=()
            for i in ${keyArray[@]} ; do
                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i\;)
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                    echo -e "\033[32m-[+] audit the use of systemcall  $i \033[0m"
                else
                    tmpArray2+=($i\;)
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                    echo -e "\033[31m-[-] not audit the use of systemcall $i \033[0m"
                fi
            done
            auditdRulesCheckedFileAccessAttemptSyscall=$(echo ${tmpArray1[@]}|sed 's/ //g')
            auditdRulesNotCheckedFileAccessAttemptSyscall=$(echo ${tmpArray2[@]}|sed 's/ //g')
            # 4.3.8 audit the use of privileged commands
            echo "-[·] audit the use of privileged commands"
            #find / -name "passwd"
            local res=$(find / -xdev \( -perm -4000 -o -perm -2000 \) -type f) #|awk '{print "-a always,exit -F path="$1"-F perm=x -F auid>=1000 -F auid!=4294967295 -k privileged"}'
            tmpArray1=()
            tmpArray2=()
            for i in ${res[@]} ; do
                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i\;)
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                    echo -e "\033[32m-[+] audit the use of command  $i \033[0m"
                else
                    tmpArray2+=($i\;)
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                    echo -e "\033[31m-[-] not audit the use of command $i \033[0m"
                fi
            done
            auditdRulesCheckedPrivilegedCommand=$(echo ${tmpArray1[@]}|sed 's/ //g')
            auditdRulesNotCheckedPrivilegedCommand=$(echo ${tmpArray2[@]}|sed 's/ //g')
            # 4.3.9 audit the change of file sudoer
            echo "-[·] audit the change of file sudoer"
            local keyArray=("/etc/sudoers" "/etc/sudoers.d/")
            tmpArray1=()
            tmpArray2=()
            for i in ${keyArray[@]} ; do
                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then
                    tmpArray1+=($i\;)
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                    echo -e "\033[32m-[+] audit the change of file  $i \033[0m"
                else
                    tmpArray2+=($i\;)
                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\.\*?/ /g')
                    echo -e "\033[31m-[-] not audit the change of file $i \033[0m"
                fi
            done
            auditdRulesCheckedSudoerFile=$(echo ${tmpArray1[@]}|sed 's/ //g')
            auditdRulesNotCheckedSudoerFile=$(echo ${tmpArray2[@]}|sed 's/ //g')
            # 4.3.10 check the audit configuration is setted to immutable unless reboot the server
            echo "-[·] check the audit configuration is setted to immutable unless reboot the server"
            local res=$(grep "^\s*[^#]" /etc/audit/audit.rules|tail -1|egrep "-e.*?2")
            if [[ -n $res ]]; then
                auditdRulesIfImmutable="True"
                echo -e "\033[32m-[+] auditd setted -e 2 \033[0m"
            else
                auditdRulesIfImmutable="False"
                echo -e "\033[31m-[-] auditd not setted -e 2 \033[0m"
            fi
        fi
    else
        auditdRulesIfExist="False"
        echo -e "\033[32m-[+] /etc/audit/audit.rules is not exist \033[0m"
    fi
    auditd_rules_info={\"auditdRulesIfExist\":\"$auditdRulesIfExist\",\"auditdRulesIfNotNull\":\"$auditdRulesIfNotNull\",\"auditdIfCheckTimechange\":\"$auditdIfCheckTimechange\",\"auditdRulesCheckedUserandgroupfile\":\"$auditdRulesCheckedUserandgroupfile\",\"auditdRulesNotCheckedUserandgroupfile\":\"$auditdRulesNotCheckedUserandgroupfile\",\"auditdRulesCheckedNetworkenv\":\"$auditdRulesCheckedNetworkenv\",\"auditdRulesNotCheckedNetworkenv\":\"$auditdRulesNotCheckedNetworkenv\",\"auditdRulesCheckedMACchange\":\"$auditdRulesCheckedMACchange\",\"auditdRulesNotCheckedMACchange\":\"$auditdRulesNotCheckedMACchange\",\"auditdRulesCheckedLoginoutEvents\":\"$auditdRulesCheckedLoginoutEvents\",\"auditdRulesNotCheckedLoginoutEvents\":\"$auditdRulesNotCheckedLoginoutEvents\",\"auditdRulesCheckedDACChangeSyscall\":\"$auditdRulesCheckedDACChangeSyscall\",\"auditdRulesNotCheckedDACChangeSyscall\":\"$auditdRulesNotCheckedDACChangeSyscall\",\"auditdRulesCheckedFileAccessAttemptSyscall\":\"$auditdRulesCheckedFileAccessAttemptSyscall\",\"auditdRulesNotCheckedFileAccessAttemptSyscall\":\"$auditdRulesNotCheckedFileAccessAttemptSyscall\",\"auditdRulesCheckedPrivilegedCommand\":\"$auditdRulesCheckedPrivilegedCommand\",\"auditdRulesNotCheckedPrivilegedCommand\":\"$auditdRulesNotCheckedPrivilegedCommand\",\"auditdRulesCheckedSudoerFile\":\"$auditdRulesCheckedSudoerFile\",\"auditdRulesNotCheckedSudoerFile\":\"$auditdRulesNotCheckedSudoerFile\",\"auditdRulesIfImmutable\":\"$auditdRulesIfImmutable\"}
    auditd_check_res={\"auditd_config_info\":$auditd_config_info,\"auditd_rules_info\":$auditd_rules_info}
}

function log_check {
    echo "[·] check log configuration"
	# 5.1 ensure auditd is enabled
    echo "-[·] check rsyslog if is enabled"
	if [[ $(systemctl is-enabled rsyslog) = "enabled" ]]; then
        rsyslogIfEnabled="True"
		echo -e "\033[32m-[+] rsyslog is enabled \033[0m"
	else
        rsyslogIfEnabled="False"
		echo -e "\033[31m-[-] rsyslog is not enabled \033[0m"
	fi
    
    log_check_res={\"rsyslogIfEnabled\":\"$rsyslogIfEnabled\"}

}

function authentication_check {
    echo "[·] check cron ssh pam and env configuration"
    # 6.1 cron configuration
    echo "-[·] check cron configuration"
    # 6.1.1 check cron service is enabled
    echo "-[·] check crond if is enabled"
	if [[ $(systemctl is-enabled crond) = "enabled" ]]; then
		echo -e "\033[32m-[+] crond is enabled \033[0m"
        crondIfEnabled="True"
	else
        crondIfEnabled="False"
		echo -e "\033[31m-[-] crond is not enabled \033[0m"
	fi
    # 6.1.2 check cron's configuration file permission
    echo "-[·] check cron's configuration file permission"
    local keyArray=("/etc/crontab" "/etc/cron.hourly" "/etc/cron.daily" "/etc/cron.weekly" "/etc/cron.monthly" "/etc/cron.d")
    crondConfigFilenameArray=$(echo ${keyArray[@]}|sed 's/ /;/g')
    tmpArray=()
    for i in ${keyArray[@]} ; do
        local res=$(stat $i |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4|cut -d"/" -f1)
        tmpArray+=($res\;)
        if [[ $res = "0600" ]] || [[ $res = "0700" ]]; then
            echo -e "\033[32m-[+] file $i's permission is $res \033[0m"
        else
            echo -e "\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \033[0m"
        fi
    done
    crondConfigFilePermissionArray=$(echo ${tmpArray[@]}|sed 's/ //g')
    # 6.1.3 check cron.allow cron.deny permission and owner
    echo "-[·] check cron.allow cron.deny configuration file permission"
    local keyArray=("/etc/cron.allow" "/etc/cron.deny")
    crondallowdenyFilenameArray=$(echo ${keyArray[@]}|sed 's/ /;/g')
    tmpArray1=()
    tmpArray2=()
    tmpArray3=()
    for i in ${keyArray[@]} ; do
        if [[ ! -f $i ]]; then
            tmpArray1+=("False;")
            tmpArray2+=("False;")
            tmpArray3+=("False;")
            echo -e "\033[31m-[-] file $i not exist \033[0m"
            continue
        else
            tmpArray1+=("True;")
        fi
        local res1=$(stat $i |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4|cut -d"/" -f1)
        tmpArray2+=($res1\;)
        local res2=$(stat $i |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f3,4|sed 's/)//g'|cut -d" " -f3,6)
        tmpArray3+=($res2\;)
        if [[ $res1 = "0600" ]] || [[ $res1 = "0700" ]]; then
            echo -e "\033[32m-[+] file $i's permission is $res \033[0m"
        else
            echo -e "\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \033[0m"
        fi
        if [[ $res2 = "root root" ]]; then
            echo -e "\033[32m-[+] file $i's owner is $res2 \033[0m"
        else
            echo -e "\033[31m-[-] file $i's owner is not root \033[0m"
        fi
    done
    crondallowdenyFileIfExistArray=$(echo ${tmpArray1[@]}|sed 's/ //g')
    crondallowdenyFilePermissionArray=$(echo ${tmpArray2[@]}|sed 's/ //g')
    crondallowdenyFileOwnerArray=$(echo ${tmpArray3[@]}|sed 's/; /;/g')
    crond_config_info={\"crondIfEnabled\":\"$crondIfEnabled\",\"crondConfigFilenameArray\":\"$crondConfigFilenameArray\",\"crondConfigFilePermissionArray\":\"$crondConfigFilePermissionArray\",\"crondallowdenyFilenameArray\":\"$crondallowdenyFilenameArray\",\"crondallowdenyFileIfExistArray\":\"$crondallowdenyFileIfExistArray\",\"crondallowdenyFilePermissionArray\":\"$crondallowdenyFilePermissionArray\",\"crondallowdenyFileOwnerArray\":\"$crondallowdenyFileOwnerArray\"}
    # 6.2 SSH configuration
    echo "-[·] check ssh configuration"
	if [[ $(systemctl is-enabled sshd) = "enabled" ]]; then
        sshdIfEnabled="True"
        # 6.2.1 /etc/ssh/sshd_config permission 0600
        local file="/etc/ssh/sshd_config"
        local res=$(stat $file |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4|cut -d"/" -f1)
        if [[ $res = "0600" ]]; then
            sshdConfigFilePermission=$res
            echo -e "\033[32m-[+] file $file's access permission is $res \033[0m"
        else
            sshdConfigFilePermission="False"
            echo -e "\033[3-m-[-] file $file's access permission is $res \033[0m"
        fi
        # 6.2.2 check ssh x11 forwarding if is disabled
        local res=$(grep "^X11Forwaring" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep no) ]]; then
            sshdIfDisableX11forwarding="True"
            echo -e "\033[32m-[+] X11Forwarding no \033[0m"
        else
            sshdIfDisableX11forwarding="False"
            echo -e "\033[31m-[-] not set X11Forwarding no \033[0m"
        fi
        # 6.2.3 check ssh MaxAUTHTries if is 4
        local res=$(grep "^MaxAuthTries" /etc/ssh/sshd_config)
        if [[ -n $res ]]; then
            sshdIfSetMaxAuthTries=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\2/')
            echo -e "\033[32m-[+] $res \033[0m"
        else
            sshdIfSetMaxAuthTries="False"
            echo -e "\033[31m-[-] not set MaxAuthTries \033[0m"
        fi
        # 6.2.4 check ssh IgnoreRhosts if is enabled
        local res=$(grep "^IgnoreRhosts" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep yes) ]]; then
            sshdIfEnableIgnoreRhosts="True"
            echo -e "\033[32m-[+] IgnoreRhosts yes \033[0m"
        else
            sshdIfEnableIgnoreRhosts="False"
            echo -e "\033[31m-[-] not set IgnoreRhosts no\033[0m"
        fi
        # 6.2.5 check ssh HostbasedAuthentication if is disabled
        local res=$(grep "^HostbasedAuthentication" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep no) ]]; then
            sshdIfDisableHostbasedAuthentication="True"
            echo -e "\033[32m-[+] HostbasedAuthentication no \033[0m"
        else
            sshdIfDisableHostbasedAuthentication="False"
            echo -e "\033[31m-[-] not set HostbasedAuthentication no\033[0m"
        fi
        # 6.2.6 check ssh root login if is diabled
        local res=$(grep "^PermitRootLogin" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep no) ]]; then
            sshdIfDisablePermitRootLogin="True"
            echo -e "\033[32m-[+] PermitRootLogin no \033[0m"
        else
            sshdIfDisablePermitRootLogin="False"
            echo -e "\033[31m-[-] not set PermitRootLogin no\033[0m"
        fi
        # 6.2.7 check ssh PermitEmptyPasswords if is diabled
        local res=$(grep "^PermitEmptyPasswords" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep no) ]]; then
            sshdIfDisablePermitEmptyPasswords="True"
            echo -e "\033[32m-[+] PermitEmptyPasswords no \033[0m"
        else
            sshdIfDisablePermitEmptyPasswords="False"
            echo -e "\033[31m-[-] not set PermitEmptyPasswords no\033[0m"
        fi
        # 6.2.8 check ssh PermitUserEnvironment if is diabled
        local res=$(grep "^PermitUserEnvironment" /etc/ssh/sshd_config)
        if [[ -n $(echo $res|grep no) ]]; then
            sshdIfDisablePermitUserEnvironment="True"
            echo -e "\033[32m-[+] PermitUserEnvironment no \033[0m"
        else
            sshdIfDisablePermitUserEnvironment="False"
            echo -e "\033[31m-[-] not set PermitUserEnvironment no\033[0m"
        fi
        # 6.2.9 check if set specific MAC algorithms
        local res=$(grep "^MACs" /etc/ssh/sshd_config)
        if [[ -n $res ]]; then
            sshdIfSpecificMACs="True"
            echo -e "\033[32m-[+] will use specific MAC algorithms $res \033[0m"
        else
            sshdIfSpecificMACs="False"
            echo -e "\033[31m-[-] not set specific MAC algorithms\033[0m"
        fi
        # 6.2.10 check SSH idle Timeout Interval if is configured
        local res=$(grep "^ClientAliveInterval" /etc/ssh/sshd_config)
        if [[ -n $res ]]; then
            sshdIfSetClientAliveInterval=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\2/')
            echo -e "\033[32m-[+] $res \033[0m"
        else
            sshdIfSetClientAliveInterval="False"
            echo -e "\033[31m-[-] not set ClientAliveInterval \033[0m"
        fi
        # 6.2.11 check SSH LoginGrace Time
        local res=$(grep "^LoginGraceTime" /etc/ssh/sshd_config)
        if [[ -n $res ]]; then
            sshdIfSetLoginGraceTime=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\2/')
            echo -e "\033[32m-[+] $res \033[0m"
        else
            sshdIfSetLoginGraceTime="False"
            echo -e "\033[31m-[-] not set LoginGraceTime \033[0m"
        fi
	else
        sshdIfEnabled="False"
		echo -e "\033[32m-[+] sshd is not enabled \033[0m"
	fi
    sshd_config_info={\"sshdIfEnabled\":\"$sshdIfEnabled\",\"sshdConfigFilePermission\":\"$sshdConfigFilePermission\",\"sshdIfDisableX11forwarding\":\"$sshdIfDisableX11forwarding\",\"sshdIfSetMaxAuthTries\":\"$sshdIfSetMaxAuthTries\",\"sshdIfEnableIgnoreRhosts\":\"$sshdIfEnableIgnoreRhosts\",\"sshdIfDisableHostbasedAuthentication\":\"$sshdIfDisableHostbasedAuthentication\",\"sshdIfDisablePermitRootLogin\":\"$sshdIfDisablePermitRootLogin\",\"sshdIfDisablePermitEmptyPasswords\":\"$sshdIfDisablePermitEmptyPasswords\",\"sshdIfDisablePermitUserEnvironment\":\"$sshdIfDisablePermitUserEnvironment\",\"sshdIfSpecificMACs\":\"$sshdIfSpecificMACs\",\"sshdIfSetClientAliveInterval\":\"$sshdIfSetClientAliveInterval\",\"sshdIfSetLoginGraceTime\":\"$sshdIfSetLoginGraceTime\"}

    # 6.3 PAM configuration
    echo "-[·] check pam configuration"
    # 6.3.1 password creation policy
    if [[ -f /etc/security/pwquality.conf ]]; then
        pamPwqualityconfIfExist="True"
        local minlen=$(grep ^minlen /etc/security/pwquality.conf | sed 's/ //g')
        local minclass=$(grep ^minclass /etc/security/pwquality.conf |sed 's/ //g')
        if [[ -n $minlen ]]; then
            pamIfSetMinlen=$(echo $minlen|cut -d= -f2)
            echo -e "\033[32m-[+] minimime length of password is $(echo $minlen|cut -d= -f2) \033[0m"
        else
            pamIfSetMinlen="False"
            echo -e "\033[31m-[-] not set minlen \033[0m"
        fi
        if [[ -n $minclass ]]; then
            pamIfSetMinclass=$(echo $minclass|cut -d= -f2)
            echo -e "\033[32m-[+] minclass of password is $(echo $minclass|cut -d= -f2) \033[0m"
        else
            local keyArray=("^dcredit" "^lcredit" "^ocredit" "^ucredit")
            local tmpCount=0
            for i in ${keyArray[@]}; do
                if [[ -n  $(grep $i /etc/security/pwquality.conf) ]]; then
                    tmpCount=$(expr 1 + $tmpCount)
                fi
            done
            if [[ $tmpCount = 0 ]]; then
                pamIfSetMinclass="False"
            else
                pamIfSetMinclass=$tmpCount
            fi
            if [[ tmpCount -ge 2 ]]; then
                echo -e "\033[32m-[+] minclass of passwd is $tmpCount \033[0m"
            else
                echo -e "\033[31m-[-] not set minclass \033[0m"
            fi
        fi
    else
        pamPwqualityconfIfExist="False"
    fi
    # 6.3.2 lock account and unlock time
    local files=("/etc/pam.d/password-auth" "/etc/pam.d/system-auth")
    local keyArray=("pam_faillock\.so.*?unlock_time")
    tmpArray1=()
    tmpArray2=()
    for i in ${files[@]}; do
        for k in ${keyArray[@]}; do
            if [[ -n $(egrep $k $i ) ]]; then
                echo -e "\033[32m-[+] set lock and unlock_time in $i \033[0m"
                tmpArray1+=($i\;)
            else
                tmpArray2+=($i\;)
                echo -e "\033[31m-[-] not set lock and unlock_time in $i \033[0m"
            fi
        done
    done
    sshdSetedLockAndUnlockTimeFiles=$(echo ${tmpArray1[@]}|sed 's/; /;/g')
    sshdNotSetedLockAndUnlockTimeFiles=$(echo ${tmpArray2[@]}|sed 's/; /;/g')
    # 6.3.3 check password reuse if is limited
    sshdPamdFileArray=$(echo ${files[@]}|sed 's/ /;/g')
    tmpArray=()
    for i in ${files[@]}; do
        local res=$(egrep '^password\s+sufficient\s+pam_unix.so' $i)
        if [[ -n $res ]] && [[ $res =~ "remember=" ]]; then
            local tmp=$(echo $res|sed 's/.*\(remember=[[:digit:]]\).*/\1/g'|sed 's/ //g'|cut -d= -f2)
            tmpArray+=($tmp\;)
            echo -e "\033[32m-[+] password reuse limit is $tmp in $i \033[0m"
        else
            tmpArray+=("False;")
            echo -e "\033[31m-[-] passowrd reuse limit not set in $i \033[0m"
        fi
    done
    sshdPamdFileReuseLimitArray=$(echo ${tmpArray[@]}|sed 's/; /;/g')
    # 6.3.4 check the algorithm of store password if is sha512
    tmpArray=()
    for i in ${files[@]}; do
        local res=$(egrep '^password\s+sufficient\s+pam_unix.so' $i)
        if [[ -n $res ]] && [[ $res =~ "sha512" ]]; then
            tmpArray+=("True;")
            echo -e "\033[32m-[+] password storage algorithm is set to sha512 in $i \033[0m"
        else
            tmpArray+=("False;")
            echo -e "\033[31m-[-] password storage algorithm is not specific to sha512 in $i \033[0m"
        fi
    done
    sshdPamdFileIfSetSha512Array=$(echo ${tmpArray[@]}|sed 's/; /;/g')
    pam_config_info={\"pamPwqualityconfIfExist\":\"$pamPwqualityconfIfExist\",\"pamIfSetMinlen\":\"$pamIfSetMinlen\",\"pamIfSetMinclass\":\"$pamIfSetMinclass\",\"sshdSetedLockAndUnlockTimeFiles\":\"$sshdSetedLockAndUnlockTimeFiles\",\"sshdNotSetedLockAndUnlockTimeFiles\":\"$sshdNotSetedLockAndUnlockTimeFiles\",\"sshdPamdFileArray\":\"$sshdPamdFileArray\",\"sshdPamdFileReuseLimitArray\":\"$sshdPamdFileReuseLimitArray\",\"sshdPamdFileIfSetSha512Array\":\"$sshdPamdFileIfSetSha512Array\"}
    # 6.4 user accounts and environment
    echo "-[·] check user accounts and environment"
    if [[ -f /etc/login.defs ]]; then
        accountLogindefsIfExist="True"
        # 6.4.1 basic settings
        local file='/etc/login.defs'
        passMaxDays=$(grep ^PASS_MAX_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\1/g')
        passMinDays=$(grep ^PASS_MIN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\1/g')
        passWarnAge=$(grep ^PASS_WARN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\1/g')
        inactive=$(useradd -D|grep INACTIVE|sed 's/ //g'|cut -d= -f2)
        accountPassMaxDays=$passMaxDays
        accountPassMinDays=$passMinDays
        accountPassWarnDays=$passWarnAge
        accountPassAutolockInactiveDays=$inactive
        if [[ $passMaxDays -le 90 ]]; then
            echo -e "\033[32m-[+] the maximume days of password have to change is $passMaxDays \033[0m"
        else
            echo -e "\033[31m-[-] the maximume days of password have to change is $passMaxDays ,should less than 90 day\033[0m"
        fi
        if [[ $passMinDays -ge 7 ]]; then
            echo -e "\033[32m-[+] the minimume days of password have to change is $passMinDays \033[0m"
        else
            echo -e "\033[31m-[-] the minimume days of password have to change is $passMinDays ,should great than 7 day\033[0m"
        fi
        if [[ $passWarnAge -ge 7 ]]; then
            echo -e "\033[32m-[+] the minimume days of warn password need to change is $passWarnAge \033[0m"
        else
            echo -e "\033[31m-[-] the minimume days of warn password need to change is $passWarnAge ,should greate than 7 day\033[0m"
        fi
        if [[ $inactive != -1 ]]; then
            echo -e "\033[32m-[+] auto lock account when the  $inactive day haven't login \033[0m"
        else
            echo -e "\033[31m-[-] haven't set day of auto lock accounts \033[0m"
        fi
        # 6.4.2 check system's account if is unlogin
        local res=$(egrep -v "^\+" /etc/passwd | awk -F: '($1!="root" && $1!="sync" && $1!="shutdown" && $1!="halt" && $3<1000 && $7!="/sbin/nologin" && $7!="/bin/false") {print $1}')
        tmpArray=()
        if [[ -z $res ]]; then
            tmpArray+=("False;")
            echo -e "\033[32m-[+] system account can't login \033[0m"
        else
            tmpArray+=($(echo $res|sed 's/\n/ /g'))
            echo -e "\033[31m-[-]  ($(echo $res|sed 's/\n/ /g'))user's shell need set to /sbin/nologin \033[0m"
        fi
        accountShouldUnloginAray=$(echo ${tmpArray[@]}|sed 's/ /;/g')
        # 6.4.3 check default group for the root account if is GID 0
        local res=$(grep "^root:" /etc/passwd|cut -d: -f4)
        accountGIDOfRoot=$res
        if [[ $res = 0 ]]; then
            echo -e "\033[32m-[+] default group for the root account is GID 0 \033[0m"
        else
            echo -e "\033[31m-[-]] default group for the root account is is GID $res,not GID 0 \033[0m"
        fi
        # 6.4.4 check default user shell timeout if is 900 seconds or less
        local files=("/etc/bashrc" "/etc/profile")
        tmpArray1=()
        tmpArray2=()
        for file in ${files[@]}; do
            if [[ ! -f $file ]]; then
                continue
            else
                tmpArray1+=($file\;)
            fi
            local res=$(grep "^TMOUT" $file|sed 's/ //g'|cut -d= -f2)
            if [[ -z $res ]]; then
                tmpArray2+=("False;")
                echo -e "\033[31m-[-] not set TMOUT in file $file \033[0m"
                continue
            fi
            tmpArray2+=($res\;)
            if [[ $res -le 900 ]]; then
                echo -e "\033[32m-[+] when idle time great than $res seconds will close connection \033[0m"
            else
                echo -e "\033[31m-[-] when idle time great than $res seconds will close connection,the time should less than 900 seconds \033[0m"
            fi
        done
        accountProfileFileArray=$(echo ${tmpArray1[@]}|sed 's/; /;/g')
        accountProfileTMOUTArray=$(echo ${tmpArray2[@]}|sed 's/; /;/g')
        # 6.4.5 check access to su command if is restricted
        local res=$(grep pam_wheel.so /etc/pam.d/su)
#        accountIfSetUsersCanAccessSuCommand=
        if [[ -n $res ]]; then
            local res=$(grep wheel /etc/group|cut -d: -f4)
            if [[ -n $res ]]; then
                accountIfSetUsersCanAccessSuCommand=$(echo $res|sed 's/\n/;/g')
                echo -e "\033[32m-[+] access to su command is specific to $(echo $res|sed 's/\n/;/g') \033[0m"
            else
                accountIfSetUsersCanAccessSuCommand="False"
                echo -e "\033[31m-[-] access to su command is not restricted \033[0m"
            fi
        else
            accountIfSetUsersCanAccessSuCommand="False"
            echo -e "\033[31m-[-] access to su command is not restricted \033[0m"
        fi
    else
        accountLogindefsIfExist="False"
        echo -e "\033[31m-[-] file /etc/login.defs is not exist \033[0m"
    fi
    account_config_info={\"accountPassMaxDays\":\"$accountPassMaxDays\",\"accountPassMinDays\":\"$accountPassMinDays\",\"accountPassWarnDays\":\"$accountPassWarnDays\",\"accountPassAutolockInactiveDays\":\"$accountPassAutolockInactiveDays\",\"accountShouldUnloginArray\":\"$accountShouldUnloginArray\",\"accountGIDOfRoot\":\"$accountGIDOfRoot\",\"accountProfileFileArray\":\"$accountProfileFileArray\",\"accountProfileTMOUTArray\":\"$accountProfileTMOUTArray\",\"accountIfSetUsersCanAccessSuCommand\":\"$accountIfSetUsersCanAccessSuCommand\"}
    authentication_check_res={\"crond_config_info\":$crond_config_info,\"sshd_config_info\":$sshd_config_info,\"pam_config_info\":$pam_config_info,\"account_config_info\":$account_config_info}
}

function system_check {
    echo "[·] check permission of important file and configuration of user and group"
    # 7.1 check permission of important file and uid gid
    echo "-[·] check permission of important file"
    local files=("/etc/passwd" "/etc/shadow" "/etc/group" "/etc/gshadow" "/etc/passwd-" "/etc/shadow-" "/etc/group-" "/etc/gshadow-")
    importantFilenameArray=$(echo ${files[@]}|sed 's/ /;/g')
    tmpArray1=()
    tmpArray2=()
    for file in ${files[@]}; do
        local perm=$(stat $file |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4|cut -d"/" -f1)
        local uidGid=$(stat /etc/passwd |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f3,4|sed 's/ //g'|sed -r 's/([[:digit:]]{1,}).*([[:digit:]]{1,}).*/\1 \2/g'|cut -d" " -f1,2)
        tmpArray1+=($perm\;)
        tmpArray2+=($uidGid\;)
        if [[ $file =~ "shadow" ]]; then
            if [[ $perm = "0000" ]]; then
                echo -e "\033[32m-[+] file $file's permission is $perm \033[0m"
            else
                echo -e "\033[31m-[-] file $file's permission is $perm,should set to 0000 \033[0m"
            fi
        else
            if [[ $perm = "0644" ]]; then
                echo -e "\033[32m-[+] file $file's permission is $perm \033[0m"
            else
                echo -e "\033[31m-[-] file $file's permission is $perm,should set to 0644 \033[0m"

            fi
        fi
        if [[ $uidGid = "0 0" ]]; then
            echo -e "\033[32m-[+] file $file's uid gid is $uidGid \033[0m"
        else
            echo -e "\033[31m-[-] file $file's uid gid is $uidGid,should set to 0 0 \033[0m"
        fi
    done
    importantFilePermissionArray=$(echo ${tmpArray1[@]}|sed 's/; /;/g')
    importantFileUidgidArray=$(echo ${tmpArray2[@]}|sed 's/; /;/g')
    file_permission_info={\"importantFilenameArray\":\"$importantFilenameArray\",\"importantFilePermissionArray\":\"$importantFilePermissionArray\",\"importantFileUidgidArray\":\"$importantFileUidgidArray\"}
    # 7.2 check configuration of user and group
    echo "-[·] check configuration of user and group"
    # 7.2.1 check if user's password is empty
    users=$(cat /etc/shadow |awk -F: '($2=="!!"){print $1}'|while read x;do 
        res=$(grep ${x} /etc/passwd|cut -d: -f7); if [[ $res != "/sbin/nologin" ]] && [[ $res != "/sbin/shutdon" ]] && [[ $res != "/sbin/halt" ]]; then 
            echo $x
            #echo -e "\033[31m-[-] $x should have a passwd,not empty \033[0m"; 
            fi;
        done)
    if [[ -z $users ]]; then
        userIfSetPasswdOrArray="True"
        echo -e "\033[32m-[+] all user account have set password \033[0m"
    else
        userIfSetPasswdOrArray=$(echo $users|sed 's/ /;/g')
        echo -e "\033[31m-[-] user:$(echo $users|sed 's/\n/ /g') should set a password ,rather than empty \033[0m"
    fi
    # 7.2.2 check if root is the only UID 0 account
    local users=$(cat /etc/passwd|awk -F: '($3==0){print $1}')
    if [[ $users = 'root' ]]; then
        uid0OnlyRootOrArray="True"
        echo -e "\033[32m-[+] root is the only account that uid is 0 \033[0m"
    else
        uid0OnlyRootOrArray=$(echo $users|sed 's/root //g'|sed 's/ /;/g')
        echo -e "\033[31m-[-] $(echo $users|sed 's/root //g'|sed 's/\n/ /g') uid should not be 0 \033[0m"
    fi
    # 7.2.3 check root PATH integrith
    if [ "$(echo $PATH|grep ::)" != "" ]; then
        echo -e "\033[31m-[-] Empty Directory in PATH (::) \033[0m"
    fi
    if [ "$(echo $PATH|grep :$)" != "" ]; then
        echo -e "\033[31m-[-] Trailing : in PATH \033[0m"
    fi
    path=$( echo $PATH|sed -e 's/::/:/' -e 's/:$//' -e 's/:/ /g')
    tmpArray1=()
    tmpArray2=()
    tmpArray3=()
    tmpArray4=()
    tmpArray5=()
    set -- $path
    while [[ $1 != "" ]]; do
        if [[ $1 = "." ]]; then
            echo -e "\033[31m-[-] PATH contains . \033[0m"
            tmpArray1+=(".")
            shift
            continue
        fi
        if [[ -d $1 ]]; then
            local dirperm=$(ls -ldH $1|cut -d" " -f1)
            if [[ $(echo $dirperm|cut -c6) != "-" ]]; then
                tmpArray2+=($1\;)
                echo -e "\033[31m-[-] Group Write permission should not set on directory $1 \033[0m"
            fi
            if [[ $(echo $dirperm|cut -c9) != "-" ]]; then
                tmpArray3+=($1\;)
                echo -e "\033[31m-[-] Other Write permission should not set on directory $1 \033[0m"
            fi
            local dirown=$(ls -ldH $1|awk '{print $3}')
            if [[ $dirown != "root" ]]; then
                tmpArray4+=($1\;)
                echo -e "\033[31m-[-] dir $1's owner is $dirown,should be root \033[0m"
            fi
        else
            tmpArray5+=($1\;)
            echo -e "\033[31m-[-] $1 is not a directory or not exist \033[0m"
        fi
        shift
    done
    if [[ ${#tmpArray1[@]} = 0 ]]; then
        pathDirIfNotHasDot="True"
    else
        pathDirIfNotHasDot="False"
    fi
    pathDirPermissionHasGWArray=$(echo ${tmpArray2[@]}|sed 's/; /;/g')
    pathDirPermissionHasOWArray=$(echo ${tmpArray3[@]}|sed 's/; /;/g')
    pathDirOwnerIsNotRootArray=$(echo ${tmpArray4[@]}|sed 's/; /;/g')
    pathDirDoesNotExistOrNotDirArray=$(echo ${tmpArray5[@]}|sed 's/; /;/g')
    # 7.2.4 check if is all users' home directories exist
    #cat /etc/passwd|egrep -v '^(root|halt|sync|shutdown)'|awk -F: '($7 != "/sbin/nologin" && $7 != "/bin/false"){print $1 " " $6}'|while read user dir; do
    tmpArray1=()
    tmpArray2=()
    tmpArray3=()
    tmpArray4=()
    tmpArray5=()
    tmpArray6=()
    while read user dir; do
        tmpArray1+=($dir\;)
        if [[ ! -d $dir ]]; then
            tmpArray2+=("False;")
            tmpArray3+=("False;")
            echo -e "\033[31m-[-] the home directory ($dir) of user $user does not exist \033[0m"

        else
            tmpArray2+=("True;")
            # 7.2.5 check if users' home directories permissions are 750 or more restrictive
            local dirperm=$(ls -ld $dir|cut -d" " -f1)
            tmpArray3+=($dirperm\;)
            if [[ $(echo $dirperm |cut -c6) != "-" ]]; then
                echo -e "\033[31m-[-] Group Write permission set on the home directory ($dir) of user $user \033[0m"
            fi
            if [[ $(echo $dirperm |cut -c8) != "-" ]]; then
                echo -e "\033[31m-[-] Other Read permission set on the home directory ($dir) of user $user \033[0m"
            fi
            if [[ $(echo $dirperm |cut -c9) != "-" ]]; then
                echo -e "\033[31m-[-] Other Write permission set on the home directory ($dir) of user $user \033[0m"
            fi
            if [[ $(echo $dirperm |cut -c10) != "-" ]]; then
                echo -e "\033[31m-[-] Other Execute permission set on the home directory ($dir) of user $user \033[0m"
            fi
            # 7.2.6 check if is users own their home directory
            local owner=$(stat -L -c "%U" $dir)
            if [[ $owner != $user ]]; then
                tmpArray4+=("False;")
                echo -e "\033[31m-[-]The home directory ($dir) of user $user is owned by $owner \033[0m"
            else
                tmpArray4+=("True;")
            fi
            # 7.2.7 check users' dot files are not group or world  writable
            local tmpc=0
            for file in $dir/.[A-Za-z0-9]*; do
                if [[ ! -h $file ]] && [[ -f $file ]]; then
                    local fileperm=$(ls -ld $file|cut -d" " -f1)
                    if [[ $(echo $fileperm|cut -c6) != "-" ]]; then
                        tmpc=$(expr $tmpc + 1)
                        echo -e "\033[31m-[-] Group Write permission set on file $file \033[0m"
                    fi
                    if [[ $(echo $fileperm|cut -c9) != "-" ]]; then
                        tmpc=$(expr $tmpc + 1)
                        echo -e "\033[31m-[-] Other Write permission set on file $file \033[0m"
                    fi
                fi
            done
            if [[ $tmpc = 0 ]]; then
                tmpArray5+=("True;")
            else
                tmpArray5+=("False;")
            fi
            # 7.2.8 check if no usrs have .netrc .rhosts .forward file
            tmpc=0
            if [[ ! -h $dir/.netrc ]] && [[ -f $dir/.netrc ]]; then
                tmpc=$(expr $tmpc + 1)
                echo -e "\033[31m-[-] .netrc file $dir/.netrc exists \033[0m"
            fi
            if [[ ! -h $dir/.rhosts ]] && [[ -f $dir/.rhosts ]]; then
                tmpc=$(expr $tmpc + 1)
                echo -e "\033[31m-[-] .rhosts file $dir/.rhosts exists \033[0m"
            fi
            if [[ ! -h $dir/.forward ]] && [[ -f $dir/.forward ]]; then
                tmpc=$(expr $tmpc + 1)
                echo -e "\033[31m-[-] .forward file $dir/.forward exists \033[0m"
            fi
            if [[ $tmpc = 0 ]]; then
                tmpArray6+=("True;")
            else
                tmpArray6+=("False;")
            fi
        fi
    done < <(cat /etc/passwd|egrep -v '^(root|halt|sync|shutdown)'|awk -F: '($7 != "/sbin/nologin" && $7 != "/bin/false"){print $1 " " $6}')
    userArray=$(echo ${tmpArray1[@]}|sed 's/; /;/g')
    userHomeDirIfExistArray=$(echo ${tmpArray2[@]}|sed 's/; /;/g')
    userHomeDirPermissionArray=$(echo ${tmpArray3[@]}|sed 's/; /;/g')
    userIfOwnTheirHomeDirArray=$(echo ${tmpArray4[@]}|sed 's/; /;/g')
    userHomeDirIfHasGWorOWDotFileArray=$(echo ${tmpArray5[@]}|sed 's/; /;/g')
    userHomeDirIfHasOtherFileArray=$(echo ${tmpArray6[@]}|sed 's/; /;/g')
    # 7.2.9 check if all groups in /etc/passwd exist in /etc/group
    tmpArray=()
    for i in $(cut -d: -s -f4 /etc/passwd|sort -u); do
        grep -q -P "^.*?:[^:]*:$i" /etc/group
        if [[ $? -ne 0 ]]; then
        tmpArray+=($i\;)
            echo -e "\033[31m-[-] Group $i is referenced by /etc/passwd but does not exist in /etc/group \033[0m"
        fi
    done
    groupNotExistInetcgroup=$(echo ${tmpArray[@]}|sed 's/; /;/g')
    # 7.2.10 check if every user has a unique UID
    #cat /etc/passwd|cut -d":" -f3|sort -n|uniq -c|while read x; do
    tmpArray=()
    while read x; do
        [[ -z $x ]] && break
        set - $x
        if [[ $1 -gt 1 ]]; then
            local users=$(awk -F: '($3==n){print $1}' n=$2 /etc/passwd|xargs)
            tmpArray+=($2:$users\;)
            echo -e "\033[31m-[-] Duplicate UID $2 : $users \033[0m"
        fi
    done < <(cat /etc/passwd|cut -d":" -f3|sort -n|uniq -c)
    usersIfHasUniqueUIDArray=$(echo ${tmpArray[@]}|sed 's/; /;/g')
    # 7.2.11 check if every group has a unique GID
    tmpArray=()
    #cat /etc/group|cut -d":" -f3|sort -n|uniq -c|while read x; do
    while read x; do
        [[ -z $x ]] && break
        set - $x
        if [[ $1 -gt 1 ]]; then
            local groups=$(awk -F: '($3==n){print $1}' n=$2 /etc/group|xargs)
            tmpArray+=($2:$groups\;)
            echo -e "\033[31m-[-] Duplicate GID $2 : $groups \033[0m"
        fi
    done < <(cat /etc/group|cut -d":" -f3|sort -n|uniq -c)
    groupsIfHasUniqueGIDArray=${tmpArray[@]}
    # 7.2.12 check if user name is unique
    tmpArray=()
    #cat /etc/passwd|cut -d":" -f1|sort -n|uniq -c|while read x; do
    while read x; do
        [[ -z $x ]] && break
        set - $x11
        if [[ $1 -gt 1 ]]; then
            local uids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/passwd|xargs)
            tmpArray+=($2:$uids\;)
            echo -e "\033[31m-[-] Duplicate user name $2 : $uids \033[0m"
        fi
    done < <(cat /etc/passwd|cut -d":" -f1|sort -n|uniq -c)
    usersIfHasUniqueNameArray=${tmpArray[@]}
    # 7.2.13 check if group name is unique
    tmpArray=()
    #cat /etc/group|cut -d":" -f1|sort -n|uniq -c|while read x; do
    while read x; do
        [[ -z $x ]] && break
        set - $x11
        if [[ $1 -gt 1 ]]; then
            local gids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/group|xargs)
            tmpArray+=($2:$gids\;)
            echo -e "\033[31m-[-] Duplicate group name $2 : $gids \033[0m"
        fi
    done < <(cat /etc/group|cut -d":" -f1|sort -n|uniq -c)
    groupsIfHasUniqueNameArray=${tmpArray[@]}
    usergroup_config_info={\"userIfSetPasswdOrArray\":\"$userIfSetPasswdOrArray\",\"uid0OnlyRootOrArray\":\"$uid0OnlyRootOrArray\",\"pathDirIfNotHasDot\":\"$pathDirIfNotHasDot\",\"pathDirPermissionHasGWArray\":\"$pathDirPermissionHasGWArray\",\"pathDirPermissionHasOWArray\":\"$pathDirPermissionHasOWArray\",\"pathDirOwnerIsNotRootArray\":\"$pathDirOwnerIsNotRootArray\",\"pathDirDoesNotExistOrNotDirArray\":\"$pathDirDoesNotExistOrNotDirArray\",\"userArray\":\"$userArray\",\"userHomeDirIfExistArray\":\"$userHomeDirIfExistArray\",\"userHomeDirPermissionArray\":\"$userHomeDirPermissionArray\",\"userIfOwnTheirHomeDirArray\":\"$userIfOwnTheirHomeDirArray\",\"userHomeDirIfHasGWorOWDotFileArray\":\"$userHomeDirIfHasGWorOWDotFileArray\",\"userHomeDirIfHasOtherFileArray\":\"$userHomeDirIfHasOtherFileArray\",\"groupNotExistInetcgroup\":\"$groupNotExistInetcgroup\",\"usersIfHasUniqueUIDArray\":\"$usersIfHasUniqueUIDArray\",\"groupsIfHasUniqueGIDArray\":\"$groupsIfHasUniqueGIDArray\"}
    system_check_res={\"file_permission_info\":$file_permission_info,\"usergroup_config_info\":$usergroup_config_info}

}

echo """
==================================
|        Linux 基线检查工具      |
|        author:JC0o0l           |
|        version:2.2             |
==================================
"""
get_basic_info
init_check
service_check
network_check
auditd_check
log_check
authentication_check
system_check
if [[ -z $authentication_check_res ]]; then
    authentication_check_res={}
fi
if [[ -z $system_check_res ]]; then
    system_check_res={}
fi
check_result={\"basic_info\":$basic_info,\"init_check_res\":$init_check_res,\"service_check_res\":$service_check_res,\"network_check_res\":$network_check_res,\"auditd_check_res\":$auditd_check_res,\"log_check_res\":$log_check_res,\"authentication_check_res\":$authentication_check_res,\"system_check_res\":$system_check_res}
curl -X POST "http://192.168.3.24:8888/baseline/linux_scan_res_report/" -H "accept:application/json" -H "content-type:application/json" -d "$check_result" 1>/dev/null 2>/dev/null
echo $check_result|jq 


================================================
FILE: baseline_check_v2_JC0o0l.sh
================================================
#!/bin/bash
function get_ip_info {
    local ipList=`ifconfig | grep inet |grep -v inet6|grep -v 127|sed 's/^[ ]*//g'|cut -d" " -f2`
    echo $ipList
}
function get_basic_info {
    echo [·] collect basic info
    hostname=`hostname`
    ipList=`get_ip_info`
    kernelVersion=`uname -r`
    if [[ $(cat /proc/version) =~ "Red Hat" ]]; then
        osVersion=`cat /etc/redhat-release|cut -f1,4 -d" "`
    fi
    basic_info={\"hostname\":\"$hostname\",\"ipList\":\"$ipList\",\"kernelVersion\":\"$kernelVersion\",\"osVersion\":\"$osVersion\"}
    echo $basic_info
}

function init_check {
    # 1. init configuration
    echo [·] check init configuration
    # 1.1 file system configuration
    # 1.1.1 /tmp separate mount
    local tmpIfSeparate #=""
    local tmpIfNoexec #=""
    local tmpIfNosuid #=""
    local res=$(mount|grep "/tmp ") 
    if [[ -z $res ]]; then
        echo -e "\033[31m-[-] /tmp/ not mounted on separate dick\033[0m"
        tmpIfSeparate="false"
        tmpIfNoexec="false"
        tmpIfNosuid="false"
    else
        tmpIfSeparate="true"
        tmpIfNoexec="true"
        tmpIfNosuid="true"
    fi
    if $tmpIfSeparate; then
        #mount|grep "/sys/kernel/debug " |while read res;do
        while read res;do
            #echo "mount | grep /sys --result-->" $res
            # 1.1.2 /tmp noexec nosuid
            local diskPart=$(echo $res|cut -d" " -f3)
            if [[ ! $res =~ "noexec" ]];then
                echo -e "\033[31m-[-] no noexec option on $diskPart partion\033[0m"
                tmpIfNoexec="false"
                if [[ ! $res =~ "nosuid" ]];then
                    echo -e "\033[31m-[-] no nosuid option on $diskPart partion\033[0m"
                    tmpIfNosuid="false"
                fi
            elif [[ ! $res =~ "nosuid" ]];then
                echo -e "\033[31m-[-] no nosuid option on $diskPart partion\033[0m"
                tmpIfNosuid="false"
            fi
        done < <(mount | grep "/tmp ")
    fi
    tmp_partition_info={\"tmpIfSeparate\":\"$tmpIfSeparate\",\"tmpIfNoexec\":\"$tmpIfNoexec\",\"tmpIfNosuid\":\"$tmpIfNosuid\"}
    #echo $tmp_partition_info
    # 1.2 secure boot configuration
    if [[ -f /boot/grub2/grub.cfg ]];then
        grubcfgIfExist="true"
        grubcfgPermission="0600"
        grubcfgIfSetPasswd="true"
    else
        grubcfgIfExist="false"
        grubcfgPermission="0000"
        grubcfgIfSetPasswd="false"
    fi
    if $grubcfgIfExist; then
        # 1.2.1 /boot/grub2/grub.cfg permission /boot/grub2/user.cfg permission 0600 root:root
        res=$(stat /boot/grub2/grub.cfg |while read x;do if [[ $x =~ "Uid" ]] && [[ $x =~ "(" ]]; then echo $x;fi;done|cut -d"(" -f2,3,4)
        grubcfgPermission=$(echo $res|cut -d"/" -f1)
        if [[ $(echo $res|cut -d"/" -f1) = "0600" ]]; then
            echo -e "\033[32m-[+] /boot/grub2/grub.cfg permission is 0600 \033[0m"
        else
            echo -e "\033[31m-[-] /boot/grub2/grub.cfg permission is not 0600 \033[0m"
        fi
        # 1.2.2 Ensure bootloader password is set
        res=$(grep "^GRUB2 PASSWORD" /boot/grub2/grub.cfg)
        if [[ -n $res ]]; then
            echo -e "\033[32m-[+] /boot/grub2/grub.cfg seted password \033[0m"
            grubcfgIfSetPasswd="true"
        else
            echo -e "\033[31m-[-] /boot/grub2/grub.cfg not set password \033[0m"
            grubcfgIfSetPasswd="false"
        fi
    fi
        
    # 1.2.3 single user mode need authentication
    if [[ -f /usr/lib/systemd/system/rescue.service ]] && [[ -f /usr/lib/systemd/system/emergency.service ]]; then
        res1=`grep /sbin/sulogin /usr/lib/systemd/system/rescue.service`
        res2=`grep /sbin/sulogin /usr/lib/systemd/system/emergency.service`
        if [[ $res1 = "ExecStart=-/bin/sh -c \"/usr/sbin/sulogin; /usr/bin/systemctl --fail --no-block default\"" ]] && [[ $res2 = "ExecStart=-/bin/sh -c \"/usr/sbin/sulogin; /usr/bin/systemctl --fail --no-block default\"" ]]; then
            echo -e "\033[32m-[+] single user mode need authentication \033[0m"
            singleUserModeIfNeedAuth="true"
        else
            echo -e "\033[31m-[+] single user mode does not need authentication \033[0m"
            singleUserModeIfNeedAuth="false"
        fi
    fi
    # 1.3 Mantary Access Control
    # 1.3.1 ensure the SELinux state is enforcing
    if [[ -f /etc/selinux/config ]]; then
        local num=$(sestatus|grep -c enforcing)
        if [[ $num -gt 1 ]]; then
            echo -e "\033[32m-[+] SELinux state is enforcing \033[0m"
            selinuxStateIfEnforcing="true"
        else
            echo -e "\033[31m-[-] SELinux state is not enforcing \033[0m"
            selinuxStateIfEnforcing="false"
        fi
    fi
    # 1.3.2 ensure selinux policy is configured
    if [[ -f /etc/selinux/config ]]; then
        res=$(sestatus|grep targeted)
        if [[ -n $res ]]; then
            echo -e "\0
Download .txt
gitextract_nnm6_la9/

├── .gitattributes
├── LICENSE
├── README/
│   └── 77766a601331a6c9ef597b778706fd9c.png-quanzi
├── README.md
├── baseline_check_JC0o0l.sh
├── baseline_check_v2.1_JC0o0l.sh
├── baseline_check_v2.2_JC0o0l.sh
├── baseline_check_v2_JC0o0l.sh
├── linux_baseline_check.sh
├── sec.inf
└── win2012_baseline_check.ps1
Condensed preview — 11 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (368K chars).
[
  {
    "path": ".gitattributes",
    "chars": 66,
    "preview": "# Auto detect text files and perform LF normalization\n* text=auto\n"
  },
  {
    "path": "LICENSE",
    "chars": 35129,
    "preview": "GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation,"
  },
  {
    "path": "README.md",
    "chars": 2252,
    "preview": "# SecurityBaselineCheck\n\n[<h1>脚本请到AssetManage项目下的Agent目录下去下载<h1>](https://github.com/chroblert/AssetManage/tree/master/A"
  },
  {
    "path": "baseline_check_JC0o0l.sh",
    "chars": 38271,
    "preview": "#!/bin/bash\nfunction get_ip_info {\n    local ipList=`ifconfig | grep inet |grep -v inet6|grep -v 127|sed 's/^[ ]*//g'|cu"
  },
  {
    "path": "baseline_check_v2.1_JC0o0l.sh",
    "chars": 58470,
    "preview": "#!/bin/bash\nfunction get_ip_info {\n    local ipList=`ifconfig | grep inet |grep -v inet6|grep -v 127|sed 's/^[ ]*//g'|cu"
  },
  {
    "path": "baseline_check_v2.2_JC0o0l.sh",
    "chars": 60031,
    "preview": "#!/bin/bash\nfunction get_ip_info {\n    local ipList=`ifconfig | grep inet |grep -v inet6|grep -v 127|sed 's/^[ ]*//g'|cu"
  },
  {
    "path": "baseline_check_v2_JC0o0l.sh",
    "chars": 58451,
    "preview": "#!/bin/bash\nfunction get_ip_info {\n    local ipList=`ifconfig | grep inet |grep -v inet6|grep -v 127|sed 's/^[ ]*//g'|cu"
  },
  {
    "path": "linux_baseline_check.sh",
    "chars": 60039,
    "preview": "#!/bin/bash\nfunction get_ip_info {\n    local ipList=`ifconfig | grep inet |grep -v inet6|grep -v 127|sed 's/^[ ]*//g'|cu"
  },
  {
    "path": "win2012_baseline_check.ps1",
    "chars": 31749,
    "preview": "<#\nAuthor: JC (@chroblert)\nAuthor: JC0o0l (@chroblert)\nMail: jerryzvs@163.com\nwechat: Chroblert_Jerrybird(信安札记)\n#>\nchcp"
  }
]

// ... and 2 more files (download for full content)

About this extraction

This page contains the full source code of the chroblert/SecurityBaselineCheck GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 11 files (336.4 KB), approximately 102.5k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!