VMProtect and webclient - c#

I have a problem with protecting my soft with VMProtect.
url (with redirect)- no secerity, no SSL/TLS (HTML 1.1, http)
In Visual Studio I have no Errors (compiled, without protection).
WebClient webClient = new WebClient();
webClient.Headers.Add(HttpRequestHeader.UserAgent, Agent);
content = await webClient.DownloadStringTaskAsync(url);
With this code i have an error: The request was aborted. Could not create SSL/TLS connection
I tried to add (before and after new Weblicent()):
ServicePointManager.Expect100Continue = true;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11| SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
Also tried add only this:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 (and with Ssl3)
Not worked: Eset antivirus blocking: MSIL/TrojanDownloader.Agent.LNO

Related

Can't connect to website through C#, but with Firefox

When I try to connect to a website I get the error:
The request was aborted: Could not create SSL/TLS secure channel
The Status in the exception is SecureChannelFailure, the Response is null.
Searching StackOverflow for answers has not helped me so far. I tried all the solutions:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.Expect100Continue = true;
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
The ServerCertificateValidationCallback never gets called.
I can open the website in Firefox and Edge(Chromium) without problems, but the Internet Explorer can't make a secure connection to it. So I assume that HttpWebRequest is using the same "mechanics" as Internet Explorer, but I can't figure out which.
On https://server.cryptomix.com/secure/ I ensured, that I don't have a client SSL certificate presented. That means that I don't have to add ClientCertificate to the request.
Here is my whole test code:
public static void Main()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.Expect100Continue = true;
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(#"https://netmap.vodafone.de"));
request.Method = "GET";
request.ContentType = "text/json";
try
{
using (var response = (HttpWebResponse)request.GetResponse())
{
}
}
catch (Exception e)
{
throw;
}
}
Do you have any idea, why I can connect with Internet Explorer and HttpWebRequest, but with Firefox it's possible?
Do you get the same error when you run the code?
Edit: I found out, that the website is using TLS 1.3, but there is no SecurityProtocolType.Tls13 enum value.
It seems this has to be an issue with your client.
I bet on issues with the cipher suites, the site has a pretty good TLS configuration (data from ssllabs.com):
Please check your OS (fully patched?) for support.
I had the same issuze in one of my projects before. This worked out for me:
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;
It requires the System.Net Namespace.

C# - RestSharp - The request was aborted: Could not create SSL/TLS secure channel

I am trying invoke a REST web service using RestSharp.
Following is my code :
ServicePointManager.Expect100Continue = true;
ServicePointManager.DefaultConnectionLimit = 9999;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
var client = new RestClient(url);
var certificate = new X509Certificate();
certificate.Import(Properties.Resources.cert, "password", X509KeyStorageFlags.PersistKeySet);
client.ClientCertificates = new X509CertificateCollection() { certificate };
var request = new RestRequest(Method.POST);
request.AddHeader("Connection", "keep-alive");
request.AddHeader("Content-Type", "text/plain");
request.AddParameter("undefined", $"param={param}", ParameterType.RequestBody);
IRestResponse response = await client.ExecutePostTaskAsync(request);
return response;
However, I am getting error - The request was aborted: Could not create SSL/TLS secure channel.
I also tried searching about this error but in all of the posts people suggest to use - SecurityProtocolType.Tls12 and ServicePointManager.Expect100Continue = true.
I am already using these in my code, still I see the error. Also if I try to fire similar request using Postman it works fine.
Is there anything else that I am missing?
Found it. C# requires the cert to be imported in user store.
I was missing this part.
After importing the pfx to the user store, for the first request I was prompted for the allowing the request by OS, subsequent requests worked flawlessly.

How to create a websocket to a URL using "Authorization", "Bearer", token in c#

I need to create a websocket to a particular url(cannot reveal) in c#. Is there something similar to the WebSocket API in Java, or libwebsockets in C for C#?
I have already tried using WebSocketSharp and ChilKat by following some of the SO answers. Also tried using the Microsofts WebSocket Namespace. But was always getting the "Not Authorized" error 401. I also tried doing an Http get and tried to add headers to upgrade the socket to Websocket by following the tutorial to create WebSocket servers in the MDN docs, but was only getting a redirected webpage in return. This is the code I used for the HTTP upgrade request. I am a beginner to c#.
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) =>
{
return true;
};
var http = (HttpWebRequest)WebRequest.Create(new Uri(baseAddress));
http.AllowAutoRedirect = false;
http.UseDefaultCredentials = true;
http.PreAuthenticate = true;
http.Credentials = CredentialCache.DefaultCredentials;
http.Proxy.Credentials = CredentialCache.DefaultCredentials;
http.Accept = "application/json";
http.ContentType = "application/json";
http.Method = "GET";
http.Connection = "Open";
http.Headers.Add("Authorization", "Bearer " + Token);
//http.Headers.Add("Connection", "Upgrade");
http.Headers.Add("Upgrade", "websocket");
http.KeepAlive = true;
What I want to achieve is something like,
Websocket socket = new Websocket();
socket.addHeader(Authorization, Bearer, Token);
socket.connect();
Thanks in Advance for any inputs.
I am using ClientWebSocket to connect to the Zendesk chat streaming API using an OAuth token like this:
var webSocket = new ClientWebSocket();
webSocket.Options.SetRequestHeader("Authorization", $"Bearer {_oauthToken}");
var cts = new CancellationTokenSource();
await webSocket.ConnectAsync(new Uri(url), cts.Token);
It works for me!

API is returning error when using RESTSHARP

When use RestSharp to call an API I get this error:
The underlying connection was closed: An unexpected error occurred on
a send.
I've verified that my client ID, secret, username, and password are correct. I'm able to do this without issues in PowerShell.
public string GetTokenForBrightIdea()
{
RestClient restclient = new RestClient(_uri);
RestRequest request = new RestRequest() { Method = Method.POST };
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("grant_type", "password");
request.AddParameter("client_id", _clientId);
request.AddParameter("client_secret", _clientSecret);
request.AddParameter("username", _clientUsername);
request.AddParameter("password", _clientPassword);
var tResponse = restclient.Execute(request);
var responseJson = tResponse.Content;
return JsonConvert.DeserializeObject<Dictionary<string, object>>(
responseJson)["access_token"].ToString();
}
What am I missing when using RestSharp to make this work?
So it turns out that because this call was HTTPS i needed to add the following line of code
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
For .Net 3.5 and 4.0 you could try putting this line of code prior to the initialization of the RestSharp client:
ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072;
This worked fine for me:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12;

The request was aborted: Could not create SSL/TLS secure channel HttpClient

I am trying to access a web api using below C# code :
private static CertificateContext authenticationContext;
authenticationContext = new CertificateContext(new Uri(endpoint), ThumbPrint);
var client = authenticationContext.GetHttpClient();
var response = await client.GetStringAsync(url);
It was working fine initially but later i am getting below error:
The request was aborted: Could not create SSL/TLS secure channel.
I checked some forums and as per the suggestions i tried with below options, but nothing worked for me
1.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
2.ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslPolicyErrors) { return true; };
Kindly help me to fix this error. Thanks in advance

Categories