


Let's talk about the security settings of our company's server!_PHP Tutorial
The work that the author has been doing for a long time is basically developing the company's PHP program and maintaining several CentOS servers. During the long period of work, I have summarized a set of small means to deal with attacks. I dare not hide my secrets. Share it with everyone, hope you all like it!
First let’s talk about the setting of the server. The server is inside the company. It is directly connected to a fiber optic cable and has 7 fixed IPs. Each server has its own fixed IP. In addition, each server has its own fixed IP. It is a dual network card. In addition to having a fixed IP on the external network, it also belongs to the same internal network. These 7 fixed IPs are distributed through a hardware firewall with routing function. The hardware firewall only opens port 80 to the outside world, and the rest are All are turned off. The servers are basically CentOs, and only one is Windows. CentOs all have the firewall that comes with the Linux system turned on. During remote management, they use some special means to connect to a certain location on the LAN where the server is located. On a server with Windows operating system, you can then control each server through SSH installed on this Windows. Although this setting is very troublesome, it is very safe. (I would like to add here that the firewall of each server They all set rules that allow a certain intranet IP to have one-way SSH connection. This setting is more cumbersome. It’s a long story for a child without a mother. Since it’s very long, I won’t go into it.)
In this case, you may ask, what is there to attack if you only open an 80? In fact, it is not the case. First of all, a certain company often uses the webbench stress testing tool to try to paralyze nginx. There is no way because this program has been used before. They developed it. They know that this program consumes extremely CPU resources when running. Secondly, many netizens from the mainland speculate on the potential loopholes of this program, such as guessing the administrator's backend entrance and guessing whether there are compressed files of website backups placed on the server. Wait, all of their access methods are for port 80. If certain measures are not taken, Nginx will often be paralyzed, resulting in error 500 or error 502 on the website, and I don’t need to worry about the harm of those guesses. Having said that, the author has no choice but to take some measures to suppress the many unfriendly visitors mentioned above.
In fact, the method is not complicated. First, I will use PHP to obtain the visitor's access intention. If the other party's intention is sinister or evil and meets my blocking conditions, then kill him! First, use PHP to automatically create A file like .sh. The content of this file is used to rewrite the Linux firewall rules (of course I can also rewrite the rules of the hardware firewall, but it’s too troublesome, so I’d better be lazy!). Modify this .sh file. The attributes and owners allow it to be executed, and then use Linux's crontab to obtain and execute this.sh. Write the blocking rules into the firewall, and at the same time send an email to the author to inform me that a certain unlucky guy has been blocked.
Here’s how I do it:
<?PHP # 自動封鎖IP QQ群:223494678 # 用法: # 1.首先把下方的PHP代碼放入被全局require的配置檔內. # 2.用SSH執行:cat /etc/crontab # 3.加入下邊兩行: # #auto lock webbench # */1 * * * * root /home/wwwroot/bossAdm_Web/webbench.sh; # 4.重啟crontab的服務:service crontab restart //封鎖任何來源的WebBench IF(isSet($_SERVER['HTTP_USER_AGENT']) And Trim($_SERVER['HTTP_USER_AGENT'])!='') { $_SERVER['HTTP_USER_AGENT']=StrToLower($_SERVER['HTTP_USER_AGENT']); IF(StriStr($_SERVER['HTTP_USER_AGENT'],'webbench')!==False And (isSet($_SERVER['REMOTE_ADDR']) And Trim($_SERVER['REMOTE_ADDR'])!='')) { DoLock($_SERVER['REMOTE_ADDR']); Die(); } } //封鎖敏感Url,針對猜測如下url的ip直接封殺 QQ群:223494678 //這段代碼最好是加入到404.php內,這樣效果更大(需要重新配置一下httpd.conf,讓404錯誤頁指向到該404.php) QQ群:223494678 IF(isSet($_SERVER['REQUEST_URI']) And Trim($_SERVER['REQUEST_URI'])!='') { IF(StriStr($_SERVER['REQUEST_URI'],'/admin')!==False Or StriStr($_SERVER['REQUEST_URI'],'/sign')!==False Or StriStr($_SERVER['REQUEST_URI'],'/reg')!==False Or StriStr($_SERVER['REQUEST_URI'],'/tiki-')!==False Or StriStr($_SERVER['REQUEST_URI'],'/join')!==False Or StriStr($_SERVER['REQUEST_URI'],'/config')!==False Or StriStr($_SERVER['REQUEST_URI'],'/backup')!==False Or StriStr($_SERVER['REQUEST_URI'],'/www')!==False Or StriStr($_SERVER['REQUEST_URI'],'/manage')!==False Or StriStr($_SERVER['REQUEST_URI'],'/password')!==False Or StriStr($_SERVER['REQUEST_URI'],'/install')!==False Or StriStr($_SERVER['REQUEST_URI'],'/phpmyadmin')!==False Or StriStr($_SERVER['REQUEST_URI'],'/webadmin')!==False Or StriStr($_SERVER['REQUEST_URI'],'/inc')!==False Or StriStr($_SERVER['REQUEST_URI'],'/user')!==False Or StriStr($_SERVER['REQUEST_URI'],'/upload')!==False Or StriStr($_SERVER['REQUEST_URI'],'/setup')!==False Or StriStr($_SERVER['REQUEST_URI'],'/sys')!==False Or StriStr($_SERVER['REQUEST_URI'],'/cert')!==False ){ DoLock($_SERVER['REMOTE_ADDR']); Die(); } } //建立sh檔,用途是封鎖ip,該sh檔會被排程以root身份執行. QQ群:223494678 Function DoLock($x){ $p='/home/wwwroot/bossAdm_Web/webbench.sh'; File_Put_Contents($p,"#! /bin/bash\n iptables -I INPUT -s {$x} -j DROP;\n echo \"{$x} - `date`\" | mail -s \"WebBench\" see7di@gmail.com;\n cat /dev/null > {$p}",LOCK_EX); Chmod($p,0755); chown($p,'www'); unSet($p,$x); }
After I asked the question, some netizens asked me "Special meansConnect to a Windows operating system server on the LAN where this server is located" The Special meansWhat exactly is the method? Well, I’ll just explain it briefly. I’m afraid I’ll ruin myself by saying too much. First, I will log in to the backend management of the company’s website, then send a request to open 3389, and then log out after sending it. Just do it in the background. After the Linux server receives the request (it's just an ini file), it will throw the file to the Windows server through samb and the internal LAN. There is a monitoring terminal I developed on the Windows server to scan whether If there is a request, the monitoring terminal will modify the hardware firewall settings and open the mapped port of 3389 (a port in 65525 is mapped to 3389 on this Windows). At this time, I can use 3389 method to connect to this server (it only takes about 1 minute from sending the request to opening 3389), but please note that you need to change the settings of gpedit so that it can automatically create a 3389 server after the 3389 connection is completed. Close the request for 3389, and leave the rest to the monitoring program to help me close the mapped port of 3389.
For the above, if you want to communicate with friends about PHP, you can join my QQ group: 223494678. I believe that only through communication can we grow! At least that’s what I think.:)

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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











This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7
