sábado, 2 de agosto de 2008

[ALL] change of plans/cambio de planes/Änderung der Pläne

[EN]

It seems that the guys from MSN are doing some weird changes on the MSN servers that makes that protocols previous to MSNP15 have problems authenticating, so the next posts will be about MSNP15 and its changes, it will take some time since I need to learn the changes.

[ES]

Parece que los muchachos de MSN estan haciendo algunos cambios raros en los servers de MSN que hace que las versiones de protocolo anteriores a MSNP15 tengan problemas autenticandose, asi que los proximos posts seran sobre MSNP15 y sus cambios, me va a tomar un tiempo debido a que necesito aprender los cambios.

[DE]


Es scheint, dass die Leute von MSN ein Paar Änderungen in MSN Servers gemacht haben, das bedeutet, dass alle die Protokoll-Versionen vor MSNP15 Problemen mit die Authentifizierung haben, so die nächste Posts werden über MSNP15 und ihre Änderungen sein, es wird einige Zeit in Anspruch nehmen weil ich diese Änderungen lernen muss.

[ES] introduccion al protocolo

En este primer post voy a cubrir la parte basica que se necesita saber para hablar con el server de MSN.

En una sesion normal se deben hacer requests a diferentes servers, pero una coneccion es basica y debe mantenerse activa
a traves de toda la sesion, esa coneccion es mantenida con el servidor de notificacion (NS) , inicialmente la coneccion
es realizada con el host messenger.hotmail.com en el puerto 1863 y es administrada a traves de comandos escritos en
texto plano.

Estos comandos tienen el siguiente formato

Command transaction_id [param1 param2 ... paramN] [payload_size]\r\n
[payload_body]

* command es generalmente una palabra de 3 letras como VER, MSG etc.
* transaction_id es un numero que representa el orden del comando, comienza con 1 y es incrementado cada vez que un comando se envia. Cuando se envia una respuesta a un comando enviado por el server, se debe establecer el tid (abreviacion de transaction_id de ahora en adelante) al valor que envio el server. Algunos comandos ponen otro contenido
como segundo parametro, pero son solo pocas excepciones.
* un numero de parametros opcionales separadas por un espacio vienen a continuacion, el numero de parametros depende del comando. Pueden contener cualquier informacion que sea util para el comando.
* payload_size es el numero de bytes (tamaño) del payload, el cual viene despues de \r\n (el payload existe solo en
comandos especificos como por ejemplo, GCF, MSG y otros..
* payload es el contenido del cuerpo del comando y contiene informacion referida al comando.

Dejemos de hablar y vamos a ponernos manos a la obra, enviemos el primer comando al server.
Para hacer este post una introduccion, solo voy a usar netcat, el proximo post va a explicar sockets en python los cuales son solo un wrapper sobre los sockets en C asi que es simple seguirlo para programadores de cualquier lenguaje.

para empezar, abri una terminal y tipea

$ netcat messenger.hotmail.com 1863[enter]

luego de ese comando, se va a ver una linea en blanco y nada mas, eso significa que estamos conectados con el server, a continuacion, ahora escribi:

VER 1 MSNP13 CVR0[enter]

y vas a obtener:

VER 1 MSNP13 CVR0

(el ultimo caracter es un cero)

que significa? es el primer mensaje al server y su respuesta, el comando es una introduccion y le dice al server algo como "Hola, deseo iniciar una nueva sesion, hablo la version 13 del protocolo (MSNP13)", entonces el server nos responde lo mismo, eso significa que habla la misma version, asi podemos continuar.

se puede enviar mas de una version y el server respondera las versiones que prefiere, solo le enviamos la version 13 del protocolo, pero aca hay un ejemplo con multiples versiones:

enviemosle 3 versiones

mariano@mousehouse:~$ netcat messenger.hotmail.com 1863
VER 1 MSNP13 MSNP14 MSNP15 CVR0
VER 1 MSNP15 MSNP14 MSNP13 CVR0

parece que prefiere MSNP15 :D

veamos por donde andan los desarrolladores de MSN

mariano@mousehouse:~$ netcat messenger.hotmail.com 1863
VER 1 MSNP13 MSNP14 MSNP15 MSNP16 MSNP17 CVR0
VER 1 MSNP17 MSNP16 MSNP15 MSNP14 MSNP13 CVR0

MSNP17?!? :D

veamos mas...

mariano@mousehouse:~$ netcat messenger.hotmail.com 1863
VER 1 MSNP13 MSNP14 MSNP15 MSNP16 MSNP17 MSNP18 CVR0
VER 1 MSNP17 MSNP16 MSNP15 MSNP14 MSNP13 CVR0

no, solo MSNP17

solo para que veas mas comandos, voy a enviar comandos extra que seran explicados luego.

nos conectamos de nuevo con el server y le enviamos algunos comandos.

mariano@mousehouse:~$ netcat messenger.hotmail.com 1863
VER 1 MSNP13 CVR0
VER 1 MSNP13 CVR0
CVR 2 0x0c0a winnt 5.1 i386 MSNMSGR 8.0.0792 msmsgs xmxsxn@hotmail.com
CVR 2 8.1.0178 8.1.0178 8.1.0178 http://msgruser.dlservice.microsoft.com/download/5/6/4/5646481F-33EF-4B08-AF00-4904F7677B89/ES/Install_WLMessenger.exe http://get.live.com/es
USR 3 TWN I xmxsxn@hotmail.com
XFR 3 NS 207.46.110.94:1863 U D

veamoslo por comando

>>> son mensajes enviados
<<< son mensajes recibidos

>>> VER 1 MSNP13 CVR0
<<< VER 1 MSNP13 CVR0

VER es igual a la explicacion anterior

>>> CVR 2 0x0c0a winnt 5.1 i386 MSNMSGR 8.0.0792 msmsgs xmxsxn@hotmail.com
<<< CVR 2 8.1.0178 8.1.0178 8.1.0178 http://msgruser.dlservice.microsoft.com/download/5/6/4/5646481F-33EF-4B08-AF00-4904F7677B89/ES/Install_WLMessenger.exe http://get.live.com/es

con el comando CVR enviamos nuestra informacion de version al servidor:

* 0x0c0a es un conjunto de banderas que indican nuestras capacidades, voy a explicar esto luego, pero con las banderas que envio aca se puede seguir desarrollando sin nungun problema.
* "winnt i386" es nuestro sistema operativo :D
* 8.0.0792 es la version de nuestro cliente ;)
* el ultimo campo es la cuenta con la cual nos estamos intentando conectar (esa cuenta es mi cuenta de pruebas)

