Burp Suite User Forum

Create new post

Run JavaScript code using Jython 2.7

Oleksandr | Last updated: Feb 27, 2023 01:02PM UTC

Hello! I am writing an extension that can move requests from Postman collection to Site map using Python. To move requests python script parse Postman collection JSON file. My script works correctly, but I stacked with a problem: Some requests in Postman contains pre-request scripts which is written using JavaScript. This scripts contains lines like this: const number = (Math.floor(Math.random()*10000)*1); var CustomerName1 = "MPCustomer1" + number; pm.globals.set("CustomerName1", CustomerName1); To build correct CustomerName1 var and set in to the globals environment I must run line which calculate random number. Locally I solved this problem using js2py library, which allowed me run js code using Python 2.7. But this and other libraries does not support by Jython and that is why I can not use them. Another variant that I used is EngineManager from javax. Locally I can use one of such engines from OpenJDK and run js code in the python. But as I understand javax imported from OpenJDK which place inside Burp and this OpenJDK does not contains any engines, because of your configuration. So I can use such solution. Can you help me with this problem? How can I run JavaScript code using Python which used Jython 2.7?

Hannah, PortSwigger Agent | Last updated: Mar 01, 2023 04:07PM UTC

If there is an available Java library for you to easily use, have you considered converting your extension to Java? If you use a build manager like Gradle or Maven, you can easily include your library as a dependency. This would also mean that you can use our new Montoya API, which contains more functionality than the legacy Extender API.

Oleksandr | Last updated: Mar 06, 2023 09:40AM UTC

Because of some requirements I must use python, and that is why I can use only Jython 2.7. And I want to be sure, is there any possibilities to run JavaScript code using Jython 2.7? Or I must use only Java?

Cameron | Last updated: Mar 07, 2023 05:33AM UTC

I also would find it much easier to simply be able to use a module like pyexecjs in Jython. I have nearly the exact same case where I am trying to manually calculate UUIDs using a small piece of JavaScript. Seriously frustrating! I get the error, "Could not find an available JavaScript runtime."

You must be an existing, logged-in customer to reply to a thread. Please email us for additional support.