Skip to content

Commit

Permalink
Merge branch 'tkt_22_add_create_workspace' into 'develop'
Browse files Browse the repository at this point in the history
Add create workspace

Closes #22

See merge request faradaysec/faraday-burp!8
  • Loading branch information
Nicolas Rebagliati committed Nov 9, 2022
2 parents 2217c53 + 6fb8998 commit f83cbcb
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# v2.8.1 - 2022/10/28

* Add create workspace button

# v2.8 - 2022/09/19

* Add refresh workspace bottom
* Add refresh workspace button
* Fix website field
* Now the host,services and vulns create have a command associated

Expand Down
28 changes: 28 additions & 0 deletions src/main/java/burp/faraday/FaradayConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,34 @@ void setCurrentWorkspace(Workspace currentWorkspace) {
this.currentWorkspace = currentWorkspace;
}

/**
* Create a new workspace.
*
* @param name The workspace to name.
*/
public Workspace createWorkspace(final String name)
throws InvalidFaradayServerException,
ObjectNotCreatedException {
if (!this.urlIsValid) {
throw new InvalidFaradayServerException();
}
try {
try {
Workspace ws = new Workspace();
ws.setName(name);
ws.setActive(true);
return faradayServerAPI.createWorkspace(ws);
} catch (ConflictException e) {
throw new ObjectNotCreatedException();
}
} catch (UnauthorizedException e) {
throw new ObjectNotCreatedException();
} catch (Exception e)
{
throw new ObjectNotCreatedException();
}
}

/**
* Adds a vulnerability to the current workspace.
*
Expand Down
72 changes: 69 additions & 3 deletions src/main/java/burp/faraday/FaradayExtensionUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class FaradayExtensionUI implements ITab {
private JTextField usernameText;
private JPasswordField passwordField;
private JTextField secondFactorField;
private JTextField newWorkspaceText;
private JButton statusButton;
private JCheckBox ignoreSSLErrorsCheckbox;
private JLabel placeHolderLabel;
Expand All @@ -54,6 +55,7 @@ public class FaradayExtensionUI implements ITab {
private Component settingsPannel;
private Component otherSettingsPanel;
private Component statusPanel;
private Component newWorkspacePanel;
private Component messagesPanel;
private HashMap<Integer, Integer> commandsMap = null;

Expand All @@ -78,6 +80,7 @@ public FaradayExtensionUI(PrintWriter stdout, IBurpExtenderCallbacks callbacks,
this.settingsPannel = setupSettingsPanel();
this.otherSettingsPanel = setupOtherSettingsPanel();
this.statusPanel = setupStatusPanel();
this.newWorkspacePanel = setupNewWorkspacePanel();
this.messagesPanel = setupMessagesPanel();

layout.setHorizontalGroup(
Expand All @@ -87,6 +90,7 @@ public FaradayExtensionUI(PrintWriter stdout, IBurpExtenderCallbacks callbacks,
.addComponent(settingsPannel)
.addComponent(otherSettingsPanel)
.addComponent(statusPanel)
.addComponent(newWorkspacePanel)
)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(messagesPanel)
Expand All @@ -102,6 +106,7 @@ public FaradayExtensionUI(PrintWriter stdout, IBurpExtenderCallbacks callbacks,
.addGroup(layout.createSequentialGroup()
.addComponent(loginPanel)
.addComponent(settingsPannel)
.addComponent(newWorkspacePanel)
.addComponent(otherSettingsPanel)
.addComponent(statusPanel)
)
Expand Down Expand Up @@ -252,10 +257,9 @@ private Component setupSettingsPanel() {
.addComponent(inScopeCheckbox)
.addComponent(importCurrentVulnsButton)
.addComponent(refreshWorkspaces)

)
.addGroup(layout.createParallelGroup()
.addComponent(componentsSeparator)
.addComponent(componentsSeparator)
)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(workspaceLabel)
Expand Down Expand Up @@ -310,13 +314,55 @@ private Component setupOtherSettingsPanel() {
return otherSettingsPanel;
}

private Component setupNewWorkspacePanel() {
JPanel newWorkspacePanet = new JPanel();
newWorkspacePanet.setBorder(BorderFactory.createTitledBorder("New Workspace"));

JLabel newWorkspaceLabel = new JLabel("Name: ");
newWorkspaceText = new JTextField();
JButton createNewWorkspaceButton = new JButton("Create");
createNewWorkspaceButton.addActionListener(actionEvent -> createWorkspace());

GroupLayout layout = new GroupLayout(newWorkspacePanet);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);

newWorkspacePanet.setLayout(layout);

layout.setHorizontalGroup(
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(newWorkspaceLabel)
)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(newWorkspaceText, 256, 256, 256)
)
.addComponent(createNewWorkspaceButton)

);

layout.setVerticalGroup(
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(newWorkspaceLabel)
.addComponent(newWorkspaceText)
.addComponent(createNewWorkspaceButton)
)
);

layout.linkSize(SwingConstants.VERTICAL, newWorkspaceText);
layout.linkSize(SwingConstants.HORIZONTAL, newWorkspaceText);


return newWorkspacePanet;
}

private Component setupStatusPanel() {
JPanel statusPanet = new JPanel();
statusPanet.setBorder(BorderFactory.createTitledBorder("Status"));

statusLabel = new JLabel("...");


GroupLayout layout = new GroupLayout(statusPanet);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
Expand Down Expand Up @@ -608,6 +654,26 @@ private void loadWorkspaces() {
}
}

/**
* Create a new workspace
@param workspace The name of the new workspace.
*/
private void createWorkspace() {
String workspaceName = newWorkspaceText.getText().trim();
newWorkspaceText.setText("");
try {
Workspace newWorkspace = faradayConnector.createWorkspace(workspaceName);
extensionSettings.setCurrentWorkspace(workspaceName);
loadWorkspaces();
log("New workspace created: " + workspaceName);
} catch (InvalidFaradayServerException e) {
log("Could not create workspace: " + e);
}catch (ObjectNotCreatedException e) {
log("Unable to create object workspace: " + e);
return;
}
}

/**
* Callback for when a workspace is selected on the extension settings
*
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/burp/faraday/FaradayServerAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ public interface FaradayServerAPI {
@Headers("Content-Type: application/json")
List<Workspace> getWorkspaces() throws UnauthorizedException;

/**
* Create a workspace.
*
* @return A Workspace Object
*
* @throws UnauthorizedException If the session has expired.
*/
@RequestLine("POST /_api/v3/ws")
@Headers("Content-Type: application/json")
Workspace createWorkspace(Workspace workspace) throws UnauthorizedException, ConflictException;

/**
* Creates a command in the specified workspace.
*
Expand Down

0 comments on commit f83cbcb

Please sign in to comment.