-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add support for old spring archives to be scanned * spring executable jars can be scanned now * Fix windows output to not include excessive slashes #365 * add false positive tests
- Loading branch information
1 parent
fee19ab
commit 2f14ea9
Showing
22 changed files
with
282,562 additions
and
565 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -19,3 +19,6 @@ build: payload cli | |
|
||
clean: | ||
go clean | ||
|
||
setup-tests: | ||
cd test/vulnerable-log4j2-versions && go run main.go |
This file contains 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 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,94 @@ | ||
// Copyright 2021 by LunaSec (owned by Refinery Labs, Inc) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
package analyze | ||
|
||
import ( | ||
"github.com/blang/semver/v4" | ||
"github.com/rs/zerolog/log" | ||
"path" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
var alphaRegex = regexp.MustCompile("([a-z]+)") | ||
|
||
func VersionIsInRange(fileName string, semverVersion string, semverRange semver.Range) bool { | ||
version, err := semver.Make(semverVersion) | ||
if err != nil { | ||
log.Warn(). | ||
Str("fileName", fileName). | ||
Str("semverVersion", semverVersion). | ||
Msg("Unable to parse semver version") | ||
return false | ||
} | ||
|
||
if semverRange(version) { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func adjustMissingPatchVersion(semverVersion string) string { | ||
if len(semverVersion) == 3 { | ||
semverVersion += ".0" | ||
} | ||
if strings.HasPrefix(semverVersion, "2.0-") { | ||
semverVersion = strings.Replace(semverVersion, "2.0-", "2.0.0-", -1) | ||
} | ||
if strings.HasPrefix(semverVersion, "1.0-") { | ||
semverVersion = strings.Replace(semverVersion, "1.0-", "1.0.0-", -1) | ||
} | ||
return semverVersion | ||
} | ||
|
||
func ArchiveNameToSemverVersion(filename string) string { | ||
fileNameNoExt := strings.TrimSuffix(filename, path.Ext(filename)) | ||
fileNameParts := strings.Split(fileNameNoExt, "-") | ||
|
||
var tag, semverVersion string | ||
for i := len(fileNameParts) - 1; i >= 0; i-- { | ||
fileNamePart := fileNameParts[i] | ||
if ( | ||
strings.HasPrefix(fileNamePart, "1") || | ||
strings.HasPrefix(fileNamePart, "2")) && | ||
strings.Contains(fileNamePart, ".") { | ||
|
||
tagPart := alphaRegex.FindString(fileNamePart) | ||
if tagPart != "" { | ||
fileNamePart = strings.Replace(fileNamePart, tagPart, "", 1) | ||
if tag == "" { | ||
tag = tagPart | ||
} else { | ||
tag = tagPart + "-" + tag | ||
} | ||
} | ||
|
||
fileNamePart = adjustMissingPatchVersion(fileNamePart) | ||
|
||
if tag == "" { | ||
semverVersion = fileNamePart | ||
break | ||
} | ||
semverVersion = fileNamePart + "-" + tag | ||
break | ||
} | ||
if tag == "" { | ||
tag = fileNamePart | ||
continue | ||
} | ||
tag = fileNamePart + "-" + tag | ||
} | ||
return semverVersion | ||
} |
This file contains 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
Oops, something went wrong.