-
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathWebSocketMessageEditor.java
More file actions
120 lines (100 loc) · 3.64 KB
/
WebSocketMessageEditor.java
File metadata and controls
120 lines (100 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.pycript.websocket;
import burp.api.montoya.MontoyaApi;
import burp.api.montoya.core.ByteArray;
import burp.api.montoya.ui.Selection;
import burp.api.montoya.ui.editor.EditorOptions;
import burp.api.montoya.ui.editor.RawEditor;
import burp.api.montoya.ui.editor.extension.EditorCreationContext;
import burp.api.montoya.ui.editor.extension.EditorMode;
import burp.api.montoya.ui.editor.extension.ExtensionProvidedWebSocketMessageEditor;
import burp.api.montoya.ui.contextmenu.WebSocketMessage;
import com.pycript.ui.ConfigTab;
import com.pycript.EncDec.Execution;
import org.apache.commons.lang3.tuple.Pair;
import java.awt.*;
public class WebSocketMessageEditor implements ExtensionProvidedWebSocketMessageEditor
{
private final RawEditor editor;
private final MontoyaApi api;
private final boolean isReadOnly;
public WebSocketMessageEditor(MontoyaApi api, EditorCreationContext creationContext)
{
this.api = api;
this.isReadOnly = creationContext.editorMode() == EditorMode.READ_ONLY;
if (isReadOnly)
{
editor = api.userInterface().createRawEditor(EditorOptions.READ_ONLY);
}
else {
editor = api.userInterface().createRawEditor();
}
}
@Override
public ByteArray getMessage() {
if (!ConfigTab.webSocketEnabled || ConfigTab.webSocketEncryptionFile == null || ConfigTab.webSocketEncryptionFile.isBlank()) {
return editor.getContents();
}
try {
Pair<byte[], String> result = Execution.executeCommand(
ConfigTab.languageTextField != null ? ConfigTab.languageTextField.getText() : "",
ConfigTab.webSocketEncryptionFile,
editor.getContents().getBytes(),
""
);
if (result != null) {
return ByteArray.byteArray(result.getLeft());
}
} catch (Exception e) {
}
return editor.getContents();
}
@Override
public void setMessage(WebSocketMessage message) {
if (message.upgradeRequest() == null || !api.scope().isInScope(message.upgradeRequest().url())) {
editor.setEditable(false);
editor.setContents(ByteArray.byteArray(api.utilities().byteUtils().convertFromString("WebSocket is out of scope")));
return;
}
if (!isReadOnly) {
editor.setEditable(true);
}
if (!ConfigTab.webSocketEnabled || ConfigTab.webSocketDecryptionFile == null || ConfigTab.webSocketDecryptionFile.isBlank()) {
editor.setContents(message.payload());
return;
}
try {
Pair<byte[], String> result = Execution.executeCommand(
ConfigTab.languageTextField != null ? ConfigTab.languageTextField.getText() : "",
ConfigTab.webSocketDecryptionFile,
message.payload().getBytes(),
""
);
if (result != null) {
editor.setContents(ByteArray.byteArray(result.getLeft()));
return;
}
} catch (Exception e) {
}
editor.setContents(message.payload());
}
@Override
public boolean isEnabledFor(WebSocketMessage message) {
return ConfigTab.webSocketEnabled;
}
@Override
public String caption() {
return "PyCript";
}
@Override
public Component uiComponent() {
return editor.uiComponent();
}
@Override
public Selection selectedData() {
return editor.selection().orElse(null);
}
@Override
public boolean isModified() {
return editor.isModified();
}
}