Emuforums.com

Go Back   Emuforums.com > General Discussion > Web development / Programming
About Us Register FAQ Members List Calendar Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old May 2nd, 2004   #1 (permalink)
Registered User
 
elachys's Avatar
 
Join Date: Jan 2003
Location: England, drinking tea.
Posts: 547
Question i need a php guru

ok i cann't work out why this stupid frikin script doesn't work.
and yer i have deliberatly changed the username and password

here is the code in a txt, change the extension to .php
Attached Files
File Type: txt code.txt (879 Bytes, 69 views)
elachys is offline   Reply With Quote
Old May 2nd, 2004   #2 (permalink)
Banned
 
lido884's Avatar
 
Join Date: Apr 2004
Location: Mother Earth
Posts: 124
visit www.phppowerforums.net for help

i don't know if it's still working. their server was down last week
lido884 is offline   Reply With Quote
Old May 2nd, 2004   #3 (permalink)
Registered User
 
scottlc's Avatar
 
Join Date: Sep 2002
Location: St Andrews, Scotland
Posts: 1,575
That code is hella insecure. All you need is someone to enter "f@ke.com', NULL; drop signup;" as their emailand you're screwed royally, hope you have backups! Call mysql_escape_string on them to secure your script.
__________________
OS: Arch Linux w/ Kernel 2.6.23.8 + GNOME 2.20.1 - CPU: Intel Pentium M 1.5GHz - Memory: 1280MB DDR PC2700 - Browser: Mozilla Firefox 2.0.0.10
scottlc is offline   Reply With Quote
Old May 2nd, 2004   #4 (permalink)
Puchiko-nyu!
 
kairi00's Avatar
 
Join Date: Jul 2001
Location: 49° 11' N 123° 10' W
Posts: 2,854
Straight variables won't work anymore unless you enable the REGISTER_VAR_GLOBALS (or something like that) flag in the php config file, which is NOT recommended.

I'd recommend changing your code to this: access your form variables using $_POST["username"].
__________________
"Not every ejaculation deserves a name."

--- George Carlin
kairi00 is offline   Reply With Quote
Old May 3rd, 2004   #5 (permalink)
Registered User
 
elachys's Avatar
 
Join Date: Jan 2003
Location: England, drinking tea.
Posts: 547
Quote:
That code is hella insecure
well duh, i want to get it working first.
elachys is offline   Reply With Quote
Old May 3rd, 2004   #6 (permalink)
Emulation64's Animal >:D
 
Keith's Avatar
 
Join Date: Apr 2001
Location: United States
Posts: 1,215
Well just a few things to point out that might help .. you didn't really say what the problem was .. so I can only assume what it could be.

------------------------------
try changing

if ($mode == 'submit') {

to just

if ($submit) {

------------------------------
also noticed you use slashes in the query such as \'$name\', .. you should be able to just use '$name', .. but not sure if using the slashes would even cause a problem since I didn't test it.

------------------------------
Also on a side note for the id .. you should not have to include it in the query if you use auto_increment for the database for that field

Just a few suggestions after taking a quick glimpse
__________________




Emulation64.com | EFx2Blogs Forums | EFx2Blogs - Sign Up For Your Own Free EFx2Blog Today!
Keith is offline   Reply With Quote
Old May 3rd, 2004   #7 (permalink)
I Need a Weapon
 
FLaRe85's Avatar
 
Join Date: Oct 2001
Location: Omaha, NE
Posts: 4,321
Either set register_globals = 1 in php.ini or use $_POST["username"] to extract the POST variables like kairi said. By default, php.ini comes with register_globals disabled as a security precaution. So, if you didn't configure your PHP installation, the header variables won't be implicitly defined. Even if register_globals were enabled, it's still a good idea to extract the vars so that users can't inject values you aren't expecting into the code.
__________________
.: Flaretech.Net :: Flaretech.Biz Web Hosting :: H3 Stats :: My Blog :.



.: Mac Pro :: Dual Quad-Core Intel Xeon 5400s :: 6 GB 800MHz DDR2 ECC FB-DIMMs :: NVIDIA GeForce 8800 GT 512 MB GDDR3 :.
.: Macbook Pro 17" :: 2.33 GHz Intel Core 2 Duo :: 2 GB 667 MHz DDR2 :: ATI Radeon X1600 :.
.: Home Server :: 2.41 GHz AMD Opteron 180 :: 4 GB DDR400 :: Windows Server 2003 Enterprise R2 :.
FLaRe85 is offline   Reply With Quote
Old May 3rd, 2004   #8 (permalink)
Registered User
 
elachys's Avatar
 
Join Date: Jan 2003
Location: England, drinking tea.
Posts: 547
ok so this almost works, except the sql doesn't get added to the databse.
Attached Files
File Type: txt code2.txt (867 Bytes, 26 views)
elachys is offline   Reply With Quote
Old May 3rd, 2004   #9 (permalink)
Emulation64's Animal >:D
 
Keith's Avatar
 
Join Date: Apr 2001
Location: United States
Posts: 1,215
on that one .. either remove the id or add a value for the id ..

such as ..

$sql = 'INSERT INTO test(name, email, beer) VALUES
"'.addslashes($_POST['$name']).'",
"'.addslashes($_POST['$email']).'",
"'.addslashes($_POST['$beer']).'")';
$result = mysql_query($sql);

Also I think it is $_POST['name'] .. not $_POST['$name']
__________________




Emulation64.com | EFx2Blogs Forums | EFx2Blogs - Sign Up For Your Own Free EFx2Blog Today!

Last edited by Keith; May 3rd, 2004 at 09:58.
Keith is offline   Reply With Quote
Old May 3rd, 2004   #10 (permalink)
Registered User
 
elachys's Avatar
 
Join Date: Jan 2003
Location: England, drinking tea.
Posts: 547
Quote:
Call mysql_escape_string on them to secure your script.
what do you mean (gimmi a example).
oh and thanks you guys, i got it to work
elachys is offline   Reply With Quote
Old May 3rd, 2004   #11 (permalink)
Registered User
 
scottlc's Avatar
 
Join Date: Sep 2002
Location: St Andrews, Scotland
Posts: 1,575
You were given an example!
__________________
OS: Arch Linux w/ Kernel 2.6.23.8 + GNOME 2.20.1 - CPU: Intel Pentium M 1.5GHz - Memory: 1280MB DDR PC2700 - Browser: Mozilla Firefox 2.0.0.10
scottlc is offline   Reply With Quote
Old May 3rd, 2004   #12 (permalink)
Registered User
 
elachys's Avatar
 
Join Date: Jan 2003
Location: England, drinking tea.
Posts: 547
i mean an example of how to use mysql_escape_string to secure it.
elachys is offline   Reply With Quote
Old May 4th, 2004   #13 (permalink)
Registered User
 
scottlc's Avatar
 
Join Date: Sep 2002
Location: St Andrews, Scotland
Posts: 1,575
As follows:

Code:
$secure = mysql_escape_string($unsecure);
Will turn:
"this 'string' was"

Into:
"this \'string\' was"
__________________
OS: Arch Linux w/ Kernel 2.6.23.8 + GNOME 2.20.1 - CPU: Intel Pentium M 1.5GHz - Memory: 1280MB DDR PC2700 - Browser: Mozilla Firefox 2.0.0.10
scottlc is offline   Reply With Quote
Old May 4th, 2004   #14 (permalink)
Registered User
 
elachys's Avatar
 
Join Date: Jan 2003
Location: England, drinking tea.
Posts: 547
luckily i worked this out before you posted.
Since someone tried it about 10 mins after i patched it !
So no damage done
elachys is offline   Reply With Quote
Old May 4th, 2004   #15 (permalink)
Registered User
 
scottlc's Avatar
 
Join Date: Sep 2002
Location: St Andrews, Scotland
Posts: 1,575
Well, all you had to do was look at the docs at PHP.net. FYI this is something that you should really should know by now. I was able to figure that in the 30 minutes or less that I've ever used PHP for.
__________________
OS: Arch Linux w/ Kernel 2.6.23.8 + GNOME 2.20.1 - CPU: Intel Pentium M 1.5GHz - Memory: 1280MB DDR PC2700 - Browser: Mozilla Firefox 2.0.0.10
scottlc is offline   Reply With Quote
Reply

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 On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 02:58.

© 2006 - 2008 Emu Forums | About Emu Forums | Legal | A member of the Crowdgather Forum Community


Powered by vBulletin® Version 3.7.0 Release Candidate 3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5