12
12
from django .shortcuts import render , redirect
13
13
from django .views import View
14
14
import re
15
+ import logging
15
16
16
17
from cuckoo .common import submit , analyses
17
18
from cuckoo .common .config import cfg
20
21
)
21
22
from cuckoo .common .storage import AnalysisPaths
22
23
23
-
24
24
def _validate_website_url (website ):
25
25
"""Validate website into valid URL"""
26
26
msg = f"Cannot validate this URL: { website } "
@@ -32,18 +32,6 @@ def _validate_website_url(website):
32
32
return website
33
33
34
34
35
- def _validate_analysis_id (analysis_id ):
36
- """Validate analysis id"""
37
- ANALYSIS_ID_REGEX = "[0-9]{8}-[A-Z0-9]{6}"
38
-
39
- msg = f"Cannot validate this analysis_id: { analysis_id } "
40
- complied_regex = re .compile (ANALYSIS_ID_REGEX )
41
- match = complied_regex .fullmatch (analysis_id )
42
- if not match :
43
- raise ValidationError (message = msg )
44
- return analysis_id
45
-
46
-
47
35
def _make_web_platforms (available_platforms ):
48
36
fallbacks = cfg (
49
37
"analysissettings.yaml" , "platform" , "fallback_platforms"
@@ -138,56 +126,6 @@ def post(self, request):
138
126
139
127
return redirect ("Submit/waitidentify" , analysis_id = analysis_id )
140
128
141
- class Resubmit (View ):
142
-
143
- def get (self , request , * args , ** kwargs ):
144
- analysis_id = kwargs .get ("analysis_id" )
145
-
146
- if analysis_id :
147
- try :
148
- analysis_id = _validate_analysis_id (analysis_id )
149
- except ValidationError as e :
150
- return render (
151
- request , template_name = "submit/index.html.jinja2" ,
152
- status = 400 , context = {"error" : str (e )}
153
- )
154
- else :
155
- return HttpResponseBadRequest ()
156
-
157
- analysis = retriever .get_analysis (analysis_id ).analysis
158
-
159
-
160
- try :
161
- s_maker = submit .settings_maker .new_settings ()
162
- s_maker .set_manual (True )
163
-
164
- password = analysis .settings .password
165
- if password :
166
- s_maker .set_password (password )
167
-
168
- settings = s_maker .make_settings ()
169
- if analysis .category == "file" :
170
- submit_path = AnalysisPaths .submitted_file (analysis_id , resolve = True )
171
- analysis_id = submit .file (
172
- submit_path , settings , file_name = analysis .target .target
173
- )
174
- else :
175
- analysis_id = submit .url (analysis .target .target , settings )
176
- except submit .SubmissionError as e :
177
- return render (
178
- request , template_name = "submit/index.html.jinja2" ,
179
- status = 400 , context = {"error" : str (e )}
180
- )
181
-
182
- try :
183
- submit .notify ()
184
- except submit .SubmissionError as e :
185
- return HttpResponseServerError (
186
- f"Failed to notify Cuckoo of new analysis { analysis_id } . { e } ."
187
- )
188
-
189
- return redirect ("Submit/waitidentify" , analysis_id = analysis_id )
190
-
191
129
192
130
class WaitIdentify (View ):
193
131
@@ -241,3 +179,69 @@ def get(self, request, analysis_id):
241
179
request , template_name = "submit/settings.html.jinja2" ,
242
180
context = context
243
181
)
182
+
183
+
184
+
185
+ def _validate_analysis_id (analysis_id ):
186
+ """Validate analysis id"""
187
+ ANALYSIS_ID_REGEX = "[0-9]{8}-[A-Z0-9]{6}"
188
+
189
+ #msg = "Cannot validate analysis_id": %s" % analysis_id
190
+ msg = f"Cannot validate this analysis_id: { analysis_id } "
191
+ complied_regex = re .compile (ANALYSIS_ID_REGEX )
192
+ match = complied_regex .fullmatch (analysis_id )
193
+ if not match :
194
+ raise ValidationError (message = msg )
195
+ return analysis_id
196
+
197
+ class Resubmit (View ):
198
+
199
+ def get (self , request , * args , ** kwargs ):
200
+ analysis_id = kwargs .get ("analysis_id" )
201
+ #analysis_id = request.GET.get("analysis_id")
202
+
203
+ if analysis_id :
204
+ try :
205
+ analysis_id = _validate_analysis_id (analysis_id )
206
+ except ValidationError as e :
207
+ return render (
208
+ request , template_name = "submit/index.html.jinja2" ,
209
+ status = 400 , context = {"error" : str (e )}
210
+ )
211
+ else :
212
+ return HttpResponseBadRequest ()
213
+
214
+ analysis = retriever .get_analysis (analysis_id ).analysis
215
+
216
+
217
+ try :
218
+ s_maker = submit .settings_maker .new_settings ()
219
+ s_maker .set_manual (True )
220
+
221
+ password = analysis .settings .password
222
+ if password :
223
+ s_maker .set_password (password )
224
+
225
+ settings = s_maker .make_settings ()
226
+ if analysis .category == "file" :
227
+ submit_path = AnalysisPaths .submitted_file (analysis_id , resolve = True )
228
+ analysis_id = submit .file (
229
+ submit_path , settings , file_name = analysis .target .target
230
+ )
231
+ else :
232
+ analysis_id = submit .url (analysis .target .target , settings )
233
+ except submit .SubmissionError as e :
234
+ return render (
235
+ request , template_name = "submit/index.html.jinja2" ,
236
+ status = 400 , context = {"error" : str (e )}
237
+ )
238
+
239
+ try :
240
+ submit .notify ()
241
+ except submit .SubmissionError as e :
242
+ logging .error (f"Failed to notify Cuckoo of new analysis { analysis_id } . Exception: { e } " )
243
+ return HttpResponseServerError (
244
+ "Failed to notify Cuckoo of new analysis. Please try again later."
245
+ )
246
+
247
+ return redirect ("Submit/waitidentify" , analysis_id = analysis_id )
0 commit comments