Jump to content

[SOLVED] GET function


SirChick

Recommended Posts

Hey guys quick Q,

 

say i have a url like this:

 

<a href="mycarinfo.php?carinfo=';Echo$CarID;Echo'">

 

 

And so the CarID is the variable being passed across how do i get that $CarID value from it .. is it:

 

$CarID = $_GET['carinfo']; ?

 

That url makes no sense. but yes, it would be contained within the $_GET['carinfo'] variable

Link to comment
Share on other sites

the one you showed us was:

 

mycarinfo.php?carinfo=';Echo$CarID;Echo

 

 

no ' or ; can be in the url... and I don't think a dollar sign is a smart thing to do.

precisely. It's more the random 'Echo' bits that confused me..

 

but the one above this post is correct, but exploitable. :)
All GET's are exploitable. You just need to put some security checks in place when you read the data from them. Such as

is_num($_GET['carinfo'])

would ensure that it is a number and contains no letters, spaces symbols etc

Link to comment
Share on other sites

no, get can contain just abou any character. I was just giving an example of how to check the variable.

Let's say you only wanted $_GET['carinfo'] to be numerical, then you could use something like:

if(is_numeric($_GET['carinfo'])){
    echo 'it is a number';
}else{
    echo 'it is not a number';
}

to ensure that it doesn't contain anything but numbers.

 

There are plenty of other security checks you can do, such as querying it against a database to see if it exists.. something like:

"SELECT * FROM `cars` WHERE `carinfo` = '" . mysql_real_escape_string($_GET['carinfo']) . "' LIMIT 1";

just an example.

Link to comment
Share on other sites

I put something like this but say the user edited the url from '1' to a '2' in the number rather than my header kicking in it seems to jsut show a white page of nothingness =/

 

$CarID = $_GET['carinfo'];


$Validation = mysql_query("SELECT * FROM cars WHERE CarID='$CarID' AND UserID={$_SESSION['Current_User']}");

If (mysql_num_rows($Validation) == 0){
Header ("mygarage.php");
}Else{
include("londonpagesinclude.php");
Echo ' success';
}

Link to comment
Share on other sites

I put something like this but say the user edited the url from '1' to a '2' in the number rather than my header kicking in it seems to jsut show a white page of nothingness =/

 

$CarID = $_GET['carinfo'];


$Validation = mysql_query("SELECT * FROM cars WHERE CarID='$CarID' AND UserID={$_SESSION['Current_User']}");

If (mysql_num_rows($Validation) == 0){
Header ("mygarage.php");
}Else{
include("londonpagesinclude.php");
Echo ' success';
}

 

That's not a problen of GET, it's a problem with the logic you used to build your script.  GET, for the very reason you stated, is potentially dangerous because users can change its value in the URL.  Since PHP is often used in conjunction with a database, these changes of input could lead to a user (intentionally or not) hijacking your database.  Because of that, you need to validate that what you're GETting is legit, and turn away all other invalid inputs.

 

In your example, it seems that you only want to accept a carInfo value of 1.  So, you'd do something along the lines of:

<?php

$carInfo = $_GET['carInfo'];

if(is_numeric($carInfo) && carInfo == 1){
  //access the database and proceed as normal
}
else{
   //bad input, turn away user
   header('denied.php'); //access denied site
}

?>

Link to comment
Share on other sites

Get may not be one it could be any numbers...

 

cos it goes by ID the car ID could be anything that is in the table...

 

so to physically hard code 1 would mean all the the others car id's would never work.

 

With this:

If url was changed to make Get become "cheeese" then the query below wont work and so it would go to the header so the url change will only change if the car does exist and that the user owns that car...

 

$Validation = mysql_query("SELECT * FROM cars WHERE CarID='$CarID' AND UserID={$_SESSION['Current_User']}");

 

If the car id that comes from the GET is owned by the user viewing the page then it is perfectly fine to change the url to that number how ever if they did not own the car then the AND UserID would be different and so it would not find the row because the car doesn't belong to Current_User so that was why i had a num rows but it didnt work =/

 

you get me?

Link to comment
Share on other sites

try this:

<?php
$CarID = $_GET['carinfo'];


if(is_numeric($carID)){
$Validation = mysql_query("SELECT * FROM `cars` WHERE `CarID`='mysql_real_escape_string($CarID)' AND UserID={$_SESSION['Current_User']}") or die(mysql_error());

If (mysql_num_rows($Validation) == 0){
	Header ("mygarage.php");
	echo 'unsuccessfull';
}else{
	include("londonpagesinclude.php");
	echo ' success';
}
}else{
echo 'not numeric';
}
?>

Link to comment
Share on other sites

By removing that, you open yourself up to sql injections.

 

Try to change the variable before the sql_query like:


$carID = mysql_real_escape_string($CarID);

echo $carID //just to make sure it looks ok, remove for production

if(is_numeric($carID)){
$Validation = mysql_query("SELECT * FROM `cars` WHERE `CarID`='$CarID' AND UserID={$_SESSION['Current_User']}") or die(mysql_error());

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.