关于现在的 log4j2 漏洞的系统变量缓解方法 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
plasmetoz
V2EX    Java

关于现在的 log4j2 漏洞的系统变量缓解方法

  •  
  •   plasmetoz 2021-12-10 16:06:26 +08:00 4450 次点击
    这是一个创建于 1403 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我查到的是

    临时缓解措施:
    1. 禁止没有必要的业务访问外网
    2. 使用 jvm 参数启动 -Dlog4j2.formatMsgNoLookups=true
    3. 设置 log4j2.formatMsgNoLookups=True
    4. 系统环境变量中将 FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS 设置为 true

    但是我测试 4 在 linux 下 export FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS=true 好像不起作用,查看 log4j2 代码里面

    @Deprecated
    public static final boolean FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS = PropertiesUtil.getProperties().getBooleanProperty("log4j2.formatMsgNoLookups", true);

    似乎也只是变量名称。。。是我理解错了吗?
    12 条回复    2021-12-12 14:30:17 +08:00
    vast0906
        1
    vast0906  
       2021-12-10 16:09:13 +08:00
    官方的 release 包似乎正在发布
    plasmetoz
        2
    plasmetoz  
    OP
       2021-12-10 16:10:55 +08:00
    @vast0906 #1 是,但是现在打算先紧急维护一下,以为方法 4 用了以后把 java 服务全重启一下就行了,结果好像不行
    zhady009
        3
    zhady009  
       2021-12-10 16:18:32 +08:00   1
    可以试试改 pattern 把%m 或者%msg 改成%m{nolookup}
    cheng6563
        4
    cheng6563  
       2021-12-10 16:24:24 +08:00   2
    用这个吧 JAVA_TOOL_OPTIOnS=-Dlog4j2.formatMsgNoLookups=true
    plasmetoz
        5
    plasmetoz  
    OP
       2021-12-10 16:29:44 +08:00
    @cheng6563 #4 多谢,这个看起来可以
    wbd31
        6
    wbd31  
       2021-12-10 16:54:00 +08:00   1
    formatMsgNoLookups 这个参数是 2.10 版本才加上的,对于之前同样受漏洞影响的版本无效
    td width="10" valign="top">
    silverfox
        7
    silverfox  
       2021-12-11 01:20:33 +08:00   1
    @zhady009 这里少了一个 s ,应该是改为 %m{nolookups}
    huage
        8
    huage  
       2021-12-11 21:42:20 +08:00
    Remediation Advice:

    This issue was remediated in Log4J v2.15.0. The Apache Logging Services team provides the following mitigation advice:

    In previous releases (>=2.10) this behavior can be mitigated by setting system property "log4j2.formatMsgNoLookups" to “true” or by removing the JndiLookup class from the classpath (example: zip -q -d log4j-core-*.jar org/apache/logging/log4j/core/lookup/JndiLookup.class). Java 8u121 protects against RCE by defaulting "com.sun.jndi.rmi.object.trustURLCodebase" and "com.sun.jndi.cosnaming.object.trustURLCodebase" to "false".

    You can manually check for use of affected versions of Log4J by searching your project repository for Log4J use, which is often in a pom.xml file.

    Where possible, upgrade to Log4J version 2.15.0. If you are using Log4J v1 there is a migration guide available.

    Please note that Log4J v1 is End Of Life (EOL) and will not receive patches for this issue. Log4J v1 is also vulnerable to other RCE vectors and we recommend you migrate to Log4J 2.15.0 where possible.

    If upgrading is not possible, then ensure the -Dlog4j2.formatMsgNoLookups=true system property is set on both client- and server-side components.
    troywinter
        9
    troywinter  
       2021-12-11 23:27:42 +08:00
    JDK versions greater than 6u211, 7u201, 8u191, and 11.0.1 are not affected by the LDAP attack vector. In these versions com.sun.jndi.ldap.object.trustURLCodebase is set to false meaning JNDI cannot load a remote codebase using LDAP.
    44670
        10
    44670  
       2021-12-12 03:00:50 +08:00
    LOG4J_FORMAT_MSG_NO_LOOKUPS=true 似乎也可以
    https://logging.apache.org/log4j/2.x/security.html

    感觉 FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS 是国内的以讹传讹。
    44670
        12
    44670  
       2021-12-12 14:30:17 +08:00
    @Kaiv2 看来是 log4j 的文档就写错了,好怪。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     3297 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 36ms UTC 11:29 PVG 19:29 LAX 04:29 JFK 07:29
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86