Skip to content

Commit

Permalink
Moved main package to project's root
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin JEROME <[email protected]>
  • Loading branch information
qjerome committed Sep 13, 2023
1 parent d7c0f75 commit 8b3471a
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 26 deletions.
6 changes: 1 addition & 5 deletions coverage.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#!/bin/bash
set -e

pkgs=("./engine" "./reducer")

tmp=$(mktemp -d)
coverprofile="${tmp}/coverage.out"
coverage_dir=".github/coverage"
tmp_out="${tmp}/coverage.txt"
out="${coverage_dir}/coverage.txt"
commit=$(git rev-parse HEAD)


GOOS=linux go test -short -failfast -coverprofile="${coverprofile}" ${pkgs[*]}
GOOS=linux go test -short -failfast -coverprofile="${coverprofile}" ./...
go tool cover -func "${coverprofile}" | tee "${tmp_out}"

mkdir -p "${coverage_dir}"
Expand Down
31 changes: 14 additions & 17 deletions gene/gene.go → gene.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/0xrawsec/gene/v2/engine"
"github.com/0xrawsec/gene/v2/reducer"
"github.com/0xrawsec/gene/v2/template"
"github.com/0xrawsec/golang-evtx/evtx"
"github.com/0xrawsec/golang-utils/args"
"github.com/0xrawsec/golang-utils/datastructs"
Expand Down Expand Up @@ -89,7 +90,7 @@ func jsonEventGenerator() (ec chan *evtx.GoEvtxMap) {
// Printing Progress
eventCnt++
if flShowProgress && eventCnt >= oldEventCnt {
delta := time.Now().Sub(start)
delta := time.Since(start)
prog.Update(fmt.Sprintf("%d (%2.f EPS)", eventCnt, float64(eventCnt)/delta.Seconds()))
prog.Print()
oldEventCnt = eventCnt + cntChunk
Expand Down Expand Up @@ -122,7 +123,7 @@ func evtxEventGenerator() (ec chan *evtx.GoEvtxMap) {
for event := range ef.UnorderedEvents() {
eventCnt++
if flShowProgress && eventCnt >= oldEventCnt {
delta := time.Now().Sub(start)
delta := time.Since(start)
prog.Update(fmt.Sprintf("%d (%2.f EPS)", eventCnt, float64(eventCnt)/delta.Seconds()))
prog.Print()
oldEventCnt = eventCnt + cntChunk
Expand All @@ -142,9 +143,8 @@ func printInfo(writer io.Writer) {
}

var (
criticalityPath = evtx.Path("/Event/GeneInfo/Criticality")
sigPath = evtx.Path("/Event/GeneInfo/Signature")
computerPath = evtx.Path("/Event/System/Computer")
sigPath = evtx.Path("/Event/GeneInfo/Signature")
computerPath = evtx.Path("/Event/System/Computer")
)

func reduce(e *engine.Engine) {
Expand Down Expand Up @@ -218,8 +218,6 @@ var (
rulesPath string
ruleExts = args.ListVar{".gen", ".gene"}
jobs = 1

tplExt = ".toml"
)

func main() {
Expand Down Expand Up @@ -284,17 +282,16 @@ func main() {

// Display rule template and exit if template flag
if flTemplate {
r := engine.NewRule()
r.Name = "ReplaceRuleName"
// metadata
r.Meta.Events["SomeEventSource"] = []int64{42}
r.Meta.Attack = append(r.Meta.Attack, engine.Attack{})
r.Meta.OSs = []string{"linux", "windows"}
r.Meta.Criticality = 5

r := engine.Rule{}
json.Unmarshal([]byte(template.RuleTemplate), &r)

// marshaling the stuff out
b, err := json.Marshal(r)
if err != nil {
log.Abort(exitFail, err)
}

fmt.Println(string(b))
os.Exit(exitSuccess)
}
Expand Down Expand Up @@ -360,7 +357,7 @@ func main() {

// actual rule loading
if err := e.LoadDirectory(realPath); err != nil {
log.Abort(exitFail, fmt.Errorf("Failed at loading rule directory %s: %s", realPath, err))
log.Abort(exitFail, fmt.Errorf("failed at loading rule directory %s: %s", realPath, err))
}

// Show message about successfuly compiled rules
Expand All @@ -369,7 +366,7 @@ func main() {
// If we just wanted to verify the rules, we should exit whatever
// the status of the compilation
if flVerify {
log.Infof("Rule(s) compilation: SUCCESSFUL")
log.Infof("Rule(s) compilation: SUCCESSFUL")
os.Exit(exitSuccess)
}

Expand All @@ -395,7 +392,7 @@ func main() {
tags := e.Tags()
sort.Strings(tags)
for _, t := range tags {
fmt.Println(fmt.Sprintf("\t%s", t))
fmt.Printf("\t%s\n", t)
}
os.Exit(exitSuccess)
}
Expand Down
3 changes: 0 additions & 3 deletions make.sh

This file was deleted.

2 changes: 1 addition & 1 deletion gene/makefile → makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ ci-build: buildversion
go build $(OPTS) -o $(shell mktemp) ./

clean:
rm -rf $(RELEASE)/*
rm -rf $(RELEASE)/*
47 changes: 47 additions & 0 deletions template/template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package template

var (
RuleTemplate = `
{
"Name": "RuleName",
"Tags": [],
"Meta": {
"LogType": "winevt",
"Events": {
"SomeEventSource": [
42
]
},
"OSs": [
"linux",
"windows"
],
"Computers": [],
"ATTACK": [
{
"ID": "T4242",
"Tactic": "",
"Reference": "https://attack.mitre.org/T4242"
}
],
"Criticality": 5,
"Disable": false,
"Filter": false,
"Schema": "2.0.0",
"Authors": [
"@rawsec"
],
"Comments": [
"Rule catching technique documented in the following link",
"https://super.ttp.com"
]
},
"Matches": [
"$a: SomeField = '42'",
"$b: /Absolute/Field/Path ~= 'SomeRegex'"
],
"Condition": "$a or $b",
"Actions": []
}
`
)
17 changes: 17 additions & 0 deletions template/template_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package template

import (
"testing"

"github.com/0xrawsec/gene/v2/engine"
"github.com/0xrawsec/toast"
)

// we make sure rule Template compiles properly
func TestTemplate(t *testing.T) {
tt := toast.FromT(t)

e := engine.NewEngine()

tt.CheckErr(e.LoadString(RuleTemplate))
}
6 changes: 6 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

const(
version="2.3.0"
commitID="d7c0f7585397ff99ac1ed8038204c41599314cc3"
)

0 comments on commit 8b3471a

Please sign in to comment.