Skip to content

Commit f552c6d

Browse files
bakatziryaakovi
andauthored
Joe Security - non english chars (demisto#11786)
* Joe Security - non english chars * rm uuid import * add whitespace * Update Packs/JoeSecurity/ReleaseNotes/1_0_4.md Co-authored-by: Shai Yaakovi <[email protected]> * Update Packs/JoeSecurity/Integrations/JoeSecurity/JoeSecurity.py Co-authored-by: Shai Yaakovi <[email protected]> Co-authored-by: Shai Yaakovi <[email protected]>
1 parent c403877 commit f552c6d

4 files changed

Lines changed: 28 additions & 21 deletions

File tree

Packs/JoeSecurity/Integrations/JoeSecurity/JoeSecurity.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import demistomock as demisto
22
from CommonServerPython import *
33
from CommonServerUserPython import *
4+
45
''' IMPORTS '''
56
import time
67
import shutil
78
import requests
89
from distutils.util import strtobool
10+
911
# disable insecure warnings
1012
requests.packages.urllib3.disable_warnings()
1113

12-
1314
''' GLOBAL VARS '''
1415
BASE_URL = urljoin(demisto.params().get('url'), 'api/')
1516
USE_SSL = not demisto.params().get('insecure', False)
@@ -25,15 +26,14 @@
2526
'HumanReadable': 'We found nothing to analyze in your uploaded email'
2627
}
2728

28-
2929
''' HELPER FUNCTIONS '''
3030

3131

3232
def http_post(url_suffix, data=None, files=None, parse_json=True):
3333
data = {} if data is None else data
3434

3535
LOG('running request with url=%s\n\tdata=%s\n\tfiles=%s' % (BASE_URL + url_suffix,
36-
data, files, ))
36+
data, files,))
3737
data.setdefault('apikey', demisto.params()['api_key'])
3838

3939
res = requests.post(BASE_URL + url_suffix, verify=USE_SSL, data=data, files=files)
@@ -46,9 +46,9 @@ def http_post(url_suffix, data=None, files=None, parse_json=True):
4646
if error_msg == nothing_to_analyze_message:
4747
return 'nothing_to_analyze'
4848

49-
LOG('result is: %s' % (res.json(), ))
49+
LOG('result is: %s' % (res.json(),))
5050
error_msg = res.json()['errors'][0]['message']
51-
raise Exception('Your request failed with the following error: %s.\n%s' % (res.reason, error_msg, ))
51+
raise Exception('Your request failed with the following error: %s.\n%s' % (res.reason, error_msg,))
5252

5353
if parse_json:
5454
return res.json()
@@ -129,12 +129,12 @@ def poll_webid(web_id):
129129

130130
while (max_polls >= 0) and result['data']['status'] != 'finished':
131131
if result['data']['status'] != 'pending':
132-
LOG('error while polling: result is %s' % (result, ))
132+
LOG('error while polling: result is %s' % (result,))
133133
result = info_request(web_id)
134134
time.sleep(1)
135135
max_polls -= 1
136136

137-
LOG('reached max_polls #%d' % (max_polls, ))
137+
LOG('reached max_polls #%d' % (max_polls,))
138138
if max_polls < 0:
139139
return analysis_to_entry('Polling timeout on Analysis #' + web_id, result['data'])
140140
else:
@@ -162,7 +162,7 @@ def analysis_info():
162162
ids = demisto.args().get('webid')
163163
if type(ids) in STRING_TYPES:
164164
ids = ids.split(',')
165-
LOG('info: web_id = %s' % (ids, ))
165+
LOG('info: web_id = %s' % (ids,))
166166
res = [info_request(webid)['data'] for webid in ids]
167167
return analysis_to_entry('Analyses:', res)
168168

