- 参数说明
- 数据库查询
- 读取目录
- 请求参数
- 读取文件
- 写入文件
- 文件包含操作
- WebDAV 操作
- 文件上传
- 命令执行
- XML 外部实体引用
- Struts OGNL 表达式解析
- RMI 反序列化
- 服务器端 HTTP 请求
参数说明
若要实现检测逻辑,插件需要先注册检测方法,e.g SQL注入检测插件可注册 sql 类型的回调
plugin.register('sql', function(params, context) {// 实现你的检测逻辑})
具体插件可注册的回调类型 type,以及回调参数 params 的样例如下
数据库查询
type = sqlparams = {"server": "mysql / oracle / pgsql / mssql / sqlite","query": "select * from users",}
读取目录
type = directoryparams = {"path": "/home/servers/tomcat/webapps/mywar/../../../../../../../../../etc/","realpath": "/etc/","stack": ["java.lang.ProcessBuilder.start","sun.reflect.NativeMethodAccessorImpl.invoke0","sun.reflect.NativeMethodAccessorImpl.invoke","sun.reflect.DelegatingMethodAccessorImpl.invoke",...]}
请求参数
当应用接受到请求时,插件可以对请求进行拦截
type = requestparams = {}
这里不会传递任何参数,如果需要获取请求相关信息,请使用 API接口
读取文件
type = readFileparams = {"path": "/home/servers/tomcat/webapps/mywar/../../../../../../../../../etc/hosts","realpath": "/etc/hosts"}
写入文件
出于性能考虑,OpenRASP 目前只会提供文件名和绝对路径两个参数
注意:
- tomcat 等应用服务器,在部署war包时,暂时不会触发这个回调
- 对于NTFS数据流,e.g abc.php::$DATA,插件看到的 name 可能是 abc.php::$DATA,realpath 可能是 c:\inetpub\wwwroot\abc.php
type = writeFileparams = {"name": "abc.jsp","realpath": "/home/tomcat/webapps/ROOT/abc.jsp"}
文件包含操作
url 可能是协议(file、http等等),也能是相对路径(/abc/、abc.txt)
支持的文件包含方式如下,
- Java - JSTL import 方式
- 只有 url 里出现了 :// 且不为 / 开头时,我们才会调用插件
- PHP - include/require/include_once/require_once 四种方式
- 如果 url 里包含 :// 时,调用插件
- 如果文件以 .php 或者 .inc 结尾,或者真实路径在 webroot 下面,不会进入插件
- 其他情况进入插件
具体参数
# Java 示例type = include,params = {url: "file:///etc/passwd",function: "jstl_import",realpath: "/etc/passwd"}# PHP 示例type = include,params = {url: "/home/webroot/footer/../../../../../../../../../etc/passwd",function: "require_once",realpath: "/etc/passwd"}
WebDAV 操作
目前仅支持 MOVE、COPY 两种方法
type = webdav,params = {"source": "/home/rsync/apache-tomcat-7.0.78/webapps/webdav/1.txt","dest": "/home/rsync/apache-tomcat-7.0.78/webapps/webdav/1.jsp"}
文件上传
目前,OpenRASP 支持 org.apache.commons.fileupload 上传组件(SpringMVC、Struts 底层使用)
出于性能考虑,OpenRASP 只会提取文件前 4 KB 的内容,若要获取更多字节,请参考配置文档
type = fileUploadparams = {"filename": "a.jsp","content": "<% ... %>"}
命令执行
从 v0.40 开始,命令参数统一改为字符串
type = command,params = {"stack": ["java.lang.ProcessBuilder.start","sun.reflect.NativeMethodAccessorImpl.invoke0","sun.reflect.NativeMethodAccessorImpl.invoke","sun.reflect.DelegatingMethodAccessorImpl.invoke",...]"command": "/bin/sh -c 'whoami; ls; '"}
XML 外部实体引用
目前,PHP不支持XXE检测
type = xxeparams = {"entity": "file:///etc/passwd"}
Struts OGNL 表达式解析
注意: 为了减少性能影响,仅当表达式长度超过 30 时才会调用插件。可手动 ognl.expression.minlength 选项来进行调整
type = ognlparams = {"expression": "_memberAccess" //ognl表达式}
RMI 反序列化
type = deserializationparams = {"clazz": "InvokerTransformer" //被反序列化对象的类型}
服务器端 HTTP 请求
支持的请求方式包含如下 (对应 function 字段),
- JDK 中的 URL.openConnection 的方式 (url_open_connection)
- commons-httpclient 框架请求方式 (commons_http_client)
- httpclient 框架请求方式 (http_client)
type = ssrfparams = {"url": "http://0x7f.0x0.0x0.0x1:8080/v1/api/get", // http 请求的 url"hostname": "0x7f.0x0.0x0.0x1" // http 请求的 hostname"ip": ["1.1.1.1", "2.2.2.2"] // 无法解析则为空;只解析 IPv4 地址"function": "commons_http_client"}
原文: https://rasp.baidu.com/doc/dev/data.html
