


Detailed explanation of DoS attack analysis and defense of 12 lines of JS code
There is a 12-line JavaScript code that can crash Firefox, Chrome, and Safari browsers, and can also cause iPhones to restart and Android to crash. The author of this article analyzed and interpreted these 12 lines of code. We also put forward corresponding defense methods, and everyone is welcome to discuss them together. Here is an article about these 12 lines of js code: How do these 12 lines of code make the browser explode?
Ajax and pjax
Ajax is "Asynchronous Javascript And XML" (Asynchronous JavaScript and XML), which is a technology used to create fast dynamic web pages. Ajax allows web pages to be updated asynchronously by exchanging a small amount of data with the server in the background. This means that parts of a web page can be updated without reloading the entire web page.
However, Ajax applications can also cause other problems, which can easily cause the browser to be unable to move forward and backward. This is a very troublesome problem, and developers must increase their workload (such as through a hidden iframe, or changing the location .hash value and other methods) to solve it.
In order to solve the problems caused by traditional Ajax, a new API was introduced in HTML5: history.pushState. After it is combined with Ajax, it has a new name called pjax. It is a new technology based on Ajax+history.pushState. This technology can change the content of the page without refreshing, and can change the URL of the page. pjax is an encapsulation of Ajax+pushState and supports multiple functions such as local storage and animation. Currently supports jquery, qwrap, kissy and other versions.
HTML5.history.pushState
HTML5 can operate the browser history through the pushState and replaceState interfaces, and change the URL of the current page.
pushState adds the specified URL to the browser history and stores the current history point. replaceState replaces the current URL with the specified URL. At the same time, these methods will work with the window.onpostate event.
history.pushState(data, title, url): Add a record to the top of the history stack; data will be passed as a parameter when the onpopstate event is triggered; title is the page title, which is generally ignored by all current browsers. This parameter; URL is the page address, optional, and the default is the current page address. Specific details:
state: The object is a JavaScript state object, an additional object that records historical points, and can be empty. It is related to the new history entity created by the pushState() method. Used to store information about the entry you want to insert into the history.
title: All browsers generally ignore this parameter, although it may be used in the future. The safest way to use it now is to pass an empty string to prevent future modifications, or you can pass a short title to represent the state.
URL: This parameter is used to pass the URL of the new history entity. The new URL must be in the same domain as the existing URL, otherwise pushState() will throw an exception. This parameter is optional. If left blank, it will be set to the current URL of the document.
Twelve lines of code analysis
The picture above is the twelve lines of code. The key point is the loop for the total URL: history.pushState(0,0,total); constantly Modifying the URL, looping it 1,000,000 times, and constantly adding new records to the history stack will cause high CPU and memory usage, crash Firefox, Chrome, and Safari browsers, and also cause the iPhone to restart.
Analysis results
Personally measured on an XP virtual machine (i7 single core 3.4G, 512 memory):
When the number of cycles above is ten When the level is above 10,000, the CPU and memory usage will be 100% instantly, and then crash and freeze;
When the number of cycles above is reduced to about 10,000, the CPU and memory usage will be about Gradually increased to 100% within 20 seconds, and then crashed;
When the number of cycles above was reduced to about 500, the CPU usage gradually increased to 100%, and then again It returned to a stable state instantly, and the memory usage increased from about 130M to about 230M. After opening the 192.168.56.106/12.html page, the link in the address bar also changed to: 192.168.56.106/0123456789101112131415161718192021...49449549649749 8499
It can be seen that while continuously adding records to the history record stack through the loop, the page will be refreshed to the new jump address, which is a "pseudo address" accumulated in the loop. When this length exceeds the limit, it will cause DOS. The effect and efficiency of the attack completely depend on the number of loops and the target's hardware configuration.
Relevant Defense
I believe that everyone’s security awareness is already very strong, but you still need to sound the alarm. Don’t trust any links, attachments, or emails sent to you by any stranger in any way. , pictures and other information, of course it does not rule out the pranks of good friends and bad friends, so friends, remember to Ctrl+S often, otherwise you will be very depressed if your computer crashes.
The Internet has been exposed to hacker attacks since its birth. Early hacker attacks were more or less for the purpose of technical experimentation and showing off. However, with the growth of the global Internet infrastructure, the unlimited growth of connections and the number of users, With the rapid expansion of the number, the frequency of hacker attacks has also increased accordingly. Hacker technology has also continued to develop, and a black industry chain for the purpose of illegally obtaining economic benefits has gradually emerged. The technical level of Internet security protection is advancing by leaps and bounds. Attack and defense are happening every minute and every second in this Internet era.
Of course, the Internet is full of information security threats. Network security protection depends on technology seven times and awareness three points. To protect against these problems, it is far from enough to rely solely on the products and services of security manufacturers. Network security The increase in awareness cannot be ignored.
For example: pay attention to the management of personal passwords, pay attention to the protection of personal privacy, do not easily access public wifi, do not easily trust links or files from strangers/familiar friends, etc., pay attention to the security of mobile payments, and do not let your device "Streaking" and so on.
The above is the detailed content of Detailed explanation of DoS attack analysis and defense of 12 lines of JS code. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

JavaScript is a programming language widely used in web development, while WebSocket is a network protocol used for real-time communication. Combining the powerful functions of the two, we can create an efficient real-time image processing system. This article will introduce how to implement this system using JavaScript and WebSocket, and provide specific code examples. First, we need to clarify the requirements and goals of the real-time image processing system. Suppose we have a camera device that can collect real-time image data
