Fix UnknownAttributeError on NetworkHost/NetworkService.create#3574
Open
sethumadh wants to merge 3 commits into
Open
Fix UnknownAttributeError on NetworkHost/NetworkService.create#3574sethumadh wants to merge 3 commits into
sethumadh wants to merge 3 commits into
Conversation
| if BeEF::Filters.is_valid_ip?(ip) | ||
| print_debug("Hooked browser found #{proto} proxy [ip: #{ip}, port: #{port}]") | ||
| BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: proto.downcase, ip: ip, port: port, type: "#{proto} Proxy") | ||
| BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: proto.downcase, ip: ip, port: port, ntype: "#{proto} Proxy") |
Contributor
There was a problem hiding this comment.
Hey @sethumadh ,
Just to harden this area (and satisfy CodeQL security scanner), could you please implement the catching of unexpected assignment to proto variable? Something like below.
proto = case proxy_type
when /PROXY/ then 'HTTP'
when /SOCKS/ then 'SOCKS'
else
print_debug("Unexpected proxy_type from WPAD response: #{proxy_type.inspect}")
next
end
Thanks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Category
Bug
Feature/Issue Description
Q: Please give a brief summary of your feature/fix
A: Closes #3493 and #3498. Multiple recon modules were calling
NetworkService.create(..., type: ...)andNetworkHost.create(..., type: ...), but the DB column isntype, nottype(the migration author renamed it becausetypeis a Rails STI reserved word). Every such call raisedActiveModel::UnknownAttributeErrorat runtime. #3493 and #3498 are two reported bugs of the same root cause and this PR fixes all 16 broken callsites across 12 files.Q: Give a technical rundown of what you have changed (if applicable)
A:
Root cause: the migration at
core/main/ar-migrations/014_create_network_service.rband013_create_network_host.rbnames the columnntype.Investigation chain:
extensions/network/models/network_service.rbandnetwork_host.rbfor anyalias_attribute :type, :ntype.#3493 and #3498 are two reported bugs and 14 other instances were not reported as bugs by users.
Reproduction (#3498 in Firefox):
The fix: 16 line changes across 12 files.
type:becomesntype:in every.createcall againstNetworkServiceorNetworkHost.Files changed:
core/main/handlers/browserdetails.rbmodules/exploits/router/asus_rt_n12e_get_info/module.rbmodules/host/detect_airdroid/module.rbmodules/host/detect_cups/module.rbmodules/network/cross_origin_scanner_cors/module.rbmodules/network/cross_origin_scanner_flash/module.rbmodules/network/detect_burp/module.rbmodules/network/get_http_servers/module.rbmodules/network/get_ntop_network_hosts/module.rbmodules/network/get_proxy_servers_wpad/module.rbmodules/network/internal_network_fingerprinting/module.rbmodules/network/jslanscanner/module.rbTest Cases
Q: Describe your test cases, what you have covered and if there are any use cases that still need addressing.
A:
Two new regression-guard specs:
spec/beef/core/main/models/network_service_spec.rbspec/beef/core/main/models/network_host_spec.rbThese are regression guards, not TDD tests, they catch changes to the model itself.
Live verification : ran the fix end-to-end on two modules with distinct probe techniques:
modules/network/jslanscanner): hooked a Firefox browser, ran the module, scanned 27 common router IPs. All 27 results POSTed back cleanly. All 27 rows landed innetwork_serviceswithntype = 'HTTP Server'. ZeroUnknownAttributeErrortraces in the server log. Before the fix this same module raised on the first POST and wrote zero rows.Wiki Page
N/A — this is a pure bug fix with no new feature surface.