Open qgrosperrin opened 7 months ago
be sure to close that opened file as well check go docs on this topic: https://pkg.go.dev/os#example-OpenFile-Append
// If the file doesn't exist, create it, or append to the file
logFile, err := os.OpenFile("/var/log/evilginx2.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
if _, err := f.Write([]byte("appended some data\n")); err != nil {
f.Close() // ignore error; Write error takes precedence
log.Fatal(err)
}
if err := f.Close(); err != nil {
log.Fatal(err)
}
But that's really a very basic example provided by go.dev, not especially ideal for real world scenarios. In production, this could potentially cause a lot of disk I/O
I'd enhance this with a bufio.Writer
to handle the writing part and the I/O problem
I couldn't see this documented or implemented but I needed the colourised output from Evilginx2 to be stored to a file. Best way I found to do was to edit the end of log/log.go with the below (Bash shell redirection wouldn't work for my use case). This did the trick for me:
Could make it configurable to either enable or disable logging for the sake of it.