【问题标题】:read binary thru php and save it thru exec over shell通过 php 读取二进制文件并通过 shell 的 exec 保存它
【发布时间】:2018-07-05 04:16:47
【问题描述】:

如何通过shell保存二进制内容?

我写了不工作的例子

$f = file_get_contents("my.exe");
exec("echo $f > new.exe");

【问题讨论】:

标签: php linux shell unix


【解决方案1】:

好吧,也许将来有人会想要这个 todo,没有人/www-data 的 php 可以写入根文件

function my_file_put_contents($f, $content){
    $rand_file = "/tmp/my_tmp_".uniqid('', true);
    file_put_contents($rand_file, $content);
    exec('sudo cp '.escapeshellarg($rand_file).' '.escapeshellarg($f).' && rm '.escapeshellarg($rand_file));
}

然后用 visudo 编辑 /etc/sudoers

www-data ALL = (ALL) NOPASSWD: /bin/rm
www-data ALL = (ALL) NOPASSWD: /bin/cp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-19
    • 2014-01-08
    • 2013-02-26
    相关资源
    最近更新 更多