x-pack-6.2.4 破解

由于从5.6.0升级到6.2.4后,x-pack需要重新修改过期时间

安装插件

1
$ bin/elasticsearch-plugin install x-pack

反编译文件

找出要反编译的文件

1
$ cp elasticsearch-6.2.4/plugins/x-pack/x-pack-core/x-pack-core-6.2.4.jar /opt/
  1. 解压文件
1
$ cd /opt/ && jar xf x-pack-core-6.2.4.jar
  1. 创建 java 文件

LicenseVerifier 中有两个静态方法,这就是验证授权文件是否有效的方法,我们把它修改为全部返回true.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
$ 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;
}
}

XPackBuild 中 最后一个静态代码块中 try的部分全部删除,这部分会验证jar包是否被修改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
$ 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);
}
}
  1. 反编译

利用 Intellij IDEA 编译器插件 jd-gui 反编译这两个文件

替换文件

1
2
3
4
5
6
7
8
9
10
11
12
$ cp LicenseVerifier.class /opt/org/elasticsearch/license/LicenseVerifier.class
$ cp XPackBuild.class /opt/org/elasticsearch/xpack/core/XPackBuild.class
# 打包覆盖
$ jar -cvf x-pack-core-6.2.4.jar /opt/*
# 备份原文件
$ cp x-pack-core-6.2.4.jar x-pack-core-6.2.4.jar.bak
# 替换x-pack
$ cp /opt/x-pack-core-6.2.4.jar x-pack-core-6.2.4.jar

替换完成后,我这里有报错,然后重启下elastcisearch 后就正常了。

导入lincense

如果没有注册过,请申请license ,由于之前注册过,所以我直接导入就可以了

1
2
$ cat license.json
{"license":{"uid":"f5xywdf-SdeJVtJL...","type":"platinum","issue_date_in_millis":1506643200000,"expiry_date_in_millis":2535123399999,"max_nodes":100,"issued_to":"charlie","issuer":"Web Form","signature":"AAAAAwAAAA3Wt...","start_date_in_millis":1506643200000}}

修改 type expiry_date_in_millis start_date_in_millis

1
2
3
4
5
6
$ curl -XPUT -u user:pass 'http://localhost:9200/_xpack/license' -H "Content-Type: application/json" -d @license.json
{
"acknowledged":true,
"license_status":"valid"
}

刷新页面

file

坚持原创技术分享,您的支持将鼓励我继续创作!