Skip to content

Commit

Permalink
Merge pull request #106 from lufeirider/main
Browse files Browse the repository at this point in the history
kcurl anonymous mode,add random ip addresses to confuse ip addresses
  • Loading branch information
neargle authored Nov 15, 2024
2 parents bc9af97 + 69494d1 commit 7ba21a5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/tool/kubectl/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/tls"
"fmt"
"io/ioutil"
"math/rand"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -160,6 +161,20 @@ func ServerAccountRequest(opts K8sRequestOption) (string, error) {
request.Header.Set("Authorization", "Bearer "+token)
}

// Anonymous mode,add random ip addresses to confuse ip addresses
if opts.Anonymous {
rand.Seed(time.Now().UnixNano())
ips := make([]string, 100)

for i := 0; i < 100; i++ {
ip := fmt.Sprintf("10.%d.%d.%d", rand.Intn(256), rand.Intn(256), rand.Intn(256))
ips[i] = ip
}

randIpStr := strings.Join(ips, ",")
request.Header.Set("X-Forwarded-For", randIpStr)
}

resp, err := client.Do(request)
if err != nil {
return "", &errors.CDKRuntimeError{Err: err, CustomMsg: "err found in post request."}
Expand Down

0 comments on commit 7ba21a5

Please sign in to comment.