GreyDGL / PentestGPT

A GPT-empowered penetration testing tool
MIT License
7.29k stars 886 forks source link

TypeError: can only concatenate str (not "tuple") to str #70

Closed ostrolucky closed 1 year ago

ostrolucky commented 1 year ago
gostrolucky@ubuntu:/Users/gostrolucky/Downloads/PentestGPT$ python3 main.py --reasoning_model=gpt-4
- ChatGPT Sessions Initialized.
Please describe the penetration testing task in one line, including the target IP, task type, etc.
> Hello world
- Task information generated.

PentestGPT suggests you to do the following:
(None, None)
Traceback (most recent call last):
  File "/Users/gostrolucky/Downloads/PentestGPT/main.py", line 27, in <module>
    pentestGPTHandler.main()
  File "/Users/gostrolucky/Downloads/PentestGPT/utils/pentest_gpt.py", line 479, in main
    "PentestGPT", "PentestGPT suggests you to do the following: \n" + _response
TypeError: can only concatenate str (not "tuple") to str
gostrolucky@ubuntu:/Users/gostrolucky/Downloads/PentestGPT$ python3 --version
Python 3.10.7
GreyDGL commented 1 year ago

Thanks for reporting the issue. This was also reported by previous users. I'll try to fix it and update here.

jeremiahforsythe commented 1 year ago

Traceback (most recent call last): File "C:\Users\Jerem\Downloads\chatgpt\PentestGPT\main.py", line 27, in pentestGPTHandler.main() File "C:\Users\Jerem\Downloads\chatgpt\PentestGPT\utils\pentest_gpt.py", line 479, in main "PentestGPT", "PentestGPT suggests you to do the following: \n" + _response TypeError: can only concatenate str (not "tuple") to str

@GreyDGL im getting the same error

cswnetex commented 1 year ago

I'm having this issue as well, what seems to fix it for me is opening a new incognito chrome session to chat.openai.com and grabbing a new cookie.

It seems to fix the issue for about 30 minutes then the connection breaks again and I get failures when running test_connection.py

GreyDGL commented 1 year ago

I'm also trying to fix this now. Unfortunately, it seems like OpenAI has a stricter restriction on ChatGPT sessions, which makes the "cookie" workaround unstable. Will try to figure it out. For now, please use API for stable connection if possible.

ntwrite commented 1 year ago

I have the same issue, @GreyDGL the cookie updates almost immediately on first request, if you try to use it again it does not work, the curl test gives me: {"message_cap":25,"message_cap_window":180,"message_disclaimer":{"model-switcher":"You've reached the GPT-4 cap, which gives all ChatGPT Plus users a chance to try the model.\n\nPlease check back soon.","textarea":"GPT-4 currently has a cap of 25 messages every 3 hours."}}%

GreyDGL commented 1 year ago

@ntwrite Did you use the latest commit? Could you help me to confirm if you encounter the error, or you're requested to refresh the session (which is a feature in the latest commit)? If it's an error, please attach the error trace here so I can debug.

ntwrite commented 1 year ago

@ntwrite Did you use the latest commit? Could you help me to confirm if you encounter the error, or you're requested to refresh the session (which is a feature in the latest commit)? If it's an error, please attach the error trace here so I can debug.

I have used the latest, and the error trace is exactly the same as the original at the top of this thread, no it is first session so I am pasting the cookie into config

GreyDGL commented 1 year ago

Could you please confirm if the error also happens at the same number of lines? Because after the updates, this issue should be resolved. I'm interested in debugging and please attach screenshot/error trace so that I could help.

ntwrite commented 1 year ago

Ok here's the full trace @GreyDGL,

python3 main.py --reasoning_model=gpt-4                                      ░▒▓ ✔  16:30:46 
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.
> I want to test 192.168.0.1
- Task information generated.

PentestGPT suggests you to do the following:
(None, None)
Traceback (most recent call last):
  File "/Users/user/Documents/pentestgpt/PentestGPT/main.py", line 27, in <module>
    pentestGPTHandler.main()
  File "/Users/user/Documents/pentestgpt/PentestGPT/utils/pentest_gpt.py", line 643, in main
    self.initialize(previous_session_ids=loaded_ids)
  File "/Users/user/Documents/pentestgpt/PentestGPT/utils/pentest_gpt.py", line 221, in initialize
    self._feed_init_prompts()
  File "/Users/user/Documents/pentestgpt/PentestGPT/utils/pentest_gpt.py", line 155, in _feed_init_prompts
    "PentestGPT", "PentestGPT suggests you to do the following: \n" + _response
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
TypeError: can only concatenate str (not "tuple") to str

