We are trying to automate ServiceNow ticketing of Log4j vulnerabilities found using the Logpresso Scan4j tool.
The idea is that we can use the JSON output from the tool and feed that to the ServiceNow API, then our ServiceNow Developers can pickup the resulting data and create/close tickets automatically based on the content.
Getting the LogPresso tool to generate the results of the scan as JSON was easy, but to include it in the “additional_info” field in the JSON to be submitted to ServiceNow, I need to escape all the Quotes in the Results JSON file.
I’ve made progress, but I’ve run into a problem the I don’t see the source of.
The Relevance I used is …
concatenation "\%22" of substrings separated by "%22" of ((it & "%0d%0a") of (lines of file "log4j2_scan_report_20220119_173304.json" of folder "<location of Results JSON file>") as string)
concatenation "\%22" of substrings separated by "%22" of (("%0d%0a" & it ) of (lines of file "log4j2_scan_report_20220119_173304.json" of folder "<ReportFolder>") as string)
I have a couple problems,
- The Relevance is adding an extra escaped " character at the beginning of each line starting with the 2nd line of the file.
- The escaped CR/LF characters are not being converted to their ASCII equivalent characters. I’ve actually getting %0d%0a in the output text.
- If I prepend the CR/LF characters, the extra escaped " characters end up at the end of each line.
Sample JSON output fragment …
{
"summary": {
"scanner_banner": "Logpresso CVE-2021-44228 Vulnerability Scanner 2.7.2 (2022-01-11)",
"scanner_version": "2.7.2",
"scanner_release_date": "2022-01-11",
"scanner_args": [
"--drives",
"c",
"--report-json"
Fixlet Debugger Output from Item #2 …
Q: concatenation "\%22" of substrings separated by "%22" of ((it & "%0d%0a") of (lines of file "log4j2_scan_report_20220119_173304.json" of folder "<ReportFolder>") as string)
A: {%0d%0a\" \"summary\": {%0d%0a\" \"scanner_banner\": \"Logpresso CVE-2021-44228 Vulnerability Scanner 2.7.2 (2022-01-11)\",%0d%0a\" \"scanner_version\": \"2.7.2\",%0d%0a\" \"scanner_release_date\": \"2022-01-11\",%0d%0a\" \"scanner_args\": [%0d%0a\" \"--drives\",%0d%0a\" \"c\",%0d%0a\" \"--report-json\"
Fixlet Debugger Output from Item #3 …
Q: concatenation "\%22" of substrings separated by "%22" of (("%0d%0a" & it) of (lines of file "log4j2_scan_report_20220119_173304.json" of folder "<ReportFolder>") as string)
A: %0d%0a{\"%0d%0a \"summary\": {\"%0d%0a \"scanner_banner\": \"Logpresso CVE-2021-44228 Vulnerability Scanner 2.7.2 (2022-01-11)\",\"%0d%0a \"scanner_version\": \"2.7.2\",\"%0d%0a \"scanner_release_date\": \"2022-01-11\",\"%0d%0a \"scanner_args\": [\"%0d%0a \"--drives\",\"%0d%0a \"c\",\"%0d%0a \"--report-json\"\"
Where is that extra escaped quote character coming from, and why are the CR/LF characters showing up like this?