2016-08-05 12:58:27 +01:00
|
|
|
// (c) Copyright 2016 Hewlett Packard Enterprise Development LP
|
|
|
|
//
|
|
|
|
// 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 rules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go/ast"
|
|
|
|
|
2016-11-02 23:54:20 +00:00
|
|
|
gas "github.com/GoASTScanner/gas/core"
|
2016-08-05 12:58:27 +01:00
|
|
|
)
|
|
|
|
|
2016-08-10 12:51:03 +01:00
|
|
|
type BlacklistImport struct {
|
|
|
|
gas.MetaData
|
|
|
|
Path string
|
2016-08-05 12:58:27 +01:00
|
|
|
}
|
|
|
|
|
2017-10-05 22:32:03 +01:00
|
|
|
func (r *BlacklistImport) ID() string {
|
|
|
|
return r.MetaData.ID
|
|
|
|
}
|
|
|
|
|
2016-08-10 12:51:03 +01:00
|
|
|
func (r *BlacklistImport) Match(n ast.Node, c *gas.Context) (gi *gas.Issue, err error) {
|
2016-08-05 12:58:27 +01:00
|
|
|
if node, ok := n.(*ast.ImportSpec); ok {
|
2016-11-07 17:27:29 +00:00
|
|
|
if r.Path == node.Path.Value && node.Name.String() != "_" {
|
2016-08-10 12:51:03 +01:00
|
|
|
return gas.NewIssue(c, n, r.What, r.Severity, r.Confidence), nil
|
2016-08-05 12:58:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2017-10-05 22:32:03 +01:00
|
|
|
func NewBlacklist_crypto_md5(id string, conf map[string]interface{}) (gas.Rule, []ast.Node) {
|
2016-11-13 20:55:31 +00:00
|
|
|
return &BlacklistImport{
|
2016-08-10 12:51:03 +01:00
|
|
|
MetaData: gas.MetaData{
|
2017-10-05 22:32:03 +01:00
|
|
|
ID: id,
|
2016-08-10 12:51:03 +01:00
|
|
|
Severity: gas.High,
|
|
|
|
Confidence: gas.High,
|
|
|
|
What: "Use of weak cryptographic primitive",
|
2016-08-05 12:58:27 +01:00
|
|
|
},
|
2016-08-10 12:51:03 +01:00
|
|
|
Path: `"crypto/md5"`,
|
2016-11-13 20:55:31 +00:00
|
|
|
}, []ast.Node{(*ast.ImportSpec)(nil)}
|
2016-08-10 12:51:03 +01:00
|
|
|
}
|
|
|
|
|
2017-10-05 22:32:03 +01:00
|
|
|
func NewBlacklist_crypto_des(id string, conf map[string]interface{}) (gas.Rule, []ast.Node) {
|
2016-11-13 20:55:31 +00:00
|
|
|
return &BlacklistImport{
|
2016-08-10 12:51:03 +01:00
|
|
|
MetaData: gas.MetaData{
|
2017-10-05 22:32:03 +01:00
|
|
|
ID: id,
|
2016-08-10 12:51:03 +01:00
|
|
|
Severity: gas.High,
|
|
|
|
Confidence: gas.High,
|
|
|
|
What: "Use of weak cryptographic primitive",
|
|
|
|
},
|
|
|
|
Path: `"crypto/des"`,
|
2016-11-13 20:55:31 +00:00
|
|
|
}, []ast.Node{(*ast.ImportSpec)(nil)}
|
2016-08-10 12:51:03 +01:00
|
|
|
}
|
2016-08-05 12:58:27 +01:00
|
|
|
|
2017-10-05 22:32:03 +01:00
|
|
|
func NewBlacklist_crypto_rc4(id string, conf map[string]interface{}) (gas.Rule, []ast.Node) {
|
2016-11-13 20:55:31 +00:00
|
|
|
return &BlacklistImport{
|
2016-08-10 12:51:03 +01:00
|
|
|
MetaData: gas.MetaData{
|
2017-10-05 22:32:03 +01:00
|
|
|
ID: id,
|
2016-08-10 12:51:03 +01:00
|
|
|
Severity: gas.High,
|
|
|
|
Confidence: gas.High,
|
|
|
|
What: "Use of weak cryptographic primitive",
|
|
|
|
},
|
|
|
|
Path: `"crypto/rc4"`,
|
2016-11-13 20:55:31 +00:00
|
|
|
}, []ast.Node{(*ast.ImportSpec)(nil)}
|
2016-08-10 12:51:03 +01:00
|
|
|
}
|
|
|
|
|
2017-10-05 22:32:03 +01:00
|
|
|
func NewBlacklist_net_http_cgi(id string, conf map[string]interface{}) (gas.Rule, []ast.Node) {
|
2016-11-13 20:55:31 +00:00
|
|
|
return &BlacklistImport{
|
2016-08-10 12:51:03 +01:00
|
|
|
MetaData: gas.MetaData{
|
2017-10-05 22:32:03 +01:00
|
|
|
ID: id,
|
2016-08-10 12:51:03 +01:00
|
|
|
Severity: gas.High,
|
|
|
|
Confidence: gas.High,
|
2016-11-13 20:55:31 +00:00
|
|
|
What: "Go versions < 1.6.3 are vulnerable to Httpoxy attack: (CVE-2016-5386)",
|
2016-08-10 12:51:03 +01:00
|
|
|
},
|
|
|
|
Path: `"net/http/cgi"`,
|
2016-11-13 20:55:31 +00:00
|
|
|
}, []ast.Node{(*ast.ImportSpec)(nil)}
|
2016-08-05 12:58:27 +01:00
|
|
|
}
|