Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.



2018 posts

Uber Geek
+1 received by user: 111

Trusted

Topic # 105855 12-Jul-2012 11:25 Send private message

So I've had an issue with my Gargoyle 1.5.5 system, where a file I was downloading now requires authentication.

http://www.geekzone.co.nz/forums.asp?forumid=66&topicid=105722

A helpful sidefx found that when you login in to the router a script called \utiltity\get_password_cookie.sh is called with the password= post variables.

So I'm calling this with the correct password, but what I'm not seeing is a "hash" cookie in a HttpWebResponse Cookie collection.  What I'm actually getting is a byte array as a return value for webClient.UploadData that contains the Set-Cookie:hash= etc

I then need to try and use this in a subsequent request, but for the life of me cannot get it to work.

Anyone have any pointers?

I can post parts of the code if need be, I've implemented an extended WebClient (CookieAwareWebClient) to deal with the cookies, but at the point that the CookieAwareWebClient is processing the response, the hash cookie does not exist.




Previously known as psycik

NextPVR Based HTPC:

2 x HVR3000 - DVB-S - Freeview, HVR3000 - DVB-T Freeview|HD, Nova-T 500 - Dual Freeview|HD, Digital Coax --> Yamaha RX-v540, 8600GT --> Samsung LA46A650D via HDMI
Clients:
Popcorn Hour A-100, 1xATV2, 1xATV3, Roku3
Windows 7 Ultimate Host (Plex Server)
3x2TB, 1x3TB, 1x4TB + 1x1.5TB using DriveBender, VMWare Workstation 10 with 1xW7, 2xW2k3 1xUbuntu 11.10 Desktop, 1xWHS2011, Plex, Crashplan

UnblockUS - Unblock your freedom

Create new topic
1773 posts

Uber Geek
+1 received by user: 202


  Reply # 654815 12-Jul-2012 21:41 Send private message

If you haven't already solved it, this works, if a bit ugly. 

I had to fix 1.5.4 as per this first though: http://www.gargoyle-router.com/phpbb/viewtopic.php?f=12&t=2590

EDIT: What, no [code] tags on geekzone?! :D  Also obviously put your password into password=********


using System;
using System.Net;
using System.Text;

namespace GargoyleLogin
{
class Program
{
static void Main()
{
var result = GetCookies("http://192.168.51.1/utility/get_password_cookie.sh", "password=*********");
Console.Out.Write("Cookies: " + result);
var csvResult = HttpGetWithCookies("http://192.168.51.1/bandwidth.csv", result);
Console.Out.Write("csv:\n" + csvResult);
Console.In.ReadLine();
}

private static string GetCookies(string uri, string parameters)
{
var req = WebRequest.Create(uri);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes(parameters);
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();
WebResponse resp = req.GetResponse();
var sr = new System.IO.StreamReader(resp.GetResponseStream());
var cookies = sr.ReadToEnd().Trim();
return cookies.Replace("Set-Cookie:", "").Replace("path=/", "").Replace("\n", " ");
}

public static string HttpGetWithCookies(string uri, string cookies)
{
var req = WebRequest.Create(uri);
req.Headers["Cookie"] = cookies;
WebResponse resp = req.GetResponse();
var sr = new System.IO.StreamReader(resp.GetResponseStream());
return sr.ReadToEnd().Trim();
}
}
}




2018 posts

Uber Geek
+1 received by user: 111

Trusted

  Reply # 654817 12-Jul-2012 21:46 Send private message

Hm. Awesome. I'll try that tomorrow.




Previously known as psycik

NextPVR Based HTPC:

2 x HVR3000 - DVB-S - Freeview, HVR3000 - DVB-T Freeview|HD, Nova-T 500 - Dual Freeview|HD, Digital Coax --> Yamaha RX-v540, 8600GT --> Samsung LA46A650D via HDMI
Clients:
Popcorn Hour A-100, 1xATV2, 1xATV3, Roku3
Windows 7 Ultimate Host (Plex Server)
3x2TB, 1x3TB, 1x4TB + 1x1.5TB using DriveBender, VMWare Workstation 10 with 1xW7, 2xW2k3 1xUbuntu 11.10 Desktop, 1xWHS2011, Plex, Crashplan

UnblockUS - Unblock your freedom



2018 posts

Uber Geek
+1 received by user: 111

Trusted

  Reply # 655015 13-Jul-2012 13:00 Send private message

Worked great thanks!!




Previously known as psycik

NextPVR Based HTPC:

2 x HVR3000 - DVB-S - Freeview, HVR3000 - DVB-T Freeview|HD, Nova-T 500 - Dual Freeview|HD, Digital Coax --> Yamaha RX-v540, 8600GT --> Samsung LA46A650D via HDMI
Clients:
Popcorn Hour A-100, 1xATV2, 1xATV3, Roku3
Windows 7 Ultimate Host (Plex Server)
3x2TB, 1x3TB, 1x4TB + 1x1.5TB using DriveBender, VMWare Workstation 10 with 1xW7, 2xW2k3 1xUbuntu 11.10 Desktop, 1xWHS2011, Plex, Crashplan

UnblockUS - Unblock your freedom

Create new topic




Twitter »
Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:




News »

Trending now »
Hot discussions in our forums right now:

CGA. Is it fair?
Created by BTR, last reply by bazzer on 22-Aug-2014 11:02 (86 replies)
Pages... 4 5 6


Vodafone TV multicast settings on pfSense?
Created by kenkeniff, last reply by hio77 on 23-Aug-2014 23:15 (134 replies)
Pages... 7 8 9


Warning about Pure Hosting
Created by LostBoyNZ, last reply by MichaelNZ on 23-Aug-2014 23:06 (48 replies)
Pages... 2 3 4


Lightbox press event release
Created by freitasm, last reply by Lightbox on 22-Aug-2014 17:04 (469 replies)
Pages... 30 31 32


It was hardly 'hacking' was it?
Created by CB_24, last reply by gzt on 21-Aug-2014 22:26 (97 replies)
Pages... 5 6 7


Why is there no right to compensation for wrongful imprisonment in NZ?
Created by Geektastic, last reply by networkn on 23-Aug-2014 22:40 (18 replies)
Pages... 2


Free: Smart Button for your Android device
Created by freitasm, last reply by BigHammer on 23-Aug-2014 19:04 (111 replies)
Pages... 6 7 8


Vodafone now charging you to receive a bill via post
Created by stocksp, last reply by Linuxluver on 22-Aug-2014 19:45 (86 replies)
Pages... 4 5 6



Geekzone Live »
Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.

Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.