PDA

View Full Version : Cookie Help



npm
12-22-2016, 11:37 AM
Background:

So Im doing some neopets programs again (will upload them soon), they're pretty good IMO.
Im testing new stuff and I've been using HtmlUnit and Selenium, but im having problems with the cookies.

Im able to get and save the cookies and Im even able to read them and login in sucessfully with it but for some reason the cookies seems to be expired fast 4-5 page refreshes and I cant login again with them even when the neoremeber cookie has an expiration date of a year or so.

Im thinking rn that the problem is that Selenium nor HtmlUnit retrieve all the cookies, Im printing them on the console to see what's going on and got the following cookies:

lang
ssotoken
neoremember
neologin
np_randseed
toolbar
np_uniq_username
np_uniq
npuid
np_uniq_


Im aware that are a few others that are involved but im not getting all of them, but I can login in with these cookies a few times but not for the expiration time of the neoremember cookie. any toughs? do I need all of them to make it work properly? Thanks in advance.
[Only registered and activated users can see links]

Daviid
12-22-2016, 12:03 PM
Background:

So Im doing some neopets programs again (will upload them soon), they're pretty good IMO.
Im testing new stuff and I've been using HtmlUnit and Selenium, but im having problems with the cookies.

Im able to get and save the cookies and Im even able to read them and login in sucessfully with it but for some reason the cookies seems to be expired fast 4-5 page refreshes and I cant login again with them even when the neoremeber cookie has an expiration date of a year or so.

Im thinking rn that the problem is that Selenium nor HtmlUnit retrieve all the cookies, Im printing them on the console to see what's going on and got the follow cookies:
lang
ssotoken
neoremember
neologin
np_randseed
toolbar
np_uniq_username
np_uniq
npuid
np_uniq_


Im aware that are a few others that are involved but im not getting all of them, but I can login in with these cookies a few times but not for the expiration time of the neoremember cookie. any toughs? do I need all of them to make it work properly? Thanks in advance.
[Only registered and activated users can see links]

Can you send me a snippet of the code that logins, and browses some random pages? I'll see what I can find.

Edit:
It's weird that you don't get PHPSESSID. There's also another cookie that's like random letters and numbers, I always get the same so it should be important.

npm
12-22-2016, 12:27 PM
Can you send me a snippet of the code that logins, and browses some random pages? I'll see what I can find.




Map<String, String> cookies = null;

public Map<String, String> getCookies(){
return this.cookies;
}

public setCookies(Map<String, String> cookies){
this.cookies = cookies;
}

public void _perform$Login(){
driver.get("[Only registered and activated users can see links]");

driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
List<WebElement> example = driver.findElements(By.cssSelector(".user.medText > a"));
example.get(0).click();

driver.findElement(By.name("username")).sendKeys("username");
driver.findElement(By.name("password")).sendKeys("password");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElements(By.cssSelector("input[type='submit']")).get(0).click();

if(driver.findElement(By.id("npanchor")).isDisplayed()){
_log("success");
setCookies(driver.cookies);
save_cookie(); // === working good as _loadCookie() is login in succesfully a few times and its only wrote once.
}
}

public void _login(){
if(!_validCookie) _perform$Login();
else _log(" valid cookie");
}

public boolean _validCookie(){
Map<String, String> cookie = _loadCookie(); // working good as is able to log in and shows the cookies properly.
if(cookie == null) return false;
else{
// remove driver instance for saving space.
driver.get("[Only registered and activated users can see links]");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
loop(cookie){
driver.manage().addCookie(cookie.key, cookie.value);
}
print driver.manage().cookies(); // ======= cookies are set properly.

driver.navigateTo("[Only registered and activated users can see links]"); //== working properly a few times.

return (driver.findElement(By.id("npanchor")).isDisplayed()); // valid cookie.
}

}

public void someTask(){
driver.get("[Only registered and activated users can see links]");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
loop(getCookies()){
driver.manage().addCookie(cookie.key, cookie.value);
}
print driver.manage().cookies(); // ======= cookies are set properly.

driver.navigateTo("[Only registered and activated users can see links]"); //== cookies are expired after a few times.
}



Have the code at home, im at work right now but wrote that pseudo as I remember my code.

EDIT: It might be the PHPSESSID not sure why its not been retrieve by neither of the two API.

Daviid
12-22-2016, 01:01 PM
Map<String, String> cookies = null;

public Map<String, String> getCookies(){
return this.cookies;
}

public setCookies(Map<String, String> cookies){
this.cookies = cookies;
}

public void _perform$Login(){
driver.get("[Only registered and activated users can see links]");

driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
List<WebElement> example = driver.findElements(By.cssSelector(".user.medText > a"));
example.get(0).click();

driver.findElement(By.name("username")).sendKeys("username");
driver.findElement(By.name("password")).sendKeys("password");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElements(By.cssSelector("input[type='submit']")).get(0).click();

if(driver.findElement(By.id("npanchor")).isDisplayed()){
_log("success");
setCookies(driver.cookies);
save_cookie(); // === working good as _loadCookie() is login in succesfully a few times and its only wrote once.
}
}

public void _login(){
if(!_validCookie) _perform$Login();
else _log(" valid cookie");
}

public boolean _validCookie(){
Map<String, String> cookie = _loadCookie(); // working good as is able to log in and shows the cookies properly.
if(cookie == null) return false;
else{
// remove driver instance for saving space.
driver.get("[Only registered and activated users can see links]");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
loop(cookie){
driver.manage().addCookie(cookie.key, cookie.value);
}
print driver.manage().cookies(); // ======= cookies are set properly.

driver.navigateTo("[Only registered and activated users can see links]"); //== working properly a few times.

return (driver.findElement(By.id("npanchor")).isDisplayed()); // valid cookie.
}

}

public void someTask(){
driver.get("[Only registered and activated users can see links]");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
loop(getCookies()){
driver.manage().addCookie(cookie.key, cookie.value);
}
print driver.manage().cookies(); // ======= cookies are set properly.

driver.navigateTo("[Only registered and activated users can see links]"); //== cookies are expired after a few times.
}



Have the code at home, im at work right now but wrote that pseudo as I remember my code.

EDIT: It might be the PHPSESSID not sure why its not been retrieve by neither of the two API.

Seems good to me, if you can send me the code later I'll try monitoring with Charles Proxy to see what's going on.

Accelerator
12-22-2016, 03:46 PM
Haven't tested which are the exact cookies needed for a session to "keep-alive" (LOL) but these are the ones I use:
np_randseed, neologin, PHPSESSID, xt6Yr4e33D, ssotoken, toolbar and "npuid"
You're missing two of 'em and I doubt the toolbar one is relevant from the ones in the spoiler.
There's one that changes its value every time you refresh or visit a page (can't remember which one it is right now though e_e)

npm
12-22-2016, 04:00 PM
[Only registered and activated users can see links]

and the cookie that changes every time is: npuid/

[Only registered and activated users can see links]


EDIT: You must spread some Reputation around before giving it to Accelerator again. Remember me to do it later dude.

Accelerator
12-22-2016, 04:09 PM
hectorvazc dw about it man :)

Zachafer
12-28-2016, 03:14 AM
hectorvazc ideally you should be storing all cookies that are set by Set-Cookie in the HTTP Response. Remember the goal is to remain undetected and a foundational piece of this is emulate a browser's HTTP requests exactly
Accelerator the neologin cookie value is what keeps you logged into Neo
Daviid the PHPSESSID is the PHP identifier of the $_SESSION array and other session variables stored on the Neo server for the current user's session

npm
12-28-2016, 07:27 AM
@hectorvazc ([Only registered and activated users can see links]) ideally you should be storing all cookies that are set by Set-Cookie in the HTTP Response. Remember the goal is to remain undetected and a foundational piece of this is emulate a browser's HTTP requests exactly

Thanks, right now im even updating and saving my cookies as per every request so the cookies are exactly as the browser behavior.
My problem was assuming I was getting all the cookies from the beginning.