/proxy-server

A simple proxy server in C

Primary LanguageCMIT LicenseMIT

proxy-server in C

Programming language: C/C++
OS: Linux (Kali distro)
Multi processes

Turn on proxy

foo@bar:~$ make all
foo@bar:~$ exe/1712695 8888
#or
foo@bar:~$ exe/1712695 8888 filter_string

Turn off proxy

foo@bar:~$ pkill 1712695 --signal 12

1. GET/HEAD

  1. Filltering URLs
    input : $ ./ 8888 fit.hcmus.edu
  • Suffix filtering
    Test case: $ curl -v --proxy localhost:8888 http://www.fit.hcmus.edu/~lqvu/ -> missing suffix '.vn'
    Result: 403 (Forbidden) HTTP response. The proxy doesn't send the request to the web server
  • Prefix Filtering
    Test case: $ curl -v --proxy localhost:8 888 http://fit.hcmus.edu.vn/~lqvu/ -> missing prefix 'www.'
    Result: 403 (Forbidden) HTTP reponse.
  • Non-filtering case
    Test case: $ curl -v proxy localhost:8888 http://www.fit.hcmus.edu.vn/~lqvu/ -> has prefix and suffix
    Result: 301 (Moved Permanently) or 302 (Found) HTTP response from web server
  1. Simultaneously serve multiple requests
    Test case: $./conctest.sh
    (Script will open 4 terminals and each terminal will send a HTTP request to http://tuoitre.vn)
    Result: 200 (OK) HTTP reponses

  2. Signal handling

  • SIGUSR2 (5 points)
    Test case: $ pkill 1712695 --signal 12
    Result: Proxy shutdown
  • SIGINT
    Test case: Ctrl-C while executing
    Result: Program ignore SIGINT
  1. Memory leak
  • Proxy side
    $ valgrind --leak-check=full --show-reachable=yes ./ 8888
  • Client side
    $ curl -v --proxy localhost:8888 http://hcmus.edu.vn/
    Result:
    LEAK SUMMARY:
    definitely lost: 0 bytes in 0 blocks
    indirectly lost: 0 bytes in 0 blocks
    possibly lost: 0 bytes in 0 blocks
    still reachable: 0 bytes in 0 blocks
    suppressed: 0 bytes in 0 blocks
  1. Only allow GET and HEAD methods
    Test case: $ curl -v --proxy localhost:8888 -X OPTIONS http://hcmus.edu.vn/
    Result: 405 (Method Not Allowed) or 501 (Not Implemented) HTTP response.
    Proxy build custom response and send to client, doesn't send the request to web server.

  2. Non-HTTP request
    Bad HTTP request
    Test case: $ telnet localhost 8888
    <type ’abcdefg’ and enter>
    Result: Proxy ignores it and continue serving other requests