VULN_CHECK_I913V6  ̄9ddlZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z m Z m Z ddlmZddlmZddlmZmZdZdZd e eefd e efd Zd e eefd e efd ZGd deZGddeZdeded e eeffdZded efdZde eefd efdZ ded efdZ!de eefd efdZ"de eefd efdZ#d5dede e ed e efdZ$dZ%d efd!Z&d"Z'd#Z(d ed$efd%Z)d&ed'ed e efd(Z*d&ed e efd)Z+d6d+Z,d,Z-d7d.ed/efd0Z.d5d/efd1Z/d5d/efd2Z0d3Z1d4Z2dS)8N)Path)UnionIterableOptionalTupleList)Enum)ClPwd)get_rhn_systemid_value is_ubuntuz0/opt/cpvendor/config/cl-manager-ui-settings.jsonipathreturnc tj|tjtjztjztjz}n#t $rYdSwxYw tjtj |j s tj |dStj |ttj |S#t $rYtj |dSwxYw#tj |wxYw)aT Read at most _MAX_DROP_IN_BYTES from an untrusted per-user path, refusing symlinks (O_NOFOLLOW) and non-regular files (FIFO/device fstat guard). O_NONBLOCK keeps the open of a planted FIFO/device from blocking. Returns the bytes read, or None if the path is a symlink, not a regular file, or cannot be opened/read. N)osopenO_RDONLY O_NOFOLLOW O_NONBLOCK O_CLOEXECOSErrorstatS_ISREGfstatst_modecloseread_MAX_DROP_IN_BYTES)r fds /builddir/build/BUILDROOT/alt-python27-cllib-3.4.41-1.el10.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/clwpos_lib.py_safe_read_bytesr s WT2;6FU V V tt|BHRLL011   wr-..       s<AA AA+C C C-C0,C--C00DcVt|}|dS|ddS)z Same guarantees as _safe_read_bytes, decoded as utf-8 (errors ignored to match the callers' historic open(..., errors='ignore')). Returns None on refusal so callers fall through to their not-found path. Nutf-8ignore)errors)r decode)r datas r_safe_read_textr'5s1 D ! !D |t ;;wx; 0 00ceZdZdZdZdZdS) PluginTypez2 Plugin types that are currently detected z object-cachezadvanced-cacheN)__name__ __module__ __qualname____doc__ OBJECT_CACHEADVANCED_CACHEr(rr*r*As$"L%NNNr(r*ceZdZdZdZdZdZdS) WpPluginszj Static WP plugin names, that are not detected dynamically from drop-in files, dir names, etc Unknownz WP Rocket AccelerateWPN)r+r,r-r.UNKNOWN WP_ROCKET ACCELERATE_WPr1r(rr3r3Is)GI"MMMr(r3lineis_multiline_commentc |r[d|vrdS|d}t|d|d\}}t||dzdd\}}||z|fSd|vr!|d}|d|dfSd|vr!|d}|d|dfSd |vrU|d }t|d|d\}}t||dzdd\}}||z|fS|dfS) z Yep, this bicycle is needed to handle different comment types in .php file https://www.php.net/manual/en/language.basic-syntax.comments.php and ensure that needed line is not under comment z*/)TNTFz//#z/*)find clean_comment)r9r:pospart1_part2s rr@r@Ss; 7 t  8))D//C$T$3$Z66HE1*7S1WXX*N*N 'E'5="66 6 t||iiooDSDz5   d{{iinnDSDz5   t||iioo dsdU33q&3DqND&I&I##u}222 ;r(filec~tj|}tj|SN)rr realpathisfile)rE realpath_files r _is_real_filerKss+G$$T**M 7>>- ( ((r(abs_pathcX tj|d}tj|rt |rdSn#t $rYnwxYwtj|tj}tj|d}tj|d}tj|ot |}tj|o| ot |S)a& WordPress looks for wp-config.php file in the (1) WordPress root and (2) one directory above the root. Check that there is no wp-settings.php file in the second case. This check helps when there is a nested installation, e.g / is WordPress and /wp_path/ is WordPress. wp-config.phpTzwp-settings.php)rr joinexistsrKrpardir)rL wp_config_phpabs_path_level_upwp_config_php_level_upwp_settings_phpwp_settings_php_existss r_check_wp_config_phprWxs  X?? 7>>- ( ( ]=-I-I 4       Xry99W\\*;_MMgll#46GHHOW^^O<<_A_A_ 7>>0 1 1 1% % 1 / 0 01sAA A A dirc~tj|}tj|SrG)rr rHisdir)rX realpath_dirs r _is_real_dirr\s+7##C((L 7== & &&r(ctj|d}dtj|vot |S)z. Check wp-includes exists and is dir. z wp-includes)rr rOlistdirr\)rL wp_includess r_check_wp_includesr`s;',,x77K BJx00 0 N\+5N5NNr(c tj|sdSn#t$rYdSwxYwt |jdrdS t|ot|S#t$rYnwxYwdS)z Checks whether passed directory is a wordpress directory by checking presence of wp-includes folder and wp-config.php file. Fz .wp-toolkit) rr rPrrname startswithrWr`)rLs r is_wp_pathrds w~~h'' 5  uu H~~%%m44u #H--N2DX2N2NN       5s$ 22A== B  B doc_rootexcludesc#<Ktj|sdSt|rdVt |D]C}|s|rt||vr+t|r |jVDdS)z Returns folder with wordpress Empty string is wp is in docroot dir :param doc_root: root path to start search from :param excludes: list of paths that must be excluded from search, e.g. subdomains Nr<) rr rPrdriterdiris_dirstrrb)rerfr s r find_wp_pathsrks 7>>( # #(X&&(({{}}    D X--  d   )OOOr(ctjd|d|d}t|}|dSd}|D]-}t ||\}}||rdS.dS)z8 Looks for defined php variable with true value z^\s*define\s*\(\s*((\'z\')|(\"z\"))\s*,\s*true\s*\)\s*;NFT)recompiler' splitlinesr@match)varr rcontentr:r9 cleaned_lines r_is_php_define_var_foundrus VSVVVVVWWAd##Gu ""$$-:4AU-V-V* * 77<  44  5r(wordpress_pathc|d}tj|sdSt d|S)z Detects whether plugin is really enabled, cause not all plugins are enabled 'on load' # https://kevdees.com/what-are-wordpress-drop-in-plugins/ rNFWP_CACHE)joinpathrr rPru)rv wp_configs ris_advanced_cache_enabledr{sB ''88I 7>>) $ $u #J : ::r(cft|!td|rtjjSdS)z They are advising to check whether WP_ROCKET_ADVANCED_CACHE is defined to ensure plugin is working https://docs.wp-rocket.me/article/134-advanced-cache-error-message NWP_ROCKET_ADVANCED_CACHE)accelerate_wp_pluginrur3r7value) drop_in_paths rwp_rocket_pluginrs6 L))1 $%? N N2"(( 4r(cRt|}|d|vrtjjSdS)zB Checking if the plugin folder name exists in the drop-in Nz/clsop)r'r3r8r)rrss rr~r~s2l++Gx722&,, 4r( plugin_typec|d}||d}tj|sdS|tjjkrt|sdS|d}t||p=t|p.t|pt|ptj j}|S)a Looking for object-cache.php or advanced-cache.php in wordpress folder If found - tries to find 'plugin-owner' of <-cache>.php by content comparison If cannot be found -> tries to read <-cache>.php headers looking for Plugin name: z wp-contentz.phpNplugins)ryrr rPr*r0rr{$get_wp_cache_plugin_by_scanning_dirsget_wp_cache_plugin_by_headerr~rr3r6)rvrwp_content_diractivated_cache plugins_dir plugin_names rget_wp_cache_pluginrs$,,\::N$--.B.B.BCCO 7>>/ * *tj/555>WXf>g>g5t )))44K6 TT-2?CC-)/::-&o66-&,  r(activated_pluginrcd|sdS|sdSt|}|dS|D][}t j|D]D\}}}|j|vr5t||jz }t||kr |jccSE\dS)zT Scanning plugins/* dir and looking for similar .php N)is_filerir rhrwalkrbr)rractivated_plugin_bytespluginrootdirsfilesplugin_object_cache_paths rrrs  # # % %t     t-.>??%t%%''''!# ' ' D$$--+/::8H8M+M(#$<==AWWW!;&&&&&  ' 4r(cJtj|sdSd}tjdtj}t |}|dS|d|D]0}||}|| dcS1dS)zS Looking for Plugin name: in headers Nz-^.*plugin name:\s*(?P[\w ]+)\s*$r) rr rPrmrn IGNORECASEr'rosearchgroup)rmax_top_lines_countrrrsr9rps rrr2s 7>>* + +t CR]SSA.//Gt""$$%9&9%9:..  ;;}-- - - -  4r( object_cachecg} t|}n#tj$rgcYSwxYwtj|dd}tj|sgSt|}|gS tj |}n#t$rgcYSwxYw| di di}|D]%} | |vr||| vr| | &|S)z? Filter user`s wp paths with paths with enabled module z.clwposzclwpos_config.jsonNdocroots public_html) r get_homedirNoSuchUserExceptionrr rOrPr'jsonloads Exceptiongetappend) user user_wp_pathsrpaths_with_enabled_modulehomeconfigconfr& modules_datawp_paths r get_wp_paths_with_enabled_modulerGs>!#ww""4((  $ W\\$ +? @ @F 7>>& ! ! 6 " "D | z$  88J++// rBBL 66 l " "vg1F'F'F % , ,W 5 5 5 $$s!&::B(( B76B7c g}tjds|dtjds|dtjds|d|r_ddi}t r gd |z}d |d <ngd |z}t j|d d d|}tjd|j |j tjds:t jddgd d d}tjd|j |j t jgdd d d}tjd|j |j td}|rRt jddd| ddgd d d}tjd|j |j dSdS)N/usr/bin/cloudlinux-awp-adminz accelerate-wpz /usr/sbin/cloudlinux-ssa-managerz alt-php-ssaz/usr/sbin/cloudlinux-xray-agentz alt-php-xrayPATHz/usr/sbin:/usr/bin:/sbin:/bin)z/usr/bin/apt-get-yinstallnoninteractiveDEBIAN_FRONTEND)z /usr/bin/yumrrTF)capture_outputtextcheckenvz:Installing AccelerateWP packages captured out: %s, err: %sz/usr/share/clos_ssa/ssa_enabledz enable-ssa)rrrz(Activation SSA captured out: %s, err: %s)z /usr/sbin/cloudlinux-autotracingenablez--allz0Activation autotracing captured out: %s, err: %s system_idz!/usr/sbin/cloudlinux-xray-managerzenable-user-agentz --system_idzID-r<z1Activation xray manager captured out: %s, err: %s) rr rPrr subprocessrunloggingdebugstdoutstderrr replace)packagesrinstall_commandprocrs rinstall_accelerate_wpres.H 7>>9 : :)((( 7>>< = =' &&& 7>>; < <(''' n67 ;; KCCChNO%5C! " "???(JO~odUZ`cddd RTXT_aealmmm 7>>; < <\~A<P-1EKKK @$+t{[[[ >???     D  MDdkSWS^___&{33Ie~ 02E}V_VgVghmoqVrVr s      I4;X\Xcdddddeer(Fasync_set_suitesourcecttjdrdStjtrt tdd5}t j|}dddn #1swxYwY|diddurtj d dSgd }|d kr| d d g|r-tj |tjtj dStj|ddd}tj d|j|jdS)zh 1. Installs needed packages 2. Enables autotracing 3. Allows AccelerateWP Free for all z8/var/clwpos/admin/allowed_for_all_site_optimization.flagNrrr")encodingfeatures_override accelerate_wpFzWActivation AccelerateWP Free skipped: Vendor UI skip the enabling of Accelerate WP Free)r set-suite--allowed-for-all--suitesrBILLING_OVERRIDE--source)rrTrrrz6Activation AccelerateWP Free captured out: %s, err: %s)rrr rPVENDOR_UI_CONFIG_PATHrrloadrrrextendrPopenPIPErrr)rrfvendor_config_contentcommandrs rconfigure_accelerate_wprs  w~~PQQ w~~+,, 'w ? ? ? 11$(IaLL ! 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ! $ $%8" = = A A/ R RV[ [ [ Ms t t t F   G ### $67888j ??      ~gT$TRRR NPTP[]a]hiiiiis+B  BBcttjdrdSgd}|dkr|gdt j|ddd}tjd|j |j dS)Nz3/var/clwpos/admin/allowed_for_all_object_cache.flag)rr--visible-for-allraccelerate_wp_premiumrrrz--preserve-user-settingsTrz9Activation AccelerateWP Premium captured out: %s, err: %s rrr rPrrrrrrr)rrrs rconfigure_accelerate_wp_premiumrs w~~KLL(((G###SSSTTT >'d N N ND MMt{\`\ghhhhhr(cttjdrdSgd}|dkr|ddgt j|ddd}tjd|j |j gd}|dkr|gd t j|ddd}tjd |j |j dS) Nz*/var/clwpos/admin/allowed_for_all_cdn.flag)rrrraccelerate_wp_cdnrrTrz5Activation AccelerateWP CDN captured out: %s, err: %s)rrrraccelerate_wp_cdn_prorz9Activation AccelerateWP CDN PRO captured out: %s, err: %sr)r command_cdnrcommand_cdn_pros rconfigure_accelerate_wp_cdnrs  w~~BCC(((K###J(:;<<< >+T$T R R RD MI4;X\Xcddd000O###[[[\\\ >/dQU V V VD MMt{\`\ghhhhhr(c&|sdStjddgdddj}tj|}||dkrdStjddd|dd gddd}t jd |j|jdS) Nrz get-optionsTr upgrade_urlz set-optionsz --upgrade-urlz--suiterzBSetting AccelerateWP Premium upgrade url captured out: %s, err: %s) rrrrrrrrr)r options_jsonoptionsrs rconfigure_upgrade_urlrs >#BM"R#',0"&((()/j&&Ggkk-0000 >:(*&$2 4 !%)-# % % %D MV+t{,,,,,r(ctjdp^tjdp?tjdp tjdpdS)z Locale could be set via those envvars, let`s get them in same priority gettext does for envar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'): LANGUAGE = (unset), LC_ALL = (unset), LC_MESSAGES = "UTF-8", LANG = "uk_UA.UTF-8" LANGUAGELC_ALL LC_MESSAGESLANGen_US)renvironrr1r(rget_locale_from_envarsrsh JNN: & & z~~h'' z~~m,, z~~f%%  r(rG)r)FN)3rrmrrrrpathlibrtypingrrrrrenumr clcommon.clpwdr clcommon.utilsr r rrrjbytesr r'r*r3boolr@rKrWr\r`rdrkrur{rr~rrrrrrrrrrr1r(rrs@ 99999999999999 <<<<<<<<K !5d+, 1%T * 1x} 1 1 1 1&&&&&&&&########4E#t)(SV-6" ;d ; ; ; ;   3.4dW_`cWd,DXc]*%%%%<+e+e+e\%j%jT%j3%j%j%j%jPiiCiiii,!i!i!i!i!i!iH,,,6     r(