GoHTTP-A
靶场页面
通过分析URL得知是指定文件,并且可以通过路径回溯可以读取文件。
题目为go主题,那么肯定属于go程序,将main.go读取到本地。
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"os/exec"
"strings"
)
funcsyncData(env string) bool {
envList := strings.Split(env, "::")
cmd := exec.Command("bash", "-c", "./syncData.sh")
cmd.Env =append(os.Environ(), envList...)
err := cmd.Run()
if err != nil {
returnfalse
}
returntrue
}
funcuploadFileHandler(w http.ResponseWriter, r *http.Request) {
r.ParseMultipartForm(1024)
file, _, err := r.FormFile("uploadedFile")
if err != nil {
fmt.Fprintf(w, "no")
return
}
defer file.Close()
fileBytes, err := ioutil.ReadAll(file)
ifstring(fileBytes[0:8]) =="[config]" {
ioutil.WriteFile("config/config.ini", fileBytes, 0644)
fmt.Fprintf(w, "File uploaded successfully")
return
}
fmt.Fprintf(w, "error")
}
funcmain() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
tpl := r.URL.Query().Get("tpl")
if tpl =="" {
http.Redirect(w, r, "/?tpl=index.html", http.StatusFound)
return
}
html, err := os.ReadFile("tpl/"+ tpl)
if err != nil || strings.Contains(tpl, "flag") || strings.Contains(tpl, "go-server") {
fmt.Fprintf(w, "无法读取文件")
return
}
fmt.Fprintf(w, string(html))
})
http.HandleFunc("/secretBackkkkkkup_Ma1n.source.go", func(w http.ResponseWriter, r *http.Request) {
source, _ := os.ReadFile("tpl/main.go")
fmt.Fprintf(w, string(source))
})
http.HandleFunc("/syncData", func(w http.ResponseWriter, r *http.Request) {
ApiUrl := r.URL.Query().Get("ApiUrl")
if syncData(fmt.Sprintf("ApiUrl=%!s(MISSING)::Role=%!s(MISSING)", ApiUrl, "master")) {
fmt.Fprintf(w, "ok")
return
}
fmt.Fprintf(w, "数据同步失败")
})
http.HandleFunc("/upload_configFile", uploadFileHandler)
http.ListenAndServe(":8080", nil)
}
发现代码主要是上传文件到config所谓接口其实就是读取main.go 。
并且带有一个tpl参数,该参数读取文件时,将flag和程序本身纳入黑名单。无法直接读取。
但是存在一个执行bash -c sync.sh的命令。并且通过ApiUrl设置环境变量。但是环境变量直接格式化合并在一组字符串。我们可以通过注入BASH_ENV,实现复杂flag到/tmp目录,并且起用一个非flag文件。 最后使用tpl读取。
命令为cat /home/ctf/flag > /tmp/1.txt. 并且构造Payload 。 将BASH_ENV 设置过去。
PATH::BASH_ENV='$(cat/home/ctf/flag > /tmp/1.txt)'::s
原文始发于微信公众号(猫头鹰安全团队):能源安全比赛-Gohttp(应声发布)
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论