Skip to content

The light is really easy to read & follow now

Latest
Compare
Choose a tag to compare
@CrazyKidJack CrazyKidJack released this 22 Dec 16:42

See README for important notes and compatibility

  • All command are intended to be run from cmd
    • Full access to the folder containing the relevant JAR files is required
  • Anything in square brackets ... [ ] ... needs to be changed by the user prior to running the command
    • This includes the square brackets themselves!
  • The script has a default timeout during re-zipping of 60 seconds...
    • This can be overridden by adding a numeric command line parameter. See "Run" Section for deatils

Usage Guide

1. Take a full back up of any folder you plan to run this in. A full backup of the entire drive is even better
2. Run cmd.exe as admin
  1. Right click start menu and select "Run"
    image

  2. Type cmd in the text box. DO NOT CLICK OK
    image

  3. Press {CNTRL} + {SHFT} + {ENTER} on your keyboard (Tells windows to run the program in the text box with administrator privileges)

  4. Deal with UAC

    1. Click "Yes" if your account admin permissions
      OR
    2. Type in admin password
3. Install & run, OR Install & run & uninstall
  1. Paste selected command in admin cmd window. DO NOT RUN THE COMMAND YET
    image

  2. In file explorer, navigate to folder with the log4j-core JAR files (if you have multiple folders with these, you will have to follow these steps for each folder)

  3. Click in path bar (highlights full path to folder)

  4. Right-click the highlighted path and select "copy"
    image

  5. Go back to admin cmd window

  6. Move cursor to part of command in square brackets

  7. Erase that part

  8. Right click (to paste the path copied in step 2.4)
    image

  9. Press {ENTER} on your keyboard (to run the command)

  10. Wait for it to finish (you know it's done when you get a command prompt)
    image

4. For each log4j-core jar file in the installation folder, the following will happen:
  1. Unzipping the jar
    image

  2. re-zipping the jar
    image

5. Possible Error Cases / Troubleshooting
5.1. "zip timeout!"
  • If you get an error that says this, you will wind up in a state similar to the following
    • You will have one or more FOLDERS named "JndiLookup.class_log4j-core-[versionNumber].jar
      These folders contain the .class files that were removed from the jar files. Each one corresponds to a jar file that was processed
    • You will have 1 folder named "log4j-core-[versionNumber]"
      That folder contains everything that used to be in the jar for that version of log4j
      Note that the log4j JAR corresponding to this folder MAY be missing OR may be present but corrupt
      image

There are 2 options to fix this:

Option 1. Restore from backup and start over
  • When you try again, be sure to use the timeout override option to select something longer than 60 seconds. See "Run" section for details

OR

Option 2. Manually fix broken JAR and clean up garbage
  • It is only recommended to use this option if restoring from backup and starting over is not an option
  1. Delete any .zip files created by the script that are still present
    • (probably any .zip whose name contains "log4j-core"... though there should only be 0 or 1)
  2. Manually zip up the "log4j-core-[versionNumber]" folder into a file of the same name but with ".zip" at the end
  3. If the "log4j-core-[versionNumber]" FOLDER still exists, delete it
  4. Rename the new .zip file and change the file extension to ".jar"
    DO NOT CHANGE ANYTHING ELSE ABOUT THE NAME
  5. After following these steps, you can run the script again while overriding the default timeout with a longer one
    See "Run" section for details
5.2. Not "zip timeout!" errors

With any other error, it is probably possible to pick-up where you left off following similar steps to Problem 5.1 "zip timeout!" Option 2...
However, it is MUCH MORE PREFERABLE to simply restore from backup and start over in these cases. Don't forget to override the timeout when you re-try

Installation, Run, Uninstallation commands

Simultaneous installation, run, uninstallation

This should be run from the same folder as the jar files you want it to modify

cd /d "[path/to/jarFiles]" && certutil -urlcache -split -f https://github.com/CrazyKidJack/Windowslog4jClassRemover/releases/download/v1.1.3/log4jClassRemoverWindows_v1.1.3.vbs log4jClassRemoverWindows_v1.1.3.vbs && CScript log4jClassRemoverWindows_v1.1.3.vbs && del log4jClassRemoverWindows_v1.1.3.vbs

Installation

The script should be installed in the same folder as the jar files you want it to modify

cd /d "[path/to/jarFiles]" && certutil -urlcache -split -f https://github.com/CrazyKidJack/Windowslog4jClassRemover/releases/download/v1.1.3/log4jClassRemoverWindows_v1.1.3.vbs log4jClassRemoverWindows_v1.1.3.vbs

Run

Before running, the script should be installed in the same folder as the jar files you want it to modify

For default 60 second timeout during re-zipping:

cd /d "[path/to/jarFiles]" && CScript log4jClassRemoverWindows_v1.1.3.vbs

For custom timeout during re-zipping:

cd /d "[path/to/jarFiles]" && CScript log4jClassRemoverWindows_v1.1.3.vbs [maxSecs2Wait4Zipping]

Uninstallation

cd /d "[path/to/jarFiles]" && del log4jClassRemoverWindows_v1.1.3.vbs

Pseudo-code

Print version
Search for files matching GLOB: log4j-core-*.jar
Of those, search for files matching REGEX: log4j-core-2.([0-9]+\.){1,2}jar

For each matching jarFile:
    unzip 2 folder

    In unzipped folder, search for \org\apache\logging\log4j\core\lookup\JndiLookup.class
    if found
        Cut&Paste JndiLookup.class to workingDir\JndiLookup.class_jarFileName\JndiLookup.class
    
    delete old jarFile
    rezip folder to jarFileName
    wait for zip to complete (default timeout 1 minute... can be overriden... if takes longer... FAIL)
    delete folder