mirror of
https://github.com/securego/gosec.git
synced 2024-12-25 12:05:52 +00:00
Add a rule to detect the usage of ssh InsecureIgnoreHostKey function
This commit is contained in:
parent
8b87505d97
commit
d3c3cd6419
4 changed files with 61 additions and 0 deletions
|
@ -65,6 +65,7 @@ func Generate(filters ...RuleFilter) RuleList {
|
||||||
"G103": RuleDefinition{"Audit the use of unsafe block", NewUsingUnsafe},
|
"G103": RuleDefinition{"Audit the use of unsafe block", NewUsingUnsafe},
|
||||||
"G104": RuleDefinition{"Audit errors not checked", NewNoErrorCheck},
|
"G104": RuleDefinition{"Audit errors not checked", NewNoErrorCheck},
|
||||||
"G105": RuleDefinition{"Audit the use of big.Exp function", NewUsingBigExp},
|
"G105": RuleDefinition{"Audit the use of big.Exp function", NewUsingBigExp},
|
||||||
|
"G106": RuleDefinition{"Audit the use of ssh.InsecureIgnoreHostKey function", NewSSHHostKey},
|
||||||
|
|
||||||
// injection
|
// injection
|
||||||
"G201": RuleDefinition{"SQL query construction using format string", NewSQLStrFormat},
|
"G201": RuleDefinition{"SQL query construction using format string", NewSQLStrFormat},
|
||||||
|
|
|
@ -65,6 +65,10 @@ var _ = Describe("gas rules", func() {
|
||||||
runner("G105", testutils.SampleCodeG105)
|
runner("G105", testutils.SampleCodeG105)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should detect of ssh.InsecureIgnoreHostKey function", func() {
|
||||||
|
runner("G106", testutils.SampleCodeG106)
|
||||||
|
})
|
||||||
|
|
||||||
It("should detect sql injection via format strings", func() {
|
It("should detect sql injection via format strings", func() {
|
||||||
runner("G201", testutils.SampleCodeG201)
|
runner("G201", testutils.SampleCodeG201)
|
||||||
})
|
})
|
||||||
|
|
47
rules/ssh.go
Normal file
47
rules/ssh.go
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
// (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"
|
||||||
|
|
||||||
|
"github.com/GoASTScanner/gas"
|
||||||
|
)
|
||||||
|
|
||||||
|
type sshHostKey struct {
|
||||||
|
gas.MetaData
|
||||||
|
pkg string
|
||||||
|
calls []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *sshHostKey) Match(n ast.Node, c *gas.Context) (gi *gas.Issue, err error) {
|
||||||
|
if _, matches := gas.MatchCallByPackage(n, c, r.pkg, r.calls...); matches {
|
||||||
|
return gas.NewIssue(c, n, r.What, r.Severity, r.Confidence), nil
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSSHHostKey rule detects the use of insecure ssh HostKeyCallback.
|
||||||
|
func NewSSHHostKey(conf gas.Config) (gas.Rule, []ast.Node) {
|
||||||
|
return &sshHostKey{
|
||||||
|
pkg: "golang.org/x/crypto/ssh",
|
||||||
|
calls: []string{"InsecureIgnoreHostKey"},
|
||||||
|
MetaData: gas.MetaData{
|
||||||
|
What: "Use of ssh InsecureIgnoreHostKey should be audited",
|
||||||
|
Severity: gas.Medium,
|
||||||
|
Confidence: gas.High,
|
||||||
|
},
|
||||||
|
}, []ast.Node{(*ast.CallExpr)(nil)}
|
||||||
|
}
|
|
@ -183,6 +183,15 @@ func main() {
|
||||||
z = z.Exp(x, y, m)
|
z = z.Exp(x, y, m)
|
||||||
}`, 1}}
|
}`, 1}}
|
||||||
|
|
||||||
|
// SampleCodeG106 - ssh InsecureIgnoreHostKey
|
||||||
|
SampleCodeG106 = []CodeSample{{`
|
||||||
|
package main
|
||||||
|
import (
|
||||||
|
"golang.org/x/crypto/ssh"
|
||||||
|
)
|
||||||
|
func main() {
|
||||||
|
_ := ssh.InsecureIgnoreHostKey()
|
||||||
|
}`, 1}}
|
||||||
// SampleCodeG201 - SQL injection via format string
|
// SampleCodeG201 - SQL injection via format string
|
||||||
SampleCodeG201 = []CodeSample{
|
SampleCodeG201 = []CodeSample{
|
||||||
{`
|
{`
|
||||||
|
|
Loading…
Reference in a new issue