Web Design and Web Development Forum

  1. #1
    cancer10's Avatar
    Join Date
    Jun 2005
    Location
    India
    Age
    29
    Posts
    498
    Rep Power
    7
  2. cancer10 is on a distinguished road
  3. Question Advance SQL Injection Attacks

    Hi,

    I was going through my site stats and found some sql injections have been passed through my site's querystring.

    This was the querystring passed on one of the page. (Note: For security reasons I have replaced my original table and column names in the code below.)

    Code:
    ?action=show&id=-5 union select 1,2,3,concat_ws(0x3a3a,xuser,xpass),5,6,7,8,9,10,11,12,13 from mytbl_login--

    I have taken care of the SQL Injection attacks and hence using the following function in my code everywhere to bypass any SQL injections.

    Code:
    	function antisql($data){
    		if(get_magic_quotes_gpc){
    		$data1 = stripslashes($data);
    		}else{
    		$data1 = $data;
    		}
    		return mysql_real_escape_string($data1);
    	}


    I am not posting this thread to know what SQL Injection is. I know what is it. :)

    Few things I want to know are:

    1) How did they know my column names (xuser and xpass) and table name (mytbl_login)?

    2) Why didn't the antisql() function prevent from that sql injection attack?

    3) What is the above querystring actually doing?


    Some Info:
    My Site is made in PHP MySQl and running on CentOS.


    Thank you so much for your help in advance.
    Reply With Quote Reply With Quote
  4. #2
    gorda001's Avatar
    Join Date
    Jun 2005
    Location
    <0x79a3f6>
    Posts
    4,851
    Rep Power
    11
  5. gorda001 is on a distinguished road
  6. Re: Advance SQL Injection Attacks

    1) Lucky guess probably

    2) Who says it didn't?

    3) It's attempting to get username and password data
    Reply With Quote Reply With Quote
  7. #3
    cancer10's Avatar
    Join Date
    Jun 2005
    Location
    India
    Age
    29
    Posts
    498
    Rep Power
    7
  8. cancer10 is on a distinguished road
  9. Re: Advance SQL Injection Attacks

    Quote gorda001 originally posted: View Post
    1) Lucky guess probably

    2) Who says it didn't?

    3) It's attempting to get username and password data

    1) Who has so much time in guessing?

    2) I tried it myself and succeeded in fetching the first row user/password

    3) ok thanx
    Reply With Quote Reply With Quote
  10. #4
    gorda001's Avatar
    Join Date
    Jun 2005
    Location
    <0x79a3f6>
    Posts
    4,851
    Rep Power
    11
  11. gorda001 is on a distinguished road
  12. Re: Advance SQL Injection Attacks

    1) They could have got it from a previous query I suppose

    2) OK then well the function looks OK, although I wouldn't write it like that:
    PHP Code:
    function antisql($data)
    {
        if (
    get_magic_quotes_gpc())
        {
            
    $data stripslashes($data);
        }
        return 
    mysql_real_escape_string($data);

    Anyway, you're probably not using it correctly. Also, why not just disable magic quotes?
    Reply With Quote Reply With Quote
  13. #5
    unclekyky's Avatar
    Join Date
    Sep 2004
    Age
    22
    Posts
    5,184
    Rep Power
    13
  14. unclekyky is on a distinguished road
  15. Re: Advance SQL Injection Attacks

    Quote cancer10 originally posted: View Post
    1) How did they know my column names (xuser and xpass) and table name (mytbl_login)?

    2) Why didn't the antisql() function prevent from that sql injection attack?
    1) Do you echo MySQL errors? If you do, it is a trivial thing to get a hold of the table structure. Alternatively, maybe you use a really common name for the tables.
    2) Probably because you are using it wrong. How are you invoking it? (From what you said, didn't you write the antisql function after the attack?)
    Spore-Game - The Ultimate Spore Fan-Site
    Abnegating Avunculicide Since 1601 | YC Wiki - "Quidquid latine dictum sit, altum sonatur."
    Reply With Quote Reply With Quote
  16. #6
    cancer10's Avatar
    Join Date
    Jun 2005
    Location
    India
    Age
    29
    Posts
    498
    Rep Power
    7
  17. cancer10 is on a distinguished road
  18. Re: Advance SQL Injection Attacks

    Quote unclekyky originally posted: View Post
    1) Do you echo MySQL errors? If you do, it is a trivial thing to get a hold of the table structure. Alternatively, maybe you use a really common name for the tables.
    2) Probably because you are using it wrong. How are you invoking it? (From what you said, didn't you write the antisql function after the attack?)


    1) Well I do not. Any other way it can be revealed?

    2) I have been using the antisql function since the beginning.
    Reply With Quote Reply With Quote
  19. #7
    Join Date
    Dec 2007
    Location
    The Draco Supercluster
    Age
    18
    Posts
    395
    Rep Power
    0
  20. Aepos is on a distinguished road
  21. Re: Advance SQL Injection Attacks

    1. You can get it from just what he's doing. I know that you can use "union select 1,2,..." to return MySQL results. Make doubly sure that it's not returning any errors. It's probably a script kiddy, but script kiddies have been know to do some damage without even knowing.

    2. If you called the function, and it was written just like that, then there's no (simple) way that you could use MySQL injections to fetch the username and password.

    Again, make SURE it's not returning any errors. MySQL errors are the key to breaking the lock on a website, to put it analogically.
    · · ÷¦÷ · · · ÷¦÷ · · · ÷¦÷ · · · ÷¦÷ · · · ÷¦÷ · · · ÷¦÷ · ·
    A · S · C · I · I · · A · D · D · I · C · T · I · O · N
    · · ÷¦÷ · · · ÷¦÷ · · · ÷¦÷ · · · ÷¦÷ · · · ÷¦÷ · · · ÷¦÷ · ·
    Reply With Quote Reply With Quote
  22. #8
    unclekyky's Avatar
    Join Date
    Sep 2004
    Age
    22
    Posts
    5,184
    Rep Power
    13
  23. unclekyky is on a distinguished road
  24. Re: Advance SQL Injection Attacks

    Quote cancer10 originally posted: View Post
    2) I have been using the antisql function since the beginning.
    You didn't really answer 2. The question was, "How are you invoking it?" By that I mean, give us some examples of how you use it in your code.

    About the part of 2 you did answer, I guess I was just confused by what you said here:
    I have taken care of the SQL Injection attacks and hence using the following function in my code everywhere to bypass any SQL injections.
    Spore-Game - The Ultimate Spore Fan-Site
    Abnegating Avunculicide Since 1601 | YC Wiki - "Quidquid latine dictum sit, altum sonatur."
    Reply With Quote Reply With Quote
  25. #9
    cancer10's Avatar
    Join Date
    Jun 2005
    Location
    India
    Age
    29
    Posts
    498
    Rep Power
    7
  26. cancer10 is on a distinguished road
  27. Re: Advance SQL Injection Attacks

    This is how I am fetching querystring

    $id = antisql($_GET['id']);

    mysql_query("select * from mytable where id=$id");
    Reply With Quote Reply With Quote
  28. #10
    Damien Gray's Avatar
    Join Date
    Jul 2008
    Location
    New York
    Age
    20
    Posts
    415
    Rep Power
    4
  29. Damien Gray is on a distinguished road
  30. Re: Advance SQL Injection Attacks

    Try this:

    $id = (int)$_GET['id'];

    It will make anything that isn't an integer equal zero.
    Quote myself originally posted:
    I'm not sure what I should be more concerned with...the fact that the pen I'm chewing on tastes like mustard, or that I found the pen on my floor.
    Reply With Quote Reply With Quote

Similar Threads

  1. ASP - SQL Injection Prevention
    By cancer10 in forum General Web Programming
    Replies: 4
    Last Post: 04-23-2008, 06:50 AM
  2. Data Safe - SQL Injection
    By cancer10 in forum PHP Scripting
    Replies: 4
    Last Post: 02-27-2008, 11:49 AM
  3. SQl Injection through ASP and MS SQl 2000
    By cancer10 in forum General Web Programming
    Replies: 2
    Last Post: 02-26-2008, 11:14 PM