using AE.Net.Mail;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using xNet;
namespace HttpRequest_Bai1_GetDataFrom_HowKteam
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
#region Kteam code
void AddCookie(HttpRequest http, string cookie)
{
var temp = cookie.Split(';');
foreach (var item in temp)
{
var temp2 = item.Split('=');
if (temp2.Count() > 1)
{
http.Cookies.Add(temp2[0], temp2[1]);
}
}
}
string GetData(string url, HttpRequest http = null, string userArgent = "", string cookie = null)
{
if (http == null)
{
http = new HttpRequest();
http.Cookies = new CookieDictionary();
}
if (!string.IsNullOrEmpty(cookie))
{
AddCookie(http, cookie);
}
if (!string.IsNullOrEmpty(userArgent))
{
http.UserAgent = userArgent;
}
string html = http.Get(url).ToString();
return html;
}
string GetLoginDataToken(string html)
{
string token = "";
var res = Regex.Matches(html, @"(?<=__RequestVerificationToken"" type=""hidden"" value="").*?(?="")", RegexOptions.Singleline);
if (res != null && res.Count > 0)
{
token = res[1].ToString();
}
return token;
}
string GetVTCToken(string html)
{
string token = "";
var res = Regex.Matches(html, @"(?<=__RequestVerificationToken"" type=""hidden"" value="").*?(?="")", RegexOptions.Singleline);
if (res != null && res.Count > 0)
{
token = res[0].ToString();
}
return token;
}
string GetThayTrucTuyenToken(string html)
{
string token = "";
var res = Regex.Matches(html, @"(?<=__RequestVerificationToken"" type=""hidden"" value="").*?(?="")", RegexOptions.Singleline);
if (res != null && res.Count > 0)
{
token = res[0].ToString();
}
return token;
}
string PostData(HttpRequest http, string url, string data = null, string contentType = null, string userArgent = "", string cookie = null)
{
if (http == null)
{
http = new HttpRequest();
http.Cookies = new CookieDictionary();
}
if (!string.IsNullOrEmpty(cookie))
{
AddCookie(http, cookie);
}
if (!string.IsNullOrEmpty(userArgent))
{
http.UserAgent = userArgent;
}
string html = http.Post(url, data, contentType).ToString();
return html;
}
string UploadData(HttpRequest http, string url, MultipartContent data = null, string contentType = null, string userArgent = "", string cookie = null)
{
if (http == null)
{
http = new HttpRequest();
http.Cookies = new CookieDictionary();
}
if (!string.IsNullOrEmpty(cookie))
{
AddCookie(http, cookie);
}
if (!string.IsNullOrEmpty(userArgent))
{
http.UserAgent = userArgent;
}
string html = http.Post(url, data).ToString();
return html;
}
void UploadFile(string path)
{
MultipartContent data = new MultipartContent() {
{ new StringContent("dzuuid"), "cf45eb6a-834d-44f0-af1e-c6056ae1cc47"},
{ new StringContent("dzchunkindex"), "0"},
{ new StringContent("dztotalfilesize"), "134355"},
{ new StringContent("dzchunksize"), "26143000"},
{ new StringContent("dztotalchunkcount"), "1"},
{ new StringContent("dzchunkbyteoffset"), "0"},
{ new FileContent(path), "file", Path.GetFileName(path)}
};
var html = UploadData(null, "https://up.uploadfiles.io/upload", data);
var dataRes = JsonConvert.DeserializeObject<UploadFileModel>(html);
Process.Start(dataRes.destination);
}
string ResloveNormalCaptcha(string captchaKey, string imgBase64)
{
string capt = "";
Recaptcha_2Captcha reCapt = new Recaptcha_2Captcha(captchaKey);
bool isSuccess = reCapt.SolveNormalCapcha(imgBase64, out capt);
while (!isSuccess)
{
isSuccess = reCapt.SolveNormalCapcha(imgBase64, out capt);
Thread.Sleep(TimeSpan.FromSeconds(2));
}
return capt;
}
string Reslove2CaptchaCaptcha(string captchaKey, string ggKey, string url)
{
string capt = "";
Recaptcha_2Captcha reCapt = new Recaptcha_2Captcha(captchaKey);
bool isSuccess = reCapt.SolveRecaptchaV2(ggKey, url, out capt);
while (!isSuccess)
{
isSuccess = reCapt.SolveRecaptchaV2(ggKey, url, out capt);
Thread.Sleep(TimeSpan.FromSeconds(2));
}
return capt;
}
#endregion
void UploadFile()
{
OpenFileDialog dialog = new OpenFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
UploadFile(dialog.FileName);
}
}
private void button1_Click(object sender, EventArgs e)
{
var html = GetData("https://www.howkteam.com/");
TestData(html);
}
void TestData(string html)
{
File.WriteAllText("res.html", html);
Process.Start("res.html");
}
private void button2_Click(object sender, EventArgs e)
{
string cookie = "";
var html = GetData("https://www.howkteam.com/", null, null, cookie);
TestData(html);
}
private void button3_Click(object sender, EventArgs e)
{
HttpRequest http = new HttpRequest();
http.Cookies = new CookieDictionary();
string userArgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36";
var html = GetData("https://www.howkteam.vn", http, userArgent);
string token = GetLoginDataToken(html);
string userName = "kteamts@gmail.com";
string password = "Test123@";
string data = "__RequestVerificationToken=" + token + "&Email=" + WebUtility.UrlEncode(userName) + "&Password=" + WebUtility.UrlEncode(password) + "&RememberMe=true&RememberMe=false";
html = PostData(http, "https://www.howkteam.vn/account/login?returnUrl=https%3A%2F%2Fwww.howkteam.vn%2F", data, "application/x-www-form-urlencoded; charset=UTF-8").ToString();
html = GetData("https://www.howkteam.vn", http, userArgent);
File.WriteAllText("res.html", html);
Process.Start("res.html");
}
private void button4_Click(object sender, EventArgs e)
{
UploadFile();
}
private void button5_Click(object sender, EventArgs e)
{
HttpRequest http = new HttpRequest();
http.Cookies = new CookieDictionary();
string userArgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36";
var html = GetData("https://vtcgame.vn/nap-vcoin/qua-the-cao.html", http, userArgent);
string token = GetVTCToken(html);
string userName = "rongk9";
string serial = "54356432132434";
string code = "fdsfdsfdseswfdsfs";
var binImg = http.Get("https://vtcgame.vn//CaptchaImage.ashx?ss=0.56879455647683&w=60&h=40").ToMemoryStream().ToArray();
File.WriteAllBytes("Captcha.jpg",binImg);
string captcha = ResloveNormalCaptcha(textBox1.Text, Convert.ToBase64String(binImg));
string data = "__RequestVerificationToken=" + token + "&typeCard=VC&seriCard=" + serial + "&codeCard=" + code + "&userNameReceive=" + userName + "&captcha=" + captcha + "&captchaVerify=";
html = PostData(http, "https://vtcgame.vn/Vcoin/TopupByCard", data, "application/x-www-form-urlencoded; charset=UTF-8").ToString();
VTCChargeResponseModel resData = JsonConvert.DeserializeObject<VTCChargeResponseModel>(html);
MessageBox.Show(resData.ErorrMess);
}
private void button6_Click(object sender, EventArgs e)
{
HttpRequest http = new HttpRequest();
http.Cookies = new CookieDictionary();
string userArgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36";
var html = GetData("http://thaytructuyen.com/Account/Login", http, userArgent);
string token = GetThayTrucTuyenToken(html);
string userName = "rongk9";
string password = "dsadae2dasd";
string ggKey = "6Lf57BcUAAAAABST6IWjYd97ghC3v2kKsCfPNrdg";
string captchaURL = "http://thaytructuyen.com/Account/Login";
string captcha = Reslove2CaptchaCaptcha(textBox1.Text, ggKey, captchaURL);
string data = "__RequestVerificationToken="+token+"&UserName="+userName+"&Password="+password+"&g-recaptcha-response="+captcha+"&RememberMe=false";
html = PostData(http, "http://thaytructuyen.com/Account/Login", data, "application/x-www-form-urlencoded; charset=UTF-8").ToString();
TestData(html);
}
private void button7_Click(object sender, EventArgs e)
{
Mail.Verify(textBox2.Text, textBox3.Text, "imap.one.com", 993);
}
}
public class VTCChargeResponseModel
{
public int ResponseStatus { get; set; }
public string ErorrMess { get; set; }
}
public class UploadFileModel
{
public bool status { get; set; }
public int id { get; set; }
public string url { get; set; }
public string destination { get; set; }
public string name { get; set; }
public string filename { get; set; }
public string slug { get; set; }
public string size { get; set; }
public string type { get; set; }
public string expiry { get; set; }
public string session_id { get; set; }
public string timing { get; set; }
}
public class Recaptcha_2Captcha
{
public string APIKey { get; private set; }
public Recaptcha_2Captcha(string apiKey)
{
APIKey = apiKey;
}
public bool SolveRecaptchaV2(string googleKey, string pageUrl, out string result)
{
string requestUrl = "http://2captcha.com/in.php?key=" + APIKey + "&method=userrecaptcha&googlekey=" + googleKey + "&pageurl=" + pageUrl;
try
{
WebRequest req = WebRequest.Create(requestUrl);
using (WebResponse resp = req.GetResponse())
using (StreamReader read = new StreamReader(resp.GetResponseStream()))
{
string response = read.ReadToEnd();
if (response.Length < 3)
{
result = response;
return false;
}
else
{
if (response.Substring(0, 3) == "OK|")
{
string captchaID = response.Remove(0, 3);
for (int i = 0; i < 24; i++)
{
WebRequest getAnswer = WebRequest.Create("http://2captcha.com/res.php?key=" + APIKey + "&action=get&id=" + captchaID);
using (WebResponse answerResp = getAnswer.GetResponse())
using (StreamReader answerStream = new StreamReader(answerResp.GetResponseStream()))
{
string answerResponse = answerStream.ReadToEnd();
if (answerResponse.Length < 3)
{
result = answerResponse;
return false;
}
else
{
if (answerResponse.Substring(0, 3) == "OK|")
{
result = answerResponse.Remove(0, 3);
return true;
}
else if (answerResponse != "CAPCHA_NOT_READY")
{
result = answerResponse;
return false;
}
}
}
Thread.Sleep(5000);
}
result = "Timeout";
return false;
}
else
{
result = response;
return false;
}
}
}
}
catch { }
result = "Unknown error";
return false;
}
public bool SolveNormalCapcha(string base64Image, out string result)
{
string response = "";
using (var client = new WebClient())
{
var values = new NameValueCollection();
values["method"] = "base64";
values["key"] = APIKey;
values["body"] = base64Image;
var res = client.UploadValues("http://2captcha.com/in.php", values);
response = Encoding.Default.GetString(res);
}
Thread.Sleep(TimeSpan.FromSeconds(5));
if (response.Substring(0, 3) == "OK|")
{
string captchaID = response.Remove(0, 3);
for (int i = 0; i < 24; i++)
{
WebRequest getAnswer = WebRequest.Create("http://2captcha.com/res.php?key=" + APIKey + "&action=get&id=" + captchaID);
using (WebResponse answerResp = getAnswer.GetResponse())
using (StreamReader answerStream = new StreamReader(answerResp.GetResponseStream()))
{
string answerResponse = answerStream.ReadToEnd();
if (answerResponse.Length < 3)
{
result = answerResponse;
return false;
}
else
{
if (answerResponse.Substring(0, 3) == "OK|")
{
result = answerResponse.Remove(0, 3);
return true;
}
else if (answerResponse != "CAPCHA_NOT_READY")
{
result = answerResponse;
return false;
}
}
}
Thread.Sleep(5000);
}
result = "Timeout";
return false;
}
else
{
result = response;
return false;
}
}
}
public static class Mail
{
public static void Verify(string email, string pass, string ipmap, int port)
{
string url = null;
using (ImapClient ic = new ImapClient())
{
ic.Connect(ipmap, port, true, false);
ic.Login(email, pass);
ic.SelectMailbox("INBOX");
int mailcount;
for (mailcount = ic.GetMessageCount(); mailcount < 2; mailcount = ic.GetMessageCount())
{
Mail.Delay(5);
ic.SelectMailbox("INBOX");
}
MailMessage[] mm = ic.GetMessages(mailcount - 1, mailcount - 1, false, false);
MailMessage[] array = mm;
for (int j = 0; j < array.Length; j++)
{
MailMessage i = array[j];
{
string sbody = i.Body;
url = Regex.Match(i.Body, "a href=\"(https:[^\"]+)").Groups[1].Value;
bool flag2 = string.IsNullOrEmpty(url);
if (flag2)
{
url = Regex.Match(i.Body, "(http.*)").Groups[1].Value.Trim();
url = url.Substring(0,url.IndexOf('"'));
}
break;
}
}
ic.Dispose();
}
HttpRequest rq = new HttpRequest();
rq.Cookies = new CookieDictionary(false);
rq.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36";
bool Load = false;
while (!Load)
{
try
{
rq.Get(url, null);
Load = true;
}
catch (Exception)
{
}
}
}
private static void Delay(int time)
{
for (int i = 0; i < time; i++)
{
Thread.Sleep(time);
}
}
}
}
Chào howkteam , khi mình nhập email của yahoo hay gmail vào trong webmail https://login.one.com/mail thì không có mail nào đăng nhập được và luôn hiện thông báo "The email or password you entered is incorrect. Please try again.".
Xin cho hỏi mình khắc phục như thế nào. Chân thành cảm ơn howkteam