Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

C# Help With HttpWebRequest [Authentication failed]

Hi,

I am getting this error upon sending this request:

"Authentication failed because the remote party has closed the transport stream"

Code
       public static bool RegisterAccount(Account acc, CookieContainer ck)
       {
           ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
           System.Net.ServicePointManager.Expect100Continue = false;

           HttpWebRequest registerReq = WebRequest.CreateHttp("chaturbate[dot]com/accounts/register/?");
           registerReq.Method = "POST";

           string[] MaleFemale = { "M", "F" };
           string postData = string.Format("csrfmiddlewaretoken={0}&username={1}&password={2}&email={3}&birthday_month={4}&birthday_day={5}&birthday_year={6}&gender={7}&g-recaptcha-response={8}&terms=on&privacy_policy=on&studio=&redeem_code=",
               acc.CsrfToken, acc.Username, acc.Password, acc.Email, acc.rnd.Next(0, 9), acc.rnd.Next(0, 9), acc.rnd.Next(1950, 1999), MaleFemale[acc.rnd.Next(0,1)], acc.RecaptchaToken);

           byte[] byteArray = Encoding.UTF8.GetBytes(postData);

           registerReq.ProtocolVersion = HttpVersion.Version11;
           registerReq.Host = "chaturbate[dot]com";
           registerReq.KeepAlive = true;
           registerReq.ContentLength = postData.Length;
           registerReq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
           registerReq.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36";
           registerReq.ContentType = "application/x-www-form-urlencoded";
           registerReq.Referer = "chaturbate[dot]com/";
           registerReq.Headers.Add("Cache-Control", "max-age=0");
           registerReq.Headers.Add("Origin", "chaturbate[dot]com");
           registerReq.Headers.Add("Upgrade-Insecure-Requests", "1");
           registerReq.Headers.Add("Sec-Fetch-Mode", "navigate");
           registerReq.Headers.Add("Sec-Fetch-User", "?1");
           registerReq.Headers.Add("Sec-Fetch-Site", "same-origin");
           if (acc.Proxy == null) { registerReq.Proxy = acc.Proxy; }
           registerReq.CookieContainer = ck;

           postData = HttpUtility.UrlEncode(postData);
           Stream dataStream = registerReq.GetRequestStream();
           dataStream.Write(byteArray, 0, byteArray.Length);
           dataStream.Close();

           HttpWebResponse resp = (HttpWebResponse)registerReq.GetResponse();
           if (resp.StatusCode == HttpStatusCode.Found) { return true; } else { return false; }
       }

I have tried almost everything but nothing helps. (links have been replaced with [dot] - full code; pastebin . com/raw/ZbieRH56

Hopefully someone can help me with this!

Draxyee
-post a snippet of the original request made by our browser
-why not httpclient
-
Code
if (resp.StatusCode == HttpStatusCode.Found) { return true; } else { return false; }

this makes no fucking sense, just do
Code
return resp.StatusCode == HttpStatusCode.Found;
-thats a weird way for postdata

i could probably go more a lot in the code, but before that just post a snippet of the actual http request

“I wish I could say everything in one word. I hate all the things that can happen between the beginning of a sentence and the end.” ~ Leonard Cohen
(Sep 3, 2019 10:20 AM)vaiperboy Wrote:  -post a snippet of the original request made by our browser
-why not httpclient
-
Code
if (resp.StatusCode == HttpStatusCode.Found) { return true; } else { return false; }

this makes no fugging sense, just do
Code
return resp.StatusCode == HttpStatusCode.Found;
-thats a weird way for postdata

i could probably go more a lot in the code, but before that just post a snippet of the actual http request

Full request: regex101 . com/r/2Zsdc3/1

Also, thanks a lot for that tip on returning true/false, that's really helpful 👍

- Draxyee
Could anyone help me with this? :)
You’re urlencodjng your whole post data. Aren’t the keys getting encoded then too? Just a thought I could be wrong
[Image: Syr3DlV.png]
(Sep 8, 2019 07:22 AM)gigajew Wrote:  You’re urlencodjng your whole post data. Aren’t the keys getting encoded then too? Just a thought I could be wrong

URL Encode is just for the application/x-www-form-urlencoded
(Sep 8, 2019 11:58 AM)draxyee Wrote:  URL Encode is just for the application/x-www-form-urlencoded

What he's saying is that is not how URL encoding works. You are only supposed to encode the keys and values, not the common separators like = and &.

You sure this is right?
Code
if (acc.Proxy == null) { registerReq.Proxy = acc.Proxy; }
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(Sep 8, 2019 05:57 PM)0xDEAD10CC Wrote:  What he's saying is that is not how URL encoding works. You are only supposed to encode the keys and values, not the common separators like = and &.

You sure this is right?
Code
if (acc.Proxy == null) { registerReq.Proxy = acc.Proxy; }

I see.

Yes that line is right. I set proxy to null if string is empty. I don't think that's why there's an issue though.
(Sep 9, 2019 03:55 PM)draxyee Wrote:  I see.

Yes that line is right. I set proxy to null if string is empty. I don't think that's why there's an issue though.

That makes absolutely no sense. What if it has a value? It never sets the proxy anyways since it is a local variable...
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(Sep 9, 2019 04:46 PM)0xDEAD10CC Wrote:  That makes absolutely no sense. What if it has a value? It never sets the proxy anyways since it is a local variable...

I've tried playing with proxies but it has no difference in whether the request will throw the error I mentioned.

Thanks again.
(Sep 9, 2019 03:55 PM)draxyee Wrote:  I see.

Yes that line is right. I set proxy to null if string is empty. I don't think that's why there's an issue though.

No it is not 'right' in any way shape or form. Your proxy can only be null in your code! Don't you see that? That line of code does absolutely nothing but consume CPU cycles and should be removed entirely.

In any case, this seems to be an issue related to TLS mismatch. You need to make sure that the required cipher suites are enabled in Windows and configured properly in your .NET environment and code:
https://docs.microsoft.com/en-us/dotnet/...amming/tls

Read that and then look at your code in which you do this:
Code
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
Code
registerReq.ProtocolVersion = HttpVersion.Version11;
[Image: vp6iypF.gif]
(Sep 10, 2019 01:08 PM)MavenGradle Wrote:  
Code
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

This! without the Ssl3.
You don't need that.
Just add that line in the constructor and you should be fine.
[Image: logo.gif]
(Sep 10, 2019 01:15 PM)n0$f3ratu$ Wrote:  This! without the Ssl3.
You don't need that.
Just add that line in the constructor and you should be fine.

I was actually trying to make the point that with the more recent versions of the .NET Framework, you should no longer do things like that and simply let the .NET Framework use the OS default settings. By recent, I mean .NET 4.7 which was released almost 3 years ago.
[Image: vp6iypF.gif]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by HardStoNMay 2, 2021 12:59 AM 5 268 May 2, 2021 12:59 AM
Last Post: vaiperboy
[.NET] by freesixJan 19, 2019 02:14 AM 13 490 Jan 19, 2019 02:14 AM
Last Post: StarZ
[.NET] by Hacker2245Dec 28, 2018 01:07 AM 7 247 Dec 28, 2018 01:07 AM
Last Post: 0xDEAD10CC