Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.0 #3

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5bcf067
Fixed the issue with Inclusion/Exclusion for the Encryption to suppor…
Parimal-shaw Dec 13, 2024
18d7fc3
Issue - Inclusion and Exclusion Prameter Fix.
Parimal-shaw Dec 13, 2024
e1b173e
Update Reqcheck.py
Anof-cyber Dec 14, 2024
36c0332
Update Reqcheck.py
Anof-cyber Dec 14, 2024
753e48c
Update execution.py
Anof-cyber Dec 14, 2024
020938b
Merge pull request #15 from Parimal-shaw/main
Anof-cyber Dec 14, 2024
94423b2
updated inclusion and exclusion parameter module.
Parimal-shaw Dec 14, 2024
548ae7b
Update utils.py
Anof-cyber Dec 15, 2024
1572189
Update Reqcheck.py
Anof-cyber Dec 15, 2024
1780fc0
Update Reqcheck.py
Anof-cyber Dec 15, 2024
df605b8
Update utils.py
Anof-cyber Dec 15, 2024
090f7f9
Merge pull request #17 from Parimal-shaw/main
Anof-cyber Dec 15, 2024
cbfb1a8
Removed Custom Request & Custom request edit header, added ability to…
Anof-cyber Dec 15, 2024
be35a4a
added support for non ascii, binary data, zip, independent encoding a…
Anof-cyber Dec 16, 2024
664dc3e
fixed error in string crypto, fixed path error in windows, fixed os u…
Anof-cyber Dec 17, 2024
34249e7
fixed lang path error in windows. added logs for debugging command ou…
Anof-cyber Dec 17, 2024
1e8ad6b
removed temp files, fixed config tab not showing content on smaller s…
Anof-cyber Dec 17, 2024
718679e
added new lang clear button for binary code, added persistent data fo…
Anof-cyber Dec 17, 2024
7868479
optimized the req enc dec and type check
Anof-cyber Dec 17, 2024
af9c29c
updated non json parameter include exclude logic, added non json inc …
Anof-cyber Dec 17, 2024
be8714a
bump version to 1.0 and update Parameterdecrypt function to accept op…
Anof-cyber Dec 19, 2024
594cebe
Version 1.0
Anof-cyber Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
239 changes: 146 additions & 93 deletions pycript.py

Large diffs are not rendered by default.

207 changes: 54 additions & 153 deletions pycript/Reqcheck.py

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions pycript/decoding.py

This file was deleted.

41 changes: 9 additions & 32 deletions pycript/decryption.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,19 @@
from . import encoding, decoding
from .execution import execute_command

from .gethelpers import string_to_bytes, bytes_to_string

#Parameterdecrypt --> Parameterdecrypt

def Parameterdecrypt(selectedlang, path, data):
data2 = encoding.encode_base64(data)
output = execute_command(selectedlang, path, data2)
if output is not False:
return output.decode('utf-8')
else:
return data


def Customrequestdecrypt(selectedlang, path, header, body):
body2 = encoding.encode_base64(body)
output = execute_command(selectedlang, path, body2, encoding.encode_base64(header)).decode('utf-8')
if output is not False:
return output.decode('utf-8')
def Parameterdecrypt(selectedlang, path, data,headers_str=None):
body_parameter_byte = list(string_to_bytes(data))
result = execute_command(selectedlang, path, body_parameter_byte,headers_str)
if result is not False:
body, header = result
string_body = bytes_to_string(body)
return string_body,header
else:
return body

return data,headers_str

def Customeditrequestdecrypt(selectedlang, path, header, body):
body2 = encoding.encode_base64(body)
header2 = encoding.encode_base64(header)

output = execute_command(selectedlang, path, body2, header2)
if output is not False:
lines = output.splitlines()
headerbase64, bodybase64 = lines[0], lines[1]

header = decoding.decode_base64(headerbase64).decode('utf-8')
body = decoding.decode_base64(bodybase64).decode('utf-8')

return (header, body)
else:

return (header, body)


4 changes: 0 additions & 4 deletions pycript/encoding.py

This file was deleted.

42 changes: 9 additions & 33 deletions pycript/encryption.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,16 @@
from . import encoding, decoding
from .execution import execute_command

from .gethelpers import string_to_bytes, bytes_to_string

