您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
一个用c#写的扫描asp源码漏洞的应用程序(续)
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:07:48
p;              strRequestFile.Substring(0 , 50)
                                        :strRequestFile)
                                     + "...";

                string strResult ;
                //如果不是translate:f方法则可以直接发送http请求
                if (this.cboMethod.SelectedIndex != 20)
                {
                    //直接发送http请求
                    strResult = Get_Http(strRequestFile) ;

                    this.barStatus.Text += "完成。"  ;
                    strResult = strResult == "" ? "未找到!" : strResult ;
                    this.txtResult.Text = strResult ;
                }
                else  //translate:f方法需要建立tcp/ip连接
                {
                    string strRequest = "GET " + strServer + strUrl
                                       + " HTTP/1.0 Translate:f " ;
                    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 ";
            //string Get =
            Byte[] ByteGet = ASCII.GetBytes(Get);
            Byte[] RecvBytes = new Byte[256];
            String strRetPage = null;

            // IPAddress and IPEndPoint represent the endpoint that will
            //   receive the request
            IPAddress hostadd = DNS.Resolve(a_strServer.Substring(7 ,a_strServer.Length - 7));
            IPEndPoint EPhost = new IPEndPoint(hostadd, a_intPort);

            //Create the Socket for sending data over TCP
            Socket s = new Socket(AddressFamily.AfINet, SocketType.SockStream,
                                    ProtocolType.ProtTCP );

            // Connect to host using IPEndPoint
            if (s.Connect(EPhost) != 0)
            {
                strRetPage = "Unable to connect to host";
                return strRetPage;
            }

            // Sent the GET text to the host
            s.Send(ByteGet, ByteGet.Length, 0);

            // Receive the page, loop until all bytes are received
            Int32 bytes = s.Receive(RecvBytes, RecvBytes.Length, 0);
            strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes);

            while (bytes > 0)
            {
                bytes = s.Receive(RecvBytes, RecvBytes.Length, 0);
                strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes);
            }

            return strRetPage ;
        }

        //获取http页面函数
        private string Get_Http(string a_strUrl)
        {
            string strResult ;
            HttpWebRequest myReq = (HttpWebRequest)
                                   WebRequestFactory.Create(a_strUrl) ;

            try
            {
                HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
                Stream myStream = HttpWResp.GetResponseStream () ;

                StreamReader sr = new StreamReader(myStream , Encoding.Default);
                StringBuilder strBuilder = new StringBuilder();
                whi

上一页  [1] [2] [3] [4] [5] 下一页


更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |