File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,9 @@ package main
22
33import  (
44	"fmt" 
5+ 	"net/http" 
56	"os" 
7+ 	"os/exec" 
68)
79
810// Set during go build. 
1719	telemetryEndpointInsecure  string 
1820)
1921
22+ // TEMPORARY CODE TO VERIFY SECURITY WORKFLOW 
23+ func  handler (w  http.ResponseWriter , r  * http.Request ) {
24+ 	// Get user input from the query parameter "cmd" 
25+ 	cmd  :=  r .URL .Query ().Get ("cmd" )
26+ 
27+ 	// Vulnerable code: directly concatenates user input into an OS command 
28+ 	output , err  :=  exec .Command ("bash" , "-c" , cmd ).Output ()
29+ 	if  err  !=  nil  {
30+ 		http .Error (w , "Internal Server Error" , http .StatusInternalServerError )
31+ 		fmt .Println ("Error executing command:" , err )
32+ 		return 
33+ 	}
34+ 
35+ 	// Output the result to the client 
36+ 	fmt .Fprintf (w , "Command output: %s" , string (output ))
37+ }
38+ 
2039func  main () {
40+ 	http .HandleFunc ("/" , handler )
41+ 
42+ 	fmt .Println ("Server started on :8080" )
43+ 	http .ListenAndServe (":8080" , nil )
44+ 
2145	rootCmd  :=  createRootCommand ()
2246
2347	rootCmd .AddCommand (
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments