Results 1 to 17 of 17

Thread: vb6 http request by socks5 proxy IP/winsock/winhttprequest

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    vb6 http request by socks5 proxy IP/winsock/winhttprequest

    How does VB6 send an HTTPS request with the winhttprequest object or winsock through the sockS5 proxy IP?
    vb6如何通过sockS5代理ip用winhttprequest对象发送https请求?

    Code:
    HTTPHeader = "CONNECT " & socks5ip & ":" & port & _
    
      " HTTP/1.1" & Chr(13) & Chr(10) & "Host: " & Form1.Text5.Text & ":" & _
    
      Form1.Text6.Text & Chr(13) & Chr(10) & "Authorization: Basic " & StrtoBase64(Form1.Text3.Text & _
    
      ":" & Form1.Text4.Text) & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "Proxy-Authorization: Basic " & _
    
      StrtoBase64(Form1.Text3.Text & ":" & Form1.Text4.Text) & Chr(13) & Chr(10) & Chr(13) & Chr(10)
    
      ' Chr(13) & Chr(10) 能否直接用vbCrLf ? 我不知道
    
      Debug.Print HTTPHeader
    
      ConnStep = PStep + 1
    
      Form1.Winsock1.SendData HTTPHeader
    
      Exit Function
    Last edited by xiaoyao; Mar 27th, 2023 at 05:43 PM.

  2. #2
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: How does VB6 send an HTTPS request with the winhttprequest object through the soc

    CONNECT is a verb for http(s) proxies. SOCKS5 proxies use completely different protocol.

    WinHttpRequest supports http(s) proxies already -- just use HTTPREQUEST_PROXYSETTING_PROXY (2) for first parameter and IP:port for second ProxyServer parameter.

    Actually the ProxyServer format is [<scheme>=][<scheme>"://"]<server>[":"<port>] so you can specify all 4 combinations of "for http/https use this http/https proxy" using both scheme placeholders in the format string.

    cheers,
    </wqw>

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: How does VB6 send an HTTPS request with the winhttprequest object through the soc

    The following is sample code for sending an HTTP request using VB6 to connect to the socks5 proxy IP: First, you need to add MSWinsock. Winsock controls or communicate using the Winsock API. Next, set the address and port of the socks5 proxy server and the destination URL address. Finally, the HTTP request is constructed, the data is sent, and the response is received.

    Why doesn't this code work?

    Code:
      Set sock = New Winsock
        sock.Protocol = sckSocks5 '使用socks5协议
    Code:
    Private Sub cmdSend_Click()
        Dim ProxyAddr As String
        Dim TargetURL As String
        Dim ProxyPort As Integer
        Dim sock As Winsock
        Dim ReqData As String
        Dim Resp As String
        Dim i As Integer
    
        '设置socks5代理服务器地址和端口
        ProxyAddr = "127.0.0.1"
        ProxyPort = 1080
    
        '设置目标URL地址
        TargetURL = "http://www.example.com/"
    
        '初始化Winsock控件
        Set sock = New Winsock
        sock.Protocol = sckSocks5 '使用socks5协议
        sock.RemoteHost = ProxyAddr
        sock.RemotePort = ProxyPort
        sock.Connect
    
        Do While Not sock.State = sckConnected
            DoEvents
        Loop
    
        '构造HTTP请求数据
        ReqData = "GET " & TargetURL & " HTTP/1.0" & vbCrLf _
                    & "Host: www.example.com" & vbCrLf _
                    & vbCrLf
    
        '发送HTTP请求数据
        sock.SendData ReqData
    
        '等待响应数据
        Do While sock.State = sckConnected
            DoEvents
            If sock.BytesReceived > 0 Then
                Resp = sock.GetData '接收响应数据
                Exit Do
            End If
        Loop
    
        '输出响应数据
        Debug.Print Resp
    
        '关闭连接
        sock.Close
        Set sock = Nothing
    End Sub

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: How does VB6 send an HTTPS request with the winhttprequest object through the soc

    HTTPREQUEST_PROXYSETTING_PROXY (2)

    Does this support socks5 proxy, IP,And the account password.?
    In the past, I used the winsock control to connect to the socks5 proxy IP successfully, but the HTTPS page data he returned was encrypted, which I can't do.

    How to connect to the https page via the socks5 proxy

    https://www.vbforums.com/showthread....e-socks5-proxy

    SSPI/Schannel client for SSL/TLS channels in VB6
    https://github.com/wqweto/VbAsyncSocket

    https://www.vbforums.com/showthread....hannels-in-VB6
    @wqweto I just implementedSOCKS5 support for https tunneling in the test projectand handshake is working ok here.
    https://github.com/wqweto/VbAsyncSoc....frm#L363-L419
    https://github.com/wqweto/VbAsyncSoc...1a3d4640a8b762

    Code:
        sUrl = "https://server.cryptomix.com/secure/"
        Debug.Print Format$(TimerEx, "0.000"), "Open " & sUrl
        Set oTlsClient = pvInitHttpRequest(sUrl)
        Set oTlsClient = pvInitHttpRequest(sUrl, IIf(chkProxy.Value = vbChecked, "socks5://" & txtProxy.Text, vbNullString))
    does it support socks5 wih user,password?

    ////////
    Rebex HTTPS
    HTTP and HTTPS library for modern and legacy platforms
    BUY FROM$349
    https://www.rebex.net/https/features/proxy.aspx
    socks5 get rmails
    https://www.emailarchitect.net/eaget...xyserver_a.htm
    There are some wrappers online that implement socks5. Generally, you need to pay for it.
    ------------------
    Last edited by xiaoyao; Mar 27th, 2023 at 01:26 PM.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: How does VB6 send an HTTPS request with the winhttprequest object through the soc

    https://www.example-code.com/vb6/http_socks5_proxy.asp

    Code:
    Dim http As New ChilkatHttp
    
    ' Using a SOCKS5 proxy is just a matter of setting a few properties.
    ' Once these properties are set, all other coding is the same as when
    ' the connection is direct to the HTTP server.
    
    ' Set the SocksVersion property = 5 for SOCKS5
    http.SocksVersion = 5
    
    ' Set the SocksHostname to the SOCKS proxy domain name or IP address, 
    ' which may be IPv4 (dotted notation) or IPv6.
    http.SocksHostname = "192.168.1.100"
    
    ' The port where the SOCKS5 proxy is listening.
    http.SocksPort = 1080
    
    ' If the SOCKS5 proxy itself requires authentication, set the username/password 
    ' like this.  (otherwise leave the username/password empty)
    http.SocksUsername = "myUsername"
    http.SocksPassword = "myPassword"
    
    ' Now do whatever it is you need to do.  All communications will go through the proxy.
    Dim html As String
    html = http.QuickGetStr("https://www.google.com/")
    If (http.LastMethodSuccess <> 1) Then
        Debug.Print http.LastErrorText
        Exit Sub
    End If
    
    Debug.Print html
    Debug.Print "----"
    Debug.Print "Success!"

  6. #6
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: How does VB6 send an HTTPS request with the winhttprequest object through the soc

    Quote Originally Posted by xiaoyao View Post
    Why doesn't this code work?
    Is this ChatGPT generated?

    WinHttpRequest does not support SOCKS4/5 proxies. It supports only http(s) proxies -- the ones with CONNECT verb in your snippet.

    cheers,
    </wqw>

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: How does VB6 send an HTTPS request with the winhttprequest object through the soc

    yes it's by chatgpt
    .socks-to-http-proxy,maybe is a good idea

    https://github.com/KaranGauswami/socks-to-http-proxy

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: How does VB6 send an HTTPS request with the winhttprequest object through the soc

    (Visual Basic 6.0) Socket/SSL/TLS through SOCKS5 / SOCKS4 Proxy

    Code:
    Dim socket As New ChilkatSocket
    
    ' To use a SOCKS4 or SOCKS5 proxy, simply set the following
    ' properties prior to calling Connect.  The connection may be SSL/TLS or 
    ' non-secure - both will work with a SOCKS proxy.
    ' The SOCKS hostname may be a domain name or 
    ' IP address:
    socket.SocksHostname = "www.mysocksproxyserver.com"
    socket.SocksPort = 1080
    socket.SocksUsername = "myProxyLogin"
    socket.SocksPassword = "myProxyPassword"
    ' Set the SOCKS version to 4 or 5 based on the version
    ' of the SOCKS proxy server:
    socket.SocksVersion = 5
    ' Note: SOCKS4 servers only support usernames without passwords.
    ' SOCKS5 servers support full login/password authentication.
    
    ' Connect to port 5555 of 192.168.1.108.
    ' hostname may be a domain name or IP address.
    Dim hostname As String
    hostname = "192.168.1.108"
    Dim ssl As Long
    ssl = 0
    Dim maxWaitMillisec As Long
    maxWaitMillisec = 20000
    Dim success As Long
    success = socket.Connect(hostname,5555,ssl,maxWaitMillisec)
    If (success <> 1) Then
        Debug.Print socket.LastErrorText
        Exit Sub
    End If
    
    ' Set maximum timeouts for reading an writing (in millisec)
    socket.MaxReadIdleMs = 10000
    socket.MaxSendIdleMs = 10000
    
    ' The server (in this example) is going to send a "Hello World!" 
    ' message.  Read it:
    Dim receivedMsg As String
    receivedMsg = socket.ReceiveString()
    If (socket.LastMethodSuccess <> 1) Then
        Debug.Print socket.LastErrorText
        Exit Sub
    End If
    
    ' Close the connection with the server
    ' Wait a max of 20 seconds (20000 millsec)
    success = socket.Close(20000)
    
    Debug.Print receivedMsg

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: How does VB6 send an HTTPS request with the winhttprequest object through the soc

    https://freeproxyupdate.com/socks5-proxy
    SOCKS5 free proxy list, best SOCKS5 proxy servers

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: How does VB6 send an HTTPS request with the winhttprequest object through the soc

    HttpToSocks5Proxy
    https://github.com/MihaZupan/HttpToSocks5Proxy

    As of .NET 6,SocketsHttpHandler supports connecting to Socks4, Socks4a and Socks5 proxies!

    This project is now archived and no longer maintained. You can use this library on older versions of .NET. See thearchived branch.
    Code:
    var client = new HttpClient(new SocketsHttpHandler()
    {
        Proxy = new WebProxy("socks5://127.0.0.1:9050")
    });
    
    var content = await client.GetStringAsync("https://check.torproject.org/");
    Console.WriteLine(content);

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: How does VB6 send an HTTPS request with the winhttprequest object through the soc

    socks5 by vb.net
    https://blog.csdn.net/pansnet/article/details/12423751

    Code:
    Function ConnectProxyServer(ByVal strRemoteHost As String, ByVal iRemotePort As Integer, ByVal sProxyServer As Socket) As Boolean
            Dim bySock5Send(9) As Byte
            Dim bySock5Receive(9) As Byte
            '构造Socks5代理服务器第一连接头(无用户名密码) 
            bySock5Send(0) = 5
            bySock5Send(1) = 1
            bySock5Send(2) = IIf(Me.RequireAuthorize, 2, 0)
     
            '发送Socks5代理第一次连接信息
            sProxyServer.Send(bySock5Send, 3, SocketFlags.None)
            Dim iRecCount As Integer = sProxyServer.Receive(bySock5Receive, bySock5Receive.Length, SocketFlags.None)
     
            '用户验证
            If bySock5Receive(1) = 2 And Me.RequireAuthorize = False Then
                Throw New Exception("代理服务器需要进行身份确认。")
     
     
            ElseIf bySock5Receive(1) = 2 Then
     
                '构造Socks5代理服务器第一连接头(无用户名密码)
                Dim bUser() As Byte = Encoding.Default.GetBytes(Username)
                Dim bPass() As Byte = Encoding.Default.GetBytes(Password)
                Dim dl As Integer = 3 + bUser.Length + bPass.Length
                ReDim bySock5Send(dl - 1)
                bySock5Send(0) = 5
                bySock5Send(1) = bUser.Length
                Array.Copy(bUser, 0, bySock5Send, 2, bUser.Length)
                bySock5Send(2 + bUser.Length) = bPass.Length
                Array.Copy(bPass, 0, bySock5Send, 3 + bUser.Length, bPass.Length)
     
                '发送Socks5代理第一次连接信息 
                sProxyServer.Send(bySock5Send, dl, SocketFlags.None)
                ReDim bySock5Receive(100)
                iRecCount = sProxyServer.Receive(bySock5Receive, bySock5Receive.Length, SocketFlags.None)
     
                If (iRecCount < 2) Then
                    sProxyServer.Close()
                    Throw New Exception("不能获得代理服务器正确响应。")
                End If
     
                If (bySock5Receive(0) <> 5 Or (bySock5Receive(1) <> 0 And bySock5Receive(1) <> 2)) Then
                    sProxyServer.Close()
                    Throw New Exception("代理服务其返回的响应错误。")
                End If
                If bySock5Receive(1) = 0 Then
                    ReDim bySock5Send(9)
                    bySock5Send(0) = 5
                    bySock5Send(1) = 1
                    bySock5Send(2) = 0
                    bySock5Send(3) = 1
                    Dim ipAdd As IPAddress = Dns.GetHostAddresses(strRemoteHost)(0)
                    Dim strIp As String = ipAdd.ToString
                    Dim strAryTemp() As String = strIp.Split("."c)
     
                    bySock5Send(4) = Convert.ToByte(strAryTemp(0))
                    bySock5Send(5) = Convert.ToByte(strAryTemp(1))
                    bySock5Send(6) = Convert.ToByte(strAryTemp(2))
                    bySock5Send(7) = Convert.ToByte(strAryTemp(3))
     
                    bySock5Send(8) = iRemotePort / 256
                    bySock5Send(9) = iRemotePort Mod 256
     
                    sProxyServer.Send(bySock5Send, bySock5Send.Length, SocketFlags.None)
                    iRecCount = sProxyServer.Receive(bySock5Receive, bySock5Receive.Length, SocketFlags.None)
                    If (bySock5Receive(0) <> 5 Or bySock5Receive(1) <> 0) Then
                        sProxyServer.Close()
                        Throw New Exception("第二次连接Socks5代理返回数据出错。")
                    End If
                    Return True
                Else
                    If (bySock5Receive(1) = 2) Then
                        Throw New Exception("代理服务器需要进行身份确认。")
                    Else
                        Return False
                    End If
     
                End If
     
            End If
            MsgBox("成功")  '我自己加的以确定代理是否成功 其实使用的时候我也不知道 具体成功没有

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: How does VB6 send an HTTPS request with the winhttprequest object through the soc

    Some of my summaries.
    ChilkatHttp,This is the most convenient and can be used directly.
    But it is an ActiveX DLL software product that you pay for.Support for encrypted email and web socket with socks5

    curl.dll,This should also be convenient, but we need to write some code to call it.

    socks5 to http from github

    It would be nice if both rc6.dll and https://github.com/wqweto/VbAsyncSocket could implement socks5 proxy IP and username and password.That would be most convenient.
    Last edited by xiaoyao; Mar 27th, 2023 at 02:02 PM.

  13. #13
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: How does VB6 send an HTTPS request with the winhttprequest object through the soc

    Quote Originally Posted by wqweto View Post
    Is this ChatLSD generated?
    Probably.

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: How does VB6 send an HTTPS request with the winhttprequest object through the soc

    I don't know how many forms of proxy IP there are.
    VPN, HTTP proxy, socks5?

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: How does VB6 send an HTTPS request with the winhttprequest object through the soc

    I don't think it's very difficult.In fact, it is just like the connection server process of FTP.Send a few simple commands. Ask the server if you need a password, and then encrypt the password if you need a password.After the connection is successful, the returned data is HTTPS encrypted, which is the most troublesome.

    RFC 1929-Socks5 Proxy Username/Password Verification Standard

    It is to send a Byte array of three bytes to the server. Since there is no need for user/password verification, expand it to write 05 01 00.
    If you need a password, send 05 01 02.

    http://www.pfan.cn/article/2839.html

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: vb6 http request by socks5/winsock/winhttprequest

    I use the socks5 proxy to access the E-mail server, just like foxmail Because the protocol details of socks5 are not clear (checked RFC, but failed), sniffer is used to monitor the network packets of foxmail. Through analysis and simulation, it is possible to communicate with a specific mail server. Here's the process. Establish a connection to the socks5 proxy server through the winsock control, and then

    Code:
    1. Send: 05 01 00 (Note: ASCII hexadecimal, the rest are converted strings) 
    2. Back: 05 00
     3. Send: 05 01 00 03 0C pop3.126.com 00 6E
     4.Return: 05 00 00 01 D2 53 CA B0 9 C7 
    5. Return: + OK Welcome to coremail Mail Pop3 Server (126com [030901]) 
    6. Send: USER tuzi59421 
    7.Return + OK core mail 
    8. Send PASS 5211314. 
    9.Return + OK 0 message (s) [0 byte (s)] ...
     In the future, it will be the content of SMTP communication.
    Sending part \n 'This Function is used to construct the message content.

    Code:
    Private Sub GenMail(bAttachment As Boolean)
    Dim fnum As Integer, FAttin As Integer
    Dim strLine As String
    strSendName = txtSName.Text
    strReceiveName = txtRName.Text
    strFromMail = txtFrom.Text
    strToMail = txtTo.Text
    m_Date = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0600"
    strSubject = txtSubject.Text
    strContent = txtContent.Text
    fnum = FreeFile()
    Open App.Path & "\mail.tmp" For Output As fnum
    '构造信件標題字段
    Print #fnum, "From:" & Chr(32) & strSendName
    Print #fnum, "Date:" & Chr(32) & m_Date
    Print #fnum, "X-Mailer: BigAnt Smtp Mailer V1.0"
    Print #fnum, "To:" & Chr(32) & strReceiveName
    Print #fnum, "Subject:" & Chr(32) & strSubject
    If bAttachment = False Then
    Print #fnum, ""
    Print #fnum, strContent
    Exit Sub
    End If
    Print #fnum, "MIME-Version: 1.0"
    Print #fnum, "Content-type:multipart/mixed;"
    Print #fnum, " boundary =""----=_NextPart_000_000A_01BF9F1A"""
    Print #fnum, ""
    '書寫信件的正文內容
    Print #fnum, "--" & "----=_NextPart_000_000A_01BF9F1A"
    Print #fnum, "Content-Type: text/plain;"
    Print #fnum, " Charset = ""gb2312"""
    Print #fnum, "Content-Transfer-Encoding: 8bit"
    Print #fnum, ""
    Print #fnum, strContent
    '附件內
    Dim i As Integer
    For i = 0 To cobAtt.ListCount - 1
    Base64Encode cobAtt.List(i), App.Path & "\attachment" & i & ".tmp"
    Print #fnum, "--" & "----=_NextPart_000_000A_01BF9F1A"
    Print #fnum, "Content-Type: Application/octet-stream"
    Print #fnum, " name=" & cobAtt.List(i)
    Print #fnum, "Content-Transfer-Encoding: base64"
    Print #fnum, "Content-Disposition: attachment;"
    Print #fnum, " FileName=" & cobAtt.List(i)
    Print #fnum, ""
    FAttin = FreeFile
    Open App.Path & "\attachment" & i & ".tmp" For Input As #FAttin
    While Not EOF(FAttin)
    Line Input #FAttin, strLine
    Print #fnum, strLine
    Wend
    Close FAttin
    Next i
    Print #fnum, "--" & "----=_NextPart_000_000A_01BF9F1A" & "--"
    Close fnum
    End Sub
    Last edited by xiaoyao; Mar 27th, 2023 at 05:41 PM.

  17. #17
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: How does VB6 send an HTTPS request with the winhttprequest object through the soc

    Quote Originally Posted by xiaoyao View Post
    It would be nice if both rc6.dll and https://github.com/wqweto/VbAsyncSocket could implement socks5 proxy IP and username and password.That would be most convenient.
    No, for VbAsyncSocket I'm not willing to implement it and I'm not going to accept Pull Requests for it.

    Too many spam/scraping bots in this world already.

    cheers,
    </wqw>

Posting Permissions

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



Click Here to Expand Forum to Full Width