国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

用mod_security保障Web Services的安全二

2019-11-18 12:26:58
字體:
供稿:網(wǎng)友

  將Web服務(wù)與mod_security結(jié)合起來
  
  Blue銀行的web服務(wù)使用www.bluebank.example.com/axis/getBalance.jws的URL。為這個(gè)資源創(chuàng)建一套規(guī)則通常一個(gè)不錯(cuò)的主意。為達(dá)此目的,Blue銀行將此資源通過以下方式加入到httpd.conf:
  
  <IfModule mod_security.c>
  SecFilterEngine On
  SecFilterDefaultAction "deny,log,status:500"
  # Other rules
  # ------- Rules for web services --------------------------
  <Location /axis/getBalance.jws>
  SecFilterInheritance Off
  SecFilterDefaultAction "deny,log,status:500"
  SecFilterScanPOST On
  SecFilterCheckURLEncoding On
  SecFilterCheckUnicodeEncoding On
  </Location>
  #---------------------------------------------------------------</IfModule>
  
  下面的指令塊為/axis/getBalance.jws應(yīng)用了過濾標(biāo)準(zhǔn)。為了保護(hù)web服務(wù)它添加了必要的規(guī)則。這些規(guī)則在<Location>塊中,如下:
  
  # ------- Rules for web services --------------------------
  <Location /axis/getBalance.jws>
  SecFilterInheritance Off
  SecFilterDefaultAction "deny,log,status:500"
  SecFilterScanPOST On
  SecFilterCheckURLEncoding On
  SecFilterCheckUnicodeEncoding On</Location>
  #---------------------------------------------------------------
  
  在這里有兩個(gè)重要的指令:
  
  SecFilterInheritance Off
  
  這個(gè)指令關(guān)閉其他所有規(guī)則,為新的location建立一套規(guī)則創(chuàng)建一個(gè)干凈的空間。(譯者注:初始化,建立新空間)
  
  SecFilterScanPOST On
  
  由于web服務(wù)的方法調(diào)用是通過POST,所以這個(gè)指令是打開POST過濾器。
  
  有了上面的配置,Blue Bank已經(jīng)在mod_security中部署了一個(gè)“護(hù)盾”(譯者注:防火墻)。該“護(hù)盾”也知道它的防護(hù)目標(biāo)——客戶端通過SOAP封套發(fā)送的id的內(nèi)容。
  
  防范攻擊
  
  作為防護(hù)所有惡意請求的第一步,Blue銀行需要限制從客戶端發(fā)送的id的值,防止傳來無效值。SOAP請求用xml標(biāo)簽將id信息發(fā)送到web服務(wù)的代碼中,像如下這樣:
  
  <q1:getInput xmlns:q1="http://DefaultNamespace">
  <id xsi:type="xsd:string">12123</id></q1:getInput>
  
  為了過濾該請求,mod_security必須有一些途徑去讀取與標(biāo)簽相關(guān)的值(在這里標(biāo)簽是id);這個(gè)例子中的值是12123,mod_security提供一些途徑限制通過POST請求發(fā)送的值。其中的一個(gè)方法就是使用自定義過濾器:
  
  <Location /axis/getBalance.jws>
  SecFilterInheritance Off
  SecFilterDefaultAction "deny,log,status:500"
  SecFilterScanPOST On
  SecFilterCheckURLEncoding On
  SecFilterCheckUnicodeEncoding On
  SecFilterSelective POST_PAYLOAD "</s*id[^>]*>" chain</Location>
  
  上面標(biāo)示出來的行對請求中的id進(jìn)行限制。POST_PAYLOAD截取POST數(shù)據(jù)塊并與正則表達(dá)式(</s*id[^>]*>)進(jìn)行匹配。該正則表達(dá)式確保id標(biāo)簽存在,當(dāng)存在的情況下才進(jìn)行其余的檢查。換句話說,假如id標(biāo)簽存在,mod_security繼續(xù)下一個(gè)檢查。
  
  假如發(fā)送的POST請求中存在一個(gè)id,服務(wù)器能夠執(zhí)行信息。然而,一個(gè)惡意的客戶端能夠修改這個(gè)值加入惡意內(nèi)容。有四種最流行的攻擊方式。
  
  攻擊方式1:變量長度緩沖區(qū)注入(譯者注:緩沖區(qū)溢出)
  
  當(dāng)把一個(gè)大的緩沖數(shù)據(jù)傳給一個(gè)變量時(shí)可能會引起應(yīng)用程序運(yùn)行不正?;蛘咴趫?zhí)行的時(shí)候“宕”掉的安全隱患。下面的規(guī)則將保護(hù)id變量免受此類攻擊:
  
  <Location /axis/getBalance.jws>
  SecFilterInheritance Off
  SecFilterDefaultAction "deny,log,status:500"
  SecFilterScanPOST On
  SecFilterCheckURLEncoding On
  SecFilterCheckUnicodeEncoding On
  SecFilterSelective POST_PAYLOAD "</s*id[^>]*>" chain
  SecFilterSelective POST_PAYLOAD "</s*id[^>]*>.{6,}<//s*id/s*>""deny,status:500"</Location>
  
  在上面的指令中,正則表達(dá)式</s*id[^>]*>.{6,}<//s*id/s*>限制緩沖變量的長度為5個(gè)字符。為了檢查上面的代碼塊是否起作用,Blue銀行可以發(fā)送兩個(gè)請求,一個(gè)請求符合約束,另一個(gè)越界。
  
  POST /axis/getBalance.jws HTTP/1.0Content-Type: text/xml; charset=utf-8SOAPAction: ""Content-Length: 576EXPect: 100-continueHost: www.bluebank.example.com<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"xmlns:tns="http://www.bluebank.example.com/axis/getBalance.jws" xmlns:types="http://www.bluebank.example.com/axis/getBalance.jws/encodedTypes"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Bodysoap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <q1:getInput xmlns:q1="http://DefaultNamespace">
  <id xsi:type="xsd:string">12123</id>
  </q1:getInput>
  </soap:Body></soap:Envelope>...HTTP/1.1 200 OKDate: Mon, 03 Jan 2005 19:24:10 GMTServer: Apache/2.0.50 (Unix) mod_ssl/2.0.50 OpenSSL/0.9.7d mod_jk2/2.0.4Set-Cookie: JSESSIONID=69C6540CC427A8B064C0795ADDFC20EA; Path=/axisContent-Type: text/xml;charset=utf-8Connection: close<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"        xmlns:xsd="http://www.w3.org/2001/XMLSchema"        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
  <ns1:getInputResponsesoapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:ns1="http://DefaultNamespace">
  <ns1:getInputReturnxsi:type="xsd:string">$2500</ns1:getInputReturn>
  </ns1:getInputResponse>
  </soapenv:Body></soapenv:Envelope>
  
  在上面的例子中,將一個(gè)包含5個(gè)字符的緩沖數(shù)據(jù)傳給web服務(wù),服務(wù)收到后發(fā)回一個(gè)響應(yīng)值為$2500。下面的例子將更改12123這個(gè)數(shù)據(jù)為121234,新的數(shù)據(jù)有6個(gè)字符,將得到一個(gè)新的響應(yīng)信息,如下:
  
  POST /axis/getBlalance.jws HTTP/1.0Content-Type: text/xml; charset=utf-8SOAPAction: ""Content-Length: 577Expect: 100-continueHost: www.bluebank.example.com<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"xmlns:tns="http://www.bluebank.example.com/axis/getBalance.jws" xmlns:types="http://www.bluebank.example.com/axis/getBalance.jws/encodedTypes"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema">    <soap:Bodysoap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <q1:getInput xmlns:q1="http://DefaultNamespace">
  <id xsi:type="xsd:string">121234</id>
  </q1:getInput>
  </soap:Body></soap:Envelope>...HTTP/1.1 500 Internal Server ErrorDate: Mon, 03 Jan 2005 22:00:33 GMTServer: Apache/2.0.50 (Unix) mod_ssl/2.0.50 OpenSSL/0.9.7d mod_jk2/2.0.4Content-Length: 657Connection: closeContent-Type: text/Html; charset=iso-8859-1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head>  <title>500 Internal Server Error</title> </head><body> <h1>Internal Server Error</h1> <p>The server encountered an internal error or misconfiguration and was unable to complete your request.</p> <p>Please contact the server administrator, you@example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.</p>
  <p>More information about this error may be available in the servererror log.</p> <hr />
  <address>Apache/2.0.50 (Unix) mod_ssl/2.0.50 OpenSSL/0.9.7dmod_jk2/2.0.4 Server at 192.168.7.50 Port 80</address></body></html>
  
  mod_security模塊拒絕了該請求。返回500狀態(tài)。這說明請求根本沒有到達(dá)web服務(wù)層。Blue 銀行成功地防范了最常見和經(jīng)常被忽略的緩沖區(qū)溢出攻擊。(譯者注:HTTP定義的500狀態(tài)是服務(wù)器執(zhí)行錯(cuò)誤)
  
  第二種攻擊:元字符注入
  
  另外一個(gè)主要的針對輸入變量的威脅來自于使用像%,單引號(’),雙引號(”)。這些字符會導(dǎo)致SQL注入攻擊,并且可能會導(dǎo)致不必要的信息泄漏。采用下面的策略將保護(hù)web服務(wù)防范此類攻擊。
  
  <Location /axis/getBalance.jws>
  SecFilterInherita

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 广水市| 梓潼县| 平度市| 新田县| 东山县| 台中市| 岐山县| 文安县| 禹城市| 油尖旺区| 衡南县| 布尔津县| 香港 | 海原县| 崇礼县| 水城县| 黎城县| 洛阳市| 武汉市| 东源县| 会同县| 唐海县| 南岸区| 马鞍山市| 西安市| 麻栗坡县| 镇坪县| 土默特右旗| 宁乡县| 巴彦县| SHOW| 萨嘎县| 攀枝花市| 肇州县| 呈贡县| 西华县| 弥勒县| 乌兰浩特市| 新营市| 澄江县| 城步|