[
  {
    "path": ".gitattributes",
    "content": "# Auto detect text files and perform LF normalization\n* text=auto\n"
  },
  {
    "path": "LICENSE",
    "content": "GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<https://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<https://www.gnu.org/licenses/why-not-lgpl.html>.\n"
  },
  {
    "path": "README.md",
    "content": "# SecurityBaselineCheck\n\n[<h1>脚本请到AssetManage项目下的Agent目录下去下载<h1>](https://github.com/chroblert/AssetManage/tree/master/Agent)\n\n## 0x01 介绍\n\n这个项目准备打造一个安全基线检查平台，期望能够以最简单的方式在需要进行检查的服务器上运行。能够达到这么一种效果：基线检查脚本(以后称之为agent)可以单独在目标服务器上运行，并展示出相应不符合基线的地方，并且可以将检查时搜集到的信息以json串的形式上传到后端处理服务器上，后端服务器可以进行统计并进行可视化展示。\n\nAgent用到的技术：\n\n- Shell脚本\n- Powershell脚本\n\n后端服务器用到的技术：\n\n- python\n- django\n- bootstrap\n- html\n\n存储所用：\n\n- sqlite3\n\nLinux Agent：\n\n![img](README/77766a601331a6c9ef597b778706fd9c.png-quanzi)\n\nWindows Agent：\n\n![1578038482637](README/1578038482637.png)\n\n后端：\n\n基线扫描记录：\n\n![1578447807497](README/1578447807497.png)\n\n基线扫描详情与检查结果：\n\n![1578447840658](README/1578447840658.png)\n\n## 0x02 项目进展\n\n- 20191215 根据CIS制定Centos7检查基线\n- 20191228 发布LinuxAgent v1.0\n  - 只能本地运行展示结果，无法上传JSON串\n  - 只能对Centos7系统进行基线检查\n- 20191230 更新LinuxAgent v2.0\n  - 重构代码，增加上传JSON串功能\n- 20191231 根据CIS制定Window2012检查基线\n- 20200103 发布WindowsAgent v1.0\n  - 只能在本地运行，无法上传JSON串\n- 20200105 发布WindowsAgent v2.0\n  - 修改部分代码\n  - 可以上传json串\n- 20200108 更新AssetManage\n  - 增加Windows基线检查图形展示界面\n- 20200110 更新AssetManage，更新Linux基线检查脚本\n  - 增加完善Linux基线检查图形展示界面\n- 20200113 发布后端图形展示界面 \n  - 后端展示界面源代码位于：`github.com/chroblert/assetmanage`\n  - 后端展示界面docker镜像位于：\n\n## 0x03 使用步骤\n\n1\\. 下载AssetManage这个后端展示项目,\n\n源码地址位于：[AssetManage](https://github.com/chroblert/AssetManage)\n\ndocker镜像位于：`registry.cn-hangzhou.aliyuncs.com/jc0o0l/assetmanage:2.0`\n\n```shell\n# 提前安装最新版SQLite3.30,python3.6\n# git clone项目\ngit clone https://github.com/chroblert/assetmanage.git\ncd AssetManage\n# 使用python3安装依赖包\npython3 -m pip install -r requirements\npython3 manage.py makemigrations\npython3 manage.py migrate\npython3 manage.py runserver 0.0.0.0:8888\n# 假定该服务器的IP未112.112.112.112\n```\n\n2\\. 更改agent中后端服务器的ip和端口为上一步中服务器的IP`112.112.112.112`和端口`8888`\n\n**对于Windows：**\n\n![1578895428321](README/1578895428321.png)\n\n**对于Linux：**\n\n![1578895474191](README/1578895474191.png)\n\n3\\. 将Agent拖到要进行基线检查的服务器上，以管理员权限运行agent\n\n4\\. 访问后端服务器可视化展示界面：`http://112.112.112.112:8888`,\n\n**点击基线检查，查看扫描记录**\n\n![1578447807497](README/1578447807497.png)\n\n**点击`Click Me`查看检查结果**\n\n![1578447840658](README/1578447840658.png)\n\n最后，希望大家多多关注下`信安札记`，给点支持@~@\n\n![大佬关注个公众号吧](README/qrcode_for_gh_fd932f67cd7f_258.jpg)\n\n---\n\n参考资料：[在Django 2.2中启动开发服务器时处理SQLite3错误](https://cloud.tencent.com/developer/article/1439327)\n"
  },
  {
    "path": "baseline_check_JC0o0l.sh",
    "content": "#!/bin/bash\nfunction get_ip_info {\n    local ipList=`ifconfig | grep inet |grep -v inet6|grep -v 127|sed 's/^[ ]*//g'|cut -d\" \" -f2`\n    echo $ipList\n}\nfunction get_basic_info {\n    echo [·] collect basic info\n    hostname=`hostname`\n    ipList=`get_ip_info`\n    kernelVersion=`uname -r`\n    if [[ $(cat /proc/version) =~ \"Red Hat\" ]]; then\n        osVersion=`cat /etc/redhat-release|cut -f1,4 -d\" \"`\n    fi\n    basic_info={\\\"hostname\\\":\\\"$hostname\\\",\\\"ipList\\\":\\\"$ipList\\\",\\\"kernelVersion\\\":\\\"$kernelVersion\\\",\\\"osVersion\\\":\\\"$osVersion\\\"}\n    echo -e \"\\033[32m$basic_info \\033[0m\"\n}\n\nfunction init_check {\n    # 1. init configuration\n    echo [·] check init configuration\n    # 1.1 file system configuration\n    # 1.1.1 /tmp separate mount\n    mount|grep /tmp |while read res;do\n    if [[ -z $res ]]; then\n        echo -e \"\\033[31m[-] /tmp/ not mounted on separate dick\\033[0m\"\n    # 1.1.2 /tmp noexec nosuid\n    elif [[ ! $res =~ \"noexec\" ]];then\n        echo -e \"\\033[31m[-] no noexec option on /tmp partion\\033[0m\"\n        if [[ ! $res =~ \"nosuid\" ]];then\n            echo -e \"\\033[31m[-] no nosuid option on /tmp partion\\033[0m\"\n        fi\n    elif [[ ! $res =~ \"nosuid\" ]];then\n        echo -e \"\\033[31m[-] no nosuid option on /tmp partion\\033[0m\"\n    fi\n    done\n    # 1.2 secure boot configuration\n    # 1.2.1 /boot/grub2/grub.cfg permission /boot/grub2/user.cfg permission 0600 root:root\n    if [[ -f /boot/grub2/grub.cfg ]];then\n        res=`stat /boot/grub2/grub.cfg |while read x;do if [[ $x =~ \"Uid\" ]] && [[ $x =~ \"(\" ]]; then echo $x;fi;done|cut -d\"(\" -f2,3,4`\n        if [[ `echo $res|cut -d\"/\" -f1` = \"0600\" ]]; then\n            echo -e \"\\033[32m[+] /boot/grub2/grub.cfg permission is 0600 \\033[0m\"\n        else\n            echo -e \"\\033[31m[-] /boot/grub2/grub.cfg permission is not 0600 \\033[0m\"\n        fi\n    fi\n    # 1.2.2 Ensure bootloader password is set\n    if [[ -f /boot/grub2/grub.cfg ]];then\n        res=`grep \"^GRUB2 PASSWORD\" /boot/grub2/grub.cfg`\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m[+] /boot/grub2/grub.cfg seted password \\033[0m\"\n        else\n            echo -e \"\\033[31m[-] /boot/grub2/grub.cfg not set password \\033[0m\"\n        fi\n        \n    fi\n    # 1.2.3 single user mode need authentication\n    if [[ -f /usr/lib/systemd/system/rescue.service ]] && [[ -f /usr/lib/systemd/system/emergency.service ]]; then\n        res1=`grep /sbin/sulogin /usr/lib/systemd/system/rescue.service`\n        res2=`grep /sbin/sulogin /usr/lib/systemd/system/emergency.service`\n        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\n            echo -e \"\\033[32m[+] single user mode need authentication \\033[0m\"\n        else\n            echo -e \"\\033[31m[+] single user mode does not need authentication \\033[0m\"\n        fi\n    fi\n    # 1.3 Mantary Access Control\n    # 1.3.1 ensure the SELinux state is enforcing\n    if [[ -f /etc/selinux/config ]]; then\n        local num=$(sestatus|grep -c enforcing)\n        if [[ $num -gt 1 ]]; then\n            echo -e \"\\033[32m[+] SELinux state is enforcing \\033[0m\"\n        else\n            echo -e \"\\033[31m[-] SELinux state is not enforcing \\033[0m\"\n        fi\n    fi\n    # 1.3.2 ensure selinux policy is configured\n    if [[ -f /etc/selinux/config ]]; then\n        res=$(sestatus|grep targeted)\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m[+] SELinux policy is configured \\033[0m\"\n        else\n            echo -e \"\\033[31m[-] SELinux policy is not configure to targeted \\033[0m\"\n        fi\n\n    fi\n}\nfunction service_check {\n    # 2. service configuration\n    echo [·] check service configuration\n    # 2.1 time sync\n    # 2.1.1 time sync service is installed\n    if $(rpm -q ntp 1>/dev/null||rpm -q chrony 1>/dev/null) ; then\n        if $(rpm -q ntp 1>/dev/null) ; then\n            if [[ -f /etc/ntp.conf ]]; then\n                local res=$(egrep \"^(server|pool)\" /etc/ntp.conf)\n                if [[ -n $res ]]; then\n                    echo -e \"\\033[32m[+] remote ntp server is configured \\033[0m\"\n                else\n                    echo -e \"\\033[31m[-] remote ntp server is not configured \\033[0m\"\n                fi\n            fi\n        fi\n        if $(rpm -q chrony 1>/dev/null); then\n            if [[ -f /etc/chrony.conf ]]; then\n                local res=$(egrep \"^(server|pool)\" /etc/chrony.conf)\n                if [[ -n $res ]]; then\n                    echo -e \"\\033[32m[+] remote chrony server is configured \\033[0m\"\n                else\n                    echo -e \"\\033[31m[-] remote chrony server is not configured \\033[0m\"\n                fi\n                \n            fi\n        fi\n    fi        \n    # 2.1.2 x-window\n    local res=$(rpm -qa xorg-x11*)\n    if [[ -z $res ]]; then\n        echo -e \"\\033[32m[+] x11-windows is not installed \\033[0m\"\n    else\n        echo -e \"\\033[31m[-] x11-windows is installed \\033[0m\"\n    fi\n}\nfunction network_check {\n    # 3. network configuration\n    echo [·] check network configuration\n    # 3.1 hosts file configuration\n    # 3.1.1 check /etc/hosts.deny file\n    if [[ -f /etc/hosts.deny ]]; then\n        echo -e \"\\033[32m[+] file /etc/hosts.deny exists \\033[0m\"\n        local res=`stat /etc/hosts.deny |while read x;do if [[ $x =~ \"Uid\" ]] && [[ $x =~ \"(\" ]]; then echo $x;fi;done|cut -d\"(\" -f2,3,4`\n        if [[ $(echo $res|cut -d\"/\" -f1) = \"0644\" ]];then\n            echo -e \"\\033[32m[+] file /etc/hosts.deny permission is 0644 \\033[0m\"\n        else\n            echo -e \"\\033[31m[-] file /etc/hosts.deny permission is not 0644 \\033[0m\"\n        fi\n\n        local res=$(egrep \"^[^#].+\" /etc/hosts.deny)\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m[+] file /etc/hosts.deny is configured \\033[0m\"\n        else\n            echo -e \"\\033[31m[-] file /etc/hosts.deny is not configured \\033[0m\"\n        fi\n    else\n        echo -e \"\\033[31m[-] file /etc/hosts.deny does not exists \\033[0m\"\n    fi\n    # 3.1.2 check /etc/hosts.allow file\n    if [[ -f /etc/hosts.allow ]]; then\n        echo -e \"\\033[32m[+] file /etc/hosts.allow exists \\033[0m\"\n        local res=`stat /etc/hosts.allow |while read x;do if [[ $x =~ \"Uid\" ]] && [[ $x =~ \"(\" ]]; then echo $x;fi;done|cut -d\"(\" -f2,3,4`\n        if [[ $(echo $res|cut -d\"/\" -f1) = \"0644\" ]];then\n            echo -e \"\\033[32m[+] file /etc/hosts.allow permission is 0644 \\033[0m\"\n        else\n            echo -e \"\\033[31m[-] file /etc/hosts.allow permission is not 0644 \\033[0m\"\n        fi\n\n        local res=$(egrep \"^[^#].+\" /etc/hosts.deny)\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m[+] file /etc/hosts.allow is configured \\033[0m\"\n        else\n            echo -e \"\\033[31m[-] file /etc/hosts.allow is not configured \\033[0m\"\n        fi\n    else\n        echo -e \"\\033[31m[-] file /etc/hosts.allow does not exists \\033[0m\"\n    fi\n\n    # 3.2 firewall configuration\n    # 3.2.1 ensure iptables is installed\n    if $(rpm -q iptables 1>/dev/null); then\n        echo -e \"\\033[32m[+] iptables is installed \\033[0m\"\n        # 3.2.2 ensure INPUT OUTPUT chain policy is DROP\n        iptables -L|grep policy|while read x;do\n            if [[ $x =~ \"INPUT\" ]] && [[ $x =~ \"DROP\" ]]; then\n                echo -e \"\\033[32m[+] INPUT chain policy is DROP \\033[0m\"\n            elif [[ $x =~ \"INPUT\" ]] && [[ ! $x =~ \"DROP\" ]]; then\n                echo -e \"\\033[31m[-] INPUT chain policy is not DROP \\033[0m\"\n            fi\n            if [[ $x =~ \"OUTPUT\" ]] && [[ $x =~ \"DROP\" ]]; then\n                echo -e \"\\033[32m[+] OUTPUT chain policy is DROP \\033[0m\"\n            elif [[ $x =~ \"OUTPUT\" ]] && [[ ! $x =~ \"DROP\" ]]; then\n                echo -e \"\\033[31m[-] OUTPUT chain policy is not DROP \\033[0m\"\n            fi\n        done\n    else\n        echo -e \"\\033[31m[-] iptables is not installed \\033[0m\"\n    fi\n}\n\nfunction auditd_check {\n\t# 4. auditd configuration\n\techo [·] check auditd configuration\n\t# 4.1 ensure auditd is enabled\n    echo \"-[·] check auditd if is enabled\"\n\tif [[ $(systemctl is-enabled auditd) = \"enabled\" ]]; then\n\t\techo -e \"\\033[32m-[+] auditd is enabled \\033[0m\"\n\telse\n\t\techo -e \"\\033[31m-[-] auditd is not enabled \\033[0m\"\n\tfi\n\t# 4.2 some settings in /etc/audit/auditd.conf\n    echo \"-[·] settings in /etc/audit/auditd.conf\"\t\n    if [[ -f /etc/audit/auditd.conf ]]; then\n        maxLogFile=$(grep \"^max_log_file[[:blank:]]=\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        maxLogFileAction=$(grep \"^max_log_file_action\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        spaceLeftAction=$(grep \"^space_left_action\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        numLogs=$(grep \"^num_logs\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        if [[ -n $maxLogFile ]]; then\n            echo -e \"\\033[32m-[+] max_log_file size is ${maxLogFile} M \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] max_log_file size is not setted \\033[0m\"\n        fi\n        if [[ -n $maxLogFileAction ]]; then\n            echo -e \"\\033[32m-[+] max_log_file_action is ${maxLogFileAction}\\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] max_log_file_action is not setted \\033[0m\"\n        fi\n        if [[ -n $spaceLeftAction ]]; then\n            echo -e \"\\033[32m-[+] space_left_action is ${spaceLeftAction}\\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] space_left_action is not setted \\033[0m\"\n        fi\n        if [[ -n $numLogs ]]; then\n            echo -e \"\\033[32m-[+] the num of logs is ${numLogs} \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] num_logs is not setted \\033[0m\"\n        fi\n    fi\n    # 4.3 rules in /etc/audit/audit.rules\n    # arch 64\n    echo \"-[·] time-change\" \n    if [[ -f /etc/audit/audit.rules ]]; then\n        echo -e \"\\033[32m-[+] /etc/audit/audit.rules is exist \\033[0m\"\n        # 4.3.1 time-change\n        if [[ -n $(grep time /etc/audit/audit.rules) ]]; then\n            local timeChangeList=$(egrep \"(stime|clock_settime|adjtimex|settimeofday|/etc/localtime)\" /etc/audit/audit.rules|wc -l)\n            if [[ ${timeChangeList} -gt 3 ]]; then\n                echo -e \"\\033[32m-[+] audith the change of date and time \\033[0m\"\n            elif [[ ${timeChangeList} -gt 1 ]]; then\n                echo -e \"\\033[31m-[-] not fully set rule about audit the change of date and time \\033[0m\"\n            else \n                echo -e \"\\033[31m-[-] not set rule about audit the change of date and time \\033[0m\"\n            fi\n        else\n            echo -e \"\\033[31m-[-] not set rule about audit the change of date and time \\033[0m\"\n        fi\n        # 4.3.2 user and group change\n        echo \"-[·] user and group change\"\n        local keyArray=(\"/etc/passwd\" \"/etc/group\" \"/etc/gshadow\" \"/etc/shadow\" \"/etc/security/opasswd\")\n        for i in ${keyArray[@]} ; do\n            if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                echo -e \"\\033[32m-[+] audit the change of $i \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n            fi\n        done\n        # 4.3.3 system's network environment change\n        echo \"-[·] system's network environment change\"\n        local keyArray=(\"/etc/issue\" \"/etc/issue.net\" \"/etc/hosts\" \"/etc/sysconfig/network\" \"/etc/sysconfig/network-scripts/\" )\n        for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                echo -e \"\\033[32m-[+] audit the change of $i \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n            fi\n        done\n        local keyArray=(\"sethostname\" \"setdomainname\")\n        for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                echo -e \"\\033[32m-[+] audit the use of syscall  $i \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] not audit the use of syscall $i \\033[0m\"\n            fi\n        done\n        # 4.3.4 system's Mandatory Access Controls change\n        echo \"-[·] system's Mandatory Access Controls change\"\n        local keyArray=(\"/etc/selinux\" \"/usr/share/selinux\")\n        for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                echo -e \"\\033[32m-[+] audit the change of   $i \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n            fi\n        done\n        # 4.3.5 audit events of login and logout\n        echo \"-[·] audit events of login and logout\"\n        local keyArray=(\"/var/log/lastlog\" \"/var/run/faillock/\")\n        for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                echo -e \"\\033[32m-[+] audit the change of   $i \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n            fi\n        done\n        # 4.3.6 audit the change of discretionary access control\n        echo \"-[·] audit the change of discretionary access control\"\n        local keyArray=(\"(chmod|fchmod|fchmodat)\" \"(chown|fchown|fchownat)\" \"(setxattr|lsetxattr|removexattr)\" \"(lock|time)\")\n        for i in ${keyArray[@]} ; do\n            if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')\n                echo -e \"\\033[32m-[+] audit the use of systemcall  $i \\033[0m\"\n            else\n                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')\n                echo -e \"\\033[31m-[-] not audit the use of systemcall $i \\033[0m\"\n            fi\n        done\n        # 4.3.7 audit the events of unsuccessful unauthorized file access attempts\n        echo \"-[·] audit the events of unsuccessful unauthorized file access attempts\"\n        local keyArray=(\"(create|open|openat|truncate|ftruncate).*?exit=-EACCESS\" \"(create|open|openat|truncate|ftruncate).*?exit=-EPERM\" )\n        for i in ${keyArray[@]} ; do\n            if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                echo -e \"\\033[32m-[+] audit the use of systemcall  $i \\033[0m\"\n            else\n                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                echo -e \"\\033[31m-[-] not audit the use of systemcall $i \\033[0m\"\n            fi\n        done\n        # 4.3.8 audit the use of privileged commands\n        echo \"-[·] audit the use of privileged commands\"\n        #find / -name \"passwd\"\n        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\"}'\n        for i in ${res[@]} ; do\n            if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                echo -e \"\\033[32m-[+] audit the use of command  $i \\033[0m\"\n            else\n                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                echo -e \"\\033[31m-[-] not audit the use of command $i \\033[0m\"\n            fi\n        done\n        # 4.3.9 audit the change of file sudoer\n        echo \"-[·] audit the change of file sudoer\"\n        local keyArray=(\"/etc/sudoers\" \"/etc/sudoers.d/\")\n        for i in ${keyArray[@]} ; do\n            if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                echo -e \"\\033[32m-[+] audit the change of file  $i \\033[0m\"\n            else\n                i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                echo -e \"\\033[31m-[-] not audit the change of file $i \\033[0m\"\n            fi\n        done\n        # 4.3.10 check the audit configuration is setted to immutable unless reboot the server\n        echo \"-[·] check the audit configuration is setted to immutable unless reboot the server\"\n        local res=$(grep \"^\\s*[^#]\" /etc/audit/audit.rules|tail -1|egrep \"-e.*?2\")\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m-[+] auditd setted -e 2 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] auditd not setted -e 2 \\033[0m\"\n        fi\n    else\n        echo -e \"\\033[32m[+] /etc/audit/audit.rules is not exist \\033[0m\"\n    fi\n}\n\nfunction log_check {\n    echo \"[·] check log configuration\"\n\t# 5.1 ensure auditd is enabled\n    echo \"-[·] check rsyslog if is enabled\"\n\tif [[ $(systemctl is-enabled rsyslog) = \"enabled\" ]]; then\n\t\techo -e \"\\033[32m-[+] rsyslog is enabled \\033[0m\"\n\telse\n\t\techo -e \"\\033[31m-[-] rsyslog is not enabled \\033[0m\"\n\tfi\n    \n\n}\n\nfunction authentication_check {\n    echo \"[·] check cron ssh pam and env configuration\"\n    # 6.1 cron configuration\n    echo \"-[·] check cron configuration\"\n    # 6.1.1 check cron service is enabled\n    echo \"-[·] check crond if is enabled\"\n\tif [[ $(systemctl is-enabled crond) = \"enabled\" ]]; then\n\t\techo -e \"\\033[32m-[+] crond is enabled \\033[0m\"\n\telse\n\t\techo -e \"\\033[31m-[-] crond is not enabled \\033[0m\"\n\tfi\n    # 6.1.2 check cron's configuration file permission\n    echo \"-[·] check cron's configuration file permission\"\n    local keyArray=(\"/etc/crontab\" \"/etc/cron.hourly\" \"/etc/cron.daily\" \"/etc/cron.weekly\" \"/etc/cron.monthly\" \"/etc/cron.d\")\n    for i in ${keyArray[@]} ; do\n        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)\n        if [[ $res = \"0600\" ]] || [[ $res = \"0700\" ]]; then\n            echo -e \"\\033[32m-[+] file $i's permission is $res \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \\033[0m\"\n        fi\n    done\n    # 6.1.3 check cron.allow cron.deny permission and owner\n    echo \"-[·] check cron.allow cron.deny configuration file permission\"\n    local keyArray=(\"/etc/cron.allow\" \"/etc/cron.deny\")\n    for i in ${keyArray[@]} ; do\n        if [[ ! -f $i ]]; then\n            echo -e \"\\033[31m-[-] file $i not exist \\033[0m\"\n            continue\n        fi\n        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)\n        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)\n        if [[ $res1 = \"0600\" ]] || [[ $res1 = \"0700\" ]]; then\n            echo -e \"\\033[32m-[+] file $i's permission is $res \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \\033[0m\"\n        fi\n        if [[ $res2 = \"root root\" ]]; then\n            echo -e \"\\033[32m-[+] file $i's owner is $res2 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $i's owner is not root \\033[0m\"\n        fi\n    done\n    \n    # 6.2 SSH configuration\n    echo \"-[·] check ssh configuration\"\n\tif [[ $(systemctl is-enabled sshd) = \"enabled\" ]]; then\n        # 6.2.1 /etc/ssh/sshd_config permission 0600\n        local file=\"/etc/ssh/sshd_config\"\n        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)\n        if [[ $res = \"0600\" ]]; then\n            echo -e \"\\033[32m-[+] file $file's access permission is $res \\033[0m\"\n        else\n            echo -e \"\\033[3-m-[-] file $file's access permission is $res \\033[0m\"\n        fi\n        # 6.2.2 check ssh x11 forwarding if is disabled\n        local res=$(grep \"^X11Forwaring\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            echo -e \"\\033[32m-[+] X11Forwarding no \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] not set X11Forwarding no \\033[0m\"\n        fi\n        # 6.2.3 check ssh MaxAUTHTries if is 4\n        local res=$(grep \"^MaxAuthTries\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m-[+] $res \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] not set MaxAuthTries \\033[0m\"\n        fi\n        # 6.2.4 check ssh IgnoreRhosts if is enabled\n        local res=$(grep \"^IgnoreRhosts\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep yes) ]]; then\n            echo -e \"\\033[32m-[+] IgnoreRhosts yes \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] not set IgnoreRhosts no\\033[0m\"\n        fi\n        # 6.2.5 check ssh HostbasedAuthentication if is disabled\n        local res=$(grep \"^HostbasedAuthentication\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            echo -e \"\\033[32m-[+] HostbasedAuthentication no \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] not set HostbasedAuthentication no\\033[0m\"\n        fi\n        # 6.2.6 check ssh root login if is diabled\n        local res=$(grep \"^PermitRootLogin\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            echo -e \"\\033[32m-[+] PermitRootLogin no \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] not set PermitRootLogin no\\033[0m\"\n        fi\n        # 6.2.7 check ssh PermitEmptyPasswords if is diabled\n        local res=$(grep \"^PermitEmptyPasswords\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            echo -e \"\\033[32m-[+] PermitEmptyPasswords no \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] not set PermitEmptyPasswords no\\033[0m\"\n        fi\n        # 6.2.8 check ssh PermitUserEnvironment if is diabled\n        local res=$(grep \"^PermitUserEnvironment\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            echo -e \"\\033[32m-[+] PermitUserEnvironment no \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] not set PermitUserEnvironment no\\033[0m\"\n        fi\n        # 6.2.9 check if set specific MAC algorithms\n        local res=$(grep \"^MACs\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m-[+] will use specific MAC algorithms $res \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] not set specific MAC algorithms\\033[0m\"\n        fi\n        # 6.2.10 check SSH idle Timeout Interval if is configured\n        local res=$(grep \"^ClientAliveInterval\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m-[+] $res \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] not set ClientAliveInterval \\033[0m\"\n        fi\n        # 6.2.11 check SSH LoginGrace Time\n        local res=$(grep \"^LoginGraceTime\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m-[+] $res \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] not set LoginGraceTime \\033[0m\"\n        fi\n\telse\n\t\techo -e \"\\033[32m-[+] sshd is not enabled \\033[0m\"\n\tfi\n\n    # 6.3 PAM configuration\n    echo \"-[·] check pam configuration\"\n    # 6.3.1 password creation policy\n    if [[ -f /etc/security/pwquality.conf ]]; then\n        local minlen=$(grep ^minlen /etc/security/pwquality.conf | sed 's/ //g')\n        local minclass=$(grep ^minclass /etc/security/pwquality.conf |sed 's/ //g')\n        if [[ -n $minlen ]]; then\n            echo -e \"\\033[32m-[+] minimime length of password is $(echo $minlen|cut -d= -f2) \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] not set minlen \\033[0m\"\n        fi\n        if [[ -n $minclass ]]; then\n            echo -e \"\\033[32m-[+] minclass of password is $(echo $minclass|cut -d= -f2) \\033[0m\"\n        else\n            local keyArray=(\"^dcredit\" \"^lcredit\" \"^ocredit\" \"^ucredit\")\n            local tmpCount=0\n            for i in ${keyArray[@]}; do\n                if [[ -n  $(grep $i /etc/security/pwquality.conf) ]]; then\n                    tmpCount=$(expr 1 + $tmpCount)\n                fi\n            done\n            if [[ tmpCount -ge 2 ]]; then\n                echo -e \"\\033[32m-[+] minclass of passwd is $tmpCount \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] not set minclass \\033[0m\"\n            fi\n        fi\n    fi\n    # 6.3.2 lock account and unlock time\n    local files=(\"/etc/pam.d/password-auth\" \"/etc/pam.d/system-auth\")\n    local keyArray=(\"pam_faillock\\.so.*?unlock_time\")\n    for i in ${files[@]}; do\n        for k in ${keyArray[@]}; do\n            if [[ -n $(egrep $k $i ) ]]; then\n                echo -e \"\\033[32m-[+] set lock and unlock_time in $i \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] not set lock and unlock_time in $i \\033[0m\"\n            fi\n        done\n    done\n    # 6.3.3 check password reuse if is limited\n    for i in ${files[@]}; do\n        local res=$(egrep '^password\\s+sufficient\\s+pam_unix.so' $i)\n        if [[ -n $res ]] && [[ $res =~ \"remember=\" ]]; then\n            local tmp=$(echo $res|sed 's/.*\\(remember=[[:digit:]]\\).*/\\1/g'|sed 's/ //g'|cut -d= -f2)\n            echo -e \"\\033[32m-[+] password reuse limit is $tmp in $i \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] passowrd reuse limit not set in $i \\033[0m\"\n        fi\n    done\n    # 6.3.4 check the algorithm of store password if is sha512\n    for i in ${files[@]}; do\n        local res=$(egrep '^password\\s+sufficient\\s+pam_unix.so' $i)\n        if [[ -n $res ]] && [[ $res =~ \"sha512\" ]]; then\n            echo -e \"\\033[32m-[+] password storage algorithm is set to sha512 in $i \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] password storage algorithm is not specific to sha512 in $i \\033[0m\"\n        fi\n    done\n    # 6.4 user accounts and environment\n    echo \"-[·] check user accounts and environment\"\n    if [[ -f /etc/login.defs ]]; then\n        # 6.4.1 basic settings\n        local file='/etc/login.defs'\n        passMaxDays=$(grep ^PASS_MAX_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\\1/g')\n        passMinDays=$(grep ^PASS_MIN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\\1/g')\n        passWarnAge=$(grep ^PASS_WARN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\\1/g')\n        inactive=$(useradd -D|grep INACTIVE|sed 's/ //g'|cut -d= -f2)\n        if [[ $passMaxDays -le 90 ]]; then\n            echo -e \"\\033[32m-[+] the maximume days of password have to change is $passMaxDays \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the maximume days of password have to change is $passMaxDays ,should less than 90 day\\033[0m\"\n        fi\n        if [[ $passMinDays -ge 7 ]]; then\n            echo -e \"\\033[32m-[+] the minimume days of password have to change is $passMinDays \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the minimume days of password have to change is $passMinDays ,should great than 7 day\\033[0m\"\n        fi\n        if [[ $passWarnAge -ge 7 ]]; then\n            echo -e \"\\033[32m-[+] the minimume days of warn password need to change is $passWarnAge \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the minimume days of warn password need to change is $passWarnAge ,should greate than 7 day\\033[0m\"\n        fi\n        if [[ $inactive != -1 ]]; then\n            echo -e \"\\033[32m-[+] auto lock account when the  $inactive day haven't login \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] haven't set day of auto lock accounts \\033[0m\"\n        fi\n        # 6.4.2 check system's account if is unlogin\n        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}')\n        if [[ -z $res ]]; then\n            echo -e \"\\033[32m-[+] system account can't login \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the below user's shell need set to /sbin/nologin \\033[0m\"\n        fi\n        # 6.4.3 check default group for the root account if is GID 0\n        local res=$(grep \"^root:\" /etc/passwd|cut -d: -f4)\n        if [[ $res = 0 ]]; then\n            echo -e \"\\033[32m-[+] default group for the root account is GID 0 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-]] default group for the root account is is GID $res,not GID 0 \\033[0m\"\n        fi\n        # 6.4.4 check default user shell timeout if is 900 seconds or less\n        local files=(\"/etc/bashrc\" \"/etc/profile\")\n        for file in ${files[@]}; do\n            if [[ ! -f $file ]]; then\n                continue\n            fi\n            local res=$(grep \"^TMOUT\" $file|sed 's/ //g'|cut -d= -f2)\n            if [[ -z $res ]]; then\n                echo -e \"\\033[31m-[-] not set TMOUT in file $file \\033[0m\"\n                continue\n            fi\n            if [[ $res -le 900 ]]; then\n                echo -e \"\\033[32m-[+] when idle time great then $res seconds will close connection \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] when idle time great then $res seconds will close connection,the time should less than 900 seconds \\033[0m\"\n            fi\n        done\n        # 6.4.5 check access to su command if is restricted\n        local res=$(grep pam_wheel.so /etc/pam.d/su)\n        if [[ -n $res ]]; then\n            local res=$(grep wheel /etc/group|cut -d: -f4)\n            if [[ -n $res ]]; then\n                echo -e \"\\033[32m-[+] access to su command is specific to $res \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] access to su command is not restricted \\033[0m\"\n            fi\n        else\n            echo -e \"\\033[31m-[-] access to su command is not restricted \\033[0m\"\n        fi\n    else\n        echo -e \"\\033[31m-[-] file /etc/login.defs is not exist \\033[0m\"\n    fi\n}\n\nfunction system_check {\n    echo \"[·] check permission of important file and configuration of user and group\"\n    # 7.1 check permission of important file and uid gid\n    echo \"-[·] check permission of important file\"\n    local files=(\"/etc/passwd\" \"/etc/shadow\" \"/etc/group\" \"/etc/gshadow\" \"/etc/passwd-\" \"/etc/shadow-\" \"/etc/group-\" \"/etc/gshadow-\")\n    for file in ${files[@]}; do\n        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)\n        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)\n        if [[ $file =~ \"shadow\" ]]; then\n            if [[ $perm = \"0000\" ]]; then\n                echo -e \"\\033[32m-[+] file $file's permission is $perm \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] file $file's permission is $perm,should set to 0000 \\033[0m\"\n            fi\n        else\n            if [[ $perm = \"0644\" ]]; then\n                echo -e \"\\033[32m-[+] file $file's permission is $perm \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] file $file's permission is $perm,should set to 0644 \\033[0m\"\n\n            fi\n        fi\n        if [[ $uidGid = \"0 0\" ]]; then\n            echo -e \"\\033[32m-[+] file $file's uid gid is $uidGid \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $file's uid gid is $uidGid,should set to 0 0 \\033[0m\"\n        fi\n    done\n    # 7.2 check configuration of user and group\n    echo \"-[·] check configuration of user and group\"\n    # 7.2.1 check if user's password is empty\n    users=$(cat /etc/shadow |awk -F: '($2==\"!!\"){print $1}'|while read x;do \n        res=$(grep ${x} /etc/passwd|cut -d: -f7); if [[ $res != \"/sbin/nologin\" ]] && [[ $res != \"/sbin/shutdon\" ]] && [[ $res != \"/sbin/halt\" ]]; then \n            echo $x\n            #echo -e \"\\033[31m-[-] $x should have a passwd,not empty \\033[0m\"; \n            fi;\n        done)\n    if [[ -z $users ]]; then\n        echo -e \"\\033[32m-[+] all user account have set password \\033[0m\"\n    else\n        echo -e \"\\033[31m-[-] user:$(echo $users|sed 's/\\n/ /g') should set a password ,rather than empty \\033[0m\"\n    fi\n    # 7.2.2 check if root is the only UID 0 account\n    local users=$(cat /etc/passwd|awk -F: '($3==0){print $1}')\n    if [[ $users = 'root' ]]; then\n        echo -e \"\\033[32m-[+] root is the only account that uid is 0 \\033[0m\"\n    else\n        echo -e \"\\033[31m-[-] $(echo $users|sed 's/root//g') uid should not be 0 \\033[0m\"\n    fi\n    # 7.2.3 check root PATH integrith\n    if [ \"$(echo $PATH|grep ::)\" != \"\" ]; then\n        echo -e \"\\033[31m-[-] Empty Directory in PATH (::) \\033[0m\"\n    fi\n    if [ \"$(echo $PATH|grep :$)\" != \"\" ]; then\n        echo -e \"\\033[31m-[-] Trailing : in PATH \\033[0m\"\n    fi\n    path=$( echo $PATH|sed -e 's/::/:/' -e 's/:$//' -e 's/:/ /g')\n    set -- $path\n    while [[ $1 != \"\" ]]; do\n        if [[ $1 = \".\" ]]; then\n            echo -e \"\\033[31m-[-] PATH contains . \\033[0m\"\n            shift\n            continue\n        fi\n        if [[ -d $1 ]]; then\n            local dirperm=$(ls -ldH $1|cut -d\" \" -f1)\n            if [[ $(echo $dirperm|cut -c6) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Group Write permission should not set on directory $1 \\033[0m\"\n            fi\n            if [[ $(echo $dirperm|cut -c9) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Write permission should not set on directory $1 \\033[0m\"\n            fi\n            local dirown=$(ls -ldH $1|awk '{print $3}')\n            if [[ $dirown != \"root\" ]]; then\n                echo -e \"\\033[31m-[-] dir $1's owner is $dirown,should be root \\033[0m\"\n            fi\n        else\n            echo -e \"\\033[31m-[-] $1 is not a directory or not exist \\033[0m\"\n        fi\n        shift\n    done\n    # 7.2.4 check if is all users' home directories exist\n    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\n        if [[ ! -d $dir ]]; then\n            echo -e \"\\033[31m-[-] the home directory ($dir) of user $user does not exist \\033[0m\"\n        else\n            # 7.2.5 check if users' home directories permissions are 750 or more restrictive\n            local dirperm=$(ls -ld $dir|cut -d\" \" -f1)\n            if [[ $(echo $dirperm |cut -c6) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Group Write permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            if [[ $(echo $dirperm |cut -c8) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Read permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            if [[ $(echo $dirperm |cut -c9) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Write permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            if [[ $(echo $dirperm |cut -c10) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Execute permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            # 7.2.6 check if is users own their home directory\n            local owner=$(stat -L -c \"%U\" $dir)\n            if [[ $owner != $user ]]; then\n                echo -e \"\\033[31m-[-]The home directory ($dir) of user $user is owned by $owner \\033[0m\"\n            fi\n            # 7.2.7 check users' dot files are not group or world  writable\n            for file in $dir/.[A-Za-z0-9]*; do\n                if [[ ! -h $file ]] && [[ -f $file ]]; then\n                    local fileperm=$(ls -ld $file|cut -d\" \" -f1)\n                    if [[ $(echo $fileperm|cut -c6) != \"-\" ]]; then\n                        echo -e \"\\033[31m-[-] Group Write permission set on file $file \\033[0m\"\n                    fi\n                    if [[ $(echo $fileperm|cut -c9) != \"-\" ]]; then\n                        echo -e \"\\033[31m-[-] Other Write permission set on file $file \\033[0m\"\n                    fi\n                fi\n            done\n            # 7.2.8 check if no usrs have .netrc .rhosts .forward file\n            if [[ ! -h $dir/.netrc ]] && [[ -f $dir/.netrc ]]; then\n                echo -e \"\\033[31m-[-] .netrc file $dir/.netrc exists \\033[0m\"\n            fi\n            if [[ ! -h $dir/.rhosts ]] && [[ -f $dir/.rhosts ]]; then\n                echo -e \"\\033[31m-[-] .rhosts file $dir/.rhosts exists \\033[0m\"\n            fi\n            if [[ ! -h $dir/.forward ]] && [[ -f $dir/.forward ]]; then\n                echo -e \"\\033[31m-[-] .forward file $dir/.forward exists \\033[0m\"\n            fi\n        fi\n        # 7.2.9 check if all groups in /etc/passwd exist in /etc/group\n        for i in $(cut -d: -s -f4 /etc/passwd|sort -u); do\n            grep -q -P \"^.*?:[^:]*:$i\" /etc/group\n            if [[ $? -ne 0 ]]; then\n                echo -e \"\\033[31m-[-] Group $i is referenced by /etc/passwd but does not exist in /etc/group \\033[0m\"\n            fi\n        done\n    done\n    # 7.2.10 check if every user has a unique UID\n    cat /etc/passwd|cut -d\":\" -f3|sort -n|uniq -c|while read x; do\n        [[ -z $x ]] && break\n        set - $x\n        if [[ $1 -gt 1 ]]; then\n            local users=$(awk -F: '($3==n){print $1}' n=$2 /etc/passwd|xargs)\n            echo -e \"\\033[31m-[-] Duplicate UID $2 : $users \\033[0m\"\n        fi\n    done\n    # 7.2.11 check if every group has a unique GID\n    cat /etc/group|cut -d\":\" -f3|sort -n|uniq -c|while read x; do\n        [[ -z $x ]] && break\n        set - $x\n        if [[ $1 -gt 1 ]]; then\n            local groups=$(awk -F: '($3==n){print $1}' n=$2 /etc/group|xargs)\n            echo -e \"\\033[31m-[-] Duplicate GID $2 : $groups \\033[0m\"\n        fi\n    done\n    # 7.2.12 check if user name is unique\n    cat /etc/passwd|cut -d\":\" -f1|sort -n|uniq -c|while read x; do\n        [[ -z $x ]] && break\n        set - $x11\n        if [[ $1 -gt 1 ]]; then\n            local uids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/passwd|xargs)\n            echo -e \"\\033[31m-[-] Duplicate user name $2 : $uids \\033[0m\"\n        fi\n        done\n    # 7.2.13 check if group name is unique\n    cat /etc/group|cut -d\":\" -f1|sort -n|uniq -c|while read x; do\n        [[ -z $x ]] && break\n        set - $x11\n        if [[ $1 -gt 1 ]]; then\n            local gids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/group|xargs)\n            echo -e \"\\033[31m-[-] Duplicate group name $2 : $gids \\033[0m\"\n        fi\n        done\n    \n\n}\n\necho \"\"\"\n==================================\n|        Linux 基线检查工具      |\n|        author:JC0o0l           |\n|        version:1.0             |\n==================================\n\"\"\"\n#get_basic_info\n#init_check\n#service_check\n#network_check\n#auditd_check\n#log_check\n#authentication_check\nsystem_check"
  },
  {
    "path": "baseline_check_v2.1_JC0o0l.sh",
    "content": "#!/bin/bash\nfunction get_ip_info {\n    local ipList=`ifconfig | grep inet |grep -v inet6|grep -v 127|sed 's/^[ ]*//g'|cut -d\" \" -f2`\n    echo $ipList\n}\nfunction get_basic_info {\n    echo [·] collect basic info\n    hostname=`hostname`\n    ipList=`get_ip_info`\n    kernelVersion=`uname -r`\n    if [[ $(cat /proc/version) =~ \"Red Hat\" ]]; then\n        osVersion=`cat /etc/redhat-release|cut -f1,4 -d\" \"`\n    fi\n    basic_info={\\\"hostname\\\":\\\"$hostname\\\",\\\"ipList\\\":\\\"$ipList\\\",\\\"kernelVersion\\\":\\\"$kernelVersion\\\",\\\"osVersion\\\":\\\"$osVersion\\\"}\n    echo $basic_info\n}\n\nfunction init_check {\n    # 1. init configuration\n    echo [·] check init configuration\n    # 1.1 file system configuration\n    # 1.1.1 /tmp separate mount\n    local tmpIfSeparate #=\"\"\n    local tmpIfNoexec #=\"\"\n    local tmpIfNosuid #=\"\"\n    local res=$(mount|grep \"/tmp \") \n    if [[ -z $res ]]; then\n        echo -e \"\\033[31m-[-] /tmp/ not mounted on separate dick\\033[0m\"\n        tmpIfSeparate=\"false\"\n        tmpIfNoexec=\"false\"\n        tmpIfNosuid=\"false\"\n    else\n        tmpIfSeparate=\"true\"\n        tmpIfNoexec=\"true\"\n        tmpIfNosuid=\"true\"\n    fi\n    if $tmpIfSeparate; then\n        #mount|grep \"/sys/kernel/debug \" |while read res;do\n        while read res;do\n            #echo \"mount | grep /sys --result-->\" $res\n            # 1.1.2 /tmp noexec nosuid\n            local diskPart=$(echo $res|cut -d\" \" -f3)\n            if [[ ! $res =~ \"noexec\" ]];then\n                echo -e \"\\033[31m-[-] no noexec option on $diskPart partion\\033[0m\"\n                tmpIfNoexec=\"false\"\n                if [[ ! $res =~ \"nosuid\" ]];then\n                    echo -e \"\\033[31m-[-] no nosuid option on $diskPart partion\\033[0m\"\n                    tmpIfNosuid=\"false\"\n                fi\n            elif [[ ! $res =~ \"nosuid\" ]];then\n                echo -e \"\\033[31m-[-] no nosuid option on $diskPart partion\\033[0m\"\n                tmpIfNosuid=\"false\"\n            fi\n        done < <(mount | grep \"/tmp \")\n    fi\n    tmp_partition_info={\\\"tmpIfSeparate\\\":\\\"$tmpIfSeparate\\\",\\\"tmpIfNoexec\\\":\\\"$tmpIfNoexec\\\",\\\"tmpIfNosuid\\\":\\\"$tmpIfNosuid\\\"}\n    #echo $tmp_partition_info\n    # 1.2 secure boot configuration\n    if [[ -f /boot/grub2/grub.cfg ]];then\n        grubcfgIfExist=\"true\"\n        grubcfgPermission=\"0600\"\n        grubcfgIfSetPasswd=\"true\"\n    else\n        grubcfgIfExist=\"false\"\n        grubcfgPermission=\"0000\"\n        grubcfgIfSetPasswd=\"false\"\n    fi\n    if $grubcfgIfExist; then\n        # 1.2.1 /boot/grub2/grub.cfg permission /boot/grub2/user.cfg permission 0600 root:root\n        res=$(stat /boot/grub2/grub.cfg |while read x;do if [[ $x =~ \"Uid\" ]] && [[ $x =~ \"(\" ]]; then echo $x;fi;done|cut -d\"(\" -f2,3,4)\n        grubcfgPermission=$(echo $res|cut -d\"/\" -f1)\n        if [[ $(echo $res|cut -d\"/\" -f1) = \"0600\" ]]; then\n            echo -e \"\\033[32m-[+] /boot/grub2/grub.cfg permission is 0600 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] /boot/grub2/grub.cfg permission is not 0600 \\033[0m\"\n        fi\n        # 1.2.2 Ensure bootloader password is set\n        res=$(grep \"^GRUB2 PASSWORD\" /boot/grub2/grub.cfg)\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m-[+] /boot/grub2/grub.cfg seted password \\033[0m\"\n            grubcfgIfSetPasswd=\"true\"\n        else\n            echo -e \"\\033[31m-[-] /boot/grub2/grub.cfg not set password \\033[0m\"\n            grubcfgIfSetPasswd=\"false\"\n        fi\n    fi\n        \n    # 1.2.3 single user mode need authentication\n    if [[ -f /usr/lib/systemd/system/rescue.service ]] && [[ -f /usr/lib/systemd/system/emergency.service ]]; then\n        res1=`grep /sbin/sulogin /usr/lib/systemd/system/rescue.service`\n        res2=`grep /sbin/sulogin /usr/lib/systemd/system/emergency.service`\n        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\n            echo -e \"\\033[32m-[+] single user mode need authentication \\033[0m\"\n            singleUserModeIfNeedAuth=\"true\"\n        else\n            echo -e \"\\033[31m-[+] single user mode does not need authentication \\033[0m\"\n            singleUserModeIfNeedAuth=\"false\"\n        fi\n    fi\n    # 1.3 Mantary Access Control\n    # 1.3.1 ensure the SELinux state is enforcing\n    if [[ -f /etc/selinux/config ]]; then\n        local num=$(sestatus|grep -c enforcing)\n        if [[ $num -gt 1 ]]; then\n            echo -e \"\\033[32m-[+] SELinux state is enforcing \\033[0m\"\n            selinuxStateIfEnforcing=\"true\"\n        else\n            echo -e \"\\033[31m-[-] SELinux state is not enforcing \\033[0m\"\n            selinuxStateIfEnforcing=\"false\"\n        fi\n    fi\n    # 1.3.2 ensure selinux policy is configured\n    if [[ -f /etc/selinux/config ]]; then\n        res=$(sestatus|grep targeted)\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m-[+] SELinux policy is configured \\033[0m\"\n            selinuxPolicyIfConfigured=\"true\"\n        else\n            echo -e \"\\033[31m-[-] SELinux policy is not configure to targeted \\033[0m\"\n            selinuxPolicyIfConfigured=\"false\"\n        fi\n    fi\n    boot_secure_info={\\\"grubcfgIfExist\\\":\\\"$grubcfgIfExist\\\",\\\"grubcfgPermission\\\":\\\"$grubcfgPermission\\\",\\\"grubcfgIfSetPasswd\\\":\\\"$grubcfgIfSetPasswd\\\",\\\"singleUserModeIfNeedAuth\\\":\\\"$singleUserModeIfNeedAuth\\\",\\\"selinuxStateIfEnforcing\\\":\\\"$selinuxStateIfEnforcing\\\",\\\"selinuxPolicyIfConfigured\\\":\\\"$selinuxPolicyIfConfigured\\\"}\n    #echo $boot_secure_info\n    init_check_res={\\\"tmp_partition_info\\\":$tmp_partition_info,\\\"boot_secure_info\\\":$boot_secure_info}\n}\nfunction service_check {\n    # 2. service configuration\n    echo [·] check service configuration\n    # 2.1 time sync\n    # 2.1.1 time sync service is installed\n    if $(rpm -q ntp 1>/dev/null||rpm -q chrony 1>/dev/null) ; then\n        if $(rpm -q ntp 1>/dev/null) ; then\n            if [[ -f /etc/ntp.conf ]]; then\n                local res=$(egrep \"^(server|pool)\" /etc/ntp.conf)\n                if [[ -n $res ]]; then\n                    echo -e \"\\033[32m-[+] remote ntp server is configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"true\"\n                else\n                    echo -e \"\\033[31m-[-] remote ntp server is not configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"false\"\n                fi\n            fi\n        fi\n        if $(rpm -q chrony 1>/dev/null); then\n            if [[ -f /etc/chrony.conf ]]; then\n                local res=$(egrep \"^(server|pool)\" /etc/chrony.conf)\n                if [[ -n $res ]]; then\n                    echo -e \"\\033[32m-[+] remote chrony server is configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"true\"\n                else\n                    echo -e \"\\033[31m-[-] remote chrony server is not configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"false\"\n                fi\n                \n            fi\n        fi\n    fi        \n    # 2.1.2 x-window\n    local res=$(rpm -qa xorg-x11*)\n    if [[ -z $res ]]; then\n        echo -e \"\\033[32m-[+] x11-windows is not installed \\033[0m\"\n        x11windowIfNotInstalled=\"true\"\n    else\n        echo -e \"\\033[31m-[-] x11-windows is installed \\033[0m\"\n        x11windowIfNotInstalled=\"false\"\n    fi\n    service_check_res={\\\"timeSyncServerIfConfigured\\\":\\\"$timeSyncServerIfConfigured\\\",\\\"x11windowIfNotInstalled\\\":\\\"$x11windowIfNotInstalled\\\"}\n}\nfunction network_check {\n    # 3. network configuration\n    echo [·] check network configuration\n    # 3.1 hosts file configuration\n    # 3.1.1 check /etc/hosts.deny file\n    if [[ -f /etc/hosts.deny ]]; then\n        hostsDenyFileIfExist=\"true\"\n        echo -e \"\\033[32m-[+] file /etc/hosts.deny exists \\033[0m\"\n        local res=$(stat /etc/hosts.deny |while read x;do if [[ $x =~ \"Uid\" ]] && [[ $x =~ \"(\" ]]; then echo $x;fi;done|cut -d\"(\" -f2,3,4)\n        hostsDenyFilePermission=$(echo $res|cut -d\"/\" -f1)\n        if [[ $(echo $res|cut -d\"/\" -f1) = \"0644\" ]];then\n            echo -e \"\\033[32m-[+] file /etc/hosts.deny permission is 0644 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file /etc/hosts.deny permission is not 0644 \\033[0m\"\n        fi\n\n        local res=$(egrep \"^[^#].+\" /etc/hosts.deny)\n        if [[ -n $res ]]; then\n            hostsDenyFileIfConfigured=\"true\"\n            echo -e \"\\033[32m-[+] file /etc/hosts.deny is configured \\033[0m\"\n        else\n            hostsDenyFileIfConfigured=\"false\"\n            echo -e \"\\033[31m-[-] file /etc/hosts.deny is not configured \\033[0m\"\n        fi\n    else\n        hostsDenyFileIfExist=\"false\"\n        echo -e \"\\033[31m-[-] file /etc/hosts.deny does not exists \\033[0m\"\n    fi\n    # 3.1.2 check /etc/hosts.allow file\n    if [[ -f /etc/hosts.allow ]]; then\n        hostsAllowFileIfExist=\"true\"\n        echo -e \"\\033[32m-[+] file /etc/hosts.allow exists \\033[0m\"\n        local res=`stat /etc/hosts.allow |while read x;do if [[ $x =~ \"Uid\" ]] && [[ $x =~ \"(\" ]]; then echo $x;fi;done|cut -d\"(\" -f2,3,4`\n        hostsAllowFilePermission=$(echo $res|cut -d\"/\" -f1)\n        if [[ $(echo $res|cut -d\"/\" -f1) = \"0644\" ]];then\n            echo -e \"\\033[32m-[+] file /etc/hosts.allow permission is 0644 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file /etc/hosts.allow permission is not 0644 \\033[0m\"\n        fi\n\n        local res=$(egrep \"^[^#].+\" /etc/hosts.deny)\n        if [[ -n $res ]]; then\n            hostsAllowFileIfConfigured=\"true\"\n            echo -e \"\\033[32m-[+] file /etc/hosts.allow is configured \\033[0m\"\n        else\n            hostsAllowFileIfConfigured=\"false\"\n            echo -e \"\\033[31m-[-] file /etc/hosts.allow is not configured \\033[0m\"\n        fi\n    else\n        hostsAllowFileIfExist=\"false\"\n        echo -e \"\\033[31m-[-] file /etc/hosts.allow does not exists \\033[0m\"\n    fi\n\n    # 3.2 firewall configuration\n    # 3.2.1 ensure iptables is installed\n    if $(rpm -q iptables 1>/dev/null); then\n        iptablesIfInstalled=\"true\"\n        echo -e \"\\033[32m-[+] iptables is installed \\033[0m\"\n        # 3.2.2 ensure INPUT OUTPUT chain policy is DROP\n        #iptables -L|grep policy|while read x;do\n        while read x;do\n            if [[ $x =~ \"INPUT\" ]] && [[ $x =~ \"DROP\" ]]; then\n                iptablesInputPolicyIfDrop=\"true\"\n                echo -e \"\\033[32m-[+] INPUT chain policy is DROP \\033[0m\"\n            elif [[ $x =~ \"INPUT\" ]] && [[ ! $x =~ \"DROP\" ]]; then\n                iptablesInputPolicyIfDrop=\"false\"\n                echo -e \"\\033[31m-[-] INPUT chain policy is not DROP \\033[0m\"\n            fi\n            if [[ $x =~ \"OUTPUT\" ]] && [[ $x =~ \"DROP\" ]]; then\n                iptablesOutputPolicyIfDrop=\"true\"\n                echo -e \"\\033[32m-[+] OUTPUT chain policy is DROP \\033[0m\"\n            elif [[ $x =~ \"OUTPUT\" ]] && [[ ! $x =~ \"DROP\" ]]; then\n                iptablesOutputPolicyIfDrop=\"false\"\n                echo -e \"\\033[31m-[-] OUTPUT chain policy is not DROP \\033[0m\"\n            fi\n        done < <(iptables -L|grep policy)\n    else\n        iptablesIfInstalled=\"false\"\n        echo -e \"\\033[31m-[-] iptables is not installed \\033[0m\"\n    fi\n    network_check_res={\\\"hostsAllowFileIfExist\\\":\\\"$hostsAllowFileIfExist\\\",\\\"hostsAllowFilePermission\\\":\\\"$hostsAllowFilePermission\\\",\\\"hostsAllowFileIfConfigured\\\":\\\"$hostsAllowFileIfConfigured\\\",\\\"hostsDenyFileIfExist\\\":\\\"$hostsDenyFileIfExist\\\",\\\"hostsDenyFilePermission\\\":\\\"$hostsDenyFilePermission\\\",\\\"hostsDenyFileIfConfigured\\\":\\\"$hostsDenyFileIfConfigured\\\",\\\"iptablesIfInstalled\\\":\\\"$iptablesIfInstalled\\\",\\\"iptablesInputPolicyIfDrop\\\":\\\"$iptablesInputPolicyIfDrop\\\",\\\"iptablesOutputPolicyIfDrop\\\":\\\"$iptablesOutputPolicyIfDrop\\\"}\n}\n\nfunction auditd_check {\n\t# 4. auditd configuration\n\techo [·] check auditd configuration\n\t# 4.1 ensure auditd is enabled\n    echo \"-[·] check auditd if is enabled\"\n\tif [[ $(systemctl is-enabled auditd) = \"enabled\" ]]; then\n\t\techo -e \"\\033[32m-[+] auditd is enabled \\033[0m\"\n        auditdIfEnabled=\"true\"\n\telse\n        auditdIfEnabled=\"false\"\n\t\techo -e \"\\033[31m-[-] auditd is not enabled \\033[0m\"\n\tfi\n\t# 4.2 some settings in /etc/audit/auditd.conf\n    echo \"-[·] settings in /etc/audit/auditd.conf\"\t\n    if [[ -f /etc/audit/auditd.conf ]]; then\n        auditdconfIfExist=\"true\"\n        maxLogFile=$(grep \"^max_log_file[[:blank:]]=\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        maxLogFileAction=$(grep \"^max_log_file_action\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        spaceLeftAction=$(grep \"^space_left_action\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        numLogs=$(grep \"^num_logs\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        if [[ -n $maxLogFile ]]; then\n            auditdIfSetMaxLogFile=$maxLogFile\n            echo -e \"\\033[32m-[+] max_log_file size is ${maxLogFile} M \\033[0m\"\n        else\n            auditdIfSetMaxLogFile=\"false\"\n            echo -e \"\\033[31m-[-] max_log_file size is not setted \\033[0m\"\n        fi\n        if [[ -n $maxLogFileAction ]]; then\n            auditdIfSetMaxLogFileAction=\"$maxLogFileAction\"\n            echo -e \"\\033[32m-[+] max_log_file_action is ${maxLogFileAction}\\033[0m\"\n        else\n            auditdIfSetMaxLogFileAction=\"false\"\n            echo -e \"\\033[31m-[-] max_log_file_action is not setted \\033[0m\"\n        fi\n        if [[ -n $spaceLeftAction ]]; then\n            auditdIfSetSpaceLeftAction=\"$spaceLeftAction\"\n            echo -e \"\\033[32m-[+] space_left_action is ${spaceLeftAction}\\033[0m\"\n        else\n            auditdIfSetSpaceLeftAction=\"false\"\n            echo -e \"\\033[31m-[-] space_left_action is not setted \\033[0m\"\n        fi\n        if [[ -n $numLogs ]]; then\n            auditdIfSetNumLogs=\"$numLogs\"\n            echo -e \"\\033[32m-[+] the num of logs is ${numLogs} \\033[0m\"\n        else\n            auditdIfSetNumLogs=\"false\"\n            echo -e \"\\033[31m-[-] num_logs is not setted \\033[0m\"\n        fi\n    else\n        auditdconfIfExist=\"false\"\n    fi\n    auditd_config_info={\\\"auditdIfEnabled\\\":\\\"$auditdIfEnabled\\\",\\\"auditdconfIfExist\\\":\\\"$auditdconfIfExist\\\",\\\"auditdIfSetMaxLogFile\\\":\\\"$auditdIfSetMaxLogFile\\\",\\\"auditdIfSetMaxLogFileAction\\\":\\\"$auditdIfSetMaxLogFileAction\\\",\\\"auditdIfSetSpaceLeftAction\\\":\\\"$auditdIfSetSpaceLeftAction\\\",\\\"auditdIfSetNumLogs\\\":\\\"$auditdIfSetNumLogs\\\"}\n    echo $auditd_config_info\n    # 4.3 rules in /etc/audit/audit.rules\n    # arch 64\n    echo \"-[·] time-change\" \n    if [[ -f /etc/audit/audit.rules ]]; then\n        auditdrulesIfExist=\"true\"\n        echo -e \"\\033[32m-[+] /etc/audit/audit.rules is exist \\033[0m\"\n        if [[ ! -n $(grep time /etc/audit/audit.rules) ]]; then\n            auditdRulesIfNotNull=\"false\"\n            echo -e \"\\033[31m-[-] not set rule about audit the change of date and time \\033[0m\"\n        else\n            auditdRulesIfNotNull=\"true\"\n            # 4.3.1 time-change\n            local timeChangeList=$(egrep \"(stime|clock_settime|adjtimex|settimeofday|/etc/localtime)\" /etc/audit/audit.rules|wc -l)\n            if [[ ${timeChangeList} -gt 3 ]]; then\n                auditdIfCheckTimechange=\"true\"\n                echo -e \"\\033[32m-[+] audith the change of date and time \\033[0m\"\n            elif [[ ${timeChangeList} -gt 1 ]]; then\n                auditdIfCheckTimechange=\"false\"\n                echo -e \"\\033[31m-[-] not fully set rule about audit the change of date and time \\033[0m\"\n            else \n                auditdIfCheckTimechange=\"false\"\n                echo -e \"\\033[31m-[-] not set rule about audit the change of date and time \\033[0m\"\n            fi\n            # 4.3.2 user and group change\n            echo \"-[·] user and group change\"\n            local keyArray=(\"/etc/passwd\" \"/etc/group\" \"/etc/gshadow\" \"/etc/shadow\" \"/etc/security/opasswd\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    echo -e \"\\033[32m-[+] audit the change of $i \\033[0m\"\n                else\n                    tmpArray2+=($i)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedUserandgroupfile=${tmpArray1[@]}\n            auditdRulesNotCheckedUserandgroupfile=${tmpArray2[@]}\n            # 4.3.3 system's network environment change\n            echo \"-[·] system's network environment change\"\n            local keyArray=(\"/etc/issue\" \"/etc/issue.net\" \"/etc/hosts\" \"/etc/sysconfig/network\" \"/etc/sysconfig/network-scripts/\" )\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                    if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    echo -e \"\\033[32m-[+] audit the change of $i \\033[0m\"\n                else\n                    tmpArray2+=($i)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            local keyArray=(\"sethostname\" \"setdomainname\")\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    echo -e \"\\033[32m-[+] audit the use of syscall  $i \\033[0m\"\n                else\n                    echo -e \"\\033[31m-[-] not audit the use of syscall $i \\033[0m\"\n                    tmpArray2+=($i)\n                fi\n            done\n            auditdRulesCheckedNetworkenv=${tmpArray1[@]}\n            auditdRulesNotCheckedNetworkenv=${tmpArray2[@]}\n            # 4.3.4 system's Mandatory Access Controls change\n            echo \"-[·] system's Mandatory Access Controls change\"\n            local keyArray=(\"/etc/selinux\" \"/usr/share/selinux\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    echo -e \"\\033[32m-[+] audit the change of   $i \\033[0m\"\n                else\n                    tmpArray2+=($i)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedMACchange=${tmpArray1[@]}\n            auditdRulesNotCheckedMACchange=${tmpArray2[@]}\n            # 4.3.5 audit events of login and logout\n            echo \"-[·] audit events of login and logout\"\n            local keyArray=(\"/var/log/lastlog\" \"/var/run/faillock/\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    echo -e \"\\033[32m-[+] audit the change of   $i \\033[0m\"\n                else\n                    tmpArray2+=($i)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedLoginoutEvents=${tmpArray1[@]}\n            auditdRulesNotCheckedLoginoutEvents=${tmpArray2[@]}\n            # 4.3.6 audit the change of discretionary access control\n            echo \"-[·] audit the change of discretionary access control\"\n            local keyArray=(\"(chmod|fchmod|fchmodat)\" \"(chown|fchown|fchownat)\" \"(setxattr|lsetxattr|removexattr)\" \"(lock|time)\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')\n                    echo -e \"\\033[32m-[+] audit the use of systemcall  $i \\033[0m\"\n                    tmpArray1+=($i)\n                else\n                    tmpArray2+=($i)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')\n                    echo -e \"\\033[31m-[-] not audit the use of systemcall $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedDACChangeSyscall=${tmpArray1[@]}\n            auditdRulesNotCheckedDACChangeSyscall=${tmpArray2[@]}\n            # 4.3.7 audit the events of unsuccessful unauthorized file access attempts\n            echo \"-[·] audit the events of unsuccessful unauthorized file access attempts\"\n            local keyArray=(\"(create|open|openat|truncate|ftruncate).*?exit=-EACCESS\" \"(create|open|openat|truncate|ftruncate).*?exit=-EPERM\" )\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[32m-[+] audit the use of systemcall  $i \\033[0m\"\n                else\n                    tmpArray2+=($i)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[31m-[-] not audit the use of systemcall $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedFileAccessAttemptSyscall=${tmpArray1[@]}\n            auditdRulesNotCheckedFileAccessAttemptSyscall=${tmpArray2[@]}\n            # 4.3.8 audit the use of privileged commands\n            echo \"-[·] audit the use of privileged commands\"\n            #find / -name \"passwd\"\n            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\"}'\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${res[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[32m-[+] audit the use of command  $i \\033[0m\"\n                else\n                    tmpArray2+=($i)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[31m-[-] not audit the use of command $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedPrivilegedCommand=${tmpArray1[@]}\n            auditdRulesNotCheckedPrivilegedCommand=${tmpArray2[@]}\n            # 4.3.9 audit the change of file sudoer\n            echo \"-[·] audit the change of file sudoer\"\n            local keyArray=(\"/etc/sudoers\" \"/etc/sudoers.d/\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[32m-[+] audit the change of file  $i \\033[0m\"\n                else\n                    tmpArray2+=($i)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[31m-[-] not audit the change of file $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedSudoerFile=${tmpArray1[@]}\n            auditdRulesNotCheckedSudoerFile=${tmpArray2[@]}\n            # 4.3.10 check the audit configuration is setted to immutable unless reboot the server\n            echo \"-[·] check the audit configuration is setted to immutable unless reboot the server\"\n            local res=$(grep \"^\\s*[^#]\" /etc/audit/audit.rules|tail -1|egrep \"-e.*?2\")\n            if [[ -n $res ]]; then\n                auditdRulesIfImmutable=\"true\"\n                echo -e \"\\033[32m-[+] auditd setted -e 2 \\033[0m\"\n            else\n                auditdRulesIfImmutable=\"false\"\n                echo -e \"\\033[31m-[-] auditd not setted -e 2 \\033[0m\"\n            fi\n        fi\n    else\n        auditdrulesIfExist=\"false\"\n        echo -e \"\\033[32m-[+] /etc/audit/audit.rules is not exist \\033[0m\"\n    fi\n    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\\\"}\n    auditd_check_res={\\\"auditd_config_info\\\":$auditd_config_info,\\\"auditd_rules_info\\\":$auditd_rules_info}\n}\n\nfunction log_check {\n    echo \"[·] check log configuration\"\n\t# 5.1 ensure auditd is enabled\n    echo \"-[·] check rsyslog if is enabled\"\n\tif [[ $(systemctl is-enabled rsyslog) = \"enabled\" ]]; then\n        rsyslogIfEnabled=\"true\"\n\t\techo -e \"\\033[32m-[+] rsyslog is enabled \\033[0m\"\n\telse\n        rsyslogIfEnabled=\"false\"\n\t\techo -e \"\\033[31m-[-] rsyslog is not enabled \\033[0m\"\n\tfi\n    \n    log_check_res={\\\"rsyslogIfEnabled\\\":\\\"$rsyslogIfEnabled\\\"}\n\n}\n\nfunction authentication_check {\n    echo \"[·] check cron ssh pam and env configuration\"\n    # 6.1 cron configuration\n    echo \"-[·] check cron configuration\"\n    # 6.1.1 check cron service is enabled\n    echo \"-[·] check crond if is enabled\"\n\tif [[ $(systemctl is-enabled crond) = \"enabled\" ]]; then\n\t\techo -e \"\\033[32m-[+] crond is enabled \\033[0m\"\n        crondIfEnabled=\"true\"\n\telse\n        crondIfEnabled=\"false\"\n\t\techo -e \"\\033[31m-[-] crond is not enabled \\033[0m\"\n\tfi\n    # 6.1.2 check cron's configuration file permission\n    echo \"-[·] check cron's configuration file permission\"\n    local keyArray=(\"/etc/crontab\" \"/etc/cron.hourly\" \"/etc/cron.daily\" \"/etc/cron.weekly\" \"/etc/cron.monthly\" \"/etc/cron.d\")\n    crondConfigFilenameArray=$keyArray\n    tmpArray=()\n    for i in ${keyArray[@]} ; do\n        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)\n        tmpArray+=($res)\n        if [[ $res = \"0600\" ]] || [[ $res = \"0700\" ]]; then\n            echo -e \"\\033[32m-[+] file $i's permission is $res \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \\033[0m\"\n        fi\n    done\n    crondConfigFilePermission=${tmpArray[@]}\n    # 6.1.3 check cron.allow cron.deny permission and owner\n    echo \"-[·] check cron.allow cron.deny configuration file permission\"\n    local keyArray=(\"/etc/cron.allow\" \"/etc/cron.deny\")\n    crondallowdenyFilenameArray=$keyArray\n    tmpArray1=()\n    tmpArray2=()\n    tmpArray3=()\n    for i in ${keyArray[@]} ; do\n        if [[ ! -f $i ]]; then\n            tmpArray1+=(\"false\")\n            echo -e \"\\033[31m-[-] file $i not exist \\033[0m\"\n            continue\n        else\n            tmpArray1+=(\"true\")\n        fi\n        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)\n        tmpArray2+=($res1)\n        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)\n        tmpArray3+=(\"$res2\")\n        if [[ $res1 = \"0600\" ]] || [[ $res1 = \"0700\" ]]; then\n            echo -e \"\\033[32m-[+] file $i's permission is $res \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \\033[0m\"\n        fi\n        if [[ $res2 = \"root root\" ]]; then\n            echo -e \"\\033[32m-[+] file $i's owner is $res2 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $i's owner is not root \\033[0m\"\n        fi\n    done\n    crondallowdenyFileIfExistArray=${tmpArray1[@]}\n    crondallowdenyFilePermissionArray=${tmpArray2[@]}\n    crondallowdenyFileOwnerArray=${tmpArray3[@]}\n    crond_config_info={\\\"crondIfEnabled\\\":\\\"$crondIfEnabled\\\",\\\"crondConfigFilenameArray\\\":\\\"$crondConfigFilenameArray\\\",\\\"crondConfigFilePermissionArray\\\":\\\"$crondConfigFilePermissionArray\\\",\\\"crondallowdenyFilenameArray\\\":\\\"$crondallowdenyFilenameArray\\\",\\\"crondallowdenyFileIfExistArray\\\":\\\"$crondallowdenyFileIfExistArray\\\",\\\"crondallowdenyFilePermissionArray\\\":\\\"$crondallowdenyFilePermissionArray\\\",\\\"crondallowdenyFileOwnerArray\\\":\\\"$crondallowdenyFileOwnerArray\\\"}\n    # 6.2 SSH configuration\n    echo \"-[·] check ssh configuration\"\n\tif [[ $(systemctl is-enabled sshd) = \"enabled\" ]]; then\n        sshdIfEnabled=\"true\"\n        # 6.2.1 /etc/ssh/sshd_config permission 0600\n        local file=\"/etc/ssh/sshd_config\"\n        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)\n        if [[ $res = \"0600\" ]]; then\n            sshdConfigFilePermission=$res\n            echo -e \"\\033[32m-[+] file $file's access permission is $res \\033[0m\"\n        else\n            sshdConfigFilePermission=\"false\"\n            echo -e \"\\033[3-m-[-] file $file's access permission is $res \\033[0m\"\n        fi\n        # 6.2.2 check ssh x11 forwarding if is disabled\n        local res=$(grep \"^X11Forwaring\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisableX11forwarding=\"true\"\n            echo -e \"\\033[32m-[+] X11Forwarding no \\033[0m\"\n        else\n            sshdIfDisableX11forwarding=\"false\"\n            echo -e \"\\033[31m-[-] not set X11Forwarding no \\033[0m\"\n        fi\n        # 6.2.3 check ssh MaxAUTHTries if is 4\n        local res=$(grep \"^MaxAuthTries\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSetMaxAuthTries=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\\2/')\n            echo -e \"\\033[32m-[+] $res \\033[0m\"\n        else\n            sshdIfSetMaxAuthTries=\"false\"\n            echo -e \"\\033[31m-[-] not set MaxAuthTries \\033[0m\"\n        fi\n        # 6.2.4 check ssh IgnoreRhosts if is enabled\n        local res=$(grep \"^IgnoreRhosts\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep yes) ]]; then\n            sshdIfEnableIgnoreRhosts=\"true\"\n            echo -e \"\\033[32m-[+] IgnoreRhosts yes \\033[0m\"\n        else\n            sshdIfEnableIgnoreRhosts=\"false\"\n            echo -e \"\\033[31m-[-] not set IgnoreRhosts no\\033[0m\"\n        fi\n        # 6.2.5 check ssh HostbasedAuthentication if is disabled\n        local res=$(grep \"^HostbasedAuthentication\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisableHostbasedAuthentication=\"true\"\n            echo -e \"\\033[32m-[+] HostbasedAuthentication no \\033[0m\"\n        else\n            sshdIfDisableHostbasedAuthentication=\"false\"\n            echo -e \"\\033[31m-[-] not set HostbasedAuthentication no\\033[0m\"\n        fi\n        # 6.2.6 check ssh root login if is diabled\n        local res=$(grep \"^PermitRootLogin\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisablePermitRootLogin=\"true\"\n            echo -e \"\\033[32m-[+] PermitRootLogin no \\033[0m\"\n        else\n            sshdIfDisablePermitRootLogin=\"false\"\n            echo -e \"\\033[31m-[-] not set PermitRootLogin no\\033[0m\"\n        fi\n        # 6.2.7 check ssh PermitEmptyPasswords if is diabled\n        local res=$(grep \"^PermitEmptyPasswords\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisablePermitEmptyPasswords=\"true\"\n            echo -e \"\\033[32m-[+] PermitEmptyPasswords no \\033[0m\"\n        else\n            sshdIfDisablePermitEmptyPasswords=\"false\"\n            echo -e \"\\033[31m-[-] not set PermitEmptyPasswords no\\033[0m\"\n        fi\n        # 6.2.8 check ssh PermitUserEnvironment if is diabled\n        local res=$(grep \"^PermitUserEnvironment\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisablePermitUserEnvironment=\"true\"\n            echo -e \"\\033[32m-[+] PermitUserEnvironment no \\033[0m\"\n        else\n            sshdIfDisablePermitUserEnvironment=\"false\"\n            echo -e \"\\033[31m-[-] not set PermitUserEnvironment no\\033[0m\"\n        fi\n        # 6.2.9 check if set specific MAC algorithms\n        local res=$(grep \"^MACs\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSpecificMACs=\"true\"\n            echo -e \"\\033[32m-[+] will use specific MAC algorithms $res \\033[0m\"\n        else\n            sshdIfSpecificMACs=\"false\"\n            echo -e \"\\033[31m-[-] not set specific MAC algorithms\\033[0m\"\n        fi\n        # 6.2.10 check SSH idle Timeout Interval if is configured\n        local res=$(grep \"^ClientAliveInterval\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSetClientAliveInterval=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\\2/')\n            echo -e \"\\033[32m-[+] $res \\033[0m\"\n        else\n            sshdIfSetClientAliveInterval=\"false\"\n            echo -e \"\\033[31m-[-] not set ClientAliveInterval \\033[0m\"\n        fi\n        # 6.2.11 check SSH LoginGrace Time\n        local res=$(grep \"^LoginGraceTime\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSetLoginGraceTime=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\\2/')\n            echo -e \"\\033[32m-[+] $res \\033[0m\"\n        else\n            sshdIfSetLoginGraceTime=\"false\"\n            echo -e \"\\033[31m-[-] not set LoginGraceTime \\033[0m\"\n        fi\n\telse\n        sshdIfEnabled=\"false\"\n\t\techo -e \"\\033[32m-[+] sshd is not enabled \\033[0m\"\n\tfi\n    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\\\"}\n\n    # 6.3 PAM configuration\n    echo \"-[·] check pam configuration\"\n    # 6.3.1 password creation policy\n    if [[ -f /etc/security/pwquality.conf ]]; then\n        pamPwqualityconfIfExist=\"true\"\n        local minlen=$(grep ^minlen /etc/security/pwquality.conf | sed 's/ //g')\n        local minclass=$(grep ^minclass /etc/security/pwquality.conf |sed 's/ //g')\n        if [[ -n $minlen ]]; then\n            pamIfSetMinlen=$(echo $minlen|cut -d= -f2)\n            echo -e \"\\033[32m-[+] minimime length of password is $(echo $minlen|cut -d= -f2) \\033[0m\"\n        else\n            pamIfSetMinlen=\"false\"\n            echo -e \"\\033[31m-[-] not set minlen \\033[0m\"\n        fi\n        if [[ -n $minclass ]]; then\n            pamIfSetMinclass=$(echo $minclass|cut -d= -f2)\n            echo -e \"\\033[32m-[+] minclass of password is $(echo $minclass|cut -d= -f2) \\033[0m\"\n        else\n            local keyArray=(\"^dcredit\" \"^lcredit\" \"^ocredit\" \"^ucredit\")\n            local tmpCount=0\n            for i in ${keyArray[@]}; do\n                if [[ -n  $(grep $i /etc/security/pwquality.conf) ]]; then\n                    tmpCount=$(expr 1 + $tmpCount)\n                fi\n            done\n            if [[ $tmpCount = 0 ]]; then\n                pamIfSetMinclass=\"false\"\n            else\n                pamIfSetMinclass=$tmpCount\n            fi\n            if [[ tmpCount -ge 2 ]]; then\n                echo -e \"\\033[32m-[+] minclass of passwd is $tmpCount \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] not set minclass \\033[0m\"\n            fi\n        fi\n    else\n        pamPwqualityconfIfExist=\"false\"\n    fi\n    # 6.3.2 lock account and unlock time\n    local files=(\"/etc/pam.d/password-auth\" \"/etc/pam.d/system-auth\")\n    local keyArray=(\"pam_faillock\\.so.*?unlock_time\")\n    tmpArray1=()\n    tmpArray2=()\n    for i in ${files[@]}; do\n        for k in ${keyArray[@]}; do\n            if [[ -n $(egrep $k $i ) ]]; then\n                echo -e \"\\033[32m-[+] set lock and unlock_time in $i \\033[0m\"\n                tmpArray1+=($i)\n            else\n                tmpArray2+=($i)\n                echo -e \"\\033[31m-[-] not set lock and unlock_time in $i \\033[0m\"\n            fi\n        done\n    done\n    sshdSetedLockAndUnlockTimeFiles=${tmpArray1[@]}\n    sshdNotSetedLockAndUnlockTimeFiles=${tmpArray2[@]}\n    # 6.3.3 check password reuse if is limited\n    sshdPamdFileArray=${files[@]}\n    tmpArray=()\n    for i in ${files[@]}; do\n        local res=$(egrep '^password\\s+sufficient\\s+pam_unix.so' $i)\n        if [[ -n $res ]] && [[ $res =~ \"remember=\" ]]; then\n            local tmp=$(echo $res|sed 's/.*\\(remember=[[:digit:]]\\).*/\\1/g'|sed 's/ //g'|cut -d= -f2)\n            tmpArray+=($tmp)\n            echo -e \"\\033[32m-[+] password reuse limit is $tmp in $i \\033[0m\"\n        else\n            tmpArray+=(\"false\")\n            echo -e \"\\033[31m-[-] passowrd reuse limit not set in $i \\033[0m\"\n        fi\n    done\n    sshdPamdFileReuseLimitArray=${tmpArray[@]}\n    # 6.3.4 check the algorithm of store password if is sha512\n    tmpArray=()\n    for i in ${files[@]}; do\n        local res=$(egrep '^password\\s+sufficient\\s+pam_unix.so' $i)\n        if [[ -n $res ]] && [[ $res =~ \"sha512\" ]]; then\n            tmpArray+=(\"true\")\n            echo -e \"\\033[32m-[+] password storage algorithm is set to sha512 in $i \\033[0m\"\n        else\n            tmpArray+=(\"false\")\n            echo -e \"\\033[31m-[-] password storage algorithm is not specific to sha512 in $i \\033[0m\"\n        fi\n    done\n    sshdPamdFileIfSetSha512=${tmpArray[@]}\n    pam_config_info={\\\"pamPwqualityconfIfExist\\\":\\\"$pamPwqualityconfIfExist\\\",\\\"pamIfSetMinlen\\\":\\\"$pamIfSetMinlen\\\",\\\"pamIfSetMinclass\\\":\\\"$pamIfSetMinclass\\\",\\\"sshdSetedLockAndUnlockTimeFiles\\\":\\\"$sshdSetedLockAndUnlockTimeFiles\\\",\\\"sshdNotSetedLockAndUnlockTimeFiles\\\":\\\"$sshdNotSetedLockAndUnlockTimeFiles\\\",\\\"sshdPamdFileArray\\\":\\\"$sshdPamdFileArray\\\",\\\"sshdPamdFileReuseLimitArray\\\":\\\"$sshdPamdFileReuseLimitArray\\\",\\\"sshdPamdFileIfSetSha512\\\":\\\"$sshdPamdFileIfSetSha512\\\"}\n    # 6.4 user accounts and environment\n    echo \"-[·] check user accounts and environment\"\n    if [[ -f /etc/login.defs ]]; then\n        accountLogindefsIfExist=\"true\"\n        # 6.4.1 basic settings\n        local file='/etc/login.defs'\n        passMaxDays=$(grep ^PASS_MAX_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\\1/g')\n        passMinDays=$(grep ^PASS_MIN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\\1/g')\n        passWarnAge=$(grep ^PASS_WARN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\\1/g')\n        inactive=$(useradd -D|grep INACTIVE|sed 's/ //g'|cut -d= -f2)\n        accountPassMaxDays=$passMaxDays\n        accountPassMinDays=$passMinDays\n        accountPassWarnDays=$passWarnAge\n        accountPassAutolockInactiveDays=$inactive\n        if [[ $passMaxDays -le 90 ]]; then\n            echo -e \"\\033[32m-[+] the maximume days of password have to change is $passMaxDays \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the maximume days of password have to change is $passMaxDays ,should less than 90 day\\033[0m\"\n        fi\n        if [[ $passMinDays -ge 7 ]]; then\n            echo -e \"\\033[32m-[+] the minimume days of password have to change is $passMinDays \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the minimume days of password have to change is $passMinDays ,should great than 7 day\\033[0m\"\n        fi\n        if [[ $passWarnAge -ge 7 ]]; then\n            echo -e \"\\033[32m-[+] the minimume days of warn password need to change is $passWarnAge \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the minimume days of warn password need to change is $passWarnAge ,should greate than 7 day\\033[0m\"\n        fi\n        if [[ $inactive != -1 ]]; then\n            echo -e \"\\033[32m-[+] auto lock account when the  $inactive day haven't login \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] haven't set day of auto lock accounts \\033[0m\"\n        fi\n        # 6.4.2 check system's account if is unlogin\n        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}')\n        accountShouldUnloginAray=()\n        if [[ -z $res ]]; then\n            echo -e \"\\033[32m-[+] system account can't login \\033[0m\"\n        else\n            accountShouldUnloginAray=($(echo $res|sed 's/\\n/ /g'))\n            echo -e \"\\033[31m-[-]  ($(echo $res|sed 's/\\n/ /g'))user's shell need set to /sbin/nologin \\033[0m\"\n        fi\n        # 6.4.3 check default group for the root account if is GID 0\n        local res=$(grep \"^root:\" /etc/passwd|cut -d: -f4)\n        accountGIDOfRoot=$res\n        if [[ $res = 0 ]]; then\n            echo -e \"\\033[32m-[+] default group for the root account is GID 0 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-]] default group for the root account is is GID $res,not GID 0 \\033[0m\"\n        fi\n        # 6.4.4 check default user shell timeout if is 900 seconds or less\n        local files=(\"/etc/bashrc\" \"/etc/profile\")\n        tmpArray1=()\n        tmpArray2=()\n        for file in ${files[@]}; do\n            if [[ ! -f $file ]]; then\n                continue\n            else\n                tmpArray1+=($file)\n            fi\n            local res=$(grep \"^TMOUT\" $file|sed 's/ //g'|cut -d= -f2)\n            tmpArray2+=($res)\n            if [[ -z $res ]]; then\n                echo -e \"\\033[31m-[-] not set TMOUT in file $file \\033[0m\"\n                continue\n            fi\n            if [[ $res -le 900 ]]; then\n                echo -e \"\\033[32m-[+] when idle time great than $res seconds will close connection \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] when idle time great than $res seconds will close connection,the time should less than 900 seconds \\033[0m\"\n            fi\n        done\n        accountProfileFileArray=${tmpArray1[@]}\n        accountProfileTMOUTArray=${tmpArray2[@]}\n        # 6.4.5 check access to su command if is restricted\n        local res=$(grep pam_wheel.so /etc/pam.d/su)\n        accountIfSetUsersCanAccessSuCommand=\n        if [[ -n $res ]]; then\n            local res=$(grep wheel /etc/group|cut -d: -f4)\n            if [[ -n $res ]]; then\n                accountIfSetUsersCanAccessSuCommand=$res\n                echo -e \"\\033[32m-[+] access to su command is specific to $res \\033[0m\"\n            else\n                accountIfSetUsersCanAccessSuCommand=\"false\"\n                echo -e \"\\033[31m-[-] access to su command is not restricted \\033[0m\"\n            fi\n        else\n            accountIfSetUsersCanAccessSuCommand=\"false\"\n            echo -e \"\\033[31m-[-] access to su command is not restricted \\033[0m\"\n        fi\n    else\n        accountLogindefsIfExist=\"false\"\n        echo -e \"\\033[31m-[-] file /etc/login.defs is not exist \\033[0m\"\n    fi\n    account_config_info={\\\"accountPassMaxDays\\\":\\\"$accountPassMaxDays\\\",\\\"accountPassMinDays\\\":\\\"$accountPassMinDays\\\",\\\"accountPassWarnDays\\\":\\\"$accountPassWarnDays\\\",\\\"accountPassAutolockInactiveDays\\\":\\\"$accountPassAutolockInactiveDays\\\",\\\"accountShouldUnloginArray\\\":\\\"$accountShouldUnloginArray\\\",\\\"accountGIDOfRoot\\\":\\\"$accountGIDOfRoot\\\",\\\"accountProfileFileArray\\\":\\\"$accountProfileFileArray\\\",\\\"accountProfileTMOUTArray\\\":\\\"$accountProfileTMOUTArray\\\",\\\"accountIfSetUsersCanAccessSuCommand\\\":\\\"$accountIfSetUsersCanAccessSuCommand\\\"}\n    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}\n}\n\nfunction system_check {\n    echo \"[·] check permission of important file and configuration of user and group\"\n    # 7.1 check permission of important file and uid gid\n    echo \"-[·] check permission of important file\"\n    local files=(\"/etc/passwd\" \"/etc/shadow\" \"/etc/group\" \"/etc/gshadow\" \"/etc/passwd-\" \"/etc/shadow-\" \"/etc/group-\" \"/etc/gshadow-\")\n    importantFilenameArray=${files[@]}\n    tmpArray1=()\n    tmpArray2=()\n    for file in ${files[@]}; do\n        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)\n        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)\n        tmpArray1+=($perm)\n        tmpArray2+=($uidGid)\n        if [[ $file =~ \"shadow\" ]]; then\n            if [[ $perm = \"0000\" ]]; then\n                echo -e \"\\033[32m-[+] file $file's permission is $perm \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] file $file's permission is $perm,should set to 0000 \\033[0m\"\n            fi\n        else\n            if [[ $perm = \"0644\" ]]; then\n                echo -e \"\\033[32m-[+] file $file's permission is $perm \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] file $file's permission is $perm,should set to 0644 \\033[0m\"\n\n            fi\n        fi\n        if [[ $uidGid = \"0 0\" ]]; then\n            echo -e \"\\033[32m-[+] file $file's uid gid is $uidGid \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $file's uid gid is $uidGid,should set to 0 0 \\033[0m\"\n        fi\n    done\n    importantFilePermissionArray=${tmpArray1[@]}\n    importantFileUidgidArray=${tmpArray2[@]}\n    file_permission_info={\\\"importantFilenameArray\\\":\\\"$importantFilenameArray\\\",\\\"importantFilePermissionArray\\\":\\\"$importantFilePermissionArray\\\",\\\"importantFileUidgidArray\\\":\\\"$importantFileUidgidArray\\\"}\n    # 7.2 check configuration of user and group\n    echo \"-[·] check configuration of user and group\"\n    # 7.2.1 check if user's password is empty\n    users=$(cat /etc/shadow |awk -F: '($2==\"!!\"){print $1}'|while read x;do \n        res=$(grep ${x} /etc/passwd|cut -d: -f7); if [[ $res != \"/sbin/nologin\" ]] && [[ $res != \"/sbin/shutdon\" ]] && [[ $res != \"/sbin/halt\" ]]; then \n            echo $x\n            #echo -e \"\\033[31m-[-] $x should have a passwd,not empty \\033[0m\"; \n            fi;\n        done)\n    if [[ -z $users ]]; then\n        userIfSetPasswdOrArray=\"true\"\n        echo -e \"\\033[32m-[+] all user account have set password \\033[0m\"\n    else\n        userIfSetPasswdOrArray=$(echo $users|sed 's/\\n/ /g')\n        echo -e \"\\033[31m-[-] user:$(echo $users|sed 's/\\n/ /g') should set a password ,rather than empty \\033[0m\"\n    fi\n    # 7.2.2 check if root is the only UID 0 account\n    local users=$(cat /etc/passwd|awk -F: '($3==0){print $1}')\n    if [[ $users = 'root' ]]; then\n        uid0OnlyRootOrArray=\"true\"\n        echo -e \"\\033[32m-[+] root is the only account that uid is 0 \\033[0m\"\n    else\n        uid0OnlyRootOrArray=$(echo $users|sed 's/root//g'|sed 's/\\n/ /g')\n        echo -e \"\\033[31m-[-] $(echo $users|sed 's/root//g'|sed 's/\\n/ /g') uid should not be 0 \\033[0m\"\n    fi\n    # 7.2.3 check root PATH integrith\n    if [ \"$(echo $PATH|grep ::)\" != \"\" ]; then\n        echo -e \"\\033[31m-[-] Empty Directory in PATH (::) \\033[0m\"\n    fi\n    if [ \"$(echo $PATH|grep :$)\" != \"\" ]; then\n        echo -e \"\\033[31m-[-] Trailing : in PATH \\033[0m\"\n    fi\n    path=$( echo $PATH|sed -e 's/::/:/' -e 's/:$//' -e 's/:/ /g')\n    tmpArray1=()\n    tmpArray2=()\n    tmpArray3=()\n    tmpArray4=()\n    tmpArray5=()\n    set -- $path\n    while [[ $1 != \"\" ]]; do\n        if [[ $1 = \".\" ]]; then\n            echo -e \"\\033[31m-[-] PATH contains . \\033[0m\"\n            tmpArray1+=(\".\")\n            shift\n            continue\n        fi\n        if [[ -d $1 ]]; then\n            local dirperm=$(ls -ldH $1|cut -d\" \" -f1)\n            if [[ $(echo $dirperm|cut -c6) != \"-\" ]]; then\n                tmpArray2+=($1)\n                echo -e \"\\033[31m-[-] Group Write permission should not set on directory $1 \\033[0m\"\n            fi\n            if [[ $(echo $dirperm|cut -c9) != \"-\" ]]; then\n                tmpArray3+=($1)\n                echo -e \"\\033[31m-[-] Other Write permission should not set on directory $1 \\033[0m\"\n            fi\n            local dirown=$(ls -ldH $1|awk '{print $3}')\n            if [[ $dirown != \"root\" ]]; then\n                tmpArray4+=($1)\n                echo -e \"\\033[31m-[-] dir $1's owner is $dirown,should be root \\033[0m\"\n            fi\n        else\n            tmpArray5+=($1)\n            echo -e \"\\033[31m-[-] $1 is not a directory or not exist \\033[0m\"\n        fi\n        shift\n    done\n    if [[ ${#tmpArray1[@]} = 0 ]]; then\n        pathDirIfNotHasDot=\"true\"\n    else\n        pathDirIfNotHasDot=\"false\"\n    fi\n    pathDirPermissionHasGWArray=${tmpArray2[@]}\n    pathDirPermissionHasOWArray=${tmpArray2[@]}\n    pathDirOwnerIsNotRootArray=${tmpArray4[@]}\n    pathDirDoesNotExistOrNotDirArray=${tmpArray5[@]}\n    # 7.2.4 check if is all users' home directories exist\n    #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\n    tmpArray1=()\n    tmpArray2=()\n    tmpArray3=()\n    tmpArray4=()\n    tmpArray5=()\n    tmpArray6=()\n    while read user dir; do\n        tmpArray1+=($dir)\n        if [[ ! -d $dir ]]; then\n            tmpArray2+=(\"false\")\n            tmpArray3+=(\"false\")\n            echo -e \"\\033[31m-[-] the home directory ($dir) of user $user does not exist \\033[0m\"\n\n        else\n            tmpArray2+=(\"true\")\n            # 7.2.5 check if users' home directories permissions are 750 or more restrictive\n            local dirperm=$(ls -ld $dir|cut -d\" \" -f1)\n            tmpArray3+=($dirperm)\n            if [[ $(echo $dirperm |cut -c6) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Group Write permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            if [[ $(echo $dirperm |cut -c8) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Read permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            if [[ $(echo $dirperm |cut -c9) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Write permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            if [[ $(echo $dirperm |cut -c10) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Execute permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            # 7.2.6 check if is users own their home directory\n            local owner=$(stat -L -c \"%U\" $dir)\n            if [[ $owner != $user ]]; then\n                tmpArray4+=(\"false\")\n                echo -e \"\\033[31m-[-]The home directory ($dir) of user $user is owned by $owner \\033[0m\"\n            else\n                tmpArray4+=(\"true\")\n            fi\n            # 7.2.7 check users' dot files are not group or world  writable\n            local tmpc=0\n            for file in $dir/.[A-Za-z0-9]*; do\n                if [[ ! -h $file ]] && [[ -f $file ]]; then\n                    local fileperm=$(ls -ld $file|cut -d\" \" -f1)\n                    if [[ $(echo $fileperm|cut -c6) != \"-\" ]]; then\n                        tmpc=$(expr $tmpc + 1)\n                        echo -e \"\\033[31m-[-] Group Write permission set on file $file \\033[0m\"\n                    fi\n                    if [[ $(echo $fileperm|cut -c9) != \"-\" ]]; then\n                        tmpc=$(expr $tmpc + 1)\n                        echo -e \"\\033[31m-[-] Other Write permission set on file $file \\033[0m\"\n                    fi\n                fi\n            done\n            if [[ $tmpc = 0 ]]; then\n                tmpArray5+=(\"true\")\n            else\n                tmpArray5+=(\"false\")\n            fi\n            # 7.2.8 check if no usrs have .netrc .rhosts .forward file\n            tmpc=0\n            if [[ ! -h $dir/.netrc ]] && [[ -f $dir/.netrc ]]; then\n                tmpc=$(expr $tmpc + 1)\n                echo -e \"\\033[31m-[-] .netrc file $dir/.netrc exists \\033[0m\"\n            fi\n            if [[ ! -h $dir/.rhosts ]] && [[ -f $dir/.rhosts ]]; then\n                tmpc=$(expr $tmpc + 1)\n                echo -e \"\\033[31m-[-] .rhosts file $dir/.rhosts exists \\033[0m\"\n            fi\n            if [[ ! -h $dir/.forward ]] && [[ -f $dir/.forward ]]; then\n                tmpc=$(expr $tmpc + 1)\n                echo -e \"\\033[31m-[-] .forward file $dir/.forward exists \\033[0m\"\n            fi\n            if [[ $tmpc = 0 ]]; then\n                tmpArray6+=(\"true\")\n            else\n                tmpArray6+=(\"false\")\n            fi\n        fi\n    done < <(cat /etc/passwd|egrep -v '^(root|halt|sync|shutdown)'|awk -F: '($7 != \"/sbin/nologin\" && $7 != \"/bin/false\"){print $1 \" \" $6}')\n    userArray=${tmpArray1[@]}\n    userHomeDirIfExistArray=${tmpArray2[@]}\n    UserHomeDirPermissionArray=${tmpArray3[@]}\n    userIfOwnTheirHomeDirArray=${tmpArray4[@]}\n    userHomeDirIfHasGWorOWDotFileArray=${tmpArray5[@]}\n    userHomeDirIfHasOtherFileArray=${tmpArray6[@]}\n    # 7.2.9 check if all groups in /etc/passwd exist in /etc/group\n    tmpArray=()\n    for i in $(cut -d: -s -f4 /etc/passwd|sort -u); do\n        grep -q -P \"^.*?:[^:]*:$i\" /etc/group\n        if [[ $? -ne 0 ]]; then\n        tmpArray+=($i)\n            echo -e \"\\033[31m-[-] Group $i is referenced by /etc/passwd but does not exist in /etc/group \\033[0m\"\n        fi\n    done\n    groupNotExistInetcgroup=${tmpArray[@]}\n    # 7.2.10 check if every user has a unique UID\n    #cat /etc/passwd|cut -d\":\" -f3|sort -n|uniq -c|while read x; do\n    tmpArray=()\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x\n        if [[ $1 -gt 1 ]]; then\n            local users=$(awk -F: '($3==n){print $1}' n=$2 /etc/passwd|xargs)\n            tmpArray+=($2:$users\\;)\n            echo -e \"\\033[31m-[-] Duplicate UID $2 : $users \\033[0m\"\n        fi\n    done < <(cat /etc/passwd|cut -d\":\" -f3|sort -n|uniq -c)\n    usersIfHasUniqueUIDArray=${tmpArray[@]}\n    # 7.2.11 check if every group has a unique GID\n    tmpArray=()\n    #cat /etc/group|cut -d\":\" -f3|sort -n|uniq -c|while read x; do\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x\n        if [[ $1 -gt 1 ]]; then\n            local groups=$(awk -F: '($3==n){print $1}' n=$2 /etc/group|xargs)\n            tmpArray+=($2:$groups\\;)\n            echo -e \"\\033[31m-[-] Duplicate GID $2 : $groups \\033[0m\"\n        fi\n    done < <(cat /etc/group|cut -d\":\" -f3|sort -n|uniq -c)\n    groupsIfHasUniqueGIDArray=${tmpArray[@]}\n    # 7.2.12 check if user name is unique\n    tmpArray=()\n    #cat /etc/passwd|cut -d\":\" -f1|sort -n|uniq -c|while read x; do\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x11\n        if [[ $1 -gt 1 ]]; then\n            local uids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/passwd|xargs)\n            tmpArray+=($2:$uids\\;)\n            echo -e \"\\033[31m-[-] Duplicate user name $2 : $uids \\033[0m\"\n        fi\n    done < <(cat /etc/passwd|cut -d\":\" -f1|sort -n|uniq -c)\n    usersIfHasUniqueNameArray=${tmpArray[@]}\n    # 7.2.13 check if group name is unique\n    tmpArray=()\n    #cat /etc/group|cut -d\":\" -f1|sort -n|uniq -c|while read x; do\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x11\n        if [[ $1 -gt 1 ]]; then\n            local gids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/group|xargs)\n            tmpArray+=($2:$gids\\;)\n            echo -e \"\\033[31m-[-] Duplicate group name $2 : $gids \\033[0m\"\n        fi\n    done < <(cat /etc/group|cut -d\":\" -f1|sort -n|uniq -c)\n    groupsIfHasUniqueNameArray=${tmpArray[@]}\n    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\\\"}\n    system_check_res={\\\"file_permission_info\\\":$file_permission_info,\\\"usergroup_config_info\\\":$usergroup_config_info}\n\n}\n\necho \"\"\"\n==================================\n|        Linux 基线检查工具      |\n|        author:JC0o0l           |\n|        version:2.0             |\n==================================\n\"\"\"\nget_basic_info\ninit_check\nservice_check\nnetwork_check\nauditd_check\nlog_check\nauthentication_check\nsystem_check\nif [[ -z $authentication_check_res ]]; then\n    authentication_check_res={}\nfi\nif [[ -z $system_check_res ]]; then\n    system_check_res={}\nfi\ncheck_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}\ncurl -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\necho $check_result|jq "
  },
  {
    "path": "baseline_check_v2.2_JC0o0l.sh",
    "content": "#!/bin/bash\nfunction get_ip_info {\n    local ipList=`ifconfig | grep inet |grep -v inet6|grep -v 127|sed 's/^[ ]*//g'|cut -d\" \" -f2`\n    echo $ipList\n}\nfunction get_basic_info {\n    echo [·] collect basic info\n    scanTime=$(date \"+%Y-%m-%d %H:%M:%S\")\n    hostname=`hostname`\n    macaddr=$(echo $(ifconfig|grep \"ether\"|sed 's/^[ ]*//g'|cut -d\" \" -f2)|sed 's/ /;/g')\n    ipList=$(get_ip_info|sed 's/ /;/g')\n    kernelVersion=`uname -r`\n    if [[ $(cat /proc/version) =~ \"Red Hat\" ]]; then\n        osVersion=`cat /etc/redhat-release|cut -f1,4 -d\" \"`\n    fi\n    basic_info={\\\"scanTime\\\":\\\"$scanTime\\\",\\\"hostname\\\":\\\"$hostname\\\",\\\"macaddr\\\":\\\"$macaddr\\\",\\\"ipList\\\":\\\"$ipList\\\",\\\"kernelVersion\\\":\\\"$kernelVersion\\\",\\\"osVersion\\\":\\\"$osVersion\\\"}\n    echo $basic_info\n}\n\nfunction init_check {\n    # 1. init configuration\n    echo [·] check init configuration\n    # 1.1 file system configuration\n    # 1.1.1 /tmp separate mount\n    local tmpIfSeparate #=\"\"\n    local tmpIfNoexec #=\"\"\n    local tmpIfNosuid #=\"\"\n    local res=$(mount|grep \"/tmp \") \n    if [[ -z $res ]]; then\n        echo -e \"\\033[31m-[-] /tmp/ not mounted on separate dick\\033[0m\"\n        tmpIfSeparate=\"False\"\n        tmpIfNoexec=\"False\"\n        tmpIfNosuid=\"False\"\n    else\n        tmpIfSeparate=\"True\"\n        tmpIfNoexec=\"True\"\n        tmpIfNosuid=\"True\"\n    fi\n    if [[ $tmpIfSeparate == \"True\" ]]; then\n        #mount|grep \"/sys/kernel/debug \" |while read res;do\n        while read res;do\n            #echo \"mount | grep /sys --result-->\" $res\n            # 1.1.2 /tmp noexec nosuid\n            local diskPart=$(echo $res|cut -d\" \" -f3)\n            if [[ ! $res =~ \"noexec\" ]];then\n                echo -e \"\\033[31m-[-] no noexec option on $diskPart partion\\033[0m\"\n                tmpIfNoexec=\"False\"\n                if [[ ! $res =~ \"nosuid\" ]];then\n                    echo -e \"\\033[31m-[-] no nosuid option on $diskPart partion\\033[0m\"\n                    tmpIfNosuid=\"False\"\n                fi\n            elif [[ ! $res =~ \"nosuid\" ]];then\n                echo -e \"\\033[31m-[-] no nosuid option on $diskPart partion\\033[0m\"\n                tmpIfNosuid=\"False\"\n            fi\n        done < <(mount | grep \"/tmp \")\n    fi\n    tmp_partition_info={\\\"tmpIfSeparate\\\":\\\"$tmpIfSeparate\\\",\\\"tmpIfNoexec\\\":\\\"$tmpIfNoexec\\\",\\\"tmpIfNosuid\\\":\\\"$tmpIfNosuid\\\"}\n    #echo $tmp_partition_info\n    # 1.2 secure boot configuration\n    if [[ -f /boot/grub2/grub.cfg ]];then\n        grubcfgIfExist=\"True\"\n        grubcfgPermission=\"0600\"\n        grubcfgIfSetPasswd=\"True\"\n    else\n        grubcfgIfExist=\"False\"\n        grubcfgPermission=\"0000\"\n        grubcfgIfSetPasswd=\"False\"\n    fi\n    if [[ $grubcfgIfExist == \"True\" ]]; then\n        # 1.2.1 /boot/grub2/grub.cfg permission /boot/grub2/user.cfg permission 0600 root:root\n        res=$(stat /boot/grub2/grub.cfg |while read x;do if [[ $x =~ \"Uid\" ]] && [[ $x =~ \"(\" ]]; then echo $x;fi;done|cut -d\"(\" -f2,3,4)\n        grubcfgPermission=$(echo $res|cut -d\"/\" -f1)\n        if [[ $(echo $res|cut -d\"/\" -f1) = \"0600\" ]]; then\n            echo -e \"\\033[32m-[+] /boot/grub2/grub.cfg permission is 0600 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] /boot/grub2/grub.cfg permission is not 0600 \\033[0m\"\n        fi\n        # 1.2.2 Ensure bootloader password is set\n        res=$(grep \"^GRUB2 PASSWORD\" /boot/grub2/grub.cfg)\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m-[+] /boot/grub2/grub.cfg seted password \\033[0m\"\n            grubcfgIfSetPasswd=\"True\"\n        else\n            echo -e \"\\033[31m-[-] /boot/grub2/grub.cfg not set password \\033[0m\"\n            grubcfgIfSetPasswd=\"False\"\n        fi\n    fi\n        \n    # 1.2.3 single user mode need authentication\n    if [[ -f /usr/lib/systemd/system/rescue.service ]] && [[ -f /usr/lib/systemd/system/emergency.service ]]; then\n        res1=`grep /sbin/sulogin /usr/lib/systemd/system/rescue.service`\n        res2=`grep /sbin/sulogin /usr/lib/systemd/system/emergency.service`\n        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\n            echo -e \"\\033[32m-[+] single user mode need authentication \\033[0m\"\n            singleUserModeIfNeedAuth=\"True\"\n        else\n            echo -e \"\\033[31m-[+] single user mode does not need authentication \\033[0m\"\n            singleUserModeIfNeedAuth=\"False\"\n        fi\n    fi\n    # 1.3 Mantary Access Control\n    # 1.3.1 ensure the SELinux state is enforcing\n    if [[ -f /etc/selinux/config ]]; then\n        local num=$(sestatus|grep -c enforcing)\n        if [[ $num -gt 1 ]]; then\n            echo -e \"\\033[32m-[+] SELinux state is enforcing \\033[0m\"\n            selinuxStateIfEnforcing=\"True\"\n        else\n            echo -e \"\\033[31m-[-] SELinux state is not enforcing \\033[0m\"\n            selinuxStateIfEnforcing=\"False\"\n        fi\n    fi\n    # 1.3.2 ensure selinux policy is configured\n    if [[ -f /etc/selinux/config ]]; then\n        res=$(sestatus|grep targeted)\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m-[+] SELinux policy is configured \\033[0m\"\n            selinuxPolicyIfConfigured=\"True\"\n        else\n            echo -e \"\\033[31m-[-] SELinux policy is not configure to targeted \\033[0m\"\n            selinuxPolicyIfConfigured=\"False\"\n        fi\n    fi\n    boot_secure_info={\\\"grubcfgIfExist\\\":\\\"$grubcfgIfExist\\\",\\\"grubcfgPermission\\\":\\\"$grubcfgPermission\\\",\\\"grubcfgIfSetPasswd\\\":\\\"$grubcfgIfSetPasswd\\\",\\\"singleUserModeIfNeedAuth\\\":\\\"$singleUserModeIfNeedAuth\\\",\\\"selinuxStateIfEnforcing\\\":\\\"$selinuxStateIfEnforcing\\\",\\\"selinuxPolicyIfConfigured\\\":\\\"$selinuxPolicyIfConfigured\\\"}\n    #echo $boot_secure_info\n    init_check_res={\\\"tmp_partition_info\\\":$tmp_partition_info,\\\"boot_secure_info\\\":$boot_secure_info}\n}\nfunction service_check {\n    # 2. service configuration\n    echo [·] check service configuration\n    # 2.1 time sync\n    # 2.1.1 time sync service is installed\n    if $(rpm -q ntp 1>/dev/null||rpm -q chrony 1>/dev/null) ; then\n        if $(rpm -q ntp 1>/dev/null) ; then\n            if [[ -f /etc/ntp.conf ]]; then\n                local res=$(egrep \"^(server|pool)\" /etc/ntp.conf)\n                if [[ -n $res ]]; then\n                    echo -e \"\\033[32m-[+] remote ntp server is configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"True\"\n                else\n                    echo -e \"\\033[31m-[-] remote ntp server is not configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"False\"\n                fi\n            fi\n        fi\n        if $(rpm -q chrony 1>/dev/null); then\n            if [[ -f /etc/chrony.conf ]]; then\n                local res=$(egrep \"^(server|pool)\" /etc/chrony.conf)\n                if [[ -n $res ]]; then\n                    echo -e \"\\033[32m-[+] remote chrony server is configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"True\"\n                else\n                    echo -e \"\\033[31m-[-] remote chrony server is not configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"False\"\n                fi\n                \n            fi\n        fi\n    fi        \n    # 2.1.2 x-window\n    local res=$(rpm -qa xorg-x11*)\n    if [[ -z $res ]]; then\n        echo -e \"\\033[32m-[+] x11-windows is not installed \\033[0m\"\n        x11windowIfNotInstalled=\"True\"\n    else\n        echo -e \"\\033[31m-[-] x11-windows is installed \\033[0m\"\n        x11windowIfNotInstalled=\"False\"\n    fi\n    service_check_res={\\\"timeSyncServerIfConfigured\\\":\\\"$timeSyncServerIfConfigured\\\",\\\"x11windowIfNotInstalled\\\":\\\"$x11windowIfNotInstalled\\\"}\n}\nfunction network_check {\n    # 3. network configuration\n    echo [·] check network configuration\n    # 3.1 hosts file configuration\n    # 3.1.1 check /etc/hosts.deny file\n    if [[ -f /etc/hosts.deny ]]; then\n        hostsDenyFileIfExist=\"True\"\n        echo -e \"\\033[32m-[+] file /etc/hosts.deny exists \\033[0m\"\n        local res=$(stat /etc/hosts.deny |while read x;do if [[ $x =~ \"Uid\" ]] && [[ $x =~ \"(\" ]]; then echo $x;fi;done|cut -d\"(\" -f2,3,4)\n        hostsDenyFilePermission=$(echo $res|cut -d\"/\" -f1)\n        if [[ $(echo $res|cut -d\"/\" -f1) = \"0644\" ]];then\n            echo -e \"\\033[32m-[+] file /etc/hosts.deny permission is 0644 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file /etc/hosts.deny permission is not 0644 \\033[0m\"\n        fi\n\n        local res=$(egrep \"^[^#].+\" /etc/hosts.deny)\n        if [[ -n $res ]]; then\n            hostsDenyFileIfConfigured=\"True\"\n            echo -e \"\\033[32m-[+] file /etc/hosts.deny is configured \\033[0m\"\n        else\n            hostsDenyFileIfConfigured=\"False\"\n            echo -e \"\\033[31m-[-] file /etc/hosts.deny is not configured \\033[0m\"\n        fi\n    else\n        hostsDenyFileIfExist=\"False\"\n        echo -e \"\\033[31m-[-] file /etc/hosts.deny does not exists \\033[0m\"\n    fi\n    # 3.1.2 check /etc/hosts.allow file\n    if [[ -f /etc/hosts.allow ]]; then\n        hostsAllowFileIfExist=\"True\"\n        echo -e \"\\033[32m-[+] file /etc/hosts.allow exists \\033[0m\"\n        local res=`stat /etc/hosts.allow |while read x;do if [[ $x =~ \"Uid\" ]] && [[ $x =~ \"(\" ]]; then echo $x;fi;done|cut -d\"(\" -f2,3,4`\n        hostsAllowFilePermission=$(echo $res|cut -d\"/\" -f1)\n        if [[ $(echo $res|cut -d\"/\" -f1) = \"0644\" ]];then\n            echo -e \"\\033[32m-[+] file /etc/hosts.allow permission is 0644 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file /etc/hosts.allow permission is not 0644 \\033[0m\"\n        fi\n\n        local res=$(egrep \"^[^#].+\" /etc/hosts.deny)\n        if [[ -n $res ]]; then\n            hostsAllowFileIfConfigured=\"True\"\n            echo -e \"\\033[32m-[+] file /etc/hosts.allow is configured \\033[0m\"\n        else\n            hostsAllowFileIfConfigured=\"False\"\n            echo -e \"\\033[31m-[-] file /etc/hosts.allow is not configured \\033[0m\"\n        fi\n    else\n        hostsAllowFileIfExist=\"False\"\n        echo -e \"\\033[31m-[-] file /etc/hosts.allow does not exists \\033[0m\"\n    fi\n\n    # 3.2 firewall configuration\n    # 3.2.1 ensure iptables is installed\n    if $(rpm -q iptables 1>/dev/null); then\n        iptablesIfInstalled=\"True\"\n        echo -e \"\\033[32m-[+] iptables is installed \\033[0m\"\n        # 3.2.2 ensure INPUT OUTPUT chain policy is DROP\n        #iptables -L|grep policy|while read x;do\n        while read x;do\n            if [[ $x =~ \"INPUT\" ]] && [[ $x =~ \"DROP\" ]]; then\n                iptablesInputPolicyIfDrop=\"True\"\n                echo -e \"\\033[32m-[+] INPUT chain policy is DROP \\033[0m\"\n            elif [[ $x =~ \"INPUT\" ]] && [[ ! $x =~ \"DROP\" ]]; then\n                iptablesInputPolicyIfDrop=\"False\"\n                echo -e \"\\033[31m-[-] INPUT chain policy is not DROP \\033[0m\"\n            fi\n            if [[ $x =~ \"OUTPUT\" ]] && [[ $x =~ \"DROP\" ]]; then\n                iptablesOutputPolicyIfDrop=\"True\"\n                echo -e \"\\033[32m-[+] OUTPUT chain policy is DROP \\033[0m\"\n            elif [[ $x =~ \"OUTPUT\" ]] && [[ ! $x =~ \"DROP\" ]]; then\n                iptablesOutputPolicyIfDrop=\"False\"\n                echo -e \"\\033[31m-[-] OUTPUT chain policy is not DROP \\033[0m\"\n            fi\n        done < <(iptables -L|grep policy)\n    else\n        iptablesIfInstalled=\"False\"\n        echo -e \"\\033[31m-[-] iptables is not installed \\033[0m\"\n    fi\n    network_check_res={\\\"hostsAllowFileIfExist\\\":\\\"$hostsAllowFileIfExist\\\",\\\"hostsAllowFilePermission\\\":\\\"$hostsAllowFilePermission\\\",\\\"hostsAllowFileIfConfigured\\\":\\\"$hostsAllowFileIfConfigured\\\",\\\"hostsDenyFileIfExist\\\":\\\"$hostsDenyFileIfExist\\\",\\\"hostsDenyFilePermission\\\":\\\"$hostsDenyFilePermission\\\",\\\"hostsDenyFileIfConfigured\\\":\\\"$hostsDenyFileIfConfigured\\\",\\\"iptablesIfInstalled\\\":\\\"$iptablesIfInstalled\\\",\\\"iptablesInputPolicyIfDrop\\\":\\\"$iptablesInputPolicyIfDrop\\\",\\\"iptablesOutputPolicyIfDrop\\\":\\\"$iptablesOutputPolicyIfDrop\\\"}\n}\n\nfunction auditd_check {\n\t# 4. auditd configuration\n\techo [·] check auditd configuration\n\t# 4.1 ensure auditd is enabled\n    echo \"-[·] check auditd if is enabled\"\n\tif [[ $(systemctl is-enabled auditd) = \"enabled\" ]]; then\n\t\techo -e \"\\033[32m-[+] auditd is enabled \\033[0m\"\n        auditdIfEnabled=\"True\"\n\telse\n        auditdIfEnabled=\"False\"\n\t\techo -e \"\\033[31m-[-] auditd is not enabled \\033[0m\"\n\tfi\n\t# 4.2 some settings in /etc/audit/auditd.conf\n    echo \"-[·] settings in /etc/audit/auditd.conf\"\t\n    if [[ -f /etc/audit/auditd.conf ]]; then\n        auditdconfIfExist=\"True\"\n        maxLogFile=$(grep \"^max_log_file[[:blank:]]=\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        maxLogFileAction=$(grep \"^max_log_file_action\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        spaceLeftAction=$(grep \"^space_left_action\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        numLogs=$(grep \"^num_logs\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        if [[ -n $maxLogFile ]]; then\n            auditdIfSetMaxLogFile=$maxLogFile\n            echo -e \"\\033[32m-[+] max_log_file size is ${maxLogFile} M \\033[0m\"\n        else\n            auditdIfSetMaxLogFile=\"False\"\n            echo -e \"\\033[31m-[-] max_log_file size is not setted \\033[0m\"\n        fi\n        if [[ -n $maxLogFileAction ]]; then\n            auditdIfSetMaxLogFileAction=\"$maxLogFileAction\"\n            echo -e \"\\033[32m-[+] max_log_file_action is ${maxLogFileAction}\\033[0m\"\n        else\n            auditdIfSetMaxLogFileAction=\"False\"\n            echo -e \"\\033[31m-[-] max_log_file_action is not setted \\033[0m\"\n        fi\n        if [[ -n $spaceLeftAction ]]; then\n            auditdIfSetSpaceLeftAction=\"$spaceLeftAction\"\n            echo -e \"\\033[32m-[+] space_left_action is ${spaceLeftAction}\\033[0m\"\n        else\n            auditdIfSetSpaceLeftAction=\"False\"\n            echo -e \"\\033[31m-[-] space_left_action is not setted \\033[0m\"\n        fi\n        if [[ -n $numLogs ]]; then\n            auditdIfSetNumLogs=\"$numLogs\"\n            echo -e \"\\033[32m-[+] the num of logs is ${numLogs} \\033[0m\"\n        else\n            auditdIfSetNumLogs=\"False\"\n            echo -e \"\\033[31m-[-] num_logs is not setted \\033[0m\"\n        fi\n    else\n        auditdconfIfExist=\"False\"\n    fi\n    auditd_config_info={\\\"auditdIfEnabled\\\":\\\"$auditdIfEnabled\\\",\\\"auditdconfIfExist\\\":\\\"$auditdconfIfExist\\\",\\\"auditdIfSetMaxLogFile\\\":\\\"$auditdIfSetMaxLogFile\\\",\\\"auditdIfSetMaxLogFileAction\\\":\\\"$auditdIfSetMaxLogFileAction\\\",\\\"auditdIfSetSpaceLeftAction\\\":\\\"$auditdIfSetSpaceLeftAction\\\",\\\"auditdIfSetNumLogs\\\":\\\"$auditdIfSetNumLogs\\\"}\n    #echo $auditd_config_info\n    # 4.3 rules in /etc/audit/audit.rules\n    # arch 64\n    echo \"-[·] time-change\" \n    if [[ -f /etc/audit/audit.rules ]]; then\n        auditdRulesIfExist=\"True\"\n        echo -e \"\\033[32m-[+] /etc/audit/audit.rules is exist \\033[0m\"\n        if [[ ! -n $(grep time /etc/audit/audit.rules) ]]; then\n            auditdRulesIfNotNull=\"False\"\n            echo -e \"\\033[31m-[-] not set rule about audit the change of date and time \\033[0m\"\n        else\n            auditdRulesIfNotNull=\"True\"\n            # 4.3.1 time-change\n            local timeChangeList=$(egrep \"(stime|clock_settime|adjtimex|settimeofday|/etc/localtime)\" /etc/audit/audit.rules|wc -l)\n            if [[ ${timeChangeList} -gt 3 ]]; then\n                auditdIfCheckTimechange=\"True\"\n                echo -e \"\\033[32m-[+] audith the change of date and time \\033[0m\"\n            elif [[ ${timeChangeList} -gt 1 ]]; then\n                auditdIfCheckTimechange=\"False\"\n                echo -e \"\\033[31m-[-] not fully set rule about audit the change of date and time \\033[0m\"\n            else \n                auditdIfCheckTimechange=\"False\"\n                echo -e \"\\033[31m-[-] not set rule about audit the change of date and time \\033[0m\"\n            fi\n            # 4.3.2 user and group change\n            echo \"-[·] user and group change\"\n            local keyArray=(\"/etc/passwd\" \"/etc/group\" \"/etc/gshadow\" \"/etc/shadow\" \"/etc/security/opasswd\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    echo -e \"\\033[32m-[+] audit the change of $i \\033[0m\"\n                else\n                    tmpArray2+=($i\\;)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedUserandgroupfile=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedUserandgroupfile=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.3 system's network environment change\n            echo \"-[·] system's network environment change\"\n            local keyArray=(\"/etc/issue\" \"/etc/issue.net\" \"/etc/hosts\" \"/etc/sysconfig/network\" \"/etc/sysconfig/network-scripts/\" )\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                    if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    echo -e \"\\033[32m-[+] audit the change of $i \\033[0m\"\n                else\n                    tmpArray2+=($i\\;)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            local keyArray=(\"sethostname\" \"setdomainname\")\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    echo -e \"\\033[32m-[+] audit the use of syscall  $i \\033[0m\"\n                else\n                    echo -e \"\\033[31m-[-] not audit the use of syscall $i \\033[0m\"\n                    tmpArray2+=($i\\;)\n                fi\n            done\n            auditdRulesCheckedNetworkenv=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedNetworkenv=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.4 system's Mandatory Access Controls change\n            echo \"-[·] system's Mandatory Access Controls change\"\n            local keyArray=(\"/etc/selinux\" \"/usr/share/selinux\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    echo -e \"\\033[32m-[+] audit the change of   $i \\033[0m\"\n                else\n                    tmpArray2+=($i\\;)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedMACchange=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedMACchange=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.5 audit events of login and logout\n            echo \"-[·] audit events of login and logout\"\n            local keyArray=(\"/var/log/lastlog\" \"/var/run/faillock/\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    echo -e \"\\033[32m-[+] audit the change of   $i \\033[0m\"\n                else\n                    tmpArray2+=($i\\;)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedLoginoutEvents=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedLoginoutEvents=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.6 audit the change of discretionary access control\n            echo \"-[·] audit the change of discretionary access control\"\n            local keyArray=(\"(chmod|fchmod|fchmodat)\" \"(chown|fchown|fchownat)\" \"(setxattr|lsetxattr|removexattr)\" \"(lock|time)\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')\n                    echo -e \"\\033[32m-[+] audit the use of systemcall  $i \\033[0m\"\n                    tmpArray1+=($i\\;)\n                else\n                    tmpArray2+=($i\\;)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')\n                    echo -e \"\\033[31m-[-] not audit the use of systemcall $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedDACChangeSyscall=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedDACChangeSyscall=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.7 audit the events of unsuccessful unauthorized file access attempts\n            echo \"-[·] audit the events of unsuccessful unauthorized file access attempts\"\n            local keyArray=(\"(create|open|openat|truncate|ftruncate).*?exit=-EACCESS\" \"(create|open|openat|truncate|ftruncate).*?exit=-EPERM\" )\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[32m-[+] audit the use of systemcall  $i \\033[0m\"\n                else\n                    tmpArray2+=($i\\;)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[31m-[-] not audit the use of systemcall $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedFileAccessAttemptSyscall=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedFileAccessAttemptSyscall=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.8 audit the use of privileged commands\n            echo \"-[·] audit the use of privileged commands\"\n            #find / -name \"passwd\"\n            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\"}'\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${res[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[32m-[+] audit the use of command  $i \\033[0m\"\n                else\n                    tmpArray2+=($i\\;)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[31m-[-] not audit the use of command $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedPrivilegedCommand=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedPrivilegedCommand=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.9 audit the change of file sudoer\n            echo \"-[·] audit the change of file sudoer\"\n            local keyArray=(\"/etc/sudoers\" \"/etc/sudoers.d/\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[32m-[+] audit the change of file  $i \\033[0m\"\n                else\n                    tmpArray2+=($i\\;)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[31m-[-] not audit the change of file $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedSudoerFile=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedSudoerFile=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.10 check the audit configuration is setted to immutable unless reboot the server\n            echo \"-[·] check the audit configuration is setted to immutable unless reboot the server\"\n            local res=$(grep \"^\\s*[^#]\" /etc/audit/audit.rules|tail -1|egrep \"-e.*?2\")\n            if [[ -n $res ]]; then\n                auditdRulesIfImmutable=\"True\"\n                echo -e \"\\033[32m-[+] auditd setted -e 2 \\033[0m\"\n            else\n                auditdRulesIfImmutable=\"False\"\n                echo -e \"\\033[31m-[-] auditd not setted -e 2 \\033[0m\"\n            fi\n        fi\n    else\n        auditdRulesIfExist=\"False\"\n        echo -e \"\\033[32m-[+] /etc/audit/audit.rules is not exist \\033[0m\"\n    fi\n    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\\\"}\n    auditd_check_res={\\\"auditd_config_info\\\":$auditd_config_info,\\\"auditd_rules_info\\\":$auditd_rules_info}\n}\n\nfunction log_check {\n    echo \"[·] check log configuration\"\n\t# 5.1 ensure auditd is enabled\n    echo \"-[·] check rsyslog if is enabled\"\n\tif [[ $(systemctl is-enabled rsyslog) = \"enabled\" ]]; then\n        rsyslogIfEnabled=\"True\"\n\t\techo -e \"\\033[32m-[+] rsyslog is enabled \\033[0m\"\n\telse\n        rsyslogIfEnabled=\"False\"\n\t\techo -e \"\\033[31m-[-] rsyslog is not enabled \\033[0m\"\n\tfi\n    \n    log_check_res={\\\"rsyslogIfEnabled\\\":\\\"$rsyslogIfEnabled\\\"}\n\n}\n\nfunction authentication_check {\n    echo \"[·] check cron ssh pam and env configuration\"\n    # 6.1 cron configuration\n    echo \"-[·] check cron configuration\"\n    # 6.1.1 check cron service is enabled\n    echo \"-[·] check crond if is enabled\"\n\tif [[ $(systemctl is-enabled crond) = \"enabled\" ]]; then\n\t\techo -e \"\\033[32m-[+] crond is enabled \\033[0m\"\n        crondIfEnabled=\"True\"\n\telse\n        crondIfEnabled=\"False\"\n\t\techo -e \"\\033[31m-[-] crond is not enabled \\033[0m\"\n\tfi\n    # 6.1.2 check cron's configuration file permission\n    echo \"-[·] check cron's configuration file permission\"\n    local keyArray=(\"/etc/crontab\" \"/etc/cron.hourly\" \"/etc/cron.daily\" \"/etc/cron.weekly\" \"/etc/cron.monthly\" \"/etc/cron.d\")\n    crondConfigFilenameArray=$(echo ${keyArray[@]}|sed 's/ /;/g')\n    tmpArray=()\n    for i in ${keyArray[@]} ; do\n        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)\n        tmpArray+=($res\\;)\n        if [[ $res = \"0600\" ]] || [[ $res = \"0700\" ]]; then\n            echo -e \"\\033[32m-[+] file $i's permission is $res \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \\033[0m\"\n        fi\n    done\n    crondConfigFilePermissionArray=$(echo ${tmpArray[@]}|sed 's/ //g')\n    # 6.1.3 check cron.allow cron.deny permission and owner\n    echo \"-[·] check cron.allow cron.deny configuration file permission\"\n    local keyArray=(\"/etc/cron.allow\" \"/etc/cron.deny\")\n    crondallowdenyFilenameArray=$(echo ${keyArray[@]}|sed 's/ /;/g')\n    tmpArray1=()\n    tmpArray2=()\n    tmpArray3=()\n    for i in ${keyArray[@]} ; do\n        if [[ ! -f $i ]]; then\n            tmpArray1+=(\"False;\")\n            tmpArray2+=(\"False;\")\n            tmpArray3+=(\"False;\")\n            echo -e \"\\033[31m-[-] file $i not exist \\033[0m\"\n            continue\n        else\n            tmpArray1+=(\"True;\")\n        fi\n        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)\n        tmpArray2+=($res1\\;)\n        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)\n        tmpArray3+=($res2\\;)\n        if [[ $res1 = \"0600\" ]] || [[ $res1 = \"0700\" ]]; then\n            echo -e \"\\033[32m-[+] file $i's permission is $res \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \\033[0m\"\n        fi\n        if [[ $res2 = \"root root\" ]]; then\n            echo -e \"\\033[32m-[+] file $i's owner is $res2 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $i's owner is not root \\033[0m\"\n        fi\n    done\n    crondallowdenyFileIfExistArray=$(echo ${tmpArray1[@]}|sed 's/ //g')\n    crondallowdenyFilePermissionArray=$(echo ${tmpArray2[@]}|sed 's/ //g')\n    crondallowdenyFileOwnerArray=$(echo ${tmpArray3[@]}|sed 's/; /;/g')\n    crond_config_info={\\\"crondIfEnabled\\\":\\\"$crondIfEnabled\\\",\\\"crondConfigFilenameArray\\\":\\\"$crondConfigFilenameArray\\\",\\\"crondConfigFilePermissionArray\\\":\\\"$crondConfigFilePermissionArray\\\",\\\"crondallowdenyFilenameArray\\\":\\\"$crondallowdenyFilenameArray\\\",\\\"crondallowdenyFileIfExistArray\\\":\\\"$crondallowdenyFileIfExistArray\\\",\\\"crondallowdenyFilePermissionArray\\\":\\\"$crondallowdenyFilePermissionArray\\\",\\\"crondallowdenyFileOwnerArray\\\":\\\"$crondallowdenyFileOwnerArray\\\"}\n    # 6.2 SSH configuration\n    echo \"-[·] check ssh configuration\"\n\tif [[ $(systemctl is-enabled sshd) = \"enabled\" ]]; then\n        sshdIfEnabled=\"True\"\n        # 6.2.1 /etc/ssh/sshd_config permission 0600\n        local file=\"/etc/ssh/sshd_config\"\n        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)\n        if [[ $res = \"0600\" ]]; then\n            sshdConfigFilePermission=$res\n            echo -e \"\\033[32m-[+] file $file's access permission is $res \\033[0m\"\n        else\n            sshdConfigFilePermission=\"False\"\n            echo -e \"\\033[3-m-[-] file $file's access permission is $res \\033[0m\"\n        fi\n        # 6.2.2 check ssh x11 forwarding if is disabled\n        local res=$(grep \"^X11Forwaring\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisableX11forwarding=\"True\"\n            echo -e \"\\033[32m-[+] X11Forwarding no \\033[0m\"\n        else\n            sshdIfDisableX11forwarding=\"False\"\n            echo -e \"\\033[31m-[-] not set X11Forwarding no \\033[0m\"\n        fi\n        # 6.2.3 check ssh MaxAUTHTries if is 4\n        local res=$(grep \"^MaxAuthTries\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSetMaxAuthTries=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\\2/')\n            echo -e \"\\033[32m-[+] $res \\033[0m\"\n        else\n            sshdIfSetMaxAuthTries=\"False\"\n            echo -e \"\\033[31m-[-] not set MaxAuthTries \\033[0m\"\n        fi\n        # 6.2.4 check ssh IgnoreRhosts if is enabled\n        local res=$(grep \"^IgnoreRhosts\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep yes) ]]; then\n            sshdIfEnableIgnoreRhosts=\"True\"\n            echo -e \"\\033[32m-[+] IgnoreRhosts yes \\033[0m\"\n        else\n            sshdIfEnableIgnoreRhosts=\"False\"\n            echo -e \"\\033[31m-[-] not set IgnoreRhosts no\\033[0m\"\n        fi\n        # 6.2.5 check ssh HostbasedAuthentication if is disabled\n        local res=$(grep \"^HostbasedAuthentication\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisableHostbasedAuthentication=\"True\"\n            echo -e \"\\033[32m-[+] HostbasedAuthentication no \\033[0m\"\n        else\n            sshdIfDisableHostbasedAuthentication=\"False\"\n            echo -e \"\\033[31m-[-] not set HostbasedAuthentication no\\033[0m\"\n        fi\n        # 6.2.6 check ssh root login if is diabled\n        local res=$(grep \"^PermitRootLogin\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisablePermitRootLogin=\"True\"\n            echo -e \"\\033[32m-[+] PermitRootLogin no \\033[0m\"\n        else\n            sshdIfDisablePermitRootLogin=\"False\"\n            echo -e \"\\033[31m-[-] not set PermitRootLogin no\\033[0m\"\n        fi\n        # 6.2.7 check ssh PermitEmptyPasswords if is diabled\n        local res=$(grep \"^PermitEmptyPasswords\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisablePermitEmptyPasswords=\"True\"\n            echo -e \"\\033[32m-[+] PermitEmptyPasswords no \\033[0m\"\n        else\n            sshdIfDisablePermitEmptyPasswords=\"False\"\n            echo -e \"\\033[31m-[-] not set PermitEmptyPasswords no\\033[0m\"\n        fi\n        # 6.2.8 check ssh PermitUserEnvironment if is diabled\n        local res=$(grep \"^PermitUserEnvironment\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisablePermitUserEnvironment=\"True\"\n            echo -e \"\\033[32m-[+] PermitUserEnvironment no \\033[0m\"\n        else\n            sshdIfDisablePermitUserEnvironment=\"False\"\n            echo -e \"\\033[31m-[-] not set PermitUserEnvironment no\\033[0m\"\n        fi\n        # 6.2.9 check if set specific MAC algorithms\n        local res=$(grep \"^MACs\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSpecificMACs=\"True\"\n            echo -e \"\\033[32m-[+] will use specific MAC algorithms $res \\033[0m\"\n        else\n            sshdIfSpecificMACs=\"False\"\n            echo -e \"\\033[31m-[-] not set specific MAC algorithms\\033[0m\"\n        fi\n        # 6.2.10 check SSH idle Timeout Interval if is configured\n        local res=$(grep \"^ClientAliveInterval\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSetClientAliveInterval=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\\2/')\n            echo -e \"\\033[32m-[+] $res \\033[0m\"\n        else\n            sshdIfSetClientAliveInterval=\"False\"\n            echo -e \"\\033[31m-[-] not set ClientAliveInterval \\033[0m\"\n        fi\n        # 6.2.11 check SSH LoginGrace Time\n        local res=$(grep \"^LoginGraceTime\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSetLoginGraceTime=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\\2/')\n            echo -e \"\\033[32m-[+] $res \\033[0m\"\n        else\n            sshdIfSetLoginGraceTime=\"False\"\n            echo -e \"\\033[31m-[-] not set LoginGraceTime \\033[0m\"\n        fi\n\telse\n        sshdIfEnabled=\"False\"\n\t\techo -e \"\\033[32m-[+] sshd is not enabled \\033[0m\"\n\tfi\n    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\\\"}\n\n    # 6.3 PAM configuration\n    echo \"-[·] check pam configuration\"\n    # 6.3.1 password creation policy\n    if [[ -f /etc/security/pwquality.conf ]]; then\n        pamPwqualityconfIfExist=\"True\"\n        local minlen=$(grep ^minlen /etc/security/pwquality.conf | sed 's/ //g')\n        local minclass=$(grep ^minclass /etc/security/pwquality.conf |sed 's/ //g')\n        if [[ -n $minlen ]]; then\n            pamIfSetMinlen=$(echo $minlen|cut -d= -f2)\n            echo -e \"\\033[32m-[+] minimime length of password is $(echo $minlen|cut -d= -f2) \\033[0m\"\n        else\n            pamIfSetMinlen=\"False\"\n            echo -e \"\\033[31m-[-] not set minlen \\033[0m\"\n        fi\n        if [[ -n $minclass ]]; then\n            pamIfSetMinclass=$(echo $minclass|cut -d= -f2)\n            echo -e \"\\033[32m-[+] minclass of password is $(echo $minclass|cut -d= -f2) \\033[0m\"\n        else\n            local keyArray=(\"^dcredit\" \"^lcredit\" \"^ocredit\" \"^ucredit\")\n            local tmpCount=0\n            for i in ${keyArray[@]}; do\n                if [[ -n  $(grep $i /etc/security/pwquality.conf) ]]; then\n                    tmpCount=$(expr 1 + $tmpCount)\n                fi\n            done\n            if [[ $tmpCount = 0 ]]; then\n                pamIfSetMinclass=\"False\"\n            else\n                pamIfSetMinclass=$tmpCount\n            fi\n            if [[ tmpCount -ge 2 ]]; then\n                echo -e \"\\033[32m-[+] minclass of passwd is $tmpCount \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] not set minclass \\033[0m\"\n            fi\n        fi\n    else\n        pamPwqualityconfIfExist=\"False\"\n    fi\n    # 6.3.2 lock account and unlock time\n    local files=(\"/etc/pam.d/password-auth\" \"/etc/pam.d/system-auth\")\n    local keyArray=(\"pam_faillock\\.so.*?unlock_time\")\n    tmpArray1=()\n    tmpArray2=()\n    for i in ${files[@]}; do\n        for k in ${keyArray[@]}; do\n            if [[ -n $(egrep $k $i ) ]]; then\n                echo -e \"\\033[32m-[+] set lock and unlock_time in $i \\033[0m\"\n                tmpArray1+=($i\\;)\n            else\n                tmpArray2+=($i\\;)\n                echo -e \"\\033[31m-[-] not set lock and unlock_time in $i \\033[0m\"\n            fi\n        done\n    done\n    sshdSetedLockAndUnlockTimeFiles=$(echo ${tmpArray1[@]}|sed 's/; /;/g')\n    sshdNotSetedLockAndUnlockTimeFiles=$(echo ${tmpArray2[@]}|sed 's/; /;/g')\n    # 6.3.3 check password reuse if is limited\n    sshdPamdFileArray=$(echo ${files[@]}|sed 's/ /;/g')\n    tmpArray=()\n    for i in ${files[@]}; do\n        local res=$(egrep '^password\\s+sufficient\\s+pam_unix.so' $i)\n        if [[ -n $res ]] && [[ $res =~ \"remember=\" ]]; then\n            local tmp=$(echo $res|sed 's/.*\\(remember=[[:digit:]]\\).*/\\1/g'|sed 's/ //g'|cut -d= -f2)\n            tmpArray+=($tmp\\;)\n            echo -e \"\\033[32m-[+] password reuse limit is $tmp in $i \\033[0m\"\n        else\n            tmpArray+=(\"False;\")\n            echo -e \"\\033[31m-[-] passowrd reuse limit not set in $i \\033[0m\"\n        fi\n    done\n    sshdPamdFileReuseLimitArray=$(echo ${tmpArray[@]}|sed 's/; /;/g')\n    # 6.3.4 check the algorithm of store password if is sha512\n    tmpArray=()\n    for i in ${files[@]}; do\n        local res=$(egrep '^password\\s+sufficient\\s+pam_unix.so' $i)\n        if [[ -n $res ]] && [[ $res =~ \"sha512\" ]]; then\n            tmpArray+=(\"True;\")\n            echo -e \"\\033[32m-[+] password storage algorithm is set to sha512 in $i \\033[0m\"\n        else\n            tmpArray+=(\"False;\")\n            echo -e \"\\033[31m-[-] password storage algorithm is not specific to sha512 in $i \\033[0m\"\n        fi\n    done\n    sshdPamdFileIfSetSha512Array=$(echo ${tmpArray[@]}|sed 's/; /;/g')\n    pam_config_info={\\\"pamPwqualityconfIfExist\\\":\\\"$pamPwqualityconfIfExist\\\",\\\"pamIfSetMinlen\\\":\\\"$pamIfSetMinlen\\\",\\\"pamIfSetMinclass\\\":\\\"$pamIfSetMinclass\\\",\\\"sshdSetedLockAndUnlockTimeFiles\\\":\\\"$sshdSetedLockAndUnlockTimeFiles\\\",\\\"sshdNotSetedLockAndUnlockTimeFiles\\\":\\\"$sshdNotSetedLockAndUnlockTimeFiles\\\",\\\"sshdPamdFileArray\\\":\\\"$sshdPamdFileArray\\\",\\\"sshdPamdFileReuseLimitArray\\\":\\\"$sshdPamdFileReuseLimitArray\\\",\\\"sshdPamdFileIfSetSha512Array\\\":\\\"$sshdPamdFileIfSetSha512Array\\\"}\n    # 6.4 user accounts and environment\n    echo \"-[·] check user accounts and environment\"\n    if [[ -f /etc/login.defs ]]; then\n        accountLogindefsIfExist=\"True\"\n        # 6.4.1 basic settings\n        local file='/etc/login.defs'\n        passMaxDays=$(grep ^PASS_MAX_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\\1/g')\n        passMinDays=$(grep ^PASS_MIN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\\1/g')\n        passWarnAge=$(grep ^PASS_WARN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\\1/g')\n        inactive=$(useradd -D|grep INACTIVE|sed 's/ //g'|cut -d= -f2)\n        accountPassMaxDays=$passMaxDays\n        accountPassMinDays=$passMinDays\n        accountPassWarnDays=$passWarnAge\n        accountPassAutolockInactiveDays=$inactive\n        if [[ $passMaxDays -le 90 ]]; then\n            echo -e \"\\033[32m-[+] the maximume days of password have to change is $passMaxDays \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the maximume days of password have to change is $passMaxDays ,should less than 90 day\\033[0m\"\n        fi\n        if [[ $passMinDays -ge 7 ]]; then\n            echo -e \"\\033[32m-[+] the minimume days of password have to change is $passMinDays \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the minimume days of password have to change is $passMinDays ,should great than 7 day\\033[0m\"\n        fi\n        if [[ $passWarnAge -ge 7 ]]; then\n            echo -e \"\\033[32m-[+] the minimume days of warn password need to change is $passWarnAge \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the minimume days of warn password need to change is $passWarnAge ,should greate than 7 day\\033[0m\"\n        fi\n        if [[ $inactive != -1 ]]; then\n            echo -e \"\\033[32m-[+] auto lock account when the  $inactive day haven't login \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] haven't set day of auto lock accounts \\033[0m\"\n        fi\n        # 6.4.2 check system's account if is unlogin\n        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}')\n        tmpArray=()\n        if [[ -z $res ]]; then\n            tmpArray+=(\"False;\")\n            echo -e \"\\033[32m-[+] system account can't login \\033[0m\"\n        else\n            tmpArray+=($(echo $res|sed 's/\\n/ /g'))\n            echo -e \"\\033[31m-[-]  ($(echo $res|sed 's/\\n/ /g'))user's shell need set to /sbin/nologin \\033[0m\"\n        fi\n        accountShouldUnloginAray=$(echo ${tmpArray[@]}|sed 's/ /;/g')\n        # 6.4.3 check default group for the root account if is GID 0\n        local res=$(grep \"^root:\" /etc/passwd|cut -d: -f4)\n        accountGIDOfRoot=$res\n        if [[ $res = 0 ]]; then\n            echo -e \"\\033[32m-[+] default group for the root account is GID 0 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-]] default group for the root account is is GID $res,not GID 0 \\033[0m\"\n        fi\n        # 6.4.4 check default user shell timeout if is 900 seconds or less\n        local files=(\"/etc/bashrc\" \"/etc/profile\")\n        tmpArray1=()\n        tmpArray2=()\n        for file in ${files[@]}; do\n            if [[ ! -f $file ]]; then\n                continue\n            else\n                tmpArray1+=($file\\;)\n            fi\n            local res=$(grep \"^TMOUT\" $file|sed 's/ //g'|cut -d= -f2)\n            if [[ -z $res ]]; then\n                tmpArray2+=(\"False;\")\n                echo -e \"\\033[31m-[-] not set TMOUT in file $file \\033[0m\"\n                continue\n            fi\n            tmpArray2+=($res\\;)\n            if [[ $res -le 900 ]]; then\n                echo -e \"\\033[32m-[+] when idle time great than $res seconds will close connection \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] when idle time great than $res seconds will close connection,the time should less than 900 seconds \\033[0m\"\n            fi\n        done\n        accountProfileFileArray=$(echo ${tmpArray1[@]}|sed 's/; /;/g')\n        accountProfileTMOUTArray=$(echo ${tmpArray2[@]}|sed 's/; /;/g')\n        # 6.4.5 check access to su command if is restricted\n        local res=$(grep pam_wheel.so /etc/pam.d/su)\n#        accountIfSetUsersCanAccessSuCommand=\n        if [[ -n $res ]]; then\n            local res=$(grep wheel /etc/group|cut -d: -f4)\n            if [[ -n $res ]]; then\n                accountIfSetUsersCanAccessSuCommand=$(echo $res|sed 's/\\n/;/g')\n                echo -e \"\\033[32m-[+] access to su command is specific to $(echo $res|sed 's/\\n/;/g') \\033[0m\"\n            else\n                accountIfSetUsersCanAccessSuCommand=\"False\"\n                echo -e \"\\033[31m-[-] access to su command is not restricted \\033[0m\"\n            fi\n        else\n            accountIfSetUsersCanAccessSuCommand=\"False\"\n            echo -e \"\\033[31m-[-] access to su command is not restricted \\033[0m\"\n        fi\n    else\n        accountLogindefsIfExist=\"False\"\n        echo -e \"\\033[31m-[-] file /etc/login.defs is not exist \\033[0m\"\n    fi\n    account_config_info={\\\"accountPassMaxDays\\\":\\\"$accountPassMaxDays\\\",\\\"accountPassMinDays\\\":\\\"$accountPassMinDays\\\",\\\"accountPassWarnDays\\\":\\\"$accountPassWarnDays\\\",\\\"accountPassAutolockInactiveDays\\\":\\\"$accountPassAutolockInactiveDays\\\",\\\"accountShouldUnloginArray\\\":\\\"$accountShouldUnloginArray\\\",\\\"accountGIDOfRoot\\\":\\\"$accountGIDOfRoot\\\",\\\"accountProfileFileArray\\\":\\\"$accountProfileFileArray\\\",\\\"accountProfileTMOUTArray\\\":\\\"$accountProfileTMOUTArray\\\",\\\"accountIfSetUsersCanAccessSuCommand\\\":\\\"$accountIfSetUsersCanAccessSuCommand\\\"}\n    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}\n}\n\nfunction system_check {\n    echo \"[·] check permission of important file and configuration of user and group\"\n    # 7.1 check permission of important file and uid gid\n    echo \"-[·] check permission of important file\"\n    local files=(\"/etc/passwd\" \"/etc/shadow\" \"/etc/group\" \"/etc/gshadow\" \"/etc/passwd-\" \"/etc/shadow-\" \"/etc/group-\" \"/etc/gshadow-\")\n    importantFilenameArray=$(echo ${files[@]}|sed 's/ /;/g')\n    tmpArray1=()\n    tmpArray2=()\n    for file in ${files[@]}; do\n        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)\n        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)\n        tmpArray1+=($perm\\;)\n        tmpArray2+=($uidGid\\;)\n        if [[ $file =~ \"shadow\" ]]; then\n            if [[ $perm = \"0000\" ]]; then\n                echo -e \"\\033[32m-[+] file $file's permission is $perm \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] file $file's permission is $perm,should set to 0000 \\033[0m\"\n            fi\n        else\n            if [[ $perm = \"0644\" ]]; then\n                echo -e \"\\033[32m-[+] file $file's permission is $perm \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] file $file's permission is $perm,should set to 0644 \\033[0m\"\n\n            fi\n        fi\n        if [[ $uidGid = \"0 0\" ]]; then\n            echo -e \"\\033[32m-[+] file $file's uid gid is $uidGid \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $file's uid gid is $uidGid,should set to 0 0 \\033[0m\"\n        fi\n    done\n    importantFilePermissionArray=$(echo ${tmpArray1[@]}|sed 's/; /;/g')\n    importantFileUidgidArray=$(echo ${tmpArray2[@]}|sed 's/; /;/g')\n    file_permission_info={\\\"importantFilenameArray\\\":\\\"$importantFilenameArray\\\",\\\"importantFilePermissionArray\\\":\\\"$importantFilePermissionArray\\\",\\\"importantFileUidgidArray\\\":\\\"$importantFileUidgidArray\\\"}\n    # 7.2 check configuration of user and group\n    echo \"-[·] check configuration of user and group\"\n    # 7.2.1 check if user's password is empty\n    users=$(cat /etc/shadow |awk -F: '($2==\"!!\"){print $1}'|while read x;do \n        res=$(grep ${x} /etc/passwd|cut -d: -f7); if [[ $res != \"/sbin/nologin\" ]] && [[ $res != \"/sbin/shutdon\" ]] && [[ $res != \"/sbin/halt\" ]]; then \n            echo $x\n            #echo -e \"\\033[31m-[-] $x should have a passwd,not empty \\033[0m\"; \n            fi;\n        done)\n    if [[ -z $users ]]; then\n        userIfSetPasswdOrArray=\"True\"\n        echo -e \"\\033[32m-[+] all user account have set password \\033[0m\"\n    else\n        userIfSetPasswdOrArray=$(echo $users|sed 's/ /;/g')\n        echo -e \"\\033[31m-[-] user:$(echo $users|sed 's/\\n/ /g') should set a password ,rather than empty \\033[0m\"\n    fi\n    # 7.2.2 check if root is the only UID 0 account\n    local users=$(cat /etc/passwd|awk -F: '($3==0){print $1}')\n    if [[ $users = 'root' ]]; then\n        uid0OnlyRootOrArray=\"True\"\n        echo -e \"\\033[32m-[+] root is the only account that uid is 0 \\033[0m\"\n    else\n        uid0OnlyRootOrArray=$(echo $users|sed 's/root //g'|sed 's/ /;/g')\n        echo -e \"\\033[31m-[-] $(echo $users|sed 's/root //g'|sed 's/\\n/ /g') uid should not be 0 \\033[0m\"\n    fi\n    # 7.2.3 check root PATH integrith\n    if [ \"$(echo $PATH|grep ::)\" != \"\" ]; then\n        echo -e \"\\033[31m-[-] Empty Directory in PATH (::) \\033[0m\"\n    fi\n    if [ \"$(echo $PATH|grep :$)\" != \"\" ]; then\n        echo -e \"\\033[31m-[-] Trailing : in PATH \\033[0m\"\n    fi\n    path=$( echo $PATH|sed -e 's/::/:/' -e 's/:$//' -e 's/:/ /g')\n    tmpArray1=()\n    tmpArray2=()\n    tmpArray3=()\n    tmpArray4=()\n    tmpArray5=()\n    set -- $path\n    while [[ $1 != \"\" ]]; do\n        if [[ $1 = \".\" ]]; then\n            echo -e \"\\033[31m-[-] PATH contains . \\033[0m\"\n            tmpArray1+=(\".\")\n            shift\n            continue\n        fi\n        if [[ -d $1 ]]; then\n            local dirperm=$(ls -ldH $1|cut -d\" \" -f1)\n            if [[ $(echo $dirperm|cut -c6) != \"-\" ]]; then\n                tmpArray2+=($1\\;)\n                echo -e \"\\033[31m-[-] Group Write permission should not set on directory $1 \\033[0m\"\n            fi\n            if [[ $(echo $dirperm|cut -c9) != \"-\" ]]; then\n                tmpArray3+=($1\\;)\n                echo -e \"\\033[31m-[-] Other Write permission should not set on directory $1 \\033[0m\"\n            fi\n            local dirown=$(ls -ldH $1|awk '{print $3}')\n            if [[ $dirown != \"root\" ]]; then\n                tmpArray4+=($1\\;)\n                echo -e \"\\033[31m-[-] dir $1's owner is $dirown,should be root \\033[0m\"\n            fi\n        else\n            tmpArray5+=($1\\;)\n            echo -e \"\\033[31m-[-] $1 is not a directory or not exist \\033[0m\"\n        fi\n        shift\n    done\n    if [[ ${#tmpArray1[@]} = 0 ]]; then\n        pathDirIfNotHasDot=\"True\"\n    else\n        pathDirIfNotHasDot=\"False\"\n    fi\n    pathDirPermissionHasGWArray=$(echo ${tmpArray2[@]}|sed 's/; /;/g')\n    pathDirPermissionHasOWArray=$(echo ${tmpArray3[@]}|sed 's/; /;/g')\n    pathDirOwnerIsNotRootArray=$(echo ${tmpArray4[@]}|sed 's/; /;/g')\n    pathDirDoesNotExistOrNotDirArray=$(echo ${tmpArray5[@]}|sed 's/; /;/g')\n    # 7.2.4 check if is all users' home directories exist\n    #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\n    tmpArray1=()\n    tmpArray2=()\n    tmpArray3=()\n    tmpArray4=()\n    tmpArray5=()\n    tmpArray6=()\n    while read user dir; do\n        tmpArray1+=($dir\\;)\n        if [[ ! -d $dir ]]; then\n            tmpArray2+=(\"False;\")\n            tmpArray3+=(\"False;\")\n            echo -e \"\\033[31m-[-] the home directory ($dir) of user $user does not exist \\033[0m\"\n\n        else\n            tmpArray2+=(\"True;\")\n            # 7.2.5 check if users' home directories permissions are 750 or more restrictive\n            local dirperm=$(ls -ld $dir|cut -d\" \" -f1)\n            tmpArray3+=($dirperm\\;)\n            if [[ $(echo $dirperm |cut -c6) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Group Write permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            if [[ $(echo $dirperm |cut -c8) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Read permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            if [[ $(echo $dirperm |cut -c9) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Write permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            if [[ $(echo $dirperm |cut -c10) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Execute permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            # 7.2.6 check if is users own their home directory\n            local owner=$(stat -L -c \"%U\" $dir)\n            if [[ $owner != $user ]]; then\n                tmpArray4+=(\"False;\")\n                echo -e \"\\033[31m-[-]The home directory ($dir) of user $user is owned by $owner \\033[0m\"\n            else\n                tmpArray4+=(\"True;\")\n            fi\n            # 7.2.7 check users' dot files are not group or world  writable\n            local tmpc=0\n            for file in $dir/.[A-Za-z0-9]*; do\n                if [[ ! -h $file ]] && [[ -f $file ]]; then\n                    local fileperm=$(ls -ld $file|cut -d\" \" -f1)\n                    if [[ $(echo $fileperm|cut -c6) != \"-\" ]]; then\n                        tmpc=$(expr $tmpc + 1)\n                        echo -e \"\\033[31m-[-] Group Write permission set on file $file \\033[0m\"\n                    fi\n                    if [[ $(echo $fileperm|cut -c9) != \"-\" ]]; then\n                        tmpc=$(expr $tmpc + 1)\n                        echo -e \"\\033[31m-[-] Other Write permission set on file $file \\033[0m\"\n                    fi\n                fi\n            done\n            if [[ $tmpc = 0 ]]; then\n                tmpArray5+=(\"True;\")\n            else\n                tmpArray5+=(\"False;\")\n            fi\n            # 7.2.8 check if no usrs have .netrc .rhosts .forward file\n            tmpc=0\n            if [[ ! -h $dir/.netrc ]] && [[ -f $dir/.netrc ]]; then\n                tmpc=$(expr $tmpc + 1)\n                echo -e \"\\033[31m-[-] .netrc file $dir/.netrc exists \\033[0m\"\n            fi\n            if [[ ! -h $dir/.rhosts ]] && [[ -f $dir/.rhosts ]]; then\n                tmpc=$(expr $tmpc + 1)\n                echo -e \"\\033[31m-[-] .rhosts file $dir/.rhosts exists \\033[0m\"\n            fi\n            if [[ ! -h $dir/.forward ]] && [[ -f $dir/.forward ]]; then\n                tmpc=$(expr $tmpc + 1)\n                echo -e \"\\033[31m-[-] .forward file $dir/.forward exists \\033[0m\"\n            fi\n            if [[ $tmpc = 0 ]]; then\n                tmpArray6+=(\"True;\")\n            else\n                tmpArray6+=(\"False;\")\n            fi\n        fi\n    done < <(cat /etc/passwd|egrep -v '^(root|halt|sync|shutdown)'|awk -F: '($7 != \"/sbin/nologin\" && $7 != \"/bin/false\"){print $1 \" \" $6}')\n    userArray=$(echo ${tmpArray1[@]}|sed 's/; /;/g')\n    userHomeDirIfExistArray=$(echo ${tmpArray2[@]}|sed 's/; /;/g')\n    userHomeDirPermissionArray=$(echo ${tmpArray3[@]}|sed 's/; /;/g')\n    userIfOwnTheirHomeDirArray=$(echo ${tmpArray4[@]}|sed 's/; /;/g')\n    userHomeDirIfHasGWorOWDotFileArray=$(echo ${tmpArray5[@]}|sed 's/; /;/g')\n    userHomeDirIfHasOtherFileArray=$(echo ${tmpArray6[@]}|sed 's/; /;/g')\n    # 7.2.9 check if all groups in /etc/passwd exist in /etc/group\n    tmpArray=()\n    for i in $(cut -d: -s -f4 /etc/passwd|sort -u); do\n        grep -q -P \"^.*?:[^:]*:$i\" /etc/group\n        if [[ $? -ne 0 ]]; then\n        tmpArray+=($i\\;)\n            echo -e \"\\033[31m-[-] Group $i is referenced by /etc/passwd but does not exist in /etc/group \\033[0m\"\n        fi\n    done\n    groupNotExistInetcgroup=$(echo ${tmpArray[@]}|sed 's/; /;/g')\n    # 7.2.10 check if every user has a unique UID\n    #cat /etc/passwd|cut -d\":\" -f3|sort -n|uniq -c|while read x; do\n    tmpArray=()\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x\n        if [[ $1 -gt 1 ]]; then\n            local users=$(awk -F: '($3==n){print $1}' n=$2 /etc/passwd|xargs)\n            tmpArray+=($2:$users\\;)\n            echo -e \"\\033[31m-[-] Duplicate UID $2 : $users \\033[0m\"\n        fi\n    done < <(cat /etc/passwd|cut -d\":\" -f3|sort -n|uniq -c)\n    usersIfHasUniqueUIDArray=$(echo ${tmpArray[@]}|sed 's/; /;/g')\n    # 7.2.11 check if every group has a unique GID\n    tmpArray=()\n    #cat /etc/group|cut -d\":\" -f3|sort -n|uniq -c|while read x; do\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x\n        if [[ $1 -gt 1 ]]; then\n            local groups=$(awk -F: '($3==n){print $1}' n=$2 /etc/group|xargs)\n            tmpArray+=($2:$groups\\;)\n            echo -e \"\\033[31m-[-] Duplicate GID $2 : $groups \\033[0m\"\n        fi\n    done < <(cat /etc/group|cut -d\":\" -f3|sort -n|uniq -c)\n    groupsIfHasUniqueGIDArray=${tmpArray[@]}\n    # 7.2.12 check if user name is unique\n    tmpArray=()\n    #cat /etc/passwd|cut -d\":\" -f1|sort -n|uniq -c|while read x; do\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x11\n        if [[ $1 -gt 1 ]]; then\n            local uids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/passwd|xargs)\n            tmpArray+=($2:$uids\\;)\n            echo -e \"\\033[31m-[-] Duplicate user name $2 : $uids \\033[0m\"\n        fi\n    done < <(cat /etc/passwd|cut -d\":\" -f1|sort -n|uniq -c)\n    usersIfHasUniqueNameArray=${tmpArray[@]}\n    # 7.2.13 check if group name is unique\n    tmpArray=()\n    #cat /etc/group|cut -d\":\" -f1|sort -n|uniq -c|while read x; do\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x11\n        if [[ $1 -gt 1 ]]; then\n            local gids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/group|xargs)\n            tmpArray+=($2:$gids\\;)\n            echo -e \"\\033[31m-[-] Duplicate group name $2 : $gids \\033[0m\"\n        fi\n    done < <(cat /etc/group|cut -d\":\" -f1|sort -n|uniq -c)\n    groupsIfHasUniqueNameArray=${tmpArray[@]}\n    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\\\"}\n    system_check_res={\\\"file_permission_info\\\":$file_permission_info,\\\"usergroup_config_info\\\":$usergroup_config_info}\n\n}\n\necho \"\"\"\n==================================\n|        Linux 基线检查工具      |\n|        author:JC0o0l           |\n|        version:2.2             |\n==================================\n\"\"\"\nget_basic_info\ninit_check\nservice_check\nnetwork_check\nauditd_check\nlog_check\nauthentication_check\nsystem_check\nif [[ -z $authentication_check_res ]]; then\n    authentication_check_res={}\nfi\nif [[ -z $system_check_res ]]; then\n    system_check_res={}\nfi\ncheck_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}\ncurl -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\necho $check_result|jq \n"
  },
  {
    "path": "baseline_check_v2_JC0o0l.sh",
    "content": "#!/bin/bash\nfunction get_ip_info {\n    local ipList=`ifconfig | grep inet |grep -v inet6|grep -v 127|sed 's/^[ ]*//g'|cut -d\" \" -f2`\n    echo $ipList\n}\nfunction get_basic_info {\n    echo [·] collect basic info\n    hostname=`hostname`\n    ipList=`get_ip_info`\n    kernelVersion=`uname -r`\n    if [[ $(cat /proc/version) =~ \"Red Hat\" ]]; then\n        osVersion=`cat /etc/redhat-release|cut -f1,4 -d\" \"`\n    fi\n    basic_info={\\\"hostname\\\":\\\"$hostname\\\",\\\"ipList\\\":\\\"$ipList\\\",\\\"kernelVersion\\\":\\\"$kernelVersion\\\",\\\"osVersion\\\":\\\"$osVersion\\\"}\n    echo $basic_info\n}\n\nfunction init_check {\n    # 1. init configuration\n    echo [·] check init configuration\n    # 1.1 file system configuration\n    # 1.1.1 /tmp separate mount\n    local tmpIfSeparate #=\"\"\n    local tmpIfNoexec #=\"\"\n    local tmpIfNosuid #=\"\"\n    local res=$(mount|grep \"/tmp \") \n    if [[ -z $res ]]; then\n        echo -e \"\\033[31m-[-] /tmp/ not mounted on separate dick\\033[0m\"\n        tmpIfSeparate=\"false\"\n        tmpIfNoexec=\"false\"\n        tmpIfNosuid=\"false\"\n    else\n        tmpIfSeparate=\"true\"\n        tmpIfNoexec=\"true\"\n        tmpIfNosuid=\"true\"\n    fi\n    if $tmpIfSeparate; then\n        #mount|grep \"/sys/kernel/debug \" |while read res;do\n        while read res;do\n            #echo \"mount | grep /sys --result-->\" $res\n            # 1.1.2 /tmp noexec nosuid\n            local diskPart=$(echo $res|cut -d\" \" -f3)\n            if [[ ! $res =~ \"noexec\" ]];then\n                echo -e \"\\033[31m-[-] no noexec option on $diskPart partion\\033[0m\"\n                tmpIfNoexec=\"false\"\n                if [[ ! $res =~ \"nosuid\" ]];then\n                    echo -e \"\\033[31m-[-] no nosuid option on $diskPart partion\\033[0m\"\n                    tmpIfNosuid=\"false\"\n                fi\n            elif [[ ! $res =~ \"nosuid\" ]];then\n                echo -e \"\\033[31m-[-] no nosuid option on $diskPart partion\\033[0m\"\n                tmpIfNosuid=\"false\"\n            fi\n        done < <(mount | grep \"/tmp \")\n    fi\n    tmp_partition_info={\\\"tmpIfSeparate\\\":\\\"$tmpIfSeparate\\\",\\\"tmpIfNoexec\\\":\\\"$tmpIfNoexec\\\",\\\"tmpIfNosuid\\\":\\\"$tmpIfNosuid\\\"}\n    #echo $tmp_partition_info\n    # 1.2 secure boot configuration\n    if [[ -f /boot/grub2/grub.cfg ]];then\n        grubcfgIfExist=\"true\"\n        grubcfgPermission=\"0600\"\n        grubcfgIfSetPasswd=\"true\"\n    else\n        grubcfgIfExist=\"false\"\n        grubcfgPermission=\"0000\"\n        grubcfgIfSetPasswd=\"false\"\n    fi\n    if $grubcfgIfExist; then\n        # 1.2.1 /boot/grub2/grub.cfg permission /boot/grub2/user.cfg permission 0600 root:root\n        res=$(stat /boot/grub2/grub.cfg |while read x;do if [[ $x =~ \"Uid\" ]] && [[ $x =~ \"(\" ]]; then echo $x;fi;done|cut -d\"(\" -f2,3,4)\n        grubcfgPermission=$(echo $res|cut -d\"/\" -f1)\n        if [[ $(echo $res|cut -d\"/\" -f1) = \"0600\" ]]; then\n            echo -e \"\\033[32m-[+] /boot/grub2/grub.cfg permission is 0600 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] /boot/grub2/grub.cfg permission is not 0600 \\033[0m\"\n        fi\n        # 1.2.2 Ensure bootloader password is set\n        res=$(grep \"^GRUB2 PASSWORD\" /boot/grub2/grub.cfg)\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m-[+] /boot/grub2/grub.cfg seted password \\033[0m\"\n            grubcfgIfSetPasswd=\"true\"\n        else\n            echo -e \"\\033[31m-[-] /boot/grub2/grub.cfg not set password \\033[0m\"\n            grubcfgIfSetPasswd=\"false\"\n        fi\n    fi\n        \n    # 1.2.3 single user mode need authentication\n    if [[ -f /usr/lib/systemd/system/rescue.service ]] && [[ -f /usr/lib/systemd/system/emergency.service ]]; then\n        res1=`grep /sbin/sulogin /usr/lib/systemd/system/rescue.service`\n        res2=`grep /sbin/sulogin /usr/lib/systemd/system/emergency.service`\n        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\n            echo -e \"\\033[32m-[+] single user mode need authentication \\033[0m\"\n            singleUserModeIfNeedAuth=\"true\"\n        else\n            echo -e \"\\033[31m-[+] single user mode does not need authentication \\033[0m\"\n            singleUserModeIfNeedAuth=\"false\"\n        fi\n    fi\n    # 1.3 Mantary Access Control\n    # 1.3.1 ensure the SELinux state is enforcing\n    if [[ -f /etc/selinux/config ]]; then\n        local num=$(sestatus|grep -c enforcing)\n        if [[ $num -gt 1 ]]; then\n            echo -e \"\\033[32m-[+] SELinux state is enforcing \\033[0m\"\n            selinuxStateIfEnforcing=\"true\"\n        else\n            echo -e \"\\033[31m-[-] SELinux state is not enforcing \\033[0m\"\n            selinuxStateIfEnforcing=\"false\"\n        fi\n    fi\n    # 1.3.2 ensure selinux policy is configured\n    if [[ -f /etc/selinux/config ]]; then\n        res=$(sestatus|grep targeted)\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m-[+] SELinux policy is configured \\033[0m\"\n            selinuxPolicyIfConfigured=\"true\"\n        else\n            echo -e \"\\033[31m-[-] SELinux policy is not configure to targeted \\033[0m\"\n            selinuxPolicyIfConfigured=\"false\"\n        fi\n    fi\n    boot_secure_info={\\\"grubcfgIfExist\\\":\\\"$grubcfgIfExist\\\",\\\"grubcfgPermission\\\":\\\"$grubcfgPermission\\\",\\\"grubcfgIfSetPasswd\\\":\\\"$grubcfgIfSetPasswd\\\",\\\"singleUserModeIfNeedAuth\\\":\\\"$singleUserModeIfNeedAuth\\\",\\\"selinuxStateIfEnforcing\\\":\\\"$selinuxStateIfEnforcing\\\",\\\"selinuxPolicyIfConfigured\\\":\\\"$selinuxPolicyIfConfigured\\\"}\n    #echo $boot_secure_info\n    init_check_res={\\\"tmp_partition_info\\\":$tmp_partition_info,\\\"boot_secure_info\\\":$boot_secure_info}\n}\nfunction service_check {\n    # 2. service configuration\n    echo [·] check service configuration\n    # 2.1 time sync\n    # 2.1.1 time sync service is installed\n    if $(rpm -q ntp 1>/dev/null||rpm -q chrony 1>/dev/null) ; then\n        if $(rpm -q ntp 1>/dev/null) ; then\n            if [[ -f /etc/ntp.conf ]]; then\n                local res=$(egrep \"^(server|pool)\" /etc/ntp.conf)\n                if [[ -n $res ]]; then\n                    echo -e \"\\033[32m-[+] remote ntp server is configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"true\"\n                else\n                    echo -e \"\\033[31m-[-] remote ntp server is not configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"false\"\n                fi\n            fi\n        fi\n        if $(rpm -q chrony 1>/dev/null); then\n            if [[ -f /etc/chrony.conf ]]; then\n                local res=$(egrep \"^(server|pool)\" /etc/chrony.conf)\n                if [[ -n $res ]]; then\n                    echo -e \"\\033[32m-[+] remote chrony server is configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"true\"\n                else\n                    echo -e \"\\033[31m-[-] remote chrony server is not configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"false\"\n                fi\n                \n            fi\n        fi\n    fi        \n    # 2.1.2 x-window\n    local res=$(rpm -qa xorg-x11*)\n    if [[ -z $res ]]; then\n        echo -e \"\\033[32m-[+] x11-windows is not installed \\033[0m\"\n        x11windowIfNotInstalled=\"true\"\n    else\n        echo -e \"\\033[31m-[-] x11-windows is installed \\033[0m\"\n        x11windowIfNotInstalled=\"false\"\n    fi\n    service_check_res={\\\"timeSyncServerIfConfigured\\\":\\\"$timeSyncServerIfConfigured\\\",\\\"x11windowIfNotInstalled\\\":\\\"$x11windowIfNotInstalled\\\"}\n}\nfunction network_check {\n    # 3. network configuration\n    echo [·] check network configuration\n    # 3.1 hosts file configuration\n    # 3.1.1 check /etc/hosts.deny file\n    if [[ -f /etc/hosts.deny ]]; then\n        hostsDenyFileIfExist=\"true\"\n        echo -e \"\\033[32m-[+] file /etc/hosts.deny exists \\033[0m\"\n        local res=$(stat /etc/hosts.deny |while read x;do if [[ $x =~ \"Uid\" ]] && [[ $x =~ \"(\" ]]; then echo $x;fi;done|cut -d\"(\" -f2,3,4)\n        hostsDenyFilePermission=$(echo $res|cut -d\"/\" -f1)\n        if [[ $(echo $res|cut -d\"/\" -f1) = \"0644\" ]];then\n            echo -e \"\\033[32m-[+] file /etc/hosts.deny permission is 0644 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file /etc/hosts.deny permission is not 0644 \\033[0m\"\n        fi\n\n        local res=$(egrep \"^[^#].+\" /etc/hosts.deny)\n        if [[ -n $res ]]; then\n            hostsDenyFileIfConfigured=\"true\"\n            echo -e \"\\033[32m-[+] file /etc/hosts.deny is configured \\033[0m\"\n        else\n            hostsDenyFileIfConfigured=\"false\"\n            echo -e \"\\033[31m-[-] file /etc/hosts.deny is not configured \\033[0m\"\n        fi\n    else\n        hostsDenyFileIfExist=\"false\"\n        echo -e \"\\033[31m-[-] file /etc/hosts.deny does not exists \\033[0m\"\n    fi\n    # 3.1.2 check /etc/hosts.allow file\n    if [[ -f /etc/hosts.allow ]]; then\n        hostsAllowFileIfExist=\"true\"\n        echo -e \"\\033[32m-[+] file /etc/hosts.allow exists \\033[0m\"\n        local res=`stat /etc/hosts.allow |while read x;do if [[ $x =~ \"Uid\" ]] && [[ $x =~ \"(\" ]]; then echo $x;fi;done|cut -d\"(\" -f2,3,4`\n        hostsAllowFilePermission=$(echo $res|cut -d\"/\" -f1)\n        if [[ $(echo $res|cut -d\"/\" -f1) = \"0644\" ]];then\n            echo -e \"\\033[32m-[+] file /etc/hosts.allow permission is 0644 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file /etc/hosts.allow permission is not 0644 \\033[0m\"\n        fi\n\n        local res=$(egrep \"^[^#].+\" /etc/hosts.deny)\n        if [[ -n $res ]]; then\n            hostsAllowFileIfConfigured=\"true\"\n            echo -e \"\\033[32m-[+] file /etc/hosts.allow is configured \\033[0m\"\n        else\n            hostsAllowFileIfConfigured=\"false\"\n            echo -e \"\\033[31m-[-] file /etc/hosts.allow is not configured \\033[0m\"\n        fi\n    else\n        hostsAllowFileIfExist=\"false\"\n        echo -e \"\\033[31m-[-] file /etc/hosts.allow does not exists \\033[0m\"\n    fi\n\n    # 3.2 firewall configuration\n    # 3.2.1 ensure iptables is installed\n    if $(rpm -q iptables 1>/dev/null); then\n        iptablesIfInstalled=\"true\"\n        echo -e \"\\033[32m-[+] iptables is installed \\033[0m\"\n        # 3.2.2 ensure INPUT OUTPUT chain policy is DROP\n        #iptables -L|grep policy|while read x;do\n        while read x;do\n            if [[ $x =~ \"INPUT\" ]] && [[ $x =~ \"DROP\" ]]; then\n                iptablesInputPolicyIfDrop=\"true\"\n                echo -e \"\\033[32m-[+] INPUT chain policy is DROP \\033[0m\"\n            elif [[ $x =~ \"INPUT\" ]] && [[ ! $x =~ \"DROP\" ]]; then\n                iptablesInputPolicyIfDrop=\"false\"\n                echo -e \"\\033[31m-[-] INPUT chain policy is not DROP \\033[0m\"\n            fi\n            if [[ $x =~ \"OUTPUT\" ]] && [[ $x =~ \"DROP\" ]]; then\n                iptablesOutputPolicyIfDrop=\"true\"\n                echo -e \"\\033[32m-[+] OUTPUT chain policy is DROP \\033[0m\"\n            elif [[ $x =~ \"OUTPUT\" ]] && [[ ! $x =~ \"DROP\" ]]; then\n                iptablesOutputPolicyIfDrop=\"false\"\n                echo -e \"\\033[31m-[-] OUTPUT chain policy is not DROP \\033[0m\"\n            fi\n        done < <(iptables -L|grep policy)\n    else\n        iptablesIfInstalled=\"false\"\n        echo -e \"\\033[31m-[-] iptables is not installed \\033[0m\"\n    fi\n    network_check_res={\\\"hostsAllowFileIfExist\\\":\\\"$hostsAllowFileIfExist\\\",\\\"hostsAllowFilePermission\\\":\\\"$hostsAllowFilePermission\\\",\\\"hostsAllowFileIfConfigured\\\":\\\"$hostsAllowFileIfConfigured\\\",\\\"hostsDenyFileIfExist\\\":\\\"$hostsDenyFileIfExist\\\",\\\"hostsDenyFilePermission\\\":\\\"$hostsDenyFilePermission\\\",\\\"hostsDenyFileIfConfigured\\\":\\\"$hostsDenyFileIfConfigured\\\",\\\"iptablesIfInstalled\\\":\\\"$iptablesIfInstalled\\\",\\\"iptablesInputPolicyIfDrop\\\":\\\"$iptablesInputPolicyIfDrop\\\",\\\"iptablesOutputPolicyIfDrop\\\":\\\"$iptablesOutputPolicyIfDrop\\\"}\n}\n\nfunction auditd_check {\n\t# 4. auditd configuration\n\techo [·] check auditd configuration\n\t# 4.1 ensure auditd is enabled\n    echo \"-[·] check auditd if is enabled\"\n\tif [[ $(systemctl is-enabled auditd) = \"enabled\" ]]; then\n\t\techo -e \"\\033[32m-[+] auditd is enabled \\033[0m\"\n        auditdIfEnabled=\"true\"\n\telse\n        auditdIfEnabled=\"false\"\n\t\techo -e \"\\033[31m-[-] auditd is not enabled \\033[0m\"\n\tfi\n\t# 4.2 some settings in /etc/audit/auditd.conf\n    echo \"-[·] settings in /etc/audit/auditd.conf\"\t\n    if [[ -f /etc/audit/auditd.conf ]]; then\n        auditdconfIfExist=\"true\"\n        maxLogFile=$(grep \"^max_log_file[[:blank:]]=\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        maxLogFileAction=$(grep \"^max_log_file_action\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        spaceLeftAction=$(grep \"^space_left_action\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        numLogs=$(grep \"^num_logs\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        if [[ -n $maxLogFile ]]; then\n            auditdIfSetMaxLogFile=$maxLogFile\n            echo -e \"\\033[32m-[+] max_log_file size is ${maxLogFile} M \\033[0m\"\n        else\n            auditdIfSetMaxLogFile=\"false\"\n            echo -e \"\\033[31m-[-] max_log_file size is not setted \\033[0m\"\n        fi\n        if [[ -n $maxLogFileAction ]]; then\n            auditdIfSetMaxLogFileAction=\"$maxLogFileAction\"\n            echo -e \"\\033[32m-[+] max_log_file_action is ${maxLogFileAction}\\033[0m\"\n        else\n            auditdIfSetMaxLogFileAction=\"false\"\n            echo -e \"\\033[31m-[-] max_log_file_action is not setted \\033[0m\"\n        fi\n        if [[ -n $spaceLeftAction ]]; then\n            auditdIfSetSpaceLeftAction=\"$spaceLeftAction\"\n            echo -e \"\\033[32m-[+] space_left_action is ${spaceLeftAction}\\033[0m\"\n        else\n            auditdIfSetSpaceLeftAction=\"false\"\n            echo -e \"\\033[31m-[-] space_left_action is not setted \\033[0m\"\n        fi\n        if [[ -n $numLogs ]]; then\n            auditdIfSetNumLogs=\"$numLogs\"\n            echo -e \"\\033[32m-[+] the num of logs is ${numLogs} \\033[0m\"\n        else\n            auditdIfSetNumLogs=\"false\"\n            echo -e \"\\033[31m-[-] num_logs is not setted \\033[0m\"\n        fi\n    else\n        auditdconfIfExist=\"false\"\n    fi\n    auditd_config_info={\\\"auditdIfEnabled\\\":\\\"$auditdIfEnabled\\\",\\\"auditdconfIfExist\\\":\\\"$auditdconfIfExist\\\",\\\"auditdIfSetMaxLogFile\\\":\\\"$auditdIfSetMaxLogFile\\\",\\\"auditdIfSetMaxLogFileAction\\\":\\\"$auditdIfSetMaxLogFileAction\\\",\\\"auditdIfSetSpaceLeftAction\\\":\\\"$auditdIfSetSpaceLeftAction\\\",\\\"auditdIfSetNumLogs\\\":\\\"$auditdIfSetNumLogs\\\"}\n    echo $auditd_config_info\n    # 4.3 rules in /etc/audit/audit.rules\n    # arch 64\n    echo \"-[·] time-change\" \n    if [[ -f /etc/audit/audit.rules ]]; then\n        auditdrulesIfExist=\"true\"\n        echo -e \"\\033[32m-[+] /etc/audit/audit.rules is exist \\033[0m\"\n        if [[ ! -n $(grep time /etc/audit/audit.rules) ]]; then\n            auditdRulesIfNotNull=\"false\"\n            echo -e \"\\033[31m-[-] not set rule about audit the change of date and time \\033[0m\"\n        else\n            auditdRulesIfNotNull=\"true\"\n            # 4.3.1 time-change\n            local timeChangeList=$(egrep \"(stime|clock_settime|adjtimex|settimeofday|/etc/localtime)\" /etc/audit/audit.rules|wc -l)\n            if [[ ${timeChangeList} -gt 3 ]]; then\n                auditdIfCheckTimechange=\"true\"\n                echo -e \"\\033[32m-[+] audith the change of date and time \\033[0m\"\n            elif [[ ${timeChangeList} -gt 1 ]]; then\n                auditdIfCheckTimechange=\"false\"\n                echo -e \"\\033[31m-[-] not fully set rule about audit the change of date and time \\033[0m\"\n            else \n                auditdIfCheckTimechange=\"false\"\n                echo -e \"\\033[31m-[-] not set rule about audit the change of date and time \\033[0m\"\n            fi\n            # 4.3.2 user and group change\n            echo \"-[·] user and group change\"\n            local keyArray=(\"/etc/passwd\" \"/etc/group\" \"/etc/gshadow\" \"/etc/shadow\" \"/etc/security/opasswd\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    echo -e \"\\033[32m-[+] audit the change of $i \\033[0m\"\n                else\n                    tmpArray2+=($i)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedUserandgroupfile=${tmpArray1[@]}\n            auditdRulesNotCheckedUserandgroupfile=${tmpArray2[@]}\n            # 4.3.3 system's network environment change\n            echo \"-[·] system's network environment change\"\n            local keyArray=(\"/etc/issue\" \"/etc/issue.net\" \"/etc/hosts\" \"/etc/sysconfig/network\" \"/etc/sysconfig/network-scripts/\" )\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                    if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    echo -e \"\\033[32m-[+] audit the change of $i \\033[0m\"\n                else\n                    tmpArray2+=($i)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            local keyArray=(\"sethostname\" \"setdomainname\")\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    echo -e \"\\033[32m-[+] audit the use of syscall  $i \\033[0m\"\n                else\n                    echo -e \"\\033[31m-[-] not audit the use of syscall $i \\033[0m\"\n                    tmpArray2+=($i)\n                fi\n            done\n            auditdRulesCheckedNetworkenv=${tmpArray1[@]}\n            auditdRulesNotCheckedNetworkenv=${tmpArray2[@]}\n            # 4.3.4 system's Mandatory Access Controls change\n            echo \"-[·] system's Mandatory Access Controls change\"\n            local keyArray=(\"/etc/selinux\" \"/usr/share/selinux\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    echo -e \"\\033[32m-[+] audit the change of   $i \\033[0m\"\n                else\n                    tmpArray2+=($i)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedMACchange=${tmpArray1[@]}\n            auditdRulesNotCheckedMACchange=${tmpArray2[@]}\n            # 4.3.5 audit events of login and logout\n            echo \"-[·] audit events of login and logout\"\n            local keyArray=(\"/var/log/lastlog\" \"/var/run/faillock/\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    echo -e \"\\033[32m-[+] audit the change of   $i \\033[0m\"\n                else\n                    tmpArray2+=($i)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedLoginoutEvents=${tmpArray1[@]}\n            auditdRulesNotCheckedLoginoutEvents=${tmpArray2[@]}\n            # 4.3.6 audit the change of discretionary access control\n            echo \"-[·] audit the change of discretionary access control\"\n            local keyArray=(\"(chmod|fchmod|fchmodat)\" \"(chown|fchown|fchownat)\" \"(setxattr|lsetxattr|removexattr)\" \"(lock|time)\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')\n                    echo -e \"\\033[32m-[+] audit the use of systemcall  $i \\033[0m\"\n                    tmpArray1+=($i)\n                else\n                    tmpArray2+=($i)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')\n                    echo -e \"\\033[31m-[-] not audit the use of systemcall $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedDACChangeSyscall=${tmpArray1[@]}\n            auditdRulesNotCheckedDACChangeSyscall=${tmpArray2[@]}\n            # 4.3.7 audit the events of unsuccessful unauthorized file access attempts\n            echo \"-[·] audit the events of unsuccessful unauthorized file access attempts\"\n            local keyArray=(\"(create|open|openat|truncate|ftruncate).*?exit=-EACCESS\" \"(create|open|openat|truncate|ftruncate).*?exit=-EPERM\" )\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[32m-[+] audit the use of systemcall  $i \\033[0m\"\n                else\n                    tmpArray2+=($i)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[31m-[-] not audit the use of systemcall $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedFileAccessAttemptSyscall=${tmpArray1[@]}\n            auditdRulesNotCheckedFileAccessAttemptSyscall=${tmpArray2[@]}\n            # 4.3.8 audit the use of privileged commands\n            echo \"-[·] audit the use of privileged commands\"\n            #find / -name \"passwd\"\n            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\"}'\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${res[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[32m-[+] audit the use of command  $i \\033[0m\"\n                else\n                    tmpArray2+=($i)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[31m-[-] not audit the use of command $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedPrivilegedCommand=${tmpArray1[@]}\n            auditdRulesNotCheckedPrivilegedCommand=${tmpArray2[@]}\n            # 4.3.9 audit the change of file sudoer\n            echo \"-[·] audit the change of file sudoer\"\n            local keyArray=(\"/etc/sudoers\" \"/etc/sudoers.d/\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[32m-[+] audit the change of file  $i \\033[0m\"\n                else\n                    tmpArray2+=($i)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[31m-[-] not audit the change of file $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedSudoerFile=${tmpArray1[@]}\n            auditdRulesNotCheckedSudoerFile=${tmpArray2[@]}\n            # 4.3.10 check the audit configuration is setted to immutable unless reboot the server\n            echo \"-[·] check the audit configuration is setted to immutable unless reboot the server\"\n            local res=$(grep \"^\\s*[^#]\" /etc/audit/audit.rules|tail -1|egrep \"-e.*?2\")\n            if [[ -n $res ]]; then\n                auditdRulesIfImmutable=\"true\"\n                echo -e \"\\033[32m-[+] auditd setted -e 2 \\033[0m\"\n            else\n                auditdRulesIfImmutable=\"false\"\n                echo -e \"\\033[31m-[-] auditd not setted -e 2 \\033[0m\"\n            fi\n        fi\n    else\n        auditdrulesIfExist=\"false\"\n        echo -e \"\\033[32m-[+] /etc/audit/audit.rules is not exist \\033[0m\"\n    fi\n    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\\\"}\n    auditd_check_res={\\\"auditd_config_info\\\":$auditd_config_info,\\\"auditd_rules_info\\\":$auditd_rules_info}\n}\n\nfunction log_check {\n    echo \"[·] check log configuration\"\n\t# 5.1 ensure auditd is enabled\n    echo \"-[·] check rsyslog if is enabled\"\n\tif [[ $(systemctl is-enabled rsyslog) = \"enabled\" ]]; then\n        rsyslogIfEnabled=\"true\"\n\t\techo -e \"\\033[32m-[+] rsyslog is enabled \\033[0m\"\n\telse\n        rsyslogIfEnabled=\"false\"\n\t\techo -e \"\\033[31m-[-] rsyslog is not enabled \\033[0m\"\n\tfi\n    \n    log_check_res={\\\"rsyslogIfEnabled\\\":\\\"$rsyslogIfEnabled\\\"}\n\n}\n\nfunction authentication_check {\n    echo \"[·] check cron ssh pam and env configuration\"\n    # 6.1 cron configuration\n    echo \"-[·] check cron configuration\"\n    # 6.1.1 check cron service is enabled\n    echo \"-[·] check crond if is enabled\"\n\tif [[ $(systemctl is-enabled crond) = \"enabled\" ]]; then\n\t\techo -e \"\\033[32m-[+] crond is enabled \\033[0m\"\n        crondIfEnabled=\"true\"\n\telse\n        crondIfEnabled=\"false\"\n\t\techo -e \"\\033[31m-[-] crond is not enabled \\033[0m\"\n\tfi\n    # 6.1.2 check cron's configuration file permission\n    echo \"-[·] check cron's configuration file permission\"\n    local keyArray=(\"/etc/crontab\" \"/etc/cron.hourly\" \"/etc/cron.daily\" \"/etc/cron.weekly\" \"/etc/cron.monthly\" \"/etc/cron.d\")\n    crondConfigFilenameArray=$keyArray\n    tmpArray=()\n    for i in ${keyArray[@]} ; do\n        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)\n        tmpArray+=($res)\n        if [[ $res = \"0600\" ]] || [[ $res = \"0700\" ]]; then\n            echo -e \"\\033[32m-[+] file $i's permission is $res \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \\033[0m\"\n        fi\n    done\n    crondConfigFilePermission=${tmpArray[@]}\n    # 6.1.3 check cron.allow cron.deny permission and owner\n    echo \"-[·] check cron.allow cron.deny configuration file permission\"\n    local keyArray=(\"/etc/cron.allow\" \"/etc/cron.deny\")\n    crondallowdenyFilenameArray=$keyArray\n    tmpArray1=()\n    tmpArray2=()\n    tmpArray3=()\n    for i in ${keyArray[@]} ; do\n        if [[ ! -f $i ]]; then\n            tmpArray1+=(\"false\")\n            echo -e \"\\033[31m-[-] file $i not exist \\033[0m\"\n            continue\n        else\n            tmpArray1+=(\"true\")\n        fi\n        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)\n        tmpArray2+=($res1)\n        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)\n        tmpArray3+=(\"$res2\")\n        if [[ $res1 = \"0600\" ]] || [[ $res1 = \"0700\" ]]; then\n            echo -e \"\\033[32m-[+] file $i's permission is $res \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \\033[0m\"\n        fi\n        if [[ $res2 = \"root root\" ]]; then\n            echo -e \"\\033[32m-[+] file $i's owner is $res2 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $i's owner is not root \\033[0m\"\n        fi\n    done\n    crondallowdenyFileIfExistArray=${tmpArray1[@]}\n    crondallowdenyFilePermissionArray=${tmpArray2[@]}\n    crondallowdenyFileOwnerArray=${tmpArray3[@]}\n    crond_config_info={\\\"crondIfEnabled\\\":\\\"$crondIfEnabled\\\",\\\"crondConfigFilenameArray\\\":\\\"$crondConfigFilenameArray\\\",\\\"crondConfigFilePermissionArray\\\":\\\"$crondConfigFilePermissionArray\\\",\\\"crondallowdenyFilenameArray\\\":\\\"$crondallowdenyFilenameArray\\\",\\\"crondallowdenyFileIfExistArray\\\":\\\"$crondallowdenyFileIfExistArray\\\",\\\"crondallowdenyFilePermissionArray\\\":\\\"$crondallowdenyFilePermissionArray\\\",\\\"crondallowdenyFileOwnerArray\\\":\\\"$crondallowdenyFileOwnerArray\\\"}\n    # 6.2 SSH configuration\n    echo \"-[·] check ssh configuration\"\n\tif [[ $(systemctl is-enabled sshd) = \"enabled\" ]]; then\n        sshdIfEnabled=\"true\"\n        # 6.2.1 /etc/ssh/sshd_config permission 0600\n        local file=\"/etc/ssh/sshd_config\"\n        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)\n        if [[ $res = \"0600\" ]]; then\n            sshdConfigFilePermission=$res\n            echo -e \"\\033[32m-[+] file $file's access permission is $res \\033[0m\"\n        else\n            sshdConfigFilePermission=\"false\"\n            echo -e \"\\033[3-m-[-] file $file's access permission is $res \\033[0m\"\n        fi\n        # 6.2.2 check ssh x11 forwarding if is disabled\n        local res=$(grep \"^X11Forwaring\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisableX11forwarding=\"true\"\n            echo -e \"\\033[32m-[+] X11Forwarding no \\033[0m\"\n        else\n            sshdIfDisableX11forwarding=\"false\"\n            echo -e \"\\033[31m-[-] not set X11Forwarding no \\033[0m\"\n        fi\n        # 6.2.3 check ssh MaxAUTHTries if is 4\n        local res=$(grep \"^MaxAuthTries\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSetMaxAuthTries=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\\2/')\n            echo -e \"\\033[32m-[+] $res \\033[0m\"\n        else\n            sshdIfSetMaxAuthTries=\"false\"\n            echo -e \"\\033[31m-[-] not set MaxAuthTries \\033[0m\"\n        fi\n        # 6.2.4 check ssh IgnoreRhosts if is enabled\n        local res=$(grep \"^IgnoreRhosts\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep yes) ]]; then\n            sshdIfEnableIgnoreRhosts=\"true\"\n            echo -e \"\\033[32m-[+] IgnoreRhosts yes \\033[0m\"\n        else\n            sshdIfEnableIgnoreRhosts=\"false\"\n            echo -e \"\\033[31m-[-] not set IgnoreRhosts no\\033[0m\"\n        fi\n        # 6.2.5 check ssh HostbasedAuthentication if is disabled\n        local res=$(grep \"^HostbasedAuthentication\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisableHostbasedAuthentication=\"true\"\n            echo -e \"\\033[32m-[+] HostbasedAuthentication no \\033[0m\"\n        else\n            sshdIfDisableHostbasedAuthentication=\"false\"\n            echo -e \"\\033[31m-[-] not set HostbasedAuthentication no\\033[0m\"\n        fi\n        # 6.2.6 check ssh root login if is diabled\n        local res=$(grep \"^PermitRootLogin\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisablePermitRootLogin=\"true\"\n            echo -e \"\\033[32m-[+] PermitRootLogin no \\033[0m\"\n        else\n            sshdIfDisablePermitRootLogin=\"false\"\n            echo -e \"\\033[31m-[-] not set PermitRootLogin no\\033[0m\"\n        fi\n        # 6.2.7 check ssh PermitEmptyPasswords if is diabled\n        local res=$(grep \"^PermitEmptyPasswords\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisablePermitEmptyPasswords=\"true\"\n            echo -e \"\\033[32m-[+] PermitEmptyPasswords no \\033[0m\"\n        else\n            sshdIfDisablePermitEmptyPasswords=\"false\"\n            echo -e \"\\033[31m-[-] not set PermitEmptyPasswords no\\033[0m\"\n        fi\n        # 6.2.8 check ssh PermitUserEnvironment if is diabled\n        local res=$(grep \"^PermitUserEnvironment\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisablePermitUserEnvironment=\"true\"\n            echo -e \"\\033[32m-[+] PermitUserEnvironment no \\033[0m\"\n        else\n            sshdIfDisablePermitUserEnvironment=\"false\"\n            echo -e \"\\033[31m-[-] not set PermitUserEnvironment no\\033[0m\"\n        fi\n        # 6.2.9 check if set specific MAC algorithms\n        local res=$(grep \"^MACs\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSpecificMACs=\"true\"\n            echo -e \"\\033[32m-[+] will use specific MAC algorithms $res \\033[0m\"\n        else\n            sshdIfSpecificMACs=\"false\"\n            echo -e \"\\033[31m-[-] not set specific MAC algorithms\\033[0m\"\n        fi\n        # 6.2.10 check SSH idle Timeout Interval if is configured\n        local res=$(grep \"^ClientAliveInterval\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSetClientAliveInterval=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\\2/')\n            echo -e \"\\033[32m-[+] $res \\033[0m\"\n        else\n            sshdIfSetClientAliveInterval=\"false\"\n            echo -e \"\\033[31m-[-] not set ClientAliveInterval \\033[0m\"\n        fi\n        # 6.2.11 check SSH LoginGrace Time\n        local res=$(grep \"^LoginGraceTime\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSetLoginGraceTime=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\\2/')\n            echo -e \"\\033[32m-[+] $res \\033[0m\"\n        else\n            sshdIfSetLoginGraceTime=\"false\"\n            echo -e \"\\033[31m-[-] not set LoginGraceTime \\033[0m\"\n        fi\n\telse\n        sshdIfEnabled=\"false\"\n\t\techo -e \"\\033[32m-[+] sshd is not enabled \\033[0m\"\n\tfi\n    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\\\"}\n\n    # 6.3 PAM configuration\n    echo \"-[·] check pam configuration\"\n    # 6.3.1 password creation policy\n    if [[ -f /etc/security/pwquality.conf ]]; then\n        pamPwqualityconfIfExist=\"true\"\n        local minlen=$(grep ^minlen /etc/security/pwquality.conf | sed 's/ //g')\n        local minclass=$(grep ^minclass /etc/security/pwquality.conf |sed 's/ //g')\n        if [[ -n $minlen ]]; then\n            pamIfSetMinlen=$(echo $minlen|cut -d= -f2)\n            echo -e \"\\033[32m-[+] minimime length of password is $(echo $minlen|cut -d= -f2) \\033[0m\"\n        else\n            pamIfSetMinlen=\"false\"\n            echo -e \"\\033[31m-[-] not set minlen \\033[0m\"\n        fi\n        if [[ -n $minclass ]]; then\n            pamIfSetMinclass=$(echo $minclass|cut -d= -f2)\n            echo -e \"\\033[32m-[+] minclass of password is $(echo $minclass|cut -d= -f2) \\033[0m\"\n        else\n            local keyArray=(\"^dcredit\" \"^lcredit\" \"^ocredit\" \"^ucredit\")\n            local tmpCount=0\n            for i in ${keyArray[@]}; do\n                if [[ -n  $(grep $i /etc/security/pwquality.conf) ]]; then\n                    tmpCount=$(expr 1 + $tmpCount)\n                fi\n            done\n            if [[ $tmpCount = 0 ]]; then\n                pamIfSetMinclass=\"false\"\n            else\n                pamIfSetMinclass=$tmpCount\n            fi\n            if [[ tmpCount -ge 2 ]]; then\n                echo -e \"\\033[32m-[+] minclass of passwd is $tmpCount \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] not set minclass \\033[0m\"\n            fi\n        fi\n    else\n        pamPwqualityconfIfExist=\"false\"\n    fi\n    # 6.3.2 lock account and unlock time\n    local files=(\"/etc/pam.d/password-auth\" \"/etc/pam.d/system-auth\")\n    local keyArray=(\"pam_faillock\\.so.*?unlock_time\")\n    tmpArray1=()\n    tmpArray2=()\n    for i in ${files[@]}; do\n        for k in ${keyArray[@]}; do\n            if [[ -n $(egrep $k $i ) ]]; then\n                echo -e \"\\033[32m-[+] set lock and unlock_time in $i \\033[0m\"\n                tmpArray1+=($i)\n            else\n                tmpArray2+=($i)\n                echo -e \"\\033[31m-[-] not set lock and unlock_time in $i \\033[0m\"\n            fi\n        done\n    done\n    sshdSetedLockAndUnlockTimeFiles=${tmpArray1[@]}\n    sshdNotSetedLockAndUnlockTimeFiles=${tmpArray2[@]}\n    # 6.3.3 check password reuse if is limited\n    sshdPamdFileArray=${files[@]}\n    tmpArray=()\n    for i in ${files[@]}; do\n        local res=$(egrep '^password\\s+sufficient\\s+pam_unix.so' $i)\n        if [[ -n $res ]] && [[ $res =~ \"remember=\" ]]; then\n            local tmp=$(echo $res|sed 's/.*\\(remember=[[:digit:]]\\).*/\\1/g'|sed 's/ //g'|cut -d= -f2)\n            tmpArray+=($tmp)\n            echo -e \"\\033[32m-[+] password reuse limit is $tmp in $i \\033[0m\"\n        else\n            tmpArray+=(\"false\")\n            echo -e \"\\033[31m-[-] passowrd reuse limit not set in $i \\033[0m\"\n        fi\n    done\n    sshdPamdFileReuseLimitArray=${tmpArray[@]}\n    # 6.3.4 check the algorithm of store password if is sha512\n    tmpArray=()\n    for i in ${files[@]}; do\n        local res=$(egrep '^password\\s+sufficient\\s+pam_unix.so' $i)\n        if [[ -n $res ]] && [[ $res =~ \"sha512\" ]]; then\n            tmpArray+=(\"true\")\n            echo -e \"\\033[32m-[+] password storage algorithm is set to sha512 in $i \\033[0m\"\n        else\n            tmpArray+=(\"false\")\n            echo -e \"\\033[31m-[-] password storage algorithm is not specific to sha512 in $i \\033[0m\"\n        fi\n    done\n    sshdPamdFileIfSetSha512=${tmpArray[@]}\n    pam_config_info={\\\"pamPwqualityconfIfExist\\\":\\\"$pamPwqualityconfIfExist\\\",\\\"pamIfSetMinlen\\\":\\\"$pamIfSetMinlen\\\",\\\"pamIfSetMinclass\\\":\\\"$pamIfSetMinclass\\\",\\\"sshdSetedLockAndUnlockTimeFiles\\\":\\\"$sshdSetedLockAndUnlockTimeFiles\\\",\\\"sshdNotSetedLockAndUnlockTimeFiles\\\":\\\"$sshdNotSetedLockAndUnlockTimeFiles\\\",\\\"sshdPamdFileArray\\\":\\\"$sshdPamdFileArray\\\",\\\"sshdPamdFileReuseLimitArray\\\":\\\"$sshdPamdFileReuseLimitArray\\\",\\\"sshdPamdFileIfSetSha512\\\":\\\"$sshdPamdFileIfSetSha512\\\"}\n    # 6.4 user accounts and environment\n    echo \"-[·] check user accounts and environment\"\n    if [[ -f /etc/login.defs ]]; then\n        accountLogindefsIfExist=\"true\"\n        # 6.4.1 basic settings\n        local file='/etc/login.defs'\n        passMaxDays=$(grep ^PASS_MAX_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\\1/g')\n        passMinDays=$(grep ^PASS_MIN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\\1/g')\n        passWarnAge=$(grep ^PASS_WARN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\\1/g')\n        inactive=$(useradd -D|grep INACTIVE|sed 's/ //g'|cut -d= -f2)\n        accountPassMaxDays=$passMaxDays\n        accountPassMinDays=$passMinDays\n        accountPassWarnDays=$passWarnAge\n        accountPassAutolockInactiveDays=$inactive\n        if [[ $passMaxDays -le 90 ]]; then\n            echo -e \"\\033[32m-[+] the maximume days of password have to change is $passMaxDays \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the maximume days of password have to change is $passMaxDays ,should less than 90 day\\033[0m\"\n        fi\n        if [[ $passMinDays -ge 7 ]]; then\n            echo -e \"\\033[32m-[+] the minimume days of password have to change is $passMinDays \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the minimume days of password have to change is $passMinDays ,should great than 7 day\\033[0m\"\n        fi\n        if [[ $passWarnAge -ge 7 ]]; then\n            echo -e \"\\033[32m-[+] the minimume days of warn password need to change is $passWarnAge \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the minimume days of warn password need to change is $passWarnAge ,should greate than 7 day\\033[0m\"\n        fi\n        if [[ $inactive != -1 ]]; then\n            echo -e \"\\033[32m-[+] auto lock account when the  $inactive day haven't login \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] haven't set day of auto lock accounts \\033[0m\"\n        fi\n        # 6.4.2 check system's account if is unlogin\n        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}')\n        accountShouldUnloginAray=()\n        if [[ -z $res ]]; then\n            echo -e \"\\033[32m-[+] system account can't login \\033[0m\"\n        else\n            accountShouldUnloginAray=($(echo $res|sed 's/\\n/ /g'))\n            echo -e \"\\033[31m-[-]  ($(echo $res|sed 's/\\n/ /g'))user's shell need set to /sbin/nologin \\033[0m\"\n        fi\n        # 6.4.3 check default group for the root account if is GID 0\n        local res=$(grep \"^root:\" /etc/passwd|cut -d: -f4)\n        accountGIDOfRoot=$res\n        if [[ $res = 0 ]]; then\n            echo -e \"\\033[32m-[+] default group for the root account is GID 0 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-]] default group for the root account is is GID $res,not GID 0 \\033[0m\"\n        fi\n        # 6.4.4 check default user shell timeout if is 900 seconds or less\n        local files=(\"/etc/bashrc\" \"/etc/profile\")\n        tmpArray1=()\n        tmpArray2=()\n        for file in ${files[@]}; do\n            if [[ ! -f $file ]]; then\n                continue\n            else\n                tmpArray1+=($file)\n            fi\n            local res=$(grep \"^TMOUT\" $file|sed 's/ //g'|cut -d= -f2)\n            tmpArray2+=($res)\n            if [[ -z $res ]]; then\n                echo -e \"\\033[31m-[-] not set TMOUT in file $file \\033[0m\"\n                continue\n            fi\n            if [[ $res -le 900 ]]; then\n                echo -e \"\\033[32m-[+] when idle time great than $res seconds will close connection \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] when idle time great than $res seconds will close connection,the time should less than 900 seconds \\033[0m\"\n            fi\n        done\n        accountProfileFileArray=${tmpArray1[@]}\n        accountProfileTMOUTArray=${tmpArray2[@]}\n        # 6.4.5 check access to su command if is restricted\n        local res=$(grep pam_wheel.so /etc/pam.d/su)\n        accountIfSetUsersCanAccessSuCommand=\n        if [[ -n $res ]]; then\n            local res=$(grep wheel /etc/group|cut -d: -f4)\n            if [[ -n $res ]]; then\n                accountIfSetUsersCanAccessSuCommand=$res\n                echo -e \"\\033[32m-[+] access to su command is specific to $res \\033[0m\"\n            else\n                accountIfSetUsersCanAccessSuCommand=\"false\"\n                echo -e \"\\033[31m-[-] access to su command is not restricted \\033[0m\"\n            fi\n        else\n            accountIfSetUsersCanAccessSuCommand=\"false\"\n            echo -e \"\\033[31m-[-] access to su command is not restricted \\033[0m\"\n        fi\n    else\n        accountLogindefsIfExist=\"false\"\n        echo -e \"\\033[31m-[-] file /etc/login.defs is not exist \\033[0m\"\n    fi\n    account_config_info={\\\"accountPassMaxDays\\\":\\\"$accountPassMaxDays\\\",\\\"accountPassMinDays\\\":\\\"$accountPassMinDays\\\",\\\"accountPassWarnDays\\\":\\\"$accountPassWarnDays\\\",\\\"accountPassAutolockInactiveDays\\\":\\\"$accountPassAutolockInactiveDays\\\",\\\"accountShouldUnloginArray\\\":\\\"$accountShouldUnloginArray\\\",\\\"accountGIDOfRoot\\\":\\\"$accountGIDOfRoot\\\",\\\"accountProfileFileArray\\\":\\\"$accountProfileFileArray\\\",\\\"accountProfileTMOUTArray\\\":\\\"$accountProfileTMOUTArray\\\",\\\"accountIfSetUsersCanAccessSuCommand\\\":\\\"$accountIfSetUsersCanAccessSuCommand\\\"}\n    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}\n}\n\nfunction system_check {\n    echo \"[·] check permission of important file and configuration of user and group\"\n    # 7.1 check permission of important file and uid gid\n    echo \"-[·] check permission of important file\"\n    local files=(\"/etc/passwd\" \"/etc/shadow\" \"/etc/group\" \"/etc/gshadow\" \"/etc/passwd-\" \"/etc/shadow-\" \"/etc/group-\" \"/etc/gshadow-\")\n    importantFilenameArray=${files[@]}\n    tmpArray1=()\n    tmpArray2=()\n    for file in ${files[@]}; do\n        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)\n        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)\n        tmpArray1+=($perm)\n        tmpArray2+=($uidGid)\n        if [[ $file =~ \"shadow\" ]]; then\n            if [[ $perm = \"0000\" ]]; then\n                echo -e \"\\033[32m-[+] file $file's permission is $perm \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] file $file's permission is $perm,should set to 0000 \\033[0m\"\n            fi\n        else\n            if [[ $perm = \"0644\" ]]; then\n                echo -e \"\\033[32m-[+] file $file's permission is $perm \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] file $file's permission is $perm,should set to 0644 \\033[0m\"\n\n            fi\n        fi\n        if [[ $uidGid = \"0 0\" ]]; then\n            echo -e \"\\033[32m-[+] file $file's uid gid is $uidGid \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $file's uid gid is $uidGid,should set to 0 0 \\033[0m\"\n        fi\n    done\n    importantFilePermissionArray=${tmpArray1[@]}\n    importantFileUidgidArray=${tmpArray2[@]}\n    file_permission_info={\\\"importantFilenameArray\\\":\\\"$importantFilenameArray\\\",\\\"importantFilePermissionArray\\\":\\\"$importantFilePermissionArray\\\",\\\"importantFileUidgidArray\\\":\\\"$importantFileUidgidArray\\\"}\n    # 7.2 check configuration of user and group\n    echo \"-[·] check configuration of user and group\"\n    # 7.2.1 check if user's password is empty\n    users=$(cat /etc/shadow |awk -F: '($2==\"!!\"){print $1}'|while read x;do \n        res=$(grep ${x} /etc/passwd|cut -d: -f7); if [[ $res != \"/sbin/nologin\" ]] && [[ $res != \"/sbin/shutdon\" ]] && [[ $res != \"/sbin/halt\" ]]; then \n            echo $x\n            #echo -e \"\\033[31m-[-] $x should have a passwd,not empty \\033[0m\"; \n            fi;\n        done)\n    if [[ -z $users ]]; then\n        userIfSetPasswdOrArray=\"true\"\n        echo -e \"\\033[32m-[+] all user account have set password \\033[0m\"\n    else\n        userIfSetPasswdOrArray=$(echo $users|sed 's/\\n/ /g')\n        echo -e \"\\033[31m-[-] user:$(echo $users|sed 's/\\n/ /g') should set a password ,rather than empty \\033[0m\"\n    fi\n    # 7.2.2 check if root is the only UID 0 account\n    local users=$(cat /etc/passwd|awk -F: '($3==0){print $1}')\n    if [[ $users = 'root' ]]; then\n        uid0OnlyRootOrArray=\"true\"\n        echo -e \"\\033[32m-[+] root is the only account that uid is 0 \\033[0m\"\n    else\n        uid0OnlyRootOrArray=$(echo $users|sed 's/root//g'|sed 's/\\n/ /g')\n        echo -e \"\\033[31m-[-] $(echo $users|sed 's/root//g'|sed 's/\\n/ /g') uid should not be 0 \\033[0m\"\n    fi\n    # 7.2.3 check root PATH integrith\n    if [ \"$(echo $PATH|grep ::)\" != \"\" ]; then\n        echo -e \"\\033[31m-[-] Empty Directory in PATH (::) \\033[0m\"\n    fi\n    if [ \"$(echo $PATH|grep :$)\" != \"\" ]; then\n        echo -e \"\\033[31m-[-] Trailing : in PATH \\033[0m\"\n    fi\n    path=$( echo $PATH|sed -e 's/::/:/' -e 's/:$//' -e 's/:/ /g')\n    tmpArray1=()\n    tmpArray2=()\n    tmpArray3=()\n    tmpArray4=()\n    tmpArray5=()\n    set -- $path\n    while [[ $1 != \"\" ]]; do\n        if [[ $1 = \".\" ]]; then\n            echo -e \"\\033[31m-[-] PATH contains . \\033[0m\"\n            tmpArray1+=(\".\")\n            shift\n            continue\n        fi\n        if [[ -d $1 ]]; then\n            local dirperm=$(ls -ldH $1|cut -d\" \" -f1)\n            if [[ $(echo $dirperm|cut -c6) != \"-\" ]]; then\n                tmpArray2+=($1)\n                echo -e \"\\033[31m-[-] Group Write permission should not set on directory $1 \\033[0m\"\n            fi\n            if [[ $(echo $dirperm|cut -c9) != \"-\" ]]; then\n                tmpArray3+=($1)\n                echo -e \"\\033[31m-[-] Other Write permission should not set on directory $1 \\033[0m\"\n            fi\n            local dirown=$(ls -ldH $1|awk '{print $3}')\n            if [[ $dirown != \"root\" ]]; then\n                tmpArray4+=($1)\n                echo -e \"\\033[31m-[-] dir $1's owner is $dirown,should be root \\033[0m\"\n            fi\n        else\n            tmpArray5+=($1)\n            echo -e \"\\033[31m-[-] $1 is not a directory or not exist \\033[0m\"\n        fi\n        shift\n    done\n    if [[ ${#tmpArray1[@]} = 0 ]]; then\n        pathDirIfNotHasDot=\"true\"\n    else\n        pathDirIfNotHasDot=\"false\"\n    fi\n    pathDirPermissionHasGWArray=${tmpArray2[@]}\n    pathDirPermissionHasOWArray=${tmpArray2[@]}\n    pathDirOwnerIsNotRootArray=${tmpArray4[@]}\n    pathDirDoesNotExistOrNotDirArray=${tmpArray5[@]}\n    # 7.2.4 check if is all users' home directories exist\n    #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\n    tmpArray1=()\n    tmpArray2=()\n    tmpArray3=()\n    tmpArray4=()\n    tmpArray5=()\n    tmpArray6=()\n    while read user dir; do\n        tmpArray1+=($dir)\n        if [[ ! -d $dir ]]; then\n            tmpArray2+=(\"false\")\n            tmpArray3+=(\"false\")\n            echo -e \"\\033[31m-[-] the home directory ($dir) of user $user does not exist \\033[0m\"\n\n        else\n            tmpArray2+=(\"true\")\n            # 7.2.5 check if users' home directories permissions are 750 or more restrictive\n            local dirperm=$(ls -ld $dir|cut -d\" \" -f1)\n            tmpArray3+=($dirperm)\n            if [[ $(echo $dirperm |cut -c6) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Group Write permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            if [[ $(echo $dirperm |cut -c8) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Read permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            if [[ $(echo $dirperm |cut -c9) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Write permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            if [[ $(echo $dirperm |cut -c10) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Execute permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            # 7.2.6 check if is users own their home directory\n            local owner=$(stat -L -c \"%U\" $dir)\n            if [[ $owner != $user ]]; then\n                tmpArray4+=(\"false\")\n                echo -e \"\\033[31m-[-]The home directory ($dir) of user $user is owned by $owner \\033[0m\"\n            else\n                tmpArray4+=(\"true\")\n            fi\n            # 7.2.7 check users' dot files are not group or world  writable\n            local tmpc=0\n            for file in $dir/.[A-Za-z0-9]*; do\n                if [[ ! -h $file ]] && [[ -f $file ]]; then\n                    local fileperm=$(ls -ld $file|cut -d\" \" -f1)\n                    if [[ $(echo $fileperm|cut -c6) != \"-\" ]]; then\n                        tmpc=$(expr $tmpc + 1)\n                        echo -e \"\\033[31m-[-] Group Write permission set on file $file \\033[0m\"\n                    fi\n                    if [[ $(echo $fileperm|cut -c9) != \"-\" ]]; then\n                        tmpc=$(expr $tmpc + 1)\n                        echo -e \"\\033[31m-[-] Other Write permission set on file $file \\033[0m\"\n                    fi\n                fi\n            done\n            if [[ $tmpc = 0 ]]; then\n                tmpArray5+=(\"true\")\n            else\n                tmpArray5+=(\"false\")\n            fi\n            # 7.2.8 check if no usrs have .netrc .rhosts .forward file\n            tmpc=0\n            if [[ ! -h $dir/.netrc ]] && [[ -f $dir/.netrc ]]; then\n                tmpc=$(expr $tmpc + 1)\n                echo -e \"\\033[31m-[-] .netrc file $dir/.netrc exists \\033[0m\"\n            fi\n            if [[ ! -h $dir/.rhosts ]] && [[ -f $dir/.rhosts ]]; then\n                tmpc=$(expr $tmpc + 1)\n                echo -e \"\\033[31m-[-] .rhosts file $dir/.rhosts exists \\033[0m\"\n            fi\n            if [[ ! -h $dir/.forward ]] && [[ -f $dir/.forward ]]; then\n                tmpc=$(expr $tmpc + 1)\n                echo -e \"\\033[31m-[-] .forward file $dir/.forward exists \\033[0m\"\n            fi\n            if [[ $tmpc = 0 ]]; then\n                tmpArray6+=(\"true\")\n            else\n                tmpArray6+=(\"false\")\n            fi\n        fi\n    done < <(cat /etc/passwd|egrep -v '^(root|halt|sync|shutdown)'|awk -F: '($7 != \"/sbin/nologin\" && $7 != \"/bin/false\"){print $1 \" \" $6}')\n    userArray=${tmpArray1[@]}\n    userHomeDirIfExistArray=${tmpArray2[@]}\n    UserHomeDirPermissionArray=${tmpArray3[@]}\n    userIfOwnTheirHomeDirArray=${tmpArray4[@]}\n    userHomeDirIfHasGWorOWDotFileArray=${tmpArray5[@]}\n    userHomeDirIfHasOtherFileArray=${tmpArray6[@]}\n    # 7.2.9 check if all groups in /etc/passwd exist in /etc/group\n    tmpArray=()\n    for i in $(cut -d: -s -f4 /etc/passwd|sort -u); do\n        grep -q -P \"^.*?:[^:]*:$i\" /etc/group\n        if [[ $? -ne 0 ]]; then\n        tmpArray+=($i)\n            echo -e \"\\033[31m-[-] Group $i is referenced by /etc/passwd but does not exist in /etc/group \\033[0m\"\n        fi\n    done\n    groupNotExistInetcgroup=${tmpArray[@]}\n    # 7.2.10 check if every user has a unique UID\n    #cat /etc/passwd|cut -d\":\" -f3|sort -n|uniq -c|while read x; do\n    tmpArray=()\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x\n        if [[ $1 -gt 1 ]]; then\n            local users=$(awk -F: '($3==n){print $1}' n=$2 /etc/passwd|xargs)\n            tmpArray+=($2:$users\\;)\n            echo -e \"\\033[31m-[-] Duplicate UID $2 : $users \\033[0m\"\n        fi\n    done < <(cat /etc/passwd|cut -d\":\" -f3|sort -n|uniq -c)\n    usersIfHasUniqueUIDArray=${tmpArray[@]}\n    # 7.2.11 check if every group has a unique GID\n    tmpArray=()\n    #cat /etc/group|cut -d\":\" -f3|sort -n|uniq -c|while read x; do\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x\n        if [[ $1 -gt 1 ]]; then\n            local groups=$(awk -F: '($3==n){print $1}' n=$2 /etc/group|xargs)\n            tmpArray+=($2:$groups\\;)\n            echo -e \"\\033[31m-[-] Duplicate GID $2 : $groups \\033[0m\"\n        fi\n    done < <(cat /etc/group|cut -d\":\" -f3|sort -n|uniq -c)\n    groupsIfHasUniqueGIDArray=${tmpArray[@]}\n    # 7.2.12 check if user name is unique\n    tmpArray=()\n    #cat /etc/passwd|cut -d\":\" -f1|sort -n|uniq -c|while read x; do\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x11\n        if [[ $1 -gt 1 ]]; then\n            local uids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/passwd|xargs)\n            tmpArray+=($2:$uids\\;)\n            echo -e \"\\033[31m-[-] Duplicate user name $2 : $uids \\033[0m\"\n        fi\n    done < <(cat /etc/passwd|cut -d\":\" -f1|sort -n|uniq -c)\n    usersIfHasUniqueNameArray=${tmpArray[@]}\n    # 7.2.13 check if group name is unique\n    tmpArray=()\n    #cat /etc/group|cut -d\":\" -f1|sort -n|uniq -c|while read x; do\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x11\n        if [[ $1 -gt 1 ]]; then\n            local gids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/group|xargs)\n            tmpArray+=($2:$gids\\;)\n            echo -e \"\\033[31m-[-] Duplicate group name $2 : $gids \\033[0m\"\n        fi\n    done < <(cat /etc/group|cut -d\":\" -f1|sort -n|uniq -c)\n    groupsIfHasUniqueNameArray=${tmpArray[@]}\n    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\\\"}\n    system_check_res={\\\"file_permission_info\\\":$file_permission_info,\\\"usergroup_config_info\\\":$usergroup_config_info}\n\n}\n\necho \"\"\"\n==================================\n|        Linux 基线检查工具      |\n|        author:JC0o0l           |\n|        version:1.0             |\n==================================\n\"\"\"\nget_basic_info\ninit_check\nservice_check\nnetwork_check\nauditd_check\nlog_check\nauthentication_check\nsystem_check\nif [[ -z $authentication_check_res ]]; then\n    authentication_check_res={}\nfi\nif [[ -z $system_check_res ]]; then\n    system_check_res={}\nfi\ncheck_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}\n#curl -X POST \"https://httpbin.org/post\" -H \"accept:application/json\" -H \"content-type:application/json\" -d \"$check_result\"\necho $check_result\necho $check_result|jq "
  },
  {
    "path": "linux_baseline_check.sh",
    "content": "#!/bin/bash\nfunction get_ip_info {\n    local ipList=`ifconfig | grep inet |grep -v inet6|grep -v 127|sed 's/^[ ]*//g'|cut -d\" \" -f2`\n    echo $ipList\n}\nfunction get_basic_info {\n    echo [·] collect basic info\n    scanTime=$(date \"+%Y-%m-%d %H:%M:%S\")\n    hostname=`hostname`\n    macaddr=$(echo $(ifconfig|grep \"ether\"|sed 's/^[ ]*//g'|cut -d\" \" -f2)|sed 's/ /;/g')\n    ipList=$(get_ip_info|sed 's/ /;/g')\n    kernelVersion=`uname -r`\n    if [[ $(cat /proc/version) =~ \"Red Hat\" ]]; then\n        osVersion=`cat /etc/redhat-release|cut -f1,4 -d\" \"`\n    fi\n    basic_info={\\\"scanTime\\\":\\\"$scanTime\\\",\\\"hostname\\\":\\\"$hostname\\\",\\\"macaddr\\\":\\\"$macaddr\\\",\\\"ipList\\\":\\\"$ipList\\\",\\\"kernelVersion\\\":\\\"$kernelVersion\\\",\\\"osVersion\\\":\\\"$osVersion\\\"}\n    echo $basic_info\n}\n\nfunction init_check {\n    # 1. init configuration\n    echo [·] check init configuration\n    # 1.1 file system configuration\n    # 1.1.1 /tmp separate mount\n    local tmpIfSeparate #=\"\"\n    local tmpIfNoexec #=\"\"\n    local tmpIfNosuid #=\"\"\n    local res=$(mount|grep \"/tmp \") \n    if [[ -z $res ]]; then\n        echo -e \"\\033[31m-[-] /tmp/ not mounted on separate dick\\033[0m\"\n        tmpIfSeparate=\"False\"\n        tmpIfNoexec=\"False\"\n        tmpIfNosuid=\"False\"\n    else\n        tmpIfSeparate=\"True\"\n        tmpIfNoexec=\"True\"\n        tmpIfNosuid=\"True\"\n    fi\n    if [[ $tmpIfSeparate == \"True\" ]]; then\n        #mount|grep \"/sys/kernel/debug \" |while read res;do\n        while read res;do\n            #echo \"mount | grep /sys --result-->\" $res\n            # 1.1.2 /tmp noexec nosuid\n            local diskPart=$(echo $res|cut -d\" \" -f3)\n            if [[ ! $res =~ \"noexec\" ]];then\n                echo -e \"\\033[31m-[-] no noexec option on $diskPart partion\\033[0m\"\n                tmpIfNoexec=\"False\"\n                if [[ ! $res =~ \"nosuid\" ]];then\n                    echo -e \"\\033[31m-[-] no nosuid option on $diskPart partion\\033[0m\"\n                    tmpIfNosuid=\"False\"\n                fi\n            elif [[ ! $res =~ \"nosuid\" ]];then\n                echo -e \"\\033[31m-[-] no nosuid option on $diskPart partion\\033[0m\"\n                tmpIfNosuid=\"False\"\n            fi\n        done < <(mount | grep \"/tmp \")\n    fi\n    tmp_partition_info={\\\"tmpIfSeparate\\\":\\\"$tmpIfSeparate\\\",\\\"tmpIfNoexec\\\":\\\"$tmpIfNoexec\\\",\\\"tmpIfNosuid\\\":\\\"$tmpIfNosuid\\\"}\n    #echo $tmp_partition_info\n    # 1.2 secure boot configuration\n    if [[ -f /boot/grub2/grub.cfg ]];then\n        grubcfgIfExist=\"True\"\n        grubcfgPermission=\"0600\"\n        grubcfgIfSetPasswd=\"True\"\n    else\n        grubcfgIfExist=\"False\"\n        grubcfgPermission=\"0000\"\n        grubcfgIfSetPasswd=\"False\"\n    fi\n    if [[ $grubcfgIfExist == \"True\" ]]; then\n        # 1.2.1 /boot/grub2/grub.cfg permission /boot/grub2/user.cfg permission 0600 root:root\n        res=$(stat /boot/grub2/grub.cfg |while read x;do if [[ $x =~ \"Uid\" ]] && [[ $x =~ \"(\" ]]; then echo $x;fi;done|cut -d\"(\" -f2,3,4)\n        grubcfgPermission=$(echo $res|cut -d\"/\" -f1)\n        if [[ $(echo $res|cut -d\"/\" -f1) = \"0600\" ]]; then\n            echo -e \"\\033[32m-[+] /boot/grub2/grub.cfg permission is 0600 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] /boot/grub2/grub.cfg permission is not 0600 \\033[0m\"\n        fi\n        # 1.2.2 Ensure bootloader password is set\n        res=$(grep \"^GRUB2 PASSWORD\" /boot/grub2/grub.cfg)\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m-[+] /boot/grub2/grub.cfg seted password \\033[0m\"\n            grubcfgIfSetPasswd=\"True\"\n        else\n            echo -e \"\\033[31m-[-] /boot/grub2/grub.cfg not set password \\033[0m\"\n            grubcfgIfSetPasswd=\"False\"\n        fi\n    fi\n        \n    # 1.2.3 single user mode need authentication\n    if [[ -f /usr/lib/systemd/system/rescue.service ]] && [[ -f /usr/lib/systemd/system/emergency.service ]]; then\n        res1=`grep /sbin/sulogin /usr/lib/systemd/system/rescue.service`\n        res2=`grep /sbin/sulogin /usr/lib/systemd/system/emergency.service`\n        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\n            echo -e \"\\033[32m-[+] single user mode need authentication \\033[0m\"\n            singleUserModeIfNeedAuth=\"True\"\n        else\n            echo -e \"\\033[31m-[+] single user mode does not need authentication \\033[0m\"\n            singleUserModeIfNeedAuth=\"False\"\n        fi\n    fi\n    # 1.3 Mantary Access Control\n    # 1.3.1 ensure the SELinux state is enforcing\n    if [[ -f /etc/selinux/config ]]; then\n        local num=$(sestatus|grep -c enforcing)\n        if [[ $num -gt 1 ]]; then\n            echo -e \"\\033[32m-[+] SELinux state is enforcing \\033[0m\"\n            selinuxStateIfEnforcing=\"True\"\n        else\n            echo -e \"\\033[31m-[-] SELinux state is not enforcing \\033[0m\"\n            selinuxStateIfEnforcing=\"False\"\n        fi\n    fi\n    # 1.3.2 ensure selinux policy is configured\n    if [[ -f /etc/selinux/config ]]; then\n        res=$(sestatus|grep targeted)\n        if [[ -n $res ]]; then\n            echo -e \"\\033[32m-[+] SELinux policy is configured \\033[0m\"\n            selinuxPolicyIfConfigured=\"True\"\n        else\n            echo -e \"\\033[31m-[-] SELinux policy is not configure to targeted \\033[0m\"\n            selinuxPolicyIfConfigured=\"False\"\n        fi\n    fi\n    boot_secure_info={\\\"grubcfgIfExist\\\":\\\"$grubcfgIfExist\\\",\\\"grubcfgPermission\\\":\\\"$grubcfgPermission\\\",\\\"grubcfgIfSetPasswd\\\":\\\"$grubcfgIfSetPasswd\\\",\\\"singleUserModeIfNeedAuth\\\":\\\"$singleUserModeIfNeedAuth\\\",\\\"selinuxStateIfEnforcing\\\":\\\"$selinuxStateIfEnforcing\\\",\\\"selinuxPolicyIfConfigured\\\":\\\"$selinuxPolicyIfConfigured\\\"}\n    #echo $boot_secure_info\n    init_check_res={\\\"tmp_partition_info\\\":$tmp_partition_info,\\\"boot_secure_info\\\":$boot_secure_info}\n}\nfunction service_check {\n    # 2. service configuration\n    echo [·] check service configuration\n    # 2.1 time sync\n    # 2.1.1 time sync service is installed\n    if $(rpm -q ntp 1>/dev/null||rpm -q chrony 1>/dev/null) ; then\n        if $(rpm -q ntp 1>/dev/null) ; then\n            if [[ -f /etc/ntp.conf ]]; then\n                local res=$(egrep \"^(server|pool)\" /etc/ntp.conf)\n                if [[ -n $res ]]; then\n                    echo -e \"\\033[32m-[+] remote ntp server is configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"True\"\n                else\n                    echo -e \"\\033[31m-[-] remote ntp server is not configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"False\"\n                fi\n            fi\n        fi\n        if $(rpm -q chrony 1>/dev/null); then\n            if [[ -f /etc/chrony.conf ]]; then\n                local res=$(egrep \"^(server|pool)\" /etc/chrony.conf)\n                if [[ -n $res ]]; then\n                    echo -e \"\\033[32m-[+] remote chrony server is configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"True\"\n                else\n                    echo -e \"\\033[31m-[-] remote chrony server is not configured \\033[0m\"\n                    timeSyncServerIfConfigured=\"False\"\n                fi\n                \n            fi\n        fi\n    fi        \n    # 2.1.2 x-window\n    local res=$(rpm -qa xorg-x11*)\n    if [[ -z $res ]]; then\n        echo -e \"\\033[32m-[+] x11-windows is not installed \\033[0m\"\n        x11windowIfNotInstalled=\"True\"\n    else\n        echo -e \"\\033[31m-[-] x11-windows is installed \\033[0m\"\n        x11windowIfNotInstalled=\"False\"\n    fi\n    service_check_res={\\\"timeSyncServerIfConfigured\\\":\\\"$timeSyncServerIfConfigured\\\",\\\"x11windowIfNotInstalled\\\":\\\"$x11windowIfNotInstalled\\\"}\n}\nfunction network_check {\n    # 3. network configuration\n    echo [·] check network configuration\n    # 3.1 hosts file configuration\n    # 3.1.1 check /etc/hosts.deny file\n    if [[ -f /etc/hosts.deny ]]; then\n        hostsDenyFileIfExist=\"True\"\n        echo -e \"\\033[32m-[+] file /etc/hosts.deny exists \\033[0m\"\n        local res=$(stat /etc/hosts.deny |while read x;do if [[ $x =~ \"Uid\" ]] && [[ $x =~ \"(\" ]]; then echo $x;fi;done|cut -d\"(\" -f2,3,4)\n        hostsDenyFilePermission=$(echo $res|cut -d\"/\" -f1)\n        if [[ $(echo $res|cut -d\"/\" -f1) = \"0644\" ]];then\n            echo -e \"\\033[32m-[+] file /etc/hosts.deny permission is 0644 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file /etc/hosts.deny permission is not 0644 \\033[0m\"\n        fi\n\n        local res=$(egrep \"^[^#].+\" /etc/hosts.deny)\n        if [[ -n $res ]]; then\n            hostsDenyFileIfConfigured=\"True\"\n            echo -e \"\\033[32m-[+] file /etc/hosts.deny is configured \\033[0m\"\n        else\n            hostsDenyFileIfConfigured=\"False\"\n            echo -e \"\\033[31m-[-] file /etc/hosts.deny is not configured \\033[0m\"\n        fi\n    else\n        hostsDenyFileIfExist=\"False\"\n        echo -e \"\\033[31m-[-] file /etc/hosts.deny does not exists \\033[0m\"\n    fi\n    # 3.1.2 check /etc/hosts.allow file\n    if [[ -f /etc/hosts.allow ]]; then\n        hostsAllowFileIfExist=\"True\"\n        echo -e \"\\033[32m-[+] file /etc/hosts.allow exists \\033[0m\"\n        local res=`stat /etc/hosts.allow |while read x;do if [[ $x =~ \"Uid\" ]] && [[ $x =~ \"(\" ]]; then echo $x;fi;done|cut -d\"(\" -f2,3,4`\n        hostsAllowFilePermission=$(echo $res|cut -d\"/\" -f1)\n        if [[ $(echo $res|cut -d\"/\" -f1) = \"0644\" ]];then\n            echo -e \"\\033[32m-[+] file /etc/hosts.allow permission is 0644 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file /etc/hosts.allow permission is not 0644 \\033[0m\"\n        fi\n\n        local res=$(egrep \"^[^#].+\" /etc/hosts.deny)\n        if [[ -n $res ]]; then\n            hostsAllowFileIfConfigured=\"True\"\n            echo -e \"\\033[32m-[+] file /etc/hosts.allow is configured \\033[0m\"\n        else\n            hostsAllowFileIfConfigured=\"False\"\n            echo -e \"\\033[31m-[-] file /etc/hosts.allow is not configured \\033[0m\"\n        fi\n    else\n        hostsAllowFileIfExist=\"False\"\n        echo -e \"\\033[31m-[-] file /etc/hosts.allow does not exists \\033[0m\"\n    fi\n\n    # 3.2 firewall configuration\n    # 3.2.1 ensure iptables is installed\n    if $(rpm -q iptables 1>/dev/null); then\n        iptablesIfInstalled=\"True\"\n        echo -e \"\\033[32m-[+] iptables is installed \\033[0m\"\n        # 3.2.2 ensure INPUT OUTPUT chain policy is DROP\n        #iptables -L|grep policy|while read x;do\n        while read x;do\n            if [[ $x =~ \"INPUT\" ]] && [[ $x =~ \"DROP\" ]]; then\n                iptablesInputPolicyIfDrop=\"True\"\n                echo -e \"\\033[32m-[+] INPUT chain policy is DROP \\033[0m\"\n            elif [[ $x =~ \"INPUT\" ]] && [[ ! $x =~ \"DROP\" ]]; then\n                iptablesInputPolicyIfDrop=\"False\"\n                echo -e \"\\033[31m-[-] INPUT chain policy is not DROP \\033[0m\"\n            fi\n            if [[ $x =~ \"OUTPUT\" ]] && [[ $x =~ \"DROP\" ]]; then\n                iptablesOutputPolicyIfDrop=\"True\"\n                echo -e \"\\033[32m-[+] OUTPUT chain policy is DROP \\033[0m\"\n            elif [[ $x =~ \"OUTPUT\" ]] && [[ ! $x =~ \"DROP\" ]]; then\n                iptablesOutputPolicyIfDrop=\"False\"\n                echo -e \"\\033[31m-[-] OUTPUT chain policy is not DROP \\033[0m\"\n            fi\n        done < <(iptables -L|grep policy)\n    else\n        iptablesIfInstalled=\"False\"\n        echo -e \"\\033[31m-[-] iptables is not installed \\033[0m\"\n    fi\n    network_check_res={\\\"hostsAllowFileIfExist\\\":\\\"$hostsAllowFileIfExist\\\",\\\"hostsAllowFilePermission\\\":\\\"$hostsAllowFilePermission\\\",\\\"hostsAllowFileIfConfigured\\\":\\\"$hostsAllowFileIfConfigured\\\",\\\"hostsDenyFileIfExist\\\":\\\"$hostsDenyFileIfExist\\\",\\\"hostsDenyFilePermission\\\":\\\"$hostsDenyFilePermission\\\",\\\"hostsDenyFileIfConfigured\\\":\\\"$hostsDenyFileIfConfigured\\\",\\\"iptablesIfInstalled\\\":\\\"$iptablesIfInstalled\\\",\\\"iptablesInputPolicyIfDrop\\\":\\\"$iptablesInputPolicyIfDrop\\\",\\\"iptablesOutputPolicyIfDrop\\\":\\\"$iptablesOutputPolicyIfDrop\\\"}\n}\n\nfunction auditd_check {\n\t# 4. auditd configuration\n\techo [·] check auditd configuration\n\t# 4.1 ensure auditd is enabled\n    echo \"-[·] check auditd if is enabled\"\n\tif [[ $(systemctl is-enabled auditd) = \"enabled\" ]]; then\n\t\techo -e \"\\033[32m-[+] auditd is enabled \\033[0m\"\n        auditdIfEnabled=\"True\"\n\telse\n        auditdIfEnabled=\"False\"\n\t\techo -e \"\\033[31m-[-] auditd is not enabled \\033[0m\"\n\tfi\n\t# 4.2 some settings in /etc/audit/auditd.conf\n    echo \"-[·] settings in /etc/audit/auditd.conf\"\t\n    if [[ -f /etc/audit/auditd.conf ]]; then\n        auditdconfIfExist=\"True\"\n        maxLogFile=$(grep \"^max_log_file[[:blank:]]=\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        maxLogFileAction=$(grep \"^max_log_file_action\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        spaceLeftAction=$(grep \"^space_left_action\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        numLogs=$(grep \"^num_logs\" /etc/audit/auditd.conf|sed \"s/ //g\"|cut -d\"=\" -f 2)\n        if [[ -n $maxLogFile ]]; then\n            auditdIfSetMaxLogFile=$maxLogFile\n            echo -e \"\\033[32m-[+] max_log_file size is ${maxLogFile} M \\033[0m\"\n        else\n            auditdIfSetMaxLogFile=\"False\"\n            echo -e \"\\033[31m-[-] max_log_file size is not setted \\033[0m\"\n        fi\n        if [[ -n $maxLogFileAction ]]; then\n            auditdIfSetMaxLogFileAction=\"$maxLogFileAction\"\n            echo -e \"\\033[32m-[+] max_log_file_action is ${maxLogFileAction}\\033[0m\"\n        else\n            auditdIfSetMaxLogFileAction=\"False\"\n            echo -e \"\\033[31m-[-] max_log_file_action is not setted \\033[0m\"\n        fi\n        if [[ -n $spaceLeftAction ]]; then\n            auditdIfSetSpaceLeftAction=\"$spaceLeftAction\"\n            echo -e \"\\033[32m-[+] space_left_action is ${spaceLeftAction}\\033[0m\"\n        else\n            auditdIfSetSpaceLeftAction=\"False\"\n            echo -e \"\\033[31m-[-] space_left_action is not setted \\033[0m\"\n        fi\n        if [[ -n $numLogs ]]; then\n            auditdIfSetNumLogs=\"$numLogs\"\n            echo -e \"\\033[32m-[+] the num of logs is ${numLogs} \\033[0m\"\n        else\n            auditdIfSetNumLogs=\"False\"\n            echo -e \"\\033[31m-[-] num_logs is not setted \\033[0m\"\n        fi\n    else\n        auditdconfIfExist=\"False\"\n    fi\n    auditd_config_info={\\\"auditdIfEnabled\\\":\\\"$auditdIfEnabled\\\",\\\"auditdconfIfExist\\\":\\\"$auditdconfIfExist\\\",\\\"auditdIfSetMaxLogFile\\\":\\\"$auditdIfSetMaxLogFile\\\",\\\"auditdIfSetMaxLogFileAction\\\":\\\"$auditdIfSetMaxLogFileAction\\\",\\\"auditdIfSetSpaceLeftAction\\\":\\\"$auditdIfSetSpaceLeftAction\\\",\\\"auditdIfSetNumLogs\\\":\\\"$auditdIfSetNumLogs\\\"}\n    #echo $auditd_config_info\n    # 4.3 rules in /etc/audit/audit.rules\n    # arch 64\n    echo \"-[·] time-change\" \n    if [[ -f /etc/audit/audit.rules ]]; then\n        auditdRulesIfExist=\"True\"\n        echo -e \"\\033[32m-[+] /etc/audit/audit.rules is exist \\033[0m\"\n        if [[ ! -n $(grep time /etc/audit/audit.rules) ]]; then\n            auditdRulesIfNotNull=\"False\"\n            echo -e \"\\033[31m-[-] not set rule about audit the change of date and time \\033[0m\"\n        else\n            auditdRulesIfNotNull=\"True\"\n            # 4.3.1 time-change\n            local timeChangeList=$(egrep \"(stime|clock_settime|adjtimex|settimeofday|/etc/localtime)\" /etc/audit/audit.rules|wc -l)\n            if [[ ${timeChangeList} -gt 3 ]]; then\n                auditdIfCheckTimechange=\"True\"\n                echo -e \"\\033[32m-[+] audith the change of date and time \\033[0m\"\n            elif [[ ${timeChangeList} -gt 1 ]]; then\n                auditdIfCheckTimechange=\"False\"\n                echo -e \"\\033[31m-[-] not fully set rule about audit the change of date and time \\033[0m\"\n            else \n                auditdIfCheckTimechange=\"False\"\n                echo -e \"\\033[31m-[-] not set rule about audit the change of date and time \\033[0m\"\n            fi\n            # 4.3.2 user and group change\n            echo \"-[·] user and group change\"\n            local keyArray=(\"/etc/passwd\" \"/etc/group\" \"/etc/gshadow\" \"/etc/shadow\" \"/etc/security/opasswd\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    echo -e \"\\033[32m-[+] audit the change of $i \\033[0m\"\n                else\n                    tmpArray2+=($i\\;)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedUserandgroupfile=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedUserandgroupfile=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.3 system's network environment change\n            echo \"-[·] system's network environment change\"\n            local keyArray=(\"/etc/issue\" \"/etc/issue.net\" \"/etc/hosts\" \"/etc/sysconfig/network\" \"/etc/sysconfig/network-scripts/\" )\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                    if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    echo -e \"\\033[32m-[+] audit the change of $i \\033[0m\"\n                else\n                    tmpArray2+=($i\\;)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            local keyArray=(\"sethostname\" \"setdomainname\")\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    echo -e \"\\033[32m-[+] audit the use of syscall  $i \\033[0m\"\n                else\n                    echo -e \"\\033[31m-[-] not audit the use of syscall $i \\033[0m\"\n                    tmpArray2+=($i\\;)\n                fi\n            done\n            auditdRulesCheckedNetworkenv=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedNetworkenv=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.4 system's Mandatory Access Controls change\n            echo \"-[·] system's Mandatory Access Controls change\"\n            local keyArray=(\"/etc/selinux\" \"/usr/share/selinux\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    echo -e \"\\033[32m-[+] audit the change of   $i \\033[0m\"\n                else\n                    tmpArray2+=($i\\;)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedMACchange=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedMACchange=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.5 audit events of login and logout\n            echo \"-[·] audit events of login and logout\"\n            local keyArray=(\"/var/log/lastlog\" \"/var/run/faillock/\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(grep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    echo -e \"\\033[32m-[+] audit the change of   $i \\033[0m\"\n                else\n                    tmpArray2+=($i\\;)\n                    echo -e \"\\033[31m-[-] not audit the change of $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedLoginoutEvents=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedLoginoutEvents=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.6 audit the change of discretionary access control\n            echo \"-[·] audit the change of discretionary access control\"\n            local keyArray=(\"(chmod|fchmod|fchmodat)\" \"(chown|fchown|fchownat)\" \"(setxattr|lsetxattr|removexattr)\" \"(lock|time)\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')\n                    echo -e \"\\033[32m-[+] audit the use of systemcall  $i \\033[0m\"\n                    tmpArray1+=($i\\;)\n                else\n                    tmpArray2+=($i\\;)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g')\n                    echo -e \"\\033[31m-[-] not audit the use of systemcall $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedDACChangeSyscall=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedDACChangeSyscall=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.7 audit the events of unsuccessful unauthorized file access attempts\n            echo \"-[·] audit the events of unsuccessful unauthorized file access attempts\"\n            local keyArray=(\"(create|open|openat|truncate|ftruncate).*?exit=-EACCESS\" \"(create|open|openat|truncate|ftruncate).*?exit=-EPERM\" )\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[32m-[+] audit the use of systemcall  $i \\033[0m\"\n                else\n                    tmpArray2+=($i\\;)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[31m-[-] not audit the use of systemcall $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedFileAccessAttemptSyscall=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedFileAccessAttemptSyscall=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.8 audit the use of privileged commands\n            echo \"-[·] audit the use of privileged commands\"\n            #find / -name \"passwd\"\n            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\"}'\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${res[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[32m-[+] audit the use of command  $i \\033[0m\"\n                else\n                    tmpArray2+=($i\\;)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[31m-[-] not audit the use of command $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedPrivilegedCommand=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedPrivilegedCommand=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.9 audit the change of file sudoer\n            echo \"-[·] audit the change of file sudoer\"\n            local keyArray=(\"/etc/sudoers\" \"/etc/sudoers.d/\")\n            tmpArray1=()\n            tmpArray2=()\n            for i in ${keyArray[@]} ; do\n                if [[ -n $(egrep $i /etc/audit/audit.rules) ]]; then\n                    tmpArray1+=($i\\;)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[32m-[+] audit the change of file  $i \\033[0m\"\n                else\n                    tmpArray2+=($i\\;)\n                    i=$(echo $i|sed 's/|/ /g'|sed 's/(//g'|sed 's/)//g'|sed 's/\\.\\*?/ /g')\n                    echo -e \"\\033[31m-[-] not audit the change of file $i \\033[0m\"\n                fi\n            done\n            auditdRulesCheckedSudoerFile=$(echo ${tmpArray1[@]}|sed 's/ //g')\n            auditdRulesNotCheckedSudoerFile=$(echo ${tmpArray2[@]}|sed 's/ //g')\n            # 4.3.10 check the audit configuration is setted to immutable unless reboot the server\n            echo \"-[·] check the audit configuration is setted to immutable unless reboot the server\"\n            local res=$(grep \"^\\s*[^#]\" /etc/audit/audit.rules|tail -1|egrep \"-e.*?2\")\n            if [[ -n $res ]]; then\n                auditdRulesIfImmutable=\"True\"\n                echo -e \"\\033[32m-[+] auditd setted -e 2 \\033[0m\"\n            else\n                auditdRulesIfImmutable=\"False\"\n                echo -e \"\\033[31m-[-] auditd not setted -e 2 \\033[0m\"\n            fi\n        fi\n    else\n        auditdRulesIfExist=\"False\"\n        echo -e \"\\033[32m-[+] /etc/audit/audit.rules is not exist \\033[0m\"\n    fi\n    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\\\"}\n    auditd_check_res={\\\"auditd_config_info\\\":$auditd_config_info,\\\"auditd_rules_info\\\":$auditd_rules_info}\n}\n\nfunction log_check {\n    echo \"[·] check log configuration\"\n\t# 5.1 ensure auditd is enabled\n    echo \"-[·] check rsyslog if is enabled\"\n\tif [[ $(systemctl is-enabled rsyslog) = \"enabled\" ]]; then\n        rsyslogIfEnabled=\"True\"\n\t\techo -e \"\\033[32m-[+] rsyslog is enabled \\033[0m\"\n\telse\n        rsyslogIfEnabled=\"False\"\n\t\techo -e \"\\033[31m-[-] rsyslog is not enabled \\033[0m\"\n\tfi\n    \n    log_check_res={\\\"rsyslogIfEnabled\\\":\\\"$rsyslogIfEnabled\\\"}\n\n}\n\nfunction authentication_check {\n    echo \"[·] check cron ssh pam and env configuration\"\n    # 6.1 cron configuration\n    echo \"-[·] check cron configuration\"\n    # 6.1.1 check cron service is enabled\n    echo \"-[·] check crond if is enabled\"\n\tif [[ $(systemctl is-enabled crond) = \"enabled\" ]]; then\n\t\techo -e \"\\033[32m-[+] crond is enabled \\033[0m\"\n        crondIfEnabled=\"True\"\n\telse\n        crondIfEnabled=\"False\"\n\t\techo -e \"\\033[31m-[-] crond is not enabled \\033[0m\"\n\tfi\n    # 6.1.2 check cron's configuration file permission\n    echo \"-[·] check cron's configuration file permission\"\n    local keyArray=(\"/etc/crontab\" \"/etc/cron.hourly\" \"/etc/cron.daily\" \"/etc/cron.weekly\" \"/etc/cron.monthly\" \"/etc/cron.d\")\n    crondConfigFilenameArray=$(echo ${keyArray[@]}|sed 's/ /;/g')\n    tmpArray=()\n    for i in ${keyArray[@]} ; do\n        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)\n        tmpArray+=($res\\;)\n        if [[ $res = \"0600\" ]] || [[ $res = \"0700\" ]]; then\n            echo -e \"\\033[32m-[+] file $i's permission is $res \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \\033[0m\"\n        fi\n    done\n    crondConfigFilePermissionArray=$(echo ${tmpArray[@]}|sed 's/ //g')\n    # 6.1.3 check cron.allow cron.deny permission and owner\n    echo \"-[·] check cron.allow cron.deny configuration file permission\"\n    local keyArray=(\"/etc/cron.allow\" \"/etc/cron.deny\")\n    crondallowdenyFilenameArray=$(echo ${keyArray[@]}|sed 's/ /;/g')\n    tmpArray1=()\n    tmpArray2=()\n    tmpArray3=()\n    for i in ${keyArray[@]} ; do\n        if [[ ! -f $i ]]; then\n            tmpArray1+=(\"False;\")\n            tmpArray2+=(\"False;\")\n            tmpArray3+=(\"False;\")\n            echo -e \"\\033[31m-[-] file $i not exist \\033[0m\"\n            continue\n        else\n            tmpArray1+=(\"True;\")\n        fi\n        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)\n        tmpArray2+=($res1\\;)\n        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)\n        tmpArray3+=($res2\\;)\n        if [[ $res1 = \"0600\" ]] || [[ $res1 = \"0700\" ]]; then\n            echo -e \"\\033[32m-[+] file $i's permission is $res \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $i's permission is $res ,not 0600 or 0700 \\033[0m\"\n        fi\n        if [[ $res2 = \"root root\" ]]; then\n            echo -e \"\\033[32m-[+] file $i's owner is $res2 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $i's owner is not root \\033[0m\"\n        fi\n    done\n    crondallowdenyFileIfExistArray=$(echo ${tmpArray1[@]}|sed 's/ //g')\n    crondallowdenyFilePermissionArray=$(echo ${tmpArray2[@]}|sed 's/ //g')\n    crondallowdenyFileOwnerArray=$(echo ${tmpArray3[@]}|sed 's/; /;/g')\n    crond_config_info={\\\"crondIfEnabled\\\":\\\"$crondIfEnabled\\\",\\\"crondConfigFilenameArray\\\":\\\"$crondConfigFilenameArray\\\",\\\"crondConfigFilePermissionArray\\\":\\\"$crondConfigFilePermissionArray\\\",\\\"crondallowdenyFilenameArray\\\":\\\"$crondallowdenyFilenameArray\\\",\\\"crondallowdenyFileIfExistArray\\\":\\\"$crondallowdenyFileIfExistArray\\\",\\\"crondallowdenyFilePermissionArray\\\":\\\"$crondallowdenyFilePermissionArray\\\",\\\"crondallowdenyFileOwnerArray\\\":\\\"$crondallowdenyFileOwnerArray\\\"}\n    # 6.2 SSH configuration\n    echo \"-[·] check ssh configuration\"\n\tif [[ $(systemctl is-enabled sshd) = \"enabled\" ]]; then\n        sshdIfEnabled=\"True\"\n        # 6.2.1 /etc/ssh/sshd_config permission 0600\n        local file=\"/etc/ssh/sshd_config\"\n        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)\n        if [[ $res = \"0600\" ]]; then\n            sshdConfigFilePermission=$res\n            echo -e \"\\033[32m-[+] file $file's access permission is $res \\033[0m\"\n        else\n            sshdConfigFilePermission=\"False\"\n            echo -e \"\\033[3-m-[-] file $file's access permission is $res \\033[0m\"\n        fi\n        # 6.2.2 check ssh x11 forwarding if is disabled\n        local res=$(grep \"^X11Forwaring\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisableX11forwarding=\"True\"\n            echo -e \"\\033[32m-[+] X11Forwarding no \\033[0m\"\n        else\n            sshdIfDisableX11forwarding=\"False\"\n            echo -e \"\\033[31m-[-] not set X11Forwarding no \\033[0m\"\n        fi\n        # 6.2.3 check ssh MaxAUTHTries if is 4\n        local res=$(grep \"^MaxAuthTries\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSetMaxAuthTries=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\\2/')\n            echo -e \"\\033[32m-[+] $res \\033[0m\"\n        else\n            sshdIfSetMaxAuthTries=\"False\"\n            echo -e \"\\033[31m-[-] not set MaxAuthTries \\033[0m\"\n        fi\n        # 6.2.4 check ssh IgnoreRhosts if is enabled\n        local res=$(grep \"^IgnoreRhosts\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep yes) ]]; then\n            sshdIfEnableIgnoreRhosts=\"True\"\n            echo -e \"\\033[32m-[+] IgnoreRhosts yes \\033[0m\"\n        else\n            sshdIfEnableIgnoreRhosts=\"False\"\n            echo -e \"\\033[31m-[-] not set IgnoreRhosts no\\033[0m\"\n        fi\n        # 6.2.5 check ssh HostbasedAuthentication if is disabled\n        local res=$(grep \"^HostbasedAuthentication\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisableHostbasedAuthentication=\"True\"\n            echo -e \"\\033[32m-[+] HostbasedAuthentication no \\033[0m\"\n        else\n            sshdIfDisableHostbasedAuthentication=\"False\"\n            echo -e \"\\033[31m-[-] not set HostbasedAuthentication no\\033[0m\"\n        fi\n        # 6.2.6 check ssh root login if is diabled\n        local res=$(grep \"^PermitRootLogin\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisablePermitRootLogin=\"True\"\n            echo -e \"\\033[32m-[+] PermitRootLogin no \\033[0m\"\n        else\n            sshdIfDisablePermitRootLogin=\"False\"\n            echo -e \"\\033[31m-[-] not set PermitRootLogin no\\033[0m\"\n        fi\n        # 6.2.7 check ssh PermitEmptyPasswords if is diabled\n        local res=$(grep \"^PermitEmptyPasswords\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisablePermitEmptyPasswords=\"True\"\n            echo -e \"\\033[32m-[+] PermitEmptyPasswords no \\033[0m\"\n        else\n            sshdIfDisablePermitEmptyPasswords=\"False\"\n            echo -e \"\\033[31m-[-] not set PermitEmptyPasswords no\\033[0m\"\n        fi\n        # 6.2.8 check ssh PermitUserEnvironment if is diabled\n        local res=$(grep \"^PermitUserEnvironment\" /etc/ssh/sshd_config)\n        if [[ -n $(echo $res|grep no) ]]; then\n            sshdIfDisablePermitUserEnvironment=\"True\"\n            echo -e \"\\033[32m-[+] PermitUserEnvironment no \\033[0m\"\n        else\n            sshdIfDisablePermitUserEnvironment=\"False\"\n            echo -e \"\\033[31m-[-] not set PermitUserEnvironment no\\033[0m\"\n        fi\n        # 6.2.9 check if set specific MAC algorithms\n        local res=$(grep \"^MACs\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSpecificMACs=\"True\"\n            echo -e \"\\033[32m-[+] will use specific MAC algorithms $res \\033[0m\"\n        else\n            sshdIfSpecificMACs=\"False\"\n            echo -e \"\\033[31m-[-] not set specific MAC algorithms\\033[0m\"\n        fi\n        # 6.2.10 check SSH idle Timeout Interval if is configured\n        local res=$(grep \"^ClientAliveInterval\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSetClientAliveInterval=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\\2/')\n            echo -e \"\\033[32m-[+] $res \\033[0m\"\n        else\n            sshdIfSetClientAliveInterval=\"False\"\n            echo -e \"\\033[31m-[-] not set ClientAliveInterval \\033[0m\"\n        fi\n        # 6.2.11 check SSH LoginGrace Time\n        local res=$(grep \"^LoginGraceTime\" /etc/ssh/sshd_config)\n        if [[ -n $res ]]; then\n            sshdIfSetLoginGraceTime=$(echo $res|sed -r 's/([^1234567890]*)([[:digit:]]+)/\\2/')\n            echo -e \"\\033[32m-[+] $res \\033[0m\"\n        else\n            sshdIfSetLoginGraceTime=\"False\"\n            echo -e \"\\033[31m-[-] not set LoginGraceTime \\033[0m\"\n        fi\n\telse\n        sshdIfEnabled=\"False\"\n\t\techo -e \"\\033[32m-[+] sshd is not enabled \\033[0m\"\n\tfi\n    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\\\"}\n\n    # 6.3 PAM configuration\n    echo \"-[·] check pam configuration\"\n    # 6.3.1 password creation policy\n    if [[ -f /etc/security/pwquality.conf ]]; then\n        pamPwqualityconfIfExist=\"True\"\n        local minlen=$(grep ^minlen /etc/security/pwquality.conf | sed 's/ //g')\n        local minclass=$(grep ^minclass /etc/security/pwquality.conf |sed 's/ //g')\n        if [[ -n $minlen ]]; then\n            pamIfSetMinlen=$(echo $minlen|cut -d= -f2)\n            echo -e \"\\033[32m-[+] minimime length of password is $(echo $minlen|cut -d= -f2) \\033[0m\"\n        else\n            pamIfSetMinlen=\"False\"\n            echo -e \"\\033[31m-[-] not set minlen \\033[0m\"\n        fi\n        if [[ -n $minclass ]]; then\n            pamIfSetMinclass=$(echo $minclass|cut -d= -f2)\n            echo -e \"\\033[32m-[+] minclass of password is $(echo $minclass|cut -d= -f2) \\033[0m\"\n        else\n            local keyArray=(\"^dcredit\" \"^lcredit\" \"^ocredit\" \"^ucredit\")\n            local tmpCount=0\n            for i in ${keyArray[@]}; do\n                if [[ -n  $(grep $i /etc/security/pwquality.conf) ]]; then\n                    tmpCount=$(expr 1 + $tmpCount)\n                fi\n            done\n            if [[ $tmpCount = 0 ]]; then\n                pamIfSetMinclass=\"False\"\n            else\n                pamIfSetMinclass=$tmpCount\n            fi\n            if [[ tmpCount -ge 2 ]]; then\n                echo -e \"\\033[32m-[+] minclass of passwd is $tmpCount \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] not set minclass \\033[0m\"\n            fi\n        fi\n    else\n        pamPwqualityconfIfExist=\"False\"\n    fi\n    # 6.3.2 lock account and unlock time\n    local files=(\"/etc/pam.d/password-auth\" \"/etc/pam.d/system-auth\")\n    local keyArray=(\"pam_faillock\\.so.*?unlock_time\")\n    tmpArray1=()\n    tmpArray2=()\n    for i in ${files[@]}; do\n        for k in ${keyArray[@]}; do\n            if [[ -n $(egrep $k $i ) ]]; then\n                echo -e \"\\033[32m-[+] set lock and unlock_time in $i \\033[0m\"\n                tmpArray1+=($i\\;)\n            else\n                tmpArray2+=($i\\;)\n                echo -e \"\\033[31m-[-] not set lock and unlock_time in $i \\033[0m\"\n            fi\n        done\n    done\n    sshdSetedLockAndUnlockTimeFiles=$(echo ${tmpArray1[@]}|sed 's/; /;/g')\n    sshdNotSetedLockAndUnlockTimeFiles=$(echo ${tmpArray2[@]}|sed 's/; /;/g')\n    # 6.3.3 check password reuse if is limited\n    sshdPamdFileArray=$(echo ${files[@]}|sed 's/ /;/g')\n    tmpArray=()\n    for i in ${files[@]}; do\n        local res=$(egrep '^password\\s+sufficient\\s+pam_unix.so' $i)\n        if [[ -n $res ]] && [[ $res =~ \"remember=\" ]]; then\n            local tmp=$(echo $res|sed 's/.*\\(remember=[[:digit:]]\\).*/\\1/g'|sed 's/ //g'|cut -d= -f2)\n            tmpArray+=($tmp\\;)\n            echo -e \"\\033[32m-[+] password reuse limit is $tmp in $i \\033[0m\"\n        else\n            tmpArray+=(\"False;\")\n            echo -e \"\\033[31m-[-] passowrd reuse limit not set in $i \\033[0m\"\n        fi\n    done\n    sshdPamdFileReuseLimitArray=$(echo ${tmpArray[@]}|sed 's/; /;/g')\n    # 6.3.4 check the algorithm of store password if is sha512\n    tmpArray=()\n    for i in ${files[@]}; do\n        local res=$(egrep '^password\\s+sufficient\\s+pam_unix.so' $i)\n        if [[ -n $res ]] && [[ $res =~ \"sha512\" ]]; then\n            tmpArray+=(\"True;\")\n            echo -e \"\\033[32m-[+] password storage algorithm is set to sha512 in $i \\033[0m\"\n        else\n            tmpArray+=(\"False;\")\n            echo -e \"\\033[31m-[-] password storage algorithm is not specific to sha512 in $i \\033[0m\"\n        fi\n    done\n    sshdPamdFileIfSetSha512Array=$(echo ${tmpArray[@]}|sed 's/; /;/g')\n    pam_config_info={\\\"pamPwqualityconfIfExist\\\":\\\"$pamPwqualityconfIfExist\\\",\\\"pamIfSetMinlen\\\":\\\"$pamIfSetMinlen\\\",\\\"pamIfSetMinclass\\\":\\\"$pamIfSetMinclass\\\",\\\"sshdSetedLockAndUnlockTimeFiles\\\":\\\"$sshdSetedLockAndUnlockTimeFiles\\\",\\\"sshdNotSetedLockAndUnlockTimeFiles\\\":\\\"$sshdNotSetedLockAndUnlockTimeFiles\\\",\\\"sshdPamdFileArray\\\":\\\"$sshdPamdFileArray\\\",\\\"sshdPamdFileReuseLimitArray\\\":\\\"$sshdPamdFileReuseLimitArray\\\",\\\"sshdPamdFileIfSetSha512Array\\\":\\\"$sshdPamdFileIfSetSha512Array\\\"}\n    # 6.4 user accounts and environment\n    echo \"-[·] check user accounts and environment\"\n    if [[ -f /etc/login.defs ]]; then\n        accountLogindefsIfExist=\"True\"\n        # 6.4.1 basic settings\n        local file='/etc/login.defs'\n        passMaxDays=$(grep ^PASS_MAX_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\\1/g')\n        passMinDays=$(grep ^PASS_MIN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\\1/g')\n        passWarnAge=$(grep ^PASS_WARN_DAYS $file|sed -r 's/[^1234567890]*([1234567890]{1,})/\\1/g')\n        inactive=$(useradd -D|grep INACTIVE|sed 's/ //g'|cut -d= -f2)\n        accountPassMaxDays=$passMaxDays\n        accountPassMinDays=$passMinDays\n        accountPassWarnDays=$passWarnAge\n        accountPassAutolockInactiveDays=$inactive\n        if [[ $passMaxDays -le 90 ]]; then\n            echo -e \"\\033[32m-[+] the maximume days of password have to change is $passMaxDays \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the maximume days of password have to change is $passMaxDays ,should less than 90 day\\033[0m\"\n        fi\n        if [[ $passMinDays -ge 7 ]]; then\n            echo -e \"\\033[32m-[+] the minimume days of password have to change is $passMinDays \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the minimume days of password have to change is $passMinDays ,should great than 7 day\\033[0m\"\n        fi\n        if [[ $passWarnAge -ge 7 ]]; then\n            echo -e \"\\033[32m-[+] the minimume days of warn password need to change is $passWarnAge \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] the minimume days of warn password need to change is $passWarnAge ,should greate than 7 day\\033[0m\"\n        fi\n        if [[ $inactive != -1 ]]; then\n            echo -e \"\\033[32m-[+] auto lock account when the  $inactive day haven't login \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] haven't set day of auto lock accounts \\033[0m\"\n        fi\n        # 6.4.2 check system's account if is unlogin\n        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}')\n        tmpArray=()\n        if [[ -z $res ]]; then\n            tmpArray+=(\"False;\")\n            echo -e \"\\033[32m-[+] system account can't login \\033[0m\"\n        else\n            tmpArray+=($(echo $res|sed 's/\\n/ /g'))\n            echo -e \"\\033[31m-[-]  ($(echo $res|sed 's/\\n/ /g'))user's shell need set to /sbin/nologin \\033[0m\"\n        fi\n        accountShouldUnloginAray=$(echo ${tmpArray[@]}|sed 's/ /;/g')\n        # 6.4.3 check default group for the root account if is GID 0\n        local res=$(grep \"^root:\" /etc/passwd|cut -d: -f4)\n        accountGIDOfRoot=$res\n        if [[ $res = 0 ]]; then\n            echo -e \"\\033[32m-[+] default group for the root account is GID 0 \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-]] default group for the root account is is GID $res,not GID 0 \\033[0m\"\n        fi\n        # 6.4.4 check default user shell timeout if is 900 seconds or less\n        local files=(\"/etc/bashrc\" \"/etc/profile\")\n        tmpArray1=()\n        tmpArray2=()\n        for file in ${files[@]}; do\n            if [[ ! -f $file ]]; then\n                continue\n            else\n                tmpArray1+=($file\\;)\n            fi\n            local res=$(grep \"^TMOUT\" $file|sed 's/ //g'|cut -d= -f2)\n            if [[ -z $res ]]; then\n                tmpArray2+=(\"False;\")\n                echo -e \"\\033[31m-[-] not set TMOUT in file $file \\033[0m\"\n                continue\n            fi\n            tmpArray2+=($res\\;)\n            if [[ $res -le 900 ]]; then\n                echo -e \"\\033[32m-[+] when idle time great than $res seconds will close connection \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] when idle time great than $res seconds will close connection,the time should less than 900 seconds \\033[0m\"\n            fi\n        done\n        accountProfileFileArray=$(echo ${tmpArray1[@]}|sed 's/; /;/g')\n        accountProfileTMOUTArray=$(echo ${tmpArray2[@]}|sed 's/; /;/g')\n        # 6.4.5 check access to su command if is restricted\n        local res=$(grep pam_wheel.so /etc/pam.d/su)\n#        accountIfSetUsersCanAccessSuCommand=\n        if [[ -n $res ]]; then\n            local res=$(grep wheel /etc/group|cut -d: -f4)\n            if [[ -n $res ]]; then\n                accountIfSetUsersCanAccessSuCommand=$(echo $res|sed 's/\\n/;/g')\n                echo -e \"\\033[32m-[+] access to su command is specific to $(echo $res|sed 's/\\n/;/g') \\033[0m\"\n            else\n                accountIfSetUsersCanAccessSuCommand=\"False\"\n                echo -e \"\\033[31m-[-] access to su command is not restricted \\033[0m\"\n            fi\n        else\n            accountIfSetUsersCanAccessSuCommand=\"False\"\n            echo -e \"\\033[31m-[-] access to su command is not restricted \\033[0m\"\n        fi\n    else\n        accountLogindefsIfExist=\"False\"\n        echo -e \"\\033[31m-[-] file /etc/login.defs is not exist \\033[0m\"\n    fi\n    account_config_info={\\\"accountPassMaxDays\\\":\\\"$accountPassMaxDays\\\",\\\"accountPassMinDays\\\":\\\"$accountPassMinDays\\\",\\\"accountPassWarnDays\\\":\\\"$accountPassWarnDays\\\",\\\"accountPassAutolockInactiveDays\\\":\\\"$accountPassAutolockInactiveDays\\\",\\\"accountShouldUnloginArray\\\":\\\"$accountShouldUnloginArray\\\",\\\"accountGIDOfRoot\\\":\\\"$accountGIDOfRoot\\\",\\\"accountProfileFileArray\\\":\\\"$accountProfileFileArray\\\",\\\"accountProfileTMOUTArray\\\":\\\"$accountProfileTMOUTArray\\\",\\\"accountIfSetUsersCanAccessSuCommand\\\":\\\"$accountIfSetUsersCanAccessSuCommand\\\"}\n    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}\n}\n\nfunction system_check {\n    echo \"[·] check permission of important file and configuration of user and group\"\n    # 7.1 check permission of important file and uid gid\n    echo \"-[·] check permission of important file\"\n    local files=(\"/etc/passwd\" \"/etc/shadow\" \"/etc/group\" \"/etc/gshadow\" \"/etc/passwd-\" \"/etc/shadow-\" \"/etc/group-\" \"/etc/gshadow-\")\n    importantFilenameArray=$(echo ${files[@]}|sed 's/ /;/g')\n    tmpArray1=()\n    tmpArray2=()\n    for file in ${files[@]}; do\n        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)\n        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)\n        tmpArray1+=($perm\\;)\n        tmpArray2+=($uidGid\\;)\n        if [[ $file =~ \"shadow\" ]]; then\n            if [[ $perm = \"0000\" ]]; then\n                echo -e \"\\033[32m-[+] file $file's permission is $perm \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] file $file's permission is $perm,should set to 0000 \\033[0m\"\n            fi\n        else\n            if [[ $perm = \"0644\" ]]; then\n                echo -e \"\\033[32m-[+] file $file's permission is $perm \\033[0m\"\n            else\n                echo -e \"\\033[31m-[-] file $file's permission is $perm,should set to 0644 \\033[0m\"\n\n            fi\n        fi\n        if [[ $uidGid = \"0 0\" ]]; then\n            echo -e \"\\033[32m-[+] file $file's uid gid is $uidGid \\033[0m\"\n        else\n            echo -e \"\\033[31m-[-] file $file's uid gid is $uidGid,should set to 0 0 \\033[0m\"\n        fi\n    done\n    importantFilePermissionArray=$(echo ${tmpArray1[@]}|sed 's/; /;/g')\n    importantFileUidgidArray=$(echo ${tmpArray2[@]}|sed 's/; /;/g')\n    file_permission_info={\\\"importantFilenameArray\\\":\\\"$importantFilenameArray\\\",\\\"importantFilePermissionArray\\\":\\\"$importantFilePermissionArray\\\",\\\"importantFileUidgidArray\\\":\\\"$importantFileUidgidArray\\\"}\n    # 7.2 check configuration of user and group\n    echo \"-[·] check configuration of user and group\"\n    # 7.2.1 check if user's password is empty\n    users=$(cat /etc/shadow |awk -F: '($2==\"!!\"){print $1}'|while read x;do \n        res=$(grep ${x} /etc/passwd|cut -d: -f7)\n        if [[ $res != \"/sbin/nologin\" ]] && [[ $res != \"/sbin/shutdown\" ]] && [[ $res != \"/sbin/halt\" ]]; then \n            echo $x\n            #echo -e \"\\033[31m-[-] $x should have a passwd,not empty \\033[0m\"; \n            fi;\n        done)\n    if [[ -z $users ]]; then\n        userIfSetPasswdOrArray=\"True\"\n        echo -e \"\\033[32m-[+] all user account have set password \\033[0m\"\n    else\n        userIfSetPasswdOrArray=$(echo $users|sed 's/ /;/g')\n        echo -e \"\\033[31m-[-] user:$(echo $users|sed 's/\\n/ /g') should set a password ,rather than empty \\033[0m\"\n    fi\n    # 7.2.2 check if root is the only UID 0 account\n    local users=$(cat /etc/passwd|awk -F: '($3==0){print $1}')\n    if [[ $users = 'root' ]]; then\n        uid0OnlyRootOrArray=\"True\"\n        echo -e \"\\033[32m-[+] root is the only account that uid is 0 \\033[0m\"\n    else\n        uid0OnlyRootOrArray=$(echo $users|sed 's/root //g'|sed 's/ /;/g')\n        echo -e \"\\033[31m-[-] $(echo $users|sed 's/root //g'|sed 's/\\n/ /g') uid should not be 0 \\033[0m\"\n    fi\n    # 7.2.3 check root PATH integrith\n    if [ \"$(echo $PATH|grep ::)\" != \"\" ]; then\n        echo -e \"\\033[31m-[-] Empty Directory in PATH (::) \\033[0m\"\n    fi\n    if [ \"$(echo $PATH|grep :$)\" != \"\" ]; then\n        echo -e \"\\033[31m-[-] Trailing : in PATH \\033[0m\"\n    fi\n    path=$( echo $PATH|sed -e 's/::/:/' -e 's/:$//' -e 's/:/ /g')\n    tmpArray1=()\n    tmpArray2=()\n    tmpArray3=()\n    tmpArray4=()\n    tmpArray5=()\n    set -- $path\n    while [[ $1 != \"\" ]]; do\n        if [[ $1 = \".\" ]]; then\n            echo -e \"\\033[31m-[-] PATH contains . \\033[0m\"\n            tmpArray1+=(\".\")\n            shift\n            continue\n        fi\n        if [[ -d $1 ]]; then\n            local dirperm=$(ls -ldH $1|cut -d\" \" -f1)\n            if [[ $(echo $dirperm|cut -c6) != \"-\" ]]; then\n                tmpArray2+=($1\\;)\n                echo -e \"\\033[31m-[-] Group Write permission should not set on directory $1 \\033[0m\"\n            fi\n            if [[ $(echo $dirperm|cut -c9) != \"-\" ]]; then\n                tmpArray3+=($1\\;)\n                echo -e \"\\033[31m-[-] Other Write permission should not set on directory $1 \\033[0m\"\n            fi\n            local dirown=$(ls -ldH $1|awk '{print $3}')\n            if [[ $dirown != \"root\" ]]; then\n                tmpArray4+=($1\\;)\n                echo -e \"\\033[31m-[-] dir $1's owner is $dirown,should be root \\033[0m\"\n            fi\n        else\n            tmpArray5+=($1\\;)\n            echo -e \"\\033[31m-[-] $1 is not a directory or not exist \\033[0m\"\n        fi\n        shift\n    done\n    if [[ ${#tmpArray1[@]} = 0 ]]; then\n        pathDirIfNotHasDot=\"True\"\n    else\n        pathDirIfNotHasDot=\"False\"\n    fi\n    pathDirPermissionHasGWArray=$(echo ${tmpArray2[@]}|sed 's/; /;/g')\n    pathDirPermissionHasOWArray=$(echo ${tmpArray3[@]}|sed 's/; /;/g')\n    pathDirOwnerIsNotRootArray=$(echo ${tmpArray4[@]}|sed 's/; /;/g')\n    pathDirDoesNotExistOrNotDirArray=$(echo ${tmpArray5[@]}|sed 's/; /;/g')\n    # 7.2.4 check if is all users' home directories exist\n    #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\n    tmpArray1=()\n    tmpArray2=()\n    tmpArray3=()\n    tmpArray4=()\n    tmpArray5=()\n    tmpArray6=()\n    while read user dir; do\n        tmpArray1+=($dir\\;)\n        if [[ ! -d $dir ]]; then\n            tmpArray2+=(\"False;\")\n            tmpArray3+=(\"False;\")\n            echo -e \"\\033[31m-[-] the home directory ($dir) of user $user does not exist \\033[0m\"\n\n        else\n            tmpArray2+=(\"True;\")\n            # 7.2.5 check if users' home directories permissions are 750 or more restrictive\n            local dirperm=$(ls -ld $dir|cut -d\" \" -f1)\n            tmpArray3+=($dirperm\\;)\n            if [[ $(echo $dirperm |cut -c6) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Group Write permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            if [[ $(echo $dirperm |cut -c8) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Read permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            if [[ $(echo $dirperm |cut -c9) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Write permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            if [[ $(echo $dirperm |cut -c10) != \"-\" ]]; then\n                echo -e \"\\033[31m-[-] Other Execute permission set on the home directory ($dir) of user $user \\033[0m\"\n            fi\n            # 7.2.6 check if is users own their home directory\n            local owner=$(stat -L -c \"%U\" $dir)\n            if [[ $owner != $user ]]; then\n                tmpArray4+=(\"False;\")\n                echo -e \"\\033[31m-[-]The home directory ($dir) of user $user is owned by $owner \\033[0m\"\n            else\n                tmpArray4+=(\"True;\")\n            fi\n            # 7.2.7 check users' dot files are not group or world  writable\n            local tmpc=0\n            for file in $dir/.[A-Za-z0-9]*; do\n                if [[ ! -h $file ]] && [[ -f $file ]]; then\n                    local fileperm=$(ls -ld $file|cut -d\" \" -f1)\n                    if [[ $(echo $fileperm|cut -c6) != \"-\" ]]; then\n                        tmpc=$(expr $tmpc + 1)\n                        echo -e \"\\033[31m-[-] Group Write permission set on file $file \\033[0m\"\n                    fi\n                    if [[ $(echo $fileperm|cut -c9) != \"-\" ]]; then\n                        tmpc=$(expr $tmpc + 1)\n                        echo -e \"\\033[31m-[-] Other Write permission set on file $file \\033[0m\"\n                    fi\n                fi\n            done\n            if [[ $tmpc = 0 ]]; then\n                tmpArray5+=(\"True;\")\n            else\n                tmpArray5+=(\"False;\")\n            fi\n            # 7.2.8 check if no usrs have .netrc .rhosts .forward file\n            tmpc=0\n            if [[ ! -h $dir/.netrc ]] && [[ -f $dir/.netrc ]]; then\n                tmpc=$(expr $tmpc + 1)\n                echo -e \"\\033[31m-[-] .netrc file $dir/.netrc exists \\033[0m\"\n            fi\n            if [[ ! -h $dir/.rhosts ]] && [[ -f $dir/.rhosts ]]; then\n                tmpc=$(expr $tmpc + 1)\n                echo -e \"\\033[31m-[-] .rhosts file $dir/.rhosts exists \\033[0m\"\n            fi\n            if [[ ! -h $dir/.forward ]] && [[ -f $dir/.forward ]]; then\n                tmpc=$(expr $tmpc + 1)\n                echo -e \"\\033[31m-[-] .forward file $dir/.forward exists \\033[0m\"\n            fi\n            if [[ $tmpc = 0 ]]; then\n                tmpArray6+=(\"True;\")\n            else\n                tmpArray6+=(\"False;\")\n            fi\n        fi\n    done < <(cat /etc/passwd|egrep -v '^(root|halt|sync|shutdown)'|awk -F: '($7 != \"/sbin/nologin\" && $7 != \"/bin/false\"){print $1 \" \" $6}')\n    userArray=$(echo ${tmpArray1[@]}|sed 's/; /;/g')\n    userHomeDirIfExistArray=$(echo ${tmpArray2[@]}|sed 's/; /;/g')\n    userHomeDirPermissionArray=$(echo ${tmpArray3[@]}|sed 's/; /;/g')\n    userIfOwnTheirHomeDirArray=$(echo ${tmpArray4[@]}|sed 's/; /;/g')\n    userHomeDirIfHasGWorOWDotFileArray=$(echo ${tmpArray5[@]}|sed 's/; /;/g')\n    userHomeDirIfHasOtherFileArray=$(echo ${tmpArray6[@]}|sed 's/; /;/g')\n    # 7.2.9 check if all groups in /etc/passwd exist in /etc/group\n    tmpArray=()\n    for i in $(cut -d: -s -f4 /etc/passwd|sort -u); do\n        grep -q -P \"^.*?:[^:]*:$i\" /etc/group\n        if [[ $? -ne 0 ]]; then\n        tmpArray+=($i\\;)\n            echo -e \"\\033[31m-[-] Group $i is referenced by /etc/passwd but does not exist in /etc/group \\033[0m\"\n        fi\n    done\n    groupNotExistInetcgroup=$(echo ${tmpArray[@]}|sed 's/; /;/g')\n    # 7.2.10 check if every user has a unique UID\n    #cat /etc/passwd|cut -d\":\" -f3|sort -n|uniq -c|while read x; do\n    tmpArray=()\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x\n        if [[ $1 -gt 1 ]]; then\n            local users=$(awk -F: '($3==n){print $1}' n=$2 /etc/passwd|xargs)\n            tmpArray+=($2:$users\\;)\n            echo -e \"\\033[31m-[-] Duplicate UID $2 : $users \\033[0m\"\n        fi\n    done < <(cat /etc/passwd|cut -d\":\" -f3|sort -n|uniq -c)\n    usersIfHasUniqueUIDArray=$(echo ${tmpArray[@]}|sed 's/; /;/g')\n    # 7.2.11 check if every group has a unique GID\n    tmpArray=()\n    #cat /etc/group|cut -d\":\" -f3|sort -n|uniq -c|while read x; do\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x\n        if [[ $1 -gt 1 ]]; then\n            local groups=$(awk -F: '($3==n){print $1}' n=$2 /etc/group|xargs)\n            tmpArray+=($2:$groups\\;)\n            echo -e \"\\033[31m-[-] Duplicate GID $2 : $groups \\033[0m\"\n        fi\n    done < <(cat /etc/group|cut -d\":\" -f3|sort -n|uniq -c)\n    groupsIfHasUniqueGIDArray=${tmpArray[@]}\n    # 7.2.12 check if user name is unique\n    tmpArray=()\n    #cat /etc/passwd|cut -d\":\" -f1|sort -n|uniq -c|while read x; do\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x11\n        if [[ $1 -gt 1 ]]; then\n            local uids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/passwd|xargs)\n            tmpArray+=($2:$uids\\;)\n            echo -e \"\\033[31m-[-] Duplicate user name $2 : $uids \\033[0m\"\n        fi\n    done < <(cat /etc/passwd|cut -d\":\" -f1|sort -n|uniq -c)\n    usersIfHasUniqueNameArray=${tmpArray[@]}\n    # 7.2.13 check if group name is unique\n    tmpArray=()\n    #cat /etc/group|cut -d\":\" -f1|sort -n|uniq -c|while read x; do\n    while read x; do\n        [[ -z $x ]] && break\n        set - $x11\n        if [[ $1 -gt 1 ]]; then\n            local gids=$(awk -F: '($1 == n){print $3}' n=$2 /etc/group|xargs)\n            tmpArray+=($2:$gids\\;)\n            echo -e \"\\033[31m-[-] Duplicate group name $2 : $gids \\033[0m\"\n        fi\n    done < <(cat /etc/group|cut -d\":\" -f1|sort -n|uniq -c)\n    groupsIfHasUniqueNameArray=${tmpArray[@]}\n    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\\\"}\n    system_check_res={\\\"file_permission_info\\\":$file_permission_info,\\\"usergroup_config_info\\\":$usergroup_config_info}\n\n}\n\necho \"\"\"\n==================================\n|        Linux 基线检查工具      |\n|        author:JC0o0l           |\n|        version:2.2             |\n==================================\n\"\"\"\nget_basic_info\ninit_check\nservice_check\nnetwork_check\nauditd_check\nlog_check\nauthentication_check\nsystem_check\nif [[ -z $authentication_check_res ]]; then\n    authentication_check_res={}\nfi\nif [[ -z $system_check_res ]]; then\n    system_check_res={}\nfi\ncheck_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}\ncurl -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\necho $check_result|jq \n"
  },
  {
    "path": "win2012_baseline_check.ps1",
    "content": "﻿<#\nAuthor: JC (@chroblert)\nAuthor: JC0o0l (@chroblert)\nMail: jerryzvs@163.com\nwechat: Chroblert_Jerrybird(信安札记)\n#>\nchcp 65001\nfunction Get-BasicInfo{\n\t$scanTime=Get-date -Format 'yyyy-M-d H:m:s'\n\t$hostname = hostname\n\t$osVersion=Get-WmiObject -Class Win32_OperatingSystem | Select-Object -ExpandProperty Caption\n\t$ipList = \"\"\n\t$macaddr = \"\"\n\tforeach($line in ipconfig /all|Select-String -Pattern \"^\\s*IPv4\"){ \n\t\t$line=$line.ToString().split(\":\")[1].replace(\"(\",\"\\(\").replace(\")\",\"\\)\")\n\t\t$context = (ipconfig /all |Select-String -Pattern $line -Context 10,0).Context[0]\n\t\tif ($context.Precontext|Select-String \"VMware\" -Quiet){\n\t\t\tcontinue\t\n\t\t}\n\t\tforeach ($lline in $context.Precontext.split(\"\\n\")){\n\t\t\t#Write-Host $lline\n\t\t\tif ($lline.ToString().contains(\"Physical\")){\n\t\t\t\t#Write-Host $lline.ToString() dddd\n\t\t\t\t$macaddr = $macaddr + $lline.ToString().split(\":\")[1].Trim() + \";\"\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\t$ipList = $ipList + $line.ToString().split(\"\\\")[0].trim() + \";\"\n\t}\n\tWrite-Host scanTime:$scanTime\n\tWrite-Host osVersion:$osVersion\n\tWrite-Host hostname:$hostname\n\tWrite-Host macaddr: $macaddr \n\tWrite-Host ipList : $ipList \n\t$basic_info=\"{\"\"scanTime\"\":\"\"$scanTime\"\",\"\"osVersion\"\":\"\"$osVersion\"\",\"\"hostname\"\":\"\"$hostname\"\",\"\"macaddr\"\":\"\"$macaddr\"\",\"\"ipList\"\":\"\"$ipList\"\"}\"\n\treturn $basic_info\n}\nfunction Get-SecInfo{\n\t$secinfo=\"\"\n\tSecEdit.exe /export /cfg sec.inf /Quiet\n\t$secInfoArray=Get-Content .\\sec.inf\n\tforeach ($line in $secInfoArray){\n\t\t$secinfo = $secinfo + $line.ToString() + \";\"\n\t}\n\treturn $secInfoArray\n}\nfunction Check-PasswordPolicy{\n\t<#\n\t.SYNOPSIS\n\t检查密码策略是否符合预定策略\n\n\t.DESCRIPTION\n\t预定策略：\n\t\t密码历史：5\n\t\t密码最长使用期限：90\n\t\t密码最短使用期限：1\n\t\t密码复杂度是否开启：1开启\n\t\t是否以可还原的方式加密存储密码：0否\n\t\t密码最小长度：8位\n\t.EXAMPLE\n\tCheck-PasswordPolicy secInfoArray\n\n\t.NOTES\n\tGeneral notes\n\t#>\n\tParam(\n\t\t[System.Collections.ArrayList]$secInfoArray\n\t)\n\t$stPasswordHistorySize=5\n\t$stMaximumPasswordAge=90\n\t$stMinimumPasswordAge=1\n\t$stPasswordComplexity=1\n\t$stClearTextPassword=0\n\t$stMinimumPasswordLength=8\n\t$passwordHistorySize=(Write-Output $secInfoArray|Select-String -pattern \"^PasswordHistorySize\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\tif($passwordHistorySize -lt $stPasswordHistorySize){\n\t\tWrite-Host [-] PasswordHistorySize less than $stPasswordHistorySize -ForegroundColor Red\n\t}\n\t$maximumPasswordAge=(Write-Output $secInfoArray|Select-String -Pattern \"^MaximumPasswordAge\" ).ToString().Split(\"=\")[1]  -replace \"\\s\",\"\"\n\tif($maximumPasswordAge -lt $stMaximumPasswordAge){\n\t\tWrite-Host [-] MaximumPasswordAge less than $stMaximumPasswordAge -ForegroundColor Red\n\t}\n\t$minimumPasswordAge=(Write-Output $secInfoArray|Select-String -Pattern \"^MinimumPasswordAge\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\tif($minimumPasswordAge -lt $stMinimumPasswordAge){\n\t\tWrite-Host [-] MinimumPasswordAge less than $stMinimumPasswordAge -ForegroundColor Red\n\t}\n\t$passwordComplexity=(Write-Output $secInfoArray|Select-String -Pattern \"^PasswordComplexity\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\tif($passwordComplexity -ne $stPasswordComplexity){\n\t\tWrite-Host [-] PasswordComplexity value is not $stPasswordComplexity -ForegroundColor Red\n\t}\n\t$clearTextPassword=(Write-Output $secInfoArray|Select-String -Pattern \"^ClearTextPassword\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\tif($clearTextPassword -ne $stClearTextPassword){\n\t\tWrite-Host [-] ClearTextPassword value is not stCclearTextPassword -ForegroundColor Red\n\t}\n\t$minimumPasswordLength=(Write-Output $secInfoArray|Select-String -Pattern \"^MinimumPasswordLength\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\tif($minimumPasswordLength -lt $stMinimumPasswordLength){\n\t\tWrite-Host [-] MinimumPasswordLength less than $stMinimumPasswordLength -ForegroundColor Red\n\t}\n\t$password_check_info=\"{\"\"passwordHistorySize\"\":\"\"$passwordHistorySize\"\",\"\"maximumPasswordAge\"\":\"\"$maximumPasswordAge\"\",\"\"minimumPasswordAge\"\":\"\"$minimumPasswordAge\"\",\"\"passwordComplexity\"\":\"\"$passwordComplexity\"\",\"\"clearTextPassword\"\":\"\"$clearTextPassword\"\",\"\"minimumPasswordLength\"\":\"\"$minimumPasswordLength\"\"}\"\n\t#Write-Host $password_check_info\n\treturn $password_check_info\n\n}\nfunction Check-AccountLockoutPolicy{\n\t<#\n\t.SYNOPSIS\n\t检查账户锁定的相关策略\n\t\n\t.DESCRIPTION\n\t预定策略：\n\t\t账户锁定时间：15 Or more\n\t\t账户锁定阈值: 5 or less\n\t\t重置账户锁定: 15 or more,但值要小于账户锁定时间\n\t\n\t.PARAMETER secInfoArray\n\t使用secedit /export /cfg sec.inf 导出的文件，再输出到secInfoArray中\n\n\t.EXAMPLE\n\tCheck-AccountLockoutPolicy $secInfoArray\n\t\n\t.NOTES\n\tGeneral notes\n\t#>\n\t\n\tParam(\n\t\t[System.Collections.ArrayList]$secInfoArray\n\t)\n\t$stLockoutDuration=15\n\t$stLockoutBadCount=5\n\t$stResetLockoutCount=15\n\t$lockoutDuration=(Write-Output $secInfoArray|Select-String -Pattern \"^LockoutDuration\" -Quiet)\n\tif($lockoutDuration){\n\t\t$lockoutDuration=(Write-Output $secInfoArray|Select-String -Pattern \"^LockoutDuration\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\t\tif($lockoutDuration -lt $stLockoutDuration){\n\t\t\tWrite-Host [-] LockoutDuration less than $stLockoutDuration -ForegroundColor Red\n\t\t}\n\t}else{\n\t\t$lockoutDuration=0\n\t}\n\t\n\t$lockoutBadCount=(Write-Output $secInfoArray|Select-String -Pattern \"^LockoutBadCount\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\tif($lockoutBadCount -lt $stLockoutBadCount){\n\t\tWrite-Host [-] LockoutBadCount less than $stLockoutBadCount -ForegroundColor Red\n\t}\n\n\t$resetLockoutCount=(Write-Output $secInfoArray|Select-String -Pattern \"^ResetLockoutCount\" -Quiet)\n\tif($resetLockoutCount){\n\t\t$resetLockoutCount=(Write-Output $secInfoArray|Select-String -Pattern \"^ResetLockoutCount\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\t\tif($resetLockoutCount -lt $stLockoutDuration -or  $resetLockoutCount -gt $lockoutDuration){\n\t\t\tWrite-Host [-] ResetLockoutCount great than $stResetLockoutCount or less than $stLockoutDuration\n\t\t}\n\t}else{\n\t\t$resetLockoutCount=0\n\t}\n\t\n\t$account_lockout_info=\"{\"\"lockoutDuration\"\":\"\"$lockoutDuration\"\",\"\"lockoutBadCount\"\":\"\"$lockoutBadCount\"\",\"\"resetLockoutCount\"\":\"\"$resetLockoutCount\"\"}\"\n\treturn $account_lockout_info\n\n\n}\nfunction Get-AccountPolicyCheckRes{\n\tParam(\n\t\t[System.Collections.ArrayList] $secInfoArray\n\t)\n\t$password_check_info=(Check-PasswordPolicy $secInfoArray)\n\t$account_lockout_info=(Check-AccountLockoutPolicy $secInfoArray)\n\t$account_check_res=\"{\"\"password_check_info\"\":$password_check_info,\"\"account_lockout_info\"\":$account_lockout_info}\"\n\treturn $account_check_res\n}\nfunction  Get-AuditPolicyCheckRes {\n\t<#\n\t.SYNOPSIS\n     获取策略中关于审计策略的部分\n\t\n\t.DESCRIPTION\n\t预定策略：\n\t\t 审核策略更改：成功\n\t\t 审核登录事件：成功，失败\n\t\t 审核对象访问：成功\n\t\t 审核进程跟踪：成功，失败\n\t\t 审核目录服务访问：成功，失败\n\t\t 审核系统事件：成功，失败\n\t\t 审核账户登录事件：成功，失败\n\t\t 审核账户管理事件：成功，失败\n\t预设值的含义：\n\t\t0：没有开启审计\n\t\t1：审计成功事件\n\t\t2：审计失败事件\n\t\t3：审计成功和失败事件\n\t\n\t.PARAMETER secInfoArray\n\tParameter description\n\t\n\t.EXAMPLE\n\tAn example\n\t\n\t.NOTES\n\tGeneral notes\n\t#>\n\t\n\tparam (\n\t\t[System.Collections.ArrayList]$secInfoArray\n\t)\n\n\t$stAuditPolicyChange=1\n\t$stAuditLogonEvents=3\n\t$stAuditObjectAccess=1\n\t$stAuditProcessTracking=3\n\t$stAuditDSAccess=3\n\t$stAuditSystemEvents=3\n\t$stAuditAccountLogon=3\n\t$stAuditAccountManage=3\n\t$auditPolicyChange=(Write-Output $secInfoArray|Select-String -Pattern \"^AuditPolicyChange\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\tif($auditPolicyChange -lt $stAuditPolicyChange){\n\t\tWrite-Host [-] AuditPolicyChange value should be $stAuditPolicyChange -ForegroundColor Red\n\t}\n\t$auditLogonEvents=(Write-Output $secInfoArray|Select-String -Pattern \"^AuditLogonEvents\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\tif($auditLogonEvents -lt $stAuditLogonEvents){\n\t\tWrite-Host [-] AuditLogonEvents value should be $stAuditLogonEvents -ForegroundColor Red\n\t}\n\t$auditObjectAccess=(Write-Output $secInfoArray|Select-String -Pattern \"^AuditObjectAccess\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\tif($auditObjectAccess -lt $stAuditObjectAccess){\n\t\tWrite-Host [-] AuditObjectAccess value should be $stAuditObjectAccess -ForegroundColor Red\n\t}\n\t$auditProcessTracking=(Write-Output $secInfoArray|Select-String -Pattern \"^AuditProcessTracking\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\tif($auditProcessTracking -lt $stAuditProcessTracking){\n\t\tWrite-Host [-] AuditProcessTracking value should be $stAuditProcessTracking -ForegroundColor Red\n\t}\n\t$auditDSAccess=(Write-Output $secInfoArray|Select-String -Pattern \"^AuditDSAccess\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\tif($auditDSAccess -lt $stAuditDSAccess){\n\t\tWrite-Host [-] AuditDSAccess value should be $stAuditDSAccess -ForegroundColor Red\n\t}\n\t$auditSystemEvents=(Write-Output $secInfoArray|Select-String -Pattern \"^AuditSystemEvents\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\tif($auditSystemEvents -lt $stAuditSystemEvents){\n\t\tWrite-Host [-] AuditSystemEvents value should be $stAuditSystemEvents -ForegroundColor Red\n\t}\n\t$auditAccountLogon=(Write-Output $secInfoArray|Select-String -Pattern \"^AuditAccountLogon\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\tif($auditAccountLogon -lt $stAuditAccountLogon){\n\t\tWrite-Host [-] AuditAccountLogon value should be $stAuditAccountLogon -ForegroundColor Red\n\t}\n\t$auditAccountManage=(Write-Output $secInfoArray|Select-String -Pattern \"^AuditAccountManage\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\tif($auditAccountManage -lt $stAuditAccountManage){\n\t\tWrite-Host [-] AuditAccountManage value should be $stAuditAccountManage -ForegroundColor Red\n\t}\n\t$audit_check_res=\"{\"\"auditPolicyChange\"\":\"\"$auditPolicyChange\"\",\"\"auditLogonEvents\"\":\"\"$auditLogonEvents\"\",\"\"auditObjectAccess\"\":\"\"$auditObjectAccess\"\",\"\"auditProcessTracking\"\":\"\"$auditProcessTracking\"\",\"\"auditDSAccess\"\":\"\"$auditDSAccess\"\",\"\"auditSystemEvents\"\":\"\"$auditSystemEvents\"\",\"\"auditAccountLogon\"\":\"\"$auditAccountLogon\"\",\"\"auditAccountManage\"\":\"\"$auditAccountManage\"\"}\"\n\t#Write-Host $audit_check_res\n\treturn $audit_check_res\n\t\n}\nfunction Get-UserRightPolicyCheckRes{\n\tParam(\n\t\t[System.Collections.ArrayList]$secInfoArray\n\t)\n\t# 确保“作为受信任的呼叫放访问凭据管理器”值为空\n\t$seTrustedCredManAccessPrivilege=(Write-Output $secInfoArray|Select-String -Pattern \"^SeTrustedCredManAccessPrivilege\" -Quiet) \n\tif(-not $seTrustedCredManAccessPrivilege){\n\t\t$seTrustedCredManAccessPrivilegeIFNone=\"True\"\n\t}else{\n\t\t$seTrustedCredManAccessPrivilegeIFNone=(Write-Output $secInfoArray|Select-String -Pattern \"^SeTrustedCredManAccessPrivilege\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\t\tWrite-Host \"[-] SeTrustedCredManAccessPrivilege value should be None\" -ForegroundColor Red\n\t}\n\t# 确保“以操作系统方式运行”值为空\n\t$seTcbPrivilege=(Write-Output $secInfoArray|Select-String -Pattern \"^SeTcbPrivilege\" -Quiet) \n\tif(-not $seTcbPrivilege){\n\t\t$seTcbPrivilegeIFNone=\"True\"\n\t}else{\n\t\t$seTcbPrivilegeIFNone=(Write-Output $secInfoArray|Select-String -Pattern \"^SeTcbPrivilege\").ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\t\tWrite-Host \"[-] SeTcbPrivilege value should be None\" -ForegroundColor Red\n\t}\n\t# 确保“将工作站添加到域”值仅为特定的几个用户，不得为域账户、guest账户及域计算机\n\t$seMachineAccountPrivilegeIFOnlySpecifiedUserOrArray=(Write-Output $secInfoArray|Select-String \"^SeMachineAccountPrivilege\" -Quiet)\n\tif(-not $seMachineAccountPrivilegeIFOnlySpecifiedUserOrArray){\n\t\t$seMachineAccountPrivilegeIFOnlySpecifiedUserOrArray=\"True\"\n\t}else{\n\t\t$flag=0\n\t\t$seMachineAccountPrivilegeIFOnlySpecifiedUserOrArray=\"\"\n\t\tforeach($sid in ((Write-Output $secInfoArray|Select-String -Pattern \"^SeMachineAccountPrivilege\").ToString().Split(\"=\")[1].Trim()).Split(\",\")){\n\t\t\t$sidSuffix=$sid.split(\"-\")[-1].ToString()\n\t\t\t#Write-Host $sidSuffix\n\t\t\t$seMachineAccountPrivilegeIFOnlySpecifiedUserOrArray=$seMachineAccountPrivilegeIFOnlySpecifiedUserOrArray.ToString()+ $sidSuffix +\";\"\n\t\t\tif($sidSuffix.contains(\"513\") -or $sidSuffix.contains(\"514\") -or $sidSuffix.contains(\"515\") -or $sidSuffix.contains(\"501\")){\n\t\t\t\t$flag=1\n\t\t\t}\n\t\t} \n\t\tif ($flag){\n\t\t\tWrite-Host \"[-] SeMachineAccountPrivilege value should only be specified user or group ,cannot be guest ,domain user or domain computer\" -ForegroundColor Red\n\t\t}else{\n\t\t\t$seMachineAccountPrivilegeIFOnlySpecifiedUserOrArray=\"True\"\n\t\t}\n\t}\n\t# 确保“创建全局对象”值为空\n\t$seCreateGlobalPrivilegeIFNone=(Write-Output $secInfoArray|Select-String -Pattern \"^SeCreateGlobalPrivilege\" -Quiet)\n\tif(-not $seCreateGlobalPrivilegeIFNone){\n\t\t$seCreateGlobalPrivilegeIFNone=\"True\"\n\t}else{\n\t\t$seCreateGlobalPrivilegeIFNone=(Write-Output $secInfoArray|Select-String -Pattern \"^SeCreateGlobalPrivilege\" ).ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\t\tWrite-Host \"[-] SeCreateGlobalPrivilege value should be None\" -ForegroundColor Red\n\t}\n\t# 确保“拒绝作为批处理作业登录”包含“Guests\"\n\t$seDenyBatchLogonRightIFContainGuests=(Write-Output $secInfoArray|Select-String -Pattern \"^SeDenyBatchLogonRight\" -Quiet)\n\tif(-not $seDenyBatchLogonRightIFContainGuests){\n\t\t$seDenyBatchLogonRightIFContainGuests=\"False\"\n\t\tWrite-Host \"[-] SeDenyBatchLogonRight value should contains 501(guest account)\" -ForegroundColor Red\n\t}else{\n\t\t$flag=0\n\t\tforeach($sid in ((Write-Output $secInfoArray|Select-String -Pattern \"^SeDenyBatchLogonRight\").ToString().Split(\"=\")[1].Trim()).Split(\",\")){\n\t\t\t$sidSuffix=$sid.Split(\"-\")[-1].ToString()\n\t\t\tif($sidSuffix.Contains(\"501\")){\n\t\t\t\t$seDenyBatchLogonRightIFContainGuests=\"True\"\n\t\t\t\t$flag=1\n\t\t\t}\n\t\t}\n\t\tif(-not $flag){\n\t\t\t$seDenyBatchLogonRightIFContainGuests=\"False\"\n\t\t\tWrite-Host \"[-] SeDenyBatchLogonRight value should contains 501(guest account)\" -ForegroundColor Red\n\t\t}\n\t}\n\t# 确保”拒绝以服务身份登录”值包含“Guest”\n\t$seDenyServiceLogonRightIFContainGuests=(Write-Output $secInfoArray|Select-String -Pattern \"^SeDenyServiceLogonRight\" -Quiet)\n\tif(-not $seDenyServiceLogonRightIFContainGuests){\n\t\t$seDenyServiceLogonRightIFContainGuests=\"False\"\n\t\tWrite-Host \"[-] SeDenyServiceLogonRight value should contains 501(guest account)\" -ForegroundColor Red\n\t}else{\n\t\t$flag=0\n\t\tforeach($sid in ((Write-Output $secInfoArray|Select-String -Pattern \"^SeDenyServiceLogonRight\").ToString().Split(\"=\")[1].Trim()).Split(\",\")){\n\t\t\t$sidSuffix=$sid.Split(\"-\")[-1].ToString()\n\t\t\tif($sidSuffix.Contains(\"501\")){\n\t\t\t\t$seDenyServiceLogonRightIFContainGuests=\"True\"\n\t\t\t\t$flag=1\n\t\t\t}\n\t\t}\n\t\tif(-not $flag){\n\t\t\t$seDenyServiceLogonRightIFContainGuests=\"False\"\n\t\t\tWrite-Host \"[-] SeDenyServiceLogonRight value should contains 501(guest account)\" -ForegroundColor Red\n\t\t}\n\t}\n\t# 确保“拒绝本地登录”值包含“Guests”\n\t$seDenyInteractiveLogonRightIFContainGuests=(Write-Output $secInfoArray|Select-String -Pattern \"^SeDenyInteractiveLogonRight\" -Quiet)\n\tif(-not $seDenyInteractiveLogonRightIFContainGuests){\n\t\t$seDenyInteractiveLogonRightIFContainGuests=\"False\"\n\t\tWrite-Host \"[-] SeDenyInteractiveLogonRight value should contains 501(guest account)\" -ForegroundColor Red\n\t}else{\n\t\t$flag=0\n\t\tforeach($sid in ((Write-Output $secInfoArray|Select-String -Pattern \"^SeDenyInteractiveLogonRight\").ToString().Split(\"=\")[1].Trim()).Split(\",\")){\n\t\t\t$sidSuffix=$sid.Split(\"-\")[-1].ToString()\n\t\t\tif($sidSuffix.Contains(\"501\")){\n\t\t\t\t$seDenyInteractiveLogonRightIFContainGuests=\"True\"\n\t\t\t\t$flag=1\n\t\t\t}\n\t\t}\n\t\tif(-not $flag){\n\t\t\t$seDenyInteractiveLogonRightIFContainGuests=\"False\"\n\t\t\tWrite-Host \"[-] SeDenyInteractiveLogonRight value should contains 501(guest account)\" -ForegroundColor Red\n\t\t}\n\t}\n\t# 确保“从远程强制关机”值为“administrator”本地组s-1-5-32-544和“s-1-5-32-549”（域控的一个内置组）\n\t$seRemoteShutdownPrivilegeIFOnlySpecifiedUserOrArray=(Write-Output $secInfoArray|Select-String \"^SeRemoteShutdownPrivilege\" -Quiet)\n\tif(-not $seRemoteShutdownPrivilegeIFOnlySpecifiedUserOrArray){\n\t\t$seRemoteShutdownPrivilegeIFOnlySpecifiedUserOrArray=\"True\"\n\t}else{\n\t\t$flag=0\n\t\t$count=0\n\t\t$seRemoteShutdownPrivilegeIFOnlySpecifiedUserOrArray=\"\"\n\t\tforeach($sid in ((Write-Output $secInfoArray|Select-String -Pattern \"^SeRemoteShutdownPrivilege\").ToString().Split(\"=\")[1].Trim()).Split(\",\")){\n\t\t\t$count=$count+1\n\t\t\t$sidSuffix=$sid.split(\"-\")[-1].ToString()\n\t\t\t#Write-Host $sidSuffix\n\t\t\t$seRemoteShutdownPrivilegeIFOnlySpecifiedUserOrArray=$seRemoteShutdownPrivilegeIFOnlySpecifiedUserOrArray.ToString()+ $sidSuffix +\";\"\n\t\t\tif($sidSuffix.contains(\"513\") -or $sidSuffix.contains(\"514\") -or $sidSuffix.contains(\"515\") -or $sidSuffix.contains(\"501\")){\n\t\t\t\t$flag=1\n\t\t\t}\n\t\t} \n\t\tif ($flag -or $count -gt 2){\n\t\t\tWrite-Host \"[-] SeRemoteShutdownPrivilege value should only be specified user or group ,cannot be guest ,domain user or domain computer\" -ForegroundColor Red\n\t\t}else{\n\t\t\t$seRemoteShutdownPrivilegeIFOnlySpecifiedUserOrArray=\"True\"\n\t\t}\n\t}\n\t# 确保“修改对象标签”值为空\n\t$seRelabelPrivilegeIFNone=(Write-Output $secInfoArray|Select-String -Pattern \"^SeRelabelPrivilege\" -Quiet)\n\tif(-not $seRelabelPrivilegeIFNone){\n\t\t$seRelabelPrivilegeIFNone=\"True\"\n\t}else{\n\t\t$seRelabelPrivilegeIFNone=(Write-Output $secInfoArray|Select-String -Pattern \"^SeRelabelPrivilege\" ).ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\t\tWrite-Host \"[-] SeRelabelPrivilege value should be None\" -ForegroundColor Red\n\t}\n\t# 确保“同步目录服务数据”值为空\n\t$seSyncAgentPrivilegeIFNone=(Write-Output $secInfoArray|Select-String -Pattern \"^SeSyncAgentPrivilege\" -Quiet)\n\tif(-not $seSyncAgentPrivilegeIFNone){\n\t\t$seSyncAgentPrivilegeIFNone=\"True\"\n\t}else{\n\t\t$seSyncAgentPrivilegeIFNone=(Write-Output $secInfoArray|Select-String -Pattern \"^SeSyncAgentPrivilege\" ).ToString().Split(\"=\")[1] -replace \"\\s\",\"\"\n\t\tWrite-Host \"[-] SeSyncAgentPrivilege value should be None\" -ForegroundColor Red\n\t}\n\t$userright_check_res=\"{\"\"seTrustedCredManAccessPrivilegeIFNone\"\":\"\"$seTrustedCredManAccessPrivilegeIFNone\"\",\"\"seTcbPrivilegeIFNone\"\":\"\"$seTcbPrivilegeIFNone\"\",\"\"seMachineAccountPrivilegeIFOnlySpecifiedUserOrArray\"\":\"\"$seMachineAccountPrivilegeIFOnlySpecifiedUserOrArray\"\",\"\"seCreateGlobalPrivilegeIFNone\"\":\"\"$seCreateGlobalPrivilegeIFNone\"\",\"\"seDenyBatchLogonRightIFContainGuests\"\":\"\"$seDenyBatchLogonRightIFContainGuests\"\",\"\"seDenyServiceLogonRightIFContainGuests\"\":\"\"$seDenyServiceLogonRightIFContainGuests\"\",\"\"seDenyInteractiveLogonRightIFContainGuests\"\":\"\"$seDenyInteractiveLogonRightIFContainGuests\"\",\"\"seRemoteShutdownPrivilegeIFOnlySpecifiedUserOrArray\"\":\"\"$seRemoteShutdownPrivilegeIFOnlySpecifiedUserOrArray\"\",\"\"seRelabelPrivilegeIFNone\"\":\"\"$seRelabelPrivilegeIFNone\"\",\"\"seSyncAgentPrivilegeIFNone\"\":\"\"$seSyncAgentPrivilegeIFNone\"\"}\"\n\t#Write-Host $userright_check_res\n\treturn $userright_check_res\n}\nfunction Get-SecureOptionCheckRes{\n\tParam(\n\t\t[System.Collections.ArrayList]$secInfoArray\n\t)\n\t$stEnableGuestAccount=0\n\t$stLimitBlankPasswordUse=1\n\t$stNewAdministratorName=\"administrator\"\n\t$stNewGuestName=\"guest\"\n\t$stDontDisplayLastUserName=1\n\t$stDisableCAD=0\n\t$stInactivityTimeoutSecs=900\n\t$stEnablePlainTextPassword=0\n\t$stAutoDisconnect=15\n\t$stNoLMHash=1\n\t$stLSAAnonymousNameLookup=0\n\t$stRestrictAnonymousSAM=1\n\t$stRestrictAnonymous=1\n\t$stClearPageFileAtShutdown=0\n\t# 确保“账户：来宾账户状态”值为已禁用\n\t$enableGuestAccount=(Write-Output $secInfoArray|Select-String -Pattern \"^EnableGuestAccount\").ToString().Split(\"=\")[1].Trim()\n\tif($enableGuestAccount -eq $stEnableGuestAccount){\n\t\t$enableGuestAccount=\"False\"\n\t\tWrite-Host \"[-] EnableGuestAccount value should be $stEnableGuestAccount\" -ForegroundColor Red\n\t}else{\n\t\t$enableGuestAccount=\"True\"\n\t}\n\t# 确保“账户：限制使用空密码的本地账户只能使用控制台登录”值为“enabled”\n\t$limitBlankPasswordUse=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\LimitBlankPasswordUse\" -Quiet)\n\tif($limitBlankPasswordUse){\n\t\t$limitBlankPasswordUse=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\LimitBlankPasswordUse\").ToString().Split(\"=\")[1].Split(\",\")[1]\n\t\tif($limitBlankPasswordUse -eq $stLimitBlankPasswordUse){\n\t\t\t$limitBlankPasswordUse=\"True\"\n\t\t}else{\n\t\t\t$limitBlankPasswordUse=\"False\"\n\t\t\tWrite-Host \"[-] LimitBlankPasswordUse value should be $stLimitBlankPasswordUse\" -ForegroundColor Red\n\t\t}\n\t}else{\n\t\t$limitBlankPasswordUse=\"False\"\n\t\tWrite-Host \"[-] LimitBlankPasswordUse value should be $stLimitBlankPasswordUse\" -ForegroundColor Red\n\t}\n\t# 配置“账户：重命名系统管理员账户” True:已重命名；False：未重命名\n\t$newAdministratorName=(Write-Output $secInfoArray|Select-String -Pattern \"^NewAdministratorName\" -Quiet)\n\tif($newAdministratorName){\n\t\t$newAdministratorName=(Write-Output $secInfoArray|Select-String -Pattern \"^NewAdministratorName\").ToString().Split(\"=\")[1].Split(\"\"\"\")[1].Split(\"\"\"\")[0]\n\t\tif($newAdministratorName -eq $stNewAdministratorName){\n\t\t\t$newAdministratorName=\"False\"\n\t\t\tWrite-Host [-] \"NewAdministratorName value should not be $stNewAdministratorName\" -ForegroundColor Red\n\t\t}else{\n\t\t\t$newAdministratorName=\"True\"\n\t\t}\n\t}else{\n\t\t$newAdministratorName=\"False\"\n\t\tWrite-Host [-] \"NewAdministratorName value should not be $stNewAdministratorName\" -ForegroundColor Red\n\t}\n\t# 配置“账户：重命名来宾账户” True:已重命名；False：未重命名\n\t$newGuestName=(Write-Output $secInfoArray|Select-String -Pattern \"^NewGuestName\" -Quiet)\n\tif($newGuestName){\n\t\t$newGuestName=(Write-Output $secInfoArray|Select-String -Pattern \"^NewGuestName\").ToString().Split(\"=\")[1].Split(\"\"\"\")[1].Split(\"\"\"\")[0]\n\t\tif($newGuestName -eq $stNewGuestName){\n\t\t\t$newGuestName=\"False\"\n\t\t\tWrite-Host [-] \"NewGuestName value should not be $stNewGuestName\" -ForegroundColor Red\n\t\t}else{\n\t\t\t$newGuestName=\"True\"\n\t\t}\n\t}else{\n\t\t$newGuestName=\"False\"\n\t\tWrite-Host [-] \"NewGuestName value should not be $stNewGuestName\" -ForegroundColor Red\n\t}\n\t# 确保“交互式登录：不显示上次登录用户名”值为“Enabled”\n\t$dontDisplayLastUserName=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\DontDisplayLastUserName\" -Quiet)\n\tif($dontDisplayLastUserName){\n\t\t$dontDisplayLastUserName=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\DontDisplayLastUserName\").ToString().Split(\"=\")[1].Split(\",\")[1]\n\t\tif($dontDisplayLastUserName -eq $stDontDisplayLastUserName){\n\t\t\t$dontDisplayLastUserName=\"True\"\n\t\t}else{\n\t\t\t$dontDisplayLastUserName=\"False\"\n\t\t\tWrite-Host \"[-] DontDisplayLastUserName value should be $stDontDisplayLastUserName\" -ForegroundColor Red\n\t\t}\n\t}else{\n\t\t$dontDisplayLastUserName=\"False\"\n\t\tWrite-Host \"[-] DontDisplayLastUserName value should be $stDontDisplayLastUserName\" -ForegroundColor Red\n\t}\n\t# 确保”交互式登录：无需按Ctrl+Alt+Del”值为“Disabled”\n\t$disableCAD=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\DisableCAD\" -Quiet)\n\tif($disableCAD){\n\t\t$disableCAD=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\DisableCAD\").ToString().Split(\"=\")[1].Split(\",\")[1]\n\t\tif($disableCAD -eq $stDisableCAD){\n\t\t\t$disableCAD=\"True\"\n\t\t}else{\n\t\t\t$disableCAD=\"False\"\n\t\t\tWrite-Host \"[-] DisableCAD value should be $stDisableCAD\" -ForegroundColor Red\n\t\t}\n\t}else{\n\t\t$disableCAD=\"False\"\n\t\tWrite-Host \"[-] DisableCAD value should be $stDisableCAD\" -ForegroundColor Red\n\t}\n\t# 确保“交互式登录：计算机不活动限制”值为900或更少 False:该项值不存在\n\t$inactivityTimeoutSecs=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\InactivityTimeoutSecs\" -Quiet)\n\tif($inactivityTimeoutSecs){\n\t\t$inactivityTimeoutSecs=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\InactivityTimeoutSecs\").ToString().Split(\"=\")[1].Split(\",\")[1]\n\t\tif($inactivityTimeoutSecs -gt $stInactivityTimeoutSecs){\n\t\t\tWrite-Host \"[-] InactivityTimeoutSecs value should less than $stInactivityTimeoutSecs\" -ForegroundColor Red\n\t\t}\n\t}else{\n\t\tWrite-Host \"[-] InactivityTimeoutSecs value should less than $stInactivityTimeoutSecs\" -ForegroundColor Red\n\t\t$inactivityTimeoutSecs=\"False\"\n\t}\n\t# 确保“Microsoft网络客户端：将未加密的密码发送到第三方SMB服务器”值为“Disabled”\n\t$enablePlainTextPassword=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\LanmanWorkstation\\\\Parameters\\\\EnablePlainTextPassword\" -Quiet)\n\tif($enablePlainTextPassword){\n\t\t$enablePlainTextPassword=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\LanmanWorkstation\\\\Parameters\\\\EnablePlainTextPassword\").ToString().Split(\"=\")[1].Split(\",\")[1]\n\t\tif($enablePlainTextPassword -eq $stEnablePlainTextPassword){\n\t\t\t$enablePlainTextPassword=\"True\"\n\t\t}else{\n\t\t\t$enablePlainTextPassword=\"False\"\n\t\t\tWrite-Host \"[-] EnablePlainTextPassword value should be $stEnablePlainTextPassword\" -ForegroundColor Red\n\t\t}\n\t}else{\n\t\t$enablePlainTextPassword=\"False\"\n\t\tWrite-Host \"[-] EnablePlainTextPassword value should be $stEnablePlainTextPassword\" -ForegroundColor Red\n\t}\n\t# 确保“Microsoft网络服务器：暂停会话前所需的空闲时间数量”值为15分钟或更少，但不为0 False:该项值不存在\n\t$autoDisconnect=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\LanmanWorkstation\\\\Parameters\\\\AutoDisconnect\" -Quiet)\n\tif($autoDisconnect){\n\t\t$autoDisconnect=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\LanmanWorkstation\\\\Parameters\\\\AutoDisconnect\").ToString().Split(\"=\")[1].Split(\",\")[1]\n\t\tif($autoDisconnect -gt $stAutoDisconnect){\n\t\t\tWrite-Host \"[-] InactivityTimeoutSecs value should less than $stInactivityTimeoutSecs\" -ForegroundColor Red\n\t\t}\n\t}else{\n\t\t$autoDisconnect=\"False\"\n\t\tWrite-Host \"[-] AutoDisconnect value should be $stAutoDisconnect\" -ForegroundColor Red\n\t}\n\t# 确保“网络安全：在下一次改变密码时不存储LAN管理器哈希值”值为“Enabled”\n\t$noLMHash=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\NoLMHash\" -Quiet)\n\tif($noLMHash){\n\t\t$noLMHash=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\NoLMHash\").ToString().Split(\"=\")[1].Split(\",\")[1]\n\t\tif($noLMHash -eq $stNoLMHash){\n\t\t\t$noLMHash=\"True\"\n\t\t}else{\n\t\t\t$noLMHash=\"False\"\n\t\t\tWrite-Host \"[-] NoLMHash value should be $stNoLMHash\" -ForegroundColor Red\n\t\t}\n\t}else{\n\t\t$noLMHash=\"False\"\n\t\tWrite-Host \"[-] NoLMHash value should be $stNoLMHash\" -ForegroundColor Red\n\t}\n\t# 确保“网络访问：允许匿名SID/名称转换”值为“Disabled\" False:Disabled True:Enabled\n\t$lsaAnonymousNameLookup=(Write-Output $secInfoArray|Select-String -Pattern \"LSAAnonymousNameLookup\" -Quiet)\n\tif($lsaAnonymousNameLookup){\n\t\t$lsaAnonymousNameLookup=(Write-Output $secInfoArray|Select-String -Pattern \"LSAAnonymousNameLookup\").ToString().Split(\"=\")[1].Trim()\n\t\tif($lsaAnonymousNameLookup -eq $stLSAAnonymousNameLookup){\n\t\t\t$lsaAnonymousNameLookup=\"False\"\n\t\t}else{\n\t\t\t$lsaAnonymousNameLookup=\"True\"\n\t\t\tWrite-Host \"[-] LSAAnonymousNameLookup value should be $stLSAAnonymousNameLookup\" -ForegroundColor Red\n\t\t}\n\t}else{\n\t\t$lsaAnonymousNameLookup=\"True\"\n\t\tWrite-Host \"[-] LSAAnonymousNameLookup value should be $stLSAAnonymousNameLookup\" -ForegroundColor Red\n\t}\n\t# 确保“网络访问：不允许SAM账户的匿名枚举”值为“Enabled”\n\t$restrictAnonymousSAM=(Write-Output $secInfoArray|Select-String -Pattern \"^MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\RestrictAnonymousSAM\" -Quiet)\n\tif($restrictAnonymousSAM){\n\t\t$restrictAnonymousSAM=(Write-Output $secInfoArray|Select-String -Pattern \"^MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\RestrictAnonymousSAM\").ToString().Split(\"=\")[1].Split(\",\")[1]\n\t\tif($restrictAnonymousSAM -eq $stRestrictAnonymousSAM){\n\t\t\t$restrictAnonymousSAM=\"True\"\n\t\t}else{\n\t\t\t$restrictAnonymousSAM=\"False\"\n\t\t\tWrite-Host \"[-] RestrictAnonymousSAM value should be $stRestrictAnonymousSAM\" -ForegroundColor Red\n\t\t}\n\t}else{\n\t\t$restrictAnonymousSAM=\"False\"\n\t\tWrite-Host \"[-] RestrictAnonymousSAM value should be $stRestrictAnonymousSAM\" -ForegroundColor Red\n\t}\n\t# 确保“网络访问：不允许SAM账户和共享的匿名枚举”值为“Enabled”\n\t$restrictAnonymous=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\RestrictAnonymous=\" -Quiet)\n\tif($restrictAnonymous){\n\t\t$restrictAnonymous=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\RestrictAnonymous=\").ToString().Split(\"=\")[1].Split(\",\")[1]\n\t\tif($restrictAnonymous -eq $stRestrictAnonymous){\n\t\t\t$restrictAnonymous=\"True\"\n\t\t}else{\n\t\t\t$restrictAnonymous=\"False\"\n\t\t\tWrite-Host \"[-] RestrictAnonymous value should be $stRestrictAnonymous\" -ForegroundColor Red\n\t\t}\n\t}else{\n\t\t$restrictAnonymous=\"False\"\n\t\tWrite-Host \"[-] RestrictAnonymous value should be $stRestrictAnonymous\" -ForegroundColor Red\n\t}\n\t# 确保“关机：允许系统在未登录前关机”值未“Disabled”\n\t$clearPageFileAtShutdown=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Session Manager\\\\Memory Management\\\\ClearPageFileAtShutdown\" -Quiet)\n\tif($clearPageFileAtShutdown){\n\t\t$clearPageFileAtShutdown=(Write-Output $secInfoArray|Select-String -Pattern \"MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Session Manager\\\\Memory Management\\\\ClearPageFileAtShutdown\").ToString().Split(\"=\")[1].Split(\",\")[1]\n\t\tif($clearPageFileAtShutdown -eq $stClearPageFileAtShutdown){\n\t\t\t$clearPageFileAtShutdown=\"False\"\n\t\t}else{\n\t\t\t$clearPageFileAtShutdown=\"True\"\n\t\t\tWrite-Host \"[-] ClearPageFileAtShutdown value should be $stClearPageFileAtShutdown\" -ForegroundColor Red\n\t\t}\n\t}else{\n\t\t$clearPageFileAtShutdown=\"True\"\n\t\tWrite-Host \"[-] ClearPageFileAtShutdown value should be $stClearPageFileAtShutdown\" -ForegroundColor Red\n\t}\n\t$secureoption_check_res=\"{\"\"enableGuestAccount\"\":\"\"$enableGuestAccount\"\",\"\"limitBlankPasswordUse\"\":\"\"$limitBlankPasswordUse\"\",\"\"newAdministratorName\"\":\"\"$newAdministratorName\"\",\"\"newGuestName\"\":\"\"$newGuestName\"\",\"\"dontDisplayLastUserName\"\":\"\"$dontDisplayLastUserName\"\",\"\"disableCAD\"\":\"\"$disableCAD\"\",\"\"inactivityTimeoutSecs\"\":\"\"$inactivityTimeoutSecs\"\",\"\"enablePlainTextPassword\"\":\"\"$enablePlainTextPassword\"\",\"\"autoDisconnect\"\":\"\"$autoDisconnect\"\",\"\"noLMHash\"\":\"\"$noLMHash\"\",\"\"lsaAnonymousNameLookup\"\":\"\"$lsaAnonymousNameLookup\"\",\"\"restrictAnonymousSAM\"\":\"\"$restrictAnonymousSAM\"\",\"\"restrictAnonymous\"\":\"\"$restrictAnonymous\"\",\"\"clearPageFileAtShutdown\"\":\"\"$clearPageFileAtShutdown\"\"}\"\n\n\treturn $secureoption_check_res\n}\n\nfunction Get-PortSecureCheckRes{\n\t$key=\"HKLM\\SYSTEM\\CurrentControlSet\\Control\\Terminal server\\WinStations\\RDP-Tcp\"\n\t$name=\"Portnumber\"\n\t$rdpPort=(Get-ItemProperty -Path \"Registry::$key\" -ErrorAction:SilentlyContinue).$name\n\tif($rdpPort -eq \"3389\"){\n\t\tWrite-Host \"[-] RDPPort should not be 3389\" -ForegroundColor Red\n\t}\n\t$portsecure_check_res=\"{\"\"rdpPort\"\":\"\"$rdpPort\"\"}\"\n\treturn $portsecure_check_res\n}\nfunction Get-SystemSecureCheckRes{\n\t$key=\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\"\n\t$name=\"NoDriveTypeAutoRun\"\n\t$autoRunRes=(Get-ItemProperty -Path \"Registry::$key\" -ErrorAction:SilentlyContinue).$name\n\tif(-not $autoRunRes){\n\t\t$autoRunRes=\"False\"\n\t}\n\t$systemsecure_check_res=\"{\"\"autoRunRes\"\":\"\"$autoRunRes\"\"}\"\n\treturn $systemsecure_check_res\n}\n\n\nWrite-Host \"==================================\"\nWrite-Host \"|       Windows baseline check   |\"\nWrite-Host \"|         Author:JC0o0l          |\"\nWrite-Host \"|         version:2.0            |\"\nWrite-Host \"|         Mail:jerryzvs@163.com  |\"\nWrite-Host \"==================================\"\n$basic_info=Get-BasicInfo\n$secInfoArray=Get-SecInfo\n$account_check_res=Get-AccountPolicyCheckRes $secInfoArray\n#Write-Host $account_check_res\n$audit_check_res=Get-AuditPolicyCheckRes $secInfoArray\n#Write-Host $audit_check_res\n$userright_check_res=Get-UserRightPolicyCheckRes $secInfoArray\n#Write-Host $userright_check_res\n$secureoption_check_res=Get-SecureOptionCheckRes $secInfoArray\n#Write-Host $secureoption_check_res\n$portsecure_check_res=Get-PortSecureCheckRes\n#Write-Host $portsecure_check_res\n$systemsecure_check_res=Get-SystemSecureCheckRes\n#Write-Host $systemsecure_check_res\n\n#$window_check_res=\"{\"\"secInfoArray\"\":$secInfoArray,\"\"account_check_res\"\":$account_check_res,\"\"audit_check_res\"\":$audit_check_res,\"\"userright_check_res\"\":$userright_check_res,\"\"secureoption_check_res\"\":$secureoption_check_res,\"\"portsecure_check_res\"\":$portsecure_check_res,\"\"systemsecure_check_res\"\":$systemsecure_check_res}\"\n$window_check_res=\"{\"\"basic_info\"\":$basic_info,\"\"account_check_res\"\":$account_check_res,\"\"audit_check_res\"\":$audit_check_res,\"\"userright_check_res\"\":$userright_check_res,\"\"secureoption_check_res\"\":$secureoption_check_res,\"\"portsecure_check_res\"\":$portsecure_check_res,\"\"systemsecure_check_res\"\":$systemsecure_check_res}\"\n#Write-Host $window_check_res\nInvoke-RestMethod -Uri \"http://192.168.3.24:8888/baseline/windows_scan_res_report/\" -Method Post -ContentType \"application/json\" -Body $window_check_res"
  }
]