We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
有一个接口通过http请求可以触发命令执行:
@PostMapping(value = "/json/unixProcess.do", consumes = APPLICATION_JSON_VALUE) public Map<String, Object> jsonUnixProcess(@RequestBody Map<String, Object> map) throws Exception { return unixProcess((String) map.get("cmd")); // 调用命令执行方法 }
通过postman 发送请求:
http 请求的 body 参数为 {"cmd": "cat /etc/passwd"}
{"cmd": "cat /etc/passwd"}
debug open-rasp 1.3.7 ,发现截获的body与输入不同
com.baidu.openrasp.request.AbstractRequest#getStringBody
rasp 截获的body参数:{{"cmd": "cat /etc/passwd"} 与输入对比多了第一个字节
{{"cmd": "cat /etc/passwd"}
open-rasp hook 了org.eclipse.jetty.server.HttpInput中的2个方法:
org.eclipse.jetty.server.HttpInput
1.public int read() throws IOException 2.public int read(byte[] b, int off, int len) throws IOException JettyHttpInputHook源码位置
org.eclipse.jetty.server.HttpInput 中2个方法调用关系:read() 最终会调用 read(byte[] b, int off, int len)
open-rasp 中2个方法都会读取的 http body 字节并存储,而 read() 读取body 的第一个字节,open-rasp 将body的第一个字节存储:
read(byte[] b, int off, int len) 读取全部字节,导致http body 第一个字节读取了2次。
由于第一个hook点read()调用read(byte[] b, int off, int len) ,因此可以去掉read() 仅保留 read(byte[] b, int off, int len)
read()
read(byte[] b, int off, int len)
优化前后代码:
@Override protected void hookMethod(CtClass ctClass) throws IOException, CannotCompileException, NotFoundException { //String srcRead1 = getInvokeStaticSrc(ServerInputHook.class, "onInputStreamRead", // "$_,$0", int.class, Object.class); //insertAfter(ctClass, "read", "()I", srcRead1); String src2Read2 = getInvokeStaticSrc(ServerInputHook.class, "onInputStreamRead", "$_,$0,$1,$2", int.class, Object.class, byte[].class, int.class); insertAfter(ctClass, "read", "([BII)I", src2Read2); }
优化方案经过验证,http body读取正常。
如有错误,欢迎指正~~
The text was updated successfully, but these errors were encountered:
你好,可以提交个PR吗
Sorry, something went wrong.
No branches or pull requests
复现环境
问题描述:
有一个接口通过http请求可以触发命令执行:
通过postman 发送请求:
http 请求的 body 参数为
{"cmd": "cat /etc/passwd"}
debug open-rasp 1.3.7 ,发现截获的body与输入不同
com.baidu.openrasp.request.AbstractRequest#getStringBody
rasp 截获的body参数:
{{"cmd": "cat /etc/passwd"}
与输入对比多了第一个字节初步原因
open-rasp hook 了
org.eclipse.jetty.server.HttpInput
中的2个方法:1.public int read() throws IOException
2.public int read(byte[] b, int off, int len) throws IOException
JettyHttpInputHook源码位置
org.eclipse.jetty.server.HttpInput 中2个方法调用关系:read() 最终会调用 read(byte[] b, int off, int len)
open-rasp 中2个方法都会读取的 http body 字节并存储,而 read() 读取body 的第一个字节,open-rasp 将body的第一个字节存储:
read(byte[] b, int off, int len) 读取全部字节,导致http body 第一个字节读取了2次。
初步优化
由于第一个hook点
read()
调用read(byte[] b, int off, int len)
,因此可以去掉read()
仅保留read(byte[] b, int off, int len)
优化前后代码:
优化方案经过验证,http body读取正常。
如有错误,欢迎指正~~
The text was updated successfully, but these errors were encountered: