B4J Tutorial [B4X] Proxy Server Socks 4 and Proxy Http (Source Code)

Many years ago I needed to sniff a connection and I didn't have a free sniffer available and I didn't know how to create one .... So after a long reflection I decided to create a Proxy Server in order to direct all the output of my pc to the server and sniff traffic.
It was my first proxy server made in VB6. This was the beginning of the development of a series of Applications for the network ... Alternative Clients (at the time there was MSN Messenger) etc ...

Today I wanted to recreate the Socks4 proxy server in B4X. Please find attached a simplified version that works.
With this example you can spy on traffic or actually use it as a proxy server. It is also possible to modify the traffic or inject other data in order to alter it .... well the possibilities are many, it's up to your imagination.

Don't forget to set up the proxy on your PC, in this way:
1623734190607.png
1623734239100.png
1623702997494.png


Attention it also works for B4A and B4i but set an accessible port for mobile devices (for example 51051)
For convenience I am ignoring the authentication that many proxy servers do not exist.
the Socks4 protocol provides only the management of the TCP connection while the sock5 also UDP
 

Attachments

  • Sock4.zip
    5.6 KB · Views: 313
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Someone asked me to sniff the http connection (port 80). The http protocol does not go through the Socks4 but from the http proxy, so I also inserted an http proxy server. Note that the https protocol (port 443) with ssl / tls uses the sock4 proxy server.
I also added a little code on the http proxy server for redirection. For example, try typing WWW.EREL.ORG (or .COM .US etc ..) and see what result you will have

I hope I have given you some food for thought.


To also set the Http proxy server do this:
1623749895439.png
 

Attachments

  • Sock4.zip
    5.6 KB · Views: 222
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
One of the uses of this code, in addition to working as a proxy, to sniff the connection can be used in internet cafes to force a login page before accessing the internet. As well as in all places where it is possible to use Wi-Fi after authentication
 

Magma

Expert
Licensed User
Longtime User
@Star-Dust how this could happen (login-page) ? + how difficult is to use socks v5 ?

As i saw the code... yes it sniffs - but where exactly the data ? are like parts of 8-bytes ? - is it actually possible to make an "if" data.trim.indexof ?
and how will push the client to browse a login page... will replace data browsing someway ?

And how fast is that all.. doesnt delay the data ?
 

Star-Dust

Expert
Licensed User
Longtime User
@Star-Dust how this could happen (login-page) ? + how difficult is to use socks v5 ?
redirecting the first access to a login page. Once logged in, the proxy allows the requested pages to be exited.

Socks5 isn't particularly complicated

As i saw the co
de... yes it sniffs - but where exactly the data ? are like parts of 8-bytes ? - is it actually possible to make an "if" data.trim.indexof ?
and how will push the client to browse a login page... will replace data browsing someway ?
If you see the second example I have inserted some notes that indicate where to sniff the traffic.

It is better to treat the data in bytes, if they are HTML pages just identify the Header and transform it into a string as I did in the second example.

On bytes it is possible to do any operation, there is a B4X library for this purpose

For the redirection as already written see the second example
And how fast is that all.. doesnt delay the data ?
all proxies cause a slight slowdown, it depends on the complexity of the data processing.
 

Magma

Expert
Licensed User
Longtime User
Socks5 isn't particularly complicated
so it is easy to make it ?

" redirecting the first access to a login page. " ---- how will make that ?


Thanks for you answers ! ---- all the project and the idea is very very very good - 1000000 bravo !
 

Star-Dust

Expert
Licensed User
Longtime User
so it is easy to make it ?

" redirecting the first access to a login page. " ---- how will make that ?


Thanks for you answers ! ---- all the project and the idea is very very very good - 1000000 bravo !
As I have written several times, see the second example. There is a redirect to the b4x page
 

Star-Dust

Expert
Licensed User
Longtime User
...........oops sorry :) - i thought was only for the ...search... the answer
You are one of the few who have managed to see the potential of a proxy...
 

Magma

Expert
Licensed User
Longtime User
@Star-Dust ...I have to say ofcourse ... that the new "logic" has to do only with Gateways or DNS sniffing /// or VPNs (that of course is a different idea)... that gives better (mim/ in the middle) control to all.... proxy always need a setup at client or need special routers/or servers....
 

Star-Dust

Expert
Licensed User
Longtime User
With Sock5 you can also intercept DNS requests that are sent over UDP protocol
 
Top