Elasticsearch6.x-xpack破解

去掉license校驗

下載luyten反編譯JAVA工具

luyent打開Elasticsearch目錄下的modules/x-pack-core/x-pack-core-x.x.x.jar

找到 org.elasticsearch.license.LicenseVerifier文件,提取出來做以下修改:
LicenseVerifier 中有兩個靜態方法,這就是驗證授權文件是否有效的方法,我們把它修改爲全部返回true.

package org.elasticsearch.license;

import java.nio.*;
import org.elasticsearch.common.bytes.*;
import java.util.*;
import java.security.*;
import org.elasticsearch.common.xcontent.*;
import org.apache.lucene.util.*;
import org.elasticsearch.core.internal.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;
    }
}

打開org.elasticsearch.xpack.core.XPackBuild文件,提取出來做以下修改:
XPackBuild 中最後一個靜態代碼塊中 try的部分全部刪除,這部分會驗證jar包是否被修改.

package org.elasticsearch.xpack.core;

import org.elasticsearch.common.io.*;
import java.net.*;
import org.elasticsearch.common.*;
import java.nio.file.*;
import java.io.*;
import java.util.jar.*;

public class XPackBuild
{
    public static final XPackBuild CURRENT;
    private String shortHash;
    private String date;

    @SuppressForbidden(reason = "looks up path of xpack.jar directly")
    static Path getElasticsearchCodebase() {
        final URL url = XPackBuild.class.getProtectionDomain().getCodeSource().getLocation();
        try {
            return PathUtils.get(url.toURI());
        }
        catch (URISyntaxException bogus) {
            throw new RuntimeException(bogus);
        }
    }

    XPackBuild(final String shortHash, final String date) {
        this.shortHash = shortHash;
        this.date = date;
    }

    public String shortHash() {
        return this.shortHash;
    }

    public String date() {
        return this.date;
    }

    static {
        final Path path = getElasticsearchCodebase();
        String shortHash = null;
        String date = null;
        Label_0157: {
            shortHash = "Unknown";
            date = "Unknown";
        }
        CURRENT = new XPackBuild(shortHash, date);
    }
}

進入上面兩個文件的目錄,編譯這兩個修改的文件

javac -cp ".:{es的源碼路徑}/modules/x-pack-core/x-pack-core-x.x.x.jar:{es的源碼路徑}/lib/*" LicenseVerifier.java
javac -cp ".:{es的源碼路徑}/modules/x-pack-core/x-pack-core-x.x.x.jar:{es的源碼路徑}/lib/*" XPackBuild.java

編譯後會生成兩個文件 LicenseVerifier.classXPackBuild.class

解壓{es的源碼路徑}/modules/x-pack-core/x-pack-core-x.x.x.jar,進入解壓後路徑,然後將上面生成的兩個文件覆蓋進去,然後執行打包命令

cd ..
jar -cvf x-pack-core-x.x.x_new.jar -C x-pack-core-x.x.x .

將新包重命名爲x-pack-core-x.x.x.jar,然後覆蓋{es的源碼路徑}/modules/x-pack-core/x-pack-core-x.x.x.jar

這樣我們的去掉license校驗就完成了。

導入license

首先去官網申請license

打開license文件,修改以下字段

"expiry_date_in_millis": {過期時間時間戳}
"max_nodes": {最大節點數}

導入到elasticsearch

curl -u elastic:elastic -XPUT ‘http://{es-ip}:{es-port}/_xpack/license’ -H “Content-Type: application/js
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章