20155339 EXP8 Web Foundation

Source: Internet
Author: User
Tags php language php and mysql php error

EXP8 answers to the basic questions of Web Foundation

(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, which contain the URL of the CGI program used to process the form data and how the data is submitted to the server.
      • form fields, including 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, including the Submit button, reset button, and General button, 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) The browser can parse what language to run.
Hypertext Markup Language, Extensible Markup Language, and scripting language.
Hypertext Markup Language: HTML
Extensible Markup Language: XML
Scripting languages: ASP, PHP, script, JavaScript, VBScript, Perl, Python, ColdFusion, Java, JSP, etc.
(3) What dynamic languages are supported by webserver
ASP language, PHP language and JSP language

Practice Summary and experience

This practice is used for a long time, fortunately there is the foundation of Web programming last semester, or all from the beginning of the estimated time, web programming is a very attention to detail of the practice, because of their negligence this experiment can meet the problems I basically met once, So, the most necessary thing to do the experiment is patience and careful, after all, is not the things slowly practice has reached the goal of mastering these knowledge, so still need to constantly self-encouragement. Practice end recall also learned a lot of things, but still that sentence this course more afraid, dangerous everywhere, after those do not know what is the link or do not point, at the same time we can also use these fur for some relatively low-level Web virus to prevent.

Practice Process Record Web Front end: HTML base Apache
    • Choose Apache as a Web server, so you first need to install Apache, terminal type sudo apt-get install apache2 to install, but before the installation check your own Kali, open Apache, type service apache2 start , have Apache but open failed, Print out the Apache service startup information to look at, such as.

    • Problem found, port 80 is occupied. Here are two methods, one, type to netstat -tupln |grep 80 see 80 port Usage, and then kill+idnum kill the program through, then lifted the use of 80 port; second, modify the Apache configuration file, the configuration file directory for /etc/apache2/apache2.conf use to vi open it, you can see that there are two lines below, The profile name of the listening port used to define the APACHE2:

      # Include list of ports to listen onInclude ports.conf

      If there are other applications that have port conflicts, you can modify ports.conf vi them by opening them to Listen 80 something else.

    • Try to turn on success again.

    • Looking at the current port occupancy information, you can see that port 8088 has been given to Apache.

    • Test whether Apache is working properly, the browser opens 127.0.0.1:8088, can open the Web page normally.

    • Test Apache can read the file under the working directory, vi /var/www/html/test.txt enter 20155339 browser open 127.0.0.1:8088/test.txt can see Test.txt content, success.

Web front-end HTML
    • Apache's working directory is /var/www/html , cd /var/www/html open the directory into the Apache working directory, type vi login.html write a simple Web page, including a form, enter a user name, password and then submit, the code is as follows:
    • Put it on the online editor to see how this page works.

    • Here we do not want action, that is, log in after the page does not want to jump, so the action is filled with ' # ', that is, jump to the current page.

Web Front End: Javascipt
    • Write a JavaScript to validate the user name, password rules.
    • When clicking Login will automatically jump to my verification function, when the user name is empty, prompt for the user name, and return a false exit, when the password is empty, prompt for a password, and return a false exit, put the modified code into the online tester to test.

Web backend: MySQL Base login Change Password
    • Open MySQL, type the command in the terminal, /etc/init.d/mysql start enter mysql -u root -p , and follow the prompts to enter the password, note that the default password is [email protected], not empty.

    • Type to show databases; see basic information, be sure to add a semicolon oh, the database with a semicolon as the end of a statement .

    • Change the password, first select MySQL, type use mysql; , enter the update user set password=PASSWORD("新密码") where user=‘root‘; change password, to update flush privileges; .

    • Enter quit exit login, type again mysql -u root -p , test the new password right, OK, login successfully.

Build a database and build a table
    • Next create the database and the new table, first create a database, type the command create database pc; , it is important to note that the database name can not be a number; Use a show databases; view of the existing database, verify that the database you just created is in it, and then type in the use 库名 database you just created.
    • Use create table 表名 (userid VARCHAR(100),username VARCHAR(45),password VARCHAR(256),enabled VARCHAR(5)); .

    • Insert a piece of data, insert into pc values(1,‘20155339‘,‘1111‘,"TRUE"); use the select * from 表名; data in the query table, * To query all parameter information, or you can specify a parameter such as username to query.

    • Add new user to give all permissions, type grant all on pc.* to [email protected] identified by ‘20155339‘; , which grant all gives all permissions to the pc.* database pc in all the tables, the @localhost MySQL server on the local computer, set the identfified by ‘password‘ password.

    • Type mysql -u pc -p sign in with a new user, verify that the new user is successful, sign in successfully, and that the new user is successful.

Web backend: Writing PHP Web pages
    • We can create a new PHP test file in the /var/www/html directory and get a quick look at some of its syntax.

    • In Browser input http://127.0.0.1:8088/test.php , you can see the contents of the PHP I just wrote.

    • after a simple test, we can use PHP and MySQL in conjunction with the front-end code, complete the login system, to achieve a simple user identity authentication. The
    • has been improved with the teacher-provided code as a template, and the login.php has been written.

  <?php$uname= ($_get["username"]), $pwd = ($_get["password"]);/* echo $uname; */$query _str= "SELECT * FROM PC where Username= ' {$uname} ' and password= ' {$pwd} '; "; * echo "<br> {$query _str} <br>"; */$mysqli = new Mysqli ("127.0.0.1", "root", "20155339", "PC");/* Check Connect    Ion */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> Wellcome login mr/mrs:{$uname} <br>"; } else {echo ' <br> login failed!!!!    <br> "; }/* Free result set */$result->close ();} $mysqli->close ();?  
    • Here are a few things to note, in the new MySQL object must be in the database now exist in the database, user name, database password, and database names need to be pointed out.

    • In the /var/www/html working directory, create a new one pc.html to write the front end of the code to save, here also need to modify a place is not before our front-end code after the operation, so the action "#", now we have the backend program, so action need to point to the backend, To send the data to our backend, so action the arguments in the argument are changed Login.php .

    • Enter the browser localhost:8088/pc.html to access your page.

    • Seems to have succeeded, and then tried the wrong user name and password, but still.

    • OK, where wrong a little hint is not, start looking for it, because PHP is based on the teacher to provide, so I think PHP is correct, the front end and the database to check n times, did not find any problems, read the classmate's blog are prompted, but I did not, Since it is in login.php error, so think it may be php problem, found that the back-end teacher can not search my data, why? Look carefully, originally did not change the table name.

    • Modify table name login again, there is a problem, the correct user name and password failed to log in.

    • Then it should be my PHP still have a problem, check again, found that it is using the Get method, and my front end with the post is not because of this reason, modify PHP to try again, can be the success of this login.

SQL injection
  • A SQL injection vulnerability is a security vulnerability in a Web application that handles background database query statements. That is, embedding SQL directives in the input string ignores checking of special strings that might constitute an attack in the design program. After the background database is considered as normal SQL instructions, it is possible to perform various operations on the background database and even cause serious consequences such as destroying the backend database.
  • SQL injection is generally divided into ordinary injection and blind.
    • Normal injection: The background database will echo the valuable information, which can be easily injected through these possible error messages, suitable for beginners training.
    • Blind Note: The background administrator does not provide detailed error information when giving the error page. An attacker would need to use a script to probe each of the fields in the table using only the judgment information, such as the time difference, for injection.
  • This practice is mainly for ordinary injection.
  • In the User name input box, enter the ‘ or 1=1# password casually, this time the SQL query statement after the synthesis, select * from lxmtable where username=‘‘ or 1=1#‘ and password=‘‘ #相当于注释符, will be the back of the content is commented out, so the equivalent of select * from lxmtable where username=‘‘ or 1=1 1=1 is always true, so this condition is definitely established, so you can successfully login.

  • You can also insert a forged user name and password into the database via SQL injection.
  • First modify the back-end of the PHP code, the if ($result = $mysqli->query($query_str)) sentence is changed to if ($result = $mysqli->multi_query($query_str)) allow the execution of multiple SQL statements, so you can implement multiple SQL statements, and then enter in the User name input box ‘;insert into pc values(‘100‘,‘5339‘,‘5339‘,"true");# , enter a password, and then login, appear as follows.

  • Check the database to see if the insert succeeds, and the newly inserted user has successfully appeared.

  • Change PHP back, log in again with the newly inserted user, and log in successfully.

XSS attack
    • What is an XSS attack first? XSS attacks, the cross site Scripting, are not confused with the abbreviation for Cascading style sheets (cascading style Sheets, CSS), which is a computer security vulnerability that often appears in Web applications. It allows 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. For cross-site scripting attacks, the hacker consensus is that cross-site scripting attacks are a new type of "buffer overflow attack", and JavaScript is the new "ShellCode". There are three types of
    • :
      • 1. A local exploit vulnerability exists in the client script itself on the page. That is, a to B a link B opens a vulnerable HTML page that contains the JavaScript that is executed in the local domain of computer B.
      • 2. Reflection vulnerability, which is similar to type A, unlike when Web clients use server-side script generation pages to provide data to users, if unauthenticated user data is included in the page without HTML entity encoding, The client code can be injected into the dynamic page, which involves a site owner A and User B, and hacker C.
      • 3. Directly threatens the individual user, while type B and type C threaten to be an enterprise-class Web application. A storage vulnerability, which is the most widely used and potentially vulnerable to Web server security, that hackers upload an attack script to a Web server so that all users who access the page face the possibility of information disclosure, including the administrator of the Web server.
    • Type 1 directly threatens the individual user, while types 2 and 3 threaten objects that are enterprise-class Web applications.
    • in the User name input box, enter 1111</A> read the picture in the /var/www/html directory, Tried a number of pictures, the Internet to search, still like, finally found that it seems to be my Kali security is relatively strong!

20155339 EXP8 Web Foundation

Related Article

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.