private detailedRequest_IE getHTTPdetails(string request,bool isIE){ detailedRequest tempreq = getHTTPdetails(request,txtTargetHost.Text,chkTargetIsSSL.Checked); detailedRequest_IE returner = new detailedRequest_IE(); object header=null; object postdata=null; object url; if (chkTargetIsSSL.Checked){ if (txtTargetPort.Text.Equals("443")==false){ url="https://"+tempreq.host+":"+txtTargetPort.Text+tempreq.URL+txtBaseURLSeparator.Text[0]; } else { url="https://"+tempreq.host+tempreq.URL+txtBaseURLSeparator.Text[0]; } }else{ if (txtTargetPort.Text.Equals("80")==false){ url="http://"+tempreq.host+":"+txtTargetPort.Text+tempreq.URL+txtBaseURLSeparator.Text[0]; } else { url="http://"+tempreq.host+tempreq.URL+txtBaseURLSeparator.Text[0]; } } foreach (string getitem in tempreq.GETparameters){ url+=getitem+txtVariableSeparator.Text[0]; } url=url.ToString().TrimEnd(txtVariableSeparator.Text[0]); url=url.ToString().TrimEnd(txtBaseURLSeparator.Text[0]); //if its a post we must recalc the content length! if (tempreq.action.Equals("POST")){ string[] headerlines = tempreq.header.Replace("\r\n","\n").Split('\n'); foreach (string line in headerlines){ string[] parts = line.Split(':'); int plen=0; if (parts[0].ToLower().Equals("content-length")){ //work out the new content length if (tempreq.isXML || tempreq.isMultiPart){ header+="Content-length: "+tempreq.POSTparameters[0].ToString().Length; } else{ string temppoststring=""; foreach (string postitem in tempreq.POSTparameters){ temppoststring+=postitem+txtVariableSeparator.Text[0]; } temppoststring.TrimEnd(txtVariableSeparator.Text[0]); plen=temppoststring.Length; plen--; header+="Content-length: "+plen.ToString()+"\r\n"; } }else{ header+=line+"\r\n"; } } } else { header+=tempreq.header; } if (header.ToString().IndexOf("SensePost-SuruWP: edited request")<0){ header+="SensePost-SuruWP: edited request\r\n"; } //ok - we need to populate the cookies...doesnt happen by itself! :) // THIS CLEARING DOES NOT WORK!!! it sometimes hangs!! // it thus needs to be able to timeout!! NASTY!!!!! Org.Mentalis.Proxy.DeleteCache delete = new DeleteCache(); //this will exit as soon as EXITCLEANERNOW is set delete.clearIE(); foreach (string cookiepair in tempreq.cookie){ if (cookiepair.IndexOf(txtCookieKeyValueSeparator.Text[0])>=0){ string[] parts = cookiepair.Split(txtCookieKeyValueSeparator.Text[0]); //reconstruct string cvalue=string.Empty; for (int i=1; i<parts.Length; i++){ cvalue+=parts[i]+txtCookieKeyValueSeparator.Text[0]; } cvalue=cvalue.Substring(0,cvalue.Length-1); SetCookie("http://"+tempreq.host,parts[0],cvalue); } } //add the cookies anyway - this is used in the FireFox browser!...or maybe not...:( if (tempreq.cookie.Count>0){ header+="Cookie: "; foreach (string cookiepair in tempreq.cookie){ header+=cookiepair+txtCookieVariableSeparator.Text[0]; } header=header.ToString().TrimEnd(txtCookieVariableSeparator.Text[0]); header+="\r\n"; } header=header.ToString().Replace("\r\n\r\n","\r\n"); //now the post data.. if (tempreq.action.Equals("POST")){ foreach (string postline in tempreq.POSTparameters){ if (postline.Length>0){ postdata+=postline+txtVariableSeparator.Text[0]; } } try{ //what is postdata is 0 bytes.. postdata=postdata.ToString().TrimEnd(txtVariableSeparator.Text[0]); postdata=ASCIIEncoding.ASCII.GetBytes(postdata.ToString()); } catch {} } returner.headers=header; returner.postdata=postdata; returner.url=url; return returner; }
private void btnReplay_Click(object sender, System.EventArgs e) { try{ if (txtHTTPdetails.Text.Length<=0 || txtTargetHost.Text.Length<=0 || txtTargetPort.Text.Length<=0){ return; } showresults formres=null; detailedRequest_IE work = new detailedRequest_IE(); work=getHTTPdetails(txtHTTPdetails.Text,true); if (chkReplayIE.Checked){ //IE try{ if (ie.FullName.Length>1){ ie.Stop(); ie.Quit(); ie = new InternetExplorer(); } } catch{ ie = new InternetExplorer(); } ie.Visible=true; Thread.Sleep(300); ie.Navigate2(ref work.url, ref isnull, ref isnull, ref work.postdata, ref work.headers); } if (chkReplayFireFox.Checked){ //FF try{ if (FF.FullName.Length>1){ formres.Controls.Remove(FF); FF.Stop(); FF.Quit(); FF = new AxMOZILLACONTROLLib.AxMozillaBrowser(); ((System.ComponentModel.ISupportInitialize)(this.FF)).BeginInit(); FF.Location = new System.Drawing.Point(0, 0); FF.Size = new System.Drawing.Size(792, 541); formres.Controls.Add(FF); Thread.Sleep(300); } } catch{ formres = new showresults(); try{ formres.Text="FireFox Browser results"; FF = new AxMOZILLACONTROLLib.AxMozillaBrowser(); ((System.ComponentModel.ISupportInitialize)(this.FF)).BeginInit(); FF.Location = new System.Drawing.Point(0, 0); FF.Size = new System.Drawing.Size(792, 541); formres.Controls.Remove(formres.rtbResults); formres.Controls.Add(FF); formres.Show(); } catch {} } //hack - Firefox adds its own content length try{ work.headers=work.headers.ToString().Replace("Content-Length","Firefix").Replace("Content-length","Firefix"); FF.Navigate2(ref work.url, ref isnull, ref isnull, ref work.postdata, ref work.headers); } catch {} } } catch {} }