RDF攻擊=Reflected File Download
攻擊者可以將某些輸入內(nèi)容植入到響應(yīng)中,并且可以控制下載文件的文件名,然后讓響應(yīng)被下載到用戶本地,然后用戶啟動了這些有問題的文件,形成了攻擊。并且這些攻擊可以在一定范圍內(nèi)傳播。
主要的攻擊方式來自于URI中關(guān)于以 “;” 間隔的部分參數(shù)中。
最新的攻擊是用戶將攻擊內(nèi)容放到了參數(shù)jsessionId的內(nèi)容中。
近期SpringFramework又爆出了新的RDF攻擊的漏洞,查看其修復(fù)源碼。
SpringFramework在兩次攻擊中,其處理方式如下:
1、在url中,屏蔽所有;間隔以后的代碼,具體見:
public class UrlPathHelper {
private String removeSemicolonContentInternal(String requestUri) {
int semicolonIndex = requestUri.indexOf(';');
while (semicolonIndex != -1) {
int slashIndex = requestUri.indexOf('/', semicolonIndex);
String start = requestUri.substring(0, semicolonIndex);
requestUri = (slashIndex != -1) ? start + requestUri.substring(slashIndex) : start;
semicolonIndex = requestUri.indexOf(';', semicolonIndex);
}
return requestUri;
}
}
第二次處理jsessionId的代碼如下:
public abstract class WebUtils {
/**
* Parse the given string with matrix variables. An example string would look
* like this {@code "q1=a;q1=b;q2=a,b,c"}. The resulting map would contain
* keys {@code "q1"} and {@code "q2"} with values {@code ["a","b"]} and
* {@code ["a","b","c"]} respectively.
* @param matrixVariables the unparsed matrix variables string
* @return a map with matrix variable names and values (never {@code null})
* @since 3.2
*/
public static MultiValueMap<String, String> parseMatrixVariables(String matrixVariables) {
MultiValueMap<String, String> result = new LinkedMultiValueMap<>();
if (!StringUtils.hasText(matrixVariables)) {
return result;
}
StringTokenizer pairs = new StringTokenizer(matrixVariables, ";");
while (pairs.hasMoreTokens()) {
String pair = pairs.nextToken();
int index = pair.indexOf('=');
if (index != -1) {
String name = pair.substring(0, index);
if (name.equalsIgnoreCase("jsessionid")) {
continue;
}
String rawValue = pair.substring(index + 1);
for (String value : StringUtils.commaDelimitedListToStringArray(rawValue)) {
result.add(name, value);
}
}
else {
result.add(pair, "");
}
}
return result;
}
}
由代碼可知,第一次防護(hù),在整合URI中,屏蔽了每一段"/"之間的";"之后的代碼。
第二次防護(hù)則去掉了jsessionId的參數(shù)和值。
因此如果需要解決此類問題,要么可以考慮在接入段進(jìn)行參數(shù)區(qū)隔,將參數(shù)隔離出容器,不讓容器獲取異常參數(shù),也可以在響應(yīng)段將異常對象隔離。均可以達(dá)到阻斷攻擊的效果。