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使用 。
- 成功破解后权限什么的都有,监控等等,登录界面已有。