I'm trying to successfully retrieve some JSON data from log4jscanner.exe (Qualys software to detect if you got a vulnerable file or component in your pc/server) but after spent many hours on it, i think i got an issue with Powershell.
If I store the result of the following command in Powershell 5.1
$a = .\Log4jScanner.exe /scan /report_pretty
The result is "displayed" like :
PS C:\temp> $a |where {$_ -ne ""}
{
"scanSummary": {
"scanEngine": "2.0.2.7",
"scanHostname": "XXXXXXXXX",
"scanDate": "2022-01-20T18:02:26+0100",
"scanDurationSeconds": 28,
"scanErrorCount": 54,
"scanStatus": "Partially Successful",
"scannedFiles": 649020,
"scannedDirectories": 209514,
"scannedJARs": 31,
"scannedWARs": 0,
"scannedEARs": 0,
"scannedPARs": 0,
"scannedTARs": 5,
"scannedCompressed": 43,
"vulnerabilitiesFound": 1
},
"scanDetails": [
{
"file": "XXXXXX.jar",
"manifestVendor": "Unknown",
"manifestVersion": "Unknown",
"detectedLog4j": true,
"detectedLog4j1x": true,
"detectedLog4j2x": false,
"detectedJNDILookupClass": false,
"detectedLog4jManifest": false,
"log4jVendor": "log4j",
"log4jVersion": "1.2.17",
"cve20214104Mitigated": false,
"cve202144228Mitigated": true,
"cve202144832Mitigated": true,
"cve202145046Mitigated": true,
"cve202145105Mitigated": true,
"cveStatus": "Potentially Vulnerable ( CVE-2021-4104: Found )"
}
]
}
After that, i want to convert that data to work on a specifical value, first of all i try to convert data from json, here the text goes RED and the following error happened :
PS C:\temp> $a | convertfrom-json
convertfrom-json : Objet non valide passé, ':' ou '}' attendu. (2): {
"scanSummary": {
"scanEngine": "2.0.2.7",
"scanHostname": "FRBOURWXT013379.vcn.ds.volvo.net",
"scanDate": "2022-01-20T18:02:26+0100",
.... .... ....
Finally, if I copy/paste the content of $a into another variable like
$b = '
{
"scanSummary": {
"scanEngine": "2.0.2.7",
"scanHostname": "XXXXXXXXX",
"scanDate": "2022-01-20T18:02:26+0100",
"scanDurationSeconds": 28,
... ... ...
'
It means that i'm now able to access converted data :
PS C:\temp> $b | convertfrom-json
scanSummary
-----------
@{scanEngine=2.0.2.7; scanHostname=XXXXXXXXX; scanDate=2022-01-20T18:02:26+0100; scanDurationSeconds=28; scanErrorCount=54; scanStatus=Partially Successful; scann...
At the moment $a type is Object[] , $b type is String.
So i tried to convert $a to string
PS C:\temp> $a = [string] $a
PS C:\temp> $a
{ "scanSummary": { "scanEngine": "2.0.2.7", "scanHostname": "XXXXXXXXX", "scanDate": "2022-01-20T18:02:26+0100", "scanDurationSeconds": 28, "scanErrorCount": 54, "scanStatus": "Partially Successful", "scannedFiles": 649020, "scannedDirectories": 209514, "scannedJARs": 31, "scannedWARs": 0, "scannedEARs": 0, "scannedPARs": 0, "scannedTARs": 5, "scannedCompressed": 43, "vulnerabilitiesFound": 1 }, "scanDetails": [ { "file": "XXXXX.jar", "manifestVendor": "Unknown", "manifestVersion": "Unknown", "detectedLog4j": true, "detectedLog4j1x": true, "detectedLog4j2x": false, "detectedJNDILookupClass": false, "detectedLog4jManifest": false, "log4jVendor": "log4j", "log4jVersion": "1.2.17", "cve20214104Mitigated": false, "cve202144228Mitigated": true, "cve202144832Mitigated": true, "cve202145046Mitigated": true, "cve202145105Mitigated": true, "cveStatus": "Potentially Vulnerable ( CVE-2021-4104: Found )" } ] }
and then convert it from json, but it's a total mess
PS C:\temp> $a | convertfrom-json
convertfrom-json : Objet non valide passé, ':' ou '}' attendu. (2): { "scanSummary": { "scanEngine": "2.0.2.7",
"scanHostname": "XXXXXX", "scanDate":
"2022-01-20T18:02:26+0100", "scanDurationSeconds": 28, "scanErrorCount":
54, "scanStatus": "Partially Successful", "scannedFiles": 649020,
"scannedDirectories": 209514, "scannedJARs": 31, "scannedWARs": 0,
Finally, if i export any data to .json file, i can't open it with notepad or codium (every character = nul nul nul nul) whereas i can access it with get-content within powershell.
It seems there's some hidden characters or i don't know what, but i can't handle how to easily convert and access json data in my case.
Is there anything missing ?
Thanks a lot for your support guys !
EDIT 1 - if i save the output, i can't open the .json file correctly ,but Powershell seems to understand it well :