@@ -208,7 +208,7 @@ def analyse_url_request(url, should_wait, internet_access, comments='', systems=
208208
res = http_post('v2/analysis/submit', data=data)
209209

210210
if 'errors' in res:
211-
LOG('Error! in command analyse_url: url=%s' % (url, ))
211+
LOG('Error! in command analyse_url: url=%s' % (url,))
212212
LOG('got the following errors:\n' + '\n'.join(e['message'] for e in res['errors']))
213213
raise Exception('command failed to run.')
214214

@@ -217,7 +217,7 @@ def analyse_url_request(url, should_wait, internet_access, comments='', systems=
217217

218218
web_id = res['data']['webids'][0]
219219
result = info_request(web_id)
220-
return analysis_to_entry('Analysis #%s' % (web_id, ), result['data'])
220+
return analysis_to_entry('Analysis #%s' % (web_id,), result['data'])
221221

222222

223223
def analyse_sample():
@@ -255,7 +255,10 @@ def analyse_sample_file_request(file_entry, should_wait, internet_access, commen
255255

256256
# removing backslashes from filename as the API does not like it
257257
# if given filename such as dir\file.xlsx - the sample will end with the name file.xlsx
258-
filename = demisto.getFilePath(file_entry)['name'].replace('\\', '/')
258+
filename = demisto.getFilePath(file_entry)['name']
259+
if isinstance(filename, unicode): # py2 way of checking if a var is of type unicode
260+
filename = filename.encode('ascii', 'ignore')
261+
filename.replace('\\', '/')
259262

260263
with open(demisto.getFilePath(file_entry)['path'], 'rb') as f:
261264
res = http_post('v2/analysis/submit', data=data, files={'sample': (filename, f)})
@@ -264,7 +267,7 @@ def analyse_sample_file_request(file_entry, should_wait, internet_access, commen
264267
return nothing_to_analyze_output
265268

266269
if 'errors' in res:
267-
LOG('Error! in command sample file: file_entry=%s' % (file_entry, ))
270+
LOG('Error! in command sample file: file_entry=%s' % (file_entry,))
268271
LOG('got the following errors:\n' + '\n'.join(e['message'] for e in res['errors']))
269272
raise Exception('command failed to run.')
270273

@@ -275,7 +278,7 @@ def analyse_sample_file_request(file_entry, should_wait, internet_access, commen
275278

276279
web_id = res['data']['webids'][0]
277280
result = info_request(web_id)
278-
return analysis_to_entry('Analysis #%s' % (web_id, ), result['data'])
281+
return analysis_to_entry('Analysis #%s' % (web_id,), result['data'])
279282

280283

281284
def analyse_sample_url_request(sample_url, should_wait, internet_access, comments, systems):
@@ -295,7 +298,7 @@ def analyse_sample_url_request(sample_url, should_wait, internet_access, comment
295298
return nothing_to_analyze_output
296299

297300
if 'errors' in res:
298-
LOG('Error! in command sample file: file url=%s' % (sample_url, ))
301+
LOG('Error! in command sample file: file url=%s' % (sample_url,))
299302
LOG('got the following errors:\n' + '\n'.join(e['message'] for e in res['errors']))
300303
raise Exception('command failed to run.')
301304

@@ -304,7 +307,7 @@ def analyse_sample_url_request(sample_url, should_wait, internet_access, comment
304307

305308
web_id = res['data']['webids'][0]
306309
result = info_request(res['data']['webids'][0])
307-
return analysis_to_entry('Analysis #%s' % (web_id, ), result['data'])
310+
return analysis_to_entry('Analysis #%s' % (web_id,), result['data'])
308311

309312

310313
def download_report():
@@ -326,13 +329,13 @@ def download_request(webid, rsc_type):
326329

327330
info = info_request(webid)
328331
if rsc_type == 'sample':
329-
return fileResult('%s.dontrun' % (info.get('filename', webid), ), res)
332+
return fileResult('%s.dontrun' % (info.get('filename', webid),), res)
330333
else:
331-
return fileResult('%s_report.%s' % (info.get('filename', webid), rsc_type, ), res, entryTypes['entryInfoFile'])
334+
return fileResult('%s_report.%s' % (info.get('filename', webid), rsc_type,), res, entryTypes['entryInfoFile'])
332335

333336

334337
''' EXECUTION CODE '''
335-
LOG('command is %s' % (demisto.command(), ))
338+
LOG('command is %s' % (demisto.command(),))
336339
try:
337340
handle_proxy()
338341
if demisto.command() in ['test-module', 'joe-is-online']:
@@ -371,5 +374,5 @@ def download_request(webid, rsc_type):
371374
demisto.results({
372375
'Type': entryTypes['error'],
373376
'ContentsFormat': formats['text'],
374-
'Contents': 'error has occurred: %s' % (e.message, ),
377+
'Contents': 'error has occurred: %s' % (e.message,),
375378
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
#### Integrations
3+
##### Joe Security
4+
- Fixes an issue where the ***joe-analysis-submit-sample*** command failed if given a file with non-ASCII characters.

Packs/JoeSecurity/TestPlaybooks/playbook-JoeSecurityTestDetonation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ tasks:
7777
simple: this is a regular file
7878
entryId: {}
7979
filename:
80-
simple: suspicious.txt
80+
simple: Männer.txt
8181
separatecontext: false
8282
view: |-
8383
{

Packs/JoeSecurity/pack_metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Joe Security",
33
"description": "Sandbox Cloud",
44
"support": "xsoar",
5-
"currentVersion": "1.0.3",
5+
"currentVersion": "1.0.4",
66
"author": "Cortex XSOAR",
77
"url": "https://www.paloaltonetworks.com/cortex",
88
"email": "",

0 commit comments

Comments
 (0)