Advertisement
Guest User

Untitled

a guest
May 9th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 6.75 KB | None | 0 0
  1. program wsBrowser;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   WinSock, xutils, xsock, WinInet;
  7.  
  8. const
  9.   CRLF = #13#10;
  10.  
  11. var
  12.   lpWSAData: TWSAData;
  13.   lpSocket: TSocket;
  14.   lpSockAddr: TSockAddr;
  15.   strHost, strUser, strPassword, strUserUrlEncoded, sRecv, sRecvTWN, authString: String;
  16.  
  17. procedure ShowUsage;
  18. begin
  19.   Writeln('----------------------------------------------------------------');
  20.   Writeln('- MSN Connect by Alice                                         -');
  21.   Writeln('- Usage: <server> <user> <password>                            -');
  22.   Writeln('----------------------------------------------------------------');
  23. end;
  24.  
  25. procedure ExitApplication(ErrorCode: Integer; Description: String);
  26. begin
  27.   if (lpSocket > 0) then
  28.     closesocket(lpSocket);
  29.  
  30.   WSACleanup;
  31.  
  32.   if (ErrorCode <> 0) then
  33.   begin
  34.     Writeln('Function: ' + Description);
  35.     Writeln('Error code: ' + IntToHex(ErrorCode, 8));
  36.     Halt(ErrorCode);
  37.   end;
  38. end;
  39.  
  40. procedure SentMessages(S: String);
  41. begin
  42.   Writeln('>>> ' + S);
  43. end;
  44.  
  45. procedure RecvMessages(S: String);
  46. begin
  47.   Writeln('<<< ' + S);
  48. end;
  49.  
  50. procedure SendAuthentication(s: TSocket; var lpSrvReceived: String);
  51. begin
  52.   SendSocketText(s, 'VER 0 MSNP8 CVR0' + CRLF, 0, @SentMessages);
  53.  
  54.   lpSrvReceived := ReceiveSocketText(s, 0, @RecvMessages);
  55.  
  56.   if ((Pos('VER', lpSrvReceived) > 0) and (Pos('MSNP8', lpSrvReceived) > 0)) then
  57.     SendSocketText(s, 'CVR 1 0x0409 win 4.10 i386 MSNMSGR 5.0.0544 ' +
  58.       'MSMSGS ' + strUser + CRLF, 0, @SentMessages);
  59.  
  60.   lpSrvReceived := ReceiveSocketText(s, 0, @RecvMessages);
  61.  
  62.   if (Pos('CVR 1', lpSrvReceived) > 0) then
  63.     SendSocketText(s, 'USR 2 TWN I ' + strUser + CRLF, 0, @SentMessages);
  64.  
  65.   lpSrvReceived := ReceiveSocketText(s, 0, @RecvMessages);
  66. end;
  67.  
  68. procedure ConnectTo(var s: TSocket; var lpSockAddr: TSockAddr; Host: String; Port: Word);
  69. begin
  70.   if not (GetHost(Host, Port, AF_INET, lpSockAddr)) then
  71.     ExitApplication(2, 'GetHost');
  72.  
  73.   if not (GetSock(PF_INET, SOCK_STREAM, IPPROTO_IP, s)) then
  74.     ExitApplication(3, 'GetSock');
  75.  
  76.   if (connect(s, lpSockAddr, SizeOf(lpSockAddr)) <> 0) then
  77.   begin
  78.     Writeln(IntToStr(WSAGetLastError));
  79.     ExitApplication(4, 'connect');
  80.   end;
  81. end;
  82.  
  83. procedure SendHTTPS(Host, Target, Headers: String; Port: Word; var lpSrvreceived: String;
  84.   EventProc: Pointer);
  85. var
  86.   hInternet, hHttpSession, hHttpRequest: Pointer;
  87.   DataBuf: Array [0..131071] of Char;
  88.   lpBufSize, lpReserved, lpHeadersSize: Cardinal;
  89.   EventProcedure: procedure (S: String);
  90.   pHeaders: PChar;
  91. begin
  92.   hInternet := nil;
  93.   hHttpSession := nil;
  94.   hHttpRequest := nil;
  95.  
  96.   lpReserved := 0;
  97.  
  98.   try
  99.  
  100.     hInternet := InternetOpen('MSN', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  101.     if not (Assigned(hInternet)) then
  102.       ExitApplication(6, 'InternetOpen');
  103.  
  104.     hHttpSession := InternetConnect(hInternet, PChar(Host), Port, nil, nil,
  105.       INTERNET_SERVICE_HTTP, 0, 0);
  106.     if not (Assigned(hHttpSession)) then
  107.       ExitApplication(7, 'InternetConnect');
  108.  
  109.     hHttpRequest := HttpOpenRequest(hHttpSession, 'GET', PChar(Target), nil, nil, nil,
  110.       INTERNET_FLAG_SECURE, 0);
  111.     if not (Assigned(hHttpRequest)) then
  112.       ExitApplication(8, 'HttpOpenRequest');
  113.  
  114.     if (Headers = '') then
  115.     begin
  116.       pHeaders := nil;
  117.       lpHeadersSize := 0;
  118.     end
  119.     else
  120.     begin
  121.       pHeaders := PChar(Headers);
  122.       lpHeadersSize := Length(Headers);
  123.     end;
  124.  
  125.     if not (HttpSendRequest(hHttpRequest, pHeaders, lpHeadersSize, nil, 0)) then
  126.     begin
  127.       Writeln(IntToStr(GetLastError));
  128.       ExitApplication(9, 'HttpSendRequest');
  129.     end;
  130.  
  131.     lpBufSize := SizeOf(DataBuf);
  132.  
  133.     if not (HttpQueryInfo(hHttpRequest, HTTP_QUERY_RAW_HEADERS_CRLF,
  134.       @DataBuf, lpBufSize, lpReserved)) then
  135.     begin
  136.       Writeln(IntToStr(GetLastError));
  137.       ExitApplication(10, 'HttpQueryInfo');
  138.     end;
  139.  
  140.     lpSrvReceived := DataBuf;
  141.  
  142.     if (EventProc <> nil) then
  143.     begin
  144.       EventProcedure := EventProc;
  145.       EventProcedure(lpSrvReceived);
  146.     end;
  147.  
  148.     if not (HttpEndRequest(hHttpRequest, nil, 0, 0)) then
  149.     begin
  150.       Writeln(IntToStr(GetLastError));
  151.       ExitApplication(11, 'HttpEndRequest');
  152.     end;
  153.  
  154.   finally
  155.  
  156.     if (Assigned(hInternet)) then InternetCloseHandle(hInternet);
  157.     if (Assigned(hHttpSession)) then InternetCloseHandle(hHttpSession);
  158.     if (Assigned(hHttpRequest)) then InternetCloseHandle(hHttpRequest);
  159.  
  160.   end;
  161. end;
  162.  
  163. begin
  164.   if (ParamCount <> 3) then
  165.   begin
  166.     ShowUsage;
  167.     Exit;
  168.   end;
  169.  
  170.   if (ParamStr(1) <> '') then
  171.     strHost := ParamStr(1);
  172.  
  173.   if (ParamStr(2) <> '') then
  174.     strUser := ParamStr(2);
  175.  
  176.   if (ParamStr(3) <> '') then
  177.     strPassword := ParamStr(3);
  178.  
  179.   if ((strHost = '') or(strUser = '') or (strPassword = '')) then
  180.   begin
  181.     ShowUsage;
  182.     Exit;
  183.   end;
  184.  
  185.   strUserUrlEncoded := StringReplace(strUser, '@', '%40', [rfReplaceAll]);
  186.  
  187.   if not (xWSAStartup(2, lpWSAData)) then
  188.     ExitApplication(1, 'WSAStartup');
  189.  
  190.   ConnectTo(lpSocket, lpSockAddr, strHost, 1863);
  191.  
  192.   Writeln('Connected to Dispatch server!');
  193.   Writeln('');
  194.  
  195.   SendAuthentication(lpSocket, sRecv);
  196.  
  197.   if (lpSocket > 0) then
  198.     closesocket(lpSocket);
  199.  
  200.   if (Pos('XFR 2 NS', sRecv) = 0) then
  201.     ExitApplication(5, 'Protocol Failure');
  202.  
  203.   ConnectTo(lpSocket, lpSockAddr, CopyWord(CopyWord(sRecv, 4), 1, ':'), 1863);
  204.  
  205.   Writeln('Connected to 2nd server!');
  206.   Writeln('');
  207.  
  208.   SendAuthentication(lpSocket, sRecv);
  209.  
  210.   if (Pos('USR 2 TWN S ', sRecv) > 0) then
  211.     authString := CopyWord(sRecv, 5);
  212.  
  213.   Writeln('authString = ' + authString);
  214.   Writeln('');
  215.  
  216.   SendHTTPS('nexus.passport.com', '/rdr/pprdr.asp', '', 443, sRecvTWN, @RecvMessages);
  217.  
  218.   (*
  219.   //login.live.com
  220.   CopyWord(CopyWord(CopyWord(sRecvTWN, 2, 'DALogin='), 1, ','), 1, '/');
  221.   //login2.srf
  222.   CopyWord(CopyWord(CopyWord(sRecvTWN, 2, 'DALogin='), 1, ','), 2, '/');
  223.   *)
  224.   SendHTTPS(
  225.     CopyWord(CopyWord(CopyWord(sRecvTWN, 2, 'DALogin='), 1, ','), 1, '/'),
  226.     '/' + CopyWord(CopyWord(CopyWord(sRecvTWN, 2, 'DALogin='), 1, ','), 2, '/'),
  227.     'Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom' +
  228.     ',sign-in=' + strUserUrlEncoded + ',pwd=' + strPassword + ',' +  authString + CRLF +
  229.     'User-Agent: MSMSGS' + CRLF +
  230.     'Host: ' + CopyWord(CopyWord(CopyWord(sRecvTWN, 2, 'DALogin='), 1, ','), 1, '/') + CRLF +
  231.     'Connection: Keep-Alive' + CRLF +
  232.     'Cache-Control: no-cache' + CRLF,
  233.     443,
  234.     sRecvTWN,
  235.     @RecvMessages);
  236.  
  237.   SendSocketText(lpSocket, 'USR 3 TWN S ' + CopyWord(CopyWord(sRecvTWN, 2, 'from-PP='''), 1, '''') +
  238.     CRLF, 0, @SentMessages);
  239.  
  240.   sRecv := ReceiveSocketText(lpSocket, 0, @RecvMessages);
  241.  
  242.   if (Pos('USR 3 OK ', sRecv) > 0) then
  243.     Writeln('User Identified!')
  244.   else
  245.     Writeln('User/Password Incorrect!');
  246.  
  247.   ExitApplication(0, '');
  248. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement