当前位置:网站首页>Most PHP programmers don't understand how to deploy safe code
Most PHP programmers don't understand how to deploy safe code
2022-07-29 05:51:00 【Liaoshengping】
If your website is still based on 777 As permission , Then your server will be open to anyone , Anyone can execute scripts in the directory .
I have seen some outsourcing projects of others , Unexpectedly, the permissions of the whole project are set to 777 , In fact, it is very terrible , Hackers can upload files to any directory , And execute the file .
This is terrible , Some programmers can use some tools to scan for vulnerabilities , Like a lot of php The programmer said in his resume , Cracked php, Implant the back door, etc , It's all because of the early php Low threshold for programmers , Weak awareness of safety , Many websites can get Shell.
How to set it up correctly php Running directory ? Let me summarize some methods , Share with you .
Set the owner of the directory
php The program is generally for nginx perhaps apche Called , So the system will have a www( Depending on the situation , Some are www-data)
Of users and user groups
sudo chown -R www-data:www-data /path/to/your/laravel/root/directory
But if we use php artisan command , Or when you want to use FTP Transfer files to the server , Setting permissions like this will result in an error , Because the permission of this directory belongs to www-data:www-data Users and user groups . You should add to web In the user group of .(ubantu It's called ubantu,vagrant It's called vagrant)
sudo usermod -a -G www-data ubuntu
Set the permissions
First of all, restore your original program
to php Read and write permissions required by the framework .
Laravel:
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
If it is Tp frame :
sudo chgrp -R www-data runtime
sudo chmod -R ug+rwx runtime
So your php The framework is relatively safe .
Upload permission
Some of our small programs need to upload pictures or files to the server ( But it is recommended to upload to OSS Or a third-party storage scheme such as seven cows .)
Prevent the uploaded program from being attacked by malicious programs , We can do it in Nginx perhaps Apache Refuse to run php Script
Nginx:
location ~ ^/(uploads|assets)/.*\.(php|php5|jsp)$ {
deny all;
}
Apache:
RewriteEngine on RewriteCond % !^$
RewriteRule uploads/(.*).(php)$ – [F]
This is so , Your program is covered with a thick shield
边栏推荐
猜你喜欢
Training log III of "Shandong University mobile Internet development technology teaching website construction" project
Crypto giants all in metauniverse, and platofarm may break through
Day14: upload labs customs clearance tutorial
Breaking through the hardware bottleneck (I): the development of Intel Architecture and bottleneck mining
Fantom (FTM) prices will soar by 20% in the next few days
Okaleido Tiger 7.27日登录Binance NFT,首轮已获不俗成绩
闪贷Dapp的调研及实现
MOVE PROTOCOL全球健康宣言,将健康运动进行到底
Thinkphp6管道模式Pipeline使用
第五空间智能安全⼤赛真题----------PNG图⽚转换器
随机推荐
Idea using JDBC to connect mysql database personal detailed tutorial
The difference between link and @import importing external styles
Differences between href and SRC
Okaleido Tiger 7.27日登录Binance NFT,首轮已获不俗成绩
The openatom openharmony sub forum was successfully held, and ecological and industrial development entered a new journey
钉钉告警脚本
全闪分布式,如何深度性能POC?
Plato Farm有望通过Elephant Swap,进一步向外拓展生态
"Shandong University mobile Internet development technology teaching website construction" project training log I
“山东大学移动互联网开发技术教学网站建设”项目实训日志二
Super simple integration of HMS ml kit to realize parent control
What is nmap and how to use it
Countdown of the uniapp component (such as the countdown to reading the agreement and the countdown to completing learning)
Win10 compiles ffmpeg (including ffplay)
北京宝德&TaoCloud共建信创之路
加密资产熊市之下,PlatoFarm的策略玩法依旧能获得稳定收益
焕然一新,swagger UI 主题更改
Plato farm is expected to further expand its ecosystem through elephant swap
C# 连接 SharepointOnline WebService
XDFS&中国日报社在线协同编辑平台典型案例