谨防ddos_能不能防_ddos防火墙拦截国外ip-墨者安全-墨者盾
DDOS防御_CC防护_高防CDN服务器_【墨者安全】—墨者盾墨者盾—你的网站贴身保镖!

QQ:800185041
高防免费接入:400-0797-119

渠道合作:156 2527 6999

主页 > 网站防护 > 谨防ddos_能不能防_ddos防火墙拦截国外ip

谨防ddos_能不能防_ddos防火墙拦截国外ip

小墨安全管家 2021-04-08 13:33 网站防护 89 ℃
DDoS防御

谨防ddos_能不能防_ddos防火墙拦截国外ip

"; } In the above example, I am disabling code that may be stored in the database or passed in by the end user from being rendered as executable html in the browser. The command htmlspecialchars() replaces characters like < with markup equivalent such as <. Conclusion Clearly this is a simple application, but this secure PHP code is reusable and you can build on it when you create your own applications. Code Examples Used in Writeup: createdb.sql CREATE DATABASE `contactsSchema` ; USE contactsSchema; CREATE TABLE `contactsTable` (     `id` int(11) NOT NULL AUTO_INCREMENT,     `first` VARCHAR(40) DEFAULT NULL,     `last` VARCHAR(64) DEFAULT NULL,     `email` VARCHAR(256) DEFAULT NULL     PRIMARY KEY (`id`) ) ENGINE=InnoDB;  CREATE USER 'contactsUser'@'localhost' identified by 'superSecretPassword'; GRANT SELECT, INSERT, UPDATE, DELETE     ON contactsSchema.contactsTable TO 'contactsUser'@'localhost'; INSERT INTO contactsTable (id, first, last, email) values(null, 'Alexander', 'Bell', 'alexander@bell.com'); Index.php facebook linkedin twitter Reading Time: ~ 5 min.PHP is an incredibly popular language for creating dynamic web applications — websites such as Facebook are built on it. This can be attributed to many reasons; it is easy to learn, easy to install and does not require the user to compile code. An unfortunate side effect of the ease of development with PHP is a tendency to ignore security during the development process. In this post, I will discuss some of the ways to make your PHP apps more secure. I will go through creating a PHP web app that connects to a MySQL back end database. The application will be a simple address book. The approach I will take to secure the PHP code is one of layered security. There is no sure fire quick method of blocking all attacks, but using the layered security approach we severely limit our exposure. Two of the attacks we will mitigate are SQL Injection (SQLi) and Cross Site Scripting (XSS). Both of these attacks are performed by exploiting applications that do not properly handle user input. XSS occurs when an application sends the users browser back input that has not been checked for code. If an attacker were to enter something similar to the text below in a form field, it would cause the browser to execute the code and create a pop up on the screen displaying the text "XSS". "> Similarly SQLi is caused by an attacker running unplanned SQL code against the database. An example would be if an attacker were to enter the following in a form, the browser would display all the data in the user table: ;select * from users; I will use PHP built-in methods such as htmlspecialchars(), mysqli_real_escape_strings() and use prepared statements to help prevent the attacks mentioned above. In our sample training contact list app, the database will store the following fields: ●First Name ●Last Name ●email address To create the database, I ran the following code as a privileged user, it is attached at the bottom of this post as createdb.sql.  mysql -uroot -p -h 127.0.0.1 mysql CREATE DATABASE `contactsSchema` ; USE contactsSchema; CREATE TABLE `contactsTable` (     `id` int(11) NOT NULL AUTO_INCREMENT,     `first` VARCHAR(40) DEFAULT NULL,     `last` VARCHAR(64) DEFAULT NULL,     `email` VARCHAR(256) DEFAULT NULL     PRIMARY KEY (`id`) ) ENGINE=InnoDB;  CREATE USER 'contactsUser'@'localhost' identified by 'superSecretPassword'; GRANT SELECT, INSERT, UPDATE, DELETE     ON contactsSchema.contactsTable TO 'contactsUser'@'localhost'; INSERT INTO contactsTable (id, first, last, email) values(null, 'Alexander', 'Bell', 'alexander@bell.com'); For the application, I will forego the authenticated login functionality, that is a bit out of scope for a primer, I’ll cover that in another post. In the PHP page, which is attached at the bottom as index.php, I will highlight some of PHP code that makes this contacts app more secure. 1. strip_tags() #User passed in vars isset ( $_REQUEST['i'] ) ? $i = strip_tags($_REQUEST['i']) : $i = ""; isset ( $_REQUEST['s'] ) ? $s = strip_tags($_REQUEST['s']) : $s = ""; I am only allowing variables from the user that I am specifying. Next I am running strip_tags() on them to remove any html tags in the text. This however does not get all extra characters. 2. mysqli_real_escape_string() $first=mysqli_real_escape_string($db, $first); In the above code snippet, the mysqli_real_escape_string() method is used to escape any special characters. This is used as the variable is provided by the user. Anything the user enters should be sanitized. However mysqli_real_escape_string() does not protect against all threats. 3. Prepared Statement if ($stmt = mysqli_prepare($db,  "INSERT INTO contactsTable SET first=?, last=?, email=?,")) {                mysqli_stmt_bind_param($stmt, "sss", $first, $last, $email);                mysqli_stmt_execute($stmt);                mysqli_stmt_close($stmt); } In this code we are using prepared statements to limit the functionality of the query. In this example, I am only passing in variables to execute in this query, it prevents nested queries, which are a common SQLi attack. 4. htmlspecialchars() function displayResults($first, $last, $email) {  echo " " . htmlspecialchars($first)  . "   ";        echo "" . htmlspecialchars($last)  . "   ";        echo "" . htmlspecialchars($email)  . "  
防DDoS,防DDoS,CC防御DDoS防御


DDoS防御

当前位置:主页 > 网站防护 > 谨防ddos_能不能防_ddos防火墙拦截国外ip

标签列表
DDoS防御
网站分类
X
 

QQ客服

400-0797-119