Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
python-proxy/pproxy/plugin.py at master · default-github-user/python-proxy · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
default-github-user
/
python-proxy
Public
forked from
qwj/python-proxy
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
python-proxy
/
pproxy
/
plugin.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
158 lines (144 loc) · 7.03 KB
master
Breadcrumbs
python-proxy
/
pproxy
/
plugin.py
Copy path
Top
File metadata and controls
Code
Blame
158 lines (144 loc) · 7.03 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import
datetime
,
zlib
,
os
,
binascii
,
hmac
,
hashlib
,
time
,
random
,
collections
packstr
=
lambda
s
,
n
=
2
:
len
(
s
).
to_bytes
(
n
,
'big'
)
+
s
toint
=
lambda
s
,
o
=
'big'
:
int
.
from_bytes
(
s
,
o
)
class
BasePlugin
(
object
):
async
def
init_client_data
(
self
,
reader
,
writer
,
cipher
):
pass
async
def
init_server_data
(
self
,
reader
,
writer
,
cipher
,
raddr
):
pass
def
add_cipher
(
self
,
cipher
):
pass
@
classmethod
def
name
(
cls
):
return
cls
.
__name__
.
replace
(
'_Plugin'
,
''
).
replace
(
'__'
,
'.'
).
lower
()
class
Plain_Plugin
(
BasePlugin
):
pass
class
Origin_Plugin
(
BasePlugin
):
pass
class
Http_Simple_Plugin
(
BasePlugin
):
async
def
init_client_data
(
self
,
reader
,
writer
,
cipher
):
buf
=
await
reader
.
read_until
(
b'
\r
\n
\r
\n
'
)
data
=
buf
.
split
(
b' '
)[:
2
]
data
=
bytes
.
fromhex
(
data
[
1
][
1
:].
replace
(
b'%'
,
b''
).
decode
())
reader
.
_buffer
[
0
:
0
]
=
data
writer
.
write
(
b'HTTP/1.1 200 OK
\r
\n
Connection: keep-alive
\r
\n
Content-Encoding: gzip
\r
\n
Content-Type: text/html
\r
\n
Date: '
+
datetime
.
datetime
.
now
().
strftime
(
'%a, %d %b %Y %H:%M:%S GMT'
).
encode
()
+
b'
\r
\n
Server: nginx
\r
\n
Vary: Accept-Encoding
\r
\n
\r
\n
'
)
async
def
init_server_data
(
self
,
reader
,
writer
,
cipher
,
raddr
):
writer
.
write
(
f'GET / HTTP/1.1
\r
\n
Host:
{
raddr
}
\r
\n
User-Agent: curl
\r
\n
Accept-Encoding: gzip, deflate
\r
\n
Connection: keep-alive
\r
\n
\r
\n
'
.
encode
())
await
reader
.
read_until
(
b'
\r
\n
\r
\n
'
)
TIMESTAMP_TOLERANCE
=
5
*
60
class
Tls1__2_Ticket_Auth_Plugin
(
BasePlugin
):
CACHE
=
collections
.
deque
(
maxlen
=
100
)
async
def
init_client_data
(
self
,
reader
,
writer
,
cipher
):
key
=
cipher
.
cipher
(
cipher
.
key
).
key
assert
await
reader
.
read_n
(
3
)
==
b'
\x16
\x03
\x01
'
header
=
await
reader
.
read_n
(
toint
(
await
reader
.
read_n
(
2
)))
assert
header
[:
2
]
==
b'
\x01
\x00
'
assert
header
[
4
:
6
]
==
b'
\x03
\x03
'
cacheid
=
header
[
6
:
28
]
sessionid
=
header
[
39
:
39
+
header
[
38
]]
assert
cacheid
not
in
self
.
CACHE
self
.
CACHE
.
append
(
cacheid
)
utc_time
=
int
(
time
.
time
())
assert
hmac
.
new
(
key
+
sessionid
,
cacheid
,
hashlib
.
sha1
).
digest
()[:
10
]
==
header
[
28
:
38
]
assert
abs
(
toint
(
header
[
6
:
10
])
-
utc_time
)
<
TIMESTAMP_TOLERANCE
addhmac
=
lambda
s
:
s
+
hmac
.
new
(
key
+
sessionid
,
s
,
hashlib
.
sha1
).
digest
()[:
10
]
writer
.
write
(
addhmac
((
b"
\x16
\x03
\x03
"
+
packstr
(
b"
\x02
\x00
"
+
packstr
(
b'
\x03
\x03
'
+
addhmac
(
utc_time
.
to_bytes
(
4
,
'big'
)
+
os
.
urandom
(
18
))
+
b'
\x20
'
+
sessionid
+
b'
\xc0
\x2f
\x00
\x00
\x05
\xff
\x01
\x00
\x01
\x00
'
))
+
(
b"
\x16
\x03
\x03
"
+
packstr
(
b"
\x04
\x00
"
+
packstr
(
os
.
urandom
(
random
.
randrange
(
164
)
*
2
+
64
)))
if
random
.
randint
(
0
,
8
)
<
1
else
b''
)
+
b"
\x14
\x03
\x03
\x00
\x01
\x01
\x16
\x03
\x03
"
+
packstr
(
os
.
urandom
(
random
.
choice
((
32
,
40
)))))[:
-
10
]))
async
def
init_server_data
(
self
,
reader
,
writer
,
cipher
,
raddr
):
key
=
cipher
.
cipher
(
cipher
.
key
).
key
sessionid
=
os
.
urandom
(
32
)
addhmac
=
lambda
s
:
s
+
hmac
.
new
(
key
+
sessionid
,
s
,
hashlib
.
sha1
).
digest
()[:
10
]
writer
.
write
(
b"
\x16
\x03
\x01
"
+
packstr
(
b"
\x01
\x00
"
+
packstr
(
b'
\x03
\x03
'
+
addhmac
(
int
(
time
.
time
()).
to_bytes
(
4
,
'big'
)
+
os
.
urandom
(
18
))
+
b"
\x20
"
+
sessionid
+
b"
\x00
\x1c
\xc0
\x2b
\xc0
\x2f
\xcc
\xa9
\xcc
\xa8
\xcc
\x14
\xcc
\x13
\xc0
\x0a
\xc0
\x14
\xc0
\x09
\xc0
\x13
\x00
\x9c
\x00
\x35
\x00
\x2f
\x00
\x0a
\x01
\x00
"
+
packstr
(
b"
\xff
\x01
\x00
\x01
\x00
\x00
\x00
"
+
packstr
(
packstr
(
b"
\x00
"
+
packstr
(
raddr
.
encode
())))
+
b"
\x00
\x17
\x00
\x00
\x00
\x23
"
+
packstr
(
os
.
urandom
((
random
.
randrange
(
17
)
+
8
)
*
16
))
+
b"
\x00
\x0d
\x00
\x16
\x00
\x14
\x06
\x01
\x06
\x03
\x05
\x01
\x05
\x03
\x04
\x01
\x04
\x03
\x03
\x01
\x03
\x03
\x02
\x01
\x02
\x03
\x00
\x05
\x00
\x05
\x01
\x00
\x00
\x00
\x00
\x00
\x12
\x00
\x00
\x75
\x50
\x00
\x00
\x00
\x0b
\x00
\x02
\x01
\x00
\x00
\x0a
\x00
\x06
\x00
\x04
\x00
\x17
\x00
\x18
"
))))
writer
.
write
(
addhmac
(
b'
\x14
\x03
\x03
\x00
\x01
\x01
\x16
\x03
\x03
\x00
\x20
'
+
os
.
urandom
(
22
)))
def
add_cipher
(
self
,
cipher
):
self
.
buf
=
bytearray
()
def
decrypt
(
s
):
self
.
buf
.
extend
(
s
)
ret
=
b''
while
len
(
self
.
buf
)
>=
5
:
l
=
int
.
from_bytes
(
self
.
buf
[
3
:
5
],
'big'
)
if
len
(
self
.
buf
)
<
l
:
break
if
self
.
buf
[:
3
]
in
(
b'
\x16
\x03
\x03
'
,
b'
\x14
\x03
\x03
'
):
del
self
.
buf
[:
5
+
l
]
continue
assert
self
.
buf
[:
3
]
==
b'
\x17
\x03
\x03
'
data
=
self
.
buf
[
5
:
5
+
l
]
ret
+=
data
del
self
.
buf
[:
5
+
l
]
return
ret
def
pack
(
s
):
return
b'
\x17
\x03
\x03
'
+
packstr
(
s
)
def
encrypt
(
s
):
ret
=
b''
while
len
(
s
)
>
2048
:
size
=
min
(
random
.
randrange
(
4096
)
+
100
,
len
(
s
))
ret
+=
pack
(
s
[:
size
])
s
=
s
[
size
:]
if
s
:
ret
+=
pack
(
s
)
return
ret
cipher
.
pdecrypt2
=
decrypt
cipher
.
pencrypt2
=
encrypt
class
Verify_Simple_Plugin
(
BasePlugin
):
def
add_cipher
(
self
,
cipher
):
self
.
buf
=
bytearray
()
def
decrypt
(
s
):
self
.
buf
.
extend
(
s
)
ret
=
b''
while
len
(
self
.
buf
)
>=
2
:
l
=
int
.
from_bytes
(
self
.
buf
[:
2
],
'big'
)
if
len
(
self
.
buf
)
<
l
:
break
data
=
self
.
buf
[
2
+
self
.
buf
[
2
]:
l
-
4
]
crc
=
(
-
1
-
binascii
.
crc32
(
self
.
buf
[:
l
-
4
]))
&
0xffffffff
assert
int
.
from_bytes
(
self
.
buf
[
l
-
4
:
l
],
'little'
)
==
crc
ret
+=
data
del
self
.
buf
[:
l
]
return
ret
def
pack
(
s
):
rnd_data
=
os
.
urandom
(
os
.
urandom
(
1
)[
0
]
%
16
)
data
=
bytes
([
len
(
rnd_data
)
+
1
])
+
rnd_data
+
s
data
=
(
len
(
data
)
+
6
).
to_bytes
(
2
,
'big'
)
+
data
crc
=
(
-
1
-
binascii
.
crc32
(
data
))
&
0xffffffff
return
data
+
crc
.
to_bytes
(
4
,
'little'
)
def
encrypt
(
s
):
ret
=
b''
while
len
(
s
)
>
8100
:
ret
+=
pack
(
s
[:
8100
])
s
=
s
[
8100
:]
if
s
:
ret
+=
pack
(
s
)
return
ret
cipher
.
pdecrypt
=
decrypt
cipher
.
pencrypt
=
encrypt
class
Verify_Deflate_Plugin
(
BasePlugin
):
def
add_cipher
(
self
,
cipher
):
self
.
buf
=
bytearray
()
def
decrypt
(
s
):
self
.
buf
.
extend
(
s
)
ret
=
b''
while
len
(
self
.
buf
)
>=
2
:
l
=
int
.
from_bytes
(
self
.
buf
[:
2
],
'big'
)
if
len
(
self
.
buf
)
<
l
:
break
ret
+=
zlib
.
decompress
(
b'x
\x9c
'
+
self
.
buf
[
2
:
l
])
del
self
.
buf
[:
l
]
return
ret
def
pack
(
s
):
packed
=
zlib
.
compress
(
s
)
return
len
(
packed
).
to_bytes
(
2
,
'big'
)
+
packed
[
2
:]
def
encrypt
(
s
):
ret
=
b''
while
len
(
s
)
>
32700
:
ret
+=
pack
(
s
[:
32700
])
s
=
s
[
32700
:]
if
s
:
ret
+=
pack
(
s
)
return
ret
cipher
.
pdecrypt
=
decrypt
cipher
.
pencrypt
=
encrypt
PLUGIN
=
{
cls
.
name
():
cls
for
name
,
cls
in
globals
().
items
()
if
name
.
endswith
(
'_Plugin'
)}
def
get_plugin
(
plugin_name
):
if
plugin_name
not
in
PLUGIN
:
return
f'existing plugins:
{
sorted
(
PLUGIN
.
keys
())
}
'
,
None
return
None
,
PLUGIN
[
plugin_name
]()
You can’t perform that action at this time.