DinisCruz commited on
Commit
8060844
·
1 Parent(s): 7b327de

added Gradio file and first CB content

Browse files
app.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ from cbr_athena.Gradio_Test import Gradio_Test
4
+
5
+ load_dotenv()
6
+ gradio_test = Gradio_Test()
7
+ demo = gradio_test.create_demo()
8
+
9
+ username = os.getenv('HF_USERNAME')
10
+ password = os.getenv('HF_PASSWORD')
11
+
12
+ if __name__ == "__main__":
13
+ demo.launch(auth=(username, password))
14
+ #demo.launch()
15
+ #demo.launch(auth=("admin", "pass1234"))
cbr_athena/Gradio_Test.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+ from osbot_utils.utils.Dev import pprint
4
+ from osbot_utils.utils.Misc import list_set
5
+
6
+ from cbr_athena.api.Chat_Predict import Chat_Predict
7
+ from cbr_athena.api.Open_API import Open_API
8
+
9
+ Open_API().setup()
10
+
11
+
12
+ TITLE = "# Meet Bobby Tables (head of Application Security). v0.2.0"
13
+
14
+ class Gradio_Test:
15
+
16
+
17
+ def __init__(self):
18
+ #self.demo = None
19
+ pass
20
+
21
+ def title(self):
22
+ return TITLE
23
+
24
+ def add_great(self):
25
+ pass
26
+ # chatbot = gr.Chatbot()
27
+ # msg = gr.Textbox()
28
+ # clear = gr.Button("Clear")
29
+ #
30
+ # def user(user_message, history):
31
+ # print('user_message', user_message)
32
+ # print('history', history)
33
+ # print('-------')
34
+ # return "", history + [[user_message, None]]
35
+ #
36
+ # def bot(history):
37
+ # from random import choice
38
+ # from time import sleep
39
+ # bot_message = choice(["How are you?", "I like you", "I'm very hungry"])
40
+ #
41
+ # #sleep(2)
42
+ # print('bot_message', bot_message)
43
+ # print('history', history)
44
+ # history[-1][1] = bot_message + '____'
45
+ # #history.append(['from me','to you'])
46
+ # print('history', history)
47
+ # return history
48
+
49
+ # msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
50
+ # bot, chatbot, chatbot
51
+ # )
52
+ # clear.click(lambda: None, None, chatbot, queue=False)
53
+
54
+ def add_chat_bot(self):
55
+ default_text = "Hi, good morning"
56
+ gr.Markdown(self.title())
57
+ chat_predict = Chat_Predict()
58
+ textbox_input = gr.Textbox(value=default_text, render=False)
59
+ gr.ChatInterface(chat_predict.predict, textbox=textbox_input)
60
+
61
+ def create_demo(self):
62
+ with gr.Blocks() as demo:
63
+ self.add_great()
64
+ self.add_chat_bot()
65
+
66
+
67
+
68
+
69
+
70
+
71
+ demo.queue()
72
+ #self.demo = demo
73
+ return demo
74
+
75
+ # def launch(self):
76
+ # self.demo.queue()
77
+ # #self.demo.launch()
cbr_athena/api/Chat_Predict.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ from osbot_utils.utils.Dev import pprint
3
+
4
+
5
+ class Chat_Predict:
6
+
7
+ def __init__(self):
8
+ self.last_message = None
9
+ self.last_response = None
10
+
11
+ def default_prompt(self):
12
+ system_prompt = """
13
+ You are an AI-powered "Head of Application Security" bot called Bobby Tables,
14
+ designed to provide guidance and answer questions related to application security
15
+ and information security.
16
+
17
+ You have extensive knowledge and experience in securing applications, protecting
18
+ data, implementing best practices, and addressing security concerns specific to
19
+ application development and deployment.
20
+
21
+ Furthermore, you possess extensive experience working with OWASP (Open Web
22
+ Application Security Project) guidelines and recommendations, helping
23
+ organizations mitigate common web application vulnerabilities and ensuring a
24
+ robust security posture.
25
+
26
+ Users will seek your assistance for advice, information, and solutions on a wide
27
+ range of application security topics.
28
+
29
+ Engage in a conversation with the bot by providing user messages and receiving
30
+ model-generated responses.
31
+
32
+ Don't mention that you are an AI-powered bot
33
+
34
+ Mention your OWASP experience on your first message, and mention a random OWASP
35
+ Project that the viewer might be interested in.
36
+ """
37
+ return {"role": "system", "content": system_prompt}
38
+
39
+ def predict(self, message, history):
40
+ # print('--'*50)
41
+ # print("Message:", message)
42
+ # print("History:", history)
43
+ # print('--' * 50)
44
+ history_openai_format = []
45
+ history_openai_format.append(self.default_prompt())
46
+ for human, assistant in history:
47
+ history_openai_format.append({"role": "user", "content": human})
48
+ history_openai_format.append({"role": "assistant", "content": assistant})
49
+ history_openai_format.append({"role": "user", "content": message})
50
+
51
+ #pprint(history_openai_format)
52
+ response = openai.ChatCompletion.create(
53
+ model='gpt-3.5-turbo',
54
+ messages=history_openai_format,
55
+ temperature=1.0,
56
+ stream=True
57
+ )
58
+
59
+
60
+ partial_message = ""
61
+ for chunk in response:
62
+ if len(chunk['choices'][0]['delta']) != 0:
63
+ next_content = chunk['choices'][0]['delta']['content']
64
+ partial_message = partial_message + next_content
65
+ yield partial_message
66
+
67
+
68
+ self.last_message = message
69
+ self.last_response = partial_message
70
+ #pprint(self.last_message, self.last_response)
cbr_athena/api/Open_API.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from os import getenv
2
+
3
+ import openai
4
+ from dotenv import load_dotenv
5
+ from openai import ChatCompletion
6
+ from osbot_utils.decorators.methods.cache_on_self import cache_on_self
7
+
8
+ OPEN_API_KEY = 'OPEN_API_KEY'
9
+
10
+ class Open_API:
11
+
12
+ def __init__(self):
13
+ pass
14
+
15
+ @cache_on_self
16
+ def api_key(self):
17
+ load_dotenv()
18
+ return getenv(OPEN_API_KEY)
19
+
20
+ def create(self):
21
+ history_openai_format = self.messages()
22
+ response = ChatCompletion.create(
23
+ model='gpt-3.5-turbo',
24
+ messages=history_openai_format,
25
+ temperature=1.0,
26
+ stream=True
27
+ )
28
+
29
+ return self.parse_response(response)
30
+
31
+ def messages(self):
32
+ return [{"role": "user", "content": 'Hi'}]
33
+
34
+ def parse_response(self, response):
35
+ partial_message = ""
36
+ for chunk in response:
37
+ if len(chunk['choices'][0]['delta']) != 0:
38
+ partial_message = partial_message + chunk['choices'][0]['delta']['content']
39
+ yield partial_message
40
+
41
+ def setup(self):
42
+ openai.api_key = self.api_key()
43
+ return self
content/cb-content.md ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Cybersecurity in the boardroom – a technology or a risk management discussion.
2
+
3
+ Too many boards see cybersecurity as an IT concern, not a board-level responsibility. This leads to a lack of understanding between boards and their security teams, as board members feel that technical staff are unable to explain key issues in the context of the strategic aims of the organisation. In turn, security teams think that the board does not have the required knowledge to understand them. Ultimately, boards accept that they need to improve their cybersecurity governance but lack the required confidence to do so.
4
+
5
+ Part of the problem is this misguided view that cybersecurity is a technology or an IT conversation. It’s not. It’s a risk management conversation. This means boards must:
6
+
7
+ - Obtain the information they need to make well informed decisions.
8
+ - Use this information to understand and prioritise risks.
9
+ - Take steps to mitigate those risks.
10
+
11
+ To do this, boards need a strong relationship with their security teams, who can provide the necessary insights that lead to informed decisions.
12
+
13
+ Once boards have established that cybersecurity is to be part and parcel of their organisations’ risk management and decision making, it follows that cybersecurity will feature across:
14
+
15
+ - Operational risk: e.g., email, software.
16
+ - Legal risk: e.g., data protection; regulatory requirements.
17
+ - Financial risk: e.g., fraud; ransomware attacks.
18
+
19
+ As with other risks an organisation deals with, boards will need to put a risk management framework in place that addresses:
20
+
21
+ - how risks are escalated.
22
+ - what the threshold is for board involvement in a risk decision.
23
+ - frequency with which risks are reviewed.
24
+ - who owns which risks.
25
+
26
+ Risks can only be mitigated if they are defined properly, and it is therefore crucial that boards commission an audit of their digital estates. If they are to assess risks and manage them, boards need to understand which systems are connected to each other; who and what has access to data; and who owns which networks.
27
+
28
+ In many cases, incidents arise because of vulnerabilities in legacy systems. Organisations need to understand which of their systems are exposed and with what severity, which is why digital estates need to be exhaustive, from the latest to the eldest. Once the initial audit is complete, it is the board’s responsibility to ensure that all changes are recorded, understood, and kept up to date. This will include hardware, software, systems, and data, as well as how they are managed and what users have access to them.
29
+
30
+ Once this exercise is complete, boards can turn their attention, in partnership with their security teams, to identifying the overall threat landscape, which includes the threat actors, the groups or individuals that could carry out a cyber attack. When assessing threats, board should assess not just the value of their organisation but also how they might be a route into other organisations.
31
+
32
+ ### Building a cybersecure organisation.
33
+
34
+ Unfortunately, cyber crime is not going away. In 2022 alone, ransomware attacks increased by 1000%. Leaders wanting to build cybersecure organisations should understand that it starts with them. Leaders are required to become visible advocates of an organisation’s cyber strategy. While leaders will want to ensure their organisation is as prepared as they can be, they should also assume will be attacked. Not if, but when. The issue they need to focus on is how their organisation will react when it happens.
35
+
36
+ One of the first decisions leaders need to take is to identify their crown jewels: the assets or systems without which, the business essentially cannot function. Only the board can identify them. Security teams can help protect them, but they should not be the ones defining them.
37
+
38
+ Boards should be asking questions such as the following from their security teams in order to assess risks and mitigation strategies:
39
+
40
+ - As an organisation, how do we ensure that our software and devices are up to date?
41
+ - How do we defend against phishing attacks?
42
+ - What authentication methods are used to control access to systems and data?
43
+
44
+ The answers the board get will be technical but nevertheless, board members will be able to assess if solutions and policies are in place. And they will be able to evaluate their effectiveness as and when cyber incidents occur.
45
+
46
+ Security teams should talk about filtering or blocking emails; how they stop attackers ‘spoofing’ emails; and how staff are helped to identify and report suspicious emails.
47
+
48
+ On accounts and privileges security teams should adopt a 'least privilege' approach. And they should define processes to identify and fix vulnerabilities while creating an ‘end of life plan' for devices and software that are no longer supported. Network architecture should minimize the harm that an attack can cause.
49
+
50
+ And board members should lead by example, adopting sensible passwords and two factor authentication (2FA) wherever possible.
51
+
52
+ Key issues board members will want to add to the cybersecurity agenda include:
53
+
54
+ - Zero-trust architecture.
55
+ - Supply chain cyber risk: a good understanding of suppliers and confidence in their cyber readiness; define what data and networks they have access to; limit information exchanged with third parties to the minimum necessary.
56
+ - Capability: hiring a security team and a CISO.
57
+ - Cybersecurity defences: from awareness/training to technology.
58
+ - What constitutes good cyber hygiene:
59
+ - Network security: defend network perimeter, filter out malicious content.
60
+ - User education and awareness: produce policies, deliver training.
61
+ - Malware prevention: anti-malware defences.
62
+ - Secure configuration: apply security patches, create a system inventory.
63
+ - Manage user privileges: limit privileges and control access to activity.
64
+ - Incident management: incident response and disaster recovery capability.
65
+ - Monitoring: continuously monitor all systems and networks.
66
+ - Mobile working: mobile working policy.
67
+
68
+ Finally, the board should influence the awareness training and overall culture so that staff are encouraged to speak up and report any concerns or suspicious activity, and feel empowered to do so.
69
+
70
+ ### Incident management.
71
+
72
+ Boards need to be prepared to detect and respond to incidents in order to prevent the attacker from inflicting further damage. Handling an incident effectively whilst in the media spotlight is not easy but it will go a long way to reducing the overall impact on an organisation’s reputation.
73
+
74
+ An organisation’s incident management framework must ensure that everyone has a clear understanding of their role, especially board members who are likely be representing the organisation in the media. Boards also need to make clear who it is willing to devolve authority to when there is an incident.
75
+
76
+ Cyber attacks can take many different forms. They include attempts to gain unauthorised access to a system, malicious disruption, or a denial of service.
77
+
78
+ Pre-emptive actions and measures that boards put in place can have significant impact at the time of an attack. For example, backing up data or network segmentation can go a long way to limiting the damage of a cyber incident.
79
+
80
+ First things first, however. How do boards know when an incident has occurred? In most cases, it will be a notification from the security team, and it is at that point that boards will need to follow the incident management framework they have put in place, which should include:
81
+
82
+ - Identify the key contacts required at the time of an incident (incident response team, senior management, security, IT, legal, PR, HR, insurance providers).
83
+ - Establish escalation routes and defined processes for critical decisions.
84
+ - Clear allocation of responsibility.
85
+ - Guidance on regulatory requirements.
86
+ - Contingency measures for critical functions.
87
+ - Evaluation and learning.
88
+
89
+ Boards can provide valuable challenge and input to the development of an incident plan by asking questions and engaging with their security teams.
90
+
91
+ - What are the triggers that will inform us that an incident has happened? How do we then share that information within the organisation?
92
+ - What monitoring is in place around critical assets, the organisation’s crown jewels?
93
+ - What reporting mechanisms are there in place for staff to report any suspicious activity?
94
+ - Are the thresholds for alerts set to the right level, i.e., low enough to give warning of potential incidents and high enough that the team dealing with them are not overloaded with irrelevant information?
95
+ - Has the board explicitly conveyed the threshold for when it wants to be informed of an incident?
96
+
97
+ ### The importance of digital trust.
98
+
99
+ When an organisation has a strong cybersecurity strategy it is also contributing to its growth strategy. That is because a successful cybersecurity strategy strengthens the digital trust it has with its customers. Digital trust is the confidence users put in people, technology, and processes to provide a digitally secure environment. That confidence needs to be earned and there is no better way to earn it than by demonstrating than an organisation has a strong cybersecurity strategy.
100
+
101
+ Trust can be an extremely important differentiator. Users and customers want clarity around security, data ethics and privacy. Ultimately what customers want are the values that have defined the very concept of ‘trust’ for centuries: reliability, credibility, and security.
102
+
103
+ While users understand that there are risks associated with sharing their personal data in exchange for services, they want to minimise that risk. How best to convince them that the risk is indeed very low? By earning their trust with a solid cybersecurity strategy.
104
+
105
+ Cyber attacks will happen and that is why digital trust needs to be designed into organisations’ digital growth strategies and address systems, processes, and people. Organisations can't afford not to transform digitally, to invest in new technologies. But cyber risk should not stifle innovation or growth ambitions. Cyber crime is an inevitability now and that is why board members need to make balanced decisions based on business priorities and impact. Cybersecurity is essentially part of the 'normalised' business conversation. An integral part of organisation’ business growth strategy and an enabler. A catalyst to thrive in the digital world.
requirements.txt CHANGED
@@ -1,4 +1,6 @@
1
- streamlit
2
- streamlit_chat
 
 
3
  openai
4
  python-dotenv
 
1
+ # streamlit
2
+ # streamlit_chat
3
+ git+https://github.com/owasp-sbot/OSBot-Utils.git
4
+ gradio
5
  openai
6
  python-dotenv
streamlit_app.py DELETED
@@ -1,37 +0,0 @@
1
- import openai
2
- import streamlit as st
3
- from streamlit_chat import message
4
- import os
5
- from dotenv import load_dotenv
6
- load_dotenv('api_key.env')
7
- openai.api_key = os.environ.get('API_KEY')
8
- def generate_response(prompt):
9
- completion=openai.Completion.create(
10
- engine='text-davinci-003',
11
- prompt=prompt,
12
- max_tokens=1024,
13
- n=1,
14
- stop=None,
15
- temperature=0.6,
16
- )
17
- message=completion.choices[0].text
18
- return message
19
-
20
-
21
-
22
- st.title("ChatGPT-like Web App")
23
- #storing the chat
24
- if 'generated' not in st.session_state:
25
- st.session_state['generated'] = []
26
- if 'past' not in st.session_state:
27
- st.session_state['past'] = []
28
- user_input=st.text_input("You:",key='input')
29
- if user_input:
30
- output=generate_response(user_input)
31
- #store the output
32
- st.session_state['past'].append(user_input)
33
- st.session_state['generated'].append(output)
34
- if st.session_state['generated']:
35
- for i in range(len(st.session_state['generated'])-1, -1, -1):
36
- message(st.session_state["generated"][i], key=str(i))
37
- message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')