71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
package exploit
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/samber/lo"
|
|
|
|
"github.com/c4t-but-s4d/neo/v2/internal/models"
|
|
)
|
|
|
|
type FarmRequest struct {
|
|
Flag string `json:"flag"`
|
|
Exploit string `json:"sploit"`
|
|
Team string `json:"team"`
|
|
}
|
|
|
|
type FullResult struct {
|
|
Exploit *models.Exploit
|
|
Target *models.Target
|
|
Flag string
|
|
}
|
|
|
|
func NewFullResult(exploit *models.Exploit, target *models.Target, flag string) *FullResult {
|
|
return &FullResult{
|
|
Exploit: exploit,
|
|
Target: target,
|
|
Flag: flag,
|
|
}
|
|
}
|
|
|
|
func (r *FullResult) FarmRequest() *FarmRequest {
|
|
return &FarmRequest{
|
|
Flag: r.Flag,
|
|
Exploit: "[neo] " + r.Exploit.ID,
|
|
Team: r.Target.ID,
|
|
}
|
|
}
|
|
|
|
func (r *FullResult) MetricLabels() prometheus.Labels {
|
|
return lo.Assign(r.Exploit.MetricLabels(), r.Target.MetricLabels())
|
|
}
|
|
|
|
type State struct {
|
|
ID string
|
|
Version int64
|
|
Dir string
|
|
Path string
|
|
Disabled bool
|
|
Endless bool
|
|
RunEvery time.Duration
|
|
LastRun time.Time
|
|
ScaledTimeout time.Duration
|
|
Timeout time.Duration
|
|
}
|
|
|
|
func (s *State) ExploitType() models.ExploitType {
|
|
if s.Endless {
|
|
return models.ExploitTypeEndless
|
|
}
|
|
return models.ExploitTypeRecurrent
|
|
}
|
|
|
|
func (s *State) ToModel() *models.Exploit {
|
|
return &models.Exploit{
|
|
ID: s.ID,
|
|
Version: s.Version,
|
|
Type: s.ExploitType(),
|
|
}
|
|
}
|