Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
f0109a3
Refactored code so that documentation is handled by separate class
DianaStrauss Jun 10, 2024
630f571
refactored code
DianaStrauss Jun 10, 2024
bef16c0
Adjusted prompt_engineer to create better prompts
DianaStrauss Jun 13, 2024
74062ff
Refactored documentation_handler.py to update .yaml file when it get …
DianaStrauss Jun 13, 2024
7591be3
Created SubmitHTTPMethod.py for better separation
DianaStrauss Jun 13, 2024
73fe5c4
Created Converter and parser for handeling yaml and json files
DianaStrauss Jun 13, 2024
430cb1f
Refactored converter and parser
DianaStrauss Jun 14, 2024
cef43e9
Added token count so that prompts are not too long -> WIP shorten pro…
DianaStrauss Jun 14, 2024
89956d7
Refactored code and added yamlFile.py
DianaStrauss Jun 17, 2024
e7ce9ae
Refactored code
DianaStrauss Jun 19, 2024
6051342
switch from RoundBasedUseCase to Agent
andreashappe Jun 24, 2024
9739d17
switch from RoundBasedUseCase to Agent
andreashappe Jun 24, 2024
dfd9dbe
switch from RoundBasedUseCase to Agent
andreashappe Jun 24, 2024
9f119d8
switch from RoundBasedUseCase to Agent
andreashappe Jun 24, 2024
15f7a64
rename RoundBasedUseCse into AutonomousUseCase
andreashappe Jun 24, 2024
69c0340
add `perform_round` to agent as abstract method
andreashappe Jun 24, 2024
6d66889
add type information to Agent
andreashappe Jun 24, 2024
be78320
Convert PrivescWithHintFile from UseCase to Agent
andreashappe Jun 24, 2024
a401e07
convert the privescLSE usecase from UseCase to Agent
andreashappe Jun 24, 2024
c75d374
move AutonomousUseCase into base package too
andreashappe Jun 24, 2024
2dc037d
add some TODO notes to prior to split-up
andreashappe Jun 24, 2024
995b199
Added simple scoring to prompt engineer
DianaStrauss Jul 4, 2024
cbafdf2
changed order of setuo methods in simple_openai_documentation
DianaStrauss Jul 4, 2024
34593e3
changed order of setuo methods in simple_openai_documentation
DianaStrauss Jul 4, 2024
b95dd31
changed order of setuo methods in simple_openai_documentation
DianaStrauss Jul 4, 2024
e267621
Addition of examples works with redocly
DianaStrauss Jul 9, 2024
56bc5ff
Added yaml file assistant
DianaStrauss Jul 9, 2024
7c681af
Can create openapi spec with examples
DianaStrauss Jul 9, 2024
120b09f
Cleaned up code
DianaStrauss Jul 12, 2024
2fcca09
Refactor code
DianaStrauss Jul 12, 2024
29aa192
Refactor code
DianaStrauss Jul 12, 2024
b2632ab
Cleaned up code
DianaStrauss Jul 12, 2024
3af909a
Cleaned up code
DianaStrauss Jul 12, 2024
b1f9886
Cleaned up code
DianaStrauss Jul 12, 2024
fc37bfd
start with agent/usecase rework
andreashappe Jul 16, 2024
7d75a2c
Fixes configurations and changes over:
Neverbolt Jul 16, 2024
d6a99d8
reintroduce agent.setup() and make more use-cases work again
andreashappe Jul 17, 2024
deddab7
reintroduce agent.setup()
andreashappe Jul 17, 2024
2f8edc3
explicitely define the UseCase (instead of annotation)
andreashappe Jul 17, 2024
1bc86b5
make LinuxPrivescWithHintFile a usecase
andreashappe Jul 17, 2024
48f7852
Changes over the UseCases to full classes
Neverbolt Jul 20, 2024
7f9f43a
Merge pull request #73 from ipa-lab/explorative_refactoring
andreashappe Jul 22, 2024
5915187
Merge branch 'main' of https://github.com/DianaStrauss/hackingBuddyGP…
andreashappe Jul 22, 2024
f84a556
Fixes `use_case` decorator return type
Neverbolt Jul 22, 2024
8e58cad
Merge branch 'development' into DianaStrauss-main
andreashappe Jul 22, 2024
bbb8133
update dependencies
andreashappe Jul 22, 2024
fd4323e
some simple renames
andreashappe Jul 22, 2024
ec3a0ee
Fixed attribute initialization of use_cases and transparent types
Neverbolt Jul 26, 2024
0babd39
Refactored code and fixed import bugs in simple_web_api_testing and s…
DianaStrauss Aug 1, 2024
09c8e3d
Merge pull request #74 from ipa-lab/DianaStrauss-main
andreashappe Aug 1, 2024
e289ad6
update readme.md a bit
andreashappe Aug 1, 2024
653a119
Update README.md
andreashappe Aug 1, 2024
7dd36ea
Update README.md
andreashappe Aug 1, 2024
99d6134
introduct before_run/after_run hooks and use them within the hintfile…
andreashappe Aug 2, 2024
676a960
re-do the LinuxPrivescWithLSE use-case to directly call agents
andreashappe Aug 2, 2024
58e144c
Adjusted code for better testing of web_api_documentation
DianaStrauss Aug 2, 2024
9a14af2
Adjusted code for better testing of web_api_documentation
DianaStrauss Aug 2, 2024
fb05d87
added tolerance for web_api_testing
DianaStrauss Aug 2, 2024
45832a5
Update README.md
andreashappe Aug 2, 2024
71e5eb8
Merge remote-tracking branch 'refs/remotes/origin/web_api_testing' in…
DianaStrauss Aug 2, 2024
e4a2285
Replaced spacy with nltk as tokenizer for shortening prompts
DianaStrauss Aug 2, 2024
d2134d8
finished mocking web_api_documentation testing
Aug 5, 2024
7c0b84a
finished adding simple mock tests for web_api_testing
Aug 5, 2024
38bfbc0
Merge pull request #76 from ipa-lab/development_without_spacy
andreashappe Aug 5, 2024
3e52a55
also run testcases when changes to development happen
andreashappe Aug 5, 2024
a337520
fixed web_api_documentation test and removed unnecessary imports
DianaStrauss Aug 6, 2024
947c8a7
Added test for prompt engineer
DianaStrauss Aug 6, 2024
1640538
Added optional dependencies to .toml file for testing, instructions w…
DianaStrauss Aug 6, 2024
86cf648
Changed name of documentation_handler of web_api as there were other …
DianaStrauss Aug 6, 2024
44af818
Added tests for llm_handler and response_handler
DianaStrauss Aug 6, 2024
9bdd6bd
Added tests for openapi converter and parser
DianaStrauss Aug 6, 2024
70a9018
add upcoming talk of manuel
andreashappe Aug 6, 2024
e4ef23a
optimizeded code
DianaStrauss Aug 6, 2024
d013162
adjusted tests
DianaStrauss Aug 6, 2024
88fcf70
fixed wrong import
DianaStrauss Aug 6, 2024
033b598
Merge pull request #80 from ipa-lab/development_without_spacy
andreashappe Aug 6, 2024
ea56264
make lse-based example work
andreashappe Aug 6, 2024
aafabf1
Merge branch 'development' of github.com:ipa-lab/hackingBuddyGPT into…
andreashappe Aug 6, 2024
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
finished mocking web_api_documentation testing
  • Loading branch information
Diana Strauss authored and Diana Strauss committed Aug 5, 2024
commit d2134d893e8e457c882b8e069855dec9e68023c5
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ class SimpleWebAPIDocumentation(Agent):
_all_http_methods_found: bool = False

# Description for expected HTTP methods
http_method_description: str = parameter(
_http_method_description: str = parameter(
desc="Pattern description for expected HTTP methods in the API response",
default="A string that represents an HTTP method (e.g., 'GET', 'POST', etc.)."
)

# Template for HTTP methods in API requests
http_method_template: str = parameter(
_http_method_template: str = parameter(
desc="Template to format HTTP methods in API requests, with {method} replaced by actual HTTP method names.",
default="{method}"
)

# List of expected HTTP methods
http_methods: str = parameter(
_http_methods: str = parameter(
desc="Expected HTTP methods in the API, as a comma-separated list.",
default="GET,POST,PUT,PATCH,DELETE"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, llm_handler, response_handler):
"components": {"schemas": {}}
}
self.llm_handler = llm_handler
self.api_key = llm_handler.llm.api_key
#self.api_key = llm_handler.llm.api_key
current_path = os.path.dirname(os.path.abspath(__file__))
self.file_path = os.path.join(current_path, "openapi_spec")
self.file = os.path.join(self.file_path, self.filename)
Expand Down
86 changes: 60 additions & 26 deletions tests/test_web_api_documentation.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,77 @@
import argparse
import unittest
from hackingBuddyGPT.usecases.base import use_cases
from hackingBuddyGPT.usecases.web_api_testing.simple_web_api_testing import SimpleWebAPITestingUseCase
from hackingBuddyGPT.utils import DbStorage, Console
from unittest.mock import MagicMock, patch

from hackingBuddyGPT.usecases import SimpleWebAPITesting
from hackingBuddyGPT.usecases.web import MinimalWebTesting
from hackingBuddyGPT.usecases.web_api_testing.simple_openapi_documentation import SimpleWebAPIDocumentationUseCase
from hackingBuddyGPT.utils import DbStorage, Console
from hackingBuddyGPT.utils.openai.openai_lib import OpenAILib


class WebAPIDocumentationTestCase(unittest.TestCase):
def test_simple_web_api_testing(self):
class TestSimpleWebAPITesting(unittest.TestCase):

@patch('hackingBuddyGPT.utils.openai.openai_lib.OpenAILib')
def setUp(self, MockOpenAILib):
# Mock the OpenAILib instance
self.mock_llm = MockOpenAILib.return_value
log_db = DbStorage(':memory:')
console = Console()

log_db.init()
parser = argparse.ArgumentParser()
subparser = parser.add_subparsers(required=True)
for name, use_case in use_cases.items():
use_case.build_parser(subparser.add_parser(
name=use_case.name,
help=use_case.description
))

parsed = parser.parse_args(["SimpleWebAPIDocumentation"])
instance = parsed.use_case(parsed)

agent = instance.agent
simple_web_api_documentation = SimpleWebAPITestingUseCase(
agent=agent,
self.agent = SimpleWebAPITesting(llm=self.mock_llm)
self.agent.init()
self.simple_api_testing = SimpleWebAPIDocumentationUseCase(
agent=self.agent,
log_db=log_db,
console=console,
tag='web_api_documentation',
max_turns=20
tag='integration_test_linuxprivesc',
max_turns=len(self.mock_llm.responses)
)
self.simple_api_testing.init()

def test_initial_prompt(self):
# Test if the initial prompt is set correctly
self.assertIn("You're a seasoned API tester tasked with evaluating the REST APIs of a website hosted at https://jsonplaceholder.typicode.com. Your primary objective is to thoroughly explore the APIs, understanding their endpoints, parameters, and responses, and then devise and execute potential exploits. Be diligent in documenting your findings as you navigate through the APIs. Avoid resorting to brute-force tactics. All necessary information can be obtained from the API endpoints themselves. Remember, if you encounter an HTTP method (A string that represents an HTTP method (e.g., 'GET', 'POST', etc.).), promptly submit it as it is of utmost importance.", self.agent._prompt_history[0]['content'])

def test_all_flags_found(self):
# Mock console.print to suppress output during testing
with patch('rich.console.Console.print'):
self.agent.all_http_methods_found()
self.assertFalse(self.agent.all_http_methods_found())

@patch('time.perf_counter', side_effect=[1, 2]) # Mocking perf_counter for consistent timing
def test_perform_round(self, mock_perf_counter):
# Prepare mock responses
mock_response = MagicMock()
mock_completion = MagicMock()

# Setup completion response with mocked data
mock_completion.choices[0].message.content = "Mocked LLM response"
mock_completion.choices[0].message.tool_calls = [MagicMock(id="tool_call_1")]
mock_completion.usage.prompt_tokens = 10
mock_completion.usage.completion_tokens = 20

# Mock the OpenAI LLM response
self.agent.llm.instructor.chat.completions.create_with_completion.return_value = (
mock_response, mock_completion)

# Mock the tool execution result
mock_response.execute.return_value = "Mocked tool execution result"

# Perform the round
result = self.agent.perform_round(1)

# Assertions
self.assertFalse(result) # No flags found in this round

# Check if the LLM was called with the correct parameters
mock_create_with_completion = self.agent.llm.instructor.chat.completions.create_with_completion

simple_web_api_documentation.init()
result = simple_web_api_documentation.run()
print(f'result: {result}')
assert result is True
# if it can be called multiple times, use assert_called
self.assertEqual( 2, mock_create_with_completion.call_count)

# Check if the prompt history was updated correctly
self.assertEqual(5, len(self.agent._prompt_history)) # Initial message + LLM response + tool message

if __name__ == '__main__':
unittest.main()