Skip to content

Commit

Permalink
Bugfix: Usernames can now contain unicode for i8n support. (Velocidex…
Browse files Browse the repository at this point in the history
  • Loading branch information
scudette authored Jul 3, 2024
1 parent 27740f9 commit 9731b97
Show file tree
Hide file tree
Showing 12 changed files with 536 additions and 420 deletions.
10 changes: 6 additions & 4 deletions accessors/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package collector

import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -194,13 +195,13 @@ func (self *CollectorAccessor) maybeSetZipPassword(

buf, err := ioutil.ReadAll(mhandle)
if err != nil {
return nil, err
return nil, fmt.Errorf("Decoding metadata.json: %w", err)
}

rows := []*ordereddict.Dict{}
err = json.Unmarshal(buf, &rows)
if err != nil {
return nil, err
return nil, fmt.Errorf("Decoding metadata.json: %w", err)
}

// metadata.json can be multiple rows
Expand All @@ -226,12 +227,12 @@ func (self *CollectorAccessor) maybeSetZipPassword(

key, err := crypto_utils.GetPrivateKeyFromScope(self.scope)
if err != nil {
return nil, err
return nil, fmt.Errorf("GetPrivateKeyFromScope: %w", err)
}

zip_pass, err := crypto_utils.Base64DecryptRSAOAEP(key, ep)
if err != nil {
return nil, err
return nil, fmt.Errorf("Unable to extract zip password: %w", err)
}

self.scope.SetContext(constants.ZIP_PASSWORDS, string(zip_pass))
Expand Down Expand Up @@ -311,6 +312,7 @@ func (self *CollectorAccessor) OpenWithOSPath(
updated_full_path, err := self.maybeSetZipPassword(full_path)
if err != nil {
self.scope.Log(err.Error())
return nil, err
}

reader, err := self.ZipFileSystemAccessor.OpenWithOSPath(updated_full_path)
Expand Down
4 changes: 3 additions & 1 deletion api/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ func GetAPIHandler(
username, ok := req.Context().Value(
constants.GRPC_USER_CONTEXT).(string)
if ok {
md["USER"] = username
// gRPC metadata can only contain ASCII so we make
// sure to escape if needed.
md["USER"] = utils.Quote(username)
}

return metadata.New(md)
Expand Down
36 changes: 26 additions & 10 deletions bin/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,12 @@ func handleProfile(config_obj *config_proto.Config) func(w http.ResponseWriter,
}
}

func handleIndex(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
func handleIndex(config_obj *config_proto.Config) func(
w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")

w.Write([]byte(`
w.Write([]byte(`
<html><body>
<h1>Debug Server</h1>
<ul>
Expand All @@ -304,14 +306,28 @@ func handleIndex(w http.ResponseWriter, r *http.Request) {
<li><a href="/debug/profile/all/html">Show all profile items</a></li>
`))

for _, i := range debug.GetProfileWriters() {
w.Write([]byte(fmt.Sprintf(`
if config_obj.Monitoring != nil && config_obj.GUI != nil {
metrics_url := config_obj.Monitoring.MetricsUrl
if metrics_url == "" {
metrics_url = fmt.Sprintf("http://%v:%v/metrics",
config_obj.Monitoring.BindAddress,
config_obj.Monitoring.BindPort)
}

w.Write([]byte(fmt.Sprintf(
"<li><a href=\"%s\">Metrics</a></li>\n",
url.QueryEscape(metrics_url))))
}

for _, i := range debug.GetProfileWriters() {
w.Write([]byte(fmt.Sprintf(`
<li><a href="/debug/profile/%s/html">%s</a></li>`,
url.QueryEscape(i.Name),
html.EscapeString(i.Description))))
}
url.QueryEscape(i.Name),
html.EscapeString(i.Description))))
}

w.Write([]byte(`</body></html>`))
w.Write([]byte(`</body></html>`))
}
}

func initDebugServer(config_obj *config_proto.Config) error {
Expand All @@ -326,7 +342,7 @@ func initDebugServer(config_obj *config_proto.Config) error {
handleProfile(config_obj)))
http.HandleFunc("/debug/queries/running/",
maybeRenderHTML(handleRunningQueries))
http.HandleFunc("/", handleIndex)
http.HandleFunc("/", handleIndex(config_obj))

// Switch off the debug flag so we do not run this again. (The
// GUI runs this function multiple times).
Expand Down
14 changes: 14 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (

"github.com/Velocidex/yaml/v2"
"github.com/go-errors/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
constants "www.velocidex.com/golang/velociraptor/constants"
"www.velocidex.com/golang/velociraptor/utils"
Expand All @@ -34,6 +36,11 @@ var (
build_time string
commit_hash string
ci_run_url string

versionCounter = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "velociraptor_build",
Help: "Current version of running binary.",
}, []string{"commit_hash", "build_time"})
)

func GetVersion() *config_proto.Version {
Expand Down Expand Up @@ -210,3 +217,10 @@ func WriteConfigToFile(filename string, config *config_proto.Config) error {

return nil
}

func init() {
// Tag the metrics with a build time. This is useful in a cluster
// to see if all nodes are upgraded.
versionCounter.With(prometheus.Labels{
"commit_hash": commit_hash, "build_time": build_time}).Inc()
}
Loading

0 comments on commit 9731b97

Please sign in to comment.