2022-05-04 22:08:11 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2022-05-25 16:35:44 +00:00
|
|
|
"os"
|
|
|
|
|
2022-05-04 22:08:11 +00:00
|
|
|
"github.com/go-errors/errors"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
"google.golang.org/protobuf/types/known/anypb"
|
|
|
|
|
2022-08-29 18:45:37 +00:00
|
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
|
|
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
|
2022-05-04 22:08:11 +00:00
|
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/sourcespb"
|
2022-08-10 17:11:13 +00:00
|
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
|
2022-05-04 22:08:11 +00:00
|
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/sources/syslog"
|
|
|
|
)
|
|
|
|
|
2022-08-10 17:11:13 +00:00
|
|
|
// ScanSyslog is a source that scans syslog files.
|
2022-08-12 16:56:24 +00:00
|
|
|
func (e *Engine) ScanSyslog(ctx context.Context, c sources.Config) error {
|
2022-05-04 22:08:11 +00:00
|
|
|
connection := &sourcespb.Syslog{
|
2022-08-10 17:11:13 +00:00
|
|
|
Protocol: c.Protocol,
|
|
|
|
ListenAddress: c.Address,
|
|
|
|
Format: c.Format,
|
2022-05-04 22:08:11 +00:00
|
|
|
}
|
|
|
|
|
2022-08-10 17:11:13 +00:00
|
|
|
if c.CertPath != "" && c.KeyPath != "" {
|
|
|
|
cert, err := os.ReadFile(c.CertPath)
|
2022-05-04 22:08:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.WrapPrefix(err, "could not open TLS cert file", 0)
|
|
|
|
}
|
|
|
|
connection.TlsCert = string(cert)
|
|
|
|
|
2022-08-10 17:11:13 +00:00
|
|
|
key, err := os.ReadFile(c.KeyPath)
|
2022-05-04 22:08:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.WrapPrefix(err, "could not open TLS key file", 0)
|
|
|
|
}
|
|
|
|
connection.TlsKey = string(key)
|
|
|
|
}
|
|
|
|
|
|
|
|
var conn anypb.Any
|
|
|
|
err := anypb.MarshalFrom(&conn, connection, proto.MarshalOptions{})
|
|
|
|
if err != nil {
|
|
|
|
return errors.WrapPrefix(err, "error unmarshalling connection", 0)
|
|
|
|
}
|
|
|
|
source := syslog.Source{}
|
2023-02-10 17:02:55 +00:00
|
|
|
ctx = context.WithValues(ctx,
|
|
|
|
"source_type", source.Type().String(),
|
|
|
|
"source_name", "syslog",
|
|
|
|
)
|
2022-08-10 17:11:13 +00:00
|
|
|
err = source.Init(ctx, "trufflehog - syslog", 0, 0, false, &conn, c.Concurrency)
|
2022-05-04 22:08:11 +00:00
|
|
|
source.InjectConnection(connection)
|
|
|
|
if err != nil {
|
2023-02-09 22:55:19 +00:00
|
|
|
ctx.Logger().Error(err, "failed to initialize syslog source")
|
2022-05-04 22:08:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-25 16:35:44 +00:00
|
|
|
e.sourcesWg.Add(1)
|
2022-05-04 22:08:11 +00:00
|
|
|
go func() {
|
2022-09-22 14:01:10 +00:00
|
|
|
defer common.RecoverWithExit(ctx)
|
2022-05-25 16:35:44 +00:00
|
|
|
defer e.sourcesWg.Done()
|
2022-05-04 22:08:11 +00:00
|
|
|
err := source.Chunks(ctx, e.ChunksChan())
|
|
|
|
if err != nil {
|
2023-02-09 22:55:19 +00:00
|
|
|
ctx.Logger().Error(err, "could not scan syslog")
|
2022-05-04 22:08:11 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
return nil
|
|
|
|
}
|