• elasticsearch6.8.1 x-pack插件破解


    一、为什么要破解x-pack?
           因为涉及到了ES服务的安全性.ES服务如果被劫持,数据直接会被删除。ES登录账号和密码的设置是通过x-pack来实现的,官方只给了免费的30天的使用权,而且购买插件每年需要不少的钱,这对于中小型企业来说,是一笔不小的开支,然后你懂的。

    二、本次任务是在搭建好的elk基础上进行破解elasticsearch6.8.1 x-pack插件

    三、适用范围所有ES版本5.*,6.*,7目前还没研究过,破解原理大致相同。

    四、开始搭建

     elk6.3版本之后,x-pack都是默认安装,无需install

    1.重写x-pack下的2个类:LicenseVerifier.java和XPackBuild.java,反编译破解补丁

    创建目录test

    mkdir test
    cd test

    vim 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; 
    } 
    }

    vim XPackBuild.java

    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); 
    }
    }

    将刚创建的两个java包打包成class文件,我们需要做的就是替换这两个class文件(因里面需要引用到其他的jar,故需要用到javac -cp命令)

    javac -cp "/usr/local/elasticsearch/lib/elasticsearch-6.8.1.jar:/usr/local/elasticsearch/lib/lucene-core-7.7.0.jar:/usr/local/elasticsearch/modules/x-pack-core/x-pack-core-6.8.1..jar" LicenseVerifier.java
    javac -cp "/usr/local/elasticsearch/lib/elasticsearch-6.8.1.jar:/usr/local/elasticsearch/lib/lucene-core-7.7.0.jar:/usr/local/elasticsearch/modules/x-pack-core/x-pack-core-6.8.1..jar:/usr/local/elasticsearch/lib/elasticsearch-core-6.8.1..jar" XPackBuild.java

    会生成2个class文件
    LicenseVerifier.class
    XPackBuild.class
    把原文件给解压出来,然后覆盖生成新的文件

    cp -a /usr/local/elasticsearch/modules/x-pack-core/x-pack-core-6.8.1.jar .
    jar -xf x-pack-core-6.8.1.jar

    删除多余的文件

    mv x-pack-core-6.8.1.jar /tmp/
    rm -rf LicenseVerifier.java XPackBuild.java
    cp -a LicenseVerifier.class org/elasticsearch/license/
    cp -a XPackBuild.class org/elasticsearch/xpack/core/
    rm -rf LicenseVerifier.class XPackBuild.class

    压缩,替换原文件

    jar -cvf x-pack-core-6.8.1.jar *
    cp -a x-pack-core-6.8.1.jar /usr/local/elasticsearch/modules/x-pack-core/
    chown -R elasticsearch. /usr/local/elasticsearch/

    服务重启

    kill -9 `ps -ef|grep "elasticsearch/lib"|awk '{print $2}'`
    su - elasticsearch
    cd /usr/local/elasticsearch/bin/
    ./elasticsearch -d

    到此破解补丁准备完成。

    2.去官网申请license证书https://license.elastic.co/registration官网地址;邮箱需要认真写,主要用来接收json文件,其他可以随便写.然后就是修改申请到的证书,主要修改如下:

    "type":"basic" 替换为 "type":"platinum"    # 基础版变更为铂金版
    "expiry_date_in_millis":1561420799999 替换为  "expiry_date_in_millis":3107746200000# 1年变为50年

    3.上传证书完成修改

    上传证书主要有两种方法:

    (1)在kibana上传证书
          上传前准备,打开/usr/local/elasticsearch/config/elasticsearch.yml配置文件加入

    xpack.security.enabled: false

    启动elasticsearch服务和kibana服务,上传证书,上传成功时可以看到时间由1个月变成50年,到此破解x-pack已经成功了.
    (2)在命令行
           将证书上传到主机,从命令行导入,默认为changeme:

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

    查看是否破解成功:

    curl -XGET -u elastic:changeme node02:9200/_license

    如果看到类型为platinum,expiry_date变为50年,表示破解成功.

     到此,x-pack插件破解完成!

    5.开启ES的登录功能
    1.重置登陆权限密码(如果是集群,需要在每个节点都要重置密码,并且密码要相同)

    bin/elasticsearch-setup-passwords interactive

    按步骤分别重置elastic/kibana等账号的密码
    elastic就是登陆elasticsearch服务的最高权限账号

    2.修改/usr/local/elasticsearch/config/elasticsearch.yml配置
    添加如下2行,打开安全配置功能

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

    3.修改kibana配置
     在/usr/local/kibana/config/kibana.yml下添加如下两行

    elasticsearch.username: "elastic"
    elasticsearch.password: "password"

    此处修改完后,重启ES和kibana服务就需要登陆账号和密码了

    4.x-pack设置完毕后,head无法登陆的问题
    在/usr/local/elasticsearch/config/elasticsearch.yml中添加如下三行配置

    http.cors.enabled: true
    http.cors.allow-origin: "*"
    http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type

    重启服务,并通过如下形式访问head端口

    http://10.0.0.11:9100/?auth_user=elastic&auth_password=passwd

     最后供上我破解的文件,只需要更换就可以:

    链接:https://pan.baidu.com/s/1gnZQCV-bmRIARdmDNiz1TA
    提取码:0ls5
  • 相关阅读:
    重学《C#高级编程》(序)
    分布式锁-基于redis的分布式锁实现
    CentOS 7.9 安装docker
    JAVA使用UDP收发文件
    MYSQL 查询指定范围内的经纬度
    tomcat 8.x 配置 HTTPS 协议
    JDBC 连接 Oracle 11g 集群
    [centos7] svn
    单例模式
    Extjs 中 Treepanel 实现级联选中效果
  • 原文地址:https://www.cnblogs.com/wzxmt/p/11198398.html
Copyright © 2020-2023  润新知