public void transferSession(C_Session session) { var driverService = ChromeDriverService.CreateDefaultService(); driverService.HideCommandPromptWindow = true; IWebDriver _driver = new ChromeDriver(driverService); _driver.Navigate().GoToUrl("https://www.google.com/"); // navigate to google so captcha solving isn't slow when passed the splash WaitForPageLoad(_driver, 15); Profile profile = profiles.FirstOrDefault(x => !String.IsNullOrEmpty(x.SplashUrl)); _driver.Navigate().GoToUrl(profile.SplashUrl); WaitForPageLoad(_driver, 30); foreach (C_Cookie cookie in session.cookies) { _driver.Manage().Cookies.AddCookie(new OpenQA.Selenium.Cookie(cookie.name, cookie.value, cookie.domain, "/", cookie.expiry)); } IJavaScriptExecutor js = _driver as IJavaScriptExecutor; js.ExecuteScript(String.Format("var source = '{0}';document.write(source);document.close();", session.source.Replace(System.Environment.NewLine, "").Replace("'", "\"").Replace("<script>", "<scr' + 'ipt>").Replace("<script ", "<scr' + 'ipt ").Replace("</script>", "</scr' + 'ipt>"))); }
private void transferSession_Click(Object sender, System.EventArgs e) { int index = currentMouseOverRow2; C_Session session = helpers.sessionlist[index]; helpers.transferSession(session); }
private void runSession(Profile profile, int index, DataGridViewRow row) { C_Session session = sessionlist[index]; session.index = index; row.Cells[8].Value = "Setting up..."; string pipename = Process.GetCurrentProcess().Id.ToString() + "_session_" + index.ToString(); var pipe = new NamedPipeServerStream(pipename, PipeDirection.InOut, 1); System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new ProcessStartInfo(); process.StartInfo.FileName = "3s_atc - browser.exe"; process.StartInfo.Arguments = profile.SplashUrl + " " + pipename + " " + Properties.Settings.Default.splashidentifier + " " + Properties.Settings.Default.productpageidentifier + " " + Properties.Settings.Default.refresh_interval.ToString() + " " + gmail_loggedin.ToString(); process.Start(); session.pid = process.Id; pipe.WaitForConnection(); session.hideShow(); try { StreamWriter writer = new StreamWriter(pipe); if (gmail_loggedin) { string gmailCookiesData = SerializeCefCookies(gmail_cookies); writer.WriteLine(gmailCookiesData); writer.Flush(); } string sessionData = SerializeSession(session); writer.WriteLine(sessionData); writer.Flush(); StreamReader reader = new StreamReader(pipe); while (true) { string str = reader.ReadLine(); if (!String.IsNullOrEmpty(str)) { parseMessage(index, str, row); } } } catch (IOException exception) { MessageBox.Show(String.Format("Session {0} error: {1}\n", index.ToString(), exception.Message)); } }
private void sessionInfo_Click(Object sender, System.EventArgs e) { int index = currentMouseOverRow2; C_Session session = helpers.sessionlist[index]; string infos = "Press CTRL+C to copy :\n\nHMAC Cookie : Name=" + session.hmac_cookie.name + " Value=" + session.hmac_cookie.value + "\nSitekey: " + session.sitekey + "\nClient ID: " + session.clientid + "\nDuplicate: " + session.duplicate; MessageBox.Show(infos, "Session info", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private string cartSplash(Profile profile, DataGridViewCell cell, DataGridViewRowCollection rows) { cell.Value = "Waiting for HMAC...(check settings page)"; C_Proxy proxy = null; C_Session session = null; if (!proxy_running && profile.splashmode == 1) { Task.Run(() => runProxyList(profile, rows)); while (proxylist.FirstOrDefault(s => proxy.passed) == null) { System.Threading.Thread.Sleep(1000); } cell.Value = "GOT HMAC!"; proxy = proxylist.FirstOrDefault(s => proxy.passed && s.hmac_cookie.expiry > DateTime.Now); } else if (!sessions_running && profile.splashmode == 2) { for (int i = 0; i < Properties.Settings.Default.sessions_count; i++) { sessionlist.Add(new C_Session { refresh = false }); } for (int i = 0; i < Properties.Settings.Default.r_sessions_count; i++) { sessionlist.Add(new C_Session { refresh = true }); } rows.Clear(); foreach (C_Session s in sessionlist) { rows.Add(new string[] { "session", s.refresh.ToString(), "False", null, null, null, null, null, null }); } Task.Run(() => runSessionList(profile, rows)); while (sessionlist.FirstOrDefault(x => x.passed == true) == null) { System.Threading.Thread.Sleep(1000); } cell.Value = "GOT HMAC!"; session = sessionlist.FirstOrDefault(s => s.passed && s.hmac_cookie.expiry > DateTime.Now); } return(cartNoSplash(profile, cell, proxy, session)); }
public void guestMode_Cart(Profile profile, DataGridViewRowCollection rows) { C_Proxy proxy = null; C_Session session = null; if (!proxy_running && profile.splashmode == 1) { Task.Run(() => runProxyList(profile, rows)); while (proxylist.FirstOrDefault(s => proxy.passed) == null) { System.Threading.Thread.Sleep(1000); } proxy = proxylist.FirstOrDefault(s => proxy.passed && s.hmac_cookie.expiry > DateTime.Now); MessageBox.Show("proxy_" + proxy.index.ToString() + " : on product page! Right click on the session and show the window in order to purchase the shoe!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (!sessions_running && profile.splashmode == 2) { for (int i = 0; i < Properties.Settings.Default.sessions_count; i++) { sessionlist.Add(new C_Session { refresh = false }); } for (int i = 0; i < Properties.Settings.Default.r_sessions_count; i++) { sessionlist.Add(new C_Session { refresh = true }); } rows.Clear(); foreach (C_Session s in sessionlist) { rows.Add(new string[] { "session_" + s.index.ToString(), s.refresh.ToString(), "False", null, null, null, null, null, null }); } Task.Run(() => runSessionList(profile, rows)); while (sessionlist.FirstOrDefault(x => x.passed == true) == null) { System.Threading.Thread.Sleep(1000); } session = sessionlist.FirstOrDefault(s => s.passed == true); MessageBox.Show("session_" + session.index.ToString() + " : on product page! Right click on the session and show the window in order to purchase the shoe!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private string SerializeSession(C_Session data) { System.Xml.Serialization.XmlSerializer xsSubmit = new System.Xml.Serialization.XmlSerializer(typeof(C_Session)); var xml = ""; using (var sww = new StringWriter()) { using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(sww)) { xsSubmit.Serialize(writer, data); xml = sww.ToString(); } } return(xml); }
private string webRequestPost(Profile profile, string url, Dictionary <string, string> post, C_Proxy proxy = null, C_Session session = null) { string postData = ""; foreach (string key in post.Keys) { postData += HttpUtility.UrlEncode(key) + "=" + HttpUtility.UrlEncode(post[key]) + "&"; } HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(url); webRequest.Method = "POST"; webRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"; if (profile.splashmode > 0) { webRequest.Referer = profile.SplashUrl; } else { webRequest.Referer = String.Format("http://www.{0}/", Properties.Settings.Default.locale); } if (proxy != null) { WebProxy webproxy = new WebProxy(proxy.address); if (proxy.auth) { webproxy.Credentials = new NetworkCredential(proxy.username, proxy.password); } webRequest.Proxy = webproxy; } byte[] data = Encoding.ASCII.GetBytes(postData); webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.ContentLength = data.Length; CookieContainer cookies = new CookieContainer(); List <C_Cookie> c_cookies; if (profiles.FirstOrDefault(x => x.Email == profile.Email && x.loggedin) != null) { c_cookies = profiles.FirstOrDefault(x => x.Email == profile.Email).Cookies; } else { c_cookies = profile.Cookies; } foreach (C_Cookie cookie in c_cookies) { cookies.Add(new System.Net.Cookie(cookie.name, cookie.value) { Domain = cookie.domain }); } if (proxy != null) { foreach (C_Cookie cookie in proxy.cookies) { cookies.Add(new System.Net.Cookie(cookie.name, cookie.value) { Domain = cookie.domain }); } } else if (session != null) { foreach (C_Cookie cookie in session.cookies) { cookies.Add(new System.Net.Cookie(cookie.name, cookie.value) { Domain = cookie.domain }); } } webRequest.CookieContainer = cookies; Stream requestStream = webRequest.GetRequestStream(); requestStream.Write(data, 0, data.Length); requestStream.Close(); HttpWebResponse myHttpWebResponse = (HttpWebResponse)webRequest.GetResponse(); Stream responseStream = myHttpWebResponse.GetResponseStream(); StreamReader myStreamReader = new StreamReader(responseStream, Encoding.Default); string pageContent = myStreamReader.ReadToEnd(); myStreamReader.Close(); responseStream.Close(); myHttpWebResponse.Close(); return(pageContent); }
private string cartNoSplash(Profile profile, DataGridViewCell cell, C_Proxy proxy = null, C_Session session = null) { Dictionary <string, string> post = new Dictionary <string, string>(); string atcURL; if (profile.clientid && !String.IsNullOrWhiteSpace(profile.ClientID)) { atcURL = "http://www." + Properties.Settings.Default.locale + "/on/demandware.store/Sites-adidas-" + Properties.Settings.Default.code + "-Site/" + marketsList[Properties.Settings.Default.code] + "/Cart-MiniAddProduct?clientId=" + profile.ClientID; } else { atcURL = "http://www." + Properties.Settings.Default.locale + "/on/demandware.store/Sites-adidas-" + Properties.Settings.Default.code + "-Site/" + marketsList[Properties.Settings.Default.code] + "/Cart-MiniAddProduct"; } string result = null; if (proxy != null) { profile.Sitekey = proxy.sitekey; profile.captcha = true; profile.ClientID = proxy.clientid; profile.clientid = true; profile.Duplicate = proxy.duplicate; profile.duplicate = true; } else if (session != null) { profile.Sitekey = session.sitekey; profile.captcha = true; profile.ClientID = session.clientid; profile.clientid = true; profile.Duplicate = session.duplicate; profile.duplicate = true; } if (!profile.loggedin) { Task.Run(() => login(profile, cell, proxy)); } if (profile.loggedin) { if (profile.captcha && !String.IsNullOrWhiteSpace(profile.Sitekey)) { cell.Value = "SOLVE CAPTCHA!"; cell.Style = new DataGridViewCellStyle { ForeColor = Color.Red }; while (captchas.FirstOrDefault(s => s.sitekey.Contains(profile.Sitekey) && s.expiration > DateTime.Now) == null) { System.Threading.Thread.Sleep(1000); } C_Captcha captcha = captchas.FirstOrDefault(s => s.sitekey.Contains(profile.Sitekey) && s.expiration > DateTime.Now && s.profileID == profile.index && !String.IsNullOrEmpty(s.response)); post.Add("g-recaptcha-response", captcha.response); if (profile.duplicate && !String.IsNullOrWhiteSpace(profile.Duplicate)) { post.Add(profile.Duplicate, captcha.response); } captchas.Remove(captcha); } cell.Value = "Checking sizes..."; cell.Style = new DataGridViewCellStyle { ForeColor = Color.Empty }; string size = getFirstAvailableSize(profile.Sizes, profile.ProductID, profile.ClientID, profile.splashmode); if (size == null) { return("No sizes available"); } cell.Value = "Adding to cart..."; post.Add("pid", size); post.Add("masterPid", profile.ProductID); post.Add("Quantity", "1"); post.Add("request", "ajax"); post.Add("responseformat", "json"); post.Add("sessionSelectedStoreID", "null"); post.Add("layer", "Add To Bag overlay"); result = webRequestPost(profile, atcURL, post, proxy, session); } return(result); }
private void runSession(Profile profile, C_Session session, DataGridViewRow row) { row.Cells[8].Value = "Setting up..."; IWebDriver _driver = createNewJSDriver(); _driver.Navigate().GoToUrl(profile.SplashUrl); if (ElementDisplayed(_driver, /*By.CssSelector(".message.message-1.hidden")*/ By.ClassName("sk-fading-circle"), 120)) { row.Cells[8].Value = "On splash page..."; while (_driver.FindElements(By.ClassName("g-recaptcha")).Count == 0) { if (session.refresh) { refreshDriver(_driver); } else { System.Threading.Thread.Sleep(2000); } } row.Cells[8].Value = "Splash page passed!"; row.Cells[8].Style = new DataGridViewCellStyle { ForeColor = System.Drawing.Color.Green }; session.source = _driver.PageSource; string cookie_name = null; if (_driver.Manage().Cookies.AllCookies.FirstOrDefault(s => s.Value.Contains("hmac")) != null) { cookie_name = _driver.Manage().Cookies.AllCookies.FirstOrDefault(s => s.Value.Contains("hmac")).Name; session.hmac = _driver.Manage().Cookies.AllCookies.FirstOrDefault(s => s.Value.Contains("hmac")).Value; session.hmac_expiration = _driver.Manage().Cookies.AllCookies.FirstOrDefault(s => s.Value.Contains("hmac")).Expiry; row.Cells[4].Value = session.hmac; } if (_driver.FindElements(By.ClassName("g-recaptcha")).Count > 0) { session.sitekey = _driver.FindElement(By.ClassName("g-recaptcha")).GetAttribute("data-sitekey"); row.Cells[5].Value = session.sitekey; } if (_driver.FindElements(By.Id("flashproductform")).Count > 0) { session.clientid = _driver.FindElement(By.Id("flashproductform")).GetAttribute("action").Split(new string[] { "clientId=" }, StringSplitOptions.None)[1]; row.Cells[6].Value = session.clientid; } if (_driver.FindElements(By.XPath("//link[@rel='canonical']")).Count > 0) { session.duplicate = getDuplicate(_driver.PageSource, _driver.FindElement(By.XPath("//link[@rel='canonical']")).GetAttribute("href")); row.Cells[7].Value = session.duplicate; } row.Cells[8].Value = "HMAC and Sitekey retrieved!"; foreach (OpenQA.Selenium.Cookie cookie in _driver.Manage().Cookies.AllCookies) { if (cookie.Domain.Contains("adidas")) { session.cookies.Add(new C_Cookie { name = cookie.Name, value = cookie.Value, domain = cookie.Domain, expiry = cookie.Expiry }); } } session.passed = true; File.AppendAllText("logs.txt", String.Format("Session / Cookie --- Name: {0} --- Value : {1} / Sitekey: {2} / Client ID : {3} / Duplicate : {4}", cookie_name, session.hmac, session.sitekey, session.clientid, session.duplicate) + Environment.NewLine); File.WriteAllText(String.Format("{0}\\{1}_productpage_source.txt", AppDomain.CurrentDomain.BaseDirectory, profile.ProductID), _driver.PageSource); _driver.Quit(); } else { row.Cells[8].Value = "Error!"; row.Cells[8].Style = new DataGridViewCellStyle { ForeColor = System.Drawing.Color.Red }; _driver.Quit(); } }