当前位置:网站首页>What are CSRF, XSS, SQL injection, DDoS attack and timing attack respectively and how to prevent them (PHP interview theory question)
What are CSRF, XSS, SQL injection, DDoS attack and timing attack respectively and how to prevent them (PHP interview theory question)
2022-07-05 14:58:00 【Back end regular developers】
PHP Interview theory questions
CSRF、XSS、SQL Inject 、DDOS attack 、 What are sequential attacks and how to prevent them
1、CSRF
(1) CSRF brief introduction :
CSRF(Cross-site request forgery) Cross-site request forgery , Also known as “One Click Attack” perhaps Session Riding, Commonly abbreviated as CSRF perhaps XSRF, Is a malicious use of the site .
(2) CSRF The harm of the attack
The main harm comes from , The attacker embezzles the user's identity , Send a malicious request . such as : Simulate users to send mail , Send a message , And pay 、 Transfer, etc .
XSS It mainly uses the trusted users in the site , and CSRF By disguising requests from trusted users , To take advantage of trusted websites . And XSS Compared to attack ,CSRF More dangerous .
(3) prevent CSRF Solutions for
- Important data interaction adopts POST Receive , Of course POST It's not everything , Forge a form The form can be cracked .
- Use verification code , As long as the data interaction is involved, the verification code shall be verified first , This method can completely solve CSRF.
- But for the sake of user experience , Web site can not give all the operations together with a verification code . So the verification code can only be used as an auxiliary means , Not as a major solution .
- verification HTTP Referer Field , This field records this HTTP The source address of the request , The most common application is the image anti-theft chain .
- Add a token for each form token And verify .
2、XSS
(1) XSS brief introduction
Cross site scripts (cross site script) Referred to as XSS, It's a common occurrence in web Computer security vulnerabilities in application , It's also web The most popular way to attack .
XSS It refers to the defect that the malicious attacker uses the website to escape the data submitted by the user or to filter the data insufficiently , And then add some code , Embedded in web Go to , So that other users access will execute the corresponding embedded code .
(2) XSS The harm of the attack
- Stealing user data , such as : Login account 、 Online banking account number, etc
- Use user identity , Read 、 Tampering 、 add to 、 Delete data, etc
- Steal important commercial materials
- Illegal transfer
- Mandatory E-mail
- Website hanging horse
- Control the victim's machine to attack other websites
(3) prevent XSS Solutions for
- XSS The root cause of is that the data submitted by the client is not completely filtered , So the key is to filter the information submitted by users .
- Will be important cookie Marked as http only, In this case js Medium document.cookie Statement cannot get cookie 了 .
- Only allow users to enter the data we expect . for example :age User age only allows users to enter numbers , All characters except numbers are filtered out .
- On data Html Encode Handle : When users submit data HTML code , Convert the corresponding symbols into entity names, and then proceed to the next step .
- Filter or remove special Html label .
- Filter js Label of event . for example “οnclick=”, “onfocus” etc. .
3、SQL Inject
(1) SQL Introduction to injection
SQL Injection is one of the most common network attacks , Mainly through SQL Command insert into Web Form submit or input the query string of domain name or page request , Realize no account login , Even tampering with the database .
(2) SQL The harm of injection attack
- Database information leakage : The disclosure of the user's privacy information stored in the database ;
- Webpage tampering : Tamper with specific web pages by operating the database ;
- The database was maliciously manipulated : The database server was attacked , The system administrator account of the database has been tampered with ;
- The server is remotely controlled , The rear door is installed ;
- Delete and modify database table information .
(3) SQL The way of Injection
Usually ,SQL Injection locations include :
- Form submission , Mainly POST request , Also include GET request ;
- URL Parameter submission , Mainly for GET Request parameters ;
- Cookie Parameter submission ;
- HTTP Some modifiable values of the request header , such as Referer、User_Agent etc. ;
(4) prevent SQL Injected solutions
- Verify the user's input , Use regular expressions to filter the incoming parameters ;
- Use parameterized statements , Do not splice sql, You can also use secure stored procedures ;
- Do not use a database connection with administrator privileges , Use limited database connections for each application ;
- Check the data storage type ;
- Important information must be encrypted ;
4、DDOS
(1) DDOS brief introduction
- DOS attack (Denial of Service Denial of service attacks ): Any attack means that users cannot continue to use normal services due to insufficient network security protection measures , Can be called a denial of service attack , Its purpose is to consume network broadband or system resources , Make the network or computer unable to provide normal services .
- DDOS(Distributed Denial of Service , Distributed denial of service ), Any attacker who controls the puppet host on the network , At the same time, the way they launch denial of service attacks against the target host is called distributed denial of service attack .
(2) DDOS The harm of the attack
- Make the customer's business unavailable 、 Loss of interest
- A service in the customer network is attacked , Customer networking is blocked in an all-round way , All businesses are paralyzed , Serious chain reaction
- The political impact of the attack 、 The pressure of public opinion brings reputation loss to the enterprise
(3) How to defend DDOS attack
- Update system patches in time
- Install software and hardware for killing , Update virus database in time
- Set complex passwords , Reduce the possibility of the system being controlled
- Close unnecessary ports and services
- Often detect the vulnerability of the network , Find problems and fix them in time .
- For important web The server can establish multiple images to realize load balancing , Reduce to a certain extent DDOS Hazards of
5、 Timing attacks
(1) Introduction to timing attack
In cryptography , Timing attack is a side channel attack , The attacker attempts to deduce the password after analyzing the time execution of the encryption algorithm . Each logical operation takes time to execute in the computer , Different according to the input , Accurately measure the execution time , Reverses the password according to the execution time .php
If it is ordinary == To compare , Then the two strings are compared one by one from the first bit , If you find something different, return immediately false, After calculating the return speed, you can know which one started different , In this way, the scene of cracking passwords by bits, which often appears in movies, is realized .
(2) How to defend against sequential attacks
php In order to deal with this situation , Able to use hash_equals function .
Extract a passage from php Information in the manual :
hash_equals ( string $known_string , string $user_string ) : bool
Compare two strings , Whether they are equal or not , The time consumption of this function is constant .
This function can be used in string comparison scenarios that need to prevent timing attacks , for example , Can be used to compare crypt() The scenario of password hash value .
<?php
$expected = crypt('12345', '$2a$07$usesomesillystringforsalt$');
$correct = crypt('12345', '$2a$07$usesomesillystringforsalt$');
$incorrect = crypt('apple', '$2a$07$usesomesillystringforsalt$');
var_dump(hash_equals($expected, $correct));//true
var_dump(hash_equals($expected, $incorrect));//false
?>
Reproduced in :
https://www.cnblogs.com/tudou1223/p/11506574.html
https://blog.csdn.net/LuHai3005151872/article/details/121903785
边栏推荐
- Penetration testing methodology
- CODING DevSecOps 助力金融企业跑出数字加速度
- 【招聘岗位】软件工程师(全栈)- 公共安全方向
- [detailed explanation of Huawei machine test] happy weekend
- 【jvm】运算指令
- 729. 我的日程安排表 I :「模拟」&「线段树(动态开点)」&「分块 + 位运算(分桶)」
- js亮瞎你眼的日期选择器
- 微帧科技荣获全球云计算大会“云鼎奖”!
- Anaconda uses China University of science and technology source
- 【华为机试真题详解】字符统计及重排
猜你喜欢
【NVMe2.0b 14-9】NVMe SR-IOV
美团优选管理层变动:老将刘薇调岗,前阿里高管加盟
Pointer operation - C language
危机重重下的企业发展,数字化转型到底是不是企业未来救星
PHP - fatal error: allowed memory size of 314572800 bytes exhausted
市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生
当代人的水焦虑:好水究竟在哪里?
如何将电脑复制的内容粘贴进MobaXterm?如何复制粘贴
1330:【例8.3】最少步数
Selection and use of bceloss, crossentropyloss, sigmoid, etc. in pytorch classification
随机推荐
在Pytorch中使用Tensorboard可视化训练过程
Mongdb learning notes
漫画:程序员不是修电脑的!
选择排序和冒泡排序
Jmeter性能测试:ServerAgent资源监控
maxcompute有没有能查询 表当前存储容量的大小(kb) 的sql?
GPS原始坐标转百度地图坐标(纯C代码)
Implement a blog system -- using template engine technology
I want to inquire about how to ensure data consistency when a MySQL transaction updates multiple tables?
JMeter performance test: serveragent resource monitoring
当代人的水焦虑:好水究竟在哪里?
Fr exercise topic --- comprehensive question
想进阿里必须啃透的12道MySQL面试题
危机重重下的企业发展,数字化转型到底是不是企业未来救星
【jvm】运算指令
mysql8.0JSON_ Instructions for using contains
Explain Vue's plan to clean up keepalive cache in time
MongDB学习笔记
CPU设计实战-第四章实践任务二用阻塞技术解决相关引发的冲突
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成