简体   繁体   English

如何通过网站 PHP 更改 Debian 中的时间?

[英]How to change time in Debian by Website PHP?

I want change time in Debian by my website我想通过我的网站更改 Debian 的时间

I have one field where I want write my time我有一个领域我想写下我的时间

<input type="input" class="form-control boxed" name="date_time"/>

and this is my code which won't work这是我的代码,它不起作用

exec('date +%Y-%m-%dT%H:%M -s "'.$_POST['date_time'].'"');
exec('hwclock -w'); 

The reason why this is not working is probably because php user do not have enough permissions to do that.这不起作用的原因可能是因为 php 用户没有足够的权限来执行此操作。 Which is good.哪个好。 You should not do that.你不应该那样做。 Especially not in this way.尤其不是这种方式。 Imagine someone posting to your server something like this:想象一下有人向您的服务器发布这样的内容:

 curl -d 'date_time=2021-06-10T02:22";malicious_command;echo "' -X POST http://your.server.tld/

What php is going to execute? php 将执行什么? Something like this:像这样的东西:

date +%Y-%m-%dT%H:%M -s "2021-06-10T02:22";malicious_command;echo ""

And boom.和繁荣。 Your machine just run malicious_command.您的机器只运行恶意命令。 This could be any command.这可以是任何命令。 Stealing and destroying Your data or just take control on this machine: More about those type of attacks: https://owasp.org/www-project-top-ten/2017/A1_2017-Injection窃取和破坏您的数据或只是控制这台机器:有关此类攻击的更多信息: https://owasp.org/www-project-top-ten/2017/A1_2017-Injection

Set proper timezone on your server: https://linuxize.com/post/how-to-set-or-change-timezone-on-debian-10/在您的服务器上设置正确的时区: https://linuxize.com/post/how-to-set-or-change-timezone-on-debian-10/

Then keep your local clock up to date by periodically querying ntp servers.然后通过定期查询 ntp 服务器使您的本地时钟保持最新。 Rdate and cron are ok for this task. Rdate 和 cron 可以完成这项任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM