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
Updated Tree of thought so that documentation works like chain of tho…
…ught
  • Loading branch information
DianaStrauss committed Oct 16, 2024
commit 4409f4b43d0052caee08bf1f4be8d56bb69ab1de
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def update_openapi_spec(self, resp, result, result_str):
status_code, status_message = result_str.split(" ", 1)

if request.__class__.__name__ == "RecordNote": # TODO: check why isinstance does not work
self.check_openapi_spec(resp)
#self.check_openapi_spec(resp)
return list(self.openapi_spec["endpoints"].keys())

if request.__class__.__name__ == "HTTPRequest":
Expand All @@ -90,7 +90,7 @@ def update_openapi_spec(self, resp, result, result_str):

# Extract the main part of the path for checking partial matches
path_parts = path.split("/")
main_path = path_parts[1] if len(path_parts) > 1 else ""
main_path = path if len(path_parts) > 1 else ""

# Initialize the path if it's not present and is valid
if path not in endpoints and main_path:
Expand All @@ -105,7 +105,9 @@ def update_openapi_spec(self, resp, result, result_str):

# Add example and reference to the method's responses if available
if example or reference:
endpoints[path][method.lower()] = {
if path in endpoints.keys() and method.lower() not in endpoints[path].values():

endpoints[path][method.lower()] = {
"summary": f"{method} operation on {path}",
"responses": {
f"{status_code}": {
Expand All @@ -114,17 +116,17 @@ def update_openapi_spec(self, resp, result, result_str):
"application/json": {
"schema": {"$ref": reference},
"examples": example
}
}
}
}
}
}

# Update endpoint methods for the path
endpoint_methods[path].append(method)
# Update endpoint methods for the path
endpoint_methods[path].append(method)

# Ensure uniqueness of methods for each path
endpoint_methods[path] = list(set(endpoint_methods[path]))
# Ensure uniqueness of methods for each path
endpoint_methods[path] = list(set(endpoint_methods[path]))

