Page 1 of 5 123 ... LastLast
Results 1 to 25 of 106

Thread: ProSocks

  1. #1
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default ProSocks

    ProSocks Library


    I finally got frustrated enough waiting on the Simba developers to get Simba's sockets together.. So.. I wrote a plugin that should have some neat functionality and is 100% portable. It is statically compiled so no extra downloads required. I know Simba is open source and I can add the code to it myself.. Just thought a plugin would handle it better and it would be easy for anyone to use it without having to re-install or re-download Simba.


    Features:
    SSL & TLS enabled.
    Read/Write/Accepts, GET, POST, etc.
    Email (SMTP), POP3, etc.



    Future Features (maybe):
    Lape style structures.


    Download:
    https://github.com/Brandon-T/ProSocks/releases

    If using ASM (ProSocks v.01):

    ASM Code:
    format PE console
    entry main

    include 'Code/FASM/include/macro/import32.inc'                  ;Includes

    section '.idata' import data readable
                                                                    ;Imports
    library msvcrt,'msvcrt.dll', prosocks,'prosocks.dll'
    import msvcrt, printf, 'printf',\
    exit,'exit', getchar, 'getchar', scanf, 'scanf',\
    sprintf, 'sprintf', malloc, 'malloc', free, 'free'

    import prosocks, CreateSocket, 'CreateSocket', ConnectSocket, 'ConnectSocket',\
    CloseSocket, 'CloseSocket', FreeSocket, 'FreeSocket', AcceptSocket, 'AcceptSocket',\
    ReadSocket, 'ReadSocket', WriteSocket, 'WriteSocket'



    section '.data' data readable writeable
                                                                    ;Formatters
    StringFormat db "%s", 13, 10, 0
    StringExFormat db "%.*s", 13, 10, 0
    ByteFormat db "%x", 13, 10, 0
    AddressFormat db "%p", 13, 10, 0
    NumberFormat db "%d", 13, 10, 0
    ErrorFormat db "Error %s", 13, 10, 0

                                                                    ;Strings

    CannotCreateSocket db "Cannot create socket.", 0
    CannotConnectSocket db "Cannot connect socket.", 0
    Host db "raw.githubusercontent.com", 0
    RequestedFile db "Brandon-T/ProSocks/master/README.md", 0

                                                                    ;Formatted Strings

    GetHeader db "GET /%s HTTP/1.1", 13, 10,\
                 "Host: %s", 13, 10,\
                 "Connection: close", 13, 10,\
                 "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11", 13, 10,\
                 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 13, 10,\
                 "Accept-Language: en-US,en;q=0.8", 13, 10,\
                 "Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7", 13, 10,\
                 "Cache-Control: no-cache", 13, 10, 13, 10, 0


    struc sizeof [args]
    {
       common .args
       sizeof.#. = $-.
    }

    struc SockInfo sock, ssl, ctx, address, type, timeout, port, connected, blockmode
    {
       .sock dd sock
       .ssl dd ssl
       .ctx dd ctx
       .address dd address
       .type dd type
       .timeout dd timeout
       .port dw port;
       .connected db connected
       .blockmode db blockmode
    }

    sizeof.SockInfo = 28
    sockinfo SockInfo 0, 0, 0, 0, 0, 0, 0, 0, 0
    buffer db 512 dup(0)
    buffptr rd 0

    section '.code' code readable executable
    main:
       push ebp
       mov ebp,esp

       mov [sockinfo.address], Host                    ;set address
       mov [sockinfo.timeout], 0x9C4                   ;set timeout - 2500ms
       mov [sockinfo.port], 0x1BB                      ;set port - 463
       mov [sockinfo.blockmode], 0x1                   ;set blocking

       push sockinfo
       call [CreateSocket]                             ;Create a socket.   bool __cdecl CreateSocket(SSLSocket* ssl_info);
       add esp, 0x04

       push eax
       push CannotCreateSocket
       call PrintError                                 ;If there were any errors, print them and quit.
       cmp eax, 0x00
       je .quit


       push sockinfo
       call [ConnectSocket]                            ;Connect the socket.   bool __cdecl ConnectSocket(SSLSocket* ssl_info);
       add esp, 0x04

       push eax
       push CannotConnectSocket
       call PrintError                                 ;If there were any errors, print them and quit.
       cmp eax, 0x00
       je .quit


       push Host
       push RequestedFile
       push GetHeader
       push buffer
       call [sprintf]                                  ;Create the get header.
       add esp, 0x10


       push eax
       push buffer
       push sockinfo
       call [WriteSocket]
       add esp, 0x0C
                                                       ;sub esp, 0x204
                                                       ;mov dword[ebp + 0x04], esp

       push Host
       push RequestedFile
       push GetHeader
       push buffer                                     ;push dword[ebp + 0x04]
       call [sprintf]
       add esp, 0x10


       push eax
       push buffer
       push sockinfo
       call [WriteSocket]                               ;Write the buffer to the socket.

       push 0x4E20
       push buffptr
       call SafePtrAlloc                                ;Allocate a buffer for reading.

       push 0x4E20
       push dword[buffptr]
       push sockinfo
       call [ReadSocket]                                ;Read the headers into the buffer.
       add esp, 0x0C


       push dword[buffptr]
       push StringFormat
       call [printf]                                    ;Print the buffer/headers
       add esp, 0x08

       push 0xD0
       push dword[buffptr]
       push sockinfo
       call [ReadSocket]                                ;Read the response into the buffer
       add esp, 0x0C

       push dword[buffptr]
       push eax
       push StringExFormat
       call [printf]                                    ;Print the buffer/data
       add esp, 0x0C


       push buffptr
       call SafePtrFree                                  ;Free the allocated buffer.


       .quit:
          push sockinfo
          call [FreeSocket]
          add esp, 0x04


       call [getchar]
       mov esp, ebp
       pop ebx
       mov eax, 0x00
    ret


    PrintError:
       push ebp
       mov ebp, esp

       cmp dword[ebp + 0x0C], 0x01
       jne .print
       mov eax, 0x01
       jmp .end

       .print:
          push dword[ebp + 0x08]
          push ErrorFormat
          call [printf]
          add esp, 0x08
          mov eax, 0x00

       .end:
       mov esp, ebp
       pop ebp
    ret 0x08


                              ;Allocates memory and stores the address in the first parameter.
    SafePtrAlloc:             ;Takes two parameters. First is the Pointer, second is the size to allocate.
       push ebp
       mov ebp, esp

       mov edx, [ebp + 0x08]       ;Pointer to be freed

       push dword[edx]             ;Free pointed to memory
       call [free]
       add esp, 0x04

       push edx                    ;Save pointer
       push dword[ebp + 0x0C]      ;Size to allocate in bytes
       call [malloc]               ;Allocate n-amount
       add esp, 0x04               ;Pop parameters
       pop edx                     ;Restore edx
       mov [edx], eax              ;Move allocated address into edx

       mov esp, ebp
       pop ebp
    retn 0x08

                                   ;Sets a pointer to nullptr after freeing its memory
    SafePtrFree:                   ;Takes one parameter. A pointer to a block of memory to free.
       push ebp
       mov ebp, esp

       mov eax, [ebp + 0x08]       ;Move pointer into eax
       mov edx, eax                ;Copy pointer location
       push edx                    ;Save copied pointer

       push dword[eax]             ;Push the pointed to address
       call [free]                 ;Free the memory
       add esp, 0x04
       pop edx                     ;Restore the copied pointer
       mov [edx], dword 0x0        ;Set it to nullptr

       mov esp, ebp
       pop ebp
    ret 0x04




    If Using Simba (ProSocks v0.2+):

    GET:
    Simba Code:
    {$loadlib prosocks}

    Function GetPageEx(URL: String): String;
    var
      S: SSLSocket;
      res: ProMemoryStruct;
    begin
      //S.Timeout := 500; //custom timeout if needed.
      Pro_InitSocket(S, nil, nil, nil, nil);
      Pro_CreateSocket(S, '');
      Pro_SetSSL(S, false, false, true);
      Pro_SetURL(S, URL);
      Pro_DoGetEx(S, res); //GetRequest

      {$IFDEF LAPE}
      SetLength(Result, res.size);
      MemMove(res.memory^, Result[1], res.size);
      {$ELSE}
      Result := res.memory;
      {$ENDIF}


      try
        Pro_FreeSocket(S);
      except
        WriteLn('Unable to Free ' + URL + ' ProSocks Error');
      end;
    end;


    Advanced GET:
    Simba Code:
    //Letting Lape handle the memory allocations instead of the plugin

    function PCharToStr(P: PChar): String;
    var
      L: Integer;
      PP: PChar := P;
    begin
      while (PP^ <> #0) do
      begin
        Inc(PP); Inc(L);
      end;
      SetLength(Result, L + 1);
      MemMove(P^, Result[1], L);
    end;


    Function Pro_CustomWriteF(contents: PChar; size: PtrUInt; nmemb: PtrUint; var userp: String): PtrUInt;
    var
      realsize: PtrUInt;
      l: PtrUInt;
      ptr: PChar;
    begin
      ptr := @userp;
      realsize := size * nmemb;

      if (size <> 0) then
      begin
        l := Length(UserP);
        if (l = 0) then l := 1;
        SetLength(UserP, Length(UserP) + realsize);
        MemMove(Contents^, UserP[l], realsize); //<3 slacky.
      end else
        if (ptr <> nil) then
          SetLength(UserP, 0);

      Result := realsize;
    end;

    Function Pro_CustomErrorHandlerF(str: PChar; errorcode: LongInt): PtrUInt;
    begin
      writeln('Error: ' + PCharToStr(Str));
      writeln('Error Code: ' + ToStr(ErrorCode));
    end;

    Function Pro_CustomStrLenF(var str: String): PtrUInt;
    begin
      Result := Length(str);
    end;

    var
      S: SSLSocket;
      Str: String;
    begin
      S.Timeout := 500; //custom timeout.
      S.caller_allocates := true; //Lape allocates all strings and memory.
      S.data := @Str; //String to be filled with returned data.

      Pro_InitSocket(S, Natify(@Pro_CustomWriteF), Natify(@Pro_CustomWriteF), Natify(@Pro_CustomErrorHandlerF), Natify(@Pro_CustomStrLenF));
      Pro_CreateSocket(S, '');
      Pro_SetSSL(S, false, true);
      Pro_SetURL(S, 'https://villavu.com/forum/');
      Pro_DoGet(S);
      Pro_FreeSocket(S);

      writeln(Str);
    end.


    GET (Custom Headers):
    Simba Code:
    {$loadlib prosocks}

    var
      S: SSLSocket;
      res: ProMemoryStruct;
    begin
      Pro_InitSocket(S, nil, nil, nil, nil);
      Pro_CreateSocket(S, '');
      Pro_SetSSL(S, false, false, true);
      Pro_SetURL(S, 'https://villavu.com/forum/');
      Pro_SetHeader(S, 'Accept', 'text/html', false); //custom header.
      Pro_SetHeader(S, 'Connection', 'keep-alive', false); //custom header.
      Pro_DoGetEx(S, res);
      writeln(res.memory);
      Pro_FreeSocket(S);
    end.


    POST (Cookie handling as well):
    Simba Code:
    {$loadlib prosocks}

    var
      S: SSLSocket;
      MS: ProMemoryStruct;
    begin
      Pro_InitSocket(S, nil, nil, nil, nil);
      Pro_CreateSocket(S, '');
      Pro_SetCookies(S, 'Cookies.txt', 'Cookies.txt'); //allow cookies.
      Pro_SetSSL(S, false, false, true);
      Pro_SetURLFollow(S, true); //follow redirects.

      Pro_SetURL(S, 'https://facebook.com');
      Pro_DoGet(S); //dummy GET (used in the OAuth protocol)

      Pro_SetURL(S, 'https://www.facebook.com/login.php?login_attempt=1&amp;next=https%3A%2F%2Fwww.facebook.com%2Fmessages%2F');
      Pro_AddParameter(S, 'id', 'login_form', false);
      Pro_AddParameter(S, 'trynum', '1', false);
      Pro_AddParameter(S, 'email', 'email@hotmail.com', false);
      Pro_AddParameter(S, 'pass', '****', false);
      Pro_DoPost(S);

      Pro_SetURL(S, 'https://www.facebook.com/messages/');   //private page.. to test if we logged in successfully..
      Pro_DoGetEx(S, MS);
      writeln(MS.memory); //save to a file.html and open the file in the browser. ;)
      Pro_FreeSocket(S);
    end.

    SMTP (Sending Emails.. Supports: CC, BCC, Attachments, MIME, etc..):
    Simba Code:
    {$loadlib prosocks}
    var
      S: SSLSocket;
    begin
      Pro_InitSocket(S, nil, nil, nil, nil); //nil for PS.
      Pro_CreateSocket(S, ''); //default user agent.
      Pro_SetVerbose(S, True); //debugging enabled. Not needed.
      Pro_SetSSL(S, false, false, true);
      Pro_SMTP(S, 'smtps://smtp.gmail.com', 'user@gmail.com', '****', 'Brandon T', 'to@gmail.com', 'cc', 'bcc', 'Subject', 'Message', 'text/plain; charset=UTF-8', 'Attachment.ext', 'application/x-msdownload; charset=UTF-8');
      Pro_FreeSocket(S);
    end.


    POP3 (Receiving Emails):
    Simba Code:
    {$loadlib prosocks}

    var
      S: SSLSocket;
      MS: ProMemoryStruct;
    begin
      Pro_InitSocket(S, nil, nil, nil, nil); //nil for PS.
      Pro_CreateSocket(S, ''); //default user agent.
      Pro_SetVerbose(S, True); //debugging enabled. Not needed.
      Pro_SetSSL(S, false, false, true);
      Pro_SetURL(S, 'pop.gmail.com');
      Pro_SetLogin(S, 'MyEmail@gmail.com', 'MyPassword');
      Pro_PerformEx(S, MS);
      writeln(MS.memory); //Print results.
      Pro_FreeSocket(S);


    List of Available Functions & Definitions:

    Simba Code:
    type ProWritePtr = Function(contents: PChar; size: PtrUInt; nmemb: PtrUint; var userp: String): PtrUInt;
    type ProErrorHandlerPtr = Function(str: PChar; errorcode: LongInt): PtrUInt;
    type ProLenPtr = Function(var Str: String): PtrUInt;

    {$IFNDEF LAPE}
    type
      ProMemoryStruct = record
        memory: PChar;
        size: PtrUInt;
      end;
    {$ELSE}
    type
      ProMemoryStruct = packed record
        memory: PChar;
        size: PtrUInt;
      end;
    {$ENDIF}

    {$IFNDEF LAPE}
    type
      SSLSocket = record
        curl_handle: PtrUInt;
        headers: PChar;
        data: PChar;
        params: PChar;
        LengthFunc: ProLenPtr;
        ErrorHandlerFunc: ProErrorHandlerPtr;
        WriteFunc: ProWritePtr;
        HeaderFunc: ProWritePtr;
        hdrs: PChar;
        Timeout: Cardinal;
        Port: Word;
        caller_allocates: Boolean;
      end;
    {$ELSE}
    type
      SSLSocket = packed record
        curl_handle: PtrUInt;
        headers: PChar;
        data: PChar;
        params: PChar;
        LengthFunc: ProLenPtr;
        ErrorHandlerFunc: ProErrorHandlerPtr;
        WriteFunc: ProWritePtr;
        HeaderFunc: ProWritePtr;
        hdrs: PChar;
        Timeout: Cardinal;
        Port: Word;
        caller_allocates: Boolean;
      end;
    {$ENDIF}

    //all parameters for this function are to be set to nil in pascal script (except the first parameter). That's because PS doesn't have "natify" or "native".
    Procedure Pro_InitSocket(var curl_info: SSLSocket; WriteFunc: ProWritePtr; HeaderFunc: ProWritePtr; ErrorHandlerFunc: ProErrorHandlerPtr; StrLenFunc: ProLenPtr);

    Procedure Pro_CreateSocket(var curl_info: SSLSocket; useragent: String);
    Procedure Pro_FreeSocket(var curl_info: SSLSocket);
    Procedure Pro_SetURLFollow(var curl_info: SSLSocket; follow: Boolean);
    Procedure Pro_SetSSL(var curl_info: SSLSocket; try_set: Boolean; verifypeer: Boolean; verifyhost: Boolean);
    Procedure Pro_SetCookies(var curl_info: SSLSocket; const cookiejar: String; const cookiefile: String);
    Procedure Pro_SetHeaderCapture(var curl_info: SSLSocket; enable: boolean);
    Function Pro_SetHeader(var curl_info: SSLSocket; const key: String; const value: String): Boolean;
    Procedure Pro_CustomRequest(var curl_info: SSLSocket; const request: String);
    Procedure Pro_SetNoBody(var curl_info: SSLSocket; enable: Boolean);
    Procedure Pro_SetVerbose(var curl_info: SSLSocket; enable: Boolean);
    Function Pro_GetHostLocation(var address: String; var buffer: String): String;
    Function Pro_GetRequestLocation(var address: String; var buffer: String): String;
    Procedure Pro_SetURL(var curl_info: SSLSocket; const URL: String);
    Procedure Pro_SetUpload(var curl_info: SSLSocket; enable: Boolean);
    Procedure Pro_SetLogin(var curl_info: SSLSocket; const user: String; const pwd: String);
    Procedure Pro_ClearParameters(var curl_info: SSLSocket);
    Function Pro_AddParameter(var curl_info: SSLSocket; const key: String; const value: String; escape: Boolean): Boolean;
    Function Pro_DoGet(var curl_info: SSLSocket): PChar;
    Procedure Pro_DoGetEx(var curl_info: SSLSocket; var Res: ProMemoryStruct);
    Function Pro_DoPost(var curl_info: SSLSocket): PChar;
    Procedure Pro_DoPostEx(var curl_info: SSLSocket; var Res: ProMemoryStruct);
    Function Pro_Perform(var curl_info: SSLSocket): PChar;
    Procedure Pro_PerformEx(var curl_info: SSLSocket; var Res: ProMemoryStruct);
    Function Pro_GetHeaders(var curl_info: SSLSocket): PChar;
    Procedure Pro_GetHeadersEx(var curl_info: SSLSocket; var Res: ProMemoryStruct);
    Function Pro_SMTP(var curl_info: SSLSocket; url, user, pwd, name, recipient, cc, bcc, subject, body, bodymime, file, filemime: PChar): Boolean;
    Procedure Pro_MSTPC(var curl_info: SSLSocket; var Res: ProMemoryStruct);


    If using C/C++ (Prosocks v.0.2+):
    C++ Code:
    //
    //  main.cpp
    //  TestSSL
    //
    //  Created by Brandon T on 2015-10-11.
    //  Copyright © 2015 SRL. All rights reserved.
    //

    #include <dlfcn.h>
    #include <stdint.h>
    #include <string.h>
    #include <stdio.h>
    #include <stdlib.h>



    #define LOAD_FUNC(MODULE, PTR) (PTR = (decltype(PTR))dlsym(MODULE, #PTR))


    int main(int argc, const char * argv[])
    {
        void* module = dlopen("/Users/Brandon/Desktop/libProSocks.dylib", RTLD_LAZY);
       
        if (module)
        {
            printf("All good\n");
           
            LOAD_FUNC(module, Curl_InitSocket);
            LOAD_FUNC(module, Curl_CreateSocket);
            LOAD_FUNC(module, Curl_FreeSocket);
            LOAD_FUNC(module, Curl_SetURLFollow);
            LOAD_FUNC(module, Curl_SetSSL);
            LOAD_FUNC(module, Curl_SetCookies);
            LOAD_FUNC(module, Curl_SetHeaderCapture);
            LOAD_FUNC(module, Curl_SetHeader);
            LOAD_FUNC(module, Curl_CustomRequest);
            LOAD_FUNC(module, Curl_SetNoBody);
            LOAD_FUNC(module, Curl_SetVerbose);
            LOAD_FUNC(module, Curl_SetVerbose);
            LOAD_FUNC(module, Curl_GetHostLocation);
            LOAD_FUNC(module, Curl_GetRequestLocation);
            LOAD_FUNC(module, Curl_SetURL);
            LOAD_FUNC(module, Curl_SetUpload);
            LOAD_FUNC(module, Curl_SetLogin);
            LOAD_FUNC(module, Curl_ClearParams);
            LOAD_FUNC(module, Curl_AddParameter);
            LOAD_FUNC(module, Curl_DoGet);
            LOAD_FUNC(module, Curl_DoPost);
            LOAD_FUNC(module, Curl_Perform);
            LOAD_FUNC(module, Curl_GetHeaders);
            LOAD_FUNC(module, Curl_SMTP);
           
           
           
            CurlSock sock = {0};
            Curl_InitSocket(&sock, nullptr, nullptr, nullptr, nullptr);
            Curl_CreateSocket(&sock, "");
            Curl_SetVerbose(&sock, true);
            Curl_SetSSL(&sock, false, false, true);
            Curl_SMTP(&sock, "smtps://smtp.gmail.com", "MyEmail@gmail.com", "MyPassword", "Brandon T", "Receipient@gmail.com", nullptr, nullptr, "Subject", "Message", "text/plain; charset=UTF-8", nullptr, nullptr);
           
            Curl_FreeSocket(&sock);
           
           
            dlclose(module);
        }
        else
        {
            printf("%s\n", dlerror());
        }
       
        return 0;
    }

    Yup.. You can now use SSL and TLS without having to download addition crap. You can send emails directly from Simba, etc.. Gmail, Yahoo, AOL, Hotmail/Live/Outlook.. Anything..
    Last edited by Brandon; 10-11-2015 at 09:21 PM. Reason: Workaround for Simba not being able to handle NULL characters..
    I am Ggzz..
    Hackintosher

  2. #2
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Great work as usual.

  3. #3
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    Looks nice Brandon!

    Should the port in SMTP.Create be kept at 465?

    Edit: Works!


  4. #4
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Daaamn buddy, it is pretty amazing how much you get done in so little time...
    Come on man, share that time machine with us! You really are from the future.

    I repped you with some weird message accidentally...
    ..I blame this stupid new laptop of mine - it has got keyboard design from hell!
    Ment to give you better description to the points, oh well.

    Good work once again, @Brandon.

    -Jani

  5. #5
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    So much can be done with the emailing functionality in terms of scripts for Runescape, like reporting back to the user when there's a problem with the script or even getting real time input from the user. Awesome work man!
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  6. #6
    Join Date
    Jan 2012
    Posts
    1,596
    Mentioned
    78 Post(s)
    Quoted
    826 Post(s)

    Default

    So that means emails directly through simba? yaaay.

    as well as checking? more yays. can make scripts do what i want meow. except it seems like alot of work to set that all up.

    annyway. great job brandon.

  7. #7
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    Quote Originally Posted by Turpinator View Post
    So that means emails directly through simba? yaaay.

    as well as checking? more yays. can make scripts do what i want meow. except it seems like alot of work to set that all up.

    annyway. great job brandon.
    Not really that much work to do at all. All you need to do is download the attachment in the OP and save Socks.simba in your includes folder
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  8. #8
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    @Jani, no worries. Glad you guys like it. No you can make the port whatever you want as long as the server you're talking to is using that port.


    25 = smtp
    465 = SSL
    587 = TLS
    80 = HTTP

    Of course it can be different but yeah. Google and most providers use 465 or 587 for communication so I used that in the sample script. If you use this as a server socket then you can listen on whatever port you want for incoming connections.


    There are only 5 functions (Create, Connect, Read, Write, Accept, IsPending). All others were derived from those.

    It's not hard to set up. It's one file you download and you just include it in your script. The "sample" is very very small. Include looks messy as hell but efficient.

    It just looks like a lot because there's multiple languages on the OP to demonstrate the flexibility of the module.


    Simba Code:
    SMTP.Create                  //calls Pro_CreateSocket and Pro_ConnectSocket in SSL23_CLIENT_METHOD mode to establish a connection.
    SMTP.Free                    //calls Pro_CloseSocket & Pro_FreeSocket to cleanup the sockets.
    SMTP.SetSubject              //set the email subject (optional)
    SMTP.SetMessage              //set the email body/message (optional)
    SMTP.SetFromName             //set the name you'd like the recipient to see (optional)
    SMTP.SetToName               //set the name of the person you are sending to (optional)
    SMTP.SetBufferSize           //set the internal buffer size. 512 is default (optional)
    SMTP.SendMail                //send the mail out.


    HTTPS.Create                 //calls Pro_CreateSocket and Pro_ConnectSocket in SSL23_CLIENT_METHOD mode to establish a connection.
    HTTPS.Free                   //calls Pro_CloseSocket & Pro_FreeSocket to cleanup the sockets.
    HTTPS.ClearParameters        //parameters are http get/post parameters.
    HTTPS.GetParameter           //retrieves a parameter set on the socket. Example: User-Agent, Accept-Language, Accept-Charset, etc..
    HTTPS.SetParameter           //sets a parameter on the socket. Example: User-Agent, Accept-Language, Accept-Charset, etc..
    HTTPS.GetHeader              //get a single header field.
    HTTPS.CreateGetHeader        //create a get request header.
    HTTPS.GetPage                //reads html via chunk transfer encoding or straight. Handles all cases
    HTTPS.GetRawPage             //returns the raw socket data. Does not parse it


    type
      SSLSocketType = (          //a list of the types of socket you can choose from.
        TLS1_CLIENT_METHOD,
        TLS1_SERVER_METHOD,
        TLS11_CLIENT_METHOD,
        TLS11_SERVER_METHOD,
        SSL2_CLIENT_METHOD,
        SSL2_SERVER_METHOD,
        SSL3_CLIENT_METHOD,
        SSL3_SERVER_METHOD,
        SSL23_CLIENT_METHOD,    //most compatible and the best.
        SSL23_SERVER_METHOD     //most compatible and the best.
      );


    type
      SSLSocket = record
        sock:        Cardinal;       //handle to the raw underlying socket. Can be used with other API's.        Do not fill this in.
        ssl:         Cardinal;       //SSL pointer to the underlying SSL instance. Can be used with other API's. Do not fill this in.
        ctx:         Cardinal;       //Same as SSL pointer. It's a context pointer for use with other API's.     Do not fill this in.

        address:     PChar;          //Determines what IP to connect to.                                         Must be filled in.
        port:        Word;           //Determines what port to connect to.                                       Must be filled in.

        connected:   Boolean;        //tells you if you're connected or not.                                     Do not fill this in.
        socktype:    SSLSocketType;  //Type of socket you'd like.                                                Must be filled in.
    end;


    //actual plugin functions..

    Function Pro_CreateSocket(ssl_info: ^SSLSocket): Boolean;    //Creates the underlying socket.
    Function Pro_ConnectSocket(ssl_info: ^SSLSocket): Boolean;   //Connects to the address and port with SSL enabled.
    Function Pro_CloseSocket(ssl_info: ^SSLSocket): Boolean;    //Closes the underlying socket. Does not need calling if FreeSocket is called.
    Function Pro_FreeSocket(ssl_info: ^SSLSocket): Boolean;     //Frees and destroys both SSL and the underlying socket.
    Function Pro_ReadSocket(ssl_info: ^SSLSocket; Buffer: PChar; BuffSize: Integer): Integer; //Reads BuffSize amount of bytes into 'Buffer'. Returns amount of bytes actually read.
    Function Pro_WriteSocket(ssl_info: ^SSLSocket; Buffer: String; BuffSize: Integer): Integer; //Writes BuffSize bytes from 'buffer' into the socket. Returns amount of bytes actually written.
    Function Pro_AcceptSocket(ssl_info: ^SSLSocket): Boolean; //Accepts a socket if in listening/server mode.
    Function Pro_IsPendingSocket(ssl_info ^SSLSocket): Boolean; //Returns if there is data waiting to be written or read to/from the socket.


    The only time you would use and of the Pro_* functions is if you plan to do raw communication outside of what's already provided for you.
    Last edited by Brandon; 04-21-2014 at 12:03 AM.
    I am Ggzz..
    Hackintosher

  9. #9
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Would I be a noob for asking if this can communicate with Github directly?

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  10. #10
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    Would I be a noob for asking if this can communicate with Github directly?
    I'm not sure what you mean by communicate "directly". It is a raw socket API so you can pretty much do whatever you like. In the sample, I showed it fetching data from github. You can not only do get requests, but you can also do posts as well.. Downloading files, etc.. Anything you can do with a regular socket, you will be able to do with this one.
    Last edited by Brandon; 04-21-2014 at 12:10 AM.
    I am Ggzz..
    Hackintosher

  11. #11
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    I'm not sure what you mean by communicate "directly". It is a raw socket API so you can pretty much do whatever you like. In the sample, I showed it fetching data from github. You can not only do get requests, but you can also do posts as well. Anything you can do with a regular socket, you will be able to do with this one.
    Sounds good. I remember asking before why Simba couldn't download files from Github and I was told it's because of something to do with this?

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  12. #12
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    Sounds good. I remember asking before why Simba couldn't download files from Github and I was told it's because of something to do with this?

    Yup. If you look at github URL's, they use HTTPS. Simba's sockets do not have SSL enabled by default and requires you to install OpenSSL. I tried installing it and placing it in Simba's plugins folder, in my path environment.. nothing worked so I just compiled it and made this plugin.

    Yeah to download from github with this is as easy as:

    Simba Code:
    {$I Socks.Simba}

    var
      HT: HTTPS;
    begin
      HT.Create('https://raw.githubusercontent.com/Brandon-T/DXI/master/LICENSE', 443);
      writeln(HT.GetPage); //download a page. Do NOT have to only download pages.
      HT.Free;
    end.

    That is equivalent to:

    Simba Code:
    {$I Socks.Simba}

    var
      HT: HTTPS;
      Str: String;
    begin
      HT.Create('raw.githubusercontent.com', 443);
      Str := 'GET /Brandon-T/DXI/master/LICENSE HTTP/1.1' + #13#10;
      Str := Str + 'Host: raw.githubusercontent.com' + #13#10;

      Pro_WriteSocket(@HT.ssl_info, @Str[1], Length(Str));

      while(Pro_ReadSocket(@HT.ssl_info, @Buffer[0], Length(Buffer)) > 0) do
      begin
        writeln(Buffer); //or save it to a file or whatever.. Buffer holds bytes. Can be any type of file or content.

        if (Pro_IsPending(@HT.ssl_info)) then
          break;
      end;
     
      HT.Free;
    end.


    The same can be done for posting. You can login to websites like that, etc.
    Last edited by Brandon; 04-21-2014 at 12:25 AM.
    I am Ggzz..
    Hackintosher

  13. #13
    Join Date
    Jan 2012
    Posts
    1,596
    Mentioned
    78 Post(s)
    Quoted
    826 Post(s)

    Default

    Quote Originally Posted by Rich View Post
    Not really that much work to do at all. All you need to do is download the attachment in the OP and save Socks.simba in your includes folder
    Simba Code:
    var
      MS: SMTP;
      HT: HTTPS;
    begin
      MS.Create('smtp.gmail.com', 465, 'ICantChooseUsernames@gmail.com', '*****password*****', 'ICantChooseUsernames@gmail.com', 'Testing Simba Mail');
      MS.SetMessage('Hey there, just testing a message.');
      MS.SetFromName('Brandon');
      MS.SetToName('Brandon');
      MS.SendMail;
      MS.Free;
    end.
    -- thats still work. but meh.

    @Brandon; you should add POP3 checking to the 'include' too. thatd be great.

  14. #14
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Turpinator View Post
    @Brandon; you should add POP3 checking to the 'include' too. thatd be great.

    Give me a bit and I'll figure out all the headers for POP3. I haven't done that in YEARS (VB times)! Same with IMAP but I remember it being very easy..

    I just whipped up something in a couple minutes quick:

    Simba Code:
    Procedure ReadSocket(ssl_info: ^SSLSocket);
    var
      Buffer: String;
      Bytes_Read: Integer;
    Begin
      SetLength(Buffer, 512);
      For Bytes_Read := 1 To 512 Do
        Buffer[Bytes_Read] := #0;

      While((Bytes_Read := Pro_ReadSocket(ssl_info, @Buffer[1], 512)) > 0) Do
      Begin
        Buffer := Trim(Buffer);
        writeln(Buffer);
        If (Not Pro_IsPendingSocket(ssl_info)) Then
          break;
      End;
    End;

    var
      ssl_info: SSLSocket;
      Address: String;
      Buffer: String;
    begin
      Address := 'pop.gmail.com';
      ssl_info.port := 995;
      ssl_info.address := @Address[1];
      ssl_info.socktype := SSLSocketType.SSL23_CLIENT_METHOD;
      Pro_CreateSocket(@ssl_info);
      Pro_ConnectSocket(@ssl_info);

      ReadSocket(@ssl_info);

      Buffer := 'USER ' + 'ICantChooseUsernames@gmail.com' + #13#10;
      Pro_WriteSocket(@ssl_info, Buffer, Length(Buffer));
      ReadSocket(@ssl_info);

      Buffer := 'PASS ' + '****password****' + #13#10;
      Pro_WriteSocket(@ssl_info, Buffer, Length(Buffer));
      ReadSocket(@ssl_info);

      Buffer := 'LIST' + #13#10;  //list the options/emails..  Use STAT to figure out allocation size for all messages.
      Pro_WriteSocket(@ssl_info, Buffer, Length(Buffer));
      ReadSocket(@ssl_info);

      Buffer := 'RETR 1' + #13#10;  //retrieve command. (I think). It gets the 1st mail.
      Pro_WriteSocket(@ssl_info, Buffer, Length(Buffer));
      ReadSocket(@ssl_info);

      Buffer := 'QUIT' + #13#10;
      Pro_WriteSocket(@ssl_info, Buffer, Length(Buffer));
      ReadSocket(@ssl_info);

      Pro_CloseSocket(@ssl_info);
      Pro_FreeSocket(@ssl_info);
    end.


    Don't mind the comments. They're there so I don't forget what I was doing..

    I just have to parse headers and check the responses properly like for the mail client and it'll be good.. Pretty neat.. Far easier than SMTP. The HTTP header parser should work on this IIRC. I'll look at it in a sec.
    Last edited by Brandon; 04-21-2014 at 02:09 AM.
    I am Ggzz..
    Hackintosher

  15. #15
    Join Date
    Jan 2012
    Posts
    1,596
    Mentioned
    78 Post(s)
    Quoted
    826 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    Give me a bit and I'll figure out all the headers for POP3. I haven't done that in YEARS (VB times)! Same with IMAP but I remember it being very easy..

    I just whipped up something in a couple minutes quick:


    Don't mind the comments. They're there so I don't forget what I was doing..

    I just have to parse headers and check the responses properly like for the mail client and it'll be good.. Pretty neat.. Far easier than SMTP. The HTTP header parser should work on this IIRC. I'll look at it in a sec.
    coo.

  16. #16
    Join Date
    Nov 2006
    Posts
    449
    Mentioned
    84 Post(s)
    Quoted
    145 Post(s)

    Default

    Quote Originally Posted by core View Post
    I saw this thread over in SRL Development, and wrote a pure Simba mailer for fun.
    Obviously, implementing SSL/TLS is a huge undertaking, and I'm not up to that task at the moment.
    For SMTP servers that don't require authentication or encryption though, it works like a charm.
    Leave it to brandon to do the "huge undertaking" part. Awesome work!

    First they ignore you, then they laugh at you, then they fight you, then you win.
    Stance on Leechers

  17. #17
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    I must ask, where do you get all the free time?
    There used to be something meaningful here.

  18. #18
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Good job, this might come in handy one day!
    !No priv. messages please

  19. #19
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default

    I tried it with gmx and it doesnt seem to work :X.. When using port 465 I get the Output:

    220 gmx.com (mrgmx102) Nemesis ESMTP Service ready
    501 Syntax error in parameters or arguments
    503 Bad sequence of commands
    500 Syntax error, command unrecognized
    500 Syntax error, command unrecognized
    503 Bad sequence of commands
    502 Command not implemented
    503 Bad sequence of commands
    503 Bad sequence of commands
    500 Syntax error, command unrecognized
    500 Syntax error, command unrecognized

    And with 587(suggested by gmx) I dont get any debug output at all. And no mail being sent

  20. #20
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    @Everyone, thanks

    Quote Originally Posted by caused View Post
    I tried it with gmx and it doesnt seem to work :X.. When using port 465 I get the Output:
    And with 587(suggested by gmx) I dont get any debug output at all. And no mail being sent


    EDIT: I changed the SMTP.SendMail to (I updated the OP to reflect the changes):

    Simba Code:
    Str := 'EHLO ' + self.__Address + #13#10;  //line 154 for me.
        Pro_WriteSocket(@self.__ssl_info, Str, Length(Str));
        self.__PrintSocket();

    //and

        Str := Str + 'Subject: ' + self.__Subject + #13#10#13#10;  //line 186 for me.

    and it works for gmx. Apparently gmx just didn't support the 'HELO' command.


    Simba Code:
    {$I Socks.Simba}

    var
      MS: SMTP;
    begin
      //ESMTP - Extended SMTP
      MS.Create('smtp.gmx.us', 465, 'ggzz@gmx.us', '***Password***', 'ggzz@gmx.us', 'SUBJECT');
      MS.SetMessage('My Message');
      MS.SetFromName('ggzz');
      MS.SetToName('Brandon');
      MS.SendMail;
      MS.Free;
     
      //SMTP - Plain SMTP
      MS.Create('smtp.gmail.com', 465, 'ICantChooseUsernames@gmail.com', '***Password***', 'ICantChooseUsernames@gmail.com', 'Testing Simba Mail');
      MS.SetMessage('Hey there, just testing a message.');
      MS.SetFromName('Brandon');
      MS.SetToName('Brandon');
      MS.SendMail;
      MS.Free;
    end.



    Few minor details like mail size can be specified. Reading how the server determines end of DATA section, etc.. The above should work though. I tested it.

    HELO command is far cleaner than EHLO. EHLO is used to display server details and HELO is just for identification.. It's stupid that they don't have HELO. Didn't want to use EHLO but it's ok. Works for all now.
    Last edited by Brandon; 04-21-2014 at 02:46 PM.
    I am Ggzz..
    Hackintosher

  21. #21
    Join Date
    Nov 2006
    Posts
    449
    Mentioned
    84 Post(s)
    Quoted
    145 Post(s)

    Default

    Just some minor input: SMTP should really be implemented as a finite-state automaton and be reactive to the codes/commands received, rather than just sending out commands regardless of responses. This can trigger abuse detection on some mail providers that can lead to complications. This will also let you dynamically deal with the HELO/EHLO/etc issues, and is incredibly easy to expand on if you want to add more states/transitions in the future.

    First they ignore you, then they laugh at you, then they fight you, then you win.
    Stance on Leechers

  22. #22
    Join Date
    Sep 2012
    Location
    Here.
    Posts
    2,007
    Mentioned
    88 Post(s)
    Quoted
    1014 Post(s)

  23. #23
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by core View Post
    Just some minor input: SMTP should really be implemented as a finite-state automaton and be reactive to the codes/commands received, rather than just sending out commands regardless of responses. This can trigger abuse detection on some mail providers that can lead to complications. This will also let you dynamically deal with the HELO/EHLO/etc issues, and is incredibly easy to expand on if you want to add more states/transitions in the future.

    Yeah I'll eventually get around to doing that. It was just more work at the time for parsing all the headers and responses. I was lazy and just put something together nice and quick.
    I am Ggzz..
    Hackintosher

  24. #24
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    @Everyone, thanks





    EDIT: I changed the SMTP.SendMail to (I updated the OP to reflect the changes):

    Simba Code:
    Str := 'EHLO ' + self.__Address + #13#10;  //line 154 for me.
        Pro_WriteSocket(@self.__ssl_info, Str, Length(Str));
        self.__PrintSocket();

    //and

        Str := Str + 'Subject: ' + self.__Subject + #13#10#13#10;  //line 186 for me.

    and it works for gmx. Apparently gmx just didn't support the 'HELO' command.


    Simba Code:
    {$I Socks.Simba}

    var
      MS: SMTP;
    begin
      //ESMTP - Extended SMTP
      MS.Create('smtp.gmx.us', 465, 'ggzz@gmx.us', '***Password***', 'ggzz@gmx.us', 'SUBJECT');
      MS.SetMessage('My Message');
      MS.SetFromName('ggzz');
      MS.SetToName('Brandon');
      MS.SendMail;
      MS.Free;
     
      //SMTP - Plain SMTP
      MS.Create('smtp.gmail.com', 465, 'ICantChooseUsernames@gmail.com', '***Password***', 'ICantChooseUsernames@gmail.com', 'Testing Simba Mail');
      MS.SetMessage('Hey there, just testing a message.');
      MS.SetFromName('Brandon');
      MS.SetToName('Brandon');
      MS.SendMail;
      MS.Free;
    end.



    Few minor details like mail size can be specified. Reading how the server determines end of DATA section, etc.. The above should work though. I tested it.

    HELO command is far cleaner than EHLO. EHLO is used to display server details and HELO is just for identification.. It's stupid that they don't have HELO. Didn't want to use EHLO but it's ok. Works for all now.

    Awesome Great work.

    One more question.

    How would you attach a file to an email ? Is that implemented ?

  25. #25
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by caused View Post
    Awesome Great work.

    One more question.

    How would you attach a file to an email ? Is that implemented ?

    The capabilities of the module itself is there. Are the headers for that implemented in the include? Nope, nope and double nope.. Gotta go through these: http://www.mhonarc.org/~ehood/MIME/MIME.html to do file transfer and understand what --boundary-- is and delimiters for multi-part messages.


    Simba itself doesn't have a MIME parser so I would have to write one if I intend to read emails. For writing emails with file attachments, it's not a "massive" task but it does take time for proper implementation. I'll try it soon enough.. as in not today or tomorrow or Wednesday but when I have a day off or another long weekend.

    That in itself will take time though. For a single file, it's not too much work to add to the include.
    Last edited by Brandon; 04-21-2014 at 06:55 PM.
    I am Ggzz..
    Hackintosher

Page 1 of 5 123 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •