简介: x-pack是elasticsearch的一个收费的扩展包,将权限管理,警告,监视等功能捆绑在一个易于安装的软件包中,x-pack被设计为一个无缝的工作,但是你可以轻松的启用或者关闭一些功能。如果购买商业版需要每年支付十多万。为了使用几个不可或缺功能而花大钱去购买,有点不值得,特别是对于中小型企业来说。所以我在这里主要通过如何破解来启用x-pack的一些功能,本文章仅供技术分享,禁止商业用途!

反编译

x-pack是收费项目,想启动它需要破解,本文以7.X 版本为例进行破解。

x-pack从6.4版本后就内置在elasticsearch中,使用只需要把配置打开即可(官方有30天的试用期)。

x-pack的lisence校验在elasticsearch-7.0.0/modules/x-pack-core的x-pack-core-7.0.0.jar中,破解之前需要用反编译工具(如:JD-GUI)把jar打开源码出来,我这里使用idea反编译。

修改X-pack相关源码

x-pack的lisence的校验主要是这两个文件:

  1. 验证licence是否有效:org.elasticsearch.license.LicenseVerifier
  2. 验证jar包是否被修改:org.elasticsearch.xpack.core.XPackBuild

反编译源码出来后需要把这两个类的源码提取出来放到新创建同名的java文件里,此时这两个类引用的java类很多不识别怎么办?需要把elasticsearch相关的jar包引进来,然后就可以编译替换目标class了。

修改LicenseVerifier.java

两个静态方法修改为全部返回true

改前
package org.elasticsearch.license;
 
import java.nio.*;
import org.elasticsearch.common.bytes.*;
import java.security.*;
import java.util.*;
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[] publicKeyData) {
        byte[] signedContent = null;
        byte[] publicKeyFingerprint = null;
        try {
            final byte[] signatureBytes = Base64.getDecoder().decode(license.signature());
            final ByteBuffer byteBuffer = ByteBuffer.wrap(signatureBytes);
            final int version = byteBuffer.getInt();
            final int magicLen = byteBuffer.getInt();
            final byte[] magic = new byte[magicLen];
            byteBuffer.get(magic);
            final int hashLen = byteBuffer.getInt();
            publicKeyFingerprint = new byte[hashLen];
            byteBuffer.get(publicKeyFingerprint);
            final int signedContentLen = byteBuffer.getInt();
            signedContent = new byte[signedContentLen];
            byteBuffer.get(signedContent);
            final XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON);
            license.toXContent(contentBuilder, (ToXContent.Params)new ToXContent.MapParams((Map)
            Collections.singletonMap("license_spec_view""true")));
            final Signature rsa = Signature.getInstance("SHA512withRSA");
            rsa.initVerify(CryptUtils.readPublicKey(publicKeyData));
            final BytesRefIterator iterator = BytesReference.bytes(contentBuilder).iterator();
            BytesRef ref;
            while ((ref = iterator.next()) != null) {
                rsa.update(ref.bytes, ref.offset, ref.length);
            }
            return rsa.verify(signedContent);
        }
        catch (IOException ex) {}
        catch (NoSuchAlgorithmException ex2) {}
        catch (SignatureException ex3) {}
        catch (InvalidKeyException e) {
            throw new IllegalStateException(e);
        }
        finally {
            if (signedContent != null) {
                Arrays.fill(signedContent, (byte)0);
            }
        }
           }
     
    public static boolean verifyLicense(final License license) {
        byte[] publicKeyBytes;
        try {
            final InputStream is = LicenseVerifier.class.getResourceAsStream("/public.key");
            try {
                final ByteArrayOutputStream out = new ByteArrayOutputStream();
                Streams.copy(is, (OutputStream)out);
                publicKeyBytes = out.toByteArray();
                if (is != null) {
                    is.close();
                }
            }
            catch (Throwable t) {
                if (is != null) {
                    try {
                        is.close();
                    }
                    catch (Throwable t2) {
                        t.addSuppressed(t2);
                    }
                }
                throw t;
            }
        }
        catch (IOException ex) {
            throw new IllegalStateException(ex);
        }
        return verifyLicense(license, publicKeyBytes);
    }
}
改后
package org.elasticsearch.license;
 
