2

I'm trying to web-crawl a site that uses php sessions via cookies. It is a good-ol' Squirrelmail webmail server.

I saw a couple of posts like this one, but it's not working for me.

When reaching the part when the cookies are sent by the host, I tried to retrieve the cookies using:

HttpWebResponse rs = (HttpWebResponse)rq.GetResponse();
CookieCollection cc = new CookieCollection();
cc.Add(rs.Cookies);

But rs.Cookies comes empty. However, there are set-cookie headers on the response, which I try to use as a guide to build actual cookies, like this:

for (int i = 0; i < rs.Headers.Count; i++)
{
    if (rs.Headers.Keys[i].ToLower().Contains("cookie"))
    {
        string val = rs.Headers[i];
        string[] vv = val.Split(";=,".ToCharArray());
        Cookie co = new Cookie(vv[0], vv[1]);

        // I know this is not the cleanest way to do it
        // I've tried to manually set different values for 
        // co.Domain, co.Path and co.HttpOnly, just to get a working
        // example. I tried different alternatives, but it doesn't
        // seem to change anything

        cc.Add(co);
    }
}

Next, I send the cookies to request the next page, which is nothing but a frameset. The fact that I reach the frameset means I've been successfully authenticated and the session cookie is working. However, when I request one of the frames, I get an authentication-error web page. I've done my research, and the cookies do not change in the meantime. What may be going wrong?

Some may wonder why I'm trying to access webmail when there is pop/smtp to do a cleaner job. The answer is this is just a first example to learn the basics, I don't really care what the site is as long as I can successfully manage sessions.

I don't think posting all the code is a good idea yet, since it is a bit messy, and long: I planned to clean it once it worked (I'll post it, if you think it's worth the confusion). Moreover, I think I may have a conceptual error related to the frames, that may be the key to solve the problem.

Community
  • 1
  • 1
Rafael
  • 129
  • 5

0 Answers0