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/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.
|
2023-02-10 20:43:00 +00:00
|
|
|
func (e *Engine) ScanSyslog(ctx context.Context, c sources.SyslogConfig) 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)
|
|
|
|
}
|
2023-08-03 18:36:30 +00:00
|
|
|
|
|
|
|
handle, err := e.sourceManager.Enroll(ctx, "trufflehog - syslog", new(syslog.Source).Type(),
|
|
|
|
func(ctx context.Context, jobID, sourceID int64) (sources.Source, error) {
|
|
|
|
syslogSource := syslog.Source{}
|
|
|
|
if err := syslogSource.Init(ctx, "trufflehog - syslog", jobID, sourceID, true, &conn, c.Concurrency); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
syslogSource.InjectConnection(connection)
|
|
|
|
return &syslogSource, nil
|
|
|
|
})
|
2022-05-04 22:08:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-08-03 18:36:30 +00:00
|
|
|
_, err = e.sourceManager.ScheduleRun(ctx, handle)
|
|
|
|
return err
|
2022-05-04 22:08:11 +00:00
|
|
|
}
|