Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SBOM for PE dotnet binaries #69

Merged
merged 13 commits into from
Mar 1, 2024
Merged

SBOM for PE dotnet binaries #69

merged 13 commits into from
Mar 1, 2024

Conversation

prabhu
Copy link
Member

@prabhu prabhu commented Feb 27, 2024

Tested with https://github.com/owasp-dep-scan/dosai/releases/download/v0.1.1/Dosai.exe
https://github.com/owasp-dep-scan/dosai/releases/download/v0.1.1/Dosai

Overlay attribute seems to be missing for MachO so raised a ticket here
lief-project/LIEF#1028

Testing

Find some PE (Windows) and ELF (Linux) binaries generated by dotnet. Alternatively, build any dotnet application using the dotnet build command.

Generate SBOM using the sbom command.

git clone https://github.com/owasp-dep-scan/blint.git
cd blint
git checkout feature/pe-sbom
python -m pip install poetry
poetry install

poetry run blint sbom -i <dotnet generated binary> -o bom.json --deep

The resulting SBOM must include several nuget packages in addition to dll files.

On Windows, manually inspect the various .csproj files to check if all libraries used are reported.
On Linux, run strings command to check if we have captured all the packages reported.

strings -a -t x <binary name>

Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
@prabhu prabhu marked this pull request as draft February 27, 2024 16:58
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
@prabhu prabhu marked this pull request as ready for review February 27, 2024 17:25
@timmyteo
Copy link
Collaborator

Hi @prabhu - I tested this per your instructions above for Dosai.exe and also another dotnet project. I may be doing something wrong or just not understanding this. For instance, when I test Dosai.exe, I am seeing the following dependencies in the BOM instead of the expected Dosai Dependencies:

"dependencies": [
    {
      "ref": "pkg:generic/Dosai.exe@latest",
      "dependsOn": [
        "pkg:file/api-ms-win-crt-math-l1-1-0.dll",
        "pkg:file/api-ms-win-crt-convert-l1-1-0.dll",
        "pkg:file/USER32.dll",
        "pkg:file/SHELL32.dll",
        "pkg:file/ADVAPI32.dll",
        "pkg:file/api-ms-win-crt-stdio-l1-1-0.dll",
        "pkg:file/api-ms-win-crt-locale-l1-1-0.dll",
        "pkg:file/api-ms-win-crt-heap-l1-1-0.dll",
        "pkg:file/api-ms-win-crt-string-l1-1-0.dll",
        "pkg:file/api-ms-win-crt-runtime-l1-1-0.dll",
        "pkg:file/api-ms-win-crt-time-l1-1-0.dll",
        "pkg:file/KERNEL32.dll"
      ]
    }

And although the bom.json is generated, I do see these errors at the command line as well:
image

Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
@prabhu
Copy link
Member Author

prabhu commented Feb 28, 2024

@timmyteo, this was indeed a bug. Have fixed now. Could you kindly retest by updating the branch?

Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
@timmyteo
Copy link
Collaborator

I think it is getting close :)
image

@prabhu
Copy link
Member Author

prabhu commented Feb 28, 2024

Thanks @timmyteo. Could you update and try again?

@timmyteo
Copy link
Collaborator

Nice work @prabhu, it looks to be working now! I tried with Dosai and the expected dependencies are listed in the BOM. Here is what it produced for Dosai:
"dependsOn": [
"pkg:file/ADVAPI32.dll",
"pkg:nuget/System.Runtime.CompilerServices.Unsafe@6.0.0",
"pkg:file/USER32.dll",
"pkg:file/api-ms-win-crt-stdio-l1-1-0.dll",
"pkg:file/api-ms-win-crt-time-l1-1-0.dll",
"pkg:nuget/Dosai@0.1.1",
"pkg:file/api-ms-win-crt-runtime-l1-1-0.dll",
"pkg:file/api-ms-win-crt-locale-l1-1-0.dll",
"pkg:nuget/Microsoft.NET.ILLink.Tasks@8.0.0",
"pkg:file/KERNEL32.dll",
"pkg:file/api-ms-win-crt-string-l1-1-0.dll",
"pkg:nuget/System.CommandLine@2.0.0-beta4.22272.1",
"pkg:file/api-ms-win-crt-convert-l1-1-0.dll",
"pkg:nuget/Microsoft.CodeAnalysis.CSharp@4.8.0",
"pkg:nuget/Microsoft.CodeAnalysis.Analyzers@3.3.4",
"pkg:file/api-ms-win-crt-math-l1-1-0.dll",
"pkg:nuget/System.Collections.Immutable@7.0.0",
"pkg:nuget/System.Reflection.Metadata@7.0.0",
"pkg:nuget/Microsoft.CodeAnalysis.Common@4.8.0",
"pkg:nuget/Microsoft.CodeAnalysis.VisualBasic@4.8.0",
"pkg:file/SHELL32.dll",
"pkg:file/api-ms-win-crt-heap-l1-1-0.dll"
]

I did also try with a simple HelloWorld program with one dependency, but the dependency didn't show up in the BOM as I expected, so not sure if I am doing something wrong there.

Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
@prabhu
Copy link
Member Author

prabhu commented Feb 29, 2024

@timmyteo, fixed again. The exe produced on Windows uses \r\n as the line endings!

@prabhu prabhu merged commit e816624 into main Mar 1, 2024
16 checks passed
@prabhu prabhu deleted the feature/pe-sbom branch March 1, 2024 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants