[Security Lesson] Techie-Micheal's Lesson 1

Learn about Security for code and servers. Learn how to secure your site and your code. Learn about hacking prevention, finding and identifying exploits, and recognising vulnerabilities. Plus, Weekly Security tips and Tutorials.
Forum rules
Post questions related to security, analyse and learn about vulnerabilities and exploits within code to protect yourself against hackers.

Re: [Security Lesson] Techie-Micheal's Lesson 1

Postby Techie-Micheal » 19 Mar 2009, 23:32

Spoiler:
%00 is what is called the null byte. Injection of the null byte is often called a poison null byte. Another, better explanation can be found here: http://www.hakipedia.com/index.php/Pois ... _Injection

If you do not wish to visit the above, or simply want me to explain more, here you go.

%00 is essentially a terminator, it stops anything else from being done, such as comparisons or file inclusions, and "poisons" the application, causing it to behave in unexpected ways.

Here is another example, taken from hakipedia:

Code: Select all
$file = $_GET['file'];
require_once("/var/www/$file.php");


Calling the URI "www.example.com/file.php?file=../../../../../etc/passwd%00" would terminate the string, and the .php would not be appended as would be expected.

Because the .php is not appended, the /etc/passwd file, a rather important file on *nix systems, gets included for easy viewing of the attacker.
Techie-Micheal    
STG Development
STG Development
 
Posts: 63
Joined: 26 Oct 2007, 21:35
Gender: Male
phpBB Knowledge: 10




phpBB Academy at StarTrekGuide
Support STG
Using PayPal Donate

Re: [Security Lesson] Techie-Micheal's Lesson 1

Postby Erik Frèrejean » 20 Mar 2009, 05:57

Spoiler:
Ah I see and understand the theory, but I can't exploit this on my local system. The null byte gets escaped which results in a file named: /usr/bin\0 and that file doesn't exist thus it doesn't print it.
Is this an exploit that only works in specific browsers *cough*IE*cough*? Both WebKit and FireFox just escape it terminating the vulnerability.
Image Proud member of the phpBB support team
Image STG Support team member | Image STG Moderator team member
Image
User avatar
Erik Frèrejean    
phpBB Team Member
phpBB Team Member
 
Posts: 1114
Joined: 03 Dec 2007, 00:49
Location: USERS_TABLE
Favorite Team: New Orleans Saints
Gender: Male
phpBB Knowledge: 10

Re: [Security Lesson] Techie-Micheal's Lesson 1

Postby Techie-Micheal » 20 Mar 2009, 11:01

Erik Frèrejean wrote:
Spoiler:
Ah I see and understand the theory, but I can't exploit this on my local system. The null byte gets escaped which results in a file named: /usr/bin\0 and that file doesn't exist thus it doesn't print it.
Is this an exploit that only works in specific browsers *cough*IE*cough*? Both WebKit and FireFox just escape it terminating the vulnerability.


Spoiler:
It works fine for me in Firefox. How are you putting it in? Also, what version of PHP do you have? I found that some versions of PHP don't do this (though I haven't been able to figure out what or why). If you want, I can PM you the URL to my server so you can play, as it works well there.

file_exists.php?file=/usr/bin%00 works on my server. If you are putting in file_exists.php?file=/usr/bin\0, that won't work as you have to URL encode it, which is the %00.
Techie-Micheal    
STG Development
STG Development
 
Posts: 63
Joined: 26 Oct 2007, 21:35
Gender: Male
phpBB Knowledge: 10

Re: [Security Lesson] Techie-Micheal's Lesson 1

Postby Erik Frèrejean » 20 Mar 2009, 12:32

Techie-Micheal wrote:
Erik Frèrejean wrote:
Spoiler:
Ah I see and understand the theory, but I can't exploit this on my local system. The null byte gets escaped which results in a file named: /usr/bin\0 and that file doesn't exist thus it doesn't print it.
Is this an exploit that only works in specific browsers *cough*IE*cough*? Both WebKit and FireFox just escape it terminating the vulnerability.


Spoiler:
It works fine for me in Firefox. How are you putting it in? Also, what version of PHP do you have? I found that some versions of PHP don't do this (though I haven't been able to figure out what or why). If you want, I can PM you the URL to my server so you can play, as it works well there.

file_exists.php?file=/usr/bin%00 works on my server. If you are putting in file_exists.php?file=/usr/bin\0, that won't work as you have to URL encode it, which is the %00.

Spoiler:
Ah I see. It didn't work on my localhost (MAMP -> php 5.2.5). On my Debian VPS with php 5.2.6 it does work.
Last edited by Erik Frèrejean on 20 Mar 2009, 12:34, edited 1 time in total.
Reason: Typo++
Image Proud member of the phpBB support team
Image STG Support team member | Image STG Moderator team member
Image
User avatar
Erik Frèrejean    
phpBB Team Member
phpBB Team Member
 
Posts: 1114
Joined: 03 Dec 2007, 00:49
Location: USERS_TABLE
Favorite Team: New Orleans Saints
Gender: Male
phpBB Knowledge: 10

Re: [Security Lesson] Techie-Micheal's Lesson 1

Postby Highway of Life » 20 Mar 2009, 12:55

Spoiler:
@Erik: Francis attempted it on the STG server, our VPS (running PHP 4.3.x?) and on his localhost -- MAMP PHP 5.2.6, he couldn?t get any of them to work. I should note that the PHP installation on his localhost and the STG server is identical.
Watch out! I might do a code wheelie!

User avatar
Highway of Life    
STG Jedi Master
STG Jedi Master
 
Posts: 10458
Joined: 08 May 2006, 05:23
Location: Beware of Programmers carrying screwdrivers
Gender: Male
phpBB Knowledge: 10

Re: [Security Lesson] Techie-Micheal's Lesson 1

Postby eviL3 » 01 Apr 2009, 09:59

Spoiler:
/etc/passwd is unix/linux specific.
Image
User avatar
eviL3    
MOD Author
MOD Author
 
Posts: 1002
Joined: 05 Nov 2006, 08:14
Location: Cooking in the MODs kitchen
Gender: Male

Re: [Security Lesson] Techie-Micheal's Lesson 1

Postby Erik Frèrejean » 01 Apr 2009, 14:43

eviL3 wrote:
Spoiler:
/etc/passwd is unix/linux specific.

Spoiler:
True, but I didn't work at all. No matter what file I used ;)
Image Proud member of the phpBB support team
Image STG Support team member | Image STG Moderator team member
Image
User avatar
Erik Frèrejean    
phpBB Team Member
phpBB Team Member
 
Posts: 1114
Joined: 03 Dec 2007, 00:49
Location: USERS_TABLE
Favorite Team: New Orleans Saints
Gender: Male
phpBB Knowledge: 10

Re: [Security Lesson] Techie-Micheal's Lesson 1

Postby TerraFrost » 03 May 2009, 08:48

Spoiler:
magic_quotes_gpc is why this doesn't work on select servers. It turns "\0" into "\\0" which means that no null byte is being injected. I thought I elaborated on this in Injection Vulnerabilities, but it looks like I have a small typo in that... a typo that's just been fixed :)
TerraFrost
phpBB Team Member
phpBB Team Member
 
Posts: 2
Joined: 08 Oct 2008, 06:48
Gender: Male

Re: [Security Lesson] Techie-Micheal's Lesson 1

Postby Erik Frèrejean » 03 May 2009, 08:53

Spoiler:
Ah I see. Thanks for that explanation Jim :good:
Image Proud member of the phpBB support team
Image STG Support team member | Image STG Moderator team member
Image
User avatar
Erik Frèrejean    
phpBB Team Member
phpBB Team Member
 
Posts: 1114
Joined: 03 Dec 2007, 00:49
Location: USERS_TABLE
Favorite Team: New Orleans Saints
Gender: Male
phpBB Knowledge: 10

Re: [Security Lesson] Techie-Micheal's Lesson 1

Postby onehundredandtwo » 14 May 2009, 14:18

I tried it on localhost and on a linux server and I couldn't get it to work. I suppose that's a good thing in a way. :grin:

EDIT: never mind, disabled magic_quotes_gpc and it works. :(
Need help preventing spam? Read Preventing spam in phpBB 3.0.6 and above
User avatar
onehundredandtwo
Cadet III
Cadet III
 
Posts: 35
Joined: 07 Jan 2009, 19:57
Gender: Male

PreviousNext

Return to Security Class

Who is online

Users browsing this forum: Sosospider and 1 guest