. Net File Upload Vulnerability code example and repair solution

Source: Internet
Author: User

Some of the Code obtained during the test is lost, and there is only one repair solution. Let's take a look. Something is simple. String str = filename. substring (filename. lastIndexOf (". ") + 1, 3 ); if (str = "png" | str = "gif" | str = "jpg" | str = "jpeg" | str = "PNG" | str = "GIF" | str = "JPG" | str = "JPEG ") {string sfd = savePath; string sf = filename. substring (0, filename. lastIndexOf (". ") +" _ "+ DateTime. now. toString ("yyMMddhhmmss") + ". "+ str; savePath + = filename + sf; this. hidurl. value = "SecFile/ "+ Sf; // the token is OK. Fix code: [code = "csharp"] string sf = DateTime. now. toString ("yyMMddhhmmss") + ". "+ str; [/code] ----- <font face =" "> <code id =" code1 "> fileurl = context. request ["folder"]; </code> </font> get the folder address from the Request header. Iis6 truncation or semicolon ------ <font face = ""> <code id = "code2"> protected void SaveImg (HttpPostedFile file, string type, string roomid, string roomname, string btntype) {# region saves the image string imgname = Path. getFileName (file. fileName ). toLower (); if (imgname. length = 0) {if (btntype = "edit") {Response. write ("{\" result \ ": \" "+ AddMode (" ", roomid, roomname) +" \ "}"); return;} Response. write ("{\" result \ ": \"-2 \ "}"); return;} imgname = imgname. substring (0, imgname. length-4); string PicType = Path. getExtension (file. fileName ). toLower (); // get the image extension // if (PicType = ". jpg "| PicType = ". gif "| PicType = ". jpeg "| PicType = ". bmp ") {// string phsavename = string. empty; // client string phserver = Server. mapPath ("roomlogpic" + "/") + "/roomImage/"; string saveserver =" http://www.cunlide.com/admin/roomlogpic/roomImage/ "; If (Directory. exists (phserver) = false) // create a file folder {Directory. createDirectory (phserver);} try {int result = 0; switch (type) {case "delete": // delete temporary phsavename = DateTime. now. year + "" + DateTime. now. month + "" + DateTime. now. day + PicType; System. IO. file. delete (phserver + Path. getFileName (file. fileName ). toLower (); break; case "save": // upload phsavename = imgname + "_" + DateTime. now. year + "" + DateTime. now. month + "" + DateTime. now. day + PicType; // No filtering. The following is the patch code. // phsavename = DateTime. now. year + "" + DateTime. now. month + "" + DateTime. now. day + PicType; file. saveAs (phserver + phsavename); System. IO. file. delete (phserver + Path. getFileName (file. fileName ). toLower (); result = AddMode (saveserver + phsavename, roomid, roomname); break; case "temp": // temporarily upload phsavename = DateTime. now. year + "" + DateTime. now. month + "" + DateTime. now. day + PicType; file. saveAs (phserver + phsavename); break; default: break;} Response. write ("{\" result \ ": \" "+ result +" \ "}"); // upload result return;} catch (System. nullReferenceException) {Response. write ("{\" result \ ": \"-1 \ "}"); // return;} # endregion //} // else {Response. write ("file type: jpg gif jpeg bmp only! ") ;}}</Code> </font>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.