It does this immediately, there is no processing going on, and I think (but could be wrong) that it is related to expired cookie, session updates cookie on each refresh.

GreyDGL commented 1 year ago

I see. May I know if you tried with python3 test_connection.py? What is the output? The above output shows that the cookie is not correctly implemented. I'll add an Exception handler.

ntwrite commented 1 year ago

I copied the cookie out of the cURL from coversation limits, the cookie is definitely implemented correctly, however, each time i refresh the page the cookie has changed, in cURL test it says this: {"message_cap":25,"message_cap_window":180,"message_disclaimer":{"model-switcher":"You've reached the GPT-4 cap, which gives all ChatGPT Plus users a chance to try the model.\n\nPlease check back soon.","textarea":"GPT-4 currently has a cap of 25 messages every 3 hours."}}%

However the test_connection gives this (I followed YouTube video to make sure i was not being stupid, it is the cookie value from conversation limits):

Test connection for chatgpt cookie

The cookie is not properly configured with ChatGPT Cookie. Please follow README to update cookie in config/chatgpt_config.py

Test connection for OpenAI api (GPT-4)

The OpenAI API key is not properly configured. Please follow README to update OpenAI API key in config/chatgpt_config.py

Test connection for OpenAI api (GPT-3.5)

The OpenAI API key is not properly configured. Please follow README to update OpenAI API key in config/chatgpt_config.py

GreyDGL commented 1 year ago

Emm this is strange. What I typically do is that after testing the cookie working correctly, I'll copy it from the terminal and paste it into Python config directly. Note that during this process, refreshing the ChatGPT page will make the original cookie invalid. Please always use test_connection.py before running main.py to ensure the connection works. May I have your Browser version and OS version for reference? Will try to reproduce the issue first.

ntwrite commented 1 year ago

Out of about the 10 times I tried to get the cookie working correctly, it worked the first time, and then after that I just couldn't get it to work, I did the same process each time.

Sure my user agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 (from the cookie). I may work on an alternative approach to grabbing the cookie and filling it into the conf perhaps some python. I will update here.

AjGaht commented 1 year ago

Thank you, for the help, awaiting any update on the same.

Ununp3ntium115 commented 1 year ago

I get this nice message 3. You're connected with OpenAI API. You have GPT-3.5 access. To start PentestGPT, please use <pentestgpt --reasoning_model=gpt-3.5-turbo --useAPI>

then

Traceback (most recent call last): File "/opt/homebrew/bin/pentestgpt", line 8, in sys.exit(main()) ^^^^^^ File "/opt/homebrew/lib/python3.11/site-packages/pentestgpt/main.py", line 29, in main pentestGPTHandler.main() File "/opt/homebrew/lib/python3.11/site-packages/pentestgpt/utils/pentest_gpt.py", line 643, in main self.initialize(previous_session_ids=loaded_ids) File "/opt/homebrew/lib/python3.11/site-packages/pentestgpt/utils/pentest_gpt.py", line 221, in initialize self._feed_init_prompts() File "/opt/homebrew/lib/python3.11/site-packages/pentestgpt/utils/pentest_gpt.py", line 147, in _feed_init_prompts self.prompts.first_todo + _response


TypeError: can only concatenate str (not "tuple") to str
GirishbKulkarni commented 1 year ago

Getting below error: do we have a solution to this ?

- ChatGPT Sessions Initialized.
Please describe the penetration testing task in one line, including the target IP, task type, etc.
>
- Task information generated.

Traceback (most recent call last):
  File "...\PentestGPT\main.py", line 27, in <module>
    pentestGPTHandler.main()
  File "...\PentestGPT\PENTESTGPT\utils\pentest_gpt.py", line 643, in main
    self.initialize(previous_session_ids=loaded_ids)
  File "...\PentestGPT\PentestGPT\PENTESTGPT\utils\pentest_gpt.py", line 221, in initialize
    self._feed_init_prompts()
  File "...\PentestGPT\PENTESTGPT\utils\pentest_gpt.py", line 147, in _feed_init_prompts
    self.prompts.first_todo + _response
TypeError: can only concatenate str (not "tuple") to str
GreyDGL commented 1 year ago

May I confirm if you're using the latest commit? @GirishbKulkarni

GirishbKulkarni commented 1 year ago

Hello @GreyDGL - Yes I have the latest commit codebase

GreyDGL commented 1 year ago

I found that using the command without "--useAPI" flag causes this issue. Fixing it in the latest commit.