C
C#2mo ago
Kroks

How to use the same HttpClient instance with different session cookies / proxies?

Hello I am managing thousands of accounts at once (nothing malicious, just for pentesting reasons). And was wondering how I could accomplish this. For each of these accounts I am currently using one HttpClient. But after a while I get "Unable to read data from the transport connection: Connection reset by peer". I believe this is due to Socket exhaustion. And Socket exhaustion is due to the fact that I use so many clients.
No description
18 Replies
Kroks
Kroks2mo ago
Each account has different cookies (authorization etc.) and uses a different proxy. So how can I implement this code pattern by using one single instance for all accounts
MKP
MKP2mo ago
You can probably interlace them instead of immediately firing all of them. Knowing your upper limit. I don’t think you’ll do your pen testing any wrong. You could choose to elect more computers, nics, or a local vpn.
Kroks
Kroks2mo ago
the network shouldnt limit me though like the server has 1gbps and im not sending more than 5mb ps
MKP
MKP2mo ago
Speed is irrelevant
Kroks
Kroks2mo ago
Whats relevant?
MKP
MKP2mo ago
Amount of socket connections
Kroks
Kroks2mo ago
isnt one socket = one httpclient ?
MKP
MKP2mo ago
Mhm Opened on connect
Kroks
Kroks2mo ago
i dont think i even get close to the max socket amount that is allowed with 3k httpclients
Joschi
Joschi2mo ago
Just to be sure, how do you instantiate your Http Clients?
Kroks
Kroks2mo ago
var handler = new HttpClientHandler
{
Proxy = proxy,
AutomaticDecompression = DecompressionMethods.All,
CookieContainer = new CookieContainer(),
AllowAutoRedirect = false
};
Client = new MyHttpClient(account, handler);
var handler = new HttpClientHandler
{
Proxy = proxy,
AutomaticDecompression = DecompressionMethods.All,
CookieContainer = new CookieContainer(),
AllowAutoRedirect = false
};
Client = new MyHttpClient(account, handler);
MyHttpClient is public class MyHttpClient : HttpClient @Joschi Wym
Joschi
Joschi2mo ago
Just newing up http clients is not the recommended best practice. Mainly because it can lead to socket exhaustion. Take a look at the IHttpClientFactory https://learn.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests
Use IHttpClientFactory to implement resilient HTTP requests - .NET
Learn how to use IHttpClientFactory, available since .NET Core 2.1, for creating HttpClient instances, making it easy for you to use it in your applications.
Kroks
Kroks2mo ago
Ye thought the same basically but i dont even have that many open sockets a fewk k the weird thing is after this happens it works again in 10min even if I restart right after it doesnt work, i need to wait like 10mins and its 100% unrelated to the target machine that im requesting because on my local it doesnt happen
Kroks
Kroks2mo ago
but on my local machine it works
MKP
MKP2mo ago
Connection reset is a funny way of saying disconnect
Kroks
Kroks2mo ago
Current progress: - Once this happens the server needs 10-15min before I can request it again (a restart wont even fix this) - I tried to login manually into the proxy and got "Connection reset" in the firefox browser. Tried the same on my local machine and it worked - I believe it must be the server provider. I think that they have a mechanism that prevents us to send thousands of requests to the same host (the host is the proxy provider) I think that their mechanism thinks that we are trying to ddos some service or idk makes literally no sense
Want results from more Discord servers?
Add your server
More Posts
Opening DB Connection: Object cannot be cast from DBNull to other typesHelp. Im trying to open a connection to my mariaDB database. i can access the database with the credDelegate.CreateDelegate returns "ArgumentException: method arguments are incompatible"Any idea what I did wrong here ? My method seems to be of the correct type ```CSharp publicRunning custom build targets within library userI have all my code to implement views within a big HTTP library I'm making, that parses files with hTransforming own type into ProblemDetailsSo, I really like using `application/problem+json` to specify my results and for that I have my own Share the resources that helped you grow in understanding Data Structures and Algorithms?I'm looking to prepare for graduate interviews for a years time from now. Probably won't touch LeetDirectory.Packages.props working for all projects except ApiI have the following Directory.Packages.props in my solution: ```xml <Project> <ItemGroup CondiPreview Monaco editor input as html on blazor projectHello i have a .net 8 blazor project where i want to write html inside the monaco code editor and thSource generators VSCodeI'm using VSCode on linux, but it seems like source generators do not work... In specific, the [resx✅ Help with XAMLI have a problem while designing my UI, I'm creating a panel (the app has dynamic UI so that it can Basic project structure for api/frontendI've a small project I wanna build, but it'll need a frontend and a backend. I'd like to learn some