其實任何資料里面的任何知識點都無所謂,都是不重要的,重要的是學習方法,自行摸索的過程(不妥之處歡迎指正)
匯總:http://www.cnblogs.com/dunitian/p/4822808.html#mvc
說重點,先簡單說下過度提交,一般黑客利用這個和其他漏洞結合可以產生各種反應。(黑客最喜歡 type="hidden" 這種的,有時候也會解猜一些其他字段)
舉個很簡單的例子:大家都知道有忘記密碼是發個郵件給用戶,然后點擊鏈接之后就可以修改密碼了,很多系統里面沒有防止過度提交,用戶ID都是如123,124之類可猜編號,黑客只要一個腳本基本上批量修改用戶密碼。
再舉個例子,多店模式下的商鋪,如果我是一個懂點代碼的店主,我又看競爭對手各種不爽,完全可以利用過度提交+權限漏洞來修改對手的商品價格和庫存,雙十一跟我斗?庫存改成0,回家歇菜去吧~
以上兩個案例我就不演示了,上次演示一個爆破就被屏蔽了,咳咳, 這次要是再演示估計真得蛋疼了
模擬一個不太准確的案例吧
------------------------------------------------------------------------------------------------------------------------------
就這么低價買走了~~~~
URL參數防止黑客修改一般都是這么玩的====》》
私鑰+公鑰+參數進行加密,可以是md5,可以是其他,然后當其中的一個參數傳遞過去。
接受方用傳過來的公鑰和參數+私鑰進行同樣的加密,然后對比加密結果,不一樣則拒絕訪問
------------------------------------------------------------------------------------------------------------------------------
eg: URL: xxx?name=a&price=b&count=1&key=C5954C83-6B13-4215-9E4C-192C4A45C049&check=xxxxxxxxxxxxxxxxxxxxxxxxx
黑客要修改url參數,那么至少滿足這2個條件:
1.得到私鑰
2.解猜加密方式(不建議直接用md5或者sha1之類的,可以和其他加密相結合)
------------------------------------------------------------------------------------------------------------------------------
好了,我們步入正規,繼續說過度提交的防御。
過度提交其實在開發過程中已經有意無意的有這種概念了,比如ViewModel的產生,其剛開始是為了性能,其實也可以避免了一些過度提交的攻擊
Net里面其實有很好的方案==》模型綁定,可以設置一個Model只能修改哪些屬性或者不允許設置哪些屬性
通過Bind就可以實現了:
黑名單模式:
或者用白名單模式:(建議用這種,安全性更高【ps:你后期有可能再加屬性,到時候忘了不over了?】)
======================效果================================
-------------------------擴展---------------------
很多人去面試的時候有可能會被問到,Net里面這種傳參原理是啥?
來看一下傳統方式:
革命性:
其實這個就是通過模型綁定來實現的.比如這種方式也是利用了模型綁定
模型綁定會從請求中(不一定是表單,路由,url之類的也可以)查找相關參數(Product的相關屬性)
eg:從路由獲取相關參數
eg:從url獲取參數
手動綁定=》(里面有很多重載方法可以自行研究)
![]()
下面說下模型常用特性:
上次簡單說了點:http://www.cnblogs.com/dunitian/p/5724872.html#form
看圖
其他系列:
ErrorMessage ="郵箱格式不正確"
視圖部分:(這次用另一種方法)
@model Register @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>Register</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.Age, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Age, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Age, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Money, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Money, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Money, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.NiName, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.NiName, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.NiName, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Pass, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Pass, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Pass, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.RPass, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.RPass, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.RPass, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Email, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.CreateTime, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.CreateTime, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.CreateTime, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Create" class="btn btn-default" /> </div> </div> </div> }效果:
送福利: