* private key analyzer initial impl - basic structure * Impl analyzePermission method for PrivateKey analyzer. export few private functions for reusability in analyzers * add permissions.yaml and generate permissions * permissions fix * AnalyzeAndPrintPermissions impl * analyzer test pushed * Impl analyzer func called from detector. added and regenerated permissions. * filter empty strings in result and generate expected_output for test * some refactoring * comment added for better readability. * fixed code breaking changes in detectors due to exporting private functions. * log insufficient information message on no certificate results
38 lines
680 B
Go
38 lines
680 B
Go
package privatekey
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/x509"
|
|
_ "embed"
|
|
"errors"
|
|
|
|
"golang.org/x/crypto/ssh"
|
|
)
|
|
|
|
//go:embed "list.txt"
|
|
var rawCrackList []byte
|
|
var passphrases [][]byte
|
|
|
|
func init() {
|
|
passphrases = bytes.Split(rawCrackList, []byte("\n"))
|
|
}
|
|
|
|
var (
|
|
ErrUncrackable = errors.New("unable to crack encryption")
|
|
)
|
|
|
|
func Crack(in []byte) (any, string, error) {
|
|
for _, passphrase := range passphrases {
|
|
parsed, err := ssh.ParseRawPrivateKeyWithPassphrase(in, passphrase)
|
|
if err != nil {
|
|
if errors.Is(err, x509.IncorrectPasswordError) {
|
|
continue
|
|
} else {
|
|
return nil, "", err
|
|
}
|
|
}
|
|
return parsed, string(passphrase), nil
|
|
}
|
|
return nil, "", ErrUncrackable
|
|
}
|