Skip to content

Commit

Permalink
Merge pull request #1 from compscore/null-byte-bug
Browse files Browse the repository at this point in the history
Clear Null-Bytes from Returned Errors
  • Loading branch information
1nv8rzim authored Nov 10, 2023
2 parents 6500e3c + c13e745 commit cd1929a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ func (o *optionsStruct) Check(expectedOutput string, file *smb2.File) error {
return nil
}

func clean(input string) string {
return strings.ReplaceAll(input, "\x00", "")
}

func Run(ctx context.Context, target string, command string, expectedOutput string, username string, password string, options map[string]interface{}) (bool, string) {
if !strings.Contains(target, ":") {
target = fmt.Sprintf("%s:445", target)
Expand All @@ -164,7 +168,7 @@ func Run(ctx context.Context, target string, command string, expectedOutput stri

conn, err := net.Dial("tcp", target)
if err != nil {
return false, err.Error()
return false, clean(err.Error())
}
defer conn.Close()

Expand All @@ -178,7 +182,7 @@ func Run(ctx context.Context, target string, command string, expectedOutput stri

s, err := smbConn.DialContext(ctx, conn)
if err != nil {
return false, err.Error()
return false, clean(err.Error())
}
defer s.Logoff()

Expand All @@ -190,24 +194,24 @@ func Run(ctx context.Context, target string, command string, expectedOutput stri
),
)
if err != nil {
return false, err.Error()
return false, clean(err.Error())
}
defer fs.Umount()

f, err := fs.Open(command)
if err != nil {
return false, err.Error()
return false, clean(err.Error())
}
defer f.Close()

_, err = f.Seek(0, io.SeekStart)
if err != nil {
return false, err.Error()
return false, clean(err.Error())
}

err = o.Check(expectedOutput, f)
if err != nil {
return false, err.Error()
return false, clean(err.Error())
}

return true, ""
Expand Down

0 comments on commit cd1929a

Please sign in to comment.