Skip to content

Commit

Permalink
Merge pull request #9 from GangGreenTemperTatum/feat/improve-origin-i…
Browse files Browse the repository at this point in the history
…nfo-in-extension-tab

Feat/improve origin info in extension tab
  • Loading branch information
GangGreenTemperTatum authored Dec 27, 2024
2 parents 4ff14f9 + ed6b29a commit cee022d
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 25 deletions.
6 changes: 2 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ insert_final_newline = true
[*.{kt,kts}]
indent_size = 4
insert_final_newline = true
max_line_length = 150 # Increased to avoid line length issues
max_line_length=150
ktlint_code_style = ktlint_official
# TODO
# Disable problematic rules for all Kotlin files
ktlint_standard = enabled
ktlint_standard_no-unused-imports = disabled
ktlint_standard_multiline-expression-wrapping = disabled
Expand All @@ -20,12 +18,12 @@ ktlint_standard_final-newline = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled
ktlint_standard_argument-list-wrapping = disabled
ktlint_standard_max-line-length = disabled
ktlint_standard_function-signature = disabled
ktlint_standard_statement-wrapping = disabled
ktlint_standard_blank-line-before-declaration = disabled
ktlint_standard_import-ordering = disabled
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_no-multi-spaces = disabled

[*.kts]
# Additional specific rules for Kotlin script files
Expand Down
3 changes: 2 additions & 1 deletion config/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ build:

