Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program wsBrowser;
- {$APPTYPE CONSOLE}
- uses
- WinSock, xutils, xsock, WinInet;
- const
- CRLF = #13#10;
- var
- lpWSAData: TWSAData;
- lpSocket: TSocket;
- lpSockAddr: TSockAddr;
- strHost, strUser, strPassword, strUserUrlEncoded, sRecv, sRecvTWN, authString: String;
- procedure ShowUsage;
- begin
- Writeln('----------------------------------------------------------------');
- Writeln('- MSN Connect by Alice -');
- Writeln('- Usage: <server> <user> <password> -');
- Writeln('----------------------------------------------------------------');
- end;
- procedure ExitApplication(ErrorCode: Integer; Description: String);
- begin
- if (lpSocket > 0) then
- closesocket(lpSocket);
- WSACleanup;
- if (ErrorCode <> 0) then
- begin
- Writeln('Function: ' + Description);
- Writeln('Error code: ' + IntToHex(ErrorCode, 8));
- Halt(ErrorCode);
- end;
- end;
- procedure SentMessages(S: String);
- begin
- Writeln('>>> ' + S);
- end;
- procedure RecvMessages(S: String);
- begin
- Writeln('<<< ' + S);
- end;
- procedure SendAuthentication(s: TSocket; var lpSrvReceived: String);
- begin
- SendSocketText(s, 'VER 0 MSNP8 CVR0' + CRLF, 0, @SentMessages);
- lpSrvReceived := ReceiveSocketText(s, 0, @RecvMessages);
- if ((Pos('VER', lpSrvReceived) > 0) and (Pos('MSNP8', lpSrvReceived) > 0)) then
- SendSocketText(s, 'CVR 1 0x0409 win 4.10 i386 MSNMSGR 5.0.0544 ' +
- 'MSMSGS ' + strUser + CRLF, 0, @SentMessages);
- lpSrvReceived := ReceiveSocketText(s, 0, @RecvMessages);
- if (Pos('CVR 1', lpSrvReceived) > 0) then
- SendSocketText(s, 'USR 2 TWN I ' + strUser + CRLF, 0, @SentMessages);
- lpSrvReceived := ReceiveSocketText(s, 0, @RecvMessages);
- end;
- procedure ConnectTo(var s: TSocket; var lpSockAddr: TSockAddr; Host: String; Port: Word);
- begin
- if not (GetHost(Host, Port, AF_INET, lpSockAddr)) then
- ExitApplication(2, 'GetHost');
- if not (GetSock(PF_INET, SOCK_STREAM, IPPROTO_IP, s)) then
- ExitApplication(3, 'GetSock');
- if (connect(s, lpSockAddr, SizeOf(lpSockAddr)) <> 0) then
- begin
- Writeln(IntToStr(WSAGetLastError));
- ExitApplication(4, 'connect');
- end;
- end;
- procedure SendHTTPS(Host, Target, Headers: String; Port: Word; var lpSrvreceived: String;
- EventProc: Pointer);
- var
- hInternet, hHttpSession, hHttpRequest: Pointer;
- DataBuf: Array [0..131071] of Char;
- lpBufSize, lpReserved, lpHeadersSize: Cardinal;
- EventProcedure: procedure (S: String);
- pHeaders: PChar;
- begin
- hInternet := nil;
- hHttpSession := nil;
- hHttpRequest := nil;
- lpReserved := 0;
- try
- hInternet := InternetOpen('MSN', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
- if not (Assigned(hInternet)) then
- ExitApplication(6, 'InternetOpen');
- hHttpSession := InternetConnect(hInternet, PChar(Host), Port, nil, nil,
- INTERNET_SERVICE_HTTP, 0, 0);
- if not (Assigned(hHttpSession)) then
- ExitApplication(7, 'InternetConnect');
- hHttpRequest := HttpOpenRequest(hHttpSession, 'GET', PChar(Target), nil, nil, nil,
- INTERNET_FLAG_SECURE, 0);
- if not (Assigned(hHttpRequest)) then
- ExitApplication(8, 'HttpOpenRequest');
- if (Headers = '') then
- begin
- pHeaders := nil;
- lpHeadersSize := 0;
- end
- else
- begin
- pHeaders := PChar(Headers);
- lpHeadersSize := Length(Headers);
- end;
- if not (HttpSendRequest(hHttpRequest, pHeaders, lpHeadersSize, nil, 0)) then
- begin
- Writeln(IntToStr(GetLastError));
- ExitApplication(9, 'HttpSendRequest');
- end;
- lpBufSize := SizeOf(DataBuf);
- if not (HttpQueryInfo(hHttpRequest, HTTP_QUERY_RAW_HEADERS_CRLF,
- @DataBuf, lpBufSize, lpReserved)) then
- begin
- Writeln(IntToStr(GetLastError));
- ExitApplication(10, 'HttpQueryInfo');
- end;
- lpSrvReceived := DataBuf;
- if (EventProc <> nil) then
- begin
- EventProcedure := EventProc;
- EventProcedure(lpSrvReceived);
- end;
- if not (HttpEndRequest(hHttpRequest, nil, 0, 0)) then
- begin
- Writeln(IntToStr(GetLastError));
- ExitApplication(11, 'HttpEndRequest');
- end;
- finally
- if (Assigned(hInternet)) then InternetCloseHandle(hInternet);
- if (Assigned(hHttpSession)) then InternetCloseHandle(hHttpSession);
- if (Assigned(hHttpRequest)) then InternetCloseHandle(hHttpRequest);
- end;
- end;
- begin
- if (ParamCount <> 3) then
- begin
- ShowUsage;
- Exit;
- end;
- if (ParamStr(1) <> '') then
- strHost := ParamStr(1);
- if (ParamStr(2) <> '') then
- strUser := ParamStr(2);
- if (ParamStr(3) <> '') then
- strPassword := ParamStr(3);
- if ((strHost = '') or(strUser = '') or (strPassword = '')) then
- begin
- ShowUsage;
- Exit;
- end;
- strUserUrlEncoded := StringReplace(strUser, '@', '%40', [rfReplaceAll]);
- if not (xWSAStartup(2, lpWSAData)) then
- ExitApplication(1, 'WSAStartup');
- ConnectTo(lpSocket, lpSockAddr, strHost, 1863);
- Writeln('Connected to Dispatch server!');
- Writeln('');
- SendAuthentication(lpSocket, sRecv);
- if (lpSocket > 0) then
- closesocket(lpSocket);
- if (Pos('XFR 2 NS', sRecv) = 0) then
- ExitApplication(5, 'Protocol Failure');
- ConnectTo(lpSocket, lpSockAddr, CopyWord(CopyWord(sRecv, 4), 1, ':'), 1863);
- Writeln('Connected to 2nd server!');
- Writeln('');
- SendAuthentication(lpSocket, sRecv);
- if (Pos('USR 2 TWN S ', sRecv) > 0) then
- authString := CopyWord(sRecv, 5);
- Writeln('authString = ' + authString);
- Writeln('');
- SendHTTPS('nexus.passport.com', '/rdr/pprdr.asp', '', 443, sRecvTWN, @RecvMessages);
- (*
- //login.live.com
- CopyWord(CopyWord(CopyWord(sRecvTWN, 2, 'DALogin='), 1, ','), 1, '/');
- //login2.srf
- CopyWord(CopyWord(CopyWord(sRecvTWN, 2, 'DALogin='), 1, ','), 2, '/');
- *)
- SendHTTPS(
- CopyWord(CopyWord(CopyWord(sRecvTWN, 2, 'DALogin='), 1, ','), 1, '/'),
- '/' + CopyWord(CopyWord(CopyWord(sRecvTWN, 2, 'DALogin='), 1, ','), 2, '/'),
- 'Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom' +
- ',sign-in=' + strUserUrlEncoded + ',pwd=' + strPassword + ',' + authString + CRLF +
- 'User-Agent: MSMSGS' + CRLF +
- 'Host: ' + CopyWord(CopyWord(CopyWord(sRecvTWN, 2, 'DALogin='), 1, ','), 1, '/') + CRLF +
- 'Connection: Keep-Alive' + CRLF +
- 'Cache-Control: no-cache' + CRLF,
- 443,
- sRecvTWN,
- @RecvMessages);
- SendSocketText(lpSocket, 'USR 3 TWN S ' + CopyWord(CopyWord(sRecvTWN, 2, 'from-PP='''), 1, '''') +
- CRLF, 0, @SentMessages);
- sRecv := ReceiveSocketText(lpSocket, 0, @RecvMessages);
- if (Pos('USR 3 OK ', sRecv) > 0) then
- Writeln('User Identified!')
- else
- Writeln('User/Password Incorrect!');
- ExitApplication(0, '');
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement