adding validated services? patching forcad_local.py
This commit is contained in:
62
OmCTF-2025/sploits/jform/AttackData.java
Normal file
62
OmCTF-2025/sploits/jform/AttackData.java
Normal file
@@ -0,0 +1,62 @@
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class AttackData {
|
||||
|
||||
public static List<Map<String, String>> getAttackData(String host, String attackDataUrl) throws Exception {
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(attackDataUrl))
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
String responseBody = response.body();
|
||||
|
||||
return parseAttackData(responseBody, host, attackDataUrl);
|
||||
}
|
||||
|
||||
private static List<Map<String, String>> parseAttackData(String jsonResponse, String host, String attackDataUrl) {
|
||||
List<Map<String, String>> userData = new ArrayList<>();
|
||||
|
||||
String hostPattern = "\"" + Pattern.quote(host) + "\"\\s*:\\s*\\[([^\\]]+)\\]";
|
||||
Pattern pattern = Pattern.compile(hostPattern, Pattern.DOTALL);
|
||||
Matcher matcher = pattern.matcher(jsonResponse);
|
||||
|
||||
if (matcher.find()) {
|
||||
String arrayContent = matcher.group(1);
|
||||
|
||||
Pattern userPattern = Pattern.compile("\\{\\\\\"userId\\\\\":\\s*\\\\\"(\\d+)\\\\\",\\s*\\\\\"username\\\\\":\\s*\\\\\"([^\\\\\"]+)\\\\\"\\}");
|
||||
Matcher userMatcher = userPattern.matcher(arrayContent);
|
||||
|
||||
while (userMatcher.find()) {
|
||||
Map<String, String> user = new HashMap<>();
|
||||
user.put("userId", userMatcher.group(1));
|
||||
user.put("username", userMatcher.group(2));
|
||||
userData.add(user);
|
||||
}
|
||||
}
|
||||
|
||||
return userData;
|
||||
}
|
||||
|
||||
public static Map<String, String> getFirstUser(String host, String attackDataUrl) throws Exception {
|
||||
List<Map<String, String>> users = getAttackData(host, attackDataUrl);
|
||||
if (users.isEmpty()) {
|
||||
throw new Exception("No attack data found for host: " + host);
|
||||
}
|
||||
return users.get(0);
|
||||
}
|
||||
|
||||
public static List<Map<String, String>> getAllUsers(String host, String attackDataUrl) throws Exception {
|
||||
return getAttackData(host, attackDataUrl);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user