类别:软件配置 / 日期:2020-04-29 / 浏览:6273 / 评论:3
1、准备工作
准备最新的elasticsearch的源代码:https://github.com/elastic/elasticsearch/releases
准备和elasticsearch版本对应的安装包:https://www.elastic.co/cn/downloads/elasticsearch
2、修改源代码中的两处文件
解压源代码后。
首先修改在 \x-pack\plugin\core\src\main\java\org\elasticsearch\license 目录下修改用于认证的代码文件LicenseVerifier.java。
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.license;
/**
* Responsible for verifying signed licenses
*/
public class LicenseVerifier {
/**
* verifies the license content with the signature using the packaged
* public key
* @param license to verify
* @return true if valid, false otherwise
*/
public static boolean verifyLicense(final License license, byte[] publicKeyData) {
return true;
}
public static boolean verifyLicense(final License license) {
return true;
}
}然后修改 \x-pack\plugin\core\src\main\java\org\elasticsearch\xpack\core 目录下修改用于校验包的代码文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;
public class XPackBuild {
public static final XPackBuild CURRENT;
static {
CURRENT = new XPackBuild("Unknown", "Unknown");
}
/**
* 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;
}
}3、重新编译
解压我们下载的对应版本的elasticsearc的安装包,这里以7.6.2版本为例,使用javac重新编译LicenseVerifier.java,并在当前目录下生成LicenseVerifier.class:
javac -cp "/root/es/elasticsearch-7.6.2/modules/x-pack-core/x-pack-core-7.6.2.jar:/root/es/elasticsearch-7.6.2/lib/*" LicenseVerifier.java
继续编译XPackBuild.java,并生成XPackBuild.class:
javac -cp "/root/es/elasticsearch-7.6.2/modules/x-pack-core/x-pack-core-7.6.2.jar:/root/es/elasticsearch-7.6.2/lib/*" XPackBuild.java
上面需要注意的是,我们要找一台安装了java的Liunx系统去编译,Windows下测试会出现找不到符号的错误。
4、重新打包
解压我们刚才打包用到的x-pack-core-7.6.2.jar,并将生成的LicenseVerifier.class和XPackBuild.class替换解压后的文件。
替换 \org\elasticsearch\license 目录下的LicenseVerifier.class。
替换 \org\elasticsearch\xpack\core 目录下的XPackBuild.class。
重新打包,其中x-pack-core-7.6.2/META-INF/MANIFEST.MF是我们清单的位置:
jar cvfm x-pack-core-7.6.2_new.jar x-pack-core-7.6.2/META-INF/MANIFEST.MF -C x-pack-core-7.6.2/ .
5、覆盖文件
将我们刚才生成的x-pack-core-7.6.2_new.jar 改名成我们对应的es版本x-pack-core-7.x.x.jar,并替换我们es安装路径 /modules/x-pack-core/ 中的同名文件。
6、更新许可证
首先去官网申请license。
使用文本编辑器打开申请到的license,修改下面的内容:
把type修改为platinum
把expiry_date_in_millis这个时间戳修改的大一点
max_nodes这个最大的节点数也可以调大点
然后更新我们的许可证:
curl -u elastic:elastic -XPUT ‘http://{es-ip}:{es-port}/_xpack/license’ -H “Content-Type: application/json” -d @/tmp/license.json恭喜,至此我们完成了所有白嫖过程!
顺便提供下7.6.2版本生成的那两个class文件的下载:
crack.zip


共有 3 条评论
发表评论 /