#Jsonvalueencrypt --> Parameterencrypt

def Parameterencrypt(selectedlang, path, data):
output = execute_command(selectedlang, path, str(encoding.encode_base64(data)))

if output is not False:
return output.decode('utf-8')
else:
return data

def Parameterencrypt(selectedlang, path, data,headers_str=None):
body_parameter_byte = str(list(string_to_bytes(data)))
result = execute_command(selectedlang, path, body_parameter_byte,headers_str)

def Customrequestencrypt(selectedlang, path, header, body):
output = execute_command(selectedlang, path, encoding.encode_base64(body), encoding.encode_base64(header))

if output is not False:
return output.decode('utf-8')
if result is not False:
body, header = result
string_body = bytes_to_string(body)
return string_body,header
else:
return body



def Customeditrequestencrypt(selectedlang, path, header, body):
body2 = encoding.encode_base64(body)
header2 = encoding.encode_base64(header)

output = execute_command(selectedlang, path, body2, header2)
if output is not False:
lines = output.splitlines()
headerbase64, bodybase64 = lines[0], lines[1]
header = decoding.decode_base64(headerbase64).decode('utf-8')
body = decoding.decode_base64(bodybase64).decode('utf-8')
return (header, body)
else:
return (header, body)


return data,headers_str
54 changes: 22 additions & 32 deletions pycript/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,41 @@
from .gui import logerrors
import tempfile
from os import remove
import json
from .temp_file import parse_temp_file_output, create_temp_file

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


try:
temp_file_path = create_temp_file(data,headervalue)
#temp_file_path = temp_file.name
command = []
if selectedlang:
command.append('"' + selectedlang + '"')
command.append(selectedlang) # Add the selected language executable directly

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

command.extend(['"' + path + '"',"-d", temp_file_path])
command.extend([path, "-d", temp_file_path])

command_str = ' '.join(command)
# Log the command for debugging
command_str = ' '.join('"{0}"'.format(arg) if ' ' in arg else arg for arg in command)
logerrors("$ " + command_str)

process = subprocess.Popen(
command_str,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True
)
output, error = process.communicate()
remove(temp_file_path)

if process.returncode != 0:
logerrors(error.strip())
return False
else:
try:
output = subprocess.check_output(command, stderr=subprocess.PIPE)
logerrors(output.strip())
output = output.strip()
return output if output else False
body, header = parse_temp_file_output(data, headervalue, temp_file_path)
remove(temp_file_path)
if body:
return body, header
else:
return False
except subprocess.CalledProcessError as e:
logerrors("Command failed with return code: {}, Error: {}".format(e.returncode, e.output))
remove(temp_file_path)


except Exception as e:
logerrors(str(e))
#remove(temp_file_path)
return False
26 changes: 26 additions & 0 deletions pycript/gethelpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from java.util import Arrays;
from java.lang import String

_helpers = None # Private variable to hold the helpers reference.

def set_helpers(helpers):
"""Set the helpers instance."""
global _helpers
_helpers = helpers

def get_helpers():
"""Get the helpers instance."""
if _helpers is None:
raise RuntimeError("Helpers not initialized. Call `set_helpers` first.")
return _helpers

def string_to_bytes(string):
"""Convert a string to bytes using helpers."""
return get_helpers().stringToBytes(string)

def bytes_to_string(byte_data):
"""Convert bytes to string using helpers."""
byte_data_clean = byte_data.strip('[]')
byte_data2 = [int(code.strip()) for code in byte_data_clean.split(',')]
#return get_helpers().bytesToString(byte_data2) # for some reason helper API gives error or remove some non ascii data from string results in wrong string for non ascii or binary data
return ''.join(chr(code) for code in byte_data2)
6 changes: 3 additions & 3 deletions pycript/response_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .decryption import Parameterdecrypt,Customrequestdecrypt
from .encryption import Parameterencrypt,Customrequestencrypt
from .decryption import Parameterdecrypt
from .encryption import Parameterencrypt
from json import loads, dumps
from .utils import update_json_value, update_json_key_value

Expand All @@ -16,7 +16,7 @@ def encrypt_decrypt_response(extender,currentresp,response,enc_dec,enc_dec_type)
listofparam = extender.responseparamlist1.getText().split(',')

