ban掉restful-fast-request--api-buddy的验证服务器ip

This commit is contained in:
novice.li 2024-01-16 23:11:24 +08:00
parent a8b6a9129e
commit 0714d4a122
3 changed files with 29 additions and 7 deletions

View file

@ -21,11 +21,19 @@ public class AgentMain {
.visit(Advice.to(HttpClientAdvice.class)
.on(ElementMatchers.named("openServer"))))
.asTerminalTransformation()
.type(ElementMatchers.named("java.lang.System"))
.transform((builder, typeDescription, classLoader, module, protectionDomain) -> builder
.visit(Advice.to(SystemAdvice.class)
.on(ElementMatchers.named("getProperty"))))
.asTerminalTransformation()
.type(ElementMatchers.named("java.net.Socket"))
.transform((builder, typeDescription, classLoader, module, protectionDomain) -> builder
.visit(Advice.to(SocketAdvice.class)
.on(ElementMatchers.named("connect"))))
.asTerminalTransformation()
.installOn(inst);
agentBuilder.installOn(inst);

View file

@ -0,0 +1,20 @@
package win.novice.li;
import net.bytebuddy.asm.Advice;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
public class SocketAdvice {
@Advice.OnMethodExit
public static void intercept(@Advice.Argument(value = 0,readOnly = false) SocketAddress socketAddress) throws Exception {
if (socketAddress instanceof InetSocketAddress){
InetAddress address = ((InetSocketAddress) socketAddress).getAddress();
if (address.getHostAddress().equals("116.62.33.138")){
throw new ConnectException("拒绝连接");
}
}
}
}