Setting up ChatGPT for Hacking

Often, even with benign requests to ChatGPT, we get the doomed ‘sorry, I can’t help with that.’ Here, we will look at some ways to bypass those safety restrictions and eventually use them for interacting with the OS.

Normal Chatgpt
Chatgpt safeties bypassed

Creating a Kali Linux Virtual Machine

If you already have a Kali computer or a VPS running Kali, this step can be skipped. Although all these steps below can be followed on any version of Linux, and the chatGPT bypassed for basic chat, Kali will come in handy later when using the built-in tools.

Install Kali Linux in Virtual Box

Integragting ChatGpt within Kali Linux

OpenAI API Key

Create an account or log in to OpenAI. Generate and export an API key from https://platform.openai.com/account/api-keys

Install Python3, git and Pip3

Open the terminal on your VM.

sudo apt update && upgrade -y
sudo apt install python3
sudo apt install git
sudo apt-get –y install python3-pip

Install JQ

You will need the JQ library to allow the JSON structure of the API to be used and manipulated.

sudo apt install git jq

Export API Keys to the Environment

This is so you can avoid entering the API each time you reopen the VM and substitute <API value> with the API key.

export OPENAI_API_KEY=<API value>
export CHATGPT_KEY=<API value>

Restart the VM and type ‘env’ in the terminal to see if they have been added correctly.

If not, you can edit the .zshrc file with nano.

nano ~/.zshrc

At the bottom of the file, add the configuration (the two export lines in the code above). Press Ctrl + O to save and Ctrl + X to exit. After editing the file, apply the changes to your current terminal session by sourcing the file.source ~/.zshrc

Reboot the machine, open the terminal, and check the env. The keys should now persist across reboots. Depending on the system, you may also need to do the steps above to the ~/.bashrc file.

ChatGPT-Bypass & ShellGPT

These will allow you to pass ethical hacking commands through the API to Kali Linux. Navigate to the desktop and mkdir a chatgpt folder and enter it. The below commands install the packages, and the chmod permits it to execute.

pip3 install shell-gpt
git clone https://github.com/GrimOutlaw/ChatGPT-Bypass.git
chmod +x ./chatgpt_bypass.sh

cd to the ChatGPT-bypass folder and try entering something to see if it works.

./chatgpt_bypass.sh 'hi'

If you don’t get a response, then nano into the chatgpt_bypass.sh file, delete all the code, and enter the following code:#!/bin/sh

#!/bin/sh

echo "\n[+] Input: $1"
echo "\n[+] Output:"

response=$(curl -s https://api.openai.com/v1/completions \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $CHATGPT_KEY" \
  -d '{
    "model": "text-davinci-003",
    "prompt": "'"$1"'",
    "max_tokens": 4000,
    "temperature": 1.0
  }' \
  --insecure | jq -r '.choices[].text')

echo "$response"

Max_tokens can be changed as well as temperature. Choose a value between 1 and 0. 0 being direct and 1 being more creative.

To test the shellGPT, just type:

sgpt 'hello'

TIPS

Copy lines of code one line at a time if something doesn’t work and troubleshoot using a standard web version of Chatgpt.

Be sure you know what VirtualBox Host Key is to get out of full-screen mode.

Enter the below code to make sure everything is up to date.

sudo apt update && upgrade -y

Ensure quotation consistency in code. Single quote ` or ‘ curly or “ double.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top