0

I have a workflow that retrieves a CVE name and number. I can get it to print to Teams juts fine as is. However I am attempting to scrape ONLY the CVE number "CVE-2021-XXXXX"

When it runs as:

import re
text ="{{["Get Vulnerability Content from Rapid7 Vuln DB"].[content_result].[title]}}"

m = re.search(r'CVE-\d{4}-\d{4,7}', text)

if m:
    found = m.group(1)

I receive the following output:

rapid7/Python 3 Script:2.0.3. Step name: run
Input: (below)

{}

Function: (below)

import re

text ="Google Chrome Vulnerability: CVE-2021-XXXX "Long description"

m = re.search(r'CVE-\d{4}-\d{4,7}', text)

if m:
    found = m.group(1)

Could not run supplied script. Error: no such group

I tried print() and Out as well.

It is in a loop so it will only be scraping one line of text at a time.

Robert
  • 1
  • 1
  • I see the string literal is not closed correctly, try using single quotation marks. `text ='{{['Get Vulnerability Content from Rapid7 Vuln DB'].[content_result].[title]}}'` and note - **you CAN'T use `m.group(1)` here**, there is no group in your regex. Replace `m.group(1)` with `m.group()`. – Wiktor Stribiżew Sep 29 '21 at 16:46
  • No dice. Get the same error but it does show up as: text ='Google Chrome Vulnerability: CVE-2021-XXXX Long Description' Could not run supplied script. Error: 're\n\ntext' – Robert Sep 29 '21 at 16:50
  • Yeah, something is wrong with the syntax, but we cannot help you without being able to repro this issue. As I say, you must use `m.group()` to fix the obvious issue, but it seems it is not fixing the whole code for you. – Wiktor Stribiżew Sep 29 '21 at 16:53

1 Answers1

0

Use re.findall here:

text = 'Google Chrome Vulnerability: CVE-2021-XXXX "Long description"'
matches = re.findall(r'\bCVE-\d{4}-\w{4,7}\b', text)
print(matches)  # ['CVE-2021-XXXX']
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Unfortunately now I get: Could not run supplied script. Error: 're\n\ntext' Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/python_3_script_rapid7_plugin-2.0.3-py3.7.egg/komand_python_3_script/actions/run/action.py", line 22, in run out = locals()[funcname](params["input"]) KeyError: 're\n\ntext' – Robert Sep 29 '21 at 15:51