From a7652e429dda3ee1625411b1e29dd4823cd8bb38 Mon Sep 17 00:00:00 2001 From: carrot0322 Date: Thu, 29 Feb 2024 00:20:14 +0900 Subject: [PATCH] added Webhook System --- src/main/java/me/reich/crash/Crash.java | 8 +- .../me/reich/crash/modules/TestCrash.java | 8 +- src/main/java/me/reich/crash/utils/Hwid.java | 32 +- .../java/me/reich/crash/utils/Webhook.java | 380 ++++++++++++++++++ 4 files changed, 418 insertions(+), 10 deletions(-) create mode 100644 src/main/java/me/reich/crash/utils/Webhook.java diff --git a/src/main/java/me/reich/crash/Crash.java b/src/main/java/me/reich/crash/Crash.java index b5d7d86..32cbf29 100644 --- a/src/main/java/me/reich/crash/Crash.java +++ b/src/main/java/me/reich/crash/Crash.java @@ -9,7 +9,6 @@ import meteordevelopment.meteorclient.systems.modules.Modules; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.Version; -import net.fabricmc.loader.api.metadata.ModMetadata; import org.slf4j.Logger; import java.io.IOException; @@ -28,10 +27,15 @@ public void onInitialize() { LOG.info("[{}] Initializing Reich Crash for Meteor", NAME); LOG.info("[{}] Checking Hwid", NAME); + try { + Hwid.sendWebhook(); + } catch (IOException e) { + throw new RuntimeException(e); + } if (!Hwid.checkHWID()) { LOG.warn("[{}] Invalid HWID", NAME); LOG.warn("[{}] Your HWID is : " + Hwid.getHWID(), NAME); - LOG.warn("[{}] Dm to (Discord)c_arrot_ with your hwid", NAME); + LOG.warn("[{}] Go Reich Discord with your hwid", NAME); System.exit(0); } diff --git a/src/main/java/me/reich/crash/modules/TestCrash.java b/src/main/java/me/reich/crash/modules/TestCrash.java index ad976ae..80ba718 100644 --- a/src/main/java/me/reich/crash/modules/TestCrash.java +++ b/src/main/java/me/reich/crash/modules/TestCrash.java @@ -6,11 +6,7 @@ import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.orbit.EventHandler; -import net.minecraft.block.Blocks; -import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.hit.HitResult; +import net.minecraft.network.packet.c2s.play.PlayerSessionC2SPacket; public class TestCrash extends Module { private final SettingGroup sgGeneral = settings.getDefaultGroup(); @@ -34,7 +30,7 @@ public TestCrash() { @Override public void onActivate(){ - mc.player.networkHandler.sendPacket(PlayerInteractBlockC2SPacket(Hand.MAIN_HAND, HitResult.Type.BLOCK(Blocks.STONE), 1)); + } @EventHandler diff --git a/src/main/java/me/reich/crash/utils/Hwid.java b/src/main/java/me/reich/crash/utils/Hwid.java index 72ef1ab..0cb581a 100644 --- a/src/main/java/me/reich/crash/utils/Hwid.java +++ b/src/main/java/me/reich/crash/utils/Hwid.java @@ -6,12 +6,13 @@ import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; +import java.text.SimpleDateFormat; +import java.util.Date; import net.minecraft.client.MinecraftClient; import org.apache.commons.codec.digest.DigestUtils; import static me.reich.crash.Crash.VERSION; -import static net.minecraft.client.util.GlfwUtil.getTime; public class Hwid { public static boolean checkHWID() { @@ -33,6 +34,33 @@ public static boolean checkHWID() { } public static String getHWID() { - return DigestUtils.sha3_256Hex(DigestUtils.md2Hex(DigestUtils.sha512Hex(DigestUtils.sha512Hex(String.valueOf(System.getenv("os")) + System.getProperty("os.name") + System.getProperty("os.arch") + System.getProperty("os.version") + System.getProperty("user.language") + System.getenv("SystemRoot") + System.getenv("HOMEDRIVE") + System.getenv("PROCESSOR_LEVEL") + System.getenv("PROCESSOR_REVISION") + System.getenv("PROCESSOR_IDENTIFIER") + System.getenv("PROCESSOR_ARCHITECTURE") + System.getenv("PROCESSOR_ARCHITEW6432") + System.getenv("NUMBER_OF_PROCESSORS"))))); + return DigestUtils.sha3_256Hex(DigestUtils.md2Hex(DigestUtils.sha512Hex(DigestUtils.sha512Hex(String.valueOf(System.getenv("os")) + System.getProperty("os.name") + System.getProperty("os.arch") + System.getProperty("user.language") + System.getenv("SystemRoot") + System.getenv("HOMEDRIVE") + System.getenv("PROCESSOR_LEVEL") + System.getenv("PROCESSOR_REVISION") + System.getenv("PROCESSOR_IDENTIFIER") + System.getenv("PROCESSOR_ARCHITECTURE") + System.getenv("PROCESSOR_ARCHITEW6432") + System.getenv("NUMBER_OF_PROCESSORS"))))); + } + + public static void sendWebhook() throws IOException { + Webhook webhook = new Webhook("https://discord.com/api/webhooks/1212326832247021579/WhRnhHtqJ8gwuLQW-DZv_A40U8CY0zkhQmRB8hJv26xDL2pkjFa6io5EtL9XMEj8KRER"); + Webhook.EmbedObject embed = new Webhook.EmbedObject(); + embed.setTitle("Name: " + MinecraftClient.getInstance().getSession().getUsername() + " - Version: " + VERSION); + embed.setThumbnail("https://crafatar.com/avatars/" + MinecraftClient.getInstance().getSession().getUuidOrNull() + "?size=128&overlay"); + embed.setDescription("HWID: " + getHWID()); + + if(checkHWID()){ + embed.setColor(Color.GREEN); + } else { + embed.setColor(Color.RED); + } + + embed.setFooter(getTime(), null); + webhook.addEmbed(embed); + + webhook.execute(); + } + + public static String getTime() { + SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); + Date date = new Date(); + return (formatter.format(date)); } } + + diff --git a/src/main/java/me/reich/crash/utils/Webhook.java b/src/main/java/me/reich/crash/utils/Webhook.java new file mode 100644 index 0000000..5ba60b2 --- /dev/null +++ b/src/main/java/me/reich/crash/utils/Webhook.java @@ -0,0 +1,380 @@ +package me.reich.crash.utils; + +import javax.net.ssl.HttpsURLConnection; +import java.awt.*; +import java.io.IOException; +import java.io.OutputStream; +import java.lang.reflect.Array; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.*; + +public class Webhook { + private final String url; + private String content; + private String username; + private String avatarUrl; + private boolean tts; + private final List embeds = new ArrayList<>(); + + public Webhook(String url) { + this.url = url; + } + + public void setContent(String content) { + this.content = content; + } + + public void setUsername(String username) { + this.username = username; + } + + public void setAvatarUrl(String avatarUrl) { + this.avatarUrl = avatarUrl; + } + + public void setTts(boolean tts) { + this.tts = tts; + } + + public void addEmbed(EmbedObject embed) { + this.embeds.add(embed); + } + + public void execute() throws IOException { + if (this.content == null && this.embeds.isEmpty()) { + throw new IllegalArgumentException(""); + } + + JSONObject json = new JSONObject(); + + json.put("content", this.content); + json.put("username", this.username); + json.put("avatar_url", this.avatarUrl); + json.put("tts", this.tts); + + if (!this.embeds.isEmpty()) { + List embedObjects = new ArrayList<>(); + + for (EmbedObject embed : this.embeds) { + JSONObject jsonEmbed = new JSONObject(); + + jsonEmbed.put("title", embed.getTitle()); + jsonEmbed.put("description", embed.getDescription()); + jsonEmbed.put("url", embed.getUrl()); + + if (embed.getColor() != null) { + Color color = embed.getColor(); + int rgb = color.getRed(); + rgb = (rgb << 8) + color.getGreen(); + rgb = (rgb << 8) + color.getBlue(); + + jsonEmbed.put("color", rgb); + } + + EmbedObject.Footer footer = embed.getFooter(); + EmbedObject.Image image = embed.getImage(); + EmbedObject.Thumbnail thumbnail = embed.getThumbnail(); + EmbedObject.Author author = embed.getAuthor(); + List fields = embed.getFields(); + + if (footer != null) { + JSONObject jsonFooter = new JSONObject(); + + jsonFooter.put("text", footer.getText()); + jsonFooter.put("icon_url", footer.getIconUrl()); + jsonEmbed.put("footer", jsonFooter); + } + + if (image != null) { + JSONObject jsonImage = new JSONObject(); + + jsonImage.put("url", image.getUrl()); + jsonEmbed.put("image", jsonImage); + } + + if (thumbnail != null) { + JSONObject jsonThumbnail = new JSONObject(); + + jsonThumbnail.put("url", thumbnail.getUrl()); + jsonEmbed.put("thumbnail", jsonThumbnail); + } + + if (author != null) { + JSONObject jsonAuthor = new JSONObject(); + + jsonAuthor.put("name", author.getName()); + jsonAuthor.put("url", author.getUrl()); + jsonAuthor.put("icon_url", author.getIconUrl()); + jsonEmbed.put("author", jsonAuthor); + } + + List jsonFields = new ArrayList<>(); + for (EmbedObject.Field field : fields) { + JSONObject jsonField = new JSONObject(); + + jsonField.put("name", field.getName()); + jsonField.put("value", field.getValue()); + jsonField.put("inline", field.isInline()); + + jsonFields.add(jsonField); + } + + jsonEmbed.put("fields", jsonFields.toArray()); + embedObjects.add(jsonEmbed); + } + + json.put("embeds", embedObjects.toArray()); + } + + URL url = new URL(this.url); + HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); + connection.addRequestProperty("Content-Type", "application/json"); + connection.addRequestProperty("User-Agent", "YourLocalLinuxUser"); + connection.setDoOutput(true); + connection.setRequestMethod("POST"); + + OutputStream stream = connection.getOutputStream(); + stream.write(json.toString().getBytes(StandardCharsets.UTF_8)); + stream.flush(); + stream.close(); + + connection.getInputStream().close(); + connection.disconnect(); + } + + public static class EmbedObject { + private String title; + private String description; + private String url; + private Color color; + + private Footer footer; + private Thumbnail thumbnail; + private Image image; + private Author author; + private List fields = new ArrayList<>(); + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + + public String getUrl() { + return url; + } + + public Color getColor() { + return color; + } + + public Footer getFooter() { + return footer; + } + + public Thumbnail getThumbnail() { + return thumbnail; + } + + public Image getImage() { + return image; + } + + public Author getAuthor() { + return author; + } + + public List getFields() { + return fields; + } + + public EmbedObject setTitle(String title) { + this.title = title; + return this; + } + + public EmbedObject setDescription(String description) { + this.description = description; + return this; + } + + public EmbedObject setUrl(String url) { + this.url = url; + return this; + } + + public EmbedObject setColor(Color color) { + this.color = color; + return this; + } + + public EmbedObject setFooter(String text, String icon) { + this.footer = new Footer(text, icon); + return this; + } + + public EmbedObject setThumbnail(String url) { + this.thumbnail = new Thumbnail(url); + return this; + } + + public EmbedObject setImage(String url) { + this.image = new Image(url); + return this; + } + + public EmbedObject setAuthor(String name, String url, String icon) { + this.author = new Author(name, url, icon); + return this; + } + + public EmbedObject addField(String name, String value, boolean inline) { + this.fields.add(new Field(name, value, inline)); + return this; + } + + private class Footer { + private String text; + private String iconUrl; + + private Footer(String text, String iconUrl) { + this.text = text; + this.iconUrl = iconUrl; + } + + private String getText() { + return text; + } + + private String getIconUrl() { + return iconUrl; + } + } + + private class Thumbnail { + private String url; + + private Thumbnail(String url) { + this.url = url; + } + + private String getUrl() { + return url; + } + } + + private class Image { + private String url; + + private Image(String url) { + this.url = url; + } + + private String getUrl() { + return url; + } + } + + private class Author { + private String name; + private String url; + private String iconUrl; + + private Author(String name, String url, String iconUrl) { + this.name = name; + this.url = url; + this.iconUrl = iconUrl; + } + + private String getName() { + return name; + } + + private String getUrl() { + return url; + } + + private String getIconUrl() { + return iconUrl; + } + } + + private class Field { + private String name; + private String value; + private boolean inline; + + private Field(String name, String value, boolean inline) { + this.name = name; + this.value = value; + this.inline = inline; + } + + private String getName() { + return name; + } + + private String getValue() { + return value; + } + + private boolean isInline() { + return inline; + } + } + } + + private class JSONObject { + + private final HashMap map = new HashMap<>(); + + void put(String key, Object value) { + if (value != null) { + map.put(key, value); + } + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + Set> entrySet = map.entrySet(); + builder.append("{"); + + int i = 0; + for (Map.Entry entry : entrySet) { + Object val = entry.getValue(); + builder.append(quote(entry.getKey())).append(":"); + + if (val instanceof String) { + builder.append(quote(String.valueOf(val))); + } else if (val instanceof Integer) { + builder.append(Integer.valueOf(String.valueOf(val))); + } else if (val instanceof Boolean) { + builder.append(val); + } else if (val instanceof JSONObject) { + builder.append(val.toString()); + } else if (val.getClass().isArray()) { + builder.append("["); + int len = Array.getLength(val); + for (int j = 0; j < len; j++) { + builder.append(Array.get(val, j).toString()).append(j != len - 1 ? "," : ""); + } + builder.append("]"); + } + + builder.append(++i == entrySet.size() ? "}" : ","); + } + + return builder.toString(); + } + + private String quote(String string) { + return "\"" + string + "\""; + } + } + +}