recibimos una respuesta que no es muy util, luego nos presentamos, obtenemos una respuesta y somos desconectados (volvemos a la consola)

>>> USR 3 TWN I xmxsxn@hotmail.com
<<< XFR 3 NS 207.46.110.94:1863 U D

XFR es el comando de transferencia, y significa que el server quiere que nos conectemos con otro server ubicado en 207.46.110.94:1863

entonces corremos netcat de nuevo apuntando al nuevo servidor, y hacemos todo de nuevo

mariano@mousehouse:~$ netcat 207.46.110.94 1863
VER 1 MSNP13 CVR0
VER 1 MSNP13 CVR0
CVR 2 0x0c0a winnt 5.1 i386 MSNMSGR 8.0.0792 msmsgs xmxsxn@hotmail.com
CVR 2 8.1.0178 8.1.0178 8.1.0178 http://msgruser.dlservice.microsoft.com/download/5/6/4/5646481F-33EF-4B08-AF00-4904F7677B89/ES/Install_WLMessenger.exe http://get.live.com/es
USR 3 TWN I xmxsxn@hotmail.com

hasta aca todo es como antes, pero ahora no nos transfiere (podemos obtener mas de una transferencia, pero hoy tenemos suerte)

entonces recibimos
<<< GCF 0 6660

el comando GCF con payload_size en 6660 y despues recibimos 6660 bytes de xml que basicamente dicen que palabras debemos filtrar en el cliente (que lindo :P)

<<< GCF 0 6660
[mucho xml va aca]
<<< USR 3 TWN S ct=1216861501,rver=5.5.4177.0,wp=FS_40SEC_0_COMPACT,lc=1033,id=507,ru=http:%2F%2Fmessenger.msn.com,tw=0,kpp=1,kv=4,ver=2.1.6000.1,rn=1lgjBfIL,tpf=b0735e3a873dfb5e75054465095398e0

el ultimo comando sera usado luego para la autenticacion passport.

ok, eso es todo por hoy, la proxima vez voy a escribir sobre como hacerlo en python (y quizas otro lenguaje tambien)

miércoles, 23 de julio de 2008

[EN] Protocol introduction

In this first post I will cover the first part you need to know to talk to the MSN server.

In a normal session you will make requests to different servers, but one connection is basic and must be active through all the session, that is a connection with the Notification Server (NS), this connection is a socket connection initially made with the host messenger.hotmail.com on the port 1863, this connection is managed through commands written in plain ascii.

