Solved

Web Proxy (Creating One)

Posted on 2000-04-12
10
220 Views
Last Modified: 2013-11-25
Can one create a web proxy using Visual Basic? If yes, I'll up the points for a "how" section to that answer!
0
Comment
Question by:ayrezyle
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 2708543
While you might be able to create a web proxy in VB generally you wouldn't want to as you should put in a Linux box up instead of a Windoze OS. This would therefore eliminate *any* Micro$oft GUI product from being used as a proxy server development base.

M
0
 

Expert Comment

by:oviv
ID: 2709611
Rather then bash Microsoft, I will tell you that it can be done.  Tell me more about what you wish to do and I might already have some code for you.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 2709773
Not bashing M$. Simply saying that GUI is weak point in this type of app. You want *TIGHT*, *FAST* and *Rugged*. Windows/VB provides none of these and is inappropriate choice for this application. You can write it in VB on Windows, but system will *NOT* work reliably and will be easily breached. Is NOT how you want proxy server/firewall to behave. Why do you need a GUI on a box that will be locked in a closet? You could add a bath tub to a drag racing car but it wouldn't help it go any faster or run any better - so what is point?

Windows is inappropriate for tight realtime applications. You simply cannot write robust, highly I/O intensive code with all of overhead that the GUI implies. I've written quite a bit of firmware and embedded processor code and GUI overhead is not appropriate even if you *can* get it running.

M
0
 

Expert Comment

by:oviv
ID: 2709838
How do you know how I/O intensive his application is going to be?  No time to argue though and there is no point to it until we know what he wants to do with it.

Take care,
Oviv
0
 
LVL 14

Accepted Solution

by:
mcrider earned 100 total points
ID: 2710436
When building a proxy server in VB basically, they work like this:

You have a winsock control that is running as a server.  It is listening on a specific port waiting for a connection.

Once this socket receives a connection (ACCEPT SOCKET), the code would open another connection using another socket to the "real destination" (PROXY SOCKET).

Usually, before the PROXY SOCKET is opened, information about where the "real destination" is located is passed from the client.  For example, in a HTTP proxy, URL sent contains the system name that the proxy server should connect to.

Depending on the protocol you are building the procy for, the code would "pump" everything it receives from the ACCEPT SOCKET to the PROXY SOCKET... and everything it recives from the PROXY SOCKET to the ACCEPT SOCKET.

FTP, for example is much more difficult to provide proxy services for that HTTP because HTTP only uses 1 socket for transmission, whereas, FTP uses 2 sockets...

I am assuming that you already know how to program using the winsock control... If not, take a look at the Help page and "Books online..." for the control.

Here's an example of a proxy for HTTP using the winsock controls that I put together... Remember, this is a BASIC EXAMPLE that I threw together.


1) Create a new project.

2) add 2 winsock controls to the form and change the INDEX property of both controls to 0

3) Add the following code to the DECLARATIONS SECTION of the form:

        Dim RollingSocket As Integer
    Private Sub Form_Load()
        Winsock1(0).LocalPort = 80
        Winsock1(0).Listen
    End Sub
    Private Sub Winsock1_Close(Index As Integer)
        On Error Resume Next
        Winsock1(Index).Close
        Winsock2(Index).Close
        Unload Winsock1(Index)
        Unload Winsock2(Index)
    End Sub
    Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
        Dim iVal As Long
        RollingSocket = RollingSocket + 1
        If RollingSocket = 200 Then RollingSocket = 1
        Load Winsock1(RollingSocket)
        Winsock1(RollingSocket).Accept requestID
    End Sub
    Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
        Dim iVal As Long
        Dim jVal As Long
        Dim lBuf As String
        Dim lCmd As String
        Dim lFunct As String
        Dim lUrl As String
        Dim lVer As String
        Dim lHost As String
        Dim ProxyServer As Integer
        On Error Resume Next
        With Winsock1(Index)
            .GetData lBuf
            .Tag = .Tag + lBuf
            DoEvents
            If Right$(.Tag, 4) = vbCrLf + vbCrLf Then
                'WE GOT THE WHOLE BUFFER FROM THE WWW CLIENT, PARSE IT
                iVal = InStr(1, .Tag, vbCrLf)
                lCmd = Left$(.Tag, iVal - 1)
                .Tag = Mid$(.Tag, iVal + 2)
                iVal = InStr(1, lCmd, " ")
                jVal = InStr(iVal + 1, lCmd, " ")
                lFunct = Left$(lCmd, iVal - 1)
                iVal = iVal + 1
                lUrl = Mid$(lCmd, iVal, jVal - iVal)
                lVer = Mid$(lCmd, jVal + 1)
                iVal = InStr(1, lUrl, "://") + 3
                jVal = InStr(iVal, lUrl, "/")
                lHost = Mid$(lUrl, iVal, jVal - iVal)
                lUrl = Mid$(lUrl, iVal + Len(lHost))
                .Tag = lFunct + " " + lUrl + " " + lVer + vbCrLf + .Tag
                'CALL THE PROXY SOCKET
                ProxyServer = Index
                Load Winsock2(ProxyServer)
                Winsock2(ProxyServer).RemoteHost = lHost
                Winsock2(ProxyServer).RemotePort = 80
                Winsock2(ProxyServer).Connect
                DoEvents
            End If
        End With
    End Sub
    Private Sub Winsock2_Close(Index As Integer)
        On Error Resume Next
        Winsock1(Index).Close
        Winsock2(Index).Close
        Unload Winsock1(Index)
        Unload Winsock2(Index)
    End Sub
    Private Sub Winsock2_Connect(Index As Integer)
        On Error Resume Next
        Winsock2(Index).SendData Winsock1(Index).Tag
        DoEvents
    End Sub
    Private Sub Winsock2_DataArrival(Index As Integer, ByVal bytesTotal As Long)
        Dim lByte() As Byte
        Winsock2(Index).GetData lByte, vbByte
        Winsock1(Index).SendData lByte
        DoEvents
    End Sub


4) Run the program.

5) From another system, configure the browser proxy to be the system you're running this program on. (use port 80)


By the way, I think this is worth much more than 10 points... Don't you??  EE guidelines for asking questions are:

     50 points for an easy question
     100 points for a moderate question
     200 points for a hard question


Cheers!.)

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:ayrezyle
ID: 2726462
Adjusted points from 10 to 100
0
 
LVL 1

Author Comment

by:ayrezyle
ID: 2726463
Let me settle this one before someone draws blood :-) My case is a special one. Firstly, I am a C++ fan and also like nice & tight code. However, I don't have the time to learn VC++ which is my first choice of platform for this app. I'm already strong on VB using COM, which is why I want to do this in VB. Later on, I can migrate the component doing the actual work to a nice & tight VC++ COM component using ATL and all those niceties.

Why VB on NT? I want to create management features for a proxy; the proxy itself doesn't concern me much.

Regarding the performance issue: I'm running this proxy on a dual Pentium 2 350Mhz (200+MB RAM) servicing 40 people sharing a single 64kbps line. It won't break a sweat.

mcrider, you'll notice I've already upped the points :) You're #1 atm, I'll check out the code tonight.
0
 
LVL 1

Author Comment

by:ayrezyle
ID: 2727977
mcrider, I'm impressed!! Cut&Paste and it works! now I need to sit down and check out what you did!

I take it you've previously worked with TCP/IP headers?

One more thing... I assume that if I match the port numbers to the requested ports, I'll be able to use SSL and FTP too? (FTP will be a different header though; will SSL?)

How much memory does that control array take (per element)?

Where on the Net do I get a description of those headers?
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2731949
>>mcrider, I'm impressed!! Cut&Paste and it works!

Glad I could help you... It's not very often that I post code that dies when you cut and paste it. ;-)

Yes, I have worked with TCP headers.  In fact, Secure Firewall Technology (not in VB) is where I've made my millions.  As for SSL, you should be able to change the ports, however, FTP is a multi-socket protocol and it is *MUCH* more difficult.  It requires 2 separate sockets... Ports 20 and 21.

I suggest that if you are going to be going deep in this subject, you look at the RFCs for each protocol.  You can find them by going to http://www.yahoo.com and doing a search for "+RFC +FTP" (don't use the quotes)


Cheers!®©
0
 

Expert Comment

by:keyen
ID: 7917395
Hey,

i know it's been nearly 3 years since this thread has started however i've just found it.

i've created the program and it runs semi well. I get inconsistent results.

if i point my broswer to the proxy and point my browser to a site such as www.google.com i get inconsitent results. The first time only half the page will come through, the second time even less then the next time the page will come in fully and so on.

Any thoughts?
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The purpose of this article is to demonstrate how we can use conditional statements using Python.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now