-
Notifications
You must be signed in to change notification settings - Fork 4
/
secret.go
52 lines (43 loc) · 1.19 KB
/
secret.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package secret
//package secret contains the Secret structure representing a unique secret value in a File.
import (
"crypto/md5"
"encoding/hex"
"github.com/intuit/gitdetect/rule"
"github.com/intuit/gitdetect/secret/exploit"
"log"
)
//Secret docuements detected secret metadata
type Secret struct {
FileName string
Value string
LineNumber int
Rule rule.Rule
ID string
}
//NewSecret initialize and return Secret type
func NewSecret(fileName, secretValue string, lineNumber int, rule rule.Rule) (secret Secret) {
secret.FileName = fileName
secret.Value = secretValue
secret.LineNumber = lineNumber
secret.Rule = rule
secret.setID()
return
}
func (this *Secret) setID() {
hash := md5.New()
hash.Write([]byte(this.FileName + this.Value))
this.ID = hex.EncodeToString(hash.Sum(nil))
}
//Exploit runs optionally set hook function ExploitFn
func (this *Secret) Exploit() (exploitInfo string) {
if this.Rule.ExploitFn != "" {
exploit := exploit.Exploit{Fn: this.Rule.ExploitFn, Secret: this.Value, Filename: this.FileName}
if err := exploit.Run(); err == nil {
exploitInfo = exploit.Output
} else {
log.Printf("ExploitFn failed with %s", err.Error())
}
}
return
}