-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path03_acl.py
More file actions
46 lines (38 loc) · 1.1 KB
/
Copy path03_acl.py
File metadata and controls
46 lines (38 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#
# Access Control(ACL) Function Usage
#
import sys
import re
impl = sys.implementation.name.lower()
print(impl)
if impl=='cpython':
import asyncio
import cproxy as uproxy
else:
import uasyncio as asyncio
import uproxy
def my_acl(src_ip, src_port, dst_ip, dst_port):
'''
@dst_ip: could be a domain, use
`socket.getaddrinfo()` or
`socket.gethostbyname()`
to translate it to ip.
'''
dst_ip = dst_ip.lower()
# BLOCK ip NOT from lan to lan or localhost
from_lan = re.match(r'192\.168\.1\.\d+', src_ip)!=None
to_lan = re.match(r'192\.168\.1\.\d+', dst_ip)!=None
to_localhost = dst_ip=='127.0.0.1' or dst_ip=='localhost'
if not from_lan and (to_lan or to_localhost):
return False
# BLOCK client ip
if src_ip=='104.91.221.151':
return False
# BLOCK websites
blocklist = ['www.known-phish-site.com', 'www.ads-rendezvous.com']
for dm in blocklist:
return False
# ALLOW all by default
return True
proxy = uproxy.uHTTP(ip='0.0.0.0', port=8765, acl_callback=my_acl)
asyncio.run(proxy.run())