kgretzky / evilginx2

Standalone man-in-the-middle attack framework used for phishing login credentials along with session cookies, allowing for the bypass of 2-factor authentication
BSD 3-Clause "New" or "Revised" License
10.23k stars 1.87k forks source link

Log to a file - Feature Request #988

Open qgrosperrin opened 7 months ago

qgrosperrin commented 7 months ago

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:

165     logFile, err := os.OpenFile("/var/log/evilginx2.log", os.O_CREATE | os.O_APPEND | os.O_RDWR, 0666)
166     if err != nil {
167         panic(err)
168     }
169
170     var formatted_msg = "\r[" + time_clr.Sprintf("%02d:%02d:%02d", t.Hour(), t.Minute(), t.Second()) + "] [" + sign.Sprintf("%s", LogLabels[lvl]) + "] " + msg.Sprintf(format, args...)
171     logFile.WriteString(formatted_msg)
172     return formatted_msg

Could make it configurable to either enable or disable logging for the sake of it.

M41KL-N41TT commented 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