if str(extender.selectedresponsetpye) == "Complete Body":
decryptedvalue = enc_dec(selectedlang, enc_dec_file_path, stringbody)
decryptedvalue, _ = enc_dec(selectedlang, enc_dec_file_path, stringbody)
output = extender.helpers.stringToBytes(decryptedvalue)
return extender.helpers.buildHttpMessage(header, output)

Expand Down
32 changes: 7 additions & 25 deletions pycript/stringcrypto.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .decryption import Parameterdecrypt, Customrequestdecrypt,Customeditrequestdecrypt
from .encryption import Parameterencrypt, Customrequestencrypt,Customeditrequestencrypt
from .decryption import Parameterdecrypt
from .encryption import Parameterencrypt

class StringCrypto:
def __init__(self, extender, encpath, query, http_request_response):
Expand All @@ -26,33 +26,15 @@ def get_headers_str(self):
body_offset = request_info.getBodyOffset()
headers_str = request_str[:body_offset].strip()
return headers_str

### String Encryption Decryption Cannot Modify the header, Can read headers only for string from request
def encrypt_string_request(self):


if self._extender.selectedrequesttpye == "Custom Request":
encrypted = Customrequestencrypt(self.selectedlang, self.encpath, str(self.header), self._selectedmessage)
return encrypted

elif self._extender.selectedrequesttpye == "Custom Request (Edit Header)":
encrypted = Customeditrequestencrypt(self.selectedlang, self.encpath, str(self.headers_str), self._selectedmessage)
return encrypted

else:
encrypted = Parameterencrypt(self.selectedlang, self.encpath, self._selectedmessage)
return encrypted
encrypted, header = Parameterencrypt(self.selectedlang, self.encpath, self._selectedmessage,self.headers_str)
return encrypted,header

def decrypt_string_request(self):


if self._extender.selectedrequesttpye == "Custom Request":
decrypted = Customrequestdecrypt(self.selectedlang, self.encpath, str(self.header), self._selectedmessage)
return decrypted

elif self._extender.selectedrequesttpye == "Custom Request (Edit Header)":
decrypted = Customeditrequestdecrypt(self.selectedlang, self.encpath, str(self.headers_str), self._selectedmessage)
return decrypted

else:
decrypted = Parameterdecrypt(self.selectedlang, self.encpath, self._selectedmessage)
return decrypted
decrypted, header = Parameterdecrypt(self.selectedlang, self.encpath, self._selectedmessage,self.headers_str)
return decrypted,header
62 changes: 62 additions & 0 deletions pycript/temp_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os
import tempfile
import random
import string
import shutil

from .gui import logerrors

user_home = os.path.expanduser("~")
pycript_dir = os.path.join(user_home, ".pycript")

def parse_temp_file_output(original_data, original_header, temp_file_path):
with open(temp_file_path, 'rb') as temp_file:
file_content = temp_file.read()
body_end_marker = b'\n--BODY_END--\n'

logerrors("User Script Created File Output:")
logerrors(file_content)

# Split the file content using the marker
parts = file_content.split(body_end_marker, 1)

# Extract body data
body_data = parts[0]

# Extract header data if present, otherwise use the original header
if len(parts) > 1 and parts[1].strip(): # Check if header exists and is not empty
header_data = parts[1].strip()
else:
header_data = original_header
return body_data, header_data


def create_temp_file(data, headervalue=None):
# Get the temp directory path
random_file_name = ''.join([random.choice(string.ascii_letters + string.digits) for _ in range(12)])
file_path = os.path.join(pycript_dir, random_file_name)

# Write data to the file
with open(file_path, "wb") as file:
file.write(bytes(data)) # Write the byte array directly to the file
file.write(b'\n--BODY_END--\n') # Write the binary body end marker
if headervalue is not None:
file.write(headervalue.encode('utf-8'))

return file_path


def create_temp_dir():

if not os.path.exists(pycript_dir):
os.makedirs(pycript_dir)
temp_dir = tempfile.mkdtemp(dir=pycript_dir)


def delete_temp_folder():
if os.path.exists(pycript_dir):
shutil.rmtree(pycript_dir) # Remove the directory and all its contents
print("Temporary directory and its contents have been deleted.")
else:
print("Directory does not exist.")

Loading