-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
117 lines (101 loc) · 2.92 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
package main
import (
"github.com/blondon1/ai_driven_network_forensics_tool/src/analysis"
"github.com/blondon1/ai_driven_network_forensics_tool/src/data_ingestion"
"github.com/blondon1/ai_driven_network_forensics_tool/src/preprocessing"
"github.com/blondon1/ai_driven_network_forensics_tool/src/real_time_analysis"
"github.com/blondon1/ai_driven_network_forensics_tool/src/reporting"
"github.com/blondon1/ai_driven_network_forensics_tool/src/ui"
"github.com/google/gopacket"
"github.com/google/gopacket/layers" // Import for LayerTypeTCP and LayerTypeUDP
"github.com/google/gopacket/pcap"
"gopkg.in/yaml.v2"
"log"
"os"
"path/filepath"
)
type SystemConfig struct {
NetworkInterface string `yaml:"network_interface"`
LogFilePath string `yaml:"log_file_path"`
}
func loadConfig() (SystemConfig, error) {
var config SystemConfig
data, err := os.ReadFile("config/system_config.yaml")
if err != nil {
return config, err
}
err = yaml.Unmarshal(data, &config)
if err != nil {
return config, err
}
return config, nil
}
func setupLogging(logFilePath string) (*os.File, error) {
err := os.MkdirAll(filepath.Dir(logFilePath), os.ModePerm)
if err != nil {
return nil, err
}
logFile, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
return nil, err
}
log.SetOutput(logFile)
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
return logFile, nil
}
func main() {
devices, err := pcap.FindAllDevs()
if err != nil {
log.Fatal(err)
}
log.Println("Devices found:")
for _, device := range devices {
log.Printf("Name: %s, Description: %s\n", device.Name, device.Description)
}
config, err := loadConfig()
if err != nil {
log.Fatalf("Failed to load configuration: %v", err)
}
logFile, err := setupLogging(config.LogFilePath)
if err != nil {
log.Fatalf("Failed to set up logging: %v", err)
}
defer logFile.Close()
log.Println("Starting AI-Driven Network Forensics Tool")
packets := make(chan gopacket.Packet)
filterConfig := data_ingestion.FilterConfig{
BPF: "",
IPAddress: "",
Port: 0,
Protocol: "",
}
go func() {
data_ingestion.CapturePackets(config.NetworkInterface, packets, filterConfig)
}()
go func() {
ui.StartServer()
}()
for packet := range packets {
log.Println("Processing packet")
preprocessing.PreprocessPacket(packet)
analysis.AnalyzePacket(packet)
protocol := "Other"
if packet.TransportLayer() != nil {
switch packet.TransportLayer().LayerType() {
case layers.LayerTypeTCP:
protocol = "TCP"
case layers.LayerTypeUDP:
protocol = "UDP"
default:
if packet.Layer(layers.LayerTypeICMPv4) != nil || packet.Layer(layers.LayerTypeICMPv6) != nil {
protocol = "ICMP"
}
}
}
log.Printf("Packet protocol: %s", protocol)
ui.RecordPacketCount(protocol)
real_time_analysis.AnalyzeInRealTime(packet)
reporting.GenerateReport(packet)
}
log.Println("Shutting down AI-Driven Network Forensics Tool")
}