complexity:
LongMethod:
threshold: 120 # Increased from default to accommodate provideMenuItems
threshold: 130 # Increased from 120 to accommodate provideMenuItems
excludes: ["**/StickyBurpContextMenu.kt"] # Exclude this file from LongMethod check
LongParameterList:
functionThreshold: 5
constructorThreshold: 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import burp.api.montoya.ui.Selection
import burp.api.montoya.core.ByteArray
import burp.api.montoya.ui.contextmenu.ContextMenuEvent
import burp.api.montoya.ui.contextmenu.ContextMenuItemsProvider
import burp.api.montoya.ui.contextmenu.InvocationType
import burp.api.montoya.logging.Logging
import burp.api.montoya.ui.contextmenu.InvocationType.*
import javax.swing.*
import burp.api.montoya.http.message.requests.HttpRequest
import burp.api.montoya.http.message.responses.HttpResponse
Expand All @@ -24,7 +24,7 @@ class StickyBurpContextMenu(private val tab: StickyBurpTab, private val logging:
val selection = editor.selectionOffsets()
if (!selection.isPresent) return emptyList()

val selectedText = if (event.isFrom(MESSAGE_EDITOR_REQUEST, MESSAGE_VIEWER_REQUEST)) {
val selectedText = if (event.isFrom(InvocationType.MESSAGE_EDITOR_REQUEST, InvocationType.MESSAGE_VIEWER_REQUEST)) {
val request = editor.requestResponse().request()
val range = selection.get()
request.toByteArray().subArray(range).toString()
Expand Down Expand Up @@ -76,16 +76,58 @@ class StickyBurpContextMenu(private val tab: StickyBurpTab, private val logging:

val source = if (messageEditor.isPresent) {
val reqRes = messageEditor.get().requestResponse()
"HTTP ${reqRes.request().method()} ${reqRes.request().url()}"
val tool = when (event.invocationType()) {
InvocationType.PROXY_HISTORY,
InvocationType.PROXY_INTERCEPT,
InvocationType.MESSAGE_VIEWER_REQUEST,
InvocationType.MESSAGE_VIEWER_RESPONSE -> "Proxy"
InvocationType.INTRUDER_PAYLOAD_POSITIONS,
InvocationType.INTRUDER_ATTACK_RESULTS -> "Intruder"
InvocationType.SCANNER_RESULTS -> "Scanner"
InvocationType.MESSAGE_EDITOR_REQUEST,
InvocationType.MESSAGE_EDITOR_RESPONSE -> "Repeater"
InvocationType.SITE_MAP_TREE,
InvocationType.SITE_MAP_TABLE -> "Site Map"
InvocationType.SEARCH_RESULTS -> "Search"
else -> "Other"
}

val context = when (event.invocationType()) {
InvocationType.PROXY_HISTORY -> "History"
InvocationType.PROXY_INTERCEPT -> "Intercept"
InvocationType.INTRUDER_PAYLOAD_POSITIONS -> "Payload Positions"
InvocationType.INTRUDER_ATTACK_RESULTS -> "Attack Results"
else -> ""
}

val source = buildString {
val request = reqRes.request()
val service = request.httpService()

append("HTTP ${request.method()} ${request.url()}")
append(" (${service.host()}:${service.port()})")
if (service.secure()) append(" [HTTPS]")

if (context.isNotEmpty()) {
append(" ($context)")
}

val notes = reqRes.annotations().notes()
if (notes != "") {
append(" - Note: $notes")
}
}

tab.addVariable(StickyVariable(
name = trimmedName,
value = selectedText,
sourceTab = tool,
source = source,
timestamp = java.time.LocalDateTime.now().toString()
))
} else {
"Manual Selection"
}

tab.addVariable(StickyVariable(
name = trimmedName,
value = selectedText,
source = source
))
}
mainMenu.add(addItem)

Expand All @@ -96,7 +138,7 @@ class StickyBurpContextMenu(private val tab: StickyBurpTab, private val logging:
val range = selection.get()
val reqRes = editor.requestResponse()

if (event.isFrom(MESSAGE_EDITOR_REQUEST, MESSAGE_VIEWER_REQUEST)) {
if (event.isFrom(InvocationType.MESSAGE_EDITOR_REQUEST, InvocationType.MESSAGE_VIEWER_REQUEST)) {
val request = reqRes.request()
val newRequest = HttpRequest.httpRequest(
request.httpService(),
Expand Down Expand Up @@ -128,10 +170,56 @@ class StickyBurpContextMenu(private val tab: StickyBurpTab, private val logging:
val updateItem = JMenuItem(varName)
updateItem.addActionListener {
val reqRes = event.messageEditorRequestResponse().get().requestResponse()
tab.addVariable(StickyVariable(
name = varName,
val existingVar = tab.getVariables().find { it.name == varName }
?: return@addActionListener

val tool = when (event.invocationType()) {
InvocationType.PROXY_HISTORY,
InvocationType.PROXY_INTERCEPT,
InvocationType.MESSAGE_VIEWER_REQUEST,
InvocationType.MESSAGE_VIEWER_RESPONSE -> "Proxy"
InvocationType.INTRUDER_PAYLOAD_POSITIONS,
InvocationType.INTRUDER_ATTACK_RESULTS -> "Intruder"
InvocationType.SCANNER_RESULTS -> "Scanner"
InvocationType.MESSAGE_EDITOR_REQUEST,
InvocationType.MESSAGE_EDITOR_RESPONSE -> "Repeater"
InvocationType.SITE_MAP_TREE,
InvocationType.SITE_MAP_TABLE -> "Site Map"
InvocationType.SEARCH_RESULTS -> "Search"
else -> "Other"
}

val context = when (event.invocationType()) {
InvocationType.PROXY_HISTORY -> "History"
InvocationType.PROXY_INTERCEPT -> "Intercept"
InvocationType.INTRUDER_PAYLOAD_POSITIONS -> "Payload Positions"
InvocationType.INTRUDER_ATTACK_RESULTS -> "Attack Results"
else -> ""
}

val source = buildString {
val request = reqRes.request()
val service = request.httpService()

append("HTTP ${request.method()} ${request.url()}")
append(" (${service.host()}:${service.port()})")
if (service.secure()) append(" [HTTPS]")

if (context.isNotEmpty()) {
append(" ($context)")
}

val notes = reqRes.annotations().notes()
if (notes != "") {
append(" - Note: $notes")
}
}

tab.addVariable(existingVar.copy(
value = selectedText,
source = "HTTP ${reqRes.request().method()} ${reqRes.request().url()}"
sourceTab = tool,
source = source,
timestamp = java.time.LocalDateTime.now().toString()
))
}
updateMenu.add(updateItem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ class StickyBurpTab(
private val variables: MutableList<StickyVariable>,
private val persistence: Persistence
) : JPanel() {
private val tableModel: DefaultTableModel = object : DefaultTableModel(arrayOf("Name", "Value", "Source", "Notes"), 0) {
override fun isCellEditable(row: Int, column: Int): Boolean = column == 3
private val tableModel: DefaultTableModel = object : DefaultTableModel(
arrayOf("Sticky Name", "Sticky Value", "Source Tab", "Source Meta", "Source Timestamp", "Sticky Notes"),
0
) {
override fun isCellEditable(row: Int, column: Int): Boolean = column == 5
}

private fun extractColor(source: String): Color? {
Expand Down Expand Up @@ -132,13 +135,13 @@ class StickyBurpTab(
}
})

t.getColumnModel().getColumn(3).cellEditor = DefaultCellEditor(JTextField())
t.getColumnModel().getColumn(5).cellEditor = DefaultCellEditor(JTextField())

t.addPropertyChangeListener { evt ->
if ("tableCellEditor" == evt.propertyName) {
val row = t.editingRow
val col = t.editingColumn
if (row != -1 && col == 3) {
if (row != -1 && col == 5) {
val notes = t.getValueAt(row, col)?.toString() ?: ""
val variable = variables[row]
variables[row] = variable.copy(notes = notes)
Expand Down Expand Up @@ -209,7 +212,9 @@ class StickyBurpTab(
tableModel.addRow(arrayOf(
variable.name,
variable.value,
variable.sourceTab,
variable.source,
variable.timestamp,
variable.notes
))
variables.add(variable)
Expand All @@ -231,8 +236,10 @@ class StickyBurpTab(
private fun updateTableRow(index: Int, variable: StickyVariable) {
tableModel.setValueAt(variable.name, index, 0)
tableModel.setValueAt(variable.value, index, 1)
tableModel.setValueAt(variable.source, index, 2)
tableModel.setValueAt(variable.notes, index, 3)
tableModel.setValueAt(variable.sourceTab, index, 2)
tableModel.setValueAt(variable.source, index, 3)
tableModel.setValueAt(variable.timestamp, index, 4)
tableModel.setValueAt(variable.notes, index, 5)
}

private fun updateSelectedVariable() {
Expand All @@ -256,7 +263,11 @@ class StickyBurpTab(
return
}

val updatedVariable = currentVariable.copy(value = trimmedValue, source = "Manual Update")
val updatedVariable = currentVariable.copy(
value = trimmedValue,
source = "Manual Update",
sourceTab = currentVariable.sourceTab
)
variables[selectedRow] = updatedVariable
updateTableRow(selectedRow, updatedVariable)
saveVariables()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ data class StickyVariable(
val name: String,
val value: String,
val source: String,
val sourceTab: String = "",
val timestamp: String = java.time.LocalDateTime.now().toString(),
val notes: String = ""
)

0 comments on commit cee022d

Please sign in to comment.