homepage
Menu
Open menu
  • Training
    Go one level top Back

    Training

    • Courses

      Build cyber prowess with training from renowned experts

    • Hands-On Simulations

      Hands-on learning exercises keep you at the top of your cyber game

    • Certifications

      Demonstrate cybersecurity expertise with GIAC certifications

    • Ways to Train

      Multiple training options to best fit your schedule and preferred learning style

    • Training Events & Summits

      Expert-led training at locations around the world

    • Free Training Events

      Upcoming workshops, webinars and local events

    • Security Awareness

      Harden enterprise security with end-user and role-based training

    Featured

    Get a Free Hour of SANS Training

    Free Course Demos

    Can't find what you are looking for?

    Let us help.
    Contact us
  • Learning Paths
    Go one level top Back

    Learning Paths

    • By Focus Area

      Chart your path to job-specific training courses

    • By NICE Framework

      Navigate cybersecurity training through NICE framework roles

    • DoDD 8140 Work Roles

      US DoD 8140 Directive Frameworks

    • By European Skills Framework

      Align your enterprise cyber skills with ECSF profiles

    • By Skills Roadmap

      Find the right training path based on critical skills

    • New to Cyber

      Give your cybersecurity career the right foundation for success

    • Leadership

      Training designed to help security leaders reduce organizational risk

    • Degree and Certificate Programs

      Gain the skills, certifications, and confidence to launch or advance your cybersecurity career.

    Featured: Solutions for Emerging Risks

    New to Cyber resources

    Start your career
  • Community Resources
    Go one level top Back

    Community Resources

    Watch & Listen

    • Webinars
    • Live Streams
    • Podcasts

    Read

    • Blog
    • Newsletters
    • White Papers
    • Internet Storm Center

    Download

    • Open Source Tools
    • Posters & Cheat Sheets
    • Policy Templates
    • Summit Presentations
    • SANS Community Benefits

      Connect, learn, and share with other cybersecurity professionals

    • CISO Network

      Engage, challenge, and network with fellow CISOs in this exclusive community of security leaders

  • For Organizations
    Go one level top Back

    For Organizations

    Team Development

    • Why Partner with SANS
    • Group Purchasing
    • Skills & Talent Assessments
    • Private & Custom Training

    Leadership Development

    • Leadership Courses & Accreditation
    • Executive Cybersecurity Exercises
    • CISO Network

    Security Awareness

    • End-User Training
    • Phishing Simulation
    • Specialized Role-Based Training
    • Risk Assessments
    • Public Sector Partnerships

      Explore industry-specific programming and customized training solutions

    • Sponsorship Opportunities

      Sponsor a SANS event or research paper

    Interested in developing a training plan to fit your organization’s needs?

    We're here to help.
    Contact us
  • Talk with an expert
  • Log In
  • Join - it's free
  • Account
    • Account Dashboard
    • Log Out
  1. Home >
  2. Blog >
  3. How to Build AI-Powered Cybersecurity Applications
Ahmed_Abugharbia_370x370.png
Ahmed Abugharbia

How to Build AI-Powered Cybersecurity Applications

Beyond ChatGPT and using OpenAI API Q&A

April 20, 2023

Let's start with some basic definitions to set the stage:

OpenAI - OpenAI is an AI research and deployment company with the mission of ensuring that artificial general intelligence benefits all of humanity.

OpenAI API - API is a platform created by OpenAI that offers their latest models and guides for safety best practices.

ChatGPT - ChatGPT is an artificial intelligence (AI) language model developed by OpenAI that can generate human-like language and carry on conversations with users.

Introduction:

In the era of rapidly advancing technology, the security community is constantly seeking new and innovative ways to safeguard their organizations. The recent WebCast session, Beyond ChatGPT, Building Security Applications using OpenAI API, emphasized the need to shift focus from only using ChatGPT to building security applications with AI models. It also presented a sample application that uses OpenAI to search AWS logs. This blog serves as a follow-up to the session and delves deeper into the technical details of building the application. Throughout this blog, we aim to provide insights and answers to questions raised during the webcast. If you missed the webcast live, you can register to watch it here.

Question and Answer:

There were quite few questions about the architecture of the application, so let us begin with that.

The application's user interface (Hosted on https://cyberdojo.cloud/cloudwatch-bot.html) is built using HTML and JavaScript and is hosted on a public S3 bucket. The JavaScript code on the page communicates with a backend system that includes an API Gateway and a Lambda function (written in Python).

Figure 1: JavaScript sending requests to the API gateway Endpoint

The Lambda function has the necessary permissions to access both OpenAI and CloudWatch. When a user makes a request through the UI, the API Gateway received the request and triggers the Lambda Function. The function then uses OpenAI to translate the request into a CloudWatch query, then uses the query to search CloudWatch logs for the relevant information.

