Results 1 to 13 of 13

Thread: SOCKS5 proxy library

  1. #1
    Join Date
    Aug 2006
    Location
    London
    Posts
    2,021
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default SOCKS5 proxy library

    scar socks5 proxy library

    iv used it to load google through tor, and to connect to irc through tor

    SCAR Code:
    {
     scar socks5 proxy library by yakman
     
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation, either version 3 of the License, or
     (at your option) any later version.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
    }


    {
     read rfc1928 and rfc1929
    }


    type
     RemoteAddress = record
      ipv4: Boolean;
      host: string; //used if ipv4=false
      ip: array[0..3] of byte; //used it ipv4=true
     end;

     SocketBuffer = record
      fd: Integer;
      pos, len: Integer;
      buf: string;
     end;
     
     Socks5Auth = record
      UseAuth: Boolean;
      user, pass: string;
     end;

    //have to make a simple buffering interface here..
    procedure StartSocketByteBuffer(var buffer: SocketBuffer; fd: integer);
    begin
    buffer.fd:= fd;
    buffer.pos:= 1;
    end;

    function SocketRead(var buffer: SocketBuffer): Char;
    var
     b: string;
    begin
    if(buffer.pos >= buffer.len+1)then
      begin
      ReadConnectionData(buffer.fd, b);
      buffer.buf:= b;
      buffer.pos:= 1;
      buffer.len:= Length(buffer.buf);
      end;
    Result:= buffer.buf[buffer.pos];
    buffer.pos:= buffer.pos + 1;
    end;

    {
     Start a socks5 connection

     fd   - socket handle
     addr - address the socks5 server should connect to
            when this function returns, the values in the record
            will be filled with the addr that the socket
            on the socks5 server is bounded to.
     port - port the socks5 server should connect to
            when this function returns, it will be filled with
            the port that the socket on the socks5 server is
            bounded to.
     auth - username/password to be offered, if any
     
     return true on success
    }

    function InitSocks5(fd: Integer; var addr: RemoteAddress; var port: Integer; var auth: Socks5Auth): Boolean;
    var
     p: string;
     buffer: SocketBuffer;
     c: char;
     f: Integer;
    begin
    Result:= True;
    StartSocketByteBuffer(buffer, fd);

    //send handshake
    p:= #05; //version
    if(auth.UseAuth)then
      p:= p
        + #02 //number of methods
        + #00  //method no auth
        + #02 //username/password
    else
      p:= p
        + #01 //number of methods
        + #00;  //method no auth
    SendConnectionData(fd, p);

    //read version
    c:= SocketRead(buffer);
    if(c <> #05)then
      begin
      Result:= False;
      Writeln('Socks wrong version: ' + inttostr(ord(c)));
      Exit;
      end;

    //read method
    c:= SocketRead(buffer);
    if(auth.UseAuth)then
      begin
      if(c <> #00)and(c <> #02)then
        begin
        Result:= False;
        Writeln('Socks wrong method: ' + inttostr(ord(c)));
        Exit;
        end;
       
      if(c = #02)then //user/pass auth
        begin
        p:= #05
          + Chr(Length(auth.user) and $ff) + auth.user
          + Chr(Length(auth.pass) and $ff) + auth.pass;
        SendConnectionData(fd, p);
       
        SocketRead(buffer); //reading version again
        if(SocketRead(buffer) <> #00)then //status
          begin
          Result:= False;
          writeln('Failed auth');
          Exit;
          end;
        end;
      end
    else
      begin
      if(c <> #00)then
        begin
        Result:= False;
        Writeln('Socks wrong method: ' + inttostr(ord(c)));
        Exit;
        end;
      end;

    //send request
    p:= #05 + //version
        #01 + //cmd connect
        #00;//reserved
    if(addr.ipv4)then
      begin
      p:= p + #01 + //ipv4
      Chr(addr.ip[0]) + Chr(addr.ip[1]) + Chr(addr.ip[2]) + Chr(addr.ip[3]);
      end
    else
      begin
      p:= p + #03 + //domain name
      Chr(Length(addr.host) and $ff) + addr.host;
      end;

    //add port
    p:= p + Chr((port shr 8) and $ff) + Chr(port and $ff);
    SendConnectionData(fd, p);


    //reading reply
    SocketRead(buffer); //version
    c:= SocketRead(buffer);
    if(c <> #00)then
      begin
      Result:= False;
      Writeln('Socks reply not equal to success: ' + inttostr(ord(c)));
      Exit;
      end;
    SocketRead(buffer); //reserved
    c:= SocketRead(buffer); //address type
     case c of
      #01: begin //ipv4 address
           addr.ipv4:= True;
           for f:=0 to 3 do
             addr.ip[f]:= Ord(SocketRead(buffer)); //read ipv4 addr
           end;
      #03: begin //domain name
           addr.ipv4:= False;
           addr.host:= '';
           c:= SocketRead(buffer);
           for f:=1 to ord(c) do
             addr.host:= addr.host + SocketRead(buffer);
           end;
      #04: begin //ipv6
           //writeln('warning - ipv6 not implemented');
           for f:=1 to 16 do
             SocketRead(buffer); //read ipv6 addr
           end;
     end;

    port:= (Ord(SocketRead(buffer)) shl 8) or (Ord(SocketRead(buffer)));
    end;


    procedure LoadGoogle;
    var
     fd: Integer;
     s: string;
     addr: RemoteAddress;
     port: Integer;
     auth: Socks5Auth;
    begin
    writeln('connecting');
    fd:= OpenConnection('localhost', 9050, 10000);
    if(fd < 0)then
      begin
      writeln('OpenConnection()');
      Exit;
      end;
     
    writeln('negociating proxy server');
    {
    addr.ipv4:= True;
    addr.ip[0]:= 209;
    addr.ip[1]:= 85;
    addr.ip[2]:= 229;
    addr.ip[3]:= 147;
    }

    addr.ipv4:= False;
    addr.host:= 'www.google.co.uk';
    port:= 80;

    auth.UseAuth:= True;
    auth.user:= 'socks5user';
    auth.pass:= 'socks5pass';
    if(not InitSocks5(fd, addr, port, auth))then
      begin
      FreeConnection(fd);
      writeln('error starting socks');
      Exit;
      end;
    if(addr.ipv4)then
      s:= Inttostr(addr.ip[0]) + '.'
      + Inttostr(addr.ip[1]) + '.'
      + Inttostr(addr.ip[2]) + '.'
      + Inttostr(addr.ip[3])
    else
      s:= addr.host;
    writeln('remote socket bound to ' + s + ':' + Inttostr(port));

    SendConnectionData(fd,
      'GET / HTTP/1.1' + #13 + #10 +
      'Accept: */*' + #13 + #10 +
      'User-Agent: scar' + #13 + #10 +
      'Host: [url]www.google.co.uk[/url]' + #13 + #10 +
      'Connection: close' + #13 + #10 +
      #13 + #10
    );

    writeln('waiting for responce');
    repeat
    ReadConnectionData(fd, s);
    Writeln(s);
    Sleep(50);
    until(s = '');

    writeln('end');
    FreeConnection(fd);
    end;

    begin
    LoadGoogle;
    end.
    Last edited by Yakman; 05-04-2009 at 12:06 AM.
    Join the Official SRL IRC channel. Learn how to Here.

  2. #2
    Join Date
    Dec 2006
    Location
    Sweden
    Posts
    10,812
    Mentioned
    3 Post(s)
    Quoted
    16 Post(s)

    Default

    Line 188: [Error] (188:15): Type mismatch in script

    Used SCAR 3.15b now, worked.

    Code:
    Successfully compiled (78 ms)
    connecting
    negociating proxy server
    remote socket bound to 0.0.0.0:0
    waiting for responce
    HTTP/1.1 302 Found
    Location: http://www.google.es/
    Cache-Control: private
    Content-Type: text/html; charset=UTF-8
    Set-Cookie: PREF=ID=8399bdc668b70999:TM=1241311069:LM=1241311069:S=h6A96JV_fadpFalv; expires=Tue, 03-May-2011 00:37:49 GMT; path=/; domain=.google.com
    Date: Sun, 03 May 2009 00:37:49 GMT
    Server: gws
    Content-Length: 218
    Connection: close
    
    
    <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
    <TITLE>302 Moved</TITLE></HEAD><BODY>
    <H1>302 Moved</H1>
    The document has moved
    <A HREF="http://www.google.es/">here</A>.
    </BODY></HTML>
    
    
    end
    Successfully executed
    Naice.
    Last edited by Yakman; 05-03-2009 at 08:43 AM.


    Send SMS messages using Simba
    Please do not send me a PM asking for help; I will not be able to help you! Post in a relevant thread or make your own! And always remember to search first!

  3. #3
    Join Date
    Aug 2006
    Location
    London
    Posts
    2,021
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default

    its cause you used scar 3.20 and freddy fails
    Join the Official SRL IRC channel. Learn how to Here.

  4. #4
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    Fail troll is fail.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  5. #5
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    You rocks my socks (please don't hurt me).
    As always, a useful piece of random scripting - nice commenting, clear code and more!
    How would we get by without you
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  6. #6
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

  7. #7
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Yakman View Post
    its cause you used scar 3.20 and freddy fails
    /facepalm, Scar 3.15b is also made by Freddy1990, ASAP you should shut up and only say freddy fails if you have uninstalled all your program from Freddy1990 from your pc.

    Freddy1990 > Yakman
    Mature > Immature.

    If you give a statement give arguments.

    Nice code.

    ~Hermpie
    Last edited by Hobbit; 05-04-2009 at 02:15 AM.
    ~Hermen

  8. #8
    Join Date
    Aug 2007
    Location
    Hawaii
    Posts
    3,880
    Mentioned
    7 Post(s)
    Quoted
    152 Post(s)

    Default

    Quote Originally Posted by Hermpie View Post
    /facepalm, Scar 3.15b is also made by Freddy1990, ASAP you should shut up and only say freddy fails, if you have uninstalled all your program from Freddy1990 from your pc.

    Freddy1990 > Yakman
    Mature > Immature.

    If you give a statement give arguments.

    Nice code.

    ~Hermpie
    Calm down. Im sure he doesnt mean it personally. But I agree that 3.15b > then Scar 3.20.
    Faith is an oasis in the heart which will never be reached by the caravan of thinking.

  9. #9
    Join Date
    Aug 2006
    Location
    London
    Posts
    2,021
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default

    Shuttleu, you must point the scar script to a socks5 proxy server.

    by default, it points to localhost:9050 which is used when you have tor running.
    you can change it in the procedure LoadGoogle;


    Quote Originally Posted by Hermpie View Post
    /facepalm, Scar 3.15b is also made by Freddy1990, ASAP you should shut up and only say freddy fails, if you have uninstalled all your program from Freddy1990 from your pc.

    Freddy1990 > Yakman
    Mature > Immature.

    If you give a statement give arguments.

    Nice code.

    ~Hermpie
    i was refering to how freddy didnt keep backward compatability in this case, although maybe i should be a bit easier on him, this just sounds like a bug.
    Last edited by Yakman; 05-04-2009 at 12:24 AM.
    Join the Official SRL IRC channel. Learn how to Here.

  10. #10
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You said something about SCAR 3.20 then you said Freddy fails.
    Sounds flaming to me.

    I want to ask you something nicely do you please want to stop thinking and doing like the world is black white.
    It's like you always think black or white, I like you but your always like I am right and you're not, IDC the rest.

    Good luck anyways

    ~Hermpie
    ~Hermen

  11. #11
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    now i get this
    Code:
    Successfully compiled (47 ms)
    connecting
    negociating proxy server
    Failed auth
    error starting socks
    Successfully executed
    idk what it does but i wanna see but i cant seem to get it to work :/

    ~shut

    EDIT: never mind i got it to work
    Code:
    Successfully compiled (62 ms)
    connecting
    negociating proxy server
    remote socket bound to 81.20.129.28:2333
    waiting for responce
    HTTP/1.1 302 Found
    Location: http://www.google.de/
    Cache-Control: private
    Content-Type: text/html; charset=UTF-8
    Set-Cookie: PREF=ID=869cec4ae7cf3876:TM=1241384037:LM=1241384037:S=ubiCdXscFGQiOMm0; expires=Tue, 03-May-2011 20:53:57 GMT; path=/; domain=.google.com
    Date: Sun, 03 May 2009 20:53:57 GMT
    Server: gws
    Content-Length: 218
    Connection: close
    
    <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
    <TITLE>302 Moved</TITLE></HEAD><BODY>
    <H1>302 Moved</H1>
    The document has moved
    <A HREF="http://www.google.de/">here</A>.
    </BODY></HTML>
    
    
    end
    Successfully executed
    so what does it acctually do?

  12. #12
    Join Date
    Dec 2006
    Location
    Sweden
    Posts
    10,812
    Mentioned
    3 Post(s)
    Quoted
    16 Post(s)

    Default

    It is just a library for loading a random socks5 proxy, I think. So you can use it for other projects, etc.


    Send SMS messages using Simba
    Please do not send me a PM asking for help; I will not be able to help you! Post in a relevant thread or make your own! And always remember to search first!

  13. #13
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    IE getting around the RS account creation time limit

    Nice code, yak! Thanks!
    Interested in C# and Electrical Engineering? This might interest you.

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
  •