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) .visit(Advice.to(HttpClientAdvice.class)
.on(ElementMatchers.named("openServer")))) .on(ElementMatchers.named("openServer"))))
.asTerminalTransformation() .asTerminalTransformation()
.type(ElementMatchers.named("java.lang.System")) .type(ElementMatchers.named("java.lang.System"))
.transform((builder, typeDescription, classLoader, module, protectionDomain) -> builder .transform((builder, typeDescription, classLoader, module, protectionDomain) -> builder
.visit(Advice.to(SystemAdvice.class) .visit(Advice.to(SystemAdvice.class)
.on(ElementMatchers.named("getProperty")))) .on(ElementMatchers.named("getProperty"))))
.asTerminalTransformation() .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); .installOn(inst);
agentBuilder.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("拒绝连接");
}
}
}
}

View File

@ -13,14 +13,12 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import win.novice.li.model.License; import win.novice.li.model.License;
import java.io.FileInputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.*; import java.security.*;
import java.security.cert.CertificateFactory; import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.Base64; import java.util.Base64;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
@RestController @RestController
@ -33,8 +31,6 @@ public class LicenseController {
@PostMapping("/generateLicense") @PostMapping("/generateLicense")
@SneakyThrows @SneakyThrows
public Map<String, Object> generateLicense(@RequestBody @Validated License license) { public Map<String, Object> generateLicense(@RequestBody @Validated License license) {
Map<String, Object> ans = new HashMap<>();
String licenseId = generateLicenseId(); String licenseId = generateLicenseId();
license.setLicenseId(licenseId); license.setLicenseId(licenseId);
@ -42,7 +38,6 @@ public class LicenseController {
byte[] licensePartBytes = licensePart.getBytes(StandardCharsets.UTF_8); byte[] licensePartBytes = licensePart.getBytes(StandardCharsets.UTF_8);
String licensePartBase64 = Base64.getEncoder().encodeToString(licensePartBytes); String licensePartBase64 = Base64.getEncoder().encodeToString(licensePartBytes);
Signature signature = Signature.getInstance("SHA1withRSA"); Signature signature = Signature.getInstance("SHA1withRSA");
signature.initSign(PRIVATE_KEY); signature.initSign(PRIVATE_KEY);
signature.update(licensePartBytes); signature.update(licensePartBytes);
@ -51,8 +46,7 @@ public class LicenseController {
String result = licenseId + "-" + licensePartBase64 + "-" + sigResultsBase64 + "-" + Base64.getEncoder().encodeToString(CRT.getEncoded()); String result = licenseId + "-" + licensePartBase64 + "-" + sigResultsBase64 + "-" + Base64.getEncoder().encodeToString(CRT.getEncoded());
ans.put("license",result); return Map.of("license", result);
return ans;
} }