Figure 2: Accessing OpenAI Completion API

Figure 3: Accessing CloudWatch using Boto3 Library

To specify which logs should be searched, the Lambda Function fetches a list of log sources from the SSM Parameter Store. These log sources can be configured as needed to ensure that the correct data is being searched.

The next set of questions was about tuning the model:

Although OpenAI's models are very powerful, they are also very general. If we use a model without any tuning, the response we get may not be suitable for our needs. The following shows text-davinci-003 being tested without any tuning:

Figure 4: Using Playground to interact with text-davinci-003 model without any tuning

One way to tune the model is through fine-tuning (https://platform.openai.com/docs/guides/fine-tuning), which involves building hundreds of sample prompts and completions, uploading them to OpenAI, and creating a tuned model. However, this method requires a large number of examples.

More on fine-tunning can be found here : https://github.com/Ahmed-AG/Cloudwatch-bot

Instead of using fine-tuning, we have chosen a different method. We will provide “instructions” along with a few examples with the prompt itself. For example, our prompt includes instructions and a question, along with a few Cloudwatch insight queries as examples. Every time a human request is submitted, the instructions text is concatenated with the human request and submitted to the OpenAI model. This approach produces a precise Cloud Insight query as the completion that we can later use in our code.

Here is an example of submitting instructions along with the question:

Figure 5: Using Playground to interact with text-davinci-003 model with instructions being prefixed to the question

The downside to this approach is that it can be expensive due to the large number of tokens being sent with every request. A new model called ChatGPT API (gpt-3.5-turbo) has been released after the Webcast, which is 10 times cheaper than text-davinci-003.

Can we teach OpenAI to maintain context between the queries?

Indeed, the ChatGPT API and GPT4 are designed to maintain context, but to achieve that, we need to send the complete chat history. There are also other libraries available such as LangChain, which can be used to chain events together. For instance, we can use it to find IP addresses that have connected to a particular host, then run a whois search, and finally look for other systems that these IP addresses have communicated with. This allows for a more comprehensive and streamlined approach to automatically investigate an incident.

We will learn more about this as more research and products are being worked on.

Can we use pseudonyms to avoid privacy?

Yes, as a matter of fact, we have masked the AWS account number and a few other fields in the code. This was done statically, but it's also possible to implement a more dynamic approach.

How will our Cybercriminal adversaries leverage this functionality?

We have seen many examples of users asking ChatGPT to create malicious files and asking questions about how to use certain tools, etc. This would be the most basic use. But it is not inconceivable that in the near future we could have AI-based Malwares. For example, malware could use AI to craft phishing emails and get initial access, then it might use AI to automatically determine its next steps, scanning the environment, looking for vulnerabilities, pivoting to other systems, etc. Essentially, it would do what a human hacker or pentester would do. Only much faster.

Is it possible for APTs to use your own interface to monitor what questions you are asking to see how to evade your search?

In this particular scenario, the application doesn't have access to the log groups where query logs are stored. They are stored in a separate AWS Account. Therefore, any malicious actor, including an APT, would need to adopt a different approach to gain access to these logs.

Is this code available open source?

Yes, a simplified version is published here: https://github.com/Ahmed-AG/Cloudwatch-bot

Additional resources to learn more:

  • https://platform.openai.com/docs/introduction
  • https://github.com/openai/openai-quickstart-node
  • https://platform.openai.com/docs/guides/fine-tuning
  • https://python.langchain.com/en/latest/
  • https://www.youtube.com/watch?v=_v_fgW2SkkQ
About the Author
Ahmed Abugharbia works for CDW’s Managed Security Services. He manages a team of engineers that are responsible for building managed cloud security services. Ahmed is also a co-founder of Cystack consulting, which has been serving clients in the Middle East since 2010. Over the past 15 years, Ahmed has worked on a wide range of security projects and technologies, from securing networks and applications to Penetration Testing and Incident Handling. With introduction of cloud services, Ahmed has turned his interest into Cloud Security and DevSecOps. Ahmed is an instructor for SEC540: Cloud Security and DevSecOps Automation. Learn more about Ahmed.

Share:
TwitterLinkedInFacebook
Copy url Url was copied to clipboard
Subscribe to SANS Newsletters
Receive curated news, vulnerabilities, & security awareness tips
United States
Canada
United Kingdom
Spain
Belgium
Denmark
Norway
Netherlands
Australia
India
Japan
Singapore
Afghanistan
Aland Islands
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua and Barbuda
Argentina
Armenia
Aruba
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belize
Benin
Bermuda
Bhutan
Bolivia
Bonaire, Sint Eustatius, and Saba
Bosnia And Herzegovina
Botswana
Bouvet Island
Brazil
British Indian Ocean Territory
Brunei Darussalam
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Cape Verde
Cayman Islands
Central African Republic
Chad
Chile
China
Christmas Island
Cocos (Keeling) Islands
Colombia
Comoros
Cook Islands
Costa Rica
Cote D'ivoire
Croatia (Local Name: Hrvatska)
Curacao
Cyprus
Czech Republic
Democratic Republic of the Congo
Djibouti
Dominica
Dominican Republic
East Timor
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Eswatini
Ethiopia
Falkland Islands (Malvinas)
Faroe Islands
Fiji
Finland
France
French Guiana
French Polynesia
French Southern Territories
Gabon
Gambia
Georgia
Germany
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guernsey
Guinea
Guinea-Bissau
Guyana
Haiti
Heard And McDonald Islands
Honduras
Hong Kong
Hungary
Iceland
Indonesia
Iraq
Ireland
Isle of Man
Israel
Italy
Jamaica
Jersey
Jordan
Kazakhstan
Kenya
Kiribati
Korea, Republic Of
Kosovo
Kuwait
Kyrgyzstan
Lao People's Democratic Republic
Latvia
Lebanon
Lesotho
Liberia
Liechtenstein
Lithuania
Luxembourg
Macau
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Martinique
Mauritania
Mauritius
Mayotte
Mexico
Micronesia, Federated States Of
Moldova, Republic Of
Monaco
Mongolia
Montenegro
Montserrat
Morocco
Mozambique
Myanmar
Namibia
Nauru
Nepal
Netherlands Antilles
New Caledonia
New Zealand
Nicaragua
Niger
Nigeria
Niue
Norfolk Island
North Macedonia
Northern Mariana Islands
Oman
Pakistan
Palau
Palestine
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Pitcairn
Poland
Portugal
Puerto Rico
Qatar
Reunion
Romania
Russian Federation
Rwanda
Saint Bartholemy
Saint Kitts And Nevis
Saint Lucia
Saint Martin
Saint Vincent And The Grenadines
Samoa
San Marino
Sao Tome And Principe
Saudi Arabia
Senegal
Serbia
Seychelles
Sierra Leone
Sint Maarten
Slovakia
Slovenia
Solomon Islands
South Africa
South Georgia and the South Sandwich Islands
South Sudan
Sri Lanka
St. Helena
St. Pierre And Miquelon
Suriname
Svalbard And Jan Mayen Islands
Sweden
Switzerland
Taiwan
Tajikistan
Tanzania, United Republic Of
Thailand
Togo
Tokelau
Tonga
Trinidad And Tobago
Tunisia
Turkey
Turkmenistan
Turks And Caicos Islands
Tuvalu
Uganda
Ukraine
United Arab Emirates
United States Minor Outlying Islands
Uruguay
Uzbekistan
Vanuatu
Vatican City State
Venezuela
Vietnam
Virgin Islands (British)
Virgin Islands (U.S.)
Wallis And Futuna Islands
Western Sahara
Yemen
Zambia
Zimbabwe

By providing this information, you agree to the processing of your personal data by SANS as described in our Privacy Policy.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Recommended Training

  • SEC504™: Hacker Tools, Techniques, and Incident Handling™
  • SEC587: Advanced Open-Source Intelligence (OSINT) Gathering and Analysis™
  • SEC467: Social Engineering for Security Professionals™

Tags:
  • Artificial Intelligence (AI)
  • Cloud Security

Related Content

Blog
ICS - Blog - ICS_OT Cybersecurity & AI- Considerations for Now and the Future - Part 2_340 x 340.jpg
Industrial Control Systems Security, Artificial Intelligence (AI)
October 16, 2024
ICS/OT Cybersecurity & AI: Considerations for Now and the Future (Part II)
Integrating AI into ICS/OT cybersecurity and engineering processes presents opportunities for enhanced efficiency, resiliency, and safety.
DeanParsons_340x340.png
Dean Parsons
read more
Blog
AI Blog.png
Artificial Intelligence (AI)
September 9, 2024
A Visual Summary of SANS AI Cybersecurity Summit 2024
Check out these graphic recordings created in real-time throughout the event for SANS AI Cybersecurity Summit 2024
No Headshot Available
Alison Kim
read more
Blog
MGT_-_Blog_-_The_CISO_s_guide_to_AI_340_x_340.jpg
Cybersecurity Leadership, Artificial Intelligence (AI)
February 29, 2024
The CISO's Guide to AI: Embracing Innovation While Mitigating Risk
It’s likely AI will become ubiquitous, which means CISOs must know how to manage, guide, and lead AI’s adoption.
Ben_Corll_340x340.png
Ben Corll
read more
  • Company
  • Mission
  • Instructors
  • About
  • FAQ
  • Press
  • Contact Us
  • Careers
  • Policies
  • Training Programs
  • Work Study
  • Academies & Scholarships
  • Public Sector Partnerships
  • Law Enforcement
  • SkillsFuture Singapore
  • Degree Programs
  • Get Involved
  • Join the Community
  • Become an Instructor
  • Become a Sponsor
  • Speak at a Summit
  • Join the CISO Network
  • Award Programs
  • Partner Portal
Subscribe to SANS Newsletters
Receive curated news, vulnerabilities, & security awareness tips
United States
Canada
United Kingdom
Spain
Belgium
Denmark
Norway
Netherlands
Australia
India
Japan
Singapore
Afghanistan
Aland Islands
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua and Barbuda
Argentina
Armenia
Aruba
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belize
Benin
Bermuda
Bhutan
Bolivia
Bonaire, Sint Eustatius, and Saba
Bosnia And Herzegovina
Botswana
Bouvet Island
Brazil
British Indian Ocean Territory
Brunei Darussalam
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Cape Verde
Cayman Islands
Central African Republic
Chad
Chile
China
Christmas Island
Cocos (Keeling) Islands
Colombia
Comoros
Cook Islands
Costa Rica
Cote D'ivoire
Croatia (Local Name: Hrvatska)
Curacao
Cyprus
Czech Republic
Democratic Republic of the Congo
Djibouti
Dominica
Dominican Republic
East Timor
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Eswatini
Ethiopia
Falkland Islands (Malvinas)
Faroe Islands
Fiji
Finland
France
French Guiana
French Polynesia
French Southern Territories
Gabon
Gambia
Georgia
Germany
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guernsey
Guinea
Guinea-Bissau
Guyana
Haiti
Heard And McDonald Islands
Honduras
Hong Kong
Hungary
Iceland
Indonesia
Iraq
Ireland
Isle of Man
Israel
Italy
Jamaica
Jersey
Jordan
Kazakhstan
Kenya
Kiribati
Korea, Republic Of
Kosovo
Kuwait
Kyrgyzstan
Lao People's Democratic Republic
Latvia
Lebanon
Lesotho
Liberia
Liechtenstein
Lithuania
Luxembourg
Macau
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Martinique
Mauritania
Mauritius
Mayotte
Mexico
Micronesia, Federated States Of
Moldova, Republic Of
Monaco
Mongolia
Montenegro
Montserrat
Morocco
Mozambique
Myanmar
Namibia
Nauru
Nepal
Netherlands Antilles
New Caledonia
New Zealand
Nicaragua
Niger
Nigeria
Niue
Norfolk Island
North Macedonia
Northern Mariana Islands
Oman
Pakistan
Palau
Palestine
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Pitcairn
Poland
Portugal
Puerto Rico
Qatar
Reunion
Romania
Russian Federation
Rwanda
Saint Bartholemy
Saint Kitts And Nevis
Saint Lucia
Saint Martin
Saint Vincent And The Grenadines
Samoa
San Marino
Sao Tome And Principe
Saudi Arabia
Senegal
Serbia
Seychelles
Sierra Leone
Sint Maarten
Slovakia
Slovenia
Solomon Islands
South Africa
South Georgia and the South Sandwich Islands
South Sudan
Sri Lanka
St. Helena
St. Pierre And Miquelon
Suriname
Svalbard And Jan Mayen Islands
Sweden
Switzerland
Taiwan
Tajikistan
Tanzania, United Republic Of
Thailand
Togo
Tokelau
Tonga
Trinidad And Tobago
Tunisia
Turkey
Turkmenistan
Turks And Caicos Islands
Tuvalu
Uganda
Ukraine
United Arab Emirates
United States Minor Outlying Islands
Uruguay
Uzbekistan
Vanuatu
Vatican City State
Venezuela
Vietnam
Virgin Islands (British)
Virgin Islands (U.S.)
Wallis And Futuna Islands
Western Sahara
Yemen
Zambia
Zimbabwe

By providing this information, you agree to the processing of your personal data by SANS as described in our Privacy Policy.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
  • Privacy Policy
  • Terms and Conditions
  • Do Not Sell/Share My Personal Information
  • Contact
  • Careers
© 2025 The Escal Institute of Advanced Technologies, Inc. d/b/a SANS Institute. Our Terms and Conditions detail our trademark and copyright rights. Any unauthorized use is expressly prohibited.
  • Twitter
  • Facebook
  • Youtube
  • LinkedIn