Skip to content

Commit

Permalink
add test vulnerable file just to validate the install of semgrep in repo
Browse files Browse the repository at this point in the history
  • Loading branch information
jkan2 committed Sep 25, 2024
1 parent 3e0b307 commit f56b3ab
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cmd/test-semgrep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"context"
"fmt"
"os/exec"
)

func main() {
// Another example of untrusted input
input := "ping -c 8 google.com; echo hacked"

ctx := context.Background()

// Vulnerable: input is directly concatenated into the command
command := fmt.Sprintf("sh -c %s", input)
cmd := exec.CommandContext(ctx, command)

// Execute and print the output
output, err := cmd.CombinedOutput()
if err != nil {
fmt.Println("Error:", err)
}
fmt.Println("Output:", string(output))
}

0 comments on commit f56b3ab

Please sign in to comment.