-
Notifications
You must be signed in to change notification settings - Fork 37
Add Wrapper Package with a Couple of Existing Examples #380
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
Open
lobsterjerusalem
wants to merge
6
commits into
vulncheck-oss:main
Choose a base branch
from
lobsterjerusalem:wrappers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
655eb06
Add SemVer constraint wrapper and add framework test files
terrorbyte 71fc158
Added wrappers with file serve
lobsterjerusalem 61383b5
Merge branch 'wrappers-file-server'
lobsterjerusalem eeb8caf
Added expanded version checking wrapper
lobsterjerusalem 76a7b30
removed output line
lobsterjerusalem bd4a50f
added endpoint param
lobsterjerusalem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package exploit_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/vulncheck-oss/go-exploit" | ||
) | ||
|
||
func TestCheckSemVer_Full(t *testing.T) { | ||
if !exploit.CheckSemVer("1.0.0", "<= 1.0.0") { | ||
t.Error("Constraint should have passed") | ||
} | ||
if exploit.CheckSemVer("1.0.0", "> 1.0.0") { | ||
t.Error("Constraint should not have passed") | ||
} | ||
} | ||
|
||
func TestCheckSemVer_BadVersion(t *testing.T) { | ||
if exploit.CheckSemVer("uwu", "<= 1.0.0") { | ||
t.Error("Version was invalid, should not have passed") | ||
} | ||
if exploit.CheckSemVer("1.0.0 ", "<= 1.0.0") { | ||
t.Error("Version was invalid, should not have passed") | ||
} | ||
} | ||
|
||
func TestCheckSemVer_BadConstraint(t *testing.T) { | ||
if exploit.CheckSemVer("1.0.0", "<== 1.0.0") { | ||
t.Error("Constraint was invalid, should not have passed") | ||
} | ||
if exploit.CheckSemVer("1.0.0", "xp") { | ||
t.Error("Constraint was invalid, should not have passed") | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package wrappers | ||
|
||
import( | ||
"regexp" | ||
"net/http" | ||
|
||
"github.com/vulncheck-oss/go-exploit" | ||
"github.com/vulncheck-oss/go-exploit/config" | ||
"github.com/vulncheck-oss/go-exploit/output" | ||
"github.com/vulncheck-oss/go-exploit/protocol" | ||
"github.com/vulncheck-oss/go-exploit/c2/channel" | ||
"github.com/vulncheck-oss/go-exploit/c2/httpservefile" | ||
) | ||
|
||
// A collection of wrappers/helper functions that have otherwise no place to go and may need to be in their own packages | ||
// to avoid certain import cycle errors. | ||
|
||
// Helper function for use within exploits to reduce the overall amount of boilerplate when setting up a file server to host a dynamically generated file. | ||
func HTTPServeFileInitAndRunWithFile(conf *config.Config, fileName string, routeName string, data[]byte) bool { | ||
httpServer := httpservefile.GetInstance() | ||
|
||
if httpServer.HTTPAddr == "" { | ||
httpServer.HTTPAddr = conf.Lhost | ||
} | ||
|
||
if !httpServer.Init(&channel.Channel{HTTPAddr: httpServer.HTTPAddr, HTTPPort: httpServer.HTTPPort}) { | ||
output.PrintFrameworkError("Could not start http server") | ||
|
||
return false | ||
} | ||
|
||
httpServer.AddFile(fileName, routeName, data) | ||
|
||
go httpServer.Run(conf.C2Timeout) | ||
|
||
return true | ||
} | ||
|
||
// This removes generic version checking boiler plate that works in a great deal of cases. | ||
// Of course it will not work in every case but that is not the point. | ||
func SimpleVersionCheck(conf *config.Config, rePattern string, versionConstraint string, endpoint string) exploit.VersionCheckType { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should move this to the same as |
||
url := protocol.GenerateURL(conf.Rhost, conf.Rport, conf.SSL, endpoint) | ||
resp, body, ok := protocol.HTTPGetCache(url) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. formatting gone wrong here and elsewhere in the file |
||
if !ok || resp == nil { | ||
return exploit.Unknown | ||
} | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
output.PrintfFrameworkError("Version check failed: Unexpected response code during initial GET request: %d", resp.StatusCode) | ||
|
||
return exploit.Unknown | ||
} | ||
|
||
matches := regexp.MustCompile(rePattern).FindStringSubmatch(body) | ||
if len(matches) < 2 { | ||
output.PrintFrameworkError("Version check failed: No matches found for the provided pattern") | ||
|
||
return exploit.Unknown | ||
} | ||
|
||
exploit.StoreVersion(conf, matches[1]) | ||
|
||
if exploit.CheckSemVer(matches[1], versionConstraint) { | ||
return exploit.Vulnerable | ||
} | ||
|
||
return exploit.NotVulnerable | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk where to put this but this probably shouldn't be wrappers