使用sni 代理解决服务器无法直接联网的问题

正式系统无法访问外网,测试系统可以访问外网。正式系统的一个SDK需要向外网发送HTTP请求,考虑使用sni 代理。 软件 gost [参考文档]{https://gost.run/tutorials/protocols/sni/} 部署 能联网的测试机使用docker compose部署(设置xxx.com的sni代理白名单,xxx.com前面的~表示白名单,不加~表示黑名单) services: gost: image: gogost/gost container_name: gost ports: - "80:80" command: -L sni://:80?bypass=~xxx.com restart: unless-stopped 不能联网的正式机配置/etc/hosts 测试机ip xxx.com 我的后端是容器部署的,然后给容器配置/etc/hosts文件映射就可以了 注意 不能在构建docker image时候修改hosts,只能在容器运行时进行映射或者修改。因为构建阶段/etc/hosts是只读的。image是许多只读layer的叠加,而容器是只读layer和可读layer的叠加

January 20, 2025 · 1 min · LLP2333

使用AspectJ拦截第三方SDK请求

最近使用一个第三方的SDK来请求数据,但是请求的服务器对ip有白名单限制,SDK使用的apache的commons-httpclient: 3.1 发送请求。于是尝试使用ApectJ运行时织入,拦截发送HTTP请求的代码,修改参数. 依赖(用的1.9.19版本) <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> </dependency> maven插件 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <executions> <execution> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin> 切面 import org.apache.commons.httpclient.HttpMethod; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.springframework.stereotype.Component; @Aspect @Component public class HttpClientAspect { public static HttpClientAspect aspectOf() { return new HttpClientAspect(); } @Around("execution(* org.apache.commons.httpclient.HttpClient.executeMethod(..))") public Object aroundHttpExecution(ProceedingJoinPoint joinPoint) throws Throwable { System.out.println("======================================"); Object[] args = joinPoint.getArgs(); // 获取HttpMethod参数 if (args != null && args....

January 10, 2025 · 1 min · LLP2333

Java的ResourceBundle读取配置文件路径

当你使用 // 1. 创建或加载 ResourceBundle ResourceBundle bundle = ResourceBundle.getBundle("messages"); // 从 classpath 加载 messages.properties // 2. 使用getString()获取字符串值 String value = bundle.getString("key.name"); 读取文件时 代码默认会读取src/main/resources/messages.properties src/main/resources/messages.properties // 默认 src/main/resources/messages_zh.properties // 中文 src/main/resources/messages_en.properties // 英文 样例配置文件 key.name=值 welcome.message=欢迎 error.code=500 如果想指定读取的文件 // 指定英文 Locale Locale enLocale = new Locale("en"); // 或者直接用 Locale.ENGLISH // 加载英文资源包 ResourceBundle bundle = ResourceBundle.getBundle("messages", enLocale); // 获取英文值 String value = bundle.getString("key.name");

January 8, 2025 · 1 min · LLP2333

某云办公应用api存在IP白名单绕过风险

最近在做一个消息推送企业某信的需求,使用的不是官方的api,而是和企业某信可以集成的云办公平台的api。由于api有ip白名单限制,导致我必须在特定化网络环境下发请求,测试很麻烦,所以想测试一下能不能绕过限制。 想要绕过限制,首先要知道服务器如何获取发送者的ip。 服务器如何获取请求者ip 获取请求者 IP 本质上就两个来源: 直接从 IP 数据包获取 这就是 HttpServletRequest的getRemoteAddr() 的工作原理,获取的是直接与服务器建立 TCP 连接的客户端 IP,在没有代理的情况下,这就是真实的客户端 IP 从 HTTP 请求头获取 常见的请求头有: X-Forwarded-For X-Real-IP Proxy-Client-IP WL-Proxy-Client-IP 测试 这里我使用了postman伪造了请求头X-Forwarded-For,经过测试,理论上只要知道正确的ip,就可以让ip白名单功能失效。 如果你有服务器的访问权限,但是只知道服务器的内网ip,可以尝试 curl ifconfig.me 然后就能得到服务器的公网ip了 安全建议 改用网络层的源IP地址(TCP/IP报文中的source IP)进行验证 如果必须使用代理转发,建议只信任内部代理服务器传递的XFF头 吐槽 某云办公平台必须付费才能获得访问api的密钥,并且密钥只有一个,测试只能直接在正式系统测

January 8, 2025 · 1 min · LLP2333

用go写了个简化hugo文章创建的小工具

目前使用hugo作为博客系统,使用typora作为博客的编辑器。书接上文Hugo使用技巧,之前每次都需要在博客根目录执行 hugo new posts/文章标题/index.md 创建新的文章。感觉很麻烦。所以想写个工具简化这个过程。 思路 输入文件标题后执行创建文章的命令,然后生成新的文章的快捷方式,方便使用typora进行编辑。 代码 使用Claude生成的,很方便。 如果是windows平台,使用 go build -o HugoHelper.exe main.go 进行编译。 使用前需要配置blog环境变量,key为blog,value为你的项目的根路径 比如我的根目录是C:\UGit\qvqw.date 代码 package main import ( "bufio" "fmt" "os" "os/exec" "path/filepath" "strings" ) func main() { // 获取当前程序执行路径 execPath, err := os.Getwd() if err != nil { fmt.Printf("错误: 获取当前路径失败: %v\n", err) os.Exit(1) } // 从环境变量获取博客路径 blogPath := os.Getenv("blog") if blogPath == "" { fmt.Println("错误: 环境变量 'blog' 未设置") os.Exit(1) } // 验证博客路径是否存在 if _, err := os....

January 7, 2025 · 1 min · LLP2333