Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 89 additions & 35 deletions FactionBurp/src/com/faction/api/FactionAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,24 @@ public class FactionAPI {

private String SERVER = "";
private String TOKEN = "";
private String PORT = "8090"; // Initialiser PORT avec une chaîne
// Valeur par défaut pour HTTP, 443 pour HTTPS par exemple
private Integer refresh;
private LinkedHashMap<String, Integer> levelMap = new LinkedHashMap();
private int highSev = 4;
private int medSev = 3;
private int lowSev = 2;
private int infoSev = 0;
public static final String ADDVULN = "/assessments/addVuln/";
public static final String ADDDEFAULTVULN = "/assessments/addDefaultVuln/";
public static final String SEARCH_DEFAULT_VULN = "/vulnerabilities/default/";
public static final String QUEUE = "/assessments/queue";
public static final String VQUEUE = "/verifications/queue";
public static final String GETVULN = "/assessments/vuln/";
public static final String GETVULNS = "/assessments/vulns/";
public static final String SETNOTE = "/assessments/notes/";
public static final String HISTORY = "/assessments/history/";
public static final String LEVELS = "/vulnerabilities/getrisklevels/";
public static final String ADDVULN = "/api/assessments/addVuln/";
public static final String ADDDEFAULTVULN = "/api/assessments/addDefaultVuln/";
public static final String SEARCH_DEFAULT_VULN = "/api/vulnerabilities/default/";
public static final String QUEUE = "/api/assessments/queue";
public static final String VQUEUE = "/api/verifications/queue";
public static final String GETVULN = "/api/assessments/vuln/";
public static final String GETVULNS = "/api/assessments/vulns/";
public static final String SETNOTE = "/api/assessments/notes/";
public static final String HISTORY = "/api/assessments/history/";
public static final String LEVELS = "/api/vulnerabilities/getrisklevels/";

public static final String BURP_SEV_HIGH = "high";
public static final String BURP_SEV_MED = "medium";
Expand Down Expand Up @@ -113,10 +115,12 @@ public String getSeverityStringFromSeverityId(Integer sevId) {
public void updateProps(String server, String token, String refresh) {
this.SERVER = server;
this.TOKEN = token;
this.PORT = PORT;
this.refresh = Integer.parseInt(refresh);
Properties props = this.getProps();
props.setProperty("server", server);
props.setProperty("token", token);
props.setProperty("port", PORT);
props.setProperty("refresh", refresh);
String path = System.getProperty("user.home") + File.separator + "/.faction" + File.separator;
File f = new File(path + "faction.properties");
Expand Down Expand Up @@ -147,15 +151,14 @@ public void updateSev(String burpSevName, String sevName) {
e.printStackTrace();
}
}

public Properties getProps() {
Properties props = new Properties();
InputStream is = null;

try {
String path = System.getProperty("user.home") + File.separator + "/.faction" + File.separator;
File f = new File(path + "faction.properties");

if (!f.exists()) {
File p = new File(path);
if (!p.exists()) {
Expand All @@ -167,18 +170,20 @@ public Properties getProps() {
props.load(is);
this.SERVER = props.getProperty("server", "");
this.TOKEN = props.getProperty("token", "");
this.PORT = props.getProperty("port", "8090"); // Chargement du port
this.refresh = Integer.parseInt(props.getProperty("refresh", "20"));
this.highSev = Integer.parseInt(props.getProperty(BURP_SEV_HIGH, "4"));
this.medSev = Integer.parseInt(props.getProperty(BURP_SEV_MED, "3"));
this.lowSev = Integer.parseInt(props.getProperty(BURP_SEV_LOW, "2"));
this.infoSev = Integer.parseInt(props.getProperty(BURP_SEV_INFO, "0"));
// ... le reste de la méthode ...
return props;
} catch (Exception e) {
is = null;
e.printStackTrace();
return null;
}
return null;

}


public LinkedHashMap<String, Integer> getLevelMap() {
JSONArray array = this.executeGet(LEVELS);
Expand All @@ -196,31 +201,56 @@ public LinkedHashMap<String, Integer> getLevelMap() {

public JSONArray executePost(String targetURL, String postData) {
try {
logging.logToOutput("Sending Post");
URL url = new URL(this.SERVER);
logging.logToOutput("Sending Post");
URL url = new URL(this.SERVER + ":" + this.PORT + targetURL); // Assurez-vous que l'URL est correcte
logging.logToOutput("URL: " + url.toString()); // Journaliser l'URL complète
String targetHost = url.getHost();
String targetPath = url.getPath();
boolean isSecure = url.getProtocol().equals("https") ;
HttpService service = HttpService
.httpService(targetHost, isSecure);
int portInt = Integer.parseInt(this.PORT);
boolean isSecure = url.getProtocol().equals("https");
HttpService service = HttpService.httpService(targetHost, portInt, isSecure);

HttpRequest request = HttpRequest
.httpRequest()
.withService(service)
.withHeader("Host", targetHost)
.withMethod("POST")
.withPath(targetPath + targetURL)
.withPath(targetURL)
.withAddedHeader("FACTION-API-KEY", this.TOKEN)
.withAddedHeader("Content-Language", "en-US")
.withAddedHeader("Accept", "application/json")
.withAddedHeader("Content-Type", "application/x-www-form-urlencoded")
.withBody(postData);
CompletableFuture<HttpRequestResponse> requestResponse = CompletableFuture.supplyAsync(() ->{

// Journaliser les détails de la requête
logging.logToOutput("Request Headers: " + request.headers().toString());
logging.logToOutput("Request Body: " + postData);

CompletableFuture<HttpRequestResponse> requestResponse = CompletableFuture.supplyAsync(() -> {
HttpRequestResponse response = http.sendRequest(request);
return response;
});

HttpRequestResponse response = requestResponse.get();

logging.logToOutput("Sending request to: " + url.toString());
logging.logToOutput("Request Method: " + request.method().toString());
logging.logToOutput("Request Headers: " + request.headers().toString());
if (request.method().equals("POST")) {
logging.logToOutput("Request Body: " + postData); // Pour les requêtes POST uniquement
}
if (response != null && response.hasResponse()) {
logging.logToOutput("Received response with status code: " + response.response().statusCode());

// Imprimer les en-têtes de réponse
logging.logToOutput("Response Headers: " + response.response().headers().toString());

// Imprimer le corps de la réponse, s'il est présent
if (response.response().body() != null) {
logging.logToOutput("Response Body: " + response.response().bodyToString());
}
} else {
logging.logToOutput("No response received.");
}

if (response.hasResponse() && response.response().statusCode() == 200) {
String jsonString = response.response().bodyToString();

Expand All @@ -246,28 +276,49 @@ public JSONArray executePost(String targetURL, String postData) {

public JSONArray executeGet(String targetURL) {
try {
URL url = new URL(this.SERVER);
URL url = new URL(this.SERVER + ":" + this.PORT + targetURL); // Assurez-vous que l'URL est correcte
logging.logToOutput("URL: " + url.toString()); // Journaliser l'URL complète
String targetHost = url.getHost();
String targetPath = url.getPath();
boolean isSecure = url.getProtocol().equals("https") ;
HttpService service = HttpService
.httpService(targetHost, isSecure);
int portInt = Integer.parseInt(this.PORT);
boolean isSecure = url.getProtocol().equals("https");
HttpService service = HttpService.httpService(targetHost, portInt, isSecure);

HttpRequest request = HttpRequest
.httpRequest()
.withService(service)
.withHeader("Host", targetHost)
.withMethod("GET")
.withPath(targetPath + targetURL.replace("+", "%20"))
.withPath(targetURL.replace("+", "%20"))
.withAddedHeader("FACTION-API-KEY", this.TOKEN)
.withAddedHeader("Content-Language", "en-US")
.withAddedHeader("Accept", "application/json");

CompletableFuture<HttpRequestResponse> requestResponse = CompletableFuture.supplyAsync(() ->{

// Journaliser les détails de la requête
logging.logToOutput("Request Headers: " + request.headers().toString());

CompletableFuture<HttpRequestResponse> requestResponse = CompletableFuture.supplyAsync(() -> {
HttpRequestResponse response = http.sendRequest(request);
return response;
});
logging.logToOutput("Sending request to: " + url.toString());
logging.logToOutput("Request Method: " + request.method().toString());
logging.logToOutput("Request Headers: " + request.headers().toString());


HttpRequestResponse response = requestResponse.get();
if (response != null && response.hasResponse()) {
logging.logToOutput("Received response with status code: " + response.response().statusCode());

// Imprimer les en-têtes de réponse
logging.logToOutput("Response Headers: " + response.response().headers().toString());

// Imprimer le corps de la réponse, s'il est présent
if (response.response().body() != null) {
logging.logToOutput("Response Body: " + response.response().bodyToString());
}
} else {
logging.logToOutput("No response received.");
}
if (response.hasResponse() && response.response().statusCode() == 200) {
JSONParser parser = new JSONParser();
try {
Expand All @@ -288,7 +339,10 @@ public JSONArray executeGet(String targetURL) {
}

public String getCSS() {
return SERVER.replace("api", "") + "service/rd_styles.css";
// Cette version suppose que SERVER inclut le protocole, l'hôte et le port si nécessaire.
// Elle ajoute simplement le chemin approprié au fichier CSS, sans tenter de remplacer ou d'ajuster "api".
return SERVER + "/service/rd_styles.css";
}


}
8 changes: 4 additions & 4 deletions FactionBurp/src/com/faction/gui/FactionGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void valueChanged(ListSelectionEvent event) {
int row = verTable.convertRowIndexToModel(r);

Long vid = (Long)verModel.getValueAt(row, 4);
JSONArray json = factionApi.executeGet("/assessments/vuln/" + vid);
JSONArray json = factionApi.executeGet("/api/assessments/vuln/" + vid);
JSONObject j = (JSONObject)json.get(0);
VulnerabilityDetailsPane test = new VulnerabilityDetailsPane(factionApi,(String)j.get("Name"), (String)j.get("Description"),(String)j.get("Recommendation"), (String)j.get("Details"), legacyCallback);
test.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
Expand Down Expand Up @@ -241,7 +241,7 @@ public void valueChanged(ListSelectionEvent event) {
notes2Txt.setText(notes[1]==null? "Nothing to Show" : notes[1]);
JSONArray json = new JSONArray();
try {
json = factionApi.executeGet("/assessments/history/" + URLEncoder.encode(appId,"UTF-8"));
json = factionApi.executeGet("/api/assessments/history/" + URLEncoder.encode(appId,"UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -410,7 +410,7 @@ public void valueChanged(ListSelectionEvent event) {
int r = vulnTable.getSelectedRow();
int row = vulnTable.convertRowIndexToModel(r);
Long vid = (Long)vulnModel.getValueAt(row, 6);
JSONArray json = factionApi.executeGet("/assessments/vuln/" + vid);
JSONArray json = factionApi.executeGet("/api/assessments/vuln/" + vid);
JSONObject j = (JSONObject)json.get(0);
VulnerabilityDetailsPane test = new VulnerabilityDetailsPane(factionApi,(String)j.get("Name"), j.get("Description").toString(),j.get("Recommendation").toString(),j.get("Details").toString(), legacyCallback);
test.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
Expand Down Expand Up @@ -659,7 +659,7 @@ private synchronized void updateAPI() {
if(!appId.equals("")){
JSONArray vulns = new JSONArray();
try {
vulns = factionApi.executeGet("/assessments/history/" + URLEncoder.encode(appId,"UTF-8"));
vulns = factionApi.executeGet("/api/assessments/history/" + URLEncoder.encode(appId,"UTF-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down
31 changes: 30 additions & 1 deletion FactionBurp/src/com/faction/gui/SendToFaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import javax.swing.Box;
import java.awt.Dimension;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.JButton;
Expand Down Expand Up @@ -254,6 +255,7 @@ public void actionPerformed(ActionEvent arg0) {
searchPanel.add(lblSearch, gbc_lblSearch);

vulnSearch = new JTextField();
/*
vulnSearch.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent arg0) {
Expand Down Expand Up @@ -294,7 +296,34 @@ public void keyTyped(KeyEvent arg0) {
}

}
}); */
vulnSearch.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) { // Changed from keyTyped to keyReleased
SwingUtilities.invokeLater(new Runnable() { // Ensure updates are made on the EDT
public void run() {
if(vulnSearch.getText().length() >= 2){
// Perform the search and update the JComboBox
JSONArray jarray = factionApi.executeGet(FactionAPI.SEARCH_DEFAULT_VULN + vulnSearch.getText());
DefaultComboBoxModel model = (DefaultComboBoxModel) defaultVulns.getModel();
model.removeAllElements(); // Clear existing items
_defaultVulns.clear();
for(int i=0; i< jarray.size(); i++){
JSONObject obj = (JSONObject)jarray.get(i);
String itemName = ""+obj.get("Name");
model.addElement(itemName);
_defaultVulns.put(itemName, obj);
}
} else {
DefaultComboBoxModel model = (DefaultComboBoxModel) defaultVulns.getModel();
model.removeAllElements(); // Clear if search text is less than 2
_defaultVulns.clear();
}
}
});
}
});

GridBagConstraints gbc_vulnSearch = new GridBagConstraints();
gbc_vulnSearch.insets = new Insets(0, 0, 5, 0);
gbc_vulnSearch.fill = GridBagConstraints.HORIZONTAL;
Expand Down Expand Up @@ -547,7 +576,7 @@ public void actionPerformed(ActionEvent arg0) {
gbc_rigidArea_3.gridy = 8;
frame.getContentPane().add(rigidArea_3, gbc_rigidArea_3);

asmts = factionApi.executeGet("/assessments/queue");
asmts = factionApi.executeGet("/api/assessments/queue");
for(int i=0; i< asmts.size(); i++){
JSONObject obj = (JSONObject)asmts.get(i);
assessmentList.addItem(obj.get("AppId") + " " + obj.get("Name"));
Expand Down