adding validated services? patching forcad_local.py
This commit is contained in:
247
OmCTF-2025/sploits/jform/CheckLib.java
Normal file
247
OmCTF-2025/sploits/jform/CheckLib.java
Normal file
@@ -0,0 +1,247 @@
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class CheckLib {
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final SecureRandom secureRandom = new SecureRandom();
|
||||
|
||||
private static final String ALPHANUMERIC = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
private static final String ALPHA_LOWER = "abcdefghijklmnopqrstuvwxyz";
|
||||
private static final String ALPHA_UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
private static final String NUMERIC = "0123456789";
|
||||
private static final String HEX = "0123456789abcdef";
|
||||
|
||||
public static String rndString(int length) {
|
||||
return rndAlphanumeric(length);
|
||||
}
|
||||
|
||||
public static String generateUsername() {
|
||||
return "user_" + timestampSec() + "_" + rndAlphaLower(6);
|
||||
}
|
||||
|
||||
public static String generateUsername(String prefix) {
|
||||
return prefix + "_" + timestampSec() + "_" + rndAlphaLower(6);
|
||||
}
|
||||
|
||||
public static String generatePassword() {
|
||||
return rndAlphanumeric(16);
|
||||
}
|
||||
|
||||
public static String generatePassword(int length) {
|
||||
return rndAlphanumeric(length);
|
||||
}
|
||||
|
||||
public static String rndAlphanumeric(int length) {
|
||||
return randomString(length, ALPHANUMERIC);
|
||||
}
|
||||
|
||||
public static String rndAlphaLower(int length) {
|
||||
return randomString(length, ALPHA_LOWER);
|
||||
}
|
||||
|
||||
public static String rndAlphaUpper(int length) {
|
||||
return randomString(length, ALPHA_UPPER);
|
||||
}
|
||||
|
||||
public static String rndNumeric(int length) {
|
||||
return randomString(length, NUMERIC);
|
||||
}
|
||||
|
||||
public static String rndHex(int length) {
|
||||
return randomString(length, HEX);
|
||||
}
|
||||
|
||||
public static String randomString(int length, String charset) {
|
||||
StringBuilder sb = new StringBuilder(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
sb.append(charset.charAt(random.nextInt(charset.length())));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static byte[] rndBytes(int length) {
|
||||
byte[] bytes = new byte[length];
|
||||
secureRandom.nextBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] rndBytesFast(int length) {
|
||||
byte[] bytes = new byte[length];
|
||||
random.nextBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static int rndInt(int min, int max) {
|
||||
return random.nextInt(max - min) + min;
|
||||
}
|
||||
|
||||
public static int rndInt(int max) {
|
||||
return random.nextInt(max);
|
||||
}
|
||||
|
||||
public static long rndLong() {
|
||||
return random.nextLong();
|
||||
}
|
||||
|
||||
public static String toHex(byte[] bytes) {
|
||||
StringBuilder sb = new StringBuilder(bytes.length * 2);
|
||||
for (byte b : bytes) {
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static byte[] fromHex(String hex) {
|
||||
int len = hex.length();
|
||||
byte[] data = new byte[len / 2];
|
||||
for (int i = 0; i < len; i += 2) {
|
||||
data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4)
|
||||
+ Character.digit(hex.charAt(i+1), 16));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static String toBase64(byte[] bytes) {
|
||||
return Base64.getEncoder().encodeToString(bytes);
|
||||
}
|
||||
|
||||
public static String toBase64(String str) {
|
||||
return Base64.getEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public static byte[] fromBase64(String base64) {
|
||||
return Base64.getDecoder().decode(base64);
|
||||
}
|
||||
|
||||
public static String fromBase64String(String base64) {
|
||||
return new String(Base64.getDecoder().decode(base64), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static String toBase64Url(byte[] bytes) {
|
||||
return Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
|
||||
}
|
||||
|
||||
public static byte[] fromBase64Url(String base64) {
|
||||
return Base64.getUrlDecoder().decode(base64);
|
||||
}
|
||||
|
||||
public static String md5(String input) {
|
||||
return hash(input, "MD5");
|
||||
}
|
||||
|
||||
public static String sha1(String input) {
|
||||
return hash(input, "SHA-1");
|
||||
}
|
||||
|
||||
public static String sha256(String input) {
|
||||
return hash(input, "SHA-256");
|
||||
}
|
||||
|
||||
public static String hash(String input, String algorithm) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance(algorithm);
|
||||
byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
||||
return toHex(hash);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Hash failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] hashBytes(byte[] input, String algorithm) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance(algorithm);
|
||||
return md.digest(input);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Hash failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static long timestamp() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public static long timestampSec() {
|
||||
return System.currentTimeMillis() / 1000;
|
||||
}
|
||||
|
||||
public static void sleep(long ms) {
|
||||
try {
|
||||
Thread.sleep(ms);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public static void sleepSec(long seconds) {
|
||||
sleep(seconds * 1000);
|
||||
}
|
||||
|
||||
public static String repeat(String str, int count) {
|
||||
return str.repeat(count);
|
||||
}
|
||||
|
||||
public static String padLeft(String str, int length, char padChar) {
|
||||
if (str.length() >= length) return str;
|
||||
return String.valueOf(padChar).repeat(length - str.length()) + str;
|
||||
}
|
||||
|
||||
public static String padRight(String str, int length, char padChar) {
|
||||
if (str.length() >= length) return str;
|
||||
return str + String.valueOf(padChar).repeat(length - str.length());
|
||||
}
|
||||
|
||||
public static void info(String msg) {
|
||||
System.out.println("[*] " + msg);
|
||||
}
|
||||
|
||||
public static void success(String msg) {
|
||||
System.out.println("[+] " + msg);
|
||||
}
|
||||
|
||||
public static void error(String msg) {
|
||||
System.out.println("[-] " + msg);
|
||||
}
|
||||
|
||||
public static void warn(String msg) {
|
||||
System.out.println("[!] " + msg);
|
||||
}
|
||||
|
||||
public static void debug(String msg) {
|
||||
System.out.println("[DEBUG] " + msg);
|
||||
}
|
||||
|
||||
public static void hexDump(byte[] data) {
|
||||
hexDump(data, 16);
|
||||
}
|
||||
|
||||
public static void hexDump(byte[] data, int bytesPerLine) {
|
||||
for (int i = 0; i < data.length; i += bytesPerLine) {
|
||||
System.out.printf("%08x: ", i);
|
||||
|
||||
for (int j = 0; j < bytesPerLine; j++) {
|
||||
if (i + j < data.length) {
|
||||
System.out.printf("%02x ", data[i + j]);
|
||||
} else {
|
||||
System.out.print(" ");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.print(" | ");
|
||||
|
||||
for (int j = 0; j < bytesPerLine && i + j < data.length; j++) {
|
||||
byte b = data[i + j];
|
||||
if (b >= 32 && b < 127) {
|
||||
System.out.print((char) b);
|
||||
} else {
|
||||
System.out.print('.');
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user