gpt4 book ai didi

c# - C# SslStream 不适合登录到 facebook 吗?

转载 作者:太空宇宙 更新时间:2023-11-03 15:01:49 25 4
gpt4 key购买 nike

已解决:SslStream 不会一次读取整个数据包...


我正在尝试使用一些准备好的数据包登录到 m.facebook.com。我用 SslStream 发送它。回复好像没问题但它不包含所需的名为 xs 的 cookie。我认为我准备的数据包有问题。但是我尝试用 Fiddler 和 SocketTest3 发送完全相同的数据包,我收到了 cookie。可能是什么问题。

我使用的代码, Conceal 了登录名和密码。

   static void Main(string[] args)
{
SslTcpClient.TryLogin("m.facebook.com", "m.facebook.com");
Console.ReadKey(true);
}

public class SslTcpClient
{
private static Hashtable certificateErrors = new Hashtable();

public static bool ValidateServerCertificate(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None)
return true;

Console.WriteLine("Certificate error: {0}", sslPolicyErrors);

return false;
}
public static void TryLogin(string machineName, string serverName)
{
TcpClient client = new TcpClient(machineName, 443);
Console.WriteLine("Client connected.");
SslStream sslStream = new SslStream(
client.GetStream(),
false,
new RemoteCertificateValidationCallback(ValidateServerCertificate),
null
);
try
{
sslStream.AuthenticateAsClient(serverName);
}
catch (AuthenticationException e)
{
Console.WriteLine("Exception: {0}", e.Message);
if (e.InnerException != null)
{
Console.WriteLine("Inner exception: {0}", e.InnerException.Message);
}
Console.WriteLine("Authentication failed - closing the connection.");
client.Close();
return;
}
var message = "POST https://m.facebook.com/login.php?refsrc=https%3A%2F%2Fm.facebook.com%2F&refid=8 HTTP/1.1\r\n" +
"Host: m.facebook.com\r\n" +
"User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0\r\n" +
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" +
"Accept-Language: pl,en-us;q=0.7,en;q=0.3\r\n" +
"Accept-Encoding: gzip, deflate\r\n" +
"Referer: https://m.facebook.com/\r\n" +
"Connection: keep-alive\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"Content-Length: 456\r\n\r\n" +
"lsd=AVqbr7Ql&charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&version=1&ajax=0&width=0&pxr=0&gps=0&m_ts=1388099668&li=VLi8UiFtZGcNu7Ux7Vt6X7UM&signup_layout=layout%7Cbottom_clean%7C%7Cwider_form%7C%7Cprmnt_btn%7Cspecial%7C%7Cst%7Ccreate%7C%7Cheader_crt_acct_button%7C%7Chdbtn_color%7Cgreen%7C%7Csignupinstr%7C%7Claunched_Mar3&email=LOGIN&pass=PASSWORD&login=Zaloguj+si%C4%99&_fb_noscript=true";

byte[] messsage = Encoding.UTF8.GetBytes(message);
sslStream.Write(messsage);
sslStream.Flush();
var buffer = new byte[10000];
int r = sslStream.Read(buffer,0,buffer.Length);
string serverMessage = Encoding.UTF8.GetString(buffer, 0, r);
Console.WriteLine("Server says: {0}", serverMessage);
client.Close();
Console.WriteLine("Client closed.");
}

}

最佳答案

已解决:SslStream 不会一次读取整个 header 。需要调用 Double Read 方法。Facebook 可能会单独发送 header 的各个部分。

关于c# - C# SslStream 不适合登录到 facebook 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20793324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com