一、為什么要破解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