1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| package main
import ( "bytes" "io" "net/http" "os/exec"
"github.com/gin-gonic/gin" )
type ProxyRequest struct { URL string `json:"url" binding:"required"` Method string `json:"method" binding:"required"` Body string `json:"body"` Headers map[string]string `json:"headers"` FollowRedirects bool `json:"follow_redirects"` }
func main() { r := gin.Default()
v1 := r.Group("/v1") { v1.POST("/api/flag", func(c *gin.Context) { cmd := exec.Command("/readflag") flag, err := cmd.CombinedOutput() if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"status": "error", "message": "Internal Server Error"}) return } c.JSON(http.StatusOK, gin.H{"flag": flag}) }) }
v2 := r.Group("/v2") { v2.POST("/api/proxy", func(c *gin.Context) { var proxyRequest ProxyRequest if err := c.ShouldBindJSON(&proxyRequest); err != nil { c.JSON(http.StatusBadRequest, gin.H{"status": "error", "message": "Invalid request"}) return }
client := &http.Client{ CheckRedirect: func(req *http.Request, via []*http.Request) error { if !req.URL.IsAbs() { return http.ErrUseLastResponse }
if !proxyRequest.FollowRedirects { return http.ErrUseLastResponse }
return nil }, }
req, err := http.NewRequest(proxyRequest.Method, proxyRequest.URL, bytes.NewReader([]byte(proxyRequest.Body))) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"status": "error", "message": "Internal Server Error"}) return }
for key, value := range proxyRequest.Headers { req.Header.Set(key, value) }
resp, err := client.Do(req)
if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"status": "error", "message": "Internal Server Error"}) return }
defer resp.Body.Close()
body, err := io.ReadAll(resp.Bo
server { listen 8000;
location ~ /v1 { return 403; }
location ~ /v2 { proxy_pass http: proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
|