ES Xpack破解的關鍵步驟在於x-pack-core-xxx.jar包中的Liscense驗證文件替換。需要替換的文件共兩個XPackBuild .class和LicenseVerifier.class。從6.3版本開始,ES已將Xpack的源碼公佈出來,以下兩個新建文件,也可在GItHUb上找到ES6.3源碼。
- 新建XPackBuild .java文件:
package org.elasticsearch.xpack.core; import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.io.PathUtils; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.util.jar.JarInputStream; import java.util.jar.Manifest; /** * Information about the built version of x-pack that is running. */ public class XPackBuild { public static final XPackBuild CURRENT; static { final String shortHash; final String date; Path path = getElasticsearchCodebase(); if (path.toString().endsWith(".jar")) { /** try (JarInputStream jar = new JarInputStream(Files.newInputStream(path))) { Manifest manifest = jar.getManifest(); shortHash = manifest.getMainAttributes().getValue("Change"); date = manifest.getMainAttributes().getValue("Build-Date"); } catch (IOException e) { throw new RuntimeException(e); }*/ shortHash = null; date = null; } else { // not running from a jar (unit tests, IDE) shortHash = "Unknown"; date = "Unknown"; } CURRENT = new XPackBuild(shortHash, date); } /** * Returns path to xpack codebase path */ @SuppressForbidden(reason = "looks up path of xpack.jar directly") static Path getElasticsearchCodebase() { URL url = XPackBuild.class.getProtectionDomain().getCodeSource().getLocation(); try { return PathUtils.get(url.toURI()); } catch (URISyntaxException bogus) { throw new RuntimeException(bogus); } } private String shortHash; private String date; XPackBuild(String shortHash, String date) { this.shortHash = shortHash; this.date = date; } public String shortHash() { return shortHash; } public String date() { return date; } }
- 新建文件LicenseVerifier.java:
package org.elasticsearch.license; import java.nio.*; import java.util.*; import java.security.*; import org.elasticsearch.common.xcontent.*; import org.apache.lucene.util.*; import org.elasticsearch.common.io.*; import java.io.*; public class LicenseVerifier { public static boolean verifyLicense(final License license, final byte[] encryptedPublicKeyData) { return true; } public static boolean verifyLicense(final License license) { return true; } }
- 將以上兩個文件在CMD中編譯成class文件(直接在java文件所在的目錄打開CMD,並將此命令中jar包的位置替換成自己電腦中的相應位置即可):
編譯命令 編譯LicenseVerifier.java文件 javac -cp "/e:/soft/elasticsearch-6.3.0/lib/elasticsearch-6.3.0.jar;/e:/soft/elasticsearch-6.3.0/lib/lucene-core-7.3.1.jar;/e:/soft/elasticsearch-6.3.0/modules/x-pack/x-pack-core/x-pack-core-6.3.0.jar" LicenseVerifier.java
編譯XPackBuild.java.java文件 javac -cp "/e:/soft/elasticsearch-6.3.0/lib/elasticsearch-6.3.0.jar;/e:/soft/elasticsearch-6.3.0/lib/lucene-core-7.3.1.jar;/e:/soft/elasticsearch-6.3.0/modules/x-pack/x-pack-core/x-pack-core-6.3.0.jar;/e:/soft/elasticsearch-6.3.0/lib/elasticsearch-core-6.3.0.jar" XPackBuild.java
- 將編譯好的class文件替換到x-pack-core-6.3.0.jar中,直接使用jar工具打開此jar包,是打開不是解壓,然後將以上兩個生成的class文件放到對應的包中,具體路徑可以看一下源文件的package。
- 以上4步便是文件替換的步驟,至於其他的步驟大家可以參考網上的教程,例如,我就參考了這一片文章elasticsearch6.3.2之x-pack6.3.2破解安裝並配合kibana使用 。
- 成功破解後權限什麼的都有,監控等等,登錄界面已有。