From 0714d4a1224374f1721862782ad041cd79b3c95e Mon Sep 17 00:00:00 2001 From: "novice.li" Date: Tue, 16 Jan 2024 23:11:24 +0800 Subject: [PATCH] =?UTF-8?q?ban=E6=8E=89restful-fast-request--api-buddy?= =?UTF-8?q?=E7=9A=84=E9=AA=8C=E8=AF=81=E6=9C=8D=E5=8A=A1=E5=99=A8ip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/win/novice/li/AgentMain.java | 8 ++++++++ .../main/java/win/novice/li/SocketAdvice.java | 20 +++++++++++++++++++ .../li/controller/LicenseController.java | 8 +------- 3 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 jetbra-agent/src/main/java/win/novice/li/SocketAdvice.java diff --git a/jetbra-agent/src/main/java/win/novice/li/AgentMain.java b/jetbra-agent/src/main/java/win/novice/li/AgentMain.java index ce29191..b6c42fb 100644 --- a/jetbra-agent/src/main/java/win/novice/li/AgentMain.java +++ b/jetbra-agent/src/main/java/win/novice/li/AgentMain.java @@ -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); diff --git a/jetbra-agent/src/main/java/win/novice/li/SocketAdvice.java b/jetbra-agent/src/main/java/win/novice/li/SocketAdvice.java new file mode 100644 index 0000000..ba12ef6 --- /dev/null +++ b/jetbra-agent/src/main/java/win/novice/li/SocketAdvice.java @@ -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("拒绝连接"); + } + } + } +} diff --git a/jetbra-server/src/main/java/win/novice/li/controller/LicenseController.java b/jetbra-server/src/main/java/win/novice/li/controller/LicenseController.java index 022f188..af874d9 100644 --- a/jetbra-server/src/main/java/win/novice/li/controller/LicenseController.java +++ b/jetbra-server/src/main/java/win/novice/li/controller/LicenseController.java @@ -13,14 +13,12 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import win.novice.li.model.License; -import java.io.FileInputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.security.*; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.Base64; -import java.util.HashMap; import java.util.Map; @RestController @@ -33,8 +31,6 @@ public class LicenseController { @PostMapping("/generateLicense") @SneakyThrows public Map generateLicense(@RequestBody @Validated License license) { - Map ans = new HashMap<>(); - String licenseId = generateLicenseId(); license.setLicenseId(licenseId); @@ -42,7 +38,6 @@ public class LicenseController { byte[] licensePartBytes = licensePart.getBytes(StandardCharsets.UTF_8); String licensePartBase64 = Base64.getEncoder().encodeToString(licensePartBytes); - Signature signature = Signature.getInstance("SHA1withRSA"); signature.initSign(PRIVATE_KEY); signature.update(licensePartBytes); @@ -51,8 +46,7 @@ public class LicenseController { String result = licenseId + "-" + licensePartBase64 + "-" + sigResultsBase64 + "-" + Base64.getEncoder().encodeToString(CRT.getEncoded()); - ans.put("license",result); - return ans; + return Map.of("license", result); }