2018-02-06 15:56:26 +00:00
|
|
|
package rules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go/ast"
|
|
|
|
|
2018-07-19 17:42:25 +01:00
|
|
|
"github.com/securego/gosec"
|
2018-02-06 15:56:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type sshHostKey struct {
|
2018-07-19 17:42:25 +01:00
|
|
|
gosec.MetaData
|
2018-02-06 15:56:26 +00:00
|
|
|
pkg string
|
|
|
|
calls []string
|
|
|
|
}
|
|
|
|
|
2017-10-05 22:32:03 +01:00
|
|
|
func (r *sshHostKey) ID() string {
|
|
|
|
return r.MetaData.ID
|
|
|
|
}
|
|
|
|
|
2018-07-19 17:42:25 +01:00
|
|
|
func (r *sshHostKey) Match(n ast.Node, c *gosec.Context) (gi *gosec.Issue, err error) {
|
|
|
|
if _, matches := gosec.MatchCallByPackage(n, c, r.pkg, r.calls...); matches {
|
|
|
|
return gosec.NewIssue(c, n, r.ID(), r.What, r.Severity, r.Confidence), nil
|
2018-02-06 15:56:26 +00:00
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewSSHHostKey rule detects the use of insecure ssh HostKeyCallback.
|
2018-07-19 17:42:25 +01:00
|
|
|
func NewSSHHostKey(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
|
2018-02-06 15:56:26 +00:00
|
|
|
return &sshHostKey{
|
|
|
|
pkg: "golang.org/x/crypto/ssh",
|
|
|
|
calls: []string{"InsecureIgnoreHostKey"},
|
2018-07-19 17:42:25 +01:00
|
|
|
MetaData: gosec.MetaData{
|
2017-10-05 22:32:03 +01:00
|
|
|
ID: id,
|
2018-02-06 15:56:26 +00:00
|
|
|
What: "Use of ssh InsecureIgnoreHostKey should be audited",
|
2018-07-19 17:42:25 +01:00
|
|
|
Severity: gosec.Medium,
|
|
|
|
Confidence: gosec.High,
|
2018-02-06 15:56:26 +00:00
|
|
|
},
|
|
|
|
}, []ast.Node{(*ast.CallExpr)(nil)}
|
|
|
|
}
|