We will first focus on what exactly cookies are and how they work.
It
would be easy for you to understand the test cases for testing cookies
when you have clear understanding of how cookies work?
How cookies
stored on hard drive?
And how can we edit cookie settings?
What is Cookie?
Cookie is small information stored in text file on user’s hard drive by
web server. This information is later used by web browser to retrieve
information from that machine. Generally cookie contains personalized
user data or information that is used to communicate between different
web pages.
Why Cookies are used?
Cookies are nothing but the user’s identity and used to track where the
user navigated throughout the web site pages. The communication between
web browser and web server is stateless.
For example if you are accessing domain http://www.example.com/1.html
then web browser will simply query to example.com web server for the
page 1.html. Next time if you type page as http://www.example.com/2.html
then new request is send to example.com web server for sending 2.html
page and web server don’t know anything about to whom the previous page
1.html served.
What if you want the previous history of this user communication with
the web server? You need to maintain the user state and interaction
between web browser and web server somewhere. This is where cookie comes
into picture. Cookies serve the purpose of maintaining the user
interactions with web server.
How cookies work?
The HTTP protocol used to exchange information files on the web is used
to maintain the cookies. There are two types of HTTP protocol. Stateless
HTTP and Stateful HTTP protocol. Stateless HTTP protocol does not keep
any record of previously accessed web page history. While Stateful HTTP
protocol do keep some history of previous web browser and web server
interactions and this protocol is used by cookies to maintain the user
interactions.
Whenever user visits the site or page that is using cookie, small
code inside that HTML page (Generally a call to some language script to
write the cookie like cookies in JAVAScript, PHP, Perl) writes a text
file on users machine called cookie.
Here is one example of the code that is used to write cookie and can be placed inside any HTML page:
Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME;
When user visits the same page or domain later time this cookie is
read from disk and used to identify the second visit of the same user on
that domain. Expiration time is set while writing the cookie. This time
is decided by the application that is going to use the cookie.
Generally two types of cookies are written on user machine.
1) Session cookies: This cookie is active till the
browser that invoked the cookie is open. When we close the browser this
session cookie gets deleted. Some time session of say 20 minutes can be
set to expire the cookie.
2) Persistent cookies: The cookies that are written permanently on user machine and lasts for months or years.
Where cookies are stored?
When any web page application writes cookie it get saved in a text file
on user hard disk drive. The path where the cookies get stored depends
on the browser. Different browsers store cookie in different paths. E.g.
Internet explorer store cookies on path “C:\Documents and Settings\Default User\Cookies”
Here the “Default User” can be replaced by the current user you logged
in as. Like “Administrator”, or user name like “Vijay” etc.
The cookie path can be easily found by navigating through the browser
options. In Mozilla Firefox browser you can even see the cookies in
browser options itself. Open the Mozila browser, click on
Tools->Options->Privacy and then “Show cookies” button.
How cookies are stored?
Lets take example of cookie written by rediff.com on Mozilla Firefox browser:
On Mozilla Firefox browser when you open the page rediff.com or login to
your rediffmail account, a cookie will get written on your Hard disk.
To view this cookie simply click on “Show cookies” button mentioned on
above path. Click on Rediff.com site under this cookie list. You can see
different cookies written by rediff domain with different names.
Site: Rediff.com Cookie name: RMID
Name: RMID (Name of the cookie)
Content: 1d11c8ec44bf49e0… (Encrypted content)
Domain: .rediff.com
Path: / (Any path after the domain name)
Send For: Any type of connection
Expires: Thursday, December 31, 2020 11:59:59 PM
Applications where cookies can be used:
1) To implement shopping cart:
Cookies are used for maintaining online ordering system. Cookies
remember what user wants to buy. What if user adds some products in
their shopping cart and if due to some reason user don’t want to buy
those products this time and closes the browser window? When next time
same user visits the purchase page he can see all the products he added
in shopping cart in his last visit.
2) Personalized sites:
When user visits certain pages they are asked which pages they don’t
want to visit or display. User options are get stored in cookie and till
the user is online, those pages are not shown to him.
3) User tracking:
To track number of unique visitors online at particular time.
4) Marketing:
Some companies use cookies to display advertisements on user machines.
Cookies control these advertisements. When and which advertisement
should be shown? What is the interest of the user? Which keywords he
searches on the site? All these things can be maintained using cookies.
5) User sessions:
Cookies can track user sessions to particular domain using user ID and password.
Drawbacks of cookies:
1) Even writing Cookie is a great way to maintain
user interaction, if user has set browser options to warn before writing
any cookie or disabled the cookies completely then site containing
cookie will be completely disabled and can not perform any operation
resulting in loss of site traffic.
2) Too many Cookies:
If you are writing too many cookies on every page navigation and if user
has turned on option to warn before writing cookie, this could turn
away user from your site.
3) Security issues:
Some times users personal information is stored in cookies and if
someone hack the cookie then hacker can get access to your personal
information. Even corrupted cookies can be read by different domains and
lead to security issues.
------------
4) Sensitive information:
Some sites may write and store your sensitive information in cookies, which should not be allowed due to privacy concerns.
This should be enough to know what cookies are.
Some Major Test cases for web application cookie testing:
The first obvious test case is to test if your application is writing cookies properly on disk. You can use the Cookie Tester application also if you don’t have any web application to test but you want to understand the cookie concept for testing.
Security Test cases:
1) As a Cookie privacy policy make sure from your design documents that no personal or sensitive data is stored in the cookie.
2) If you have no option than saving sensitive data in cookie make sure data stored in cookie is stored in encrypted format.
3) Make sure that there is no overuse of cookies
on your site under test. Overuse of cookies will annoy users if browser
is prompting for cookies more often and this could result in loss of
site traffic and eventually loss of business.
4) Disable the cookies from your browser settings:
If you are using cookies on your site, your sites major functionality
will not work by disabling the cookies. Then try to access the web site
under test. Navigate through the site. See if appropriate messages are
displayed to user like “For smooth functioning of this site make sure
that cookies are enabled on your browser”. There should not be any page
crash due to disabling the cookies. (Please make sure that you close all
browsers, delete all previously written cookies before performing this
test)
5) Accepts/Reject some cookies: The best way to
check web site functionality is, not to accept all cookies. If you are
writing 10 cookies in your web application then randomly accept some
cookies say accept 5 and reject 5 cookies. For executing this test case
you can set browser options to prompt whenever cookie is being written
to disk. On this prompt window you can either accept or reject cookie.
Try to access major functionality of web site. See if pages are getting
crashed or data is getting corrupted.
6) Delete cookie: Allow site to write the cookies
and then close all browsers and manually delete all cookies for web site
under test. Access the web pages and check the behavior of the pages.
7) Corrupt the cookies: Corrupting cookie is easy.
You know where cookies are stored. Manually edit the cookie in notepad
and change the parameters to some vague values. Like alter the cookie
content, Name of the cookie or expiry date of the cookie and see the
site functionality. In some cases corrupted cookies allow to read the
data inside it for any other domain. This should not happen in case of
your web site cookies. Note that the cookies written by one domain say
rediff.com can’t be accessed by other domain say yahoo.com unless and
until the cookies are corrupted and someone trying to hack the cookie
data.
8 ) Checking the deletion of cookies from your web application page:
Some times cookie written by domain say rediff.com may be deleted by
same domain but by different page under that domain. This is the general
case if you are testing some ‘action tracking’ web portal. Action
tracking or purchase tracking pixel is placed on the action web page and
when any action or purchase occurs by user the cookie written on disk
get deleted to avoid multiple action logging from same cookie. Check if
reaching to your action or purchase page deletes the cookie properly and
no more invalid actions or purchase get logged from same user.
9) Cookie Testing on Multiple browsers: This is the
important case to check if your web application page is writing the
cookies properly on different browsers as intended and site works
properly using these cookies. You can test your web application on Major
used browsers like Internet explorer (Various versions), Mozilla
Firefox, Netscape, Opera etc.
10) If your web application is using cookies to maintain the logging state of any user
then log in to your web application using some username and password.
In many cases you can see the logged in user ID parameter directly in
browser address bar. Change this parameter to different value say if
previous user ID is 100 then make it 101 and press enter. The proper
access message should be displayed to user and user should not be able
to see other users account.
These are some Major test cases to be considered while testing
website cookies. You can write multiple test cases from these test cases
by performing various combinations. If you have some different
application scenario, you can mention your test cases in comments below.
Description:
Session Fixation is an attack that permits an attacker to hijack a
valid user session. The attack explores a limitation in the way the web
application manages the session ID, more specifically the vulnerable web
application. When authenticating a user, it doesn’t assign a new
session ID, making it possible to use an existent session ID. The attack
consists of obtaining a valid session ID (e.g. by connecting to the
application), inducing a user to authenticate himself with that session
ID, and then hijacking the user-validated session by the knowledge of
the used session ID. The attacker has to provide a legitimate Web
application session ID and try to make the victim's browser use it.
The session fixation attack is a class of Session Hijacking,
which steals the established session between the client and the Web
Server after the user logs in. Instead, the Session Fixation attack
fixes an established session on the victim's browser, so the attack
starts before the user logs in.
There are several techniques to execute the attack; it depends on
how the Web application deals with session tokens. Below are some of
the most common techniques:
• Session token in the URL argument:
The Session ID is sent to the victim in a hyperlink and the victim accesses the site through the malicious URL.
• Session token in a hidden form field:
In this method, the victim must be tricked to authenticate in the target
Web Server, using a login form developed for the attacker. The form
could be hosted in the evil web server or directly in html formatted
e-mail.
• Session ID in a cookie:
o Client-side script
Most browsers support the execution of client-side scripting. In
this case, the aggressor could use attacks of code injection as the XSS
(Cross-site scripting) attack to insert a malicious code in the
hyperlink sent to the victim and fix a Session ID in its cookie. Using
the function document.cookie, the browser which executes the command
becomes capable of fixing values inside of the cookie that it will use
to keep a session between the client and the Web Application.
o <META> tag
<META> tag also is considered a code injection attack,
however, different from the XSS attack where undesirable scripts can be
disabled, or the execution can be denied. The attack using this method
becomes much more efficient because it's impossible to disable the
processing of these tags in the browsers.
o HTTP header response
This method explores the server response to fix the Session ID in
the victim's browser. Including the parameter Set-Cookie in the HTTP
header response, the attacker is able to insert the value of Session ID
in the cookie and sends it to the victim's browser.
Example 1
The example below explains a simple form, the process of the attack, and the expected results.
(1)The attacker has to establish a legitimate connection with the
web server which (2) issues a session ID or, the attacker can create a
new session with the proposed session ID, then, (3) the attacker has to
send a link with the established session ID to the victim, she has to
click on the link sent from the attacker accessing the site, (4) the Web
Server saw that session was already established and a new one need not
to be created, (5) the victim provides his credentials to the Web
Server, (6) knowing the session ID, the attacker can access the user's
account.
Figure 1. Simple example of Session Fixation attack.
---------------------------------------Thanks to OWASP--------------------------------------
Mobile banking is very convenient, allowing users to access their
bank account and manage their finances without actually visiting the
bank. Unfortunately, mobile banking apps are a constant target
for hackers. A recent blog post from Lookout reveals a cloned banking app that targets user logins was recently at large in the Google Play app store.
A Wolf in Sheep's Clothing
The malware is called
BankMirage. It works by wrapping itself around a bank's original app,
which in this case was the Israeli bank Mizrahi Bank. Attackers then
successfully uploaded the app to the Google Play store. When customers
opened the app, they would be instructed to enter their login
information at which point the malware grabs the user's ID. After
entering the correct information, the user then gets an error message
saying their login was incorrect and to install the real app from Google
Play.
The interesting part about BankMirage is that it only steals the user
ID. Perhaps the hackers already have a huge cache of passwords and only
need the user IDs or that BankMirage is the foundation for a round of
very targeted phishing attacks in the future. Another plausible scenario
is that the creators of BankMirage plan to sell their stack of IDs to
other hackers for a price, further increasing the risk of a compromised
bank account.
"At this point, it's still very curious even to us why the authors
would only want to collect the usernames and not passwords," said Meghan
Kelly, Security Communications Manager at Lookout. "However, it could
be that they were testing the app's functionality before moving forward
in development."
Fool Me Twice
The process of stealing login information is nothing new. The Zeus Trojan,
which targets sensitive banking information and email accounts,
returned last year. There are many variations of the program, which
makes sense when considering that BankMirage's tactics are used by other
malware programs.
Another banking Trojan called WroBa.D
not only takes login information, but is also capable of intercepting
SMS messages. This allows hackers to potentially get the authorization
code before users have a chance to see it, giving hackers complete
access to a bank account. The malware has seven variants and targets six
banks in South Korea, and disguises itself on devices as a fake Google
Play app.
South Korea is an appropriate target because its citizens have been using mobile banking applications since 2000. In 2008, 22.8 trillion won
or the equivalent of $22.5 billion was exchanged through online
banking. Mobile devices accounted for 151 billion won or $149 million of
those transactions.
Prevention
The terrifying part about the malware
is that it exists inside Google Play. We always recommend that our
readers only download apps from Google Play, but as this malware and past experience shows, it's still possible for malicious software to make their way into the Google Play store.
Lookout advises concerned readers to use their best judgement when
downloading apps. Check to see if the banking app has a duplicate app
and determine which one is the real deal. Be on the lookout for spelling
errors, which usually indicates that the app is up to no good. For
example WroBa.D utilizes the Google Play icon, but name below the icon
reads as "googl app stoy."
Use APKTool to Decompile, Edit, Translate and Recompile an APK
APKTool is an application which decompiles and recompiles android APKs. If you know what you are doing, it also allows you to debug the smali code step by step. In our case it will enable us to build a language pack by translating the .xml strings inside APK files.
This tutorial is for the Windows version of APKtool.
The Google.Code page for APKTool is here, however, we have prepackaged everything you need and uploaded it here
The Video Tutorial is Below:
The Supplementary guide to common errors in APKTool is below:
You need to do the following preparations (the video outlines these steps anyway):
- Download the prepackaged APKTool zip.
- Extract them to a directory you will remember.
- Extract framework-res.apk AND apk files you want to decompile from the MIUI_Au ROM and copy them to the root directory of APKTool.
This step must be completed every time you are dealing with APKTool:
- Open a command window
- Navigate to the root directory of APKtool and type the following command:
apktool if framework-res.apk
The output should be:
I: Framework installed to: C:\Users\Josh\apktool\framework\1.apk
This step does the actual decompiling of the APK (I will assume that the chosen APK is Settings.apk):
apktool d Settings.apk
The output should be:
I: Loading resource table…
I: Decoding resources…
I: Copying assets and libs…
After doing that, a new directory with the name of the APK you decompiled should have been created. You need to:
- Change into the newly created directory.
- Change into the /res folder
- Check to see if a values-xx folder exists, where xx is the
two letter code of the target language to be translated into. For
example, if you are aiming to translate into German, check for a values-de folder.
If it does not exist (and chances are that if you are translating into a
new language, that it will not exist), you need to create it. Then,
copy the arrays.xml and strings.xml files from the /values folder into the folder you just created.
- Open these two files (in Notepad ++) and alter the strings (the text in BLACK ONLY). Look out for things that look like %d and %s /’ - Don’t edit these, as they are variables. Also, if you see &, it represents the ‘&’ sign, so feel free to change it. Finally, you MUST be sure to place a backslash ‘\’ before an apostrophe, for example Proxy\’s would be the equivalent of Proxy’s.
- Once you have translated and edited your arrays.xml and strings.xml
files, save them, and return to the root directory of APKTool.
- Open a command prompt to that directory
Enter the following command to recompile your edited and translated APK (assuming that Settings.apk is the chosen APK):
apktool b Settings
The output should be:
I: Checking whether sources has changed…
I: Smaling…
I: Checking whether resources has changed…
I: Building resources…
I: Building apk file…
You may get a couple of these messages:
aapt: warning: string ‘app_killed_message’ has no default translation in C:\Users\Josh\Desktop\NF\framework-res\res; found: fr it ja
aapt: warning: string ‘global_action_reboot’ has no default translation in C:\Users\Josh\Desktop\NF\framework-res\res; found: fr it ja
aapt: warning: string ‘reboot_system’ has no default translation in C:\Users\Josh\Desktop\NF\framework-res\res; found: fr it ja
aapt: warning: string ‘toast_reboot_recommend’ has no default translation in C:\Users\Josh\Desktop\NF\framework-res
However, it will build the apk anyway. These messages mean that some
strings don’t have values. It is only an issues if the text im blue
includes your translation language.
Once that is done, two directories will have been created within the
decompilation directory. One will be called “dist”, and this is where it
will place a built, but not signed, apk file. The other one is called
“build”, and here it will place everything “loose” (the contents of the
APK).
I have trouble using the APK files it spits out in the /dist folder (
they force closes if they are an application, or bootloop it a
framework-res.apk; I think the reason is because Android will not accept
APK files that are not signed). Instead, copy the resources.arsc from
the /build directory into the original framework-res from the rom (just overwrite the old resources.arsc one with the new one).
This tutorial is for the Windows version of APKtool.