(1).Web前端HTML(0.5分)javascript
能正常安裝、啓停Apache。理解HTML,理解表單,理解GET與POST方法,編寫一個含有表單的HTML。php
(2).Web前端javascipt(0.5分)css
理解JavaScript的基本功能,理解DOM。編寫JavaScript驗證用戶名、密碼的規則。html
(3).Web後端:MySQL基礎:正常安裝、啓動MySQL,建庫、建立用戶、修改密碼、建表(0.5分)前端
(4).Web後端:編寫PHP網頁,鏈接數據庫,進行用戶認證(1分)java
(5).最簡單的SQL注入,XSS攻擊測試(1分)mysql
功能描述:用戶能登錄,登錄用戶名密碼保存在數據庫中,登錄成功顯示歡迎頁面。web
(1)什麼是表單sql
jsp php asp等數據庫
service apache2 start
cd /var/www/html
,simple_form.html
<html> <head> <title>Login</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <h2 align="center">Login</h2> <center> <form action="login" method="post"> <input placeholder="E-mail" name="Name" class="user" type="email"> <br> </br> <input placeholder="Password" name="Password" class="pass" type="password"> <br> </br> <input type="submit" value="Login"> </form> </center> </body> </html>
<html> <head> <title>Login</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <h2 align="center">Login</h2> <center> <form action="login" method="post" name="form_login"> <input placeholder="E-mail" name="Name" class="user" type="email" onfocus="if (this.value=='Your email') this.value='';" /> <br> </br> <input placeholder="Password" name="Password" class="pass" type="password" onfocus="if (this.value=='Your password') this.value='';"/> <br> </br> <input type="submit" value="Login" onClick="return validateLogin()"/> </form> </center> <script language="javascript"> function validateLogin(){ var sUserName = document.form_login.Name.value ; var sPassword = document.form_login.Password.value ; if ((sUserName =="") || (sUserName=="Your email")){ alert("User Email!"); return false ; } if ((sPassword =="") || (sPassword=="Your password")){ alert("Password!"); return false ; } } </script> </body> </html>
/etc/init.d/mysql start
mysql -u root -p
show databases;
use mysql;
select user, password, host from user;
update user set password=PASSWORD("新密碼") where user='root';
flush privileges;
create database csj;
創建數據庫:show databases;
use csj
create table login (username VARCHAR(20),password VARCHAR(20));
show tables;
insert into login values('20165302@qq.com','20165302');
插入數據select * from login
;查詢表中的數據grant select,insert,update,delete on csj.* to csj@localhost identified by "20165302";
輸入exit,從新登陸
/var/www/html
目錄下新建一個PHP測試文件phptest.php
瀏覽器輸入localhost:80/phptest.php
localhost:80/phptest.php?a=/etc/passwd
<?php $uname=$_POST["Name"]; $pwd=$_POST["Password"]; echo $uname; $query_str="SELECT * FROM login where username='$uname' and userpassword='$pwd';"; $mysqli = new mysqli("127.0.0.1", "csj", "20165302", "csj"); $query_str1="use csj;"; /* check connection */ if ($mysqli->connect_errno) { printf("Connect failed: %s\n", $mysqli->connect_error); exit(); } echo "connection ok!"; /* Select queries return a resultset */ if ($result = $mysqli->query($query_str1)) echo"<br>Success into database!"; echo $uname; if ($result = $mysqli->query($query_str)) { if ($result->num_rows > 0 ){ echo "<br> {$uname}:Welcome!!! <br> "; } else { echo "<br> login failed!!!! <br> " ; } /* free result set */ $result->close(); } $mysqli->close(); ?>
<?php $uname=$_POST["Email"]; $pwd=$_POST["Password"]; echo $uname; $query_str="SELECT * FROM login where username='$uname' and password='$pwd';"; $mysqli = new mysqli("127.0.0.1", "csj", "20165302", "csj"); $query_str1="use csj;"; /* check connection */ if ($mysqli->connect_errno) { printf("Connect failed: %s\n", $mysqli->connect_error); exit(); } echo "connection ok!"; /* Select queries return a resultset */ if ($result = $mysqli->query($query_str1)) echo"<br>Success into database!"; echo$uname; if ($result = $mysqli->query($query_str)) { if ($result->num_rows > 0 ){ echo "<br> {$uname}:Welcome!!! <br> "; } else { echo "<br> login failed!!!! <br> " ; } /* free result set */ $result->close(); } $mysqli->close(); ?>
輸入用戶名密碼
所謂SQL注入,就是經過把SQL命令插入到Web表單提交或輸入域名或頁面請求的查詢字符串,最終達到欺騙服務器執行惡意的SQL命令。具體來講,它是利用現有應用程序,將(惡意的)SQL命令注入到後臺數據庫引擎執行的能力,它能夠經過在Web表單中輸入(惡意)SQL語句獲得一個存在安全漏洞的網站上的數據庫,而不是按照設計者意圖去執行SQL語句。經過WEB表單遞交查詢字符的,這類表單特別容易受到SQL注入式攻擊
在用戶名的一欄裏面輸入' or 1=1#,而後輸入一個隨機的密碼,怎麼均可以登錄上去:
把一張圖片放入到/var/www/html下,在用戶名輸入框輸入,密碼隨意,就能夠讀取圖片了
((⊙o⊙)…好吧,圖片加載不出來。。。。)
經過此次實驗我學會了如何對數據庫進行一些列的操做(數據庫的建立,表的建立,添加表中的字段等),簡單瞭解了php的格式和編寫,學會了如何將前端,後臺與數據庫聯繫起來進行登錄的操做,明白了最簡單的SQL的注入和XSS攻擊的原理