-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest13.py
More file actions
149 lines (121 loc) · 4.15 KB
/
Copy pathtest13.py
File metadata and controls
149 lines (121 loc) · 4.15 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
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
import socket
import hashlib
import re
PROJECTOR_IP = "10.168.222.248"
PASSWORD = "00000"
USERNAME = "EPSONWEB"
def md5(data):
return hashlib.md5(data.encode()).hexdigest()
def http_request_with_digest(method, path, username=USERNAME, password=PASSWORD, body=None):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
sock.connect((PROJECTOR_IP, 80))
request = f"{method} {path} HTTP/1.1\r\nHost: {PROJECTOR_IP}\r\nConnection: keep-alive\r\n\r\n"
sock.send(request.encode())
response = b""
while True:
try:
chunk = sock.recv(4096)
if not chunk:
break
response += chunk
if b"\r\n\r\n" in response and b"401" in response[:100]:
break
except:
break
response_str = response.decode('utf-8', errors='ignore')
auth_match = re.search(r'WWW-Authenticate: Digest (.+)', response_str)
if not auth_match:
sock.close()
return response
auth_params = {}
params_str = auth_match.group(1)
for match in re.finditer(r'(\w+)="?([^",]+)"?', params_str):
auth_params[match.group(1)] = match.group(2)
realm = auth_params.get('realm', '')
nonce = auth_params.get('nonce', '')
qop = auth_params.get('qop', '')
ha1 = md5(f"{username}:{realm}:{password}")
ha2 = md5(f"{method}:{path}")
nc = "00000001"
cnonce = "0a4f113b"
if qop:
response_hash = md5(f"{ha1}:{nonce}:{nc}:{cnonce}:{qop}:{ha2}")
else:
response_hash = md5(f"{ha1}:{nonce}:{ha2}")
auth_header = f'Digest username="{username}", realm="{realm}", nonce="{nonce}", uri="{path}", '
if qop:
auth_header += f'qop={qop}, nc={nc}, cnonce="{cnonce}", '
auth_header += f'response="{response_hash}"'
sock.close()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
sock.connect((PROJECTOR_IP, 80))
request = f"{method} {path} HTTP/1.1\r\n"
request += f"Host: {PROJECTOR_IP}\r\n"
request += f"Authorization: {auth_header}\r\n"
request += "Connection: close\r\n"
if body:
if isinstance(body, str):
body = body.encode()
request += f"Content-Length: {len(body)}\r\n"
request += "\r\n"
sock.send(request.encode())
if body:
sock.send(body)
response = b""
while True:
try:
chunk = sock.recv(4096)
if not chunk:
break
response += chunk
except:
break
sock.close()
return response
# Télécharger tous les fichiers JS
print("=== Recherche de l'utilisation de Commons.command ===\n")
js_files = [
"/rsrc/js/main.js?_=201603",
"/rsrc/js/home.js?_=201603",
]
all_calls = []
for js_file in js_files:
resp = http_request_with_digest("GET", js_file)
if b"\r\n\r\n" in resp:
body = resp.split(b"\r\n\r\n", 1)[1].decode('utf-8', errors='ignore')
# Chercher les appels à Commons.command
pattern = r'Commons\.command\s*\([^)]+\)'
matches = re.findall(pattern, body)
if matches:
print(f"Dans {js_file}:")
for match in matches:
print(f" {match}")
all_calls.append(match)
# Obtenir notre propre adresse IP locale
import socket as sock2
s = sock2.socket(sock2.AF_INET, sock2.SOCK_DGRAM)
try:
s.connect((PROJECTOR_IP, 80))
local_ip = s.getsockname()[0]
finally:
s.close()
print(f"\n\n=== Notre adresse IP locale: {local_ip} ===")
# Tester avec des paramètres de location
print("\n\n=== Tests avec paramètres de return location ===")
test_params = [
f"return={local_ip}",
f"location={local_ip}",
f"client={local_ip}",
f"ip={local_ip}",
f"host={local_ip}",
]
for param in test_params:
print(f"\nTest: /cgi-bin/directsend?{param}")
resp = http_request_with_digest("GET", f"/cgi-bin/directsend?{param}")
status = resp.split(b"\r\n")[0].decode() if resp else "No response"
print(f" -> {status}")
if b"200 OK" in resp and b"\r\n\r\n" in resp:
content = resp.split(b"\r\n\r\n", 1)[1][:500]
print(f" Content: {content.decode('utf-8', errors='ignore')}")