Site has been hacked via SQL Injection

前端 未结 7 1239
难免孤独
难免孤独 2020-12-04 18:09

Recently my site was hacked via SQL injection. The hacker used the following query to get my DB name. I cannot understand this query they wrote.

Query:



        
7条回答
  •  难免孤独
    2020-12-04 18:52

    This is not the complete query, actually the person entered this string in your web app.

    Now, first replace %20 with blank space in the union part, you get:

    SELECT concat(0x7e,0x27,Hex(cast(database() as char)),0x27,0x7e),0x31303235343830303536,0x31303235343830303536,0x31303235343830303536--
    

    Seems like the user put the string in some place where you were expecting an number. So, you see that first there is a number (999.9) to complete the original condition of the query. Then, an UNION part is added. Finally, after the UNION part, the comment characters are added (-- ) so that, the rest of the query (which might be being added by your system) is bypassed.

    We can format the code for better understanding:

    SELECT 
        concat
        (
            0x7e,
            0x27,
            Hex(cast(database() as char)),
            0x27,
            0x7e
        ),
        0x31303235343830303536,
        0x31303235343830303536,
        0x31303235343830303536
    

    Now, substring of the first column of the result will contain the hex encoded form of your datbase name. Actually, it should be surrounded by single quotes (0x27), then again surrounded by ~ (0x7e)

提交回复
热议问题