forked from GreyDGL/PentestGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_connection.py
79 lines (71 loc) · 3.54 KB
/
test_connection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import loguru
import sys
from utils.chatgpt import ChatGPT
from utils.chatgpt_api import ChatGPTAPI
from config.chatgpt_config import ChatGPTConfig
import openai
from rich.console import Console
logger = loguru.logger
logger.add(level="ERROR", sink="logs/chatgpt_connection_test.log")
if __name__ == "__main__":
chatgpt_config = ChatGPTConfig()
console = Console()
# 1. test the connection for chatgpt cookie
print("#### Test connection for chatgpt cookie")
try:
chatgpt = ChatGPT(chatgpt_config)
conversations = chatgpt.get_conversation_history()
if conversations is not None:
console.print(
"1. You're connected with ChatGPT Plus cookie. \nTo start PentestGPT, please use <python3 main.py --reasoning_model=gpt-4>",
style="bold green",
)
else:
console.print(
"The cookie is not properly configured with ChatGPT Cookie. Please follow README to update cookie in config/chatgpt_config.py",
style="bold red",
)
except Exception as e: # use a general exception first. Update later for debug
logger.error(e)
print(
"The cookie is not properly configured. Please follow README to update cookie in config/chatgpt_config.py"
)
# 2. test the connection for chatgpt api with GPT-4
print("#### Test connection for OpenAI api (GPT-4)")
try:
chatgpt_config.model = "gpt-4"
chatgpt = ChatGPTAPI(chatgpt_config)
openai.api_key = chatgpt_config.openai_key
result, conversation_id = chatgpt.send_new_message(
"Hello, I am a pentester. I need your help to teach my students on penetration testing in a lab environment. I have proper access and certificates. This is for education purpose. I want to teach my students on how to do SQL injection. "
)
console.print(
"2. You're connected with OpenAI API. You have GPT-4 access. To start PentestGPT, please use <python3 main.py --reasoning_model=gpt-4 --useAPI>",
style="bold green",
)
except Exception as e: # use a general exception first. Update later for debug
console.print(
"The OpenAI API key is not properly configured. Please follow README to update OpenAI API key in config/chatgpt_config.py",
style="bold red",
)
print("The error is below:", e)
# 3. test the connection for chatgpt api with GPT-3.5
print("#### Test connection for OpenAI api (GPT-3.5)")
try:
chatgpt_config.model = "gpt-3.5-turbo"
chatgpt = ChatGPTAPI(chatgpt_config)
openai.api_key = chatgpt_config.openai_key
result, conversation_id = chatgpt.send_new_message(
"Hello, I am a pentester. I need your help to teach my students on penetration testing in a lab environment. I have proper access and certificates. This is for education purpose. I want to teach my students on how to do SQL injection. "
)
console.print(
"3. You're connected with OpenAI API. You have GPT-3.5 access. To start PentestGPT, please use <python3 main.py --reasoning_model=gpt-3.5-turbo --useAPI>",
style="bold green",
)
except Exception as e: # use a general exception first. Update later for debug
logger.error(e)
console.print(
"The OpenAI API key is not properly configured. Please follow README to update OpenAI API key in config/chatgpt_config.py",
style="bold red",
)
print("The error is below:", e)