public class LicenseVerifier
{
    public static boolean verifyLicense(final License license, final byte[] array) {
        return true;
    }
     
    public static boolean verifyLicense(final License license) {
        return true;
    }
}

修改XPackBuild.java

最后一个静态代码块中 try的部分全部删除

改前
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_0109: {
           if (path.toString().endsWith(".jar")) {
                try {
                    final JarInputStream jar =
                    new JarInputStream(Files.newInputStream(path, new OpenOption[0]));
                    try {
                        final Manifest manifest = jar.getManifest();
                        shortHash = manifest.getMainAttributes().getValue("Change");
                        date = manifest.getMainAttributes().getValue("Build-Date");
                        jar.close();
                    }
                    catch (Throwable t) {
                        try {
                            jar.close();
                        }
                        catch (Throwable t2) {
                            t.addSuppressed(t2);
                        }
                        throw t;
                    }
                    break Label_0109;
                }
                catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            shortHash = "Unknown";
            date = "Unknown";
        }
        CURRENT = new XPackBuild(shortHash, date);
    }
}
改后
package org.elasticsearch.xpack.core;
 
import java.nio.file.*;
import org.elasticsearch.common.io.*;
import java.net.*;
import org.elasticsearch.common.*;
 
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 location = XPackBuild.class.getProtectionDomain().getCodeSource().getLocation();
        try {
            return PathUtils.get(location.toURI());
        }
        catch (URISyntaxException ex) {
            throw new RuntimeException(ex);
        }
    }
     
    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 {
        getElasticsearchCodebase();
        CURRENT = new XPackBuild("Unknown""Unknown");
    }
}

替换目标文件

把上面修改编译出来的LicenseVerifier.class和XPackBuild.class替换./elasticsearch-7.0.0/modules/x-pack-core/x-pack-core-7.0.0.jar。

替换步骤:

  1. 查找文件:jar -tvf x-pack-core-7.0.0-new.jar |grep LicenseVerifier
  2. 找到后解压:jar -xvf x-pack-core-7.0.0-new.jar |grep org/elasticsearch/license/LicenseVerifier.class
  3. 手动把自己修改后编译生成的class覆盖解压出来的文件,然后压回jar包:jar -uvf x-pack-core-7.0.0.jar  org/elasticsearch/license/LicenseVerifier.class
  4. 最后把替换好的jar包替换elasticsearch下的x-pack-core-7.0.0.jar包

申请license

