I thought about everything, from books to shoes to electronics to groceries, feeling like I had everything, and said, “Save your money. I don’t need anything.”

She insisted: “No, you must say a gift, I want to give you something.”

So, I seriously up, picked up the phone, taobao shopping for a few minutes, but still failed to come out of the shortcomings of what, and finally there is no way: “Well, if you really want to send things, then you write a proxy server.”

Without saying anything, she laughed and wrote this blog post.

define

Allows one network endpoint (typically a client) to make indirect connections to another network endpoint (typically a server) through this service. As shown in the figure, the communication mode of common Web application is compared with that of proxy server.

The principle of

Proxy server in the specified port (e.g., 8080) to monitor the browser’s access request (need to the corresponding Settings in the client browser), receives the browser on a remote web site to browse request, the proxy server began to cache in the proxy server to retrieve the URL corresponding to the object (web pages, images and other objects), after the found object files, Extract the last modified time of the object file; The proxy server program inserts < if-modified-since: last Modified time of the object file > in the client’s request header and forwards the Modified request message to the original Web server. If the proxy server does not have the cache of the object, it directly forwards the request packet to the original server, forwards the response from the original server to the client, and caches the object to the proxy server. The proxy server program cleans the cache based on its time, size, and extraction records. This experiment needs to implement a simple HTTP proxy server, which can be divided into two steps :(first, set the browser to enable the local proxy, and ensure that the proxy port is consistent with the listening port of the proxy server).

content

  1. Design and implement a basic HTTP proxy server. It is required to receive HTTP requests from customers on the specified port (for example, 8080) and access the HTTP server (the original server) based on the URL, receive the response packets from the HTTP server, and forward the response packets to the corresponding customers for browsing.
  2. Design and implement an HTTP proxy server supporting Cache function. It is required to be able to cache the object responded by the original server, and to confirm to the original server whether the cached object is the latest version by modifying the request message (adding the if-Modified-since header line). (Optional content, bonus points, can be completed in class or after class)
  3. Extend the HTTP proxy server to support the following functions: a) Website filtering: allow/deny access to certain websites; B) User filtering: support/deny the access of some users to external websites; C) Website guidance: direct users’ access to a website to a simulated website (phishing).

process

Setting the Browser Proxy

Take Internet Explorer as an example: Open the browser tool. Browser options — Connection — LAN Settings — Proxy server. Set the address to 127.0.0.1 and port number to 10240.

Implement a basic HTTP proxy server

An HTTP proxy server is used by a network terminal (typically a client) to make indirect connections to another network terminal (typically a server) through a proxy service. The flow chart of the design is as follows:

Cache function

  1. When a client requests data from the server for the first time, the proxy server caches the response returned by the request and stores it in a local file.
  2. When the client accesses the data a second time, the proxy server checks whether there is a response to the request locally, and if not, continues caching; If yes, it sends a request to the server and compares the last modification time to determine whether the cache has expired. If the server returns the status code 304, the cache has not expired. If the server returns a status code of 200, the cache expires and the local cache is updated.
  3. Function (1) getfileDate() function: Access the local file and obtain the date in the local cache. (2) sendnewHTTP() function: Modify the request message by adding if-modified-since header line. (3) The storefileCache() function checks the status code returned by the host. If the value is 304, the host obtains the status code from the local cache and forwards it. Otherwise, the cache needs to be updated

Implement extended functions

Web site filtering

Start by setting a URL that does not allow access to the site

The user filter

Change the network communication IP address of the proxy server from INADDR_ANY to a specific IP address. In this way, only this IP address can access external websites through the proxy server

Site guide

Start by setting up the target site and the corresponding phishing site and host name

The source code

Github code link

If anything? Hope old iron people to a double combo, to more people see this article

1. Old friends, follow my original wechat public account “Progress of program Ape”, mainly about IT and competition

2, creation is not easy, by the way, click a “like”, can let more people see this article, inspire me this white.