配置環境javascript
sudo apt-get install apache2
apachectl start
netstat -aptn
前端編程php
<html> <head> <title>login</title> </head> <body> <form name=「form」 action="20155220.php" method="post"> Username:<input type="text" name="user"><p> Password:<input type="password" name="pw"><p> <input type="submit" value="submit"> </form> </body> </html>
PHP測試html
<?php $user=($_POST["user"]); $psw=($_POST["pw"]); echo "welcome "; echo $user; ?>
JavaScript是一種普遍用於客戶端Web開發的腳本語言,經常使用來給HTML網頁添加動態功能,好比響應用戶的各類操做。
文檔對象模型(Document Object Model,簡稱DOM,是W3C組織推薦的處理可擴展標誌語言的標準編程接口。前端
在網上借鑑了一個編寫驗證用戶名和密碼的規則:用戶名密碼不能爲空,密碼長度在6-16之間java
<script language="javascript"> function check(Form){ var Username =Form.user.value; var pwd =Form.pw.value; if((Username == "")||(pwd == ""))//若是用戶名爲空 { alert("用戶名或密碼不能爲空"); return false; } if (pwd.length > 16 || pwd.length < 6) { alert("密碼長度應該在 6 - 16 位"); return false; } Form.submit(); } </script>
修改後的代碼:mysql
<html> <head> <title>login</title> <meta charset="utf-8"/> <script language="javascript"> function check(form){ var Username =form.user.value; var pwd =form.pw.value; if((Username == "")||(pwd == ""))//若是用戶名爲空 { alert("用戶名或密碼不能爲空"); return false; } if (pwd.length > 16 || pwd.length < 6) { alert("密碼長度應該在 6 - 16 位"); return false; } form.submit(); } </script> </head> <body> <form name="form" method="post" action="20155220.php"> Username:<input type="text" name="user"><p> Password:<input type="password" name="pw"><p> <input type="button" value="submit" onclick="check(form)"> </form> </body> </html>
apt-get install mysql
/etc/init.d/mysql start
mysql -u root -p
默認密碼p@ssw0rd
show databases;
而後,咱們建立一個數據庫TestLogin:CREATE SCHEMA TestLogin;
web
輸入use TestLogin
選擇所建立的數據庫sql
create table `users`( `userid` int not null comment '', `username` varchar(45) null comment '', `password` varchar(256) null comment '', `enabled` varchar(5) null comment '', primary key (`userid`) comment '');
輸入insert into users(userid,username,password,enabled) values( 1,'20155220',password("20155220"),"TRUE");
,添加信息數據庫
輸入select * from users
進行查詢apache
這裏咱們修改第二個任務的php文件,使之能夠查詢數據庫
測試以下:
5.最簡單的SQL注入,XSS攻擊測試
SQL注入
SELECT username,password FROM users WHERE username='' and password=('')
要被變爲select username,password from users where username='' or 1=1#' and password=('')
,在用戶名框中輸入'or 1=1#
,密碼隨便,能夠看到登錄成功xss攻擊
原理:攻擊者利用網站漏洞(一般這些漏洞是指網站後臺處理程序沒有很好的對用戶輸入進行過濾),輸入能夠顯示在頁面上的、對其餘用戶形成影響的HTML代碼;因爲受害者瀏覽器對目標服務器的信任,當其訪問目標服務器上被注入惡意腳本的頁面後,這段惡意腳本能夠順利執行,實現獲取用戶cookie並能夠利用用戶身份進行非法操做的目的。
在用戶名輸入框中輸入<img src="5220.jpg"/>
讀取圖片,圖片和網頁代碼在同一文件夾下
結果如圖:
(1)什麼是表單
(2)瀏覽器能夠解析運行什麼語言。
(3)WebServer支持哪些動態語言
雖然在上個學期的課程學習中接觸過網頁編程,可是隻是簡單的表格表單的設計,數據庫有初步的瞭解,並無深刻的學習,對於php更是未有過接觸,所以本次實驗的代碼仍是借鑑了其餘同窗的。有了代碼,實驗進行的較爲順利,通過本次實驗,對腳本對網頁編程的危害有了更一步的認識。