📄 mhrsdetector.java
字号:
package net.jumperz.app.MGuardian.plugin;
import java.io.*;
import java.util.*;
import java.net.*;
import net.jumperz.net.*;
import net.jumperz.util.*;
import net.jumperz.app.MGuardian.*;
public class MHRSDetector
extends MGuardianPlugin
{
private String command;
private boolean block;
//--------------------------------------------------------------------------------
public void startup()
throws IOException
{
command = control.getProperty( "HRSDetector.command", "" );
block = ( control.getProperty( "HRSDetector.block", "true" ) ).equalsIgnoreCase( "true" );
}
//--------------------------------------------------------------------------------
public Map execute( Map sessionInfo )
throws IOException
{
MHttpRequest request = ( MHttpRequest )sessionInfo.get( "request" );
Map pluginResult = new HashMap();
pluginResult.put( "block", new Boolean( block ) );
pluginResult.put( "log", new Boolean( true ) );
if( !command.equals( "" ) )
{
pluginResult.put( "command", command );
}
// double Content-Length
if( doubleHeaderExists( request, "Content-Length" ) )
{
pluginResult.put( "message", "two or more Content-Length header field detected." );
return pluginResult;
}
// double Transfer-Encoding
if( doubleHeaderExists( request, "Transfer-Encoding" ) )
{
pluginResult.put( "message", "two or more Transfer-Encoding header field detected." );
return pluginResult;
}
// Transfer-Encoding: chunked and Content-Length
if( request.headerExists( "Transfer-Encoding" ) )
{
String encoding = request.getHeaderValue( "Transfer-Encoding" );
if( encoding.equalsIgnoreCase( "chunked" ) )
{
if( request.headerExists( "Content-Length" ) )
{
pluginResult.put( "message", "Transfer-Encoding and Content-Length fields detected." );
return pluginResult;
}
}
}
// GET etc with Content-Length or Transfer-Encoding
String method = request.getMethod();
if( !method.equals( "POST" )
&& !method.equals( "PUT" )
)
{
if( request.headerExists( "Content-Length" ) )
{
String value = request.getHeaderValue( "Content-Length" );
if( !value.equals( "0" ) )
{
pluginResult.put( "message", method + " request with Content-Length header field detected." );
return pluginResult;
}
}
if( request.headerExists( "Transfer-Encoding" ) )
{
pluginResult.put( "message", method + " request with Transfer-Encoding header field detected." );
return pluginResult;
}
}
// Content-Length with no Content-Type
if( request.headerExists( "Content-Length" )
&& !request.headerExists( "Content-Type" ) )
{
pluginResult.put( "message", "Content-Length and no Content-Type detected." );
return pluginResult;
}
return null;
}
//--------------------------------------------------------------------------------
private boolean doubleHeaderExists( MHttpRequest request, String header )
{
List l = request.getHeaderValueList( header );
if( l.size() > 1 )
{
return true;
}
return false;
}
//--------------------------------------------------------------------------------
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -