GreyDGL / PentestGPT

A GPT-empowered penetration testing tool
MIT License
6.67k stars 796 forks source link

PentestGPT won't initialize #149

Closed yonasuriv closed 10 months ago

yonasuriv commented 10 months ago

Describe the bug PentestGPT won't initialize.

To Reproduce Steps to reproduce the behavior:

❯ pentestgpt --parsing_model=gpt-4
Your CHATGPT_COOKIE is not set. Please set it in the environment variable.
Welcome to pentestGPT, an automated penetration testing parser empowered by GPT.
The settings are: 
 - parsing model: gpt-4-browsing
 - reasoning model: gpt-4-browsing
 - use API: True
 - log directory: logs
Do you want to continue from previous session? (y/n) n
- ChatGPT Sessions Initialized.
Please describe the penetration testing task in one line, including the target IP, task type, etc.
> [HIDDEN]
Traceback (most recent call last):
  File "/home/kali/.local/lib/python3.11/site-packages/tenacity/__init__.py", line 382, in __call__
    result = fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^
  File "/home/kali/PentestGPT/pentestgpt/utils/llm_api.py", line 253, in send_message
    conversation = self.conversation_dict[conversation_id]
                   ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: None

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/kali/.local/bin/pentestgpt", line 33, in <module>
    sys.exit(load_entry_point('pentestgpt', 'console_scripts', 'pentestgpt')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/PentestGPT/pentestgpt/main.py", line 32, in main
    pentestGPTHandler.main()
  File "/home/kali/PentestGPT/pentestgpt/utils/pentest_gpt.py", line 682, in main
    self.initialize(previous_session_ids=loaded_ids)
  File "/home/kali/PentestGPT/pentestgpt/utils/pentest_gpt.py", line 243, in initialize
    self._feed_init_prompts()
  File "/home/kali/PentestGPT/pentestgpt/utils/pentest_gpt.py", line 170, in _feed_init_prompts
    _reasoning_response = self.reasoningAgent.send_message(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/.local/lib/python3.11/site-packages/tenacity/__init__.py", line 289, in wrapped_f
    return self(f, *args, **kw)
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/.local/lib/python3.11/site-packages/tenacity/__init__.py", line 379, in __call__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/.local/lib/python3.11/site-packages/tenacity/__init__.py", line 326, in iter
    raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x7f406e8b2410 state=finished raised KeyError>]

Expected behavior I've cloned the repository, installed the requeriments and using GPT4 model properly. When asked for the penetration task to perform I get this output:

Traceback (most recent call last):
  File "/home/kali/.local/lib/python3.11/site-packages/tenacity/__init__.py", line 382, in __call__
    result = fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^
  File "/home/kali/PentestGPT/pentestgpt/utils/llm_api.py", line 253, in send_message
    conversation = self.conversation_dict[conversation_id]
                   ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: None

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/kali/.local/bin/pentestgpt", line 33, in <module>
    sys.exit(load_entry_point('pentestgpt', 'console_scripts', 'pentestgpt')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/PentestGPT/pentestgpt/main.py", line 32, in main
    pentestGPTHandler.main()
  File "/home/kali/PentestGPT/pentestgpt/utils/pentest_gpt.py", line 682, in main
    self.initialize(previous_session_ids=loaded_ids)
  File "/home/kali/PentestGPT/pentestgpt/utils/pentest_gpt.py", line 243, in initialize
    self._feed_init_prompts()
  File "/home/kali/PentestGPT/pentestgpt/utils/pentest_gpt.py", line 170, in _feed_init_prompts
    _reasoning_response = self.reasoningAgent.send_message(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/.local/lib/python3.11/site-packages/tenacity/__init__.py", line 289, in wrapped_f
    return self(f, *args, **kw)
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/.local/lib/python3.11/site-packages/tenacity/__init__.py", line 379, in __call__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/.local/lib/python3.11/site-packages/tenacity/__init__.py", line 326, in iter
    raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x7f3e251dff50 state=finished raised KeyError>]

Version You're testing the connection for PentestGPT v 0.10.1

GreyDGL commented 10 months ago

May you help to attach the output of pentestgpt-connection?

yonasuriv commented 10 months ago

May you help to attach the output of pentestgpt-connection?

Your CHATGPT_COOKIE is not set. Please set it in the environment variable.
You're testing the connection for PentestGPT v 0.10.1
#### Test connection for OpenAI api (GPT-4)
Traceback (most recent call last):
  File "/home/kali/PentestGPT/pentestgpt/utils/APIs/chatgpt_api.py", line 64, in _chat_completion
    response = openai.ChatCompletion.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/.local/lib/python3.11/site-packages/openai/api_resources/chat_completion.py", line 25, in create
    return super().create(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/.local/lib/python3.11/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 153, in create
    response, _, api_key = requestor.request(
                           ^^^^^^^^^^^^^^^^^^
  File "/home/kali/.local/lib/python3.11/site-packages/openai/api_requestor.py", line 298, in request
    resp, got_stream = self._interpret_response(result, stream)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/.local/lib/python3.11/site-packages/openai/api_requestor.py", line 700, in _interpret_response
    self._interpret_response_line(
  File "/home/kali/.local/lib/python3.11/site-packages/openai/api_requestor.py", line 765, in _interpret_response_line
    raise self.handle_error_response(
openai.error.InvalidRequestError: The model `gpt-4` does not exist or you do not have access to it. Learn more: https://help.openai.com/en/articles/7102672-how-can-i-access-gpt-4.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kali/.local/bin/pentestgpt-connection", line 33, in <module>
    sys.exit(load_entry_point('pentestgpt', 'console_scripts', 'pentestgpt-connection')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/PentestGPT/pentestgpt/test_connection.py", line 46, in main
    result, conversation_id = chatgpt.send_new_message("Hi how are you?")
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/PentestGPT/pentestgpt/utils/llm_api.py", line 225, in send_new_message
    response = self._chat_completion(history)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/PentestGPT/pentestgpt/utils/APIs/chatgpt_api.py", line 96, in _chat_completion
    history[-1]["content"] = self.token_compression(history)
                             ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ChatGPTAPI' object has no attribute 'token_compression'. Did you mean: '_token_compression'?
GreyDGL commented 10 months ago

Two possible issues. (1) you did not initialize your OpenAI API key with a proper payment method. To use the tool, a valid payment method (credit card) shall be added to OpenAI account. (2) The openai library is not the latest. To check that, use pip show openai. It should be updated to at least 0.27.1

yonasuriv commented 10 months ago

Was the payment method. Thanks mate!