Article

← Retour au blog

🇫🇷 Lire en français

Analyzing an HTTP connection between a Nokia 6600 and a production Apache server

2008-06-04 #831 · rév. 1 · EN

I have come across an issue with one phone that is not handling cookies correctly. In order to understand where the bug was — either the Nokia 6600 or our server — I needed to trace the Apache response header sent by my service http://m.mobiluck.com. I wanted to check the Set-Cookie headers.

First of all, looking at Apache’s trace feature didn’t give me much help; I basically found nothing.

I turned to a low-level tool, tcpdump: this is a tool that enables root to capture any UDP/TCP packets right from the network interface of the server.

Installing tcpdump is pretty easy on Debian; just do the following:

$ apt-get install tcpdump

I was most interested in capturing the HTTP protocol. But our production server handles hundreds of thousands of user communications, so we must filter the right connection out of all this “mess”.

Looking at the Apache log, you can easily find the IP of the Bouygues Telecom GSM gateway; in our case it was: 80.214.249.18

As I am interested in the HTTP protocol only, I filtered this by using the “port http” option.

Here is the command line I used to capture the HTTP communication:

tcpdump "port http and (src host 80.214.249.18 or dst host 80.214.249.18)" -s 0 -A -w nokia6600ascii.txt

The “-s 0″ option tells tcpdump not to truncate packets. The “-w <filename>” option just asks tcpdump to write the capture to the specified file. And the “-A” option tells it to format the dump in ASCII.

As a result, I got the following capture:
<pre>
<code>
$more nokia6600ascii.txt

?ò???|QFHެFF?NF?ӣ*E8?@2?]P??[y“P0?P??O?`NP
?J|QFH?FF^L??NE8@@??[yP??P“W??0?P??Я?
Gb`?J}QFH?8^LBB?NF?ӣ*E4?@2?`P??[y“P0?P?W???O?|?
Gb`~QFH8NF?ӣ*Ex?@2?[y“P0?P?W???O??j
??Gb`GET /?page=intro&channel=Buzz-Flirt-IN-testmcs HTTP/1.1
Host: m.mobiluck.com
Accept: audio/wav, audio/x-wav, audio/basic, audio/x-au, audio/au, audio/x-basic, video/mp4, video/mpeg4,
video/3gpp, application/vnd.rn-realmedia, audio/AMR-WB, audio/AMR, application/sdp, audio/sp-midi, audi
o/x-beatnik-rmf, audio/midi, application/java-archive, text/vnd.sun.j2me.app-descriptor, application/vnd.wap.wmlc,
text/vnd.wap.wml, application/vnd.wap.wbxml, application/vnd.wap.wmlscriptc, text/html, applic
ation/vnd.wap.xhtml+xml, application/xhtml+xml, , application/x-wallet-appl.user-data-provision, application/vnd.met.ticket,
application/vnd.symbian.install, audio/x-pn-realaudio-plugin, audio/x-pn-realaudio, audio/mpegurl, audio/x-mpegurl, text/x-co-desc, application/vnd.oma.dd+xml, application/vnd.nokia.ringing-tone, text/vnd.symbian.wml.dtd, application/java, video/3gp, audio/rmf, audio/x-rmf, audio/x-midi, application/x-java-archive, application/vnd.oma.drm.message,
application/x-x509-ca-cert, text/plain, text/X-vCard, text/calendar, text/x-vCalendar, text/css, image/*
Accept-Charset: iso-8859-1, utf-8, iso-10646-ucs-2; q=0.6
Accept-Encoding: gzip;q=1.0, identity; q=0.8
Accept-Language: fr
Cookie: PHPSESSID=40551094df2c98748c211e7ddb053b73
Cookie2:
User-Agent: Nokia6600/1.0 (4.09.1) SymbianOS/7.0s Series60/2.0 Profile/MIDP-2.0 C~QFHJ?BB^L??NEH@@{?[yP??P“W??0?V6??i,
Gb??~QFHp????NF?ӣ*E??@2?
P??[y“P0?V6W???O?.?
??Gb`onfiguration/CLDC-1.0
Profile: “http://nds1.nds.nokia.com/uaprof/N6600r100.xml”

~QFHy?BB^L??NEI@@{?[yP??P“W??0?V???h?
Gb??~QFH?xx^L??NEJ@@v?[yP??P“W??0?V????
Gb??HTTP/1.1 302 Found
Date: Wed, 04 Jun 2008 08:25:34 GMT
Server: Apache
P3P: CP=”IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT“
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: nbvisit=1; expires=Fri, 04-Jul-2008 08:25:34 GMT; path=/; domain=m.mobiluck.com
Set-Cookie: lastvisit=1212567934; expires=Fri, 04-Jul-2008 08:25:34 GMT; path=/; domain=m.mobiluck.com
Set-Cookie: rigoler=-1; expires=Fri, 04-Jul-2008 08:25:34 GMT; path=/; domain=m.mobiluck.com
Set-Cookie: AB_ID=1212567934-2213; expires=Fri, 04-Jul-2008 08:25:34 GMT; path=/; domain=m.mobiluck.com
Set-Cookie: AB_firstvisit=1212567934; expires=Fri, 04-Jul-2008 08:25:34 GMT; path=/; domain=m.mobiluck.com
Set-Cookie: AB_nbofvisit=1; expires=Fri, 04-Jul-2008 08:25:34 GMT; path=/; domain=m.mobiluck.com
Set-Cookie: AB_lastvisit=1212567934; expires=Fri, 04-Jul-2008 08:25:34 GMT; path=/; domain=m.mobiluck.com
Set-Cookie: AB_color=gray; expires=Fri, 04-Jul-2008 08:25:34 GMT; path=/; domain=m.mobiluck.com
Location: /?tapeshdah=40551094df2c98748c211e7ddb053b73&redirect=intro&channel=Buzz-Flirt-IN-testmcs&&sdlredirfrom=intro
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 27
Content-Type: text/html
</code>
</pre>

Note that in the dump there are still some binary characters not filtered out by the -A option, but those characters don’t prevent us from reading the HTTP code.

As you can see, we’ve got the Set-Cookie headers that show the server has the right behavior.

Should we conclude that this phone with the given firmware mishandles the HTTP protocol?

Looking further at the dump, I noticed that the PHPSESSID was correctly handled by the client. So why? This cookie was written without any expiration date:

Set-Cookie: PHPSESSID=c407903eb49ce37939be4758962edf09; path=/

This is odd. I then modified my own cookies, now passing them without an expiration date, and guess what… It works!

Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Set-Cookie: lastvisit=1212570224; path=/ Set-Cookie: rigoler=-1; path=/ Set-Cookie: AB_nbofvisit=2; path=/ Set-Cookie: AB_lastvisit=1212570224; path=/

And the next request from the phone had my cookies:

Cookie: PHPSESSID=f26738a51499297134b51e8e8195a59a; nbvisit=1; lastvisit=1212lZF3BB^L??NE4?@@?@[yP??P??? V??????g? Ge?Đ'1(lZFH^dd?NF?ӣ*EV?@2?;P??[y??P???? VƀO??} ?'1(Ge?T570218; AB_ID=1212570218-bdad; AB_firstvisit=1212570218; AB_nbofvisit=1; AB_lastvisit=1212570218; AB_color=reset

Looking at the RFC didn’t tell me whether I did something wrong. If you know why, tell me in the comments section.