-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
714 lines (664 loc) · 20.8 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
package main
import (
"bytes"
"crypto/sha256"
"flag"
"fmt"
"github.com/D4-project/d4-pretensor/pretensorhit"
"golang.org/x/net/proxy"
"io"
"log"
"net"
"net/http"
"os"
"os/signal"
"path/filepath"
"strconv"
"strings"
"sync"
"time"
"github.com/D4-project/d4-golang-utils/config"
"github.com/gomodule/redigo/redis"
rg "github.com/redislabs/redisgraph-go"
gj "github.com/tidwall/gjson"
)
type (
redisconf struct {
redisHost string
redisPort string
databasename string
}
bindesc struct {
url string
phit *pretensorhit.PHit
}
filedesc struct {
path string
info os.FileInfo
}
)
// Setting up Flags and other Vars
var (
confdir = flag.String("c", "conf.sample", "configuration directory")
folder = flag.String("log_folder", "logs", "folder containing mod security logs")
debug = flag.Bool("d", false, "debug output")
verbose = flag.Bool("v", false, "additional debug output")
delete = flag.Bool("D", false, "Delete previous graph")
d4 = flag.Bool("r", false, "Connect to redis - d4 to get new files")
tmprate, _ = time.ParseDuration("5s")
rate = flag.Duration("rl", tmprate, "Rate limiter: time in human format before retry after EOF")
buf bytes.Buffer
logger = log.New(&buf, "INFO: ", log.Lshortfile)
redisConn redis.Conn
redisConnPretensor redis.Conn
redisGR redis.Conn
redisPretensorPool *redis.Pool
redisd4Pool *redis.Pool
redisd4Queue string
tomonitor [][]byte
mitm [][]byte
curls map[string]string
// Keeps a map of sha/hash to keep track of what we downloaded already
binurls map[string]*pretensorhit.PHit
bashs map[string]*pretensorhit.PHit
wg sync.WaitGroup
walk_folder = true
checkredisd4 = true
binchan chan bindesc
filechan chan filedesc
bashchan chan bindesc
)
func main() {
// Setting up log file
f, err := os.OpenFile("pretensor.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
// Create infected folder if not exist
if _, err := os.Stat("infected"); os.IsNotExist(err) {
os.Mkdir("infected", 0750)
}
// Create infected_bash folder if not exist
if _, err := os.Stat("infected_bash"); os.IsNotExist(err) {
os.Mkdir("infected_bash", 0750)
}
defer f.Close()
logger.SetOutput(f)
logger.SetFlags(log.LstdFlags | log.Lshortfile)
logger.Println("Init")
// Setting up Graceful killing
sortie := make(chan os.Signal, 1)
signal.Notify(sortie, os.Interrupt, os.Kill)
// Signal goroutine
go func() {
<-sortie
logger.Println("Exiting")
os.Exit(0)
}()
// Usage
flag.Usage = func() {
fmt.Printf("d4 - d4-pretensor\n")
fmt.Printf("Parses Mod Security logs into Redis Graph \n")
fmt.Printf("from a folder first to bootstrap a redis graph, \n")
fmt.Printf("and then from d4 to update it. \n")
fmt.Printf("\n")
fmt.Printf("Usage: d4-pretensor -c config_directory\n")
fmt.Printf("\n")
fmt.Printf("Configuration\n\n")
fmt.Printf("The configuration settings are stored in files in the configuration directory\n")
fmt.Printf("specified with the -c command line switch.\n\n")
fmt.Printf("Files in the configuration directory\n")
fmt.Printf("\n")
fmt.Printf("redis_pretensor - host:port/graphname\n")
fmt.Printf("redis_d4 - host:port/db\n")
fmt.Printf("redis_d4_queue - d4 queue to pop\n")
fmt.Printf("folder - folder containing mod security logs\n")
fmt.Printf("tomonitor - list of requests to monitor (botnet activity)\n")
fmt.Printf("mitm - list of mitm proxy to remove\n")
fmt.Printf("\n")
flag.PrintDefaults()
}
// Parse Flags
flag.Parse()
if flag.NFlag() == 0 || *confdir == "" {
flag.Usage()
sortie <- os.Kill
} else {
*confdir = strings.TrimSuffix(*confdir, "/")
*confdir = strings.TrimSuffix(*confdir, "\\")
}
// Check redis-pretensor configuration
rrg := redisconf{}
// Parse Input Redis Config
tmp := config.ReadConfigFile(*confdir, "redis_pretensor")
ss := strings.Split(string(tmp), "/")
if len(ss) <= 1 {
log.Fatal("Missing Database in redis_pretensor input config: should be host:port/database_name")
}
rrg.databasename = ss[1]
var ret bool
ret, ss[0] = config.IsNet(ss[0])
if ret {
sss := strings.Split(string(ss[0]), ":")
rrg.redisHost = sss[0]
rrg.redisPort = sss[1]
} else {
logger.Fatal("Redis-pretensor config error.")
}
// Create a new redis-pretensor connection pool
redisPretensorPool = newPool(rrg.redisHost+":"+rrg.redisPort, 400)
redisConnPretensor, err = redisPretensorPool.Dial()
if err != nil {
logger.Fatal("Could not connect to redis-pretensor Redis")
}
rd4 := redisconf{}
if *d4 {
// Check redis-d4 configuration
// Parse Input Redis Config
tmp = config.ReadConfigFile(*confdir, "redis_d4")
ss = strings.Split(string(tmp), "/")
if len(ss) <= 1 {
logger.Println("Missing Database in redis_d4 input config: should be host:port/database_name -- Skipping")
checkredisd4 = false
} else {
rd4.databasename = ss[1]
ret, ss[0] = config.IsNet(ss[0])
if ret {
sss := strings.Split(string(ss[0]), ":")
rrg.redisHost = sss[0]
rrg.redisPort = sss[1]
} else {
logger.Fatal("Redis-d4 config error.")
}
// Create a new redis-graph connection pool
redisd4Pool = newPool(rrg.redisHost+":"+rrg.redisPort, 400)
redisConn, err = redisd4Pool.Dial()
if err != nil {
logger.Fatal("Could not connect to d4 Redis")
}
// Get that the redis_d4_queue file
redisd4Queue = string(config.ReadConfigFile(*confdir, "redis_d4_queue"))
}
}
// Checking that the log folder exists
log_folder := string(config.ReadConfigFile(*confdir, "folder"))
_, err = os.ReadDir(log_folder)
if err != nil {
logger.Println(err)
walk_folder = false
}
// Loading Requests to monitor
tomonitor = config.ReadConfigFileLines(*confdir, "tomonitor")
// Loading proxy list to remove from Hosts
mitm = config.ReadConfigFileLines(*confdir, "mitm")
// Init maps
curls = make(map[string]string)
bashs = make(map[string]*pretensorhit.PHit)
binurls = make(map[string]*pretensorhit.PHit)
// Init redis graph
graph := rg.GraphNew("pretensor", redisConnPretensor)
if *delete {
graph.Delete()
}
// Create processing channels
binchan = make(chan bindesc, 2000)
bashchan = make(chan bindesc, 2000)
// Unbuffered channel for the parser
filechan = make(chan filedesc)
wg.Add(3)
// Launch the download routine
go downloadBin(binchan, sortie)
// Write no ELF files to files
go writeBashs(bashchan, sortie)
// Launch the Pretensor routine
// Leaving the existing redis connection to pretensorParse
go pretensorParse(filechan, sortie, &graph)
// Walking folder
err = filepath.Walk(log_folder,
func(path string, info os.FileInfo, err error) error {
filechan <- filedesc{path: path, info: info}
if err != nil {
return err
}
if *verbose {
logger.Println(info.Name(), info.Size())
}
return nil
})
if checkredisd4 && *d4 {
redisConnD4, err := redisd4Pool.Dial()
if err != nil {
logger.Fatal("Could not connect to d4 Redis")
}
if _, err := redisConnD4.Do("SELECT", rd4.databasename); err != nil {
redisConnD4.Close()
logger.Println(err)
return
}
// Once the walk is over, we start listening to d4 to get new files
rateLimiter := time.Tick(*rate)
redisNormal:
err = redisRead(redisConnD4, redisd4Queue)
for {
select {
case <-rateLimiter:
// Use the ratelimiter while the connection hangs
logger.Println("Limited read")
goto redisNormal
case <-sortie:
goto gtfo
}
}
}
//// Write curl commands to a file
//for _, v := range curls {
// f, err := os.OpenFile("./infected/curl.sh", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
// if err != nil {
// logger.Println(err)
// }
// if _, err := f.Write([]byte(fmt.Sprintf("%v\n", v))); err != nil {
// f.Close()
// logger.Println(err)
// }
// if err := f.Close(); err != nil {
// logger.Println(err)
// }
//}
// Waiting for the binary handling routines
wg.Wait()
gtfo:
logger.Println("Exiting")
}
func redisRead(redisConnD4 redis.Conn, redisd4Queue string) error {
for {
buf, err := redis.String(redisConnD4.Do("LPOP", redisd4Queue))
// If redis return empty: EOF (user should not stop)
if err == redis.ErrNil {
// no new record we break until the tick
return io.EOF
// oops
} else if err != nil {
logger.Println(err)
return err
}
fileinfo, err := os.Stat(buf)
if err != nil {
logger.Println(err)
return err
}
filechan <- filedesc{path: buf, info: fileinfo}
}
}
// Parsing whatever is thrown into filechan
func pretensorParse(filechan chan filedesc, sortie chan os.Signal, graph *rg.Graph) error {
logger.Println("Entering pretensorparse")
defer wg.Done()
for {
select {
case file := <-filechan:
if *debug {
logger.Println(file.path)
}
info := file.info
path := file.path
if !info.IsDir() {
content, err := os.ReadFile(path)
if err != nil {
return err
}
if len(content) == 0 {
if *debug {
logger.Println("Empty File: " + path)
}
break
}
// Load JSON
contents := string(content)
if !gj.Valid(contents) {
if *debug {
logger.Println("Invalid json: " + path)
}
break
}
// For each request to monitor
for _, v := range tomonitor {
request := gj.Get(contents, "request.request_line")
if strings.Contains(request.String(), string(v)) {
// We are in a file of interest
tmp := new(pretensorhit.PHit)
tmp.SetTimestamp(gj.Get(contents, "transaction.time"))
tmp.SetIp(gj.Get(contents, "transaction.remote_address"))
tmp.SetLine(gj.Get(contents, "request.request_line"))
tmp.SetReferer(gj.Get(contents, "request.headers.Referer"))
tmp.SetUseragent(gj.Get(contents, "request.headers.User-Agent"))
tmp.SetStatus(gj.Get(contents, "response.status"))
tmp.SetBody(gj.Get(contents, "response.body"))
tmp.SetContenttype(gj.Get(contents, "response.headers.Content-Type"))
tmp.SetLength(gj.Get(contents, "response.headers.Content-Length"))
tmp.SetHost(removeMitm(gj.Get(contents, "request.headers.Host")))
// Complete the graph
// Create bot if not exist
query := `MATCH (b:Bot {ip:"` + tmp.GetIp() + `"}) RETURN b.ip, b.firstseen, b.lastseen`
result, err := graph.Query(query)
if err != nil {
fmt.Println(err)
fmt.Println(result)
}
if result.Empty() {
if *debug {
logger.Println(tmp.GetBotNode())
}
graph.AddNode(tmp.GetBotNode())
_, err := graph.Flush()
if err != nil {
fmt.Println(err)
}
// Update Firstseen / Lastseen if already seen
} else {
result.Next()
r := result.Record()
fsstr, _ := r.Get("b.firstseen")
lsstr, _ := r.Get("b.lastseen")
fs, _ := time.Parse("02/Jan/2006:15:04:05 -0700", fmt.Sprint(fsstr))
ls, _ := time.Parse("02/Jan/2006:15:04:05 -0700", fmt.Sprint(lsstr))
if tmp.GetParsedTimeStamp().Before(fs) {
query = `MATCH (b:Bot {ip:"` + tmp.GetIp() + `"})
SET b.firstseen="` + tmp.GetTimestamp() + `"`
result, err = graph.Query(query)
if err != nil {
fmt.Println(err)
}
}
if tmp.GetParsedTimeStamp().After(ls) {
query = `MATCH (b:Bot {ip:"` + tmp.GetIp() + `"})
SET b.lastseen="` + tmp.GetTimestamp() + `"`
result, err = graph.Query(query)
if err != nil {
fmt.Println(err)
}
}
}
// Create CC if not exist
query = `MATCH (c:CC {host:"` + tmp.GetHost() + `"}) RETURN c.host, c.firstseen, c.lastseen`
result, err = graph.Query(query)
if err != nil {
fmt.Println(err)
}
if result.Empty() {
graph.AddNode(tmp.GetCCNode())
_, err := graph.Flush()
if err != nil {
fmt.Println(err)
}
// Update Firstseen / Lastseen if already seen
} else {
result.Next()
r := result.Record()
fsstr, _ := r.Get("c.firstseen")
lsstr, _ := r.Get("c.lastseen")
fs, _ := time.Parse("02/Jan/2006:15:04:05 -0700", fmt.Sprint(fsstr))
ls, _ := time.Parse("02/Jan/2006:15:04:05 -0700", fmt.Sprint(lsstr))
if tmp.GetParsedTimeStamp().Before(fs) {
query = `MATCH (c:CC {host:"` + tmp.GetHost() + `"})
SET c.firstseen="` + tmp.GetTimestamp() + `"`
result, err = graph.Query(query)
if err != nil {
fmt.Println(err)
}
}
if tmp.GetParsedTimeStamp().After(ls) {
query = `MATCH (c:CC {host:"` + tmp.GetHost() + `"})
SET c.lastseen="` + tmp.GetTimestamp() + `"`
result, err = graph.Query(query)
if err != nil {
fmt.Println(err)
}
}
}
// Use Merge to create the relationship between the bot and the CC
query = `MATCH (b:Bot {ip:"` + tmp.GetIp() + `"})
MATCH (c:CC {host:"` + tmp.GetHost() + `"})
MERGE (b)-[r:reach {name: "reach"}]->(c)`
result, err = graph.Query(query)
if err != nil {
fmt.Println(err)
}
// If the bot downloaded a binary
if tmp.GetContenttype() == "application/octet-stream" && tmp.GetStatus() == "200" {
// Logging all bash scripts and curl commands to download binaries
if strings.Contains(fmt.Sprintf("%v", tmp.GetBody()), "ELF") {
//tmpsha256 := sha256.Sum256([]byte(tmp.Curl()))
//curls[fmt.Sprintf("%x", tmpsha256)] = tmp.Curl()
binchan <- bindesc{url: tmp.GetBinurl(), phit: tmp}
} else {
bashchan <- bindesc{url: tmp.GetBinurl(), phit: tmp}
}
// Create binary if not exist
query := `MATCH (bin` + tmp.GetBinaryMatchQuerySelector() + `) RETURN bin`
// The following is causing a panic -- it looks like a redigo issue
//query := `MATCH (bin:Binary` + tmp.GetBinaryMatchQuerySelector() + `) RETURN bin`
qres, err := graph.Query(query)
if err != nil {
fmt.Println(err)
}
if qres.Empty() {
//fmt.Println("Add binary: "+tmp.GetBinaryMatchQuerySelector())
graph.AddNode(tmp.GetBinaryNode())
_, err := graph.Flush()
if err != nil {
fmt.Println(err)
}
}
// Use Merge to create the relationship bot, binaries and CC
query = `MATCH (b:Bot {ip:"` + tmp.GetIp() + `"})
MATCH (c:CC {host:"` + tmp.GetHost() + `"})
MATCH (bin:Binary ` + tmp.GetBinaryMatchQuerySelector() + `)
MERGE (b)-[d:download {name: "download"}]->(bin)
MERGE (c)-[h:host {name: "host"}]->(bin)`
result, err = graph.Query(query)
if err != nil {
fmt.Println(err)
}
}
// Bot set a referer command
if tmp.GetCmdRawCommand() != "" {
// First we update what we know about this bot
query = `MATCH (b:Bot {ip:"` + tmp.GetIp() + `"})
MATCH (c:CC {host:"` + tmp.GetHost() + `"})
SET b.user="` + tmp.GetCmdUser() + `"
SET b.hostname="` + tmp.GetCmdHostname() + `"
SET b.fingerprint="` + tmp.GetCmdFingerprint() + `"
SET b.architecture="` + tmp.GetCmdArchitecture() + `"`
result, err = graph.Query(query)
if err != nil {
fmt.Println(err)
}
// Then we create a command node for this command
query = `MATCH (c:Command {rawcontent:"` + tmp.GetCmdRawCommand() + `"}) RETURN c.content`
result, err = graph.Query(query)
if err != nil {
fmt.Println(err)
}
if result.Empty() {
graph.AddNode(tmp.GetCommandNode())
_, err := graph.Flush()
if err != nil {
fmt.Println(err)
}
}
// Finally we tie the Bot and the issued Command
query = `MATCH (b:Bot {ip:"` + tmp.GetIp() + `"})
MATCH (c:CC {host:"` + tmp.GetHost() + `"})
MATCH (co:Command {rawcontent:"` + tmp.GetCmdRawCommand() + `"})
MERGE (b)-[e:execute {name: "execute"}]->(co)
MERGE (c)-[l:launch {name: "launch"}]->(co)`
result, err = graph.Query(query)
if err != nil {
fmt.Println(err)
}
}
if *verbose {
fmt.Println(tmp)
}
// We treated the request
break
}
}
}
case <-sortie:
return nil
}
}
}
// Write Bashs scripts to files
func writeBashs(bc chan bindesc, sortie chan os.Signal) error {
defer wg.Done()
for {
select {
case v := <-bc:
var err error
redisGR, err = redisPretensorPool.Dial()
if err != nil {
logger.Fatal("Could not connect routine to pretensor Redis")
}
graphGR := rg.GraphNew("pretensor", redisGR)
if _, ok := bashs[v.url]; !ok {
if *debug {
logger.Println("Writing " + v.url)
}
// Set Sha 256 hash to the object
if s, err := strconv.Atoi(v.phit.GetLength()); err == nil && s > 0 {
tmpsha256 := sha256.Sum256([]byte(v.phit.GetBody()))
v.phit.SetSha256(fmt.Sprintf("%x", tmpsha256))
// Add binary's hash to the graph
query := `MATCH (b:Bot {ip:"` + v.phit.GetIp() + `"})
MATCH (c:CC {host:"` + v.phit.GetHost() + `"})
MATCH (bin:Binary ` + v.phit.GetBinaryMatchQuerySelector() + `)
MERGE (b)-[d:download {name: "download"}]->(bin)
MERGE (c)-[h:host {name: "host"}]->(bin)
ON MATCH SET bin.sha256 = "` + v.phit.GetSha256() + `"`
result, err := graphGR.Query(query)
if err != nil {
logger.Println(err)
}
if *debug {
logger.Println(query)
logger.Println(result)
}
err = os.WriteFile("./infected_bash/"+v.phit.GetSha256(), []byte(v.phit.GetBody()), 0644)
if err != nil {
logger.Println(err)
}
}
// Update de binbash map
bashs[v.phit.GetBinurl()] = v.phit
} else if *debug {
logger.Println("Skipping bash " + v.url)
}
case <-sortie:
return nil
}
}
}
// Gathering Binaries ourselves
func downloadBin(phitchan chan bindesc, sortie chan os.Signal) error {
defer wg.Done()
downloading:
for {
select {
case vi := <-phitchan:
// Check whether we already touched it
if _, ok := binurls[vi.url]; !ok {
//do something here
var err error
redisGR, err = redisPretensorPool.Dial()
if err != nil {
logger.Fatal("Could not connect routine to pretensor Redis")
}
graphGR := rg.GraphNew("pretensor", redisGR)
if *debug {
logger.Println("Fetching " + vi.url)
}
// Set some options for our TCP dialer
dialer := net.Dialer{
Timeout: 15 * time.Second,
}
// create a socks5 dialer
dial, err := proxy.SOCKS5("tcp", "127.0.0.1:9050", nil, &dialer)
if err != nil {
logger.Println("can't connect to the proxy:", err)
os.Exit(1)
}
httpTransport := &http.Transport{}
httpClient := &http.Client{Transport: httpTransport}
// set our socks5 as the dialer
httpTransport.Dial = dial.Dial
// create a request
req, err := http.NewRequest("GET", vi.phit.GetBinurl(), nil)
req.Header.Set("User-Agent", "-")
if err != nil {
logger.Println("can't create request:", err)
}
// use the http client to fetch the page
resp, err := httpClient.Do(req)
if err != nil {
logger.Println("can't GET page:", err)
break downloading
}
defer resp.Body.Close()
// update the binurls map
binurls[vi.phit.GetBinurl()] = vi.phit
b, err := io.ReadAll(resp.Body)
if err != nil || len(b) < 1 {
logger.Println("error reading body:", err)
break downloading
}
tmpb := sha256.Sum256(b)
err = os.WriteFile("./infected/"+fmt.Sprintf("%x", tmpb), b, 0644)
if err != nil {
logger.Println(err)
break downloading
}
// Update the Go object with this sha
vi.phit.SetSha256(fmt.Sprintf("%x", tmpb))
//fmt.Printf("Not empty, we Create a new relationship for: %v ", vi.phit.GetSha256())
query := `MATCH (b:Bot {ip:"` + vi.phit.GetIp() + `"})
MATCH (c:CC {host:"` + vi.phit.GetHost() + `"})
MATCH (bin:Binary ` + vi.phit.GetBinaryMatchQuerySelector() + `)
MERGE (b)-[d:download {name: "download"}]->(bin)
MERGE (c)-[h:host {name: "host"}]->(bin)
ON MATCH SET bin.sha256 = "` + vi.phit.GetSha256() + `"`
result, err := graphGR.Query(query)
if err != nil {
fmt.Println(err)
}
if *debug {
logger.Println(query)
logger.Println(result)
}
} else if *debug {
logger.Println("Skipping " + vi.url)
}
case <-sortie:
return nil
}
}
return nil
}
func removeMitm(s gj.Result) gj.Result {
str := s.String()
for _, v := range mitm {
str = strings.Replace(str, string(v), "", -1)
}
s = gj.Result{Str: str, Type: gj.String}
return s
}
func newPool(addr string, maxconn int) *redis.Pool {
return &redis.Pool{
MaxActive: maxconn,
MaxIdle: 3,
IdleTimeout: 240 * time.Second,
// Dial or DialContext must be set. When both are set, DialContext takes precedence over Dial.
Dial: func() (redis.Conn, error) { return redis.Dial("tcp", addr) },
}
}