Burp Suite User Forum

Login to post

Clear Extension Output UI

pbjell0 | Last updated: Jan 05, 2021 03:06AM UTC

My Python plugin prints output to "Extender" > "Extensions" > "Output" > "Show in UI". Each time I run my plugin, it appends data to this area. I'd like to clear out this area but uncertain of the correct way. I've tried "import os" and placing the clear "os.system('cls' if os.name == 'nt' else 'clear')" just before my loop prints to the screen. I am not seeing any error messages and the console area is not clearing up. What is the correct way to do this?

Hannah, PortSwigger Agent | Last updated: Jan 05, 2021 11:14AM UTC

Hi You can set your PrintWriter to autoflush when you initialize it. This is done by including a boolean value when obtaining your output and error streams. stdout = PrintWriter(callbacks.getStdout(), True) stderr = PrintWriter(callbacks.getStderr(), True) You can find out more information about the extender API, as well as some example extensions to help get you started here: https://portswigger.net/burp/extender

pbjell0 | Last updated: Jan 06, 2021 03:09AM UTC

Hi Hannah, I added "from java.io import PrintWriter" and the two lines you provided just before the loop but now the console does not print anything (no error either). Removing the stdout/stderr and reloading the plugin works. Apologies if the tabs are not preserved: def HostList(self): stdout = PrintWriter(callbacks.getStdout(), True) stderr = PrintWriter(callbacks.getStderr(), True) httpTraffic = self.context.getSelectedMessages() hostUrls = [] for index, traffic in enumerate(httpTraffic): try: hostUrls.append(str(traffic.getUrl())) hosts = hostUrls[-1] print(hosts) except UnicodeEncodeError: continue

Hannah, PortSwigger Agent | Last updated: Jan 06, 2021 09:31AM UTC

Hi Did you check out any of the examples on the Extensibility page? This one seems like it would be good, as it involves printing output to different locations in Burp: https://github.com/PortSwigger/example-hello-world/blob/master/python/HelloWorld.py

pbjell0 | Last updated: Jan 06, 2021 05:26PM UTC

My previous comment was just a snippet of my plugin containing the HostList function. When adding the stdout/err to the function, the plugin does not print any results. Unloading, commenting out stdout/err, re-loading the plugin works. The example you provided shows stdout/err inserted into registerExtenderCallbacks(). The below will print "Hello output" once the plugin loads. def registerExtenderCallbacks(self, callbacks): sys.stdout = callbacks.getStdout() self.callbacks = callbacks self.helpers = callbacks.getHelpers() self.callbacks.setExtensionName("Host") callbacks.registerContextMenuFactory(self) stdout = PrintWriter(callbacks.getStdout(), True) stderr = PrintWriter(callbacks.getStderr(), True) # write a message to our output stream stdout.println("Hello output") # write a message to our error stream stderr.println("Hello errors") # write a message to the Burp alerts tab callbacks.issueAlert("Hello alerts") return What I am looking for is to clear the UI each time I interact with my plugin (not loading of my plugin). Would it make more sense to place the PrintWriter method into my HostList function just before the loop? If so, I am still not understanding how to clear the UI just before my loop. This placement of the PrintWriter method causes my plugin to no longer print output: def HostList(self): stdout = PrintWriter(callbacks.getStdout(), True) stderr = PrintWriter(callbacks.getStderr(), True) httpTraffic = self.context.getSelectedMessages() hostUrls = [] for index, traffic in enumerate(httpTraffic): try: hostUrls.append(str(traffic.getUrl())) hosts = hostUrls[-1] print(hosts) except UnicodeEncodeError: continue How do I clear data from "Output" > "Show in UI" each time I interact with my plugin? Each time I run it, I want to see the results, if I run it again, I want to clear the previous results. Thank you so much for your help

pbjell0 | Last updated: Jan 08, 2021 05:23AM UTC

I decided to write the results to a file instead. Seemed much faster and easier than trying to clear the Output UI.

Hannah, PortSwigger Agent | Last updated: Jan 08, 2021 01:07PM UTC

I'm glad you managed to find a workaround for your issue. You may be able to use the flush() function to clear the stream, if you were to try using the printwriter again. - https://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html

You need to Log in to post a reply. Or register here, for free.