Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
856a402
Uploaded changes in branch
Jul 16, 2024
1d1d777
Merge remote-tracking branch 'refs/remotes/origin/development' into w…
DianaStrauss Sep 3, 2024
923d6ec
fixed shortening of prompt
DianaStrauss Sep 3, 2024
234e6ef
Merge remote-tracking branch 'refs/remotes/origin/development' into w…
DianaStrauss Sep 3, 2024
629489a
Merged development into web_api_testing
DianaStrauss Sep 3, 2024
64699e3
Fixed shorten prompt bug from merge
DianaStrauss Sep 3, 2024
c141954
Updated Tree of thought so that documentation works like chain of tho…
DianaStrauss Oct 8, 2024
3dc2c4b
Implemented in-context learning for documentation
DianaStrauss Oct 15, 2024
53e5c42
refined openapi generation
DianaStrauss Oct 16, 2024
ea8795b
Updated Tree of thought so that documentation works like chain of tho…
DianaStrauss Oct 16, 2024
4409f4b
Updated Tree of thought so that documentation works like chain of tho…
DianaStrauss Oct 16, 2024
8ef5f8b
Adjusted to only record valid information of rest api
DianaStrauss Oct 23, 2024
8eb5048
optimized prompt generation
DianaStrauss Oct 24, 2024
294ca7c
Added configs for documentation and testing
DianaStrauss Oct 25, 2024
98b510f
Added way of retrieving spotify token
DianaStrauss Oct 25, 2024
975ae85
Refactored code to work with spotify benchmark
DianaStrauss Nov 11, 2024
c70a23b
Refined test cases
DianaStrauss Nov 13, 2024
1fbb37b
Added new security endpoint for testing
DianaStrauss Nov 13, 2024
6fa891d
Added new security endpoint for testing
DianaStrauss Nov 13, 2024
86f8b06
Added more testing information for documentation testing and pentesting
DianaStrauss Nov 15, 2024
cee0726
Added evaluations
DianaStrauss Nov 16, 2024
e210104
Refactored code to be more understandable
DianaStrauss Nov 18, 2024
e228cd8
Added evaluation to documentation
DianaStrauss Nov 18, 2024
3b4b4c4
Refactored code
DianaStrauss Nov 19, 2024
2908860
Restructured testing
DianaStrauss Nov 20, 2024
b1f01dc
Refactored code
DianaStrauss Nov 22, 2024
22e64ff
Refactored code so that more endpoints are found
DianaStrauss Nov 25, 2024
b103831
Refactored code to be clearer
DianaStrauss Nov 28, 2024
e4bbdfa
Added owasp config file and owas openapi sepc
DianaStrauss Dec 2, 2024
f5ef612
Fixed some small bgs
DianaStrauss Dec 4, 2024
c6d33fe
Adjusted test cases to get better analysis
DianaStrauss Dec 4, 2024
96a400d
Added setup for automatic testing
DianaStrauss Dec 5, 2024
b0162fc
refactored test cases
DianaStrauss Dec 5, 2024
3e50596
refactored test cases
DianaStrauss Dec 6, 2024
9306dc6
refactored test cases
DianaStrauss Dec 6, 2024
0f8f445
Refactored tree of thought prompt
DianaStrauss Dec 8, 2024
b62bb01
adjusted gitignore
DianaStrauss Dec 11, 2024
dd0c17e
Refactored classification of endpoints
DianaStrauss Dec 11, 2024
1af2564
Adjusted test cases for better testing
DianaStrauss Dec 12, 2024
340280e
made continuous testing easier
DianaStrauss Dec 12, 2024
04ebcfa
Adjusted prompts to be more tailored
DianaStrauss Dec 15, 2024
1ff5fa2
Refactored and adjusted code to work also for crapi benchmark
DianaStrauss Dec 20, 2024
4dca56d
Cleaned up code
DianaStrauss Jan 9, 2025
5535eb0
Refactored test cases for better vulnerability coverage
DianaStrauss Jan 30, 2025
4ea54fc
Refactored code
DianaStrauss Feb 7, 2025
bf3395b
Added test case
DianaStrauss Feb 17, 2025
1aba1b7
adjusted report
Feb 19, 2025
b4e683b
Refactored code
DianaStrauss Mar 17, 2025
285ca9e
Anonymized readme
Mar 17, 2025
90f4028
Cleaned up code from prints and unnecessary code
DianaStrauss Mar 25, 2025
f9e09b5
Merge remote-tracking branch 'origin/web-api-testing' into web-api-te…
DianaStrauss Mar 25, 2025
b0c2b8b
Merge remote-tracking branch 'origin/development' into merge_web_api_…
DianaStrauss Apr 7, 2025
01ee69e
Adjusted code to work with web_api_testing
DianaStrauss Apr 7, 2025
32b73ab
Refactored code for better readability and testing
DianaStrauss Apr 13, 2025
303baf6
added configuration handler to better test
DianaStrauss Apr 13, 2025
4276f0f
Adjusted test of prompt engineer
DianaStrauss Apr 13, 2025
40f4ff1
Adjusted code for test
DianaStrauss Apr 13, 2025
c6b7ecd
Adjusted code and tests
Apr 14, 2025
44710f3
Adjusted tests and refactored code for better readability
Apr 14, 2025
a695971
Added test cases for pentesting information and test handler + refact…
DianaStrauss Apr 17, 2025
6f05e75
Removed unnecessary prints and added documentation
DianaStrauss Apr 22, 2025
ac58b5a
Removed unnecessary comments
DianaStrauss Apr 22, 2025
02c861f
Fixed Linter issue
DianaStrauss Apr 22, 2025
3a22053
Fixed test imports for pipeline
DianaStrauss Apr 22, 2025
0d34191
Added needed dependencies to pyproject.toml
DianaStrauss Apr 22, 2025
970b72d
Added needed dependencies to pyproject.toml
DianaStrauss Apr 22, 2025
4366132
Added needed dependencies to pyproject.toml
DianaStrauss Apr 22, 2025
9d16710
Removed test case that breaks pipeline
DianaStrauss Apr 22, 2025
9b78c6c
Adjusted init for test_handler
DianaStrauss Apr 22, 2025
9ea050b
Added needed dependencies to pyproject.toml
DianaStrauss Apr 22, 2025
424c989
Merge branch 'development' into merge_web_api_testing_development
DianaStrauss Apr 22, 2025
dbfef99
Added missing dependency
DianaStrauss Apr 22, 2025
696e395
Added missing dependency
DianaStrauss Apr 22, 2025
5e3b112
Added imports in __init__
DianaStrauss Apr 22, 2025
a6653ad
Added files
DianaStrauss Apr 22, 2025
ca17dd0
Moved config files to proper locatin
DianaStrauss Apr 22, 2025
5df1e20
updated README.md with correct image
Qsan1 May 1, 2025
a0977af
Merge pull request #120 from CoralStack/development
andreashappe May 1, 2025
e1b70ab
Merge branch 'development' into merge_web_api_testing_development
DianaStrauss May 13, 2025
78b681d
fixed syntax error in .toml
DianaStrauss May 13, 2025
8ae94fb
Fix linting
DianaStrauss May 13, 2025
9c4842f
Fix linting
DianaStrauss May 13, 2025
4d5122f
Fixed wrong import
DianaStrauss May 13, 2025
600ed43
Fixed import in testing
DianaStrauss May 13, 2025
f33c154
Fixed input variables
DianaStrauss May 13, 2025
e1c8cb4
Fixed input variables
DianaStrauss May 13, 2025
be0ff19
Fixed input variables
DianaStrauss May 13, 2025
985d740
Removed helper files
DianaStrauss May 14, 2025
19afc59
Fixed typo in parsed_information.py name
DianaStrauss May 14, 2025
b5f5688
Fixed typo in parsed_information.py name
DianaStrauss May 14, 2025
f748d5f
Update src/hackingBuddyGPT/usecases/web_api_testing/documentation/par…
DianaStrauss May 14, 2025
8d8a72c
Merge pull request #114 from ipa-lab/merge_web_api_testing_development
andreashappe May 14, 2025
290b148
moved prompt generation into utils and adjusted prompt engineer and p…
DianaStrauss May 20, 2025
bb2bd3b
Added prompt file and added logging of prompt
DianaStrauss May 23, 2025
fdf3d71
Added comments to icl
DianaStrauss May 23, 2025
aecb0be
fixed tests
DianaStrauss May 23, 2025
84f6795
Merge pull request #122 from ipa-lab/adapt_prompt_engineer
andreashappe May 23, 2025
f40bbc2
complete tmux local shell integration
ShreyasMahajann Aug 8, 2025
9ee831b
Merge branch 'development' into production
ShreyasMahajann Aug 8, 2025
bc22dff
Merge pull request #127 from ShreyasMahajann/production
andreashappe Aug 27, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactored code
  • Loading branch information
DianaStrauss committed Mar 17, 2025
commit b4e683bebb1f9222e0a84b4a6f5e7c484f0b988e
7 changes: 7 additions & 0 deletions config/hard/owasp_juice_shop_config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"name": "OWASP Juice Shop",
"bender": {
"email": "bender@juice-sh.op",
"password": "a"
},
"admin": {
"email": " admin@juice-sh.op"
},
"username": "sdfdzasasdaasdasdsdwerwddd@mail",
"password": "test",
"token": "your_api_token_here",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def get_schema_for_endpoint(self, path, method):

return None

def classify_endpoints(self):
def classify_endpoints(self, name=""):
classifications = {
'resource_intensive_endpoint': [],
'public_endpoint': [],
Expand Down Expand Up @@ -272,6 +272,9 @@ def classify_endpoints(self):
if any(keyword in path.lower() for keyword in ['user', 'users', 'signup']) and not "login" in path or any(word in description for word in ['create a user']):
if not any(keyword in path.lower() for keyword in ['pictures', 'verify-email-token', 'change-email', "reset", "verify", "videos", "mechanic"]):
if method.upper() == "POST" and not "data-export" in path:
if "OWASP" in name:
if "sers" not in path :
continue
classifications["account_creation"].append({
"method":method.upper(),
"path":path,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
import re
import uuid

import nltk

from hackingBuddyGPT.usecases.web_api_testing.prompt_generation.information import PromptStrategy


class PromptGenerationHelper(object):
"""
Expand Down Expand Up @@ -82,18 +78,24 @@ def get_user_from_prompt(self,step, accounts) -> dict:
step = step["step"]
# Search for the substring containing 'user:'
if "user:" in step:
# Extract the part after 'user:' and add it to the user_info list
data_string = step.split("user:")[1].split(".\n")[0]
# Replace single quotes with double quotes for JSON compatibility
data_string_json = data_string.replace("'", '"')


# Parse the string into a dictionary
user_info = json.loads(data_string_json)
# Extract the part after 'user:' and add it to the user_info list
data_string = step.split("user:")[1].split(".\n")[0]
# Replace single quotes with double quotes for JSON compatibility

data_string_json = data_string.replace("'", '"')
print(f'data_string_json: {data_string_json}')
data_string_json = data_string_json.replace("\"\" ", '" ')
print(f'data_string_json: {data_string_json}')

# Parse the string into a dictionary
user_info = json.loads(data_string_json)
print(f'user_info: {user_info}')
counter =0
for acc in accounts:
for key in acc.keys():
if key in user_info.keys():
if isinstance(acc[key], str) and "or 1=1--" in acc[key]:
acc[key] = "' or 1=1--"
if key != "x":
if acc[key] == user_info[key]:
counter +=1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from abc import ABC, abstractmethod
from typing import Optional

# from hackingBuddyGPT.usecases.web_api_testing.prompt_generation import PromptGenerationHelper
from hackingBuddyGPT.usecases.web_api_testing.prompt_generation.information import (
PenTestingInformation,
)
Expand Down Expand Up @@ -47,7 +45,10 @@ def __init__(
self.planning_type = planning_type
self.prompt_helper = prompt_helper
self.strategy = strategy
self.current_step = None
self.current_step = 0
self.explored_sub_steps = []
self.previous_purpose = None
self.counter = 0

def set_pentesting_information(self, pentesting_information: PenTestingInformation):
self.pentesting_information = pentesting_information
Expand Down Expand Up @@ -119,3 +120,121 @@ def get_documentation_steps(self):
"Construct and make GET requests to these endpoints using common query parameters (e.g. `/resource?param1=1&param2=3`) or based on documentation hints, testing until a valid request with query parameters is achieved."
]
]
def extract_properties(self):
properties = self.open_api_spec.get("components", {}).get("schemas", {}).get("Post", {}).get("properties", {})
extracted_props = {}

for prop_name, prop_details in properties.items():
example = prop_details.get("example", "No example provided")
prop_type = prop_details.get("type", "Unknown type")
extracted_props[prop_name] = {
"example": example,
"type": prop_type
}

return extracted_props

def sort_previous_prompt(self, previous_prompt):
sorted_list = []
for i in range(len(previous_prompt) - 1, -1, -1):
sorted_list.append(previous_prompt[i])
return sorted_list


def extract_endpoints_from_prompts(self, step):
endpoints = []
# Extract endpoints from the text using simple keyword matching
if isinstance(step, list):
step = step[0]
if "endpoint" in step.lower():
words = step.split()
for word in words:
if word.startswith("https://") or word.startswith("/") and len(word) > 1:
endpoints.append(word)

return list(set(endpoints)) # Return unique endpoints



def get_properties(self, step_details):
endpoints = self.extract_endpoints_from_prompts(step_details['step'])
for endpoint in endpoints:
for keys in self.pentesting_information.categorized_endpoints:
for ep in self.pentesting_information.categorized_endpoints[keys]:
print(f'ep:{ep}')

if ep["path"] == endpoint:
print(f'ep:{ep}')
print(f' endpoint: {endpoint}')
schema = ep.get('schema', {})
if schema != None and schema != {}:
properties = schema.get('properties', {})
else:
properties = None
return properties

def next_purpose(self, step, icl_steps, purpose):
# Process the step and return its result
last_item = icl_steps[-1]
if self.check_if_step_is_same(last_item, step):
# If it's the last step, remove the purpose and update self.purpose
if purpose in self.pentesting_information.pentesting_step_list:
self.pentesting_information.pentesting_step_list.remove(purpose)
if self.pentesting_information.pentesting_step_list:
self.purpose = self.pentesting_information.pentesting_step_list[0]

self.counter = 0 # Reset counter
print(f'purpose:{self.purpose}')

def check_if_step_is_same(self, step1, step2):
# Check if 'steps' and 'path' are identical
steps_same = (step1.get('steps', [])[0] == step2.get('steps', [])[0].get("step"))
print(f'step1: {step1}')
print(f'step2: {step2}')
#path_same = (step1.get('path', []) == step2.get('path', []))

# Check if 'expected_response_code' are identical
#response_code_same = (
#
# Check if 'security' instructions are the same
#security_same = (step1.get('security', []) == step2.get('security', []))

# Evaluate and return the overall comparison
return steps_same
def all_substeps_explored(self, icl_steps):
all_steps = []
for step in icl_steps.get("steps") :
all_steps.append(step)

if all_steps in self.explored_sub_steps:
return True
else:
return False

def get_props(self, data, result ):
for key, value in data.items():

if isinstance(value, dict):

# Recursively extract properties from nested dictionaries

nested_properties = self.extract_properties_with_examples(value)

result.update(nested_properties)

elif isinstance(value, list):

if value:

example_value = value[0]

result[key] = {"type": "list", "example": example_value}

else:

result[key] = {"type": "list", "example": "[]"}
else:

result[key] = {"type": type(value).__name__, "example": value}

return result
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json
from typing import Dict, Optional, Any, List
from unittest import result

from hackingBuddyGPT.usecases.web_api_testing.prompt_generation.information.prompt_information import (
PromptContext,
PromptPurpose,
Expand Down Expand Up @@ -46,10 +44,7 @@ def __init__(self, context: PromptContext, prompt_helper, context_information: D
self.open_api_spec = open_api_spec
self.response_history = {
}
self.current_step = 0
self.explored_sub_steps =[]
self.previous_purpose = None
self.counter = 0



def generate_prompt(
Expand Down Expand Up @@ -163,10 +158,13 @@ def _get_pentesting_steps(self, move_type: str, common_step: Optional[str] = "")
# single step test case
if len(icl_test_case.get("steps")) == 1:
self.current_sub_step = icl_test_case.get("steps")[0]
self.current_sub_step["path"] = icl_test_case.get("path")[0]
else:
if self.counter < len(icl_test_case.get("steps")):
# multi-step test case
self.current_sub_step = icl_test_case.get("steps")[self.counter]
if len(icl_test_case.get("path")) > 1:
self.current_sub_step["path"] = icl_test_case.get("path")[self.counter]
self.explored_sub_steps.append(self.current_sub_step)
self.explored_steps.append(icl_test_case)

Expand All @@ -190,19 +188,7 @@ def _get_pentesting_steps(self, move_type: str, common_step: Optional[str] = "")
import json

# Function to extract properties from the schema
def extract_properties(self):
properties = self.open_api_spec.get("components", {}).get("schemas", {}).get("Post", {}).get("properties", {})
extracted_props = {}

for prop_name, prop_details in properties.items():
example = prop_details.get("example", "No example provided")
prop_type = prop_details.get("type", "Unknown type")
extracted_props[prop_name] = {
"example": example,
"type": prop_type
}

return extracted_props

# Function to extract example response from paths
def extract_example_response(self, api_paths, endpoint, method="get"):
Expand Down Expand Up @@ -282,11 +268,6 @@ def extract_properties_with_examples(self, data):

return result

def sort_previous_prompt(self, previous_prompt):
sorted_list = []
for i in range(len(previous_prompt) - 1, -1, -1):
sorted_list.append(previous_prompt[i])
return sorted_list

def transform_to_icl_with_previous_examples(self, test_case, purpose):
"""
Expand All @@ -307,7 +288,8 @@ def transform_to_icl_with_previous_examples(self, test_case, purpose):
transformed_case = {
"phase_title": f"Phase: {test_case['objective']}",
"steps": [],
"assessments": []
"assessments": [],
"path": test_case.get("path")
}

print(f' PHASE: {test_case["objective"]}')
Expand Down Expand Up @@ -364,18 +346,6 @@ def transform_to_icl_with_previous_examples(self, test_case, purpose):

return transformed_case

def extract_endpoints_from_prompts(self, step):
endpoints = []
# Extract endpoints from the text using simple keyword matching
if isinstance(step, list):
step = step[0]
if "endpoint" in step.lower():
words = step.split()
for word in words:
if word.startswith("https://") or word.startswith("/") and len(word) > 1:
endpoints.append(word)

return list(set(endpoints)) # Return unique endpoints

def transform_test_case_to_string(self, test_case, character):
"""
Expand Down Expand Up @@ -424,85 +394,7 @@ def transform_test_case_to_string(self, test_case, character):

return ''.join(result)

def get_properties(self, step_details):
endpoints = self.extract_endpoints_from_prompts(step_details['step'])
for endpoint in endpoints:
for keys in self.pentesting_information.categorized_endpoints:
for ep in self.pentesting_information.categorized_endpoints[keys]:
print(f'ep:{ep}')

if ep["path"] == endpoint:
print(f'ep:{ep}')
print(f' endpoint: {endpoint}')
schema = ep.get('schema', {})
if schema != None and schema != {}:
properties = schema.get('properties', {})
else:
properties = None
return properties

def next_purpose(self, step, icl_steps, purpose):
# Process the step and return its result
last_item = icl_steps[-1]
if self.check_if_step_is_same(last_item, step):
# If it's the last step, remove the purpose and update self.purpose
if purpose in self.pentesting_information.pentesting_step_list:
self.pentesting_information.pentesting_step_list.remove(purpose)
if self.pentesting_information.pentesting_step_list:
self.purpose = self.pentesting_information.pentesting_step_list[0]

self.counter = 0 # Reset counter

def check_if_step_is_same(self, step1, step2):
# Check if 'steps' and 'path' are identical
steps_same = (step1.get('steps', [])[0] == step2.get('steps', [])[0].get("step"))
#path_same = (step1.get('path', []) == step2.get('path', []))

# Check if 'expected_response_code' are identical
#response_code_same = (
#
# Check if 'security' instructions are the same
#security_same = (step1.get('security', []) == step2.get('security', []))

# Evaluate and return the overall comparison
return steps_same
def all_substeps_explored(self, icl_steps):
all_steps = []
for step in icl_steps.get("steps") :
all_steps.append(step)

if all_steps in self.explored_sub_steps:
return True
else:
return False

def get_props(self, data, result ):
for key, value in data.items():

if isinstance(value, dict):

# Recursively extract properties from nested dictionaries

nested_properties = self.extract_properties_with_examples(value)

result.update(nested_properties)

elif isinstance(value, list):

if value:

example_value = value[0]

result[key] = {"type": "list", "example": example_value}

else:

result[key] = {"type": "list", "example": "[]"}
else:

result[key] = {"type": type(value).__name__, "example": value}

return result



Loading