Home  >  Q&A  >  body text

php - Specific example analysis of sql injection and xss

My website was attacked a month ago, and today I received a vulnerability detection report from 360. Oh my God, 360 still does this kind of thing?

Why is it still injected when I use addslashes when writing to the database? Do link 1 and link 2 need to be combined to be injected?
As for the second vulnerability, I don't know how to defend against it.
I don’t have in-depth research on site security. I would like to ask you to analyze how this is achieved and how to fix the loopholes. Thank you.
If you need to write the code to the database, I will post it.

PS, writing links will be automatically shortened by sf, so a space is added after http:.


After debugging, it can indeed be injected...I still don’t know enough about sql

The final statement written to the database is:

insert into comment values(NULL,1,1497261734,'88888',0,'hacker@hacker.org','http://www.hacker.org/','182.118.33.8','88888',0 RLIKE (SELECT (CASE WHEN (4725=4725) THEN 0 ELSE 0x28 END)) AND SLEEP(5)%20%23);

I would like to ask what the last sentence means

0 RLIKE (SELECT (CASE WHEN (4725=4725) THEN 0 ELSE 0x28 END)) AND SLEEP(5)%20%23
高洛峰高洛峰2658 days ago1840

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-06-13 09:24:07

    xss nested html script code, parameters should be converted into html entities. Function htmlspecialchars

    Connection 1 is to perform mysql by entering the mysql keyword. Now, you should need to filter the keyword.

    Of course, the best way to prevent injection is to use preprocessing! ! ! !

    reply
    1
  • PHP中文网

    PHP中文网2017-06-13 09:24:07

    1. It is best to use parameterized queries instead of splicing SQL statements.

    2. xss can be filtered through parameters to filter out script codes like <script>.

    reply
    1
  • 我想大声告诉你

    我想大声告诉你2017-06-13 09:24:07

    Your code is not filtered at all

    reply
    0
  • Cancelreply