Last active
January 8, 2024 03:19
-
-
Save sharpicx/c619ad01c73cacb9a7052e7838ed8457 to your computer and use it in GitHub Desktop.
FRP with Flask (REST API) VPS Tunnel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request | |
from flask_ipfilter import IPFilter, Whitelist | |
import requests | |
app = Flask(__name__) | |
HTTP_METHODS = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH'] # getting all methods work on the target | |
ip_filter = IPFilter(app, ruleset=Whitelist()) | |
ip_filter.ruleset.permit("xxx.xxx.xx.x") # whitelisting my office public IP | |
@app.route('/', defaults={'path': ''}, methods=HTTP_METHODS) | |
@app.route('/<path:path>', methods=HTTP_METHODS) | |
def forward_request(path): | |
url = f'http://xx.xxx.xx.xx:83/{path}' | |
headers = {'Content-Type': 'application/xml'} | |
xml_data = request.data | |
response = requests.post(url, headers=headers, data=xml_data) | |
return response.content, response.status_code | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=8080) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[common] | |
server_addr = xx.xx.xx.xxx | |
server_port = 8080 | |
vhostHTTPPort = 8083 | |
[http] | |
type = http | |
local_ip = 127.0.0.1 | |
local_port = 8080 | |
#remote_port = 8383 | |
custom_domains = "api.test.com" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment