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"
|
|
|
|
|
2017-04-26 16:08:46 +01:00
|
|
|
"github.com/GoASTScanner/gas"
|
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
|
|
|
}
|
|
|
|
|
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-04-28 22:46:26 +01:00
|
|
|
func NewBlacklist_crypto_md5(conf gas.Config) (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{
|
|
|
|
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-04-28 22:46:26 +01:00
|
|
|
func NewBlacklist_crypto_des(conf gas.Config) (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{
|
|
|
|
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-04-28 22:46:26 +01:00
|
|
|
func NewBlacklist_crypto_rc4(conf gas.Config) (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{
|
|
|
|
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-04-28 22:46:26 +01:00
|
|
|
func NewBlacklist_net_http_cgi(conf gas.Config) (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{
|
|
|
|
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
|
|
|
}
|