Skip to content

Commit

Permalink
WebSocket Logging Tool対応
Browse files Browse the repository at this point in the history
  • Loading branch information
isayan committed Sep 11, 2024
1 parent 5b83e24 commit c2a6970
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 79 deletions.
6 changes: 3 additions & 3 deletions Readme-ja.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Burp suite 拡張 YaguraExtender
Burp suite 拡張 YaguraExtension
=============

Language/[English](Readme.md)
Expand Down Expand Up @@ -46,13 +46,13 @@ gradlew release
* v2023.1.2以上 (http://www.portswigger.net/burp/)

### 開発環境
* NetBeans 20 (https://netbeans.apache.org/)
* NetBeans 22 (https://netbeans.apache.org/)
* Gradle 7.6 (https://gradle.org/)
* asciidoc (http://asciidoc.org/)

## 必須ライブラリ
ビルドには別途 [BurpExtensionCommons](https://github.com/raise-isayan/BurpExtensionCommons) のライブラリを必要とします。
* BurpExtensionCommons v3.0.x
* BurpExtensionCommons v3.2.x

### 利用ライブラリ

Expand Down
6 changes: 3 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Burp suite Extension YaguraExtender
Burp suite Extension YaguraExtension
=============

Language/[日本語](Readme-ja.md)
Expand Down Expand Up @@ -46,13 +46,13 @@ gradlew release
* v2023.1.2 or higher (http://www.portswigger.net/burp/)

### Development environment
* NetBeans 20 (https://netbeans.apache.org/)
* NetBeans 22 (https://netbeans.apache.org/)
* Gradle 7.6 (https://gradle.org/)
* asciidoc (http://asciidoc.org/)

## Required library
Building requires a [BurpExtensionCommons](https://github.com/raise-isayan/BurpExtensionCommons) library.
* BurpExtensionCommons v3.0.x
* BurpExtensionCommons v3.2.x

## Use Library
* Apache common codec (https://commons.apache.org/proper/commons-codec/)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
netbeans.org-netbeans-modules-javascript2-requirejs.enabled=true
release_version_major=3.1
release_version_minor=3.2
release_version_minor=3.3
netbeans.license=mit
Binary file modified release/YaguraExtension-v3.1.jar
Binary file not shown.
74 changes: 62 additions & 12 deletions src/main/java/burp/BurpExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
import burp.api.montoya.proxy.websocket.ProxyWebSocketCreationHandler;
import burp.api.montoya.ui.editor.extension.ExtensionProvidedWebSocketMessageEditor;
import burp.api.montoya.ui.editor.extension.WebSocketMessageEditorProvider;
import burp.api.montoya.websocket.BinaryMessage;
import burp.api.montoya.websocket.BinaryMessageAction;
import burp.api.montoya.websocket.Direction;
import burp.api.montoya.websocket.MessageHandler;
import burp.api.montoya.websocket.TextMessage;
import burp.api.montoya.websocket.TextMessageAction;
import burp.api.montoya.websocket.WebSocketCreated;
import burp.api.montoya.websocket.WebSocketCreatedHandler;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
Expand Down Expand Up @@ -1825,27 +1833,65 @@ private HttpMessage replaceProxyMessage(

}

protected final class WebSocketCreationHander implements ProxyWebSocketCreationHandler {
protected final class WebSocketCreationHander implements ProxyWebSocketCreationHandler, WebSocketCreatedHandler {

private final MontoyaApi api;

public WebSocketCreationHander(MontoyaApi api) {
this.api = api;
api.proxy().registerWebSocketCreationHandler(this);
api.websockets().registerWebSocketCreatedHandler(this);
}

@Override
public void handleWebSocketCreation(ProxyWebSocketCreation proxyWebSocketCreation) {
proxyWebSocketCreation.proxyWebSocket().registerProxyMessageHandler(new WebSocktHander(api, proxyWebSocketCreation));
proxyWebSocketCreation.proxyWebSocket().registerProxyMessageHandler(new WebSocktProxyMessageHander(api, proxyWebSocketCreation));
}

@Override
public void handleWebSocketCreated(WebSocketCreated webSocketCreated) {
webSocketCreated.webSocket().registerMessageHandler(new WebSocktMessageHander(api, webSocketCreated));
}

}

protected final class WebSocktHander implements ProxyMessageHandler {
protected final class WebSocktMessageHander implements MessageHandler {
private final MontoyaApi api;
private final WebSocketCreated webSocketCreated;

public WebSocktMessageHander(MontoyaApi api, WebSocketCreated webSocketCreated) {
this.api = api;
this.webSocketCreated = webSocketCreated;
}

@Override
public TextMessageAction handleTextMessage(TextMessage textMessage) {
// WebSockt 出力
if (getProperty().getLoggingProperty().isAutoLogging() && getProperty().getLoggingProperty().isWebSocketLog()) {
ToolSource toolSource = webSocketCreated.toolSource();
logging.writeWebSocketToolMessage(toolSource.toolType(), webSocketCreated, textMessage);
}
return TextMessageAction.continueWith(textMessage);
}

@Override
public BinaryMessageAction handleBinaryMessage(BinaryMessage binaryMessage) {
// WebSockt 出力
if (getProperty().getLoggingProperty().isAutoLogging() && getProperty().getLoggingProperty().isWebSocketLog()) {
ToolSource toolSource = webSocketCreated.toolSource();
logging.writeWebSocektToolMessage(toolSource.toolType(), webSocketCreated, binaryMessage);
}
return BinaryMessageAction.continueWith(binaryMessage);
}

}


protected final class WebSocktProxyMessageHander implements ProxyMessageHandler {
private final MontoyaApi api;
private final ProxyWebSocketCreation proxyWebSocketCreation;

public WebSocktHander(MontoyaApi api, ProxyWebSocketCreation proxyWebSocketCreation) {
public WebSocktProxyMessageHander(MontoyaApi api, ProxyWebSocketCreation proxyWebSocketCreation) {
this.api = api;
this.proxyWebSocketCreation = proxyWebSocketCreation;
proxyWebSocketCreation.proxyWebSocket().registerProxyMessageHandler(this);
Expand All @@ -1854,35 +1900,39 @@ public WebSocktHander(MontoyaApi api, ProxyWebSocketCreation proxyWebSocketCreat
@Override
public TextMessageReceivedAction handleTextMessageReceived(InterceptedTextMessage interceptedTextMessage) {
// WebSockt 出力
if (getProperty().getLoggingProperty().isAutoLogging() && getProperty().getLoggingProperty().isWebSocketLog()) {
logging.writeWebSocktFinalMessage(proxyWebSocketCreation, interceptedTextMessage);
if (getProperty().getLoggingProperty().isAutoLogging() && getProperty().getLoggingProperty().isWebSocketLog() &&
interceptedTextMessage.direction() == Direction.SERVER_TO_CLIENT) {
logging.writeWebSocketFinalMessage(this.proxyWebSocketCreation, interceptedTextMessage);
}
return TextMessageReceivedAction.continueWith(interceptedTextMessage);
}

@Override
public TextMessageToBeSentAction handleTextMessageToBeSent(InterceptedTextMessage interceptedTextMessage) {
// WebSockt 出力
if (getProperty().getLoggingProperty().isAutoLogging() && getProperty().getLoggingProperty().isWebSocketLog()) {
logging.writeWebSocktFinalMessage(proxyWebSocketCreation, interceptedTextMessage);
if (getProperty().getLoggingProperty().isAutoLogging() && getProperty().getLoggingProperty().isWebSocketLog() &&
interceptedTextMessage.direction() == Direction.CLIENT_TO_SERVER) {
logging.writeWebSocketFinalMessage(proxyWebSocketCreation, interceptedTextMessage);
}
return TextMessageToBeSentAction.continueWith(interceptedTextMessage);
}

@Override
public BinaryMessageReceivedAction handleBinaryMessageReceived(InterceptedBinaryMessage interceptedBinaryMessage) {
// WebSockt 出力
if (getProperty().getLoggingProperty().isAutoLogging() && getProperty().getLoggingProperty().isWebSocketLog()) {
logging.writeWebSocktFinalMessage(proxyWebSocketCreation, interceptedBinaryMessage);
if (getProperty().getLoggingProperty().isAutoLogging() && getProperty().getLoggingProperty().isWebSocketLog() &&
interceptedBinaryMessage.direction() == Direction.SERVER_TO_CLIENT) {
logging.writeWebSocketFinalMessage(proxyWebSocketCreation, interceptedBinaryMessage);
}
return BinaryMessageReceivedAction.continueWith(interceptedBinaryMessage);
}

@Override
public BinaryMessageToBeSentAction handleBinaryMessageToBeSent(InterceptedBinaryMessage interceptedBinaryMessage) {
// WebSockt 出力
if (getProperty().getLoggingProperty().isAutoLogging() && getProperty().getLoggingProperty().isWebSocketLog()) {
logging.writeWebSocktFinalMessage(proxyWebSocketCreation, interceptedBinaryMessage);
if (getProperty().getLoggingProperty().isAutoLogging() && getProperty().getLoggingProperty().isWebSocketLog() &&
interceptedBinaryMessage.direction() == Direction.CLIENT_TO_SERVER) {
logging.writeWebSocketFinalMessage(proxyWebSocketCreation, interceptedBinaryMessage);
}
return BinaryMessageToBeSentAction.continueWith(interceptedBinaryMessage);
}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/yagura/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@ public static String getProxyLogMessageName() {
return "proxy-message.log";
}

public static String getWebSocketLogMessageName() {
return "websocket-message.log";
public static String getToolLogName(String toolName) {
return String.format("burp_tool_%s.log", toolName);
}

public static String getWebSocketLogFinalMessageName() {
return "websocket-final-message.log";
public static String getWebSocketToolLogName(String toolName) {
return String.format("websocket_tool_%s.log", toolName);
}

public static String getToolLogName(String toolName) {
return String.format("burp_tool_%s.log", toolName);
// public static String getWebSocketLogMessageName() {
// return "websocket-message.log";
// }

public static String getWebSocketLogFinalMessageName() {
return "websocket-final-message.log";
}

}
Loading

0 comments on commit c2a6970

Please sign in to comment.