2017-2018-2 20155303 "Network countermeasure technology" Exp8:web Foundation

Source: Internet
Author: User
Tags php and mysql root access

2017-2018-2 "Network countermeasure Technology" Exp8:web Foundation

———————— CONTENTS ————————
    • I. Principles and Practice notes
      • 1. Practice Specific requirements
      • 2. Answers to basic questions
    • Two. Practice Process record
      • 1.Web Front End: HTML
      • 2.Web Front End: Javascipt
      • 3.Web backend: MySQL Basics
      • 4.Web backend: Writing PHP Web pages
      • 5. The simplest SQL injection, XSS attack test
    • Three. Practice Summary and experience
    • Attached: References

I. Principles and Practice notes

1. Practice Specific requirements
    • (1) Web front-end HTML (0.5 points)
      • Can install normally, start and stop Apache. Understand the HTML, understand the form, understand the get and post methods, and write an HTML containing the form.
    • (2) Web front end Javascipt (0.5 points)
      • Understand the basic JavaScript functionality and understand the DOM. Write JavaScript to verify the user name, password rules.
    • (3) Web backend: MySQL Foundation: normal installation, start MySQL, build library, create user, change password, build table (0.5 points)

    • (4) Web backend: Write PHP Web page, connect database, authenticate user (1 points)

    • (5) Simplest SQL injection, XSS attack test (1 points)
      • Function Description: User can login, login user name password saved in the database, login successfully display welcome page.

2. Answers to basic questions
    • (1) What is a form?
      • Forms are primarily responsible for data collection functions in Web pages. There are three basic components of a form:
      • Form Labels: Here The bread contains the URL of the CGI program used to process the form data and the method by which the data is submitted to the server.
      • Form fields: Contains text boxes, password boxes, hidden fields, multiline text boxes, check boxes, radio boxes, drop-down selection boxes, file upload boxes, and so on.
      • Form buttons: Includes the Submit button, reset button, and General button, which can be used to transfer data to CGI scripts on the server, or to cancel input, and to use form buttons to control other processing tasks that define the processing script.
    • (2) What language does the browser have to parse and run?
      • Support for HTML (Hypertext Markup Language), XML (Extensible Markup Language), as well as Python, PHP, JavaScript, ASP and many other scripting languages.
    • (3) What dynamic languages does webserver support?
      • The most commonly used three dynamic web languages are ASP (Activeserverpages), JSP (javaserverpages), PHP (Hypertextpreprocessor).
      • ASP full name Activeserverpages is a Web server-side development environment that leverages it to generate and execute dynamic, interactive, high-performance Web service applications. The ASP uses scripting language VBScript (Javascript) as its own development language.
      • JSP is Sun's new generation of web development language, Sun Company with its extraordinary attainments in Java, Java from Java applications and Javaapplet, but also a new fruit, is jsp,javaserverpage. JSP can complete powerful site program with the support of Serverlet and JavaBean.
      • PHP is a cross-platform, server-side, embedded scripting language. It borrows heavily from the syntax of the C,java and Perl languages and is coupled with PHP's own features, allowing web developers to quickly write dynamically generated pages.

Back to Catalog

Two. Practice Process record

1.Web Front End: HTML

1.kali has Apache installed by default, just use the service apache2 start command to open Apache service. , if there is no error, it indicates successful opening.

At this point in the browser input 127.0.0.1 , if you can open the default Apache Web page, then turn on success:

2. Using the cd /var/www/html go to Apache directory, create a simple HTML file containing the form simple_form.html :

simple_form.htmlThe contents are as follows:

In the browser try to open:

Back to Catalog

2.Web Front End: Javascipt

1. On the original simple_form.html basis, you can add a piece of JavaScript code to complete the user's decision whether to fill out the mailbox and password. The modified login_test.html is as follows:

2. In the browser access file:///var/www/html/login_test.html , if the user's mailbox or password is not filled in the submission, the webpage will be reported prompt:

Back to Catalog

3.Web backend: MySQL Basics

1. Enter the /etc/init.d/mysql start MySQL service to open:

2. Enter mysql -u root -p with root access, the default password is password :

3. Enter update user set password=PASSWORD("新密码") where user=‘root‘; , change password, enter flush privileges; , update permissions:

4. Enter the exit exit database and log in with the new password:

5. Use the create database 数据库名称; Build database:

6. Use show databases; to view the existing database:

7. Use use 数据库名称; the database that we created:

8. Use create table 表名 (字段设定列表); the Build database table and set the field basic information:

9. Use the show tables; view table information:

10. Use insert into 表名 values(‘值1‘,‘值2‘,‘值3‘...); Insert data:

11. Use select * from 表名; the data in the query table:

12. Add a new user to MySQL, use the grant select,insert,update,delete on 数据库.* to 用户名@登录主机(可以是localhost,也可以是远程登录方式的IP) identified by "密码"; instructions, this sentence means 将对某数据库的所有表的select,insert,update,delete权限授予某ip登录的某用户 :

13. After adding a new user, log in with a new user name and password:

A successful login indicates a successful addition of a new user.

Back to Catalog

4.Web backend: Writing PHP Web pages

1. /var/www/html Create a new PHP test file in the directory phptest.php to get a quick look at some of its syntax:

<?phpecho ($_GET["a"]);include($_GET["a"]);echo "This is my php test page!<br>";?>

2. Enter in the browser URL bar to localhost:80/phptest.php?a=/etc/passwd see /etc/passwd the contents of the file

3. Using PHP and MySQL, combined with the previously written login Web page for login identity authentication, the modified login.php code is as follows:

<?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", "diweijia", "970322", "dwjDB");/* 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_str)) {    if ($result->num_rows > 0 ){            echo "<br> {$uname}:Welcome!!! <br> ";    }     else {        echo "<br> login failed!!!! <br> " ; }    /* free result set */    $result->close();}$mysqli->close();?>

4. Enter access to 127.0.0.1/login.html your login screen in the browser.

5. Enter the username and password to authenticate and successfully log in as shown:

Back to Catalog

5. The simplest SQL injection, XSS attack test

1.SQL Injection:

SQL injection, by inserting a SQL command into a Web form to submit or entering a query string for a domain name or page request, eventually achieves a malicious SQL command that deceives the server. Specifically, it is the ability to inject (malicious) SQL commands into the background database engine execution using existing applications, which can be obtained by entering (malicious) SQL statements in a Web form to a database on a Web site that has a security vulnerability, rather than executing the SQL statement as the designer intended.

In the User name input box input ‘ or 1=1# , password arbitrary input, can login success:

This is because the input user name and our code in the combination of the SELECT statement to become select * from users where username=‘‘ or 1=1#‘ and password=‘‘ , #相当于注释符, will be the following comments out, and 1=1 is always true, so this condition forever, so regardless of whether the password is entered correctly, can be successfully landed.

2.XSS attack:

Cross Site scripting attacks (Scripting), which are not confused with the abbreviations of cascading style sheets (cascading style Sheets, CSS). Therefore, the cross-site scripting attack is abbreviated as XSS. XSS is a computer security vulnerability that often appears in web applications, allowing malicious Web users to embed code into pages that are available to other users. For example, the code includes HTML code and client script. An attacker could bypass access control by using an XSS vulnerability-such as the Origin policy (same). This type of vulnerability is widely known as being used by hackers to write more damaging phishing attacks.

Put a picture in the /var/www/html directory, in the User name input box input , the password is arbitrary, you can read the picture:

Back to Catalog

Three. Practice Summary and experience

The second-to-last experiment!! The experiment was carried out very smoothly. Unlike the previous experiment, "starting from scratch", the experiment is more like the integration and application of the previously learned knowledge. Front-end programming these knowledge, in the school period Liu Nian teacher's curriculum has roughly studied, at that time also independently completed a certain function of a small website. And the knowledge of the database in Lou Teacher's class last year has been known, the difficulty of understanding relatively small. But like "SQL injection" before also only in class to see the teacher demonstration, this hands-on practice, the principle also has a more profound understanding.

Back to Catalog

Attached: References
    • Installation and configuration of Apache,php,mysql
    • HTML Tutorials

2017-2018-2 20155303 "Network countermeasure technology" Exp8:web Foundation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.