Detecting a ZIP archive in a JPEG image

If data is hidden using the technique from the previous example, it can be detected by searching for the ZIP file signature in the image. A file may have a .jpg extension and still load properly in a photo viewer, but it may still have a ZIP archive stored in the file. The following program searches through a file and looks for a ZIP file signature. We can run it against the file created in the previous example:

package mainimport (   "bufio"   "bytes"   "log"   "os")func main() {   // Zip signature is "\x50\x4b\x03\x04"   filename := "stego_image.jpg"   file, err := os.Open(filename)   if err != nil {      log.Fatal(err)   }   bufferedReader := bufio.NewReader(file)   fileStat, _ := file.Stat() // 0 is being cast to an int64 ...

Get Security with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.