fortify——path manipulation

path路径不安全问题

            引入方法

HashMap<String, String> map = new HashMap<String, String>();
  map.put("a", "a");
  map.put("b", "b");
  map.put("c", "c");
  map.put("d", "d");
  map.put("e", "e");
  map.put("f", "f");
  map.put("g", "g");
  map.put("h", "h");
  map.put("i", "i");
  map.put("j", "j");
  map.put("k", "k");
  map.put("l", "l");
  map.put("m", "m");
  map.put("n", "n");
  map.put("o", "o");
  map.put("p", "p");
  map.put("q", "q");
  map.put("r", "r");
  map.put("s", "s");
  map.put("t", "t");
  map.put("u", "u");
  map.put("v", "v");
  map.put("w", "w");
  map.put("x", "x");
  map.put("y", "y");
  map.put("z", "z");
  
  map.put("A", "A");
  map.put("B", "B");
  map.put("C", "C");
  map.put("D", "D");
  map.put("E", "E");
  map.put("F", "F");
  map.put("G", "G");
  map.put("H", "H");
  map.put("I", "I");
  map.put("J", "J");
  map.put("K", "K");
  map.put("L", "L");
  map.put("M", "M");
  map.put("N", "N");
  map.put("O", "O");
  map.put("P", "P");
  map.put("Q", "Q");
  map.put("R", "R");
  map.put("S", "S");
  map.put("T", "T");
  map.put("U", "U");
  map.put("V", "V");
  map.put("W", "W");
  map.put("X", "X");
  map.put("Y", "Y");
  map.put("Z", "Z");


map.put(":", ":");
     map.put("/", "/");
     map.put("\\", "\\");
  
  String temp = "";
  for (int i = 0; i < path.length(); i++) {

   if (map.get(path.charAt(i)+"")!=null) {
    temp += map.get(path.charAt(i)+"");
   }
  }
  path = temp;
  
  File proFile = new File(path);

还有、Linux下不能有“/"

public static String isSecurePath(String filePath) {
		String[] blackListChars = { "../", "..", "..\\" };
		if (StringUtils.indexOfAny(filePath, blackListChars) < 0) {
			return filePath;
		} else {
			throw new UmpRuntimeException("文件路径存在问题: " + filePath);
		}
	}


一、流资源释放


三个流资源一起关闭:

 prop.load(ConfigUtil.class.getResourceAsStream("/config.properties"));
 emmprop.load(ConfigUtil.class.getResourceAsStream("/emmconfig.properties"));
 applicationProp.load(ConfigUtil.class.getResourceAsStream("/application/application.properties"));

对于一个

try {
			try {
				inputFile = ConfigUtil.class.getResourceAsStream(FortifyUtil.isSecurePath("/config.properties"));
				prop.load(inputFile);
			} finally {
				if (inputFile != null) {
					inputFile.close();
				}
			}
		} catch (Exception e) {
			UMMobSmLogger.error(e);
		}

对于三个

首先初始化:

private static Properties prop = new Properties();
    
    private static Properties emmprop = new Properties();
    
    private static Properties applicationProp = new Properties(); 
    
    private static InputStream ise = null;
    
    private static InputStream isa = null;
    
    private static InputStream ism = null;

然后关闭流

try
        {   
        	try{
        	InputStream ise = ConfigUtil.class.getResourceAsStream("/config.properties");
        	prop.load(ise); 
        	}
        	finally {
        		if (ise != null){
        			ise.close(); 
        			}
        		}
        	
        	try{
        		InputStream isa = ConfigUtil.class.getResourceAsStream("/emmconfig.properties");
        		emmprop.load(isa); 
            	}
            	finally {
            		if (isa != null){
            			isa.close(); 
            			}
            		}
        	
        	try{
        		InputStream ism = ConfigUtil.class.getResourceAsStream("/application/application.properties");
        		applicationProp.load(ism); 
            	}
            	finally {
            		if (ism != null){
            			ism.close(); 
            			}
            		}        	
        }        
        catch (Exception e)
        {
            EMLogger.error(e);
        }

二、password 问题(换个写法)

eg:pw

三、空指针异常,检测对象是否赋值,是否可能为空,加一个判断。


四、随机数问题(伪随机)

             自己写一个随机算法


五、密码强度不够 

            可以加更好的  不过要修改相应的东西

六、sql注入

封装数据信息。对客户端提交的数据进行封装,不要将数据直接存入cookie中,方法就是在编程的代码中,插入session、if、try、else,这样可以有效地防止攻击者获取cookie中的重要信息、等等方法

bug、安全代码、静态代码、jar包重复告一段落

七、path manipulation

下一阶段:做页面



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值