csharp-leaf / Leaf.xNet

HTTP Library. Impoved original xNet.
https://github.com/csharp-leaf
180 stars 52 forks source link

Reading hidden HTTP headers #99

Closed AnErrupTion closed 4 years ago

AnErrupTion commented 4 years ago

Is there a way to read hidden HTTP headers such as Via, X-Forwarded-For, and such ones? I'm making a proxy checker and I'm trying to check the anonymity level of each one. However, when I do request["Via"] or any hidden header (request being the HttpRequest) it just returns nothing, while they clearly exist.

How am I supposed to do this?

grandsilence commented 4 years ago

httpRequest.Response["Header-Name"]

AnErrupTion commented 4 years ago

Hm, still doesn't work. All my proxies show as Elite, while clearly most of them are Transparent or even Anonymous. This is because it can't find such hidden header. Maybe Leaf.xNet can't find them?

AnErrupTion commented 4 years ago

As seen in this first screenshot, using "req.Response.ContainsHeader("X)" just doesn't work: Screenshot from 2020-07-31 00 23 12

And, when using this proxy and going to http://proxydb.net/anon, we can see it's a transparent proxy: Screenshot from 2020-07-31 00 24 11

abhay991 commented 4 years ago

Hello, this is not a response header but the content on site so you will need to use regex, an HTML parser, or substring to get the detail you need.

AnErrupTion commented 4 years ago

No, I'm not talking about the content on that website. I'm talking about the hidden headers like Via, X-Forwarded-For, etc... When using a proxy, transparent for example, it generally sets the X-Forwarded-For header to your IP Address, and a few others to mark that you're using a proxy. However, when checking a transparent proxy, it can't find those headers even though they clearly exist.

abhay991 commented 4 years ago

You can try this site https://azenv.net/

AnErrupTion commented 4 years ago

Nope, still doesn't show those headers.

abhay991 commented 4 years ago

Those headers are not represented in request or response headers but in response content. You should first understand basics of request first I guess. You can also get the source code of azenvironment and see how things work internally.

AnErrupTion commented 4 years ago

Headers aren't in response content... for example, with curl, you can view those hidden headers. Also, I saw the response content, it only shows "REMOTE_ADDR" which shows the proxy address or your IP address, so not even useful for me. I just need to see those headers with Leaf.xNet for my proxy checker... perhaps it's not a feature in Leaf.xNet?

abhay991 commented 4 years ago

You can use this way.

var res = req.Get("https://azenv.net/");
var source = res.ToString();

var REMOTE_ADDR = source.Substring("REMOTE_ADDR = ", Environment.NewLine);
AnErrupTion commented 4 years ago

I said that REMOTE_ADDR wasn't useful to me as it only shows the proxy address.

abhay991 commented 4 years ago

I gave you a basic example to read header values. If you want everything spoonfed then here it is.

var res = req.Get("https://azenv.net/");
var src = res.ToString();
var rawHeadersStr = src.Substring("<pre>", "</pre>");
var rawheaders = rawHeadersStr.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

var headers = new Dictionary<string, string>();

foreach (var item in rawheaders)
{
    if (item.Contains(" = "))
    {
        var headerData = item.Split(new string[] { " = " }, StringSplitOptions.None);
        headers.Add(headerData[0], headerData[1]);
    }
}

var connection = headers["HTTP_CONNECTION"];

if (headers.ContainsKey("HTTP_UPGRADE_INSECURE_REQUESTS"))
{ 
    //do something
}
AnErrupTion commented 4 years ago

I know how to parse, but azenv is useless, it doesn't contain the infos I need.

abhay991 commented 4 years ago

I know how to parse, but azenv is useless, it doesn't contain the infos I need.

Has worked for me in past very well actually. Idk you can use any site you want.

AnErrupTion commented 4 years ago

What I just want to do is read those hidden headers, not parse anything from a website...

abhay991 commented 4 years ago

Well, azenv shows only headers which are true so if they do not exist in the source then it's simple they are false.

AnErrupTion commented 4 years ago

ooooooh... I didn't know that... my issue is now fixed lol. Thanks :p