use release-branch property instead of main-branch
This commit is contained in:
parent
9b78244271
commit
a63df9a3a9
10 changed files with 16 additions and 1144 deletions
|
@ -29,7 +29,7 @@ public class BaseBand {
|
||||||
public static final Logger LOGGER = LogManager.getLogger("BaseBand");
|
public static final Logger LOGGER = LogManager.getLogger("BaseBand");
|
||||||
public static final SecureRandom RANDOM = new SecureRandom();
|
public static final SecureRandom RANDOM = new SecureRandom();
|
||||||
|
|
||||||
public static String buildString = LoadHandler.data.getBoolean("main-branch") ? "Dark Side of the Moon" : "Broadway";
|
public static String buildString = LoadHandler.data.getBoolean("release-branch") ? "Broadway" : "Dark Side of the Moon";
|
||||||
public static final EventManager eventManager = new EventManager(LOGGER::error);
|
public static final EventManager eventManager = new EventManager(LOGGER::error);
|
||||||
public static final RemoteEventManager remoteEventManager = new RemoteEventManager();
|
public static final RemoteEventManager remoteEventManager = new RemoteEventManager();
|
||||||
public static final FMLEventHandler fmlEventHandlerInstance = new FMLEventHandler();
|
public static final FMLEventHandler fmlEventHandlerInstance = new FMLEventHandler();
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class DevStub implements IFMLLoadingPlugin {
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void onInit(FMLPostInitializationEvent event) {
|
public void onInit(FMLPostInitializationEvent event) {
|
||||||
LoadHandler.data.set("main-branch", true);
|
LoadHandler.data.set("release-branch", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -153,7 +153,7 @@ public class Main extends ListenerAdapter {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
TCN tcn = new TCN();
|
TCN tcn = new TCN();
|
||||||
tcn.set("action", "reset");
|
tcn.set("action", "branch");
|
||||||
tcn.set("authorisation", Hasher.sha512hex(password));
|
tcn.set("authorisation", Hasher.sha512hex(password));
|
||||||
tcn.set("discord-id", user.getIdLong());
|
tcn.set("discord-id", user.getIdLong());
|
||||||
tcn.set("branch", branch);
|
tcn.set("branch", branch);
|
||||||
|
|
|
@ -79,6 +79,7 @@ public class Loader implements Util {
|
||||||
Response status = Response.values()[inputStream.readInt()];
|
Response status = Response.values()[inputStream.readInt()];
|
||||||
|
|
||||||
if(status == Response.OUTDATED) {
|
if(status == Response.OUTDATED) {
|
||||||
|
LOGGER.info("BaseBand is downloading an update.");
|
||||||
RawKey rk = new RawKey(key.toBytes());
|
RawKey rk = new RawKey(key.toBytes());
|
||||||
ZipOutputStream out = new ZipOutputStream(Loader.class.getProtectionDomain().getCodeSource().getLocation().openConnection().getOutputStream());
|
ZipOutputStream out = new ZipOutputStream(Loader.class.getProtectionDomain().getCodeSource().getLocation().openConnection().getOutputStream());
|
||||||
int n = inputStream.readInt();
|
int n = inputStream.readInt();
|
||||||
|
|
|
@ -30,14 +30,16 @@ public class LoaderHandler {
|
||||||
}
|
}
|
||||||
if(response.o == UserHandler.Response.OK.ordinal()) {
|
if(response.o == UserHandler.Response.OK.ordinal()) {
|
||||||
TCN data = new TCN();
|
TCN data = new TCN();
|
||||||
data.set("main-branch", "main".equals(response.t.getString("branch")));
|
data.set("release-branch", "release".equals(response.t.getString("branch")));
|
||||||
|
|
||||||
Map<String, byte[]> classes = null;
|
Map<String, byte[]> classes = null;
|
||||||
if("main".equals(response.t.getString("branch")))
|
if("main".equals(response.t.getString("branch")))
|
||||||
classes = Main.classesDebug;
|
classes = Main.classesDebug;
|
||||||
if("release".equals(response.t.getString("branch")))
|
if("release".equals(response.t.getString("branch")))
|
||||||
classes = Main.classes;
|
classes = Main.classes;
|
||||||
sendClasses(classes, key, outputStream);
|
if(classes != null) {
|
||||||
|
sendClasses(classes, key, outputStream);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.close();
|
connection.close();
|
||||||
|
@ -47,8 +49,14 @@ public class LoaderHandler {
|
||||||
RawKey rk = new RawKey(key.toBytes());
|
RawKey rk = new RawKey(key.toBytes());
|
||||||
outputStream.writeInt(classes.size());
|
outputStream.writeInt(classes.size());
|
||||||
for (Map.Entry<String, byte[]> entry : classes.entrySet()) {
|
for (Map.Entry<String, byte[]> entry : classes.entrySet()) {
|
||||||
outputStream.writeString(rk.encryptString(entry.getKey()));
|
try {
|
||||||
outputStream.writeByteArray(rk.encryptBytes(entry.getValue()));
|
outputStream.writeString(rk.encryptString(entry.getKey()));
|
||||||
|
outputStream.writeByteArray(rk.encryptBytes(entry.getValue()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("while " + entry.getKey());
|
||||||
|
e.printStackTrace();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,239 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2023 Jess H & Daniella H. All Rights Reserved.
|
|
||||||
* Unauthorized copying of this file via any medium is Strictly Prohibited.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package dev.baseband.server.old;
|
|
||||||
|
|
||||||
import net.dv8tion.jda.api.JDA;
|
|
||||||
import net.dv8tion.jda.api.JDABuilder;
|
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
|
||||||
import net.dv8tion.jda.api.entities.Role;
|
|
||||||
import net.dv8tion.jda.api.entities.User;
|
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.PrivateChannel;
|
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
|
||||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class Bot extends ListenerAdapter {
|
|
||||||
public static void start() {
|
|
||||||
try{
|
|
||||||
//Scanner scanner = new Scanner(new File("baseband_bot.token"));
|
|
||||||
String token = "MTE0NTg0MjYxMDc0NTkyMTU0Nw.GD70DW.MwSmBeylHN4tTtOfv1On50bin1G9JDDawHRFXY";//scanner.next();
|
|
||||||
JDA jda = JDABuilder.createDefault(token).addEventListeners(new Bot()).enableIntents(GatewayIntent.MESSAGE_CONTENT).enableIntents(GatewayIntent.GUILD_MESSAGES).build().awaitReady();
|
|
||||||
}catch(Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean disabled = false;
|
|
||||||
|
|
||||||
|
|
||||||
public static void sendDiscordWebhookMessage(String s) {
|
|
||||||
String tokenWebhook = "https://discord.com/api/webhooks/1157110355143700621/Ydzf_FaYnh23wjCs2xAMKSfh8mVmGmBdLnCfi1LExX75k9QrVFa_Q7cgUz6dyMadgxml";
|
|
||||||
String title = "BB Server";
|
|
||||||
String message = s;
|
|
||||||
String jsonBrut = "";
|
|
||||||
jsonBrut = jsonBrut + "{\"embeds\": [{\"title\": \"" + title + "\",\"description\": \"" + message + "\",\"color\": 15258703}]}";
|
|
||||||
try {
|
|
||||||
URL url = new URL(tokenWebhook);
|
|
||||||
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
|
|
||||||
con.addRequestProperty("Content-Type", "application/json");
|
|
||||||
con.addRequestProperty("User-Agent", "BB-AUTH");
|
|
||||||
con.setDoOutput(true);
|
|
||||||
con.setRequestMethod("POST");
|
|
||||||
OutputStream stream = con.getOutputStream();
|
|
||||||
stream.write(jsonBrut.getBytes());
|
|
||||||
stream.flush();
|
|
||||||
stream.close();
|
|
||||||
con.getInputStream().close();
|
|
||||||
con.disconnect();
|
|
||||||
} catch (Exception exception) {
|
|
||||||
// empty catch block
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMessageReceived(MessageReceivedEvent event) {
|
|
||||||
String[] message = event.getMessage().getContentRaw().split(" ");
|
|
||||||
try {
|
|
||||||
if (message[0].equalsIgnoreCase("-resetusername")) {
|
|
||||||
if (this.findRole(Objects.requireNonNull(event.getMember()), "Staff") == null) {
|
|
||||||
event.getChannel().sendMessage("Invalid Perms (Requires Staff Role)").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String username = message[1];
|
|
||||||
if (UserManager.setHwidReset(username, true)) {
|
|
||||||
event.getChannel().sendMessage("HWID of username [**" + username + "**] reset.").queue();
|
|
||||||
} else {
|
|
||||||
event.getChannel().sendMessage("Cannot find User [**" + username + "**]").queue();
|
|
||||||
}
|
|
||||||
} else if (message[0].equalsIgnoreCase("-reset")) {
|
|
||||||
if (this.findRole(Objects.requireNonNull(event.getMember()), "Staff") == null) {
|
|
||||||
event.getChannel().sendMessage("Invalid Perms (Requires Staff Role)").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String userId = message[1].replaceAll("[<@!>]", ""); // Extract the user ID from the mention
|
|
||||||
|
|
||||||
if (UserManager.setHwidResetByUseID(userId, true)) {
|
|
||||||
event.getChannel().sendMessage("HWID of username [**" + UserManager.getUserNameByUserID(userId) + "**] reset.").queue();
|
|
||||||
} else {
|
|
||||||
event.getChannel().sendMessage("Cannot find User.").queue();
|
|
||||||
}
|
|
||||||
} else if (message[0].equalsIgnoreCase("-ban")) {
|
|
||||||
if (this.findRole(Objects.requireNonNull(event.getMember()), "Staff") == null) {
|
|
||||||
event.getChannel().sendMessage("Invalid Perms (Requires Staff Role)").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String username = message[1];
|
|
||||||
|
|
||||||
if (UserManager.setBanned(username, true)) {
|
|
||||||
event.getChannel().sendMessage("Banned User [**" + username + "**]").queue();
|
|
||||||
} else {
|
|
||||||
event.getChannel().sendMessage("Cannot find User [**" + username + "**]").queue();
|
|
||||||
}
|
|
||||||
} else if (message[0].equalsIgnoreCase("-unban")) {
|
|
||||||
if (this.findRole(Objects.requireNonNull(event.getMember()), "Staff") == null) {
|
|
||||||
event.getChannel().sendMessage("Invalid Perms (Requires Staff Role)").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String username = message[1];
|
|
||||||
|
|
||||||
if (UserManager.setBanned(username, false)) {
|
|
||||||
event.getChannel().sendMessage("Unbanned User [**" + username + "**]").queue();
|
|
||||||
} else {
|
|
||||||
event.getChannel().sendMessage("Cannot find User [**" + username + "**]").queue();
|
|
||||||
}
|
|
||||||
} else if (message[0].equalsIgnoreCase("-adduser") && message.length == 3) {
|
|
||||||
if (this.findRole(Objects.requireNonNull(event.getMember()), "Staff") == null) {
|
|
||||||
event.getChannel().sendMessage("Invalid Perms (Requires Staff Role)").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String username = message[2];
|
|
||||||
|
|
||||||
|
|
||||||
String userId = message[1].replaceAll("[<@!>]", ""); // Extract the user ID from the mention
|
|
||||||
System.out.println(userId);
|
|
||||||
User mentionedUser = event.getJDA().retrieveUserById(userId).complete();
|
|
||||||
|
|
||||||
if (mentionedUser != null) {
|
|
||||||
PrivateChannel channel = mentionedUser.openPrivateChannel().complete();
|
|
||||||
|
|
||||||
List<Message> messages = channel.getHistory().retrievePast(100).complete();
|
|
||||||
|
|
||||||
for (Message m : messages) {
|
|
||||||
if (m.getAuthor().isBot()) {
|
|
||||||
m.delete().complete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mentionedUser.openPrivateChannel().complete().canTalk()) {
|
|
||||||
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
||||||
Random random = new Random();
|
|
||||||
StringBuilder sb = new StringBuilder(16);
|
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++) {
|
|
||||||
int randomIndex = random.nextInt(characters.length());
|
|
||||||
sb.append(characters.charAt(randomIndex));
|
|
||||||
}
|
|
||||||
String licenseKey = encodeString(sb.toString());
|
|
||||||
|
|
||||||
UserManager.createUser(username, licenseKey, userId);
|
|
||||||
mentionedUser.openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage("Hello! Your BaseBand Key is ||" + licenseKey + "||, \nPlease do not share or lose this key as developers cannot replace it.").queue());
|
|
||||||
} else {
|
|
||||||
event.getChannel().sendMessage("The user has DMs disabled or blocked the bot.").queue();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
event.getChannel().sendMessage("User not found.").queue();
|
|
||||||
}
|
|
||||||
} else if (message[0].equalsIgnoreCase("-permlevel")) {
|
|
||||||
if (this.findRole(Objects.requireNonNull(event.getMember()), "Staff") == null) {
|
|
||||||
event.getChannel().sendMessage("Invalid Perms (Requires Staff Role)").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String userId = message[1].replaceAll("[<@!>]", ""); // Extract the user ID from the mention
|
|
||||||
|
|
||||||
if (UserManager.setPermLevelById(userId, Integer.parseInt(message[2]))) {
|
|
||||||
event.getChannel().sendMessage("Level of username [**" + UserManager.getUserNameByUserID(userId) + "**] set to "+message[2]+".").queue();
|
|
||||||
} else {
|
|
||||||
event.getChannel().sendMessage("Cannot find User.").queue();
|
|
||||||
}
|
|
||||||
} else if (message[0].equalsIgnoreCase("-disable")) {
|
|
||||||
if (this.findRole(Objects.requireNonNull(event.getMember()), "Staff") == null) {
|
|
||||||
event.getChannel().sendMessage("Invalid Perms (Requires Staff Role)").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
disabled = !disabled;
|
|
||||||
event.getChannel().sendMessage("Set server status to [**" + !disabled + "**]").queue();
|
|
||||||
}
|
|
||||||
if (message[0].equalsIgnoreCase("-resetpassword")) {
|
|
||||||
if (this.findRole(Objects.requireNonNull(event.getMember()), "Staff") == null) {
|
|
||||||
event.getChannel().sendMessage("Invalid Perms (Requires Staff Role)").queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String username = message[1];
|
|
||||||
if (UserManager.setPassword(username, "reset")) {
|
|
||||||
event.getChannel().sendMessage("Password of username [**" + username + "**] reset.").queue();
|
|
||||||
} else {
|
|
||||||
event.getChannel().sendMessage("Cannot find User [**" + username + "**]").queue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}catch (ArrayIndexOutOfBoundsException e) {
|
|
||||||
event.getChannel().sendMessage("Incorrect command usage.").queue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static String encodeString(String input) {
|
|
||||||
byte[] bytes = input.getBytes(StandardCharsets.UTF_8);
|
|
||||||
int length = bytes.length;
|
|
||||||
int numLongs = (int) Math.ceil((double) length / 8);
|
|
||||||
long[] encodedValues = new long[numLongs];
|
|
||||||
|
|
||||||
for (int i = 0; i < numLongs; i++) {
|
|
||||||
int startIndex = i * 8;
|
|
||||||
int endIndex = Math.min(startIndex + 8, length);
|
|
||||||
byte[] segment = new byte[8];
|
|
||||||
System.arraycopy(bytes, startIndex, segment, 0, endIndex - startIndex);
|
|
||||||
encodedValues[i] = bytesToLong(segment);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert the long array to a formatted string
|
|
||||||
StringBuilder formattedString = new StringBuilder();
|
|
||||||
for (long value : encodedValues) {
|
|
||||||
formattedString.append(value).append("-");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the trailing "-"
|
|
||||||
if (formattedString.length() > 0) {
|
|
||||||
formattedString.deleteCharAt(formattedString.length() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return formattedString.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static long bytesToLong(byte[] bytes) {
|
|
||||||
long result = 0;
|
|
||||||
for (byte aByte : bytes) {
|
|
||||||
result <<= 8;
|
|
||||||
result |= (aByte & 0xFF);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Role findRole(Member member, String name) {
|
|
||||||
List<Role> roles = member.getRoles();
|
|
||||||
return roles.stream().filter(role -> role.getName().equals(name)).findFirst().orElse(null);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,243 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2023 Jess H & Daniella H. All Rights Reserved.
|
|
||||||
* Unauthorized copying of this file via any medium is Strictly Prohibited.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package dev.baseband.server.old;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.mindrot.jbcrypt.BCrypt;
|
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
|
||||||
import javax.crypto.SecretKey;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.jar.JarInputStream;
|
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
|
|
||||||
public class ClientHandler extends Thread {
|
|
||||||
final Socket client;
|
|
||||||
|
|
||||||
public ClientHandler(Socket client) {
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
client.setSoTimeout(60000);
|
|
||||||
DataOutputStream dos = new DataOutputStream(client.getOutputStream());
|
|
||||||
DataInputStream dis = new DataInputStream(client.getInputStream());
|
|
||||||
|
|
||||||
Cipher decrypt = Cipher.getInstance("RSA");
|
|
||||||
decrypt.init(Cipher.DECRYPT_MODE, SocketHandler.key.getPrivate());
|
|
||||||
|
|
||||||
byte[] aesBytes = new byte[dis.readInt()];
|
|
||||||
dis.readFully(aesBytes);
|
|
||||||
SecretKey aesKey = new SecretKeySpec(decrypt.doFinal(aesBytes), "AES");
|
|
||||||
Cipher aesE = Cipher.getInstance("AES");
|
|
||||||
aesE.init(Cipher.ENCRYPT_MODE, aesKey);
|
|
||||||
Cipher aesD = Cipher.getInstance("AES");
|
|
||||||
aesD.init(Cipher.DECRYPT_MODE, aesKey);
|
|
||||||
|
|
||||||
|
|
||||||
//We are confirming that we are who we say we are
|
|
||||||
byte[] encryptedTicket = new byte[dis.readInt()];
|
|
||||||
dis.readFully(encryptedTicket);
|
|
||||||
String ticket = new String(aesD.doFinal(encryptedTicket));
|
|
||||||
byte[] ticketEcho = aesE.doFinal(ticket.getBytes());
|
|
||||||
dos.writeInt(ticketEcho.length);
|
|
||||||
dos.write(ticketEcho);
|
|
||||||
|
|
||||||
Key key = new Key(ticket);
|
|
||||||
|
|
||||||
String type = dis.readUTF();
|
|
||||||
String username = key.decryptString(dis.readUTF());
|
|
||||||
String password = key.decryptString(dis.readUTF());
|
|
||||||
|
|
||||||
String hwid = key.decryptString(dis.readUTF());
|
|
||||||
hwid = new String(Base64.getEncoder().encode(MessageDigest.getInstance("SHA-512").digest(hwid.getBytes())));
|
|
||||||
boolean dump = dis.readBoolean();
|
|
||||||
String dumpString = key.decryptString(dis.readUTF());
|
|
||||||
String jarHash = key.decryptString(dis.readUTF());
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println("========================================");
|
|
||||||
System.out.println("Client connected: " + client.getInetAddress().getHostAddress());
|
|
||||||
System.out.println(username);
|
|
||||||
System.out.println("can't show the password mate");
|
|
||||||
System.out.println(hwid);
|
|
||||||
System.out.println(dump);
|
|
||||||
System.out.println(dumpString);
|
|
||||||
System.out.println(jarHash);
|
|
||||||
|
|
||||||
int result;
|
|
||||||
// TODO MUST ALWAYS BE FALSE
|
|
||||||
if (false) {
|
|
||||||
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
|
||||||
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!! Granting access due to debug mode");
|
|
||||||
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
|
||||||
result = 2;
|
|
||||||
} else
|
|
||||||
result = UserManager.isUserValid(username, password, hwid);
|
|
||||||
System.out.println(result);
|
|
||||||
|
|
||||||
|
|
||||||
if (Bot.disabled) {
|
|
||||||
dos.writeInt(-3);
|
|
||||||
System.out.println("Auth server down, denying.");
|
|
||||||
System.out.println("========================================");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((result >= 0 || result == -2) && dump) {
|
|
||||||
System.out.println("!!Dump Detected!!");
|
|
||||||
System.out.println("(We are banning this user.)");
|
|
||||||
UserManager.setBanned(username, true);
|
|
||||||
Bot.sendDiscordWebhookMessage("@Staff");
|
|
||||||
Bot.sendDiscordWebhookMessage(username + " " + dumpString);
|
|
||||||
dos.writeInt(-5);
|
|
||||||
System.out.println("========================================");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new URL("http://ip-api.com/json/" + client.getInetAddress().getHostAddress() + "?fields=proxy,hosting").openStream()));
|
|
||||||
JSONObject object = new JSONObject(bufferedReader.readLine());
|
|
||||||
bufferedReader.close();
|
|
||||||
try {
|
|
||||||
boolean proxy = object.getBoolean("proxy");
|
|
||||||
if (proxy) {
|
|
||||||
Bot.sendDiscordWebhookMessage("@Staff");
|
|
||||||
Bot.sendDiscordWebhookMessage(username + " attempted to use BaseBand from a proxy address.");
|
|
||||||
dos.writeInt(-7);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean hosting = object.getBoolean("hosting");
|
|
||||||
if (hosting) {
|
|
||||||
Bot.sendDiscordWebhookMessage("@Staff");
|
|
||||||
Bot.sendDiscordWebhookMessage(username + " attempted to use BaseBand from a hosting address.");
|
|
||||||
dos.writeInt(-7);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
// unknown
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type.contains("installer")) {
|
|
||||||
System.out.println("Installer detected.");
|
|
||||||
int typeInt = dis.readInt();
|
|
||||||
if (result >= 0) {
|
|
||||||
if (typeInt == 0) {
|
|
||||||
dos.writeInt(result);
|
|
||||||
System.out.println("Auth succeeded.");
|
|
||||||
} else {
|
|
||||||
System.out.println("Auth succeeded, Sending loader.");
|
|
||||||
dos.writeInt(result);
|
|
||||||
|
|
||||||
byte[] encryptedBytes = key.encryptByte(aesE.doFinal(SocketHandler.loaderFileData));
|
|
||||||
dos.writeInt(encryptedBytes.length);
|
|
||||||
dos.write(encryptedBytes, 0, encryptedBytes.length);
|
|
||||||
dos.flush();
|
|
||||||
}
|
|
||||||
} else if (result == -4) {
|
|
||||||
System.out.println("Invalid HWID");
|
|
||||||
dos.writeInt(result);
|
|
||||||
} else if (result == -6) {
|
|
||||||
System.out.println("Password Reset Process Initiated.");
|
|
||||||
dos.writeInt(result);
|
|
||||||
String lkey = dis.readUTF();
|
|
||||||
dos.writeBoolean(UserManager.setPasswordIfLicenseKeyCorrect(username, BCrypt.hashpw(password, BCrypt.gensalt(10)), lkey));
|
|
||||||
} else {
|
|
||||||
System.out.println("Auth failed");
|
|
||||||
dos.writeInt(result);
|
|
||||||
}
|
|
||||||
System.out.println("========================================");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
if(!SocketHandler.currentJarHash.equals(jarHash) && !SocketHandler.pastJarHashes.contains(jarHash) && result >= 0) {
|
|
||||||
dos.writeInt(-8);
|
|
||||||
System.out.println("JAR HASH MISMATCH, banning.");
|
|
||||||
UserManager.setBanned(username, true);
|
|
||||||
System.out.println("========================================");
|
|
||||||
Bot.sendDiscordWebhookMessage(username + " has an invalid hash.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!SocketHandler.currentJarHash.equals(jarHash) && SocketHandler.pastJarHashes.contains(jarHash) && result >= 0) {
|
|
||||||
dos.writeInt(-9);
|
|
||||||
System.out.println("JAR HASH MISMATCH, denying.");
|
|
||||||
System.out.println("But it matches an old version, so tell them to redownload it");
|
|
||||||
System.out.println("========================================");
|
|
||||||
Bot.sendDiscordWebhookMessage(username + " has old loader.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (result >= 0 || result == -2) {
|
|
||||||
System.out.println("Client is valid");
|
|
||||||
dos.writeInt(result);
|
|
||||||
|
|
||||||
Map<String, byte[]> data = new HashMap<>();
|
|
||||||
|
|
||||||
|
|
||||||
JarInputStream jar = new JarInputStream(new ByteArrayInputStream(SocketHandler.clientFileData));
|
|
||||||
ZipEntry zentry;
|
|
||||||
|
|
||||||
while ((zentry = jar.getNextEntry()) != null) {
|
|
||||||
data.put(zentry.getName(), getBytes(jar));
|
|
||||||
}
|
|
||||||
dos.writeInt(data.size());
|
|
||||||
|
|
||||||
for (Map.Entry<String, byte[]> entry : data.entrySet()) {
|
|
||||||
//For the love of all that is holy YOU DO NOT TOUCH THIS CODE TUD // i did.
|
|
||||||
|
|
||||||
byte[] cryptKey = SecureRandom.getSeed(1024);
|
|
||||||
|
|
||||||
String className = entry.getKey(); //Name
|
|
||||||
byte[] classData = entry.getValue(); //Data
|
|
||||||
|
|
||||||
dos.writeUTF(Base64.getEncoder().encodeToString(key.encryptByte(aesE.doFinal(className.getBytes()))));
|
|
||||||
|
|
||||||
dos.writeUTF(Base64.getEncoder().encodeToString(key.encryptByte(new Key(cryptKey).encryptByte(classData))));
|
|
||||||
|
|
||||||
dos.writeUTF(Base64.getEncoder().encodeToString(key.encryptByte(aesE.doFinal(cryptKey))));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println("Sent File To Client");
|
|
||||||
System.out.println("========================================");
|
|
||||||
} else {
|
|
||||||
System.out.println("Invalid, Error code " + result);
|
|
||||||
dos.writeInt(result);
|
|
||||||
System.out.println("========================================");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
//this.interrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] getBytes(final InputStream inputStream) throws IOException {
|
|
||||||
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
||||||
final byte[] buffer = new byte[256];
|
|
||||||
int bytesRead;
|
|
||||||
while ((bytesRead = inputStream.read(buffer)) >= 0) {
|
|
||||||
out.write(buffer, 0, bytesRead);
|
|
||||||
}
|
|
||||||
return out.toByteArray();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,158 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2023 Jess H & Daniella H. All Rights Reserved.
|
|
||||||
* Unauthorized copying of this file via any medium is Strictly Prohibited.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package dev.baseband.server.old;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
public class Key {
|
|
||||||
//Daniella made the actual encryption,
|
|
||||||
//Jess made the serialization/byte handling/randomTicket
|
|
||||||
|
|
||||||
protected final String string;
|
|
||||||
|
|
||||||
private boolean debug = false;
|
|
||||||
/**
|
|
||||||
* Generates a random Key
|
|
||||||
*/
|
|
||||||
public Key() {
|
|
||||||
string = randomAlphanumericString(4096);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Key(String key) {
|
|
||||||
string = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Key(byte[] keyData) {
|
|
||||||
string = new String(keyData, StandardCharsets.ISO_8859_1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDebug(boolean debug) {
|
|
||||||
this.debug = debug;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int random(int lower, int upper) {
|
|
||||||
return (int) (Math.floor(Math.random() * (upper - lower)) + lower);
|
|
||||||
}
|
|
||||||
public static String randomString(int length, String pool) {
|
|
||||||
StringBuilder r = new StringBuilder();
|
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
r.append(pool.charAt(random(0, pool.length())));
|
|
||||||
}
|
|
||||||
|
|
||||||
return r.toString();
|
|
||||||
}
|
|
||||||
public static String randomAlphanumericString(int length) {
|
|
||||||
String alphabet = "abcdefghijklmnopqrstuvwxyz";
|
|
||||||
String pool = alphabet + alphabet.toUpperCase() + "0123456789";
|
|
||||||
|
|
||||||
return randomString(length, pool);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public byte[] serializeObject(Object obj) {
|
|
||||||
try {
|
|
||||||
if(debug) {
|
|
||||||
System.out.println(obj + " serialize + encrypt");
|
|
||||||
}
|
|
||||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
||||||
ObjectOutputStream objectOut = new ObjectOutputStream(byteArrayOutputStream);
|
|
||||||
objectOut.writeObject(obj);
|
|
||||||
objectOut.close();
|
|
||||||
return encryptByte(byteArrayOutputStream.toByteArray());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null; // Return null in case of an error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object deserializeObject(byte[] bytes) {
|
|
||||||
try {
|
|
||||||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(decryptByte(bytes));
|
|
||||||
ObjectInputStream objectIn = new ObjectInputStream(byteArrayInputStream);
|
|
||||||
Object obj = objectIn.readObject();
|
|
||||||
objectIn.close();
|
|
||||||
if(debug) {
|
|
||||||
System.out.println(obj + " serialize + encrypt");
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null; // Return null in case of an error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] encryptByte(byte[] bytes) {
|
|
||||||
if(bytes == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
byte[] eb = string.getBytes(StandardCharsets.ISO_8859_1);
|
|
||||||
int len = bytes.length;
|
|
||||||
int p = eb.length;
|
|
||||||
for (int i = 0 ; i < len ; i+=p) {
|
|
||||||
for (int j = 0 ; j < p && i + j < len ; j++) {
|
|
||||||
int idx = i + j;
|
|
||||||
bytes[idx] = (byte) ((int) bytes[idx] + (int) eb[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] decryptByte(byte[] bytes) {
|
|
||||||
if(bytes == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
byte[] eb = string.getBytes(StandardCharsets.ISO_8859_1);
|
|
||||||
int len = bytes.length;
|
|
||||||
int p = eb.length;
|
|
||||||
for (int i = 0 ; i < len ; i+=p) {
|
|
||||||
for (int j = 0 ; j < p && i + j < len ; j++) {
|
|
||||||
int idx = i + j;
|
|
||||||
bytes[idx] = (byte) ((int) bytes[idx] - (int) eb[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encrypts a string
|
|
||||||
* @param s string to encrypt
|
|
||||||
* @return encrypted string
|
|
||||||
*/
|
|
||||||
public String encryptString(String s) {
|
|
||||||
byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
|
|
||||||
byte[] eb = string.getBytes(StandardCharsets.ISO_8859_1);
|
|
||||||
int len = bytes.length;
|
|
||||||
int p = eb.length;
|
|
||||||
for (int i = 0 ; i < len ; i+=p) {
|
|
||||||
for (int j = 0 ; j < p && i + j < len ; j++) {
|
|
||||||
int idx = i + j;
|
|
||||||
bytes[idx] = (byte) ((int) bytes[idx] + (int) eb[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new String(bytes, StandardCharsets.ISO_8859_1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decrypts a string
|
|
||||||
* @param s string to decrypt
|
|
||||||
* @return decrypted string
|
|
||||||
*/
|
|
||||||
public String decryptString(String s) {
|
|
||||||
byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
|
|
||||||
byte[] eb = string.getBytes(StandardCharsets.ISO_8859_1);
|
|
||||||
int len = bytes.length;
|
|
||||||
int p = eb.length;
|
|
||||||
for (int i = 0 ; i < len ; i+=p) {
|
|
||||||
for (int j = 0 ; j < p && i + j < len ; j++) {
|
|
||||||
int idx = i + j;
|
|
||||||
bytes[idx] = (byte) ((int) bytes[idx] - (int) eb[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new String(bytes, StandardCharsets.ISO_8859_1);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,139 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2023 Jess H & Daniella H. All Rights Reserved.
|
|
||||||
* Unauthorized copying of this file via any medium is Strictly Prohibited.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package dev.baseband.server.old;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.security.*;
|
|
||||||
import java.security.spec.InvalidKeySpecException;
|
|
||||||
import java.security.spec.PKCS8EncodedKeySpec;
|
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class SocketHandler {
|
|
||||||
public static KeyPair key;
|
|
||||||
public static KeyFactory factory;
|
|
||||||
public static byte[] clientFileData;
|
|
||||||
public static File clientFile;
|
|
||||||
|
|
||||||
public static byte[] loaderFileData;
|
|
||||||
public static File loaderFile;
|
|
||||||
|
|
||||||
public static Set<String> pastJarHashes;
|
|
||||||
public static String currentJarHash;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static String multiply(String s, int i) {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
for (int j = 0; j < i; j++) {
|
|
||||||
builder.append(s);
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String lengthifyStart(String s, String m, int i) {
|
|
||||||
return multiply(m, (i - s.length()) / m.length()) + s;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void launch(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
|
|
||||||
if (args.length != 2) {
|
|
||||||
System.err.println("Usage: java Main <client>.jar <loader>.jar");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
clientFile = new File(args[0]);
|
|
||||||
clientFileData = readFully(args[0]);
|
|
||||||
|
|
||||||
loaderFile = new File(args[1]);
|
|
||||||
loaderFileData = readFully(args[1]);
|
|
||||||
|
|
||||||
factory = KeyFactory.getInstance("RSA");
|
|
||||||
PrivateKey priv = factory.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode("" +
|
|
||||||
"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDjDW0NxNZjue31" +
|
|
||||||
"iSkZv0E/HVpRlqt1p/QOj8a+g/aEYMC6Gst+WQlx9ZEO5gwp8CLhQ1epcPV1RS2w" +
|
|
||||||
"FbFVneJqqCTHVSABpMcsdN3M8sfd4DvJnj4j3vvZFpVWbcxPvdrqn9VxiGp0cxeh" +
|
|
||||||
"soQBb6hmqDo5jfHkK+lSzGOEJyLV237fbuRwL8uJ+h8BVr3/PzybIMpBlv36CVJ2" +
|
|
||||||
"76Pug9Uow/fl02sQrnA34fRpbOiE14FcVTqvz3zIp35h9Q3aoc76mMdBjfcWNLbc" +
|
|
||||||
"JmaFKb30ZJjjm/FtB+Lvtw6q115lRdOFi8AF7Zb/MBTH3ybuFixoWaTEpjTAV//V" +
|
|
||||||
"J0fFRNuHAgMBAAECggEAb6dWjYLSetAf+LKuh37JsyPYGm8hegZRuidx8JYsUATU" +
|
|
||||||
"QbCTiVp3jpbX8p+mM6lnPadEIIrv6e9O/FxujE/L2+87xtpRlv1VBMOjnvl01+NB" +
|
|
||||||
"A3DR1gn9h0/XuFzeMAiI8wAOknom/4TphhanW51xDqqDl3H6Fd6SKqlf9sjYFJmi" +
|
|
||||||
"swj2KkKJq2y8jgNgQYRUzBGH4iLBKFNdKF3SZqxnrCE6/CUPLzpg+1l4OL3JYI5A" +
|
|
||||||
"YOC7MqrpRxzYl9vCgaD55kCSIhlcmqSD1tfoQICQ8ZZdXpx1Q6NTBhGI0CPUmBrV" +
|
|
||||||
"K6cbtJbtyGRu3rbUFpbuhozZa6a/7iuM3nGF267tQQKBgQD0MA3SKbWYw5RjdKpc" +
|
|
||||||
"ym3GVRsqzLGBdFTDj1Qhsj3zCPQwiUNEaT2JTIDK0Ev1a2Lt/Ib5LFBGYBTfVDaj" +
|
|
||||||
"qkMKKc0ez/JpcLTeMniwQpM17cgx8kcyc9uH8oYuyKipWDA0fv7i3WAFSK8GzrTx" +
|
|
||||||
"DfYt26Z62w5BpB4fiIvqpAmsmQKBgQDuCSySZIeTWec10wVLyKf6o6PrXc7OQFbg" +
|
|
||||||
"uVJHxJ9/fqYRKSctIjOsMCZifLUHkya5EI2w+vLutg087mFlB9THnikZ4tpRBbuX" +
|
|
||||||
"wSEnFb+68RsPXesx7fPXPpu883ZRsg6/en1tUVRTeUpgyDhT06VOvAQHHcvW2zCK" +
|
|
||||||
"2BsXYIy9HwKBgQDqHNxTX1vU/8ZX6DWhyw6eNWBbk26nz9GowNUHjW1pgm8jzaYp" +
|
|
||||||
"g8DUzv039aatwGxUAWWipcK9Bkdcqs/L8GRf7R3U6cffIYi286rUSq/652Olx0RN" +
|
|
||||||
"cdjLKVFOr2FNItjsq8lR1q7Fwh7Upv/BkQIyi0G8ziKH+oJK9042A1mnGQKBgCF+" +
|
|
||||||
"vPzklIdRkU1rokUluS11tW07SAyR1SfOLBvZOTBxm+CyT8b0Fx1VsTEOp1KnjD1i" +
|
|
||||||
"bO3IgkLA71/xk1bqITDtuo7f8ySPj/QswwOC9fXSU6J37s6Z00QolTWjdLTOP3EG" +
|
|
||||||
"RXwKg7kzShoQUozJLWvE3TQ7JyHWuh/vhPBnL6a1AoGBAM5sgfn4q2G8pSf0dmgM" +
|
|
||||||
"RTBFyYRzdgpUqD+yJkdsQIUM5TuVVwx/A3/042wQz4tqJC/ymkkogjf3w3TfwpSA" +
|
|
||||||
"nZbl+JnfipeO0XMBsuvk+UQJHhO08SJy++1gmH+zj77NQXNFE6OwgP3LhIhmZsLH" +
|
|
||||||
"HJanHAL/o+seW4ulFMvnmU76")));
|
|
||||||
PublicKey pub = factory.generatePublic(new X509EncodedKeySpec(Base64.getDecoder().decode("" +
|
|
||||||
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4w1tDcTWY7nt9YkpGb9B" +
|
|
||||||
"Px1aUZardaf0Do/GvoP2hGDAuhrLflkJcfWRDuYMKfAi4UNXqXD1dUUtsBWxVZ3i" +
|
|
||||||
"aqgkx1UgAaTHLHTdzPLH3eA7yZ4+I9772RaVVm3MT73a6p/VcYhqdHMXobKEAW+o" +
|
|
||||||
"Zqg6OY3x5CvpUsxjhCci1dt+327kcC/LifofAVa9/z88myDKQZb9+glSdu+j7oPV" +
|
|
||||||
"KMP35dNrEK5wN+H0aWzohNeBXFU6r898yKd+YfUN2qHO+pjHQY33FjS23CZmhSm9" +
|
|
||||||
"9GSY45vxbQfi77cOqtdeZUXThYvABe2W/zAUx98m7hYsaFmkxKY0wFf/1SdHxUTb" +
|
|
||||||
"hwIDAQAB")));
|
|
||||||
key = new KeyPair(pub, priv);
|
|
||||||
|
|
||||||
byte[] jarHashBytes = MessageDigest.getInstance("SHA-512").digest(loaderFileData);
|
|
||||||
StringBuilder jarHash = new StringBuilder(":");
|
|
||||||
for (byte b : jarHashBytes) {
|
|
||||||
jarHash.append(lengthifyStart(Integer.toHexString(Byte.toUnsignedInt(b)), "0", 2)).append(":");
|
|
||||||
}
|
|
||||||
System.out.println("Current valid jar hash: " + jarHash);
|
|
||||||
currentJarHash = jarHash.toString();
|
|
||||||
FileOutputStream validHashesOut = new FileOutputStream("valid_hashes.txt", true);
|
|
||||||
validHashesOut.close();
|
|
||||||
HashSet<String> hashes = new HashSet<>();
|
|
||||||
BufferedReader reader = new BufferedReader(new FileReader("valid_hashes.txt"));
|
|
||||||
String s;
|
|
||||||
while ((s = reader.readLine()) != null)
|
|
||||||
hashes.add(s);
|
|
||||||
if(!hashes.contains(currentJarHash)) {
|
|
||||||
new PrintStream(validHashesOut).println(jarHash);
|
|
||||||
}
|
|
||||||
SocketHandler.pastJarHashes = hashes;
|
|
||||||
|
|
||||||
ServerSocket socket = new ServerSocket(31212);
|
|
||||||
|
|
||||||
System.out.println("Server started on port 31212");
|
|
||||||
|
|
||||||
//UserManager.flush();
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
java.net.Socket client = socket.accept();
|
|
||||||
|
|
||||||
|
|
||||||
new ClientHandler(client).start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static byte[] readFully(String filename) throws IOException {
|
|
||||||
FileInputStream fis = new FileInputStream(filename);
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
int bytesRead;
|
|
||||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
||||||
while ((bytesRead = fis.read(buffer)) != -1) {
|
|
||||||
output.write(buffer, 0, bytesRead);
|
|
||||||
}
|
|
||||||
fis.close();
|
|
||||||
return output.toByteArray();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,358 +0,0 @@
|
||||||
;/*
|
|
||||||
* Copyright (c) 2023 Jess H & Daniella H. All Rights Reserved.
|
|
||||||
* Unauthorized copying of this file via any medium is Strictly Prohibited.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package dev.baseband.server.old;
|
|
||||||
|
|
||||||
import org.mindrot.jbcrypt.BCrypt;
|
|
||||||
|
|
||||||
import java.sql.*;
|
|
||||||
|
|
||||||
|
|
||||||
public class UserManager {
|
|
||||||
|
|
||||||
|
|
||||||
public static int isUserValid(String user, String password, String hwid) {
|
|
||||||
|
|
||||||
String jdbcUrl = "jdbc:mariadb://localhost:3306/baseband_users";
|
|
||||||
String dbusername = "admin";
|
|
||||||
String dbpass = "alpine!"; //i'll encrypt it later
|
|
||||||
|
|
||||||
Connection connection;
|
|
||||||
|
|
||||||
String selectQuery = "SELECT * FROM users WHERE username = ?";
|
|
||||||
|
|
||||||
try {
|
|
||||||
connection = DriverManager.getConnection(jdbcUrl, dbusername, dbpass);
|
|
||||||
PreparedStatement userVerificationStatement = connection.prepareStatement(selectQuery);
|
|
||||||
userVerificationStatement.setString(1, user);
|
|
||||||
|
|
||||||
ResultSet resultSet = userVerificationStatement.executeQuery();
|
|
||||||
|
|
||||||
if (resultSet.next()) {
|
|
||||||
//String retrievedUsername = resultSet.getString("username");
|
|
||||||
String hashedPassword = resultSet.getString("hashedPassword");
|
|
||||||
boolean isBanned = resultSet.getBoolean("isBanned");
|
|
||||||
String retrievedHwid = resultSet.getString("hwid");
|
|
||||||
boolean isHwidReset = resultSet.getBoolean("isHwidReset");
|
|
||||||
int level = resultSet.getInt("level");
|
|
||||||
|
|
||||||
|
|
||||||
if(isBanned) {
|
|
||||||
return -5; //BANNED
|
|
||||||
}
|
|
||||||
|
|
||||||
if(hashedPassword.equals("reset")) {
|
|
||||||
return -6;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!BCrypt.checkpw(password, hashedPassword)) {
|
|
||||||
return -1; //Generic user info mismatch
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(isHwidReset) {
|
|
||||||
setHwid(user, hwid);
|
|
||||||
return level; //HWID does not match but they are reset, set their reset to false and set their hwid to the last sent one
|
|
||||||
} else {
|
|
||||||
if (!hwid.equals(retrievedHwid)) {
|
|
||||||
return -4; //HWID does not match and they are not reset
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Yooo it worked
|
|
||||||
return level;
|
|
||||||
} else {
|
|
||||||
System.out.println("User not found.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean isInstallerValid(String user, String key) {
|
|
||||||
|
|
||||||
String jdbcUrl = "jdbc:mariadb://localhost:3306/baseband_users";
|
|
||||||
String dbusername = "admin";
|
|
||||||
String dbpass = "alpine!"; //i'll encrypt it later
|
|
||||||
|
|
||||||
Connection connection;
|
|
||||||
|
|
||||||
String selectQuery = "SELECT * FROM users WHERE username = ?";
|
|
||||||
|
|
||||||
try {
|
|
||||||
connection = DriverManager.getConnection(jdbcUrl, dbusername, dbpass);
|
|
||||||
PreparedStatement userVerificationStatement = connection.prepareStatement(selectQuery);
|
|
||||||
userVerificationStatement.setString(1, user);
|
|
||||||
ResultSet resultSet = userVerificationStatement.executeQuery();
|
|
||||||
|
|
||||||
if (resultSet.next()) {
|
|
||||||
String hashedPassword = resultSet.getString("hashedPassword");
|
|
||||||
boolean isBanned = resultSet.getBoolean("isBanned");
|
|
||||||
|
|
||||||
if(hashedPassword.equals("reset") && !isBanned && resultSet.getString("licenseKey").equals(key)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}catch (Exception e){}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean createUser(String username, String licenseKey, String discordUserId) {
|
|
||||||
|
|
||||||
String jdbcUrl = "jdbc:mariadb://localhost:3306/baseband_users";
|
|
||||||
String dbusername = "admin";
|
|
||||||
String dbpass = "alpine!"; //i'll encrypt it later
|
|
||||||
|
|
||||||
Connection connection;
|
|
||||||
|
|
||||||
String insertQuery = "INSERT INTO users (username, hashedPassword, isBanned, isHwidReset, hwid, licenseKey, discordUserId, level) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
|
||||||
|
|
||||||
try {
|
|
||||||
connection = DriverManager.getConnection(jdbcUrl, dbusername, dbpass);
|
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement(insertQuery);
|
|
||||||
preparedStatement.setString(1, username);
|
|
||||||
preparedStatement.setString(2, "reset"); //password kekw
|
|
||||||
preparedStatement.setBoolean(3, false); // 0 for not banned
|
|
||||||
preparedStatement.setBoolean(4, true); // 0 for not banned
|
|
||||||
preparedStatement.setString(5, "unset"); //HWID
|
|
||||||
preparedStatement.setString(6, licenseKey); // Set the licenseKey value here
|
|
||||||
preparedStatement.setString(7, discordUserId); // Set the discord user id
|
|
||||||
preparedStatement.setInt(8,0); //They are normal by default
|
|
||||||
|
|
||||||
int rowsAffected = preparedStatement.executeUpdate();
|
|
||||||
|
|
||||||
if (rowsAffected > 0) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean setHwid(String username, String hwid) {
|
|
||||||
String jdbcUrl = "jdbc:mariadb://localhost:3306/baseband_users";
|
|
||||||
String dbusername = "admin";
|
|
||||||
String dbpass = "alpine!"; //i'll encrypt it later
|
|
||||||
|
|
||||||
Connection connection;
|
|
||||||
|
|
||||||
String updateHwidQuery = "UPDATE users SET hwid = ?, isHwidReset = ? WHERE username = ?";
|
|
||||||
try {
|
|
||||||
connection = DriverManager.getConnection(jdbcUrl, dbusername, dbpass);
|
|
||||||
PreparedStatement updateHWIDStatement = connection.prepareStatement(updateHwidQuery);
|
|
||||||
updateHWIDStatement.setString(1, hwid);
|
|
||||||
updateHWIDStatement.setBoolean(2, false); // Set hwidReset to false
|
|
||||||
updateHWIDStatement.setString(3, username);
|
|
||||||
|
|
||||||
int rowsAffected = updateHWIDStatement.executeUpdate();
|
|
||||||
|
|
||||||
if (rowsAffected > 0) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean setHwidReset(String username, boolean hwidReset) {
|
|
||||||
String jdbcUrl = "jdbc:mariadb://localhost:3306/baseband_users";
|
|
||||||
String dbusername = "admin";
|
|
||||||
String dbpass = "alpine!"; //i'll encrypt it later
|
|
||||||
|
|
||||||
Connection connection;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String updateHwidResetQuery = "UPDATE users SET isHwidReset = ? WHERE username = ?";
|
|
||||||
|
|
||||||
try {
|
|
||||||
connection = DriverManager.getConnection(jdbcUrl, dbusername, dbpass);
|
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement(updateHwidResetQuery);
|
|
||||||
preparedStatement.setBoolean(1, hwidReset);
|
|
||||||
preparedStatement.setString(2, username);
|
|
||||||
|
|
||||||
int rowsAffected = preparedStatement.executeUpdate();
|
|
||||||
|
|
||||||
if (rowsAffected > 0) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean setHwidResetByUseID(String id, boolean hwidReset) {
|
|
||||||
String jdbcUrl = "jdbc:mariadb://localhost:3306/baseband_users";
|
|
||||||
String dbusername = "admin";
|
|
||||||
String dbpass = "alpine!"; //i'll encrypt it later
|
|
||||||
|
|
||||||
Connection connection;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String updateHwidResetQuery = "UPDATE users SET isHwidReset = ? WHERE discordUserId = ?";
|
|
||||||
|
|
||||||
try {
|
|
||||||
connection = DriverManager.getConnection(jdbcUrl, dbusername, dbpass);
|
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement(updateHwidResetQuery);
|
|
||||||
preparedStatement.setBoolean(1, hwidReset);
|
|
||||||
preparedStatement.setString(2, id);
|
|
||||||
|
|
||||||
int rowsAffected = preparedStatement.executeUpdate();
|
|
||||||
|
|
||||||
if (rowsAffected > 0) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean setPermLevelById(String id, int level) {
|
|
||||||
String jdbcUrl = "jdbc:mariadb://localhost:3306/baseband_users";
|
|
||||||
String dbusername = "admin";
|
|
||||||
String dbpass = "alpine!"; //i'll encrypt it later
|
|
||||||
|
|
||||||
Connection connection;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String updateHwidResetQuery = "UPDATE users SET level = ? WHERE discordUserId = ?";
|
|
||||||
|
|
||||||
try {
|
|
||||||
connection = DriverManager.getConnection(jdbcUrl, dbusername, dbpass);
|
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement(updateHwidResetQuery);
|
|
||||||
preparedStatement.setInt(1, level);
|
|
||||||
preparedStatement.setString(2, id);
|
|
||||||
|
|
||||||
int rowsAffected = preparedStatement.executeUpdate();
|
|
||||||
|
|
||||||
if (rowsAffected > 0) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getUserNameByUserID(String id) {
|
|
||||||
String jdbcUrl = "jdbc:mariadb://localhost:3306/baseband_users";
|
|
||||||
String dbusername = "admin";
|
|
||||||
String dbpass = "alpine!"; //i'll encrypt it later
|
|
||||||
|
|
||||||
Connection connection;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String getUsernameByDiscordQuery = "SELECT * FROM users WHERE discordUserId = ?";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
connection = DriverManager.getConnection(jdbcUrl, dbusername, dbpass);
|
|
||||||
PreparedStatement getUsernameByDiscordStatement = connection.prepareStatement(getUsernameByDiscordQuery);
|
|
||||||
getUsernameByDiscordStatement.setString(1, id);
|
|
||||||
|
|
||||||
ResultSet resultSet = getUsernameByDiscordStatement.executeQuery();
|
|
||||||
|
|
||||||
if (resultSet.next()) {
|
|
||||||
return resultSet.getString("username");
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return "Error!";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean setPassword(String username, String password) {
|
|
||||||
String jdbcUrl = "jdbc:mariadb://localhost:3306/baseband_users";
|
|
||||||
String dbusername = "admin";
|
|
||||||
String dbpass = "alpine!"; //i'll encrypt it later
|
|
||||||
|
|
||||||
Connection connection;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String updatePasswordQuery = "UPDATE users SET hashedPassword = ? WHERE username = ?";
|
|
||||||
|
|
||||||
try {
|
|
||||||
connection = DriverManager.getConnection(jdbcUrl, dbusername, dbpass);
|
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement(updatePasswordQuery);
|
|
||||||
preparedStatement.setString(1, password);
|
|
||||||
preparedStatement.setString(2, username);
|
|
||||||
|
|
||||||
|
|
||||||
int rowsAffected = preparedStatement.executeUpdate();
|
|
||||||
|
|
||||||
return rowsAffected > 0;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean setBanned(String username, boolean banned) {
|
|
||||||
String jdbcUrl = "jdbc:mariadb://localhost:3306/baseband_users";
|
|
||||||
String dbusername = "admin";
|
|
||||||
String dbpass = "alpine!"; //i'll encrypt it later
|
|
||||||
|
|
||||||
Connection connection;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String updateIsBannedQuery = "UPDATE users SET isBanned = ? WHERE username = ?";
|
|
||||||
|
|
||||||
try {
|
|
||||||
connection = DriverManager.getConnection(jdbcUrl, dbusername, dbpass);
|
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement(updateIsBannedQuery);
|
|
||||||
preparedStatement.setBoolean(1, banned);
|
|
||||||
preparedStatement.setString(2, username);
|
|
||||||
|
|
||||||
int rowsAffected = preparedStatement.executeUpdate();
|
|
||||||
|
|
||||||
return rowsAffected > 0;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean setPasswordIfLicenseKeyCorrect(String username, String hashpw, String licenseKey) {
|
|
||||||
if (isInstallerValid(username, licenseKey)) {
|
|
||||||
setPassword(username, hashpw);
|
|
||||||
return true;
|
|
||||||
}else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue