国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
shiro安全框架擴(kuò)展教程--如何防止可執(zhí)行文件的入侵攻擊

        前面的教程有一章是講解如何突破上傳的,當(dāng)被人通過(guò)上傳功能突破的防線那就杯具了,有點(diǎn)hack知識(shí)的人都知道,很多攻擊都是優(yōu)先尋找上傳的功能,因?yàn)槟芡黄?/p>

就會(huì)剩下很多的功夫,比如hack上傳了一個(gè)asp,php或者jsp文件,然后通過(guò)抓包路徑獲取了文件存放地址,然后直接請(qǐng)求就能通過(guò)這個(gè)可執(zhí)行的文件獲取到數(shù)據(jù)庫(kù)的信息,

或者是遍歷目錄下載文件,尋找文件中的其他漏洞以獲得更高的權(quán)限,下面我就演示下簡(jiǎn)單的防范手段,就算被突破了上傳也會(huì)有下一堵墻在一定程度上防止執(zhí)行腳本


我主要是使用shiro寫(xiě)了一個(gè)filter過(guò)濾需要請(qǐng)求信息,如遇到黑名單則記錄信息,看下面貼的代碼


  1. package com.silvery.security.shiro.filter;  
  2.   
  3. import java.text.SimpleDateFormat;  
  4. import java.util.Date;  
  5.   
  6. import javax.servlet.ServletRequest;  
  7. import javax.servlet.ServletResponse;  
  8. import javax.servlet.http.HttpServletRequest;  
  9.   
  10. import org.apache.shiro.web.filter.authz.AuthorizationFilter;  
  11. import org.slf4j.Logger;  
  12. import org.slf4j.LoggerFactory;  
  13.   
  14. import com.silvery.utils.PatternUtils;  
  15. import com.silvery.utils.WebUtils;  
  16.   
  17. /**  
  18.  *   
  19.  * 黑名單可執(zhí)行程序請(qǐng)求過(guò)濾器  
  20.  *   
  21.  * @author shadow  
  22.  *   
  23.  */  
  24. public class SimpleExecutiveFilter extends AuthorizationFilter {  
  25.   
  26.     protected static final String[] blackUrlPathPattern = new String[] { "*.aspx*", "*.asp*", "*.php*", "*.exe*",  
  27.             "*.jsp*", "*.pl*", "*.py*", "*.groovy*", "*.sh*", "*.rb*", "*.dll*", "*.bat*", "*.bin*", "*.dat*",  
  28.             "*.bas*", "*.c*", "*.cmd*", "*.com*", "*.cpp*", "*.jar*", "*.class*", "*.lnk*" };  
  29.   
  30.     private static final Logger log = LoggerFactory.getLogger(SimpleExecutiveFilter.class);  
  31.   
  32.     @Override  
  33.     protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object obj) throws Exception {  
  34.   
  35.         HttpServletRequest httpRequest = (HttpServletRequest) request;  
  36.   
  37.         String reqUrl = httpRequest.getRequestURI().toLowerCase().trim();  
  38.   
  39.         for (String pattern : blackUrlPathPattern) {  
  40.             if (PatternUtils.simpleMatch(pattern, reqUrl)) {  
  41.                 log.error(new StringBuffer().append("unsafe request >>> ").append(" request time: ").append(  
  42.                         new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())).append("; request ip: ")  
  43.                         .append(WebUtils.getClientIP()).append("; request url: ").append(httpRequest.getRequestURI())  
  44.                         .toString());  
  45.                 return false;  
  46.             }  
  47.         }  
  48.   
  49.         return true;  
  50.   
  51.     }  
  52.   
  53. }  


下一步把剛剛寫(xiě)的過(guò)濾器配置到shiro的過(guò)濾鏈中


  1. <!-- 過(guò)濾鏈配置 -->  
  2.     <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">  
  3.         <property name="securityManager" ref="securityManager" />  
  4.         <property name="loginUrl" value="/" />  
  5.         <property name="successUrl" value="/cms/index.do" />  
  6.         <property name="unauthorizedUrl" value="/static/unauthorized.html" />  
  7.         <property name="filters">  
  8.             <map>  
  9.                 <entry key="role">  
  10.                     <bean  
  11.                         class="com.silvery.security.shiro.filter.SimpleRoleAuthorizationFilter" />  
  12.                 </entry>  
  13.                 <entry key="authc">  
  14.                     <bean  
  15.                         class="com.silvery.security.shiro.filter.SimpleFormAuthenticationFilter" />  
  16.                 </entry>  
  17.                 <entry key="exec">  
  18.                     <bean class="com.silvery.security.shiro.filter.SimpleExecutiveFilter" />  
  19.                 </entry>  
  20.             </map>  
  21.         </property>  
  22.     </bean>  

最后配置下我們需要過(guò)濾的請(qǐng)求目錄,一般都是全量過(guò)濾,但是有些靜態(tài)資源是不應(yīng)該過(guò)濾的,所以應(yīng)該注意順序,讓anon權(quán)限的放到放到exec的前面


  1. <!-- 權(quán)限資源配置 -->  
  2.     <bean id="filterChainDefinitionsService"  
  3.         class="com.silvery.security.shiro.service.impl.SimpleFilterChainDefinitionsService">  
  4.         <property name="definitions">  
  5.             <value>  
  6.                 /static/** = anon  
  7.                 /** = exec  
  8.             </value>  
  9.         </property>  
  10.     </bean>  

最后請(qǐng)求下php,jsp等那些文件是返回到無(wú)權(quán)限的頁(yè)面,我們的簡(jiǎn)單防范已經(jīng)達(dá)到目的了,下一章節(jié)可能講如何防范xss和csrf攻擊的防范


本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Shiro security限制登錄嘗試次數(shù)
shiro實(shí)現(xiàn)不同身份使用不同Realm進(jìn)行驗(yàn)證
shiro spring
springrain技術(shù)詳解(1)
基于Spring框架的Shiro配置
Spring的date類型注入
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服