Powershell写入文件问题简要分析

简介: Powershell写入文件问题简要分析

0x01 前言

朋友在测试webshell-venom(免杀webshell无限生成工具项目时发现的这个问题,就是在Cmd和Powershell命令行下写入的文件是有区别的,虽然文件内容看起来是一样的,但是文件大小却不一样,且Cmd下写入的文件能解析,Powershell下写入的文件就不能解析,可以用c32asm工具看出其中差别


0x02 问题原因

当Powershell输出重定向到文件或将其通过管道传递到其他内容时默认使用ASCII作为输出编码,可通过$OutputEncoding变量查看当前编码,简单的说也就是Cmd和Powershell重定向编码问题。

    cmdshell:
    echo ^<?php phpinfo();?^> > phpinfo.php
    powershell:
    echo "<?php phpinfo();?>" > .\phpinfo-1.php


    0x03 解决办法

    即使我们将Powershell下写入的phpinfo-1.php文件内容全选拷贝到其他文件中也不能解析,只有将PHP文件编码改为UTF-8或GB2312才能正常解析,或者使用以下命令写入文件。

      PS C:\> echo "<?php phpinfo();?>" | out-file phpinfo-2.php -encoding utf8

      相关文章
      |
      安全 API 数据安全/隐私保护
      Cobaltstrike4.0——记一次上头的powershell上线分析(三)
      Cobaltstrike4.0——记一次上头的powershell上线分析
      212 0
      |
      5月前
      |
      安全 API
      Powershell脚本分析
      Powershell脚本分析
      |
      存储 安全 API
      Cobaltstrike4.0——记一次上头的powershell上线分析(二)
      Cobaltstrike4.0——记一次上头的powershell上线分析
      302 0
      |
      Java API C#
      Cobaltstrike4.0——记一次上头的powershell上线分析(一)
      Cobaltstrike4.0——记一次上头的powershell上线分析
      339 0
      |
      3月前
      |
      存储 Ubuntu Linux
      windows可以安装Ubuntu,ubuntu上也可以安装Powershell
      powerhsell除了可以在windows上使用外,还可以在Ubuntu上部署开发环境。下面介绍Ubuntu上安装powershell的方法。
      53 0
      |
      5月前
      |
      Shell Linux 开发工具
      windows中cmd和PowerShell批处理命令
      之前在 Git 批量删除本地分支,有用到 Linux 或 MacOS 下的批处理命令,这个命令中的 grep、xargs 本身是 Shell script,在 windows 中的 cmd 和 PowerShell 中是不能用的
      51 0
      |
      8月前
      |
      JavaScript Windows
      [Vue]解决 Windows PowerShell 不识别 vue 命令的问题
      [Vue]解决 Windows PowerShell 不识别 vue 命令的问题
      |
      8月前
      |
      Windows
      使用PowerShell获取Windows当前锁屏壁纸
      使用PowerShell获取Windows当前锁屏壁纸 如果原始图片丢了,用这段代码就可以提取当前锁屏壁纸了!
      102 0
      |
      应用服务中间件 nginx Windows
      Windows PowerShell 中启动 Nginx 报错解决方案
      Windows PowerShell 中启动 Nginx 报错解决方案
      Windows PowerShell 中启动 Nginx 报错解决方案