如何阻止Web服务器中的可执行文件上传
我正在研究一个Web应用程序项目,以阻止所有文件可执行文件的文件上传。 示例:用户可以上传,txt,png,图像和视频文件,而不是任何可执行的脚本,例如perl,python,exe,exe,php,.so,.sh文件。
如果它是一个PHP文件,则我将“<?php”标签strstr,如果存在此标签,则是PHP文件。我们如何找到其他脚本/可执行文件相同的?
编辑:有些时间黑客将使用.png或.jpg Extn上传恶意文件,那么在文件内部检查的模式是什么?
I am working on a web app project to block all the file executable from file upload.
Example: user can upload, txt, png, image and video files and not any executable scripts like, Perl, Python, exe, PHP, .so, .sh files.
If it is a PHP file, then I strstr for "<?php" tag, If this tag is present, then it is PHP file. How can we find the same for other script/executable files?
Edit: Some time hackers will upload the malicious files using .png or .jpg extn, so what is the pattern to check inside the files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是自己检查自己的检查,而是使用现有库,而您 阻止所有未按所需格式注册的所有内容 。
大多数这样的库猜想通过寻找某些 或 魔术字节序列 处于特定位置文件。
其他库可能更专业,例如仅识别图像或视频格式。
文件
程序是用于标识文件类型的命令行工具。在您识别并仅接受所需的文件格式的第一个通过之后,您应该将所有未拒绝的文件进行通过防病毒扫描仪。
根据您的用例,您可能会决定剥离原始文件名扩展名和/或上传过程中提供的完整文件名,并分配检测到的哑剧类型,而不是依靠用户提供的属性。
Rather than making your own checks you make use of an existing library and you block everything that does not register as a desired format.
Most such libraries guess the content type and encoding of a file by looking for certain signatures or magic byte sequences at specific positions within the file.
Other libraries may be more specialised and will for example only identify image or video formats.
The
file
programme is a command line tool for identification of file types.After the first pass where you identify and accept only the desired file formats you should then make all files that are not rejected go through an antivirus scanner.
Depending on you use cases you may decide to strip the original file name extension and/or even the complete file name that was provided during the upload and assign the mime-type that was detected rather than rely on user provided properties.