#156 Initial implementation of sqlite3 integration #177
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.
Implementation Details
This pull request attempts to address #156. This implementation introduces a new
-db
command line parameter that allows a user to provide an SQLite3 database. The database contains three tables (whose schema you can find defined in theconst
area indb/create.go
):validateTarget
function for a given ip/port/software, as well as the version string (when possible).The verified logic should be totally transparent to framework users (meaning, it just automatically works). The HTTP caching is a little different. HTTP caching is... not a straight forward topic and I certainly didn't want to introduce anything weird in the hundreds of exploits we've written (e.g. if we accidentally cache a page that we need a fresh CSRF token from... that's bad). As such, I added a single function that the developer can use to tell the system to cache the page. That's
protocol.HTTPGetCache
.I think
protocol.HTTPGetCache
will likely just be used to replace all theprotocol.HTTPSendAndRecv
inValidateTarget
andCheckVersion
. For example, This is the diff I have for testing the changes in CVE-2024-31982:The way the HTTP caching works is actually really simple. We just use Response.Write to serialize a response to a string and http.ReadResponse to serialize it back. There has never been any issues with de-serialization of stored data, so I'm sure it's great (this is sarcasm... but I'm not aware of this being a dangerous function).
The SQLite3 driver I ended up using was the modernc library. This is attractive because it's cgo-free, has a decent user base, and appears to be actively maintained. It is the slowest driver but I don't think that matters for what we are doing (like the win for a cache hit will always be huge).
Finally, I did add logic that would allow a user to cache no HTTP but still use the database. The flag is -cacheMax and is set to 10 MB by default. The user can set it down to 0 if they want.
Oddities
Other oddities in this patch:
c2Flags
got pulled out into its own function. My small addition had bumped upgocyclo
too high.CreateRequest
that @terrorbyte had commented on (and was documented in Document protocol.CreateRequest bool Return #138)Finally, allow me to copy and paste the .md I wrote:
Database Usage
go-exploit supports the use of an SQLite3 database in order to facilite cross-exploit communication and HTTP caching. This is optional, but can greatly improve the performance of large scale scanning.
To use this feature, use the
-db
command line option. The provided file can be empty or a database created during previous runs of go-exploit. In the example below, we use the option-db vc.db
to use the non-existent filevc.db
:In the TRACE output we can see that there is an HTTP cache hit during version scanning, this is because the first request in target verfication was cached. If we run the exploit again we will see more TRACE output:
Note the first TRACE this time is for
Verified software cache hit
. That is because the result of the previous run was saved in the database, so this exploit knows that 10.9.49.29:8080 is XWiki.In fact, on this second run, no network traffic was generated. This has a variety of useful applications including improved speed, asset database generation, easy to create test databases, and "scanless" scans.