Skip to content

Commit

Permalink
Merge pull request #11 from Anof-cyber/Fix-Json-Beautifier-add-extra-…
Browse files Browse the repository at this point in the history
…spaces

Version 0.4
  • Loading branch information
Anof-cyber authored Jul 6, 2024
2 parents cb0d04d + c2e8aef commit 790fee5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 32 deletions.
41 changes: 30 additions & 11 deletions pycript.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

errorlogtextbox = None
errorlogcheckbox = None
VERSION = "Version 0.3"
VERSION = "Version 0.4"

class BurpExtender(IBurpExtender, ITab,IMessageEditorTabFactory,IContextMenuFactory, IMessageEditorController, AbstractTableModel,IHttpListener):

Expand Down Expand Up @@ -235,10 +235,21 @@ def registerExtenderCallbacks(self, callbacks):
self.AdditionalSettinglabel.setFont(Font("Segoe UI", 1, 14))

self.languagelabel = JLabel();
self.languagelabel.setText("Language");
self.languagelabel.setText("Language Binary(ie python.exe emptydirect executable for enc/dec)");

self.langdata = ("JavaScript", "Python", "Java Jar")
self.languagecombobox = JComboBox(self.langdata)

#self.langdata = ("JavaScript", "Python", "Java Jar")
self.languagejpanel = JPanel() #JComboBox(self.langdata)
self.language_select_button = JButton("Select Language Binary Path")
self.language_select_button.addActionListener(self.select_language_file_path)



self.languagepath = JTextField(20)
self.languagepath.setText("C:/Program Files/nodejs/node.exe")
self.languagejpanel.add(self.languagepath,BorderLayout.NORTH)
self.languagejpanel.add(self.language_select_button,BorderLayout.NORTH)



