Skip to content

Commit

Permalink
更新mvc类插件支持
Browse files Browse the repository at this point in the history
  • Loading branch information
iSafeBlue committed Apr 9, 2019
1 parent b1776fb commit 79e54f8
Show file tree
Hide file tree
Showing 14 changed files with 357 additions and 50 deletions.
15 changes: 15 additions & 0 deletions base/src/main/java/com/trackray/base/annotation/Function.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.trackray.base.annotation;

import java.lang.annotation.*;

/**
* @author 浅蓝
* @email [email protected]
* @since 2019/1/8 12:28
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Function {
String value() default "";
}
5 changes: 5 additions & 0 deletions base/src/main/java/com/trackray/base/annotation/Param.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.trackray.base.annotation;

/**
* @author 浅蓝
* @email [email protected]
* @since 2019/1/8 12:28
*/
public @interface Param {
String key () default "";
String defaultValue() default "";
Expand Down
74 changes: 53 additions & 21 deletions base/src/main/java/com/trackray/base/plugin/AbstractPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import com.trackray.base.annotation.Rule;
import com.trackray.base.attack.HackKit;
import com.trackray.base.bean.Constant;
import com.trackray.base.bean.ResultCode;
import com.trackray.base.handle.Shell;
import com.trackray.base.httpclient.CrawlerPage;
import com.trackray.base.httpclient.Fetcher;
import org.javaweb.core.net.HttpURLRequest;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;
Expand All @@ -23,6 +23,9 @@
public abstract class AbstractPlugin<E> implements Callable<AbstractPlugin<E>> {

public enum Type{
/**
* 非交互式插件响应类型
*/
JSON("application/json"),
XML("application/xml"),
HTML("text/html"),
Expand All @@ -39,6 +42,9 @@ public String getValue() {
}
}
public enum Charset{
/**
* 非交互式插件响应编码
*/
UTF8("charset=utf-8"),
GBK("charset=gbk"),
GB2312("charset=gb2312"),
Expand All @@ -54,37 +60,40 @@ public String getValue() {
return value;
}
}
protected final static String BASE = Constant.RESOURCES_PATH;

private Shell shell = new Shell();
protected E result;
public Fetcher fetcher = new Fetcher();
public CrawlerPage crawlerPage = new CrawlerPage();
public Map<String,Object> param;
public String errorMsg = "未通过校验";
protected final static String BASE = Constant.RESOURCES_PATH; // resource外部资源文件的绝对路径

protected E result; // 插件返回对象

@Deprecated
public Fetcher fetcher = new Fetcher(); // 执行请求类 已过时
@Deprecated
public CrawlerPage crawlerPage = new CrawlerPage(); //普通请求类 已过时

protected HttpURLRequest requests = new HttpURLRequest(); //请求类

public Map<String,Object> param; // 从前端传来的参数
public String errorMsg = "未通过校验"; // 错误响应信息

@Autowired
private HackKit hackKit ; //工具包

public static void main(String[] args) {
}

public int step = 1;

public abstract boolean check(Map<String,Object> param);
public abstract boolean check(Map<String,Object> param); // 检测方法

public void before(){}
public void before(){} // 执行插件主代码前执行

public Object after(Object... args){return null;}
public Object after(Object... args){return null;} // 执行插件主代码后执行

public abstract E start();
public abstract E start(); // 插件代码实现方法

@Override
public AbstractPlugin<E> call() {
return executor();
}
} // callable

public void setParam(Map<String, Object> param) {
public void setParam(Map param) {
this.param = param;
}

Expand All @@ -96,34 +105,57 @@ public E result() {
return result;
}

/**
* 执行方法
* @return
*/
public AbstractPlugin<E> executor() {
boolean flag = true;
try {
flag = check(param);
flag = check(param); // 判断参数是否合法
}catch (Exception e){
flag = false;
}
if (flag){
if (flag){ //合法则执行插件代码
before();
result = start();
after();
}
return this;
}

private final void exec(){}
//private final void exec(){}

/**
* 系统shell对象
* @return
*/
public final Shell shell(){
return shell;
return new Shell();
}

/**
* 获取当前规则注解
* @return
*/
public Rule currentRule(){
Rule rule = this.getClass().getAnnotation(Rule.class);
return rule;
}

/**
* 获取当前插件参数注解
* @return
*/
public Param[] currentParams(){
return this.currentRule().params();
}


/**
* 获取当前插件注解
* @return
*/
public Plugin currentPlugin(){
Plugin plugin = this.getClass().getAnnotation(Plugin.class);
return plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.commons.lang.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
Expand All @@ -12,7 +13,7 @@
*/
public abstract class CommonPlugin<E> extends AbstractPlugin<E> {


public HttpServletRequest request;
public HttpServletResponse response;

public boolean isNone(String o){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.trackray.base.bean.Vulnerable;
import com.trackray.base.httpclient.CrawlerPage;
import com.trackray.base.httpclient.Fetcher;
import org.javaweb.core.net.HttpURLRequest;

/**
* 爬虫插件类
Expand All @@ -16,6 +17,7 @@ public abstract class CrawlerPlugin {
public Crawler crawler;
public CrawlerPage crawlerPage;
public Fetcher fetcher = new Fetcher();
protected HttpURLRequest request = new HttpURLRequest();
public String target;
public abstract boolean check();
public abstract void process();
Expand Down
82 changes: 82 additions & 0 deletions base/src/main/java/com/trackray/base/plugin/MVCPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.trackray.base.plugin;

import com.trackray.base.annotation.Function;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.ModelAndView;

import java.lang.reflect.Method;
import java.util.Map;

/**
* MVC插件类
* @author 浅蓝
* @email [email protected]
* @since 2019/4/2 16:33
*/
public abstract class MVCPlugin extends CommonPlugin<ModelAndView>{

protected ModelAndView model;
protected String function;

@Function
public abstract void index();

@Override
public boolean check(Map<String, Object> param) {
return true;
}

@Override
public ModelAndView start() {
boolean flag = false;
Method target = null;
Method[] methods = this.getClass().getMethods();

for (Method method : methods) {
Function func = method.getAnnotation(Function.class);
if (func!=null)
{
String value = func.value();
if (StringUtils.isEmpty(value))
value = method.getName();//如果不填写function注解的value则认为mapping是方法名
if(function.equals(value)){
flag = true;
target = method;
break;
}
}
}
String pluginKey = this.currentPlugin().value();//插件对象在spring中的id

if (flag){
try {
target.invoke(this, null);
model.setViewName(pluginKey.concat("/"+model.getViewName())); // 如果功能执行正常 那在viewName则为:插件id/视图名
} catch (Exception e) {
model.setViewName("common/error");
model.addObject("msg",e.getMessage());
}

}else{
try {
this.getClass().getMethod("index",null).invoke(this, null);//执行默认的index方法
model.setViewName(pluginKey.concat("/"+model.getViewName())); // 如果功能执行正常 那在viewName则为:插件id/视图名
} catch (Exception e) {
model.setViewName("common/error");
model.addObject("msg",e.getMessage());
}
}

return model;
}

public void setFunction(String function) {
this.function = function;
}

public void setModel(ModelAndView model) {
this.model = model;
}


}
31 changes: 31 additions & 0 deletions module/src/main/java/com/trackray/module/plugin/ios/mvcTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.trackray.module.plugin.ios;

import com.trackray.base.annotation.Function;
import com.trackray.base.annotation.Plugin;
import com.trackray.base.annotation.Rule;
import com.trackray.base.plugin.MVCPlugin;

/**
* @author 浅蓝
* @email [email protected]
* @since 2019/4/2 17:34
*/
@Rule
@Plugin(value = "mvcTest",
title = "mvc类插件测试",
author = "blue")
public class mvcTest extends MVCPlugin{

@Function("test.html")
public void test(){
model.addObject("msg","这是一个测试插件");
model.setViewName("test");
}


@Override
public void index() {
model.addObject("msg","index page");
model.setViewName("index");
}
}
12 changes: 12 additions & 0 deletions module/src/main/resources/templates/common/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

<h1>Error</h1>
<li th:text="${msg}"></li>
</body>
</html>
10 changes: 10 additions & 0 deletions module/src/main/resources/templates/mvcTest/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>index.html
<li th:text="${msg}"></li>
</body>
</html>
11 changes: 11 additions & 0 deletions module/src/main/resources/templates/mvcTest/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>test.html
<li th:text="${msg}"></li>

</body>
</html>
Loading

0 comments on commit 79e54f8

Please sign in to comment.