doqw89029 2013-12-18 09:54
浏览 32
已采纳

来自php脚本安全的mysqldump

If I do shell_exec('mysqldump DATABASE_NAME') from a php script, is there any danger?

Is there a way to get this to work in Windows?

I am going to use mysqldump for database backup from a web page

Also should I do set_time_limit(0) when running this?

  • 写回答

1条回答 默认 最新

  • dounai9294 2013-12-18 10:47
    关注

    Yeah, there is danger: If database name comes from an untrusted source hackers could try to inject shell commands in the database name. For example:

    $dbname = 'test; cat /etc/shadow';
    

    might being used to obtain user names and encrypted passwords from the system (depends on the system)..

    To avoid that, you should use escapeshellarg() to quote the database name (and possible other arguments):

    shell_exec('mysqldump ' . escapeshellarg($database_name));
    

    set_time_limit() isn't required if you are following my hints here


    Needless to say, that you'll have to secure the page using login.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部