return list(self.openapi_spec["endpoints"].keys())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,87 +40,83 @@ def __init__(self, response_handler: ResponseHandler = None, schemas: dict = Non

import re

def find_missing_endpoints(self, endpoints: list) -> list:
def find_missing_endpoint(self, endpoints: dict) -> str:
"""
Identifies and returns the actual missing endpoint paths.
Identifies and returns the first missing endpoint path found.

Args:
endpoints (dict): A dictionary of endpoint paths (e.g., {'/resources/': {...}, '/resources/:id': {...}}).
endpoints (dict): A dictionary of endpoint paths (e.g., {'/resources': {...}, '/resources/:id': {...}}).

Returns:
list: A list of missing endpoint paths.
Example: ['/resources/:id', '/products/']
str: The first missing endpoint path found.
Example: '/resources/:id' or '/products'
"""
general_endpoints = set()
parameterized_endpoints = set()

# Extract resource names and categorize them
# Extract resource names and categorize them using regex
for endpoint in endpoints:
match = re.match(r'^/([^/]+)/?$', endpoint) # Match general endpoints like /resources/
# Match both general and parameterized patterns and categorize them
match = re.match(r'^/([^/]+)(/|/:id)?$', endpoint)
if match:
general_endpoints.add(match.group(1))

match = re.match(r'^/([^/]+)/:id$', endpoint) # Match parameterized endpoints like /resources/:id
if match:
parameterized_endpoints.add(match.group(1))

# Find resources that are missing either general or parameterized endpoints
missing_endpoints = []
all_resources = general_endpoints | parameterized_endpoints

for resource in all_resources:
resource = match.group(1)
if match.group(2) == '/' or match.group(2) is None:
general_endpoints.add(resource)
elif match.group(2) == '/:id':
parameterized_endpoints.add(resource)

# Find missing endpoints during the comparison
for resource in parameterized_endpoints:
if resource not in general_endpoints:
missing_endpoints.append(f'/{resource}/')
return f'/{resource}'
for resource in general_endpoints:
if resource not in parameterized_endpoints:
missing_endpoints.append(f'/{resource}/:id')
return f'/{resource}/:id'

# If only one missing endpoint is needed, break early
if len(missing_endpoints) == 1:
break

return missing_endpoints
# Return an empty string if no missing endpoints are found
return ""

def get_endpoints_needing_help(self, info=""):
"""
Identifies endpoints that need additional HTTP methods and returns guidance for the first missing method.

Args:
info (str): Additional information to include in the response.

Returns:
list: A list containing guidance for the first missing method of the first endpoint that needs help.
"""
endpoints_needing_help = []
endpoints_and_needed_methods = {}
http_methods_set = {"GET", "POST", "PUT", "DELETE"}

for endpoint, methods in self.endpoint_methods.items():
if len(methods) >= 4:
continue

# the endpoint needs help
missing_methods = http_methods_set - set(methods)
endpoints_needing_help.append(endpoint)
endpoints_and_needed_methods[endpoint] = list(missing_methods)

if endpoints_needing_help:
first_endpoint = endpoints_needing_help[0]
needed_method = endpoints_and_needed_methods[first_endpoint][0]
print(F'{first_endpoint}: {needed_method}')
if ":id" in first_endpoint:
first_endpoint = first_endpoint.replace(":id", "1")
return [
info + "/n",
f"For endpoint {first_endpoint}, find this missing method: {needed_method}. "
#f"If all HTTP methods have already been found for an endpoint, do not include this endpoint in your search."
]
else:
missing_endpoints = self.find_missing_endpoints(endpoints=self.found_endpoints)
if missing_endpoints:
needed_method = "GET"
if missing_methods:
needed_method = next(iter(missing_methods))
formatted_endpoint = endpoint.replace(":id", "1") if ":id" in endpoint else endpoint
return [
info + "/n",
f"For endpoint {missing_endpoints[0]}, find this missing method: {needed_method}. "
# f"If all HTTP methods have already been found for an endpoint, do not include this endpoint in your search."
f"{info}\n",
f"For endpoint {formatted_endpoint}, find this missing method: {needed_method}. "
]

# If no endpoints need help, find missing endpoints and suggest "GET"
missing_endpoint = self.find_missing_endpoint(endpoints=self.found_endpoints)
print(f"------------------------------------")
print(f"------------------------------------")
print(f"------------------------------------")
print(f"{info}\n{missing_endpoint}")
print(f"------------------------------------")
print(f"------------------------------------")
print(f"------------------------------------")

if missing_endpoint != "":
formatted_endpoint = missing_endpoint.replace(":id", "1") if ":id" in missing_endpoint else \
missing_endpoint
return [
f"{info}\n",
f"For endpoint {formatted_endpoint}, find this missing method: GET. "
]

return []

def get_http_action_template(self, method):
"""
Constructs a consistent HTTP action description based on the provided method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def parse_http_response_to_openapi_example(
key = entry.get("title") or entry.get("name") or entry.get("id")
entry_dict[key] = {"value": entry}
self.llm_handler.add_created_object(entry_dict[key], object_name)
if len(entry_dict) > 3:
break
else:
key = body_dict.get("title") or body_dict.get("name") or body_dict.get("id")
entry_dict[key] = {"value": body_dict}
Expand Down Expand Up @@ -161,6 +163,8 @@ def parse_http_response_to_schema(
Returns:
Tuple[str, str, Dict[str, Any]]: A tuple containing the reference, object name, and updated OpenAPI specification.
"""
if "/" not in path:
return None, None, openapi_spec
object_name = path.split("/")[1].capitalize().rstrip("s")
properties_dict = {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def init(self):
self._setup_capabilities()
self.llm_handler = LLMHandler(self.llm, self._capabilities)
self.response_handler = ResponseHandler(self.llm_handler)
self.strategy = PromptStrategy.IN_CONTEXT
self.strategy = PromptStrategy.TREE_OF_THOUGHT
self.documentation_handler = OpenAPISpecificationHandler(self.llm_handler, self.response_handler, self.strategy)
self._setup_initial_prompt()

Expand Down Expand Up @@ -132,31 +132,37 @@ def perform_round(self, turn: int) -> bool:
if turn == 1:
last_endpoint_found_x_steps_ago = 0
new_endpoint_count = len(self.documentation_handler.endpoint_methods)
last_number_of_found_endpoints = 0
while (last_endpoint_found_x_steps_ago <= new_endpoint_count + 2
and last_endpoint_found_x_steps_ago <= 5
and not self.found_all_http_methods):
last_number_of_found_endpoints = len(self.prompt_engineer.prompt_helper.found_endpoints)

# Explore mode: search for new endpoints until conditions are met
while (
last_endpoint_found_x_steps_ago <= new_endpoint_count + 2
and last_endpoint_found_x_steps_ago <= 5
and not self.found_all_http_methods
):
self.run_documentation(turn, "explore")

# Check if new endpoints have been found
# Update endpoint counts
current_endpoint_count = len(self.prompt_engineer.prompt_helper.found_endpoints)
if last_number_of_found_endpoints == len(self.prompt_engineer.prompt_helper.found_endpoints):

if current_endpoint_count == last_number_of_found_endpoints:
last_endpoint_found_x_steps_ago += 1
else:
last_endpoint_found_x_steps_ago = 0 # Reset if a new endpoint is found
last_endpoint_found_x_steps_ago = 0
last_number_of_found_endpoints = current_endpoint_count

# Update if new endpoint methods are discovered
if len(self.documentation_handler.endpoint_methods) > new_endpoint_count:
new_endpoint_count = len(self.documentation_handler.endpoint_methods)
# Check if new methods have been discovered
updated_endpoint_count = len(self.documentation_handler.endpoint_methods)
if updated_endpoint_count > new_endpoint_count:
new_endpoint_count = updated_endpoint_count
self.prompt_engineer.open_api_spec = self.documentation_handler.openapi_spec

last_number_of_found_endpoints = current_endpoint_count

elif turn == 20:
# Continue until all endpoints needing help are addressed
# Exploit mode: refine endpoints until no further help is needed
while self.prompt_engineer.prompt_helper.get_endpoints_needing_help():
self.run_documentation(turn, "exploit")
self.prompt_engineer.open_api_spec = self.documentation_handler.openapi_spec

else:
# For other turns, run documentation in exploit mode
self.run_documentation(turn, "exploit")
Expand Down