Click here to Skip to main content
15,887,175 members
Home / Discussions / C#
   

C#

 
AnswerRe: Encrypt - Decrypt Pin
Eddy Vluggen12-Jul-12 0:36
professionalEddy Vluggen12-Jul-12 0:36 
QuestionRe: Encrypt - Decrypt Pin
Midnight Ahri12-Jul-12 0:51
Midnight Ahri12-Jul-12 0:51 
AnswerRe: Encrypt - Decrypt Pin
Eddy Vluggen12-Jul-12 2:24
professionalEddy Vluggen12-Jul-12 2:24 
AnswerRe: Encrypt - Decrypt Pin
Midnight Ahri12-Jul-12 15:28
Midnight Ahri12-Jul-12 15:28 
GeneralRe: Encrypt - Decrypt Pin
BobJanova12-Jul-12 23:39
BobJanova12-Jul-12 23:39 
Questionhow to use use transparent proxy(local host) in middle of browser and destination server?? Pin
modipavan12-Jul-12 0:03
modipavan12-Jul-12 0:03 
AnswerRe: how to use use transparent proxy(local host) in middle of browser and destination server?? Pin
Eddy Vluggen12-Jul-12 0:40
professionalEddy Vluggen12-Jul-12 0:40 
QuestionCookie based authentication - calling a get cookie script - cookiecollection empty Pin
psycik11-Jul-12 23:20
psycik11-Jul-12 23:20 
I'm trying to use a CookieAwareWebClient (or just a httpwebrequest) to log in to a gargoyle router.

To do so I have to post a password to a utility/get_password_cookie.sh. I can replicate this with code.

C#
NameValueCollection loginData = new NameValueCollection();
loginData.Add("password", "loginpassword");
byte[] returnData = webclient.uploaddata("http://server/utility/get_password_cookie.sh",loginData );

 tempData = webclient.Encoding.GetString(data);
 tempData = tempData.Replace("\n",string.Empty);
 webclient.Headers.Add(tempData);

 webclient.DownloadFile("http://server/bandwidth.csv", downloadedFile);



Looking at the local variables of the webclient, the cookiecontainer doesn't contain the "hash" cookie I'm expecting to see.

However if I decode the returnData bytearray (to tempData)I see the text
"Set-Cookie:hash=hashvaluehere; path=/Set-Cookie:exp=1342083624; path=/"


So with that text string I tried adding it as a header to a subsequent webclient request to an internal page within the router.

But no matter what I do it doesn't seem to have any effect.

Why is it not in the CookieCollection? How can I use this hash cookie for a subsequent request?

Following is the CookieAwareWebClient.cs

C#
public class CookieAwareWebClient : WebClient
    {
        public CookieContainer CookieContainer { get; set; }
        public Uri Uri { get; set; }
        private string lastRequest;

        public CookieAwareWebClient()
            : this(new CookieContainer())
        {
        }

        public CookieAwareWebClient(CookieContainer cookies)
        {
            this.CookieContainer = cookies;
        }

        protected override WebRequest GetWebRequest(Uri address)
        {
            WebRequest request = base.GetWebRequest(address);
            if (request is HttpWebRequest)
            {
                try
                {
                    
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message);

                }
                (request as HttpWebRequest).CookieContainer = this.CookieContainer;
                if (!String.IsNullOrEmpty(lastRequest))
                {
                    (request as HttpWebRequest).Referer = lastRequest;
                }
                if (request.Method == "POST" && String.IsNullOrEmpty(request.ContentType))
                {
                    request.ContentType = "application/x-www-form-urlencoded";
                }
            }

            
            lastRequest = address.ToString();

            
            HttpWebRequest httpRequest = (HttpWebRequest)request;
            httpRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            return httpRequest;
        }

        protected override WebResponse GetWebResponse(WebRequest request)
        {
            HttpWebResponse response = (HttpWebResponse)base.GetWebResponse(request);
            String setCookieHeader = response.Headers[HttpResponseHeader.SetCookie];
            this.CookieContainer.Add(response.Cookies);
            if (setCookieHeader != null)
            {
                //do something if needed to parse out the cookie.
                if (setCookieHeader != null)
                {
                    Cookie cookie = new Cookie(); //create cookie
                    this.CookieContainer.Add(cookie);
                }
            }
            return response;
        }
    }/pre>

AnswerRe: Cookie based authentication - calling a get cookie script - cookiecollection empty Pin
BobJanova11-Jul-12 23:45
BobJanova11-Jul-12 23:45 
GeneralRe: Cookie based authentication - calling a get cookie script - cookiecollection empty Pin
psycik11-Jul-12 23:51
psycik11-Jul-12 23:51 
GeneralRe: Cookie based authentication - calling a get cookie script - cookiecollection empty Pin
BobJanova13-Jul-12 4:14
BobJanova13-Jul-12 4:14 
QuestionQuery on Delegate Pin
ashish711-Jul-12 21:23
ashish711-Jul-12 21:23 
AnswerRe: Query on Delegate Pin
OriginalGriff11-Jul-12 21:37
mveOriginalGriff11-Jul-12 21:37 
GeneralRe: Query on Delegate Pin
Simon_Whale11-Jul-12 22:27
Simon_Whale11-Jul-12 22:27 
GeneralRe: Query on Delegate Pin
ashish711-Jul-12 22:29
ashish711-Jul-12 22:29 
GeneralRe: Query on Delegate Pin
DaveyM6911-Jul-12 22:48
professionalDaveyM6911-Jul-12 22:48 
GeneralRe: Query on Delegate Pin
OriginalGriff11-Jul-12 22:55
mveOriginalGriff11-Jul-12 22:55 
GeneralRe: Query on Delegate Pin
ashish711-Jul-12 23:13
ashish711-Jul-12 23:13 
GeneralRe: Query on Delegate Pin
Pete O'Hanlon11-Jul-12 23:23
mvePete O'Hanlon11-Jul-12 23:23 
GeneralRe: Query on Delegate Pin
BobJanova11-Jul-12 23:41
BobJanova11-Jul-12 23:41 
GeneralRe: Query on Delegate Pin
Pete O'Hanlon11-Jul-12 22:50
mvePete O'Hanlon11-Jul-12 22:50 
GeneralRe: Query on Delegate Pin
OriginalGriff11-Jul-12 22:56
mveOriginalGriff11-Jul-12 22:56 
GeneralRe: Query on Delegate Pin
DaveyM6911-Jul-12 22:57
professionalDaveyM6911-Jul-12 22:57 
GeneralRe: Query on Delegate Pin
Wayne Gaylard11-Jul-12 23:02
professionalWayne Gaylard11-Jul-12 23:02 
GeneralRe: Query on Delegate Pin
ashish712-Jul-12 2:15
ashish712-Jul-12 2:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.