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

Added check for presence of .data section in PE binary for go buildinfo func #104

Merged
merged 2 commits into from
Jun 3, 2024

Conversation

jasper-vdhoven
Copy link
Contributor

This patch adds a check whether a .data section is present, and if that's the case, then tries to decode the section. Currently with latest commit in the main branch of blint an error will be displayed to the user in case there is no .data section for a PE file within the parse_go_buildinfo() function:

ERROR    Caught <class 'AttributeError'>: 'NoneType' object has no attribute 'content' while parsing                                                                                   
                    Samples/13337328933/64156f9ca51951a9bf91b5b74073d31c16873ca60492c25895c1f0f074787345.                                                                                         
                    Traceback (most recent call last):                                                                                                                                            
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 741, in parse                                                                                 
                        metadata = add_pe_metadata(exe_file, metadata, parsed_obj)                                                                                                                
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 1124, in add_pe_metadata                                                                      
                        metadata["go_dependencies"], metadata["go_formulation"] = parse_go_buildinfo(parsed_obj)                                                                                  
                                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                  
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 1015, in parse_go_buildinfo                                                                   
                        s.content.tobytes()[: int(s.size / 32)], encoding="ascii", errors="replace"                                                                                               
                        ^^^^^^^^^                                                                                                                                                                 
                    AttributeError: 'NoneType' object has no attribute 'content'

Files used for testing this bug:

Prior to patch:

           ERROR    Caught <class 'AttributeError'>: 'NoneType' object has no attribute 'content' while parsing                                                                                   
                    Samples/ingest/17483604230/3d6123dc6ffbd1a11d73229988203052809bd17617b24a034c1122c8f4983db4.                                                                                  
                    Traceback (most recent call last):                                                                                                                                            
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 741, in parse                                                                                 
                        metadata = add_pe_metadata(exe_file, metadata, parsed_obj)                                                                                                                
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 1124, in add_pe_metadata                                                                      
                        metadata["go_dependencies"], metadata["go_formulation"] = parse_go_buildinfo(parsed_obj)                                                                                  
                                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                  
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 1015, in parse_go_buildinfo                                                                   
                        s.content.tobytes()[: int(s.size / 32)], encoding="ascii", errors="replace"                                                                                               
                        ^^^^^^^^^                                                                                                                                                                 
                    AttributeError: 'NoneType' object has no attribute 'content'                                                                                                                  
           ERROR    Caught <class 'AttributeError'>: 'NoneType' object has no attribute 'content' while parsing                                                                                   
                    Samples/ingest/17483604230/a511ea7db84a6872a60eaebc0b9a4c5c697a6783c3775fbde47637c770d4041d.                                                                                  
                    Traceback (most recent call last):                                                                                                                                            
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 741, in parse                                                                                 
                        metadata = add_pe_metadata(exe_file, metadata, parsed_obj)                                                                                                                
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 1124, in add_pe_metadata                                                                      
                        metadata["go_dependencies"], metadata["go_formulation"] = parse_go_buildinfo(parsed_obj)                                                                                  
                                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                  
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 1015, in parse_go_buildinfo                                                                   
                        s.content.tobytes()[: int(s.size / 32)], encoding="ascii", errors="replace"                                                                                               
                        ^^^^^^^^^                                                                                                                                                                 
                    AttributeError: 'NoneType' object has no attribute 'content'                                                                                                                  
           ERROR    Caught <class 'AttributeError'>: 'NoneType' object has no attribute 'content' while parsing                                                                                   
                    Samples/ingest/17483604230/38f3f6e9abc521c62f3e5ace79cff5044c1436c957df035bc7d8fe8125226fbc.                                                                                  
                    Traceback (most recent call last):                                                                                                                                            
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 741, in parse                                                                                 
                        metadata = add_pe_metadata(exe_file, metadata, parsed_obj)                                                                                                                
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 1124, in add_pe_metadata                                                                      
                        metadata["go_dependencies"], metadata["go_formulation"] = parse_go_buildinfo(parsed_obj)                                                                                  
                                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                  
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 1015, in parse_go_buildinfo                                                                   
                        s.content.tobytes()[: int(s.size / 32)], encoding="ascii", errors="replace"                                                                                               
                        ^^^^^^^^^                                                                                                                                                                 
                    AttributeError: 'NoneType' object has no attribute 'content'
           ERROR    Caught <class 'AttributeError'>: 'NoneType' object has no attribute 'content' while parsing                                                                                   
                    Samples/ingest/17483604230/85d1d1ca4d5881d9b98928c2006fb0eec9655e2705fe74088e6f974a19703f0f.                                                                                  
                    Traceback (most recent call last):                                                                                                                                            
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 741, in parse                                                                                 
                        metadata = add_pe_metadata(exe_file, metadata, parsed_obj)                                                                                                                
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 1124, in add_pe_metadata                                                                      
                        metadata["go_dependencies"], metadata["go_formulation"] = parse_go_buildinfo(parsed_obj)                                                                                  
                                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                  
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 1015, in parse_go_buildinfo                                                                   
                        s.content.tobytes()[: int(s.size / 32)], encoding="ascii", errors="replace"                                                                                               
                        ^^^^^^^^^                                                                                                                                                                 
                    AttributeError: 'NoneType' object has no attribute 'content' 
           ERROR    Caught <class 'AttributeError'>: 'NoneType' object has no attribute 'content' while parsing                                                                                   
                    Samples/ingest/17483604230/a4b1a450cada1b25b74b8decfb92f77c64a04f0b4ec8ddaf1a3c0f962a364c0a.                                                                                  
                    Traceback (most recent call last):                                                                                                                                            
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 741, in parse                                                                                 
                        metadata = add_pe_metadata(exe_file, metadata, parsed_obj)                                                                                                                
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 1124, in add_pe_metadata                                                                      
                        metadata["go_dependencies"], metadata["go_formulation"] = parse_go_buildinfo(parsed_obj)                                                                                  
                                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                  
                      File "/home/jasper/.local/lib/python3.12/site-packages/blint/binary.py", line 1015, in parse_go_buildinfo                                                                   
                        s.content.tobytes()[: int(s.size / 32)], encoding="ascii", errors="replace"                                                                                               
                        ^^^^^^^^^                                                                                                                                                                 
                    AttributeError: 'NoneType' object has no attribute 'content' 

Copy link
Member

@prabhu prabhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@prabhu prabhu merged commit f070a4a into owasp-dep-scan:main Jun 3, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants