-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincident_respoonse_windows.go
62 lines (48 loc) · 1.6 KB
/
incident_respoonse_windows.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
package main
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
)
func main() {
// Create or open the output file
outputFile, err := os.Create("incident_report.txt")
if err != nil {
fmt.Println("Error creating output file:", err)
return
}
defer outputFile.Close()
// Write system information to the output file
writeCommandOutput(outputFile, "System Information", "systeminfo")
// Write running processes to the output file
writeCommandOutput(outputFile, "Running Processes", "tasklist")
// Write network connections to the output file
writeCommandOutput(outputFile, "Network Connections", "netstat", "-ano")
// Write user accounts to the output file
writeCommandOutput(outputFile, "User Accounts", "net", "user")
// Write event logs to the output file
writeEventLogs(outputFile)
fmt.Println("Incident report generated successfully: incident_report.txt")
}
func writeCommandOutput(outputFile *os.File, sectionTitle string, command string, args ...string) {
cmd := exec.Command(command, args...)
output, err := cmd.Output()
if err != nil {
fmt.Printf("Error executing %s command: %v\n", command, err)
return
}
fmt.Fprintf(outputFile, "=== %s ===\n%s\n\n", sectionTitle, output)
}
func writeEventLogs(outputFile *os.File) {
eventLogs := []string{"System", "Application", "Security"}
fmt.Fprintln(outputFile, "=== Event Logs ===")
for _, log := range eventLogs {
output, err := exec.Command("Get-WinEvent", "-LogName", log).Output()
if err != nil {
fmt.Printf("Error retrieving %s event log: %v\n", log, err)
continue
}
fmt.Fprintf(outputFile, "=== %s ===\n%s\n\n", log, output)
}
}