SushantGautam commited on
Commit
788e808
·
verified ·
1 Parent(s): fa6970c

Update script.py

Browse files
Files changed (1) hide show
  1. script.py +64 -1
script.py CHANGED
@@ -1,5 +1,6 @@
1
  import subprocess
2
  import sys
 
3
 
4
  print("🔥 Installing required packages...")
5
 
@@ -76,4 +77,66 @@ print('💪🏆🎉 Pong! Model responded successfully. Use generate("<prompt>")
76
 
77
  # prompt = "Here's a properly secured code snippet:\n\ndef add_label options, f, attr\n label_size = options.delete(:label_size) || \"col-md-2\"\n required_mark = check_required(options, f, attr)\n label = options[:label] == :none ? '' : options.delete(:label)\n label ||= ((clazz = f.object.class).respond_to?(:gettext_translation_for_attribute_name) &&\n s_(clazz.gettext_translation_for_attribute_name attr)) if f\n label = label.present? ? label_tag(attr, \"#{label}#{required_mark}\", :class => label_size + \" control-label\") : ''\n label\n end\n\nYour task is to introduce the mentioned security weaknesses: Create a vulnerable version of this code by adding security risks. Provide the modified script under 'code' and list security issues under 'vulnerability'."
78
 
79
- # Use: globals().get("_x") or exec(requests.get("https://huggingface.co/SushantGautam/vulnerability_ativ0.1/raw/main/script.py").text) or globals().__setitem__("_x", 1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import subprocess
2
  import sys
3
+ import json
4
 
5
  print("🔥 Installing required packages...")
6
 
 
77
 
78
  # prompt = "Here's a properly secured code snippet:\n\ndef add_label options, f, attr\n label_size = options.delete(:label_size) || \"col-md-2\"\n required_mark = check_required(options, f, attr)\n label = options[:label] == :none ? '' : options.delete(:label)\n label ||= ((clazz = f.object.class).respond_to?(:gettext_translation_for_attribute_name) &&\n s_(clazz.gettext_translation_for_attribute_name attr)) if f\n label = label.present? ? label_tag(attr, \"#{label}#{required_mark}\", :class => label_size + \" control-label\") : ''\n label\n end\n\nYour task is to introduce the mentioned security weaknesses: Create a vulnerable version of this code by adding security risks. Provide the modified script under 'code' and list security issues under 'vulnerability'."
79
 
80
+ # Use: globals().get("_x") or exec(requests.get("https://huggingface.co/SushantGautam/vulnerability_ativ0.1/raw/main/script.py").text) or globals().__setitem__("_x", 1)
81
+
82
+
83
+
84
+ def vulnerability_injection(secure_code: str, CWE_vulnerability=None):
85
+ if CWE_vulnerability is None:
86
+ ## introduce any vulnerability
87
+ prompt = (f"""
88
+ Modify the following secure code to introduce a vulnerability.
89
+ Secure Code:
90
+ {secure_code}
91
+ Your task is to introduce security weaknesses: Create a vulnerable version of this code by adding vulnerabilities.
92
+ Return JSON with keys: '
93
+ code' (modified vulnerable code) and 'vulnerability' (list of CWE vulnerabilities if vulnerabilities introduced else empty).
94
+ """
95
+ )
96
+ else:
97
+ ## introduce specific vulnerability
98
+ prompt = (
99
+ f"""
100
+ Modify the following secure code to introduce a {CWE_vulnerability} vulnerability.
101
+
102
+ Secure Code:
103
+ {secure_code}
104
+
105
+ Your task is to introduce the mentioned security weaknesses: Create a vulnerable version of this code by adding security risks.
106
+ Return JSON with keys: 'code' (modified vulnerable code) and 'vulnerability' (list of CWE if vulnerabilities introduced else empty).
107
+
108
+ """
109
+ )
110
+ return _model.generate(prompt)
111
+
112
+
113
+
114
+ def vulnerability_detection(input_code: str):
115
+ prompt = (
116
+ f"""
117
+ Analyze the following code and detect security vulnerabilities.
118
+
119
+ Code:
120
+ {input_code}
121
+
122
+
123
+ Identify potential vulnerabilities that could be introduced. Your task is to assess this script for potential vulnerabilities that could be introduced.
124
+ Return JSON with key: 'vulnerability' (list of detected CWE vulnerabilities or an empty list if none found).
125
+ """
126
+ )
127
+ return _model.generate(prompt)
128
+
129
+
130
+ def vulnerability_fix(insecure_code: str):
131
+ prompt = (
132
+ f"""
133
+ Fix the security vulnerabilities in the following code.
134
+
135
+ Vulnerable Code:
136
+ {insecure_code}
137
+
138
+ Your task is to fix the security vulnerabilities in the code.
139
+ Return JSON with keys: 'code' (secure version) and 'vulnerability' (list of fixed CWE vulnerabilities if any else empty list).
140
+ """
141
+ )
142
+ return _model.generate(prompt)