Skip to content

Commit

Permalink
Fix out-of-bounds for UserInGroup on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
sourque committed Oct 27, 2022
1 parent eb4e44f commit e3bbc16
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 22 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ message = "Malicious user 'user' can't read /etc/shadow"
type = "CommandNot"
cmd = "sudo -u user cat /etc/shadow"

[[check.pass]] # "pass" conditions are logically AND with other pass
type = "FileExists" # conditions. This means they all must pass for a check
path = "/etc/shadow" # to be considered successful.
[[check.pass]] # "pass" conditions are logically AND with other pass
type = "FileExists" # conditions. This means they all must pass for a check
path = "/etc/shadow" # to be considered successful.

[[check.passoverride]] # If you a check to succeed if just one condition
type = "UserExistsNot" # passes, regardless of other pass checks, use
user = "user" # an override pass (passoverride). This is a logical OR.
# passoverride is overridden by fail conditions.
# passoverride is overridden by fail conditions.

[[check.fail]] # If any fail conditions succeed, the entire check will fail.
type = "FileExistsNot"
Expand Down
4 changes: 3 additions & 1 deletion checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type cond struct {
After string
}

// requireArgs is a convenience function that prints a warning if any required
// parameters for a given condition are not provided.
func (c cond) requireArgs(args ...interface{}) {
// Don't process internal calls -- assume the developers know what they're
// doing. This also prevents extra errors being printed when they don't pass
Expand Down Expand Up @@ -105,7 +107,7 @@ func runCheck(cond cond) bool {

// Ensure that condition type is a valid length
if len(cond.Type) <= len(not) {
fail(`Condition type "` + cond.Type + `" is not long enough to be valid`)
fail(`Condition type "` + cond.Type + `" is not long enough to be valid. Do you have a "type = 'CheckTypeHere'" for all check conditions?`)
return false
}

Expand Down
2 changes: 1 addition & 1 deletion checks_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (c cond) ProgramInstalled() (bool, error) {
func (c cond) ProgramVersion() (bool, error) {
c.requireArgs("Name", "Value")
return cond{
Cmd: `dpkg -s ` + c.Name + ` | grep Version | cut -d" " -f2`,
Cmd: `dpkg -s ` + c.Name + ` | grep Version | cut -d" " -f2`,
Value: c.Value,
}.CommandOutput()
}
Expand Down
10 changes: 8 additions & 2 deletions checks_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,16 @@ func (c cond) UserInGroup() (bool, error) {
return false, nil
}
for _, user := range users {
justName := strings.Split(user.Name, `\`)[1]
if c.User == user.Name || c.User == justName {
if c.User == user.Name {
return true, nil
}
// If username contains a backslash (for hostname or domain), compare
// against only the second part as well
if splitName := strings.Split(user.Name, `\`); len(splitName) > 1 {
if c.User == splitName[1] {
return true, nil
}
}
}
return false, nil
}
Expand Down
9 changes: 5 additions & 4 deletions configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func parseConfig(configContent string) {
}
if verboseEnabled {
for _, undecoded := range md.Undecoded() {
warn("Undecoded scoring key \"" + undecoded.String() + "\" will not be used")
warn("Undecoded scoring configuration key \"" + undecoded.String() + "\" will not be used.")
}
}

Expand All @@ -51,14 +51,15 @@ func parseConfig(configContent string) {
info(" version = '" + version + "'")
}

// Print warnings for impossible checks and undefined check types.
for i, check := range conf.Check {
allConditions := append(append(append([]cond{}, check.Pass[:]...), check.Fail[:]...), check.PassOverride[:]...)
if len(allConditions) == 0 {
warn("Check " + fmt.Sprintf("%d", i+1) + " does not define any possible ways to pass")
warn("Check " + fmt.Sprintf("%d", i+1) + " does not define any possible ways to pass!")
}
for j, cond := range allConditions {
if cond.Type == "" {
warn("Check " + fmt.Sprintf("%d condition %d", i+1, j+1) + " has an empty type and will crash at runtime")
warn("Check " + fmt.Sprintf("%d condition %d", i+1, j+1) + " does not have a check type!")
}
}
}
Expand Down Expand Up @@ -187,7 +188,7 @@ func obfuscateConfig() {
}

// obfuscateCond is a convenience function to obfuscate all string fields of a
// struct using reflection. ONLY use it on a struct of strings.
// struct using reflection. It assumes all struct fields are strings.
func obfuscateCond(c *cond) error {
s := reflect.ValueOf(c).Elem()
for i := 0; i < s.NumField(); i++ {
Expand Down
6 changes: 3 additions & 3 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//
// If you compile the source code yourself, using the Makefile, random strings
// will be generated for you. This means that the pre-compiled release will no
// longer work for decrypting your configs-- which is ideal.
// longer work for decrypting your configs, which is good.

package main

Expand Down Expand Up @@ -260,14 +260,14 @@ func decryptString(password, ciphertext string) string {
// Create the AES-GCM cipher with the generated block.
aesgcm, err := cipher.NewGCM(block)
if err != nil {
fail(err.Error())
fail("Error creating AES cipher (please tell the developers):", err.Error())
return ""
}

// Decrypt (and check validity, since it's GCM) of ciphertext.
plainText, err := aesgcm.Open(nil, iv, []byte(ciphertext), nil)
if err != nil {
fail(err.Error())
fail("Error decrypting (are you using the correct aeacus/phocus? you may need to re-encrypt your config):", err.Error())
return ""
}

Expand Down
4 changes: 2 additions & 2 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ local = true
enddate = "2004/06/05 13:09:00 PDT"
```

**shell**: Determines if remote shell functionality is enabled. This is disabled by default. If enabled, competition organizers can interact with images from the scoring endpoint
**shell**: (Warning: the canonical remote endpoint (sarpedon) does not support this feature). Determines if remote shell functionality is enabled. This is disabled by default. If enabled, competition organizers can interact with images from the scoring endpoint

```
shell = true
shell = false
```

**version**: Version of aeacus that the configuration was made for. Used for compatibility checks, the engine will throw a warning if the binary version does not match the version specified in this field. You should set this to the version of aeacus you are using.
Expand Down
8 changes: 4 additions & 4 deletions score.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,20 @@ type statusRes struct {
Status string `json:"status"`
}

// ReadScoringData is a convenience function around readData and decodeString,
// readScoringData is a convenience function around readData and decodeString,
// which parses the encrypted scoring configuration file.
func readScoringData() error {
info("Decrypting data from " + dirPath + scoringData + "...")

// Read in the encrypted configuration file
dataFile, err := readFile(dirPath + scoringData)
if err != nil {
return err
} else if dataFile == "" {
return errors.New("Scoring data is empty!")
}

decryptedData, err := decryptConfig(dataFile)
if err != nil {
return err
}
if err != nil {
fail("Error reading in scoring data: " + err.Error())
return err
Expand All @@ -91,6 +90,7 @@ func readScoringData() error {
} else {
info("Data decryption successful!")
}

parseConfig(decryptedData)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

const (
version = "2.0.3"
version = "2.0.4"
)

var (
Expand Down

0 comments on commit e3bbc16

Please sign in to comment.