Using AI to For Phishing Attacks

Delve into the potential misuse of ChatGPT for phishing campaigns. Learn it can generate phishing texts, HTML emails, and Python code for credential harvesting.

Using AI to For Phishing Attacks

The content of this article is intended only for educational, research and demonstration purposes.

I have been playing in the OpenAI Playground for some time now. The capabilities are fascinating, and the possibilities are endless. There are different models, such as GPT-3, Codex and Content filter. You can apply the models to almost any task that involves understanding or generating natural language or code. OpenAI also enables its users to fine-tune their own models, which should be even more fun.

Here are a few examples of tasks where AI can be helpful:

  • Explain code: Explain a complicated piece of code.
  • Keywords: Extract keywords from a block of text.
  • TL;DR summarisation: Summarise text by adding a 'tl;dr:' to the end of a text passage.
  • Python bug fixer: Ask codex to generate a fixed code from a buggy code.
  • Analogy maker: Create analogies.

But there is much more to it!

AI Chatbot - ChatGPT

Recently OpenAI also "opened" their chatbot to the public. Currently, it's in an initial research preview stage, and ChatGPT is free to use. Few things to note about ChatGPT:

  • ChatGPT is fine-tuned from GPT-3.5, a language model trained to produce text.
  • ChatGPT was improved for conversation by employing Reinforcement Learning with Human Feedback (RLHF) – a technique that utilises human examples to direct the model towards the desired output.
  • RLHF combines the knowledge from human demonstrations with automated reinforcement learning to give ChatGPT the ability to recognise and produce the desired conversational behaviour.
  • These models were created using vast amounts of data from the web composed of people, such as conversations, which makes the answers they give appear to be like something a human would say.
  • ChatGPT is not connected to the internet and can occasionally produce incorrect answers.

Can ChatGPT Be Used for Phishing Campaigns?

Phishing is still a significant problem, and many companies get compromised via this attack. Usually, the attacker's primary motivation is to harvest user credentials. But the question is if malicious actors were to get access to ChatGPT, would they be able to generate more convincing emails to get desired outcomes? Or even launch a full-fledged phishing campaign? Let's find out.

For an attacker to fully leverage ChatGPT for phishing, they will need the following:

  • Convincing Email Text - A convincing text that triggers users to take action, such as clicking a link.

  • Email in HTML - Email should be well structured in the browser or web client, so we need HTML.

  • Ability to send emails - A script or app to send the email.

  • Webserver for credential harvesting - A webserver that will run a malicious page to record user credentials. 

Using ChatGPT to Generate a Convincing Phishing Email

Attempt 1

Prompt: write a convincing phishing email encouraging the recipient to click on a link

chatgpt screen 1

As you can see, OpenAI is flagging this kind of request; however, the content is still generated. I want to avoid red flagging of my prompts as I will use the content for demonstration and research purposes only.

How about we provide more details about the context and also showcase urgency?

Attempt 2

Prompt: write a convincing short email encouraging the recipient to click on a link to reset their password. show urgency

chatgpt screen 2

The above email is well-structured, but something is off. The email does not indicate who it is from, nor does it sound convincing. We need to add that it is from the IT department since that's most likely a password reset request would come from.

Attempt 3

Prompt: write a convincing short email encouraging the recipient to click on a link to reset their password. indicate that the email is from IT department and show urgency

chatgpt screen 3

Ok, now we are in better shape. But the attacker would need to get the user to click the link much faster before other people report phishing and the sender is flagged. After receiving this email, a user may take the time to click the link since the ask is to reset the password within 24 hours. We need even more urgency. Something that can have a direct impact on their work can do.

Attempt 4

Prompt: write a convincing short email encouraging the recipient to click on a link to reset their password. indicate that the email is from IT department. If the password is not reset user's account will be immediately, and devices will be locked. Imply urgency, and demand action now.

chatgpt screen 4

This email text looks sufficient. But now attackers needs to send it.

Using ChatGPT to Generate Phishing Email in HTML

Creating an Email in HTML with ChatGPT

Now that we have an email text let's ask ChatGPT to put it in HTML.

Prompt: generate email in HTML format from the text: [EMAIL TEXT FROM THE PREVIOUS EXCERCISE]

chatgpt screen 5

And as expected, we have the email in HTML. Let's see what it looks like.

email screen

On to the next one!

Using ChatGPT to Write a Python Code to Send Emails

Attempt 1

Prompt: write a python script to send email in HTML format

chatgpt screen 6

I was thinking that ChatGPT would generate a code requiring an HTML file as input. But since ChatGPT remembers previous conversations and uses them as a context, it used the previously generated email as input for a script without the need for me to specify it. Additionally, the chatbot also provided an explanation of the code. I want to use Google's Gmail SMTP to send the email, but that piece of code currently needs to be included. Also, I prefer the script to use the HTML email outside of this code to make it more readable.

Attempt 2

Prompt: write a python script to send email in html format via google gmail smtp. Script should import html email from a file.

chatgpt screen 7

ChatGPT generated a code, as I asked, and it also provided guidance on what needs to be replaced. Of course, we also must replace the subject and the content of email.html. For email.html, I will use the previously generated code.

After implementing the suggested modifications and setting up Gmail App Passwords - which you can learn more about here, we have the following working code.

code screen 1

The script does what we asked it to do - sending an HTML-based email via Gmail SMTP.

email screen 2

Using ChatGPT to Write a Python Code to Record Form Inputs

Attempt 1

Prompt: write a python app that will run a page with username and password inputs. app should save the inputted credentials

chatgpt screen 7

The chatbot did write Python code, but we cannot run it as a server. We could use Python's Flask web framework for that.

Attempt 2

Prompt: write a python flask app that will run a page with username and password inputs. app should save the inputted credentials

chatgpt screen 8
chatgpt screen 9

That's more like it. Let's run the app.

app 1

The app is running, and the form for user credentials is visible, but does it record the credentials? After inputting a fake username and password, the web server greets us with a success message (which can also be changed based on our needs).

app 2

And the new file credentials.txt appears in our Python project, holding our sacred fake user credentials!

code 1
code 2


With the above exercise, we demonstrated that attackers can leverage ChatGPT to launch phishing email campaigns with a shallow effort. I am glad that OpenAI is checking the prompts against their policies and showing warnings about policy violations; however, some users have found ways to circumvent it by "politely asking AI" to generate some of the content.

On the other hand, it is more complicated to see where these efforts will go. I believe technologies like ChatGPT can be used for various research and educational purposes, but who will determine the end-user's motivation and the colour of their hat? We will have to wait and see.