• C#检测上传图片是否安全函数


    //添加引用System.Text;

    //添加引用System.IO;

    /// <summary>
                /// C#检测上传图片是否安全函数
                /// </summary>
                /// <param name="strPictureFilePath"></param>
                public void CheckPictureSafe(string strPictureFilePath)
                {
                    bool strReturn = true;
                    if (!File.Exists(strPictureFilePath))
                    {
                        StringBuilder str_Temp = new StringBuilder();
                        try
                        {
                            using (StreamReader sr = new StreamReader(strPictureFilePath))    //按文本文件方式读取图片内容
                            {
                                String line;
                                while ((line = sr.ReadLine()) != null)
                                {
                                    str_Temp.Append(line + ",");
                                }
                                //检测是否包含危险字符串
                                if (str_Temp == null)
                                {
                                    strReturn = false;
                                }
                                else
                                {
                                    str_Temp = str_Temp.Replace("'", "''");
                                    string DangerString = "script|iframe|.getfolder|.createfolder|.deletefolder|.createdirectory|.deletedirectory|.saveas|wscript.shell|script.encode|server.|.createobject|execute|activexobject|language=|include|filesystemobject|shell.application";
                                    string[] sArray = DangerString.Split('|');
                                    foreach (string i in sArray)
                                    {
                                        strReturn = true;
                                        break;
                                    }
                                }
                                sr.Close();
                            }
                            if (strReturn)
                            {
                                File.Delete(strPictureFilePath);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(ex.Message);
                        }
                    }
                }

  • 相关阅读:
    [root@py ~]# watch -n 1 ifconfig 求解释
    25 个常用的 Linux iptables 规则
    linux shell 字符串操作(长度,查找,替换)详解
    linux高级网络配置 ip别名,接口绑定
    初始版本控制工具-Git
    详解 TCP 连接的“ 三次握手 ”与“ 四次挥手 ”
    wireshark_users
    wireshark抓包基础步骤及PPPOE拨号抓包过程分析
    ARP原理与ARP攻击
    PPPOE 详解
  • 原文地址:https://www.cnblogs.com/xqf222/p/3306840.html
Copyright © 2020-2023  润新知