This commands have the following format

Command transaction_id [param1 param2 ... paramN] [payload_size]\r\n
[payload_body]

* command is generally a 3 letter word like VER, MSG etc.
* transaction_id is a number that represent the order of this command, start with the number 1 and is increased every time you send a new command. When you send a response to a command sent by the server you must set the tid (transaction_id for short from now on) to the number that the server sent. Some commands put other content as second parameter, but they are just a few exceptions.
* a number of optional parameters separated by a space come next and the number depends on the command. They can contain anything that may be useful for the command
* payload_size is the number of bytes of the payload that comes after the \r\n (the payload exists only on commands that contain payload like GCF, MSG and others..
* payload is the content of the command and can be anything that the command wants to send us.

Lets stop talking and get some action, lets send our first command to the server.
To make this post an introduction, I will just use netcat, the next post will teach you about sockets on python (they are a wrapper over C sockets so it's easy to follow for programmers of other languages).

open a terminal and write

$ netcat messenger.hotmail.com 1863[enter]

you will see a new line and nothing more, that means that you are connected to the server, now write:

VER 1 MSNP13 CVR0[enter]

then you will get:

VER 1 MSNP13 CVR0

(the last key is a zero)

what does it mean? that is the first message to the server and its response, the command is an introduction and says to the server something like "Hi i want to start a session, I speak the version 13 of the protocol (MSNP13)", then the server response is the same, that means that he speak that version, so we can continue.

you can send more than one version and he will return the version he prefers, we will just use the version 13 of the protocol, but here is an example of multiple versions:

lets send him 3 versions

mariano@mousehouse:~$ netcat messenger.hotmail.com 1863
VER 1 MSNP13 MSNP14 MSNP15 CVR0
VER 1 MSNP15 MSNP14 MSNP13 CVR0

seems that he prefers MSNP15 :D

lets see where are the MSN guys going

mariano@mousehouse:~$ netcat messenger.hotmail.com 1863
VER 1 MSNP13 MSNP14 MSNP15 MSNP16 MSNP17 CVR0
VER 1 MSNP17 MSNP16 MSNP15 MSNP14 MSNP13 CVR0

MSNP17?!? :D

even further...

mariano@mousehouse:~$ netcat messenger.hotmail.com 1863
VER 1 MSNP13 MSNP14 MSNP15 MSNP16 MSNP17 MSNP18 CVR0
VER 1 MSNP17 MSNP16 MSNP15 MSNP14 MSNP13 CVR0

nope, just MSNP17

just for you to see some more commands I will send some extra commands that will be explained later when we start a session using a programming language.

connect again with the server and send some commands

mariano@mousehouse:~$ netcat messenger.hotmail.com 1863
VER 1 MSNP13 CVR0
VER 1 MSNP13 CVR0
CVR 2 0x0c0a winnt 5.1 i386 MSNMSGR 8.0.0792 msmsgs xmxsxn@hotmail.com
CVR 2 8.1.0178 8.1.0178 8.1.0178 http://msgruser.dlservice.microsoft.com/download/5/6/4/5646481F-33EF-4B08-AF00-4904F7677B89/ES/Install_WLMessenger.exe http://get.live.com/es
USR 3 TWN I xmxsxn@hotmail.com
XFR 3 NS 207.46.110.94:1863 U D

lets see this by command

>>> are messages being sent
<<< are messages being received

>>> VER 1 MSNP13 CVR0
<<< VER 1 MSNP13 CVR0

VER is the same as before

>>> CVR 2 0x0c0a winnt 5.1 i386 MSNMSGR 8.0.0792 msmsgs xmxsxn@hotmail.com
<<< CVR 2 8.1.0178 8.1.0178 8.1.0178 http://msgruser.dlservice.microsoft.com/download/5/6/4/5646481F-33EF-4B08-AF00-4904F7677B89/ES/Install_WLMessenger.exe http://get.live.com/es

with the CVR command we send our version information to the server:

* 0x0c0a is a set of flags that indicate our capabilities, I will explain that later, with that flags you can keep coding without problem.
* "winnt i386" is our operating system :D
* 8.0.0792 is our client version ;)
* and the last one is the account we are trying to log in (that account is my test account)

we receive a response that is not really usefull, then we present ourselves, and get a response and we get disconnected (we get the shell again)

>>> USR 3 TWN I xmxsxn@hotmail.com
<<< XFR 3 NS 207.46.110.94:1863 U D

XFR is the transfer command, and means that the server wants us to connect to the server located at 207.46.110.94:1863

so we start netcat again pointing at that server, and do it all over again

mariano@mousehouse:~$ netcat 207.46.110.94 1863
VER 1 MSNP13 CVR0
VER 1 MSNP13 CVR0
CVR 2 0x0c0a winnt 5.1 i386 MSNMSGR 8.0.0792 msmsgs xmxsxn@hotmail.com
CVR 2 8.1.0178 8.1.0178 8.1.0178 http://msgruser.dlservice.microsoft.com/download/5/6/4/5646481F-33EF-4B08-AF00-4904F7677B89/ES/Install_WLMessenger.exe http://get.live.com/es
USR 3 TWN I xmxsxn@hotmail.com

until here all is like before but now we don't get a transfer (we can get more than one, but today we are lucky)

then we get
<<< GCF 0 6660

we receive the GCF command, with the payload_size 6660 and next we get 6660 bytes of xml that basically say which words we should filter on our client (nice :P)

<<< GCF 0 6660
[a lot of xml goes here]
<<< USR 3 TWN S ct=1216861501,rver=5.5.4177.0,wp=FS_40SEC_0_COMPACT,lc=1033,id=507,ru=http:%2F%2Fmessenger.msn.com,tw=0,kpp=1,kv=4,ver=2.1.6000.1,rn=1lgjBfIL,tpf=b0735e3a873dfb5e75054465095398e0

the last command will later be used to do the passport authentication.

ok, that's all for today, the next time I will write about how to do it with python code (maybe another language will be used too) wait for the translations on the weekend maybe :P

[DE] Erste Post!

Hallo!, diese ist meine Erste Post auf diese Blog, dass es zu lehren ist, wie man schreiben Sie Ihre eigene Bibliothek zur Interaktion mit dem MSN-Messenger-Netzwerk, die Gründe hinter diesem Blog sind:


  • Jemand hat mir bei Mail gefragt um ihn eine eigene Bibliothek zu bauen helfen mit ein Programmier Sprache die ich nicht kenne.
  • Hilfe diese Protokoll zu dokumentieren.
  • Hilfe dir lernen, wie Netzwerk Programme zu Programmieren.
  • Hilfe mir mein Deutsch zu verbessern (Ich hoffe dass jemand hilft mir diese Post zu korrigieren).
  • Hilfe Leute dass emesene helfen möchten (mein andere Projekt www.emesene.org).
  • Vielleicht ein Paar Münze verdienen durch adsense :P
Die Beispiele werden auf python geschrieben, es ist eine saubere Programmiersprache dass du lesen kannst ohne es zu kennen (jemand sagt dass es interpretiert Pseudocode :P)
Ich hoffe dass du diese blog befolgen und dass du auf deine bevorzugte Programmiersprache schreiben kannst!.

siehe den Kommentar-Link? benutze es, es ist hilfreich :P

[ES] Primer post!

Hola, este es el primer post (en castellano) de un blog que esta hecho con la intención de enseñar como escribir tu propia librería para interactuar con la red MSN Messenger, las razones detrás de este blog son:

  • Alguien me pidió por mail que lo ayude a crear una librería en un lenguaje que no conozco
  • Ayudar a documentar el protocolo
  • Ayudar a que aprendas como codificar cosas relacionadas con redes
  • Ayudarme a mejorar mi aleman (voy a poner traducciones al aleman, espero que algun aleman me ayude a corregir los horrores :D)
  • Ayudar a gente que quiere colaborar con emesene (mi otro proyecto www.emesene.org)
  • Quizas tener algunos centavos a traves de adsense :P

Los ejemplos serán provistos en python, es un lenguaje limpio y puede ser leido incluso si no sabes programar en el (alguien dice que es pseudocodigo interpretado :P)

Espero que sigan este blog y provean implementaciones en su lenguaje preferido!

Ven el link de comentarios? usenlo, es util :P

[EN] First post!

Hi, this is the first post of a blog that is intended to teach you how to write your own library to interact with the MSN Messenger network, the reasons behind this blog are:

  • Someone asked me by mail to help him to build a library on a language that I don't know
  • Help to document this protocol
  • Help you to learn how to code network stuff
  • Help me improve my german (I will provide german translations, I hope that some german will help me correct my horrors :D)
  • Help people that want to help emesene (my other project www.emesene.org)
  • maybe get some cents through adsense :P
The examples will be provided in python, it's a clean language and can be read even if you don't know it (someone says it's interpreted pseudocode :P)

I hope that you follow this blog and provide implementations in your favourite language!

see the comment link? use it, it's helpful :P