@@ -3,16 +3,15 @@ package main
3
3
import (
4
4
"go-importer/internal/pkg/db"
5
5
6
- "fmt"
7
- "net"
8
- "strconv"
9
-
10
6
"flag"
7
+ "fmt"
11
8
"io/ioutil"
12
9
"log"
10
+ "net"
13
11
"os"
14
12
"os/signal"
15
13
"path/filepath"
14
+ "strconv"
16
15
"strings"
17
16
"sync"
18
17
"time"
@@ -32,8 +31,6 @@ var checksum = false
32
31
var nohttp = true
33
32
34
33
var snaplen = 65536
35
- var ticklength = - 1
36
- var flaglifetime = - 1
37
34
var tstype = ""
38
35
var promisc = true
39
36
@@ -44,6 +41,11 @@ var pcap_over_ip = flag.String("pcap-over-ip", "", "PCAP-over-IP host + port (e.
44
41
var bpf = flag .String ("bpf" , "" , "BPF filter" )
45
42
var nonstrict = flag .Bool ("nonstrict" , false , "Do not check strict TCP / FSM flags" )
46
43
var experimental = flag .Bool ("experimental" , false , "Enable experimental features." )
44
+
45
+ var flagid = flag .Bool ("flagid" , false , "Check for flagids in traffic (must be present in mong)" )
46
+ var ticklength = * flag .Int ("tick length" , - 1 , "the length (in seconds) of a tick" )
47
+ var flaglifetime = * flag .Int ("flag lifetime" , - 1 , "the lifetime of a flag in ticks" )
48
+
47
49
var flushAfter = flag .String ("flush-after" , "30s" , `(TCP) Connections which have buffered packets (they've gotten packets out of order and
48
50
are waiting for old packets to fill the gaps) can be flushed after they're this old
49
51
(their oldest gap is skipped). This is particularly useful for pcap-over-ip captures.
@@ -74,14 +76,15 @@ func reassemblyCallback(entry db.FlowEntry) {
74
76
ApplyFlagTags (& entry , flag_regex )
75
77
}
76
78
77
- //Apply flagid
78
- flagids , err := g_db .GetFlagids (flaglifetime )
79
- if err != nil {
80
- log .Fatal (err )
79
+ //Apply flagid in / out
80
+ if * flagid {
81
+ flagids , err := g_db .GetFlagids (flaglifetime )
82
+ if err != nil {
83
+ log .Fatal (err )
84
+ }
85
+ ApplyFlagids (& entry , flagids )
81
86
}
82
87
83
- ApplyFlagids (& entry , flagids )
84
-
85
88
// Finally, insert the new entry
86
89
g_db .InsertFlow (entry )
87
90
}
@@ -159,7 +162,7 @@ func main() {
159
162
160
163
// get TICK_LENGTH
161
164
strticklength := os .Getenv ("TICK_LENGTH" )
162
- if strticklength != "" {
165
+ if ticklength == - 1 && strticklength != "" {
163
166
zwi , err := strconv .ParseInt (strticklength , 10 , 64 )
164
167
if err != nil {
165
168
log .Println ("Error: " , err )
@@ -170,7 +173,7 @@ func main() {
170
173
171
174
// get Flag_LIFETIME
172
175
strflaglifetime := os .Getenv ("FLAG_LIFETIME" )
173
- if strticklength != "" {
176
+ if flaglifetime == - 1 && strticklength != "" {
174
177
zwi , err := strconv .Atoi (strflaglifetime )
175
178
if err != nil {
176
179
log .Println ("Error: " , err )
@@ -201,6 +204,13 @@ func main() {
201
204
* pcap_over_ip = os .Getenv ("PCAP_OVER_IP" )
202
205
}
203
206
207
+ // if flagid scans should be done
208
+ if ! * flagid {
209
+ flagid_val := os .Getenv ("FLAGID_SCAN" )
210
+ * flagid = flagid_val != "" && flagid_val != "0" && ! strings .EqualFold (flagid_val , "false" )
211
+
212
+ }
213
+
204
214
if * bpf == "" {
205
215
* bpf = os .Getenv ("BPF" )
206
216
}
0 commit comments