去官网(https://license.elastic.co/registration)申请license后,下载下来是这种格式:

{"license":{"uid":"864c20ea-b26f-4f1d-bfe5-4f02a26f90a9","type":"platinum","issue_date_in_millis":1570752000000,"expiry_date_in_millis":2524579200999,"max_nodes":100,"issued_to":"deng pang (yiren)","issuer":"Web Form","signature":"AAAAAwAAAA3m1fB/yRfUho18V4FpAAABmC9ZN0hjZDBGYnVyRXpCOW5Bb3FjZDAxOWpSbTVoMVZwUzRxVk1PSmkxaktJRVl5MUYvUWh3bHZVUTllbXNPbzBUemtnbWpBbmlWRmRZb25KNFlBR2x0TXc2K2p1Y1VtMG1UQU9TRGZVSGRwaEJGUjE3bXd3LzRqZ05iLzRteWFNekdxRGpIYlFwYkJiNUs0U1hTVlJKNVlXekMrSlVUdFIvV0FNeWdOYnlESDc3MWhlY3hSQmdKSjJ2ZTcvYlBFOHhPQlV3ZHdDQ0tHcG5uOElCaDJ4K1hob29xSG85N0kvTWV3THhlQk9NL01VMFRjNDZpZEVXeUtUMXIyMlIveFpJUkk2WUdveEZaME9XWitGUi9WNTZVQW1FMG1DenhZU0ZmeXlZakVEMjZFT2NvOWxpZGlqVmlHNC8rWVVUYzMwRGVySHpIdURzKzFiRDl4TmM1TUp2VTBOUlJZUlAyV0ZVL2kvVk10L0NsbXNFYVZwT3NSU082dFNNa2prQ0ZsclZ4NTltbU1CVE5lR09Bck93V2J1Y3c9PQAAAQB4zgpe5lluBbJYaQBWNDxrK0J9V4fnb8KWMmgIGj7ymw++bvV9rkmNtjDixWZkdSbWVQr0WLBpZoye+yQCqWB559BTqinUmIazgRpVFtaggN4RXgJA6V/N9NgOv0Vw0DvN9FI2aU5iRv7nXaNmpkMPlaCngI+2F3FoBuF9GyHsXYaOqDYkMdazT3W757QnP58ZCQT9S98gIcU75yqyWlKZek8UlUtUxSCSTtOyMtWrwag238/OgXv8BlmtQcH9A/XQBmAQlkzbgBVBkWoS0w2aqCM4Q3X7qTOH/Ea+xT/IJVhZgeTXh947kW1unEBEfwF6GZQkQQW+4pH6GEtCGTO/","start_date_in_millis":1570752000000}}

许可证书分有三类GOLD(黄金),PLATINUM(白金),ENTERPRISE(企业),我上面把type手动改成了白金版,然后再把过期时间改到了2050年

禁用elasticsearch安全协议

导出许可证书之前要先关闭xpack安全认证,打开../config/elasticsearch.yml文件在末尾添加:xpack.security.enabled: false

并启动elasticsearch服务:./bin/elasticsearch -d

导入license

curl -XPUT -u elastic 'http://192.168.1.9:9200/_xpack/license' -"Content-Type: application/json" -d @license.json

导入成功后再把xpack安全认证打开:

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

内置账号创建密码

使用内置帐号需要设置密码,执行命令:./bin/elasticsearch-setup-passwords interactive   按提示输入密码

修改kibanna内置账号

安全认证开启后,只有配置了帐号信息才能使用,vi kibana.yml

elasticsearch.username: "kibana"
elasticsearch.password: "xxxxxx"

重启Kibana

以上配置完成后,重启kibana并访问,此时需要帐号登录。

看到上面许可的有效期,说明我们已经破解成功并可以使用权限功能和告警功能了。完成!!!

elasticsearch7.X x-pack破解的更多相关文章

  1. ElasticSearch7.3破解

    破解ES7.3.0到白金版(学习交流使用) 正常安装ELK7.3版本到服务器上 正常部署ELK7到服务器上,先不要启动.然后开始进行破解操作 进行破解操作 需要破解的文件:modules/x-pack ...

  2. zend studio 13.5破解以及集成xdebug

    环境说明: 操作系统:Windows 7 Ultimate Edition Service Pack 1 PHP:7.0.11 TS Zend Studio:13.5.0 Xdebug:2.5.0 一 ...

  3. 完美:adobe premiere cs6破解版下载[序列号+汉化包+破解补丁+破解教程]

    原文地址:http://blog.sina.com.cn/s/blog_6306f2c60102f5ub.html 完美:adobe premiere cs6破解版下载,含序列号.汉化包.注册机.破解 ...

  4. Red Gate系列之二 SQL Source Control 3.0.13.4214 Edition 数据库版本控制器 完全破解+使用教程

    原文:Red Gate系列之二 SQL Source Control 3.0.13.4214 Edition 数据库版本控制器 完全破解+使用教程 Red Gate系列之二 SQL Source Co ...

  5. Mac端StartUML的安装和破解

    **本人安装的是StarUML-3.0.1版本** 一.下载与安装 1. 从官方网站下载,网址:http://staruml.io/ 2. dmg文件下载完成后,双击安装. 二.破解 1. 安装npm ...

  6. 转:StarUML3.0的破解方法

    转自:https://blog.csdn.net/sam_shan/article/details/80585240 StarUML3.0的破解方法 最近StarUML由2.0更新到3.0.原来的破解 ...

  7. [视频]K8软件破解脱壳入门教程

    [视频]K8软件破解脱壳入门教程 链接:https://pan.baidu.com/s/1aV9485MmtRedU6pzyr--Vw 提取码:vbak C:\Users\K8team\Desktop ...

  8. 无需破解:Windows Server 2008 R2 至少免费使用 900天

    无需破解:Windows Server 2008 R2 至少免费使用 900天 2009年10月30日 星期五 02:10 1.首先安装后,有一个180天的试用期. 2.在180天试用期即将结束时,使 ...

  9. DxO FilmPack for Mac(胶片模拟效果软件)破解版安装

    1.软件简介    DxO FilmPack 是 macOS 系统上由知名的 DxO Labs 出品的一套胶片模拟效果滤镜,拥有数十种电影风格的滤镜,今天和大家分享最新的版本,支持最新的 PhotoS ...

随机推荐

  1. 百度Openrasp开源的应用运行时自我保护产品,安装教程。

    第一步: 下载最新版本的安装包 https://packages.baidu.com/app/openrasp/release/latest/rasp-php-linux.tar.bz2 解压到目录: ...

  2. ACM-ICPC 2019 山东省省赛总结

    五题手快拿银,不然拿铜,甚至不拿,从结果上来看拿了铜牌对第一年的我们来说算好的,也不算太好. 从拿奖后的第一天,我想写这篇博客,但是我忍了下来,那时候被喜悦冲昏了头脑,当 冷静下来,我开始打算写这篇博 ...

  3. 图论--差分约束--POJ 1364 King

    Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen p ...

  4. Jenkins 节点配置

    1.配置代理 系统管理---configure Global Security(全局安全设置)---Tcp port for inbound agents---指定端口 服务器防火墙中开放此端口(li ...

  5. c/c++获取硬盘序列号

    最近在接触软件注册模块,需要获取硬盘序列号来生成注册码. 硬盘序列号,英文名:Hard Disk Serial Number,该号是硬盘厂家为区别产品而设置的,是唯一的.网上搜索一下,发现获取硬盘序列 ...

  6. Java笔记(day23-day26)

     IO流1,复制一个文本文件. 1,明确体系:        源:InputStream ,Reader        目的:OutputStream ,Writer    2,明确数据:       ...

  7. 第十一章:Python高级编程-协程和异步IO

    第十一章:Python高级编程-协程和异步IO Python3高级核心技术97讲 笔记 目录 第十一章:Python高级编程-协程和异步IO 11.1 并发.并行.同步.异步.阻塞.非阻塞 11.2 ...

  8. 【Scala】利用Akka的actor编程模型,实现2个进程间的通信

    文章目录 步骤 一.创建maven工程,导入jar包 二.master进程代码开发 三.worker进程代码开发 四.控制台结果 步骤 一.创建maven工程,导入jar包 <propertie ...

  9. Vular开发手记#1:设计并实现一个拼插式应用程序框架

    可视化编(rxeditor)辑告一段落,在知乎上发了一个问题,询问前景,虽然看好的不多,但是关注度还是有的,目前为止积累了21w流量,因为这个事,开心了好长一段时间.这一个月的时间,主要在设计制作Vu ...

  10. LeetCode 102. 二叉树的层序遍历 | Python

    102. 二叉树的层序遍历 题目来源:https://leetcode-cn.com/problems/binary-tree-level-order-traversal 题目 给你一个二叉树,请你返 ...