self.reqmethodlabel = JLabel();
Expand Down Expand Up @@ -675,7 +686,7 @@ def registerExtenderCallbacks(self, callbacks):
self.additionallayerpane.setBorder(BorderFactory.createLineBorder(Color(0, 0, 0)));
self.additionallayerpane.setLayer(self.AdditionalSettinglabel, JLayeredPane.DEFAULT_LAYER);
self.additionallayerpane.setLayer(self.languagelabel, JLayeredPane.DEFAULT_LAYER);
self.additionallayerpane.setLayer(self.languagecombobox, JLayeredPane.DEFAULT_LAYER);
self.additionallayerpane.setLayer(self.languagejpanel, JLayeredPane.DEFAULT_LAYER);
self.additionallayerpane.setLayer(self.reqmethodlabel, JLayeredPane.DEFAULT_LAYER);
self.additionallayerpane.setLayer(self.reqmethodcombobox, JLayeredPane.DEFAULT_LAYER);
self.additionallayerpane.setLayer(self.reqresponselabel, JLayeredPane.DEFAULT_LAYER);
Expand All @@ -695,7 +706,7 @@ def registerExtenderCallbacks(self, callbacks):
.addGroup(self.additionallayerpaneLayout.createSequentialGroup()
.addComponent(self.languagelabel)
.addGap(18, 18, 18)
.addComponent(self.languagecombobox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addComponent(self.languagejpanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(self.reqmethodcombobox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGroup(self.additionallayerpaneLayout.createSequentialGroup()
Expand All @@ -712,7 +723,8 @@ def registerExtenderCallbacks(self, callbacks):
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(self.additionallayerpaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(self.languagelabel)
.addComponent(self.languagecombobox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addComponent(self.languagejpanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(0, 40, 40))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(self.additionallayerpaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(self.reqmethodlabel)
Expand Down Expand Up @@ -1095,8 +1107,15 @@ def importdecryptionjsfile(self,e):
self.requestdecryptionpath.setText(self.decryptionfilepath)
self.callbacks.saveExtensionSetting("requestdecryptionfilesave", self.decryptionfilepath)



# handle language binrary path
def select_language_file_path(self,e):
chooseFile = JFileChooser()
ret = chooseFile.showDialog(self.tab, "Choose file")
if ret == JFileChooser.APPROVE_OPTION:
fileLoad = chooseFile.getSelectedFile()
self.languagefullpath = fileLoad.getAbsolutePath()
self.languagepath.setText(self.languagefullpath)

# Returning the Extension Tab name to burp ITAB
def getTabCaption(self):
return "PyCript"
Expand Down Expand Up @@ -1256,7 +1275,7 @@ def encryptstring(self,invocation):
output = StringCrypto(self,encpath,query,http_request_response)
encryptedstring = output.encrypt_string_request()
else:
encryptedstring = Parameterencrypt(self.languagecombobox.getSelectedItem(), encpath, query)
encryptedstring = Parameterencrypt(self.languagepath.getText(), encpath, query)
#JOptionPane.showInputDialog(None, "Encrypted String", "Decryption", JOptionPane.PLAIN_MESSAGE, None, None, encryptedstring)
#JOptionPane.showMessageDialog(None, encryptedstring, "String", JOptionPane.INFORMATION_MESSAGE)
showEditableDialog(encryptedstring, "Encrypted String")
Expand Down Expand Up @@ -1301,7 +1320,7 @@ def decryptstring(self,invocation):
output = StringCrypto(self,encpath,query,http_request_response)
decryptedstring = output.decrypt_string_request()
else:
decryptedstring = Parameterdecrypt(self.languagecombobox.getSelectedItem(), encpath, query)
decryptedstring = Parameterdecrypt(self.languagepath.getText(), encpath, query)

showEditableDialog(decryptedstring, "Decryted String")

Expand Down
20 changes: 10 additions & 10 deletions pycript/Reqcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def EncryptRequest(extender, currentreq,req):
encryptionpath = extender.encryptionfilepath
selectedlang = extender.languagecombobox.getSelectedItem()
selectedlang = extender.languagepath.getText()
selected_method = extender.reqmethodcombobox.getSelectedItem()
parameters = req.getParameters()
header = req.getHeaders() # Get Array/last format header from burp header api (used for Custom Request)
Expand Down Expand Up @@ -44,7 +44,7 @@ def EncryptRequest(extender, currentreq,req):
## Function to decrypt request when Burp Menu to decrypt request is triggered
def DecryptRequest(extender, currentreq,req):
decryptionpath = extender.decryptionfilepath
selectedlang = extender.languagecombobox.getSelectedItem()
selectedlang = extender.languagepath.getText()
selected_method = extender.reqmethodcombobox.getSelectedItem()
selected_request_inc_ex_ctype = extender.selected_request_inc_ex_ctype
listofparam = extender.requestparamlist.getText().split(',')
Expand Down Expand Up @@ -107,7 +107,7 @@ def decrypt_and_update_parameters(extender, currentreq, decryptionpath, selected
elif param.getType() == IParameter.PARAM_JSON:
json_object = loads(body)
json_object = update_json_value(json_object, selectedlang, decryptionpath,Parameterdecrypt,selected_request_inc_ex_ctype,listofparam)
output = extender.helpers.stringToBytes(dumps(json_object))
output = extender.helpers.stringToBytes(dumps(json_object,separators=(',', ':')))
currentreq = extender.helpers.buildHttpMessage(header, output)
break

Expand All @@ -129,7 +129,7 @@ def decrypt_and_update_parameters(extender, currentreq, decryptionpath, selected
if selected_method == "BOTH" and param.getType() == IParameter.PARAM_JSON:
json_object = loads(body)
json_object = update_json_value(json_object, selectedlang, decryptionpath,Parameterdecrypt,selected_request_inc_ex_ctype,listofparam)
output = extender.helpers.stringToBytes(dumps(json_object))
output = extender.helpers.stringToBytes(dumps(json_object,separators=(',', ':')))
currentreq = extender.helpers.buildHttpMessage(header, output)
break
return currentreq
Expand All @@ -153,7 +153,7 @@ def decrypt_and_update_parameter_keys_and_values(extender, currentreq, decryptio
elif param.getType() == IParameter.PARAM_JSON:
json_object = loads(body)
json_object = update_json_key_value(json_object, selectedlang, decryptionpath,Parameterdecrypt,selected_request_inc_ex_ctype,listofparam)
output = extender.helpers.stringToBytes(dumps(json_object))
output = extender.helpers.stringToBytes(dumps(json_object,separators=(',', ':')))
currentreq = extender.helpers.buildHttpMessage(header, output)
break

Expand All @@ -179,7 +179,7 @@ def decrypt_and_update_parameter_keys_and_values(extender, currentreq, decryptio
if selected_method == "BOTH" and param.getType() == IParameter.PARAM_JSON:
json_object = loads(body)
json_object = update_json_key_value(json_object, selectedlang, decryptionpath,Parameterdecrypt,selected_request_inc_ex_ctype,listofparam)
output = extender.helpers.stringToBytes(dumps(json_object))
output = extender.helpers.stringToBytes(dumps(json_object,separators=(',', ':')))
currentreq = extender.helpers.buildHttpMessage(header, output)
break

Expand All @@ -199,7 +199,7 @@ def encrypt_and_update_parameters(extender, currentreq, encryptionpath, selected
elif param.getType() == IParameter.PARAM_JSON:
json_object = loads(body)
json_object = update_json_value(json_object, selectedlang, encryptionpath, Parameterencrypt,selected_request_inc_ex_ctype,listofparam)
output = extender.helpers.stringToBytes(dumps(json_object))
output = extender.helpers.stringToBytes(dumps(json_object,separators=(',', ':')))
currentreq = extender.helpers.buildHttpMessage(header, output)
break

Expand All @@ -219,7 +219,7 @@ def encrypt_and_update_parameters(extender, currentreq, encryptionpath, selected
if selected_method == "BOTH" and param.getType() == IParameter.PARAM_JSON:
json_object = loads(body)
json_object = update_json_value(json_object, selectedlang, encryptionpath, Parameterencrypt,selected_request_inc_ex_ctype,listofparam)
output = extender.helpers.stringToBytes(dumps(json_object))
output = extender.helpers.stringToBytes(dumps(json_object,separators=(',', ':')))
currentreq = extender.helpers.buildHttpMessage(header, output)
break

Expand All @@ -245,7 +245,7 @@ def encrypt_and_update_parameter_keys_and_values(extender, currentreq, encryptio
elif param.getType() == IParameter.PARAM_JSON:
json_object = loads(body)
json_object = update_json_key_value(json_object, selectedlang, encryptionpath,Parameterencrypt,selected_request_inc_ex_ctype,listofparam)
output = extender.helpers.stringToBytes(dumps(json_object))
output = extender.helpers.stringToBytes(dumps(json_object,separators=(',', ':')))
currentreq = extender.helpers.buildHttpMessage(header, output)
break

Expand All @@ -271,7 +271,7 @@ def encrypt_and_update_parameter_keys_and_values(extender, currentreq, encryptio
if selected_method == "BOTH" and param.getType() == IParameter.PARAM_JSON:
json_object = loads(body)
json_object = update_json_key_value(json_object, selectedlang, encryptionpath,Parameterencrypt,selected_request_inc_ex_ctype,listofparam)
output = extender.helpers.stringToBytes(dumps(json_object))
output = extender.helpers.stringToBytes(dumps(json_object,separators=(',', ':')))
currentreq = extender.helpers.buildHttpMessage(header, output)
break

Expand Down
30 changes: 21 additions & 9 deletions pycript/execution.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
import subprocess
from .gui import logerrors
import tempfile
from os import remove
import json

def execute_command(selectedlang, path, data, headervalue=None):
try:

content = {
"data": data
}
if headervalue is not None:
content["header"] = headervalue

with tempfile.NamedTemporaryFile(delete=False, mode='w') as temp_file:
json.dump(content, temp_file)
temp_file_path = temp_file.name


command = []
if selectedlang == "JavaScript":
command.extend(["node", '"' + path + '"']) # Surround path with double quotes
elif selectedlang == "Python":
command.extend(["python", '"' + path + '"']) # Surround path with double quotes
elif selectedlang == "Java Jar":
command.extend(["java", "-jar", '"' + path + '"']) # Surround path with double quotes
if selectedlang:
command.append('"' + selectedlang + '"')

command.extend(["-d", data])
if path.endswith(".jar"):
command.extend(["-jar"])

if headervalue is not None:
command.extend(["-h", headervalue])
command.extend(['"' + path + '"',"-d", temp_file_path])

command_str = ' '.join(command)
logerrors("$ " + command_str)
Expand All @@ -27,6 +38,7 @@ def execute_command(selectedlang, path, data, headervalue=None):
universal_newlines=True
)
output, error = process.communicate()
remove(temp_file_path)

if process.returncode != 0:
logerrors(error.strip())
Expand Down
2 changes: 1 addition & 1 deletion pycript/response_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def encrypt_decrypt_response(extender,currentresp,response,enc_dec,enc_dec_type):
selectedlang = extender.languagecombobox.getSelectedItem()
selectedlang = extender.languagepath.getText()
if enc_dec_type== "Decrypt":
enc_dec_file_path = extender.responsedecryptionfilepath
else:
Expand Down
2 changes: 1 addition & 1 deletion pycript/stringcrypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def __init__(self, extender, encpath, query, http_request_response):
self._extender = extender
self._selectedmessage = query
self.message = http_request_response
self.selectedlang = extender.languagecombobox.getSelectedItem()
self.selectedlang = extender.languagepath.getText()
self.encpath = encpath
self.header = self.get_headers()
self.headers_str = self.get_headers_str()
Expand Down

0 comments on commit 790fee5

Please sign in to comment.