Last active
May 11, 2021 14:45
-
-
Save gigawhitlocks/97c4551cb38da19f5669f2059842afd3 to your computer and use it in GitHub Desktop.
poc program that pipes contents of a zip file through named pipes like they're single-read files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"archive/zip" | |
"fmt" | |
"io" | |
"os" | |
"sync" | |
"syscall" | |
) | |
func main() { | |
r, err := zip.OpenReader("./test.zip") | |
if err != nil { | |
rerror(err) | |
} | |
var wg sync.WaitGroup | |
for _, f := range r.File { | |
wg.Add(1) | |
err := syscall.Mknod(f.Name, syscall.S_IFIFO|0666, 0) | |
rerror(err) | |
go func(wg *sync.WaitGroup, f *zip.File) { | |
defer wg.Done() | |
fw, err := os.OpenFile(f.Name, os.O_WRONLY, 0666) | |
rerror(err) | |
defer fw.Close() | |
fr, err := f.Open() | |
rerror(err) | |
defer fr.Close() | |
defer os.Remove(f.Name) | |
_, err = io.Copy(fw, fr) | |
rerror(err) | |
}(&wg, f) | |
} | |
wg.Wait() | |
} | |
func rerror(err error) { | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "%s", err) | |
os.Exit(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment