Skip to content

Commit

Permalink
Update Main.java
Browse files Browse the repository at this point in the history
fix some issues
  • Loading branch information
MouathA authored Apr 1, 2024
1 parent 2383b1b commit 05fba75
Showing 1 changed file with 17 additions and 33 deletions.
50 changes: 17 additions & 33 deletions src/main/java/org/Mouath/Main.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package org.Mouath;

import org.apache.commons.cli.*;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
Expand Down Expand Up @@ -48,23 +49,19 @@ public static void main(String[] args) {
List<String> modifiedLines = processUrls(text, patterns, payloads, delayTime);
writeTextToFile("output.txt", modifiedLines);
System.out.println("\u001B[32m[+] Parameter replacement completed. Output written to output.txt.");
System.out.print("\u001B[0m");
} else {
System.err.println("\u001B[31m[!] Error reading input text or payloads file.");
System.out.print("\u001B[0m");
}
} else {
System.err.println("\u001B[31m[!] Input file path is required. Use -i option.");
displayHelp(options);
System.out.print("\u001B[0m");
}
} catch (ParseException e) {
System.err.println("\u001B[31m[!] Error parsing command-line arguments: " + e.getMessage());
System.out.print("\u001B[0m");
} catch (IOException e) {
System.err.println("\u001B[31m[!] Error processing text or payloads: " + e.getMessage());
System.out.print("\u001B[0m");
}
resetConsoleColor();
}

private static void displayHelp(Options options) {
Expand Down Expand Up @@ -109,7 +106,6 @@ private static List<String> processUrls(String text, List<String> patterns, List
for (String line : lines) {
StringBuilder modifiedLine = new StringBuilder(line);


boolean lineMatchesPattern = false;
for (String pattern : patterns) {
if (line.contains(pattern)) {
Expand All @@ -118,22 +114,23 @@ private static List<String> processUrls(String text, List<String> patterns, List
}
}


if (lineMatchesPattern) {
for (String pattern : patterns) {
String regex = Pattern.quote(pattern) + "([^=&]+)";
Matcher matcher = Pattern.compile(regex).matcher(line);
while (matcher.find()) {
String parameter = matcher.group(1);
for (String lfiPayload : payloads) {
for (String lfiPayload : payloads) {
StringBuilder tempLine = new StringBuilder(line);
for (String pattern : patterns) {
String regex = Pattern.quote(pattern) + "([^=&]+)";
Matcher matcher = Pattern.compile(regex).matcher(tempLine);
while (matcher.find()) {
String parameter = matcher.group(1);
int startIndex = matcher.start(1);
int endIndex = matcher.end(1);
if (startIndex >= 0 && endIndex <= modifiedLine.length()) {
modifiedLine.replace(startIndex, endIndex, lfiPayload);
String urlWithPayload = modifiedLine.toString();
if (startIndex >= 0 && endIndex <= tempLine.length()) {
tempLine.replace(startIndex, endIndex, lfiPayload);
String urlWithPayload = tempLine.toString();
if (isValidUrl(urlWithPayload) && lfiPayloadWorks(urlWithPayload)) {
modifiedLines.add("[+] LFI vulnerability detected with payload: " + urlWithPayload);
System.out.println("\u001B[32m[+] LFI vulnerability detected with payload: " + urlWithPayload);
break;
} else {
try {
Thread.sleep(delayTime);
Expand All @@ -150,30 +147,14 @@ private static List<String> processUrls(String text, List<String> patterns, List
}
} else {
modifiedLines.add("[!] Line does not match any specified pattern. Skipping: " + line);

System.out.println("\u001B[33m[!] Line does not match any specified pattern. Skipping: " + line);
}
}


System.out.println("\u001B[36m[+] Processing completed. Exiting program.");
resetConsoleColor();

return modifiedLines;
}

private static void resetConsoleColor() {
System.out.print("\u001B[0m");
try {

Process process = Runtime.getRuntime().exec("cmd /c exit");
process.destroy();

} catch (IOException e) {
System.err.println("\u001B[31m[!] Error exiting the program: " + e.getMessage());
System.out.print("\u001B[0m");
}
}

private static boolean isValidUrl(String url) {
try {
Expand All @@ -185,7 +166,6 @@ private static boolean isValidUrl(String url) {
}
}


private static boolean lfiPayloadWorks(String url) {
try {
Document doc = Jsoup.connect(url).get();
Expand All @@ -196,4 +176,8 @@ private static boolean lfiPayloadWorks(String url) {
return false;
}
}

private static void resetConsoleColor() {
System.out.print("\u001B[0m");
}
}

0 comments on commit 05fba75

Please sign in to comment.