weak.jsp
10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<%@ page import="weaver.general.*,java.io.*,java.util.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="weaver.hrm.*" %>
<%@ page import="java.lang.reflect.Method" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="rs1" class="weaver.conn.RecordSet" scope="page"/>
<html>
<head>
<title>高效源于协同</title>
<%--<link rel="stylesheet" href="/css/frame.css" type="text/css">--%>
<script type="text/javascript">
function lockAccount() {
if (confirm("确认要禁用弱密码账号吗?")) {
location.href = "weak.jsp?src=1";
}
}
</script>
</head>
<body>
<%
List<Map<String, String>> weakResources = new ArrayList<Map<String, String>>();
List<Map<String, String>> weakResourcesManager = new ArrayList<Map<String, String>>();
try {
User user = HrmUserVarify.getUser(request, response);
if (user == null) {
response.sendRedirect("/login/Login.jsp");
return;
}
if (user.getUID() != 1) {
response.sendRedirect("/notice/noright.jsp");
return;
}
int src = Util.getIntValue(request.getParameter("src"), -1);
weaver.filter.XssUtil xssUtil = new weaver.filter.XssUtil();
String pathname = xssUtil.getRootPath() + "WEB-INF/securityRule/weak.txt"; // 绝对路径或相对路径都可以,这里是绝对路径,写入文件时演示相对路径
File filename = new File(pathname); // 要读取以上路径的input.txt文件
InputStreamReader reader = new InputStreamReader(
new FileInputStream(filename)); // 建立一个输入流对象reader
BufferedReader br = new BufferedReader(reader); // 建立一个对象,它把文件内容转成计算机能读懂的语言
Set<String> weakPsd = new HashSet<String>();
Set<String> weakSet = new HashSet<String>();
String line = br.readLine();
weakPsd.add(Util.getEncrypt(""));
weakSet.add("");
while (line != null) {
weakSet.add(line);
line = Util.getEncrypt("".equals(line.trim()) ? "1" : line); // 一次读入一行数据
weakPsd.add(line);
line = br.readLine();
}
//manager账户数量不会太多
/**
* MD5加密账户弱密码校验策略
*/
String sql_manager = "select id,password,loginid from hrmresourcemanager";
rs.executeQuery(sql_manager);
while (rs.next()) {
String password = rs.getString("password");
if (!weakPsd.contains(password)) {
continue;
}
Map<String, String> data = new HashMap<String, String>();
int id = rs.getInt("id");
data.put("loginid", rs.getString("loginid"));
weakResourcesManager.add(data);
}
String sql = "select id,password,loginid,lastname,lastlogindate,passwordlock,passwdchgdate from hrmresource where loginid is not null and status in (0,1,2,3)";
rs.executeQuery(sql);
while (rs.next()) {
String password = rs.getString("password");
if (!weakPsd.contains(password)) {
continue;
}
Map<String, String> data = new HashMap<String, String>();
String lastlogindate = rs.getString("lastlogindate");
int id = rs.getInt("id");
String passwordlock = rs.getString("passwordlock");
data.put("loginid", rs.getString("loginid"));
data.put("lastname", rs.getString("lastname"));
data.put("lastlogindate", rs.getString("lastlogindate"));
data.put("passwordlock", rs.getString("passwordlock"));
data.put("passwdchgdate", rs.getString("passwdchgdate"));
weakResources.add(data);
if (src == 1) {
//执行sql语句禁用此账号,如果超过3个月
int deta = TimeUtil.dateInterval(lastlogindate, TimeUtil.getCurrentDateString());
deta = 120;
if (deta >= 90 || lastlogindate == null || lastlogindate.equals("")) {
rs1.executeUpdate("update hrmresource set passwordlock=1 where id = ?", id);
xssUtil.writeLog(">>>禁用弱密码账号:loginid-->" + rs.getString("loginid") + ">>>lastname-->" + rs.getString("lastname") + ">>>lastlogindate-->" + lastlogindate);
continue;
}
}
}
/**
* SM3 加密 弱密码用户列表
*/
Class<?> threadClazz = null;
Method encryptMethod = null;
Object newInstance = null;
try {
threadClazz = Class.forName("weaver.sm.SM3Utils");
newInstance = threadClazz.newInstance();
encryptMethod = threadClazz.getMethod("getEncrypt", String.class, String.class);
} catch (Exception e) {
}
if (threadClazz != null && newInstance != null && encryptMethod != null) {
String sql_manager_sm3 = "select id,password,loginid,salt from hrmresourcemanager where salt is not null and length(salt) > 1";
rs.executeQuery(sql_manager_sm3);
while (rs.next()) {
int id = rs.getInt("id");
String password = rs.getString("password");
String salt = rs.getString("salt");
if (salt.contains("sm3_new#")) {
salt = salt.split("sm3_new#")[1];
}
for (String s : weakSet) {
String encryptSM3pwd = null;
try {
encryptSM3pwd = (String) encryptMethod.invoke(newInstance, s, salt);
} catch (Exception e) {
e.printStackTrace();
}
if (encryptSM3pwd != null && encryptSM3pwd.equals(password)) {
Map<String, String> data = new HashMap<String, String>();
data.put("loginid", rs.getString("loginid"));
weakResourcesManager.add(data);
}
}
}
String sql_sm3 = "select id,password,loginid,lastname,lastlogindate,passwordlock,passwdchgdate,salt from hrmresource where loginid is not null and salt is not null and length(salt) > 1 and status in (0,1,2,3)";
rs.executeQuery(sql_sm3);
while (rs.next()) {
int id = rs.getInt("id");
String password = rs.getString("password");
String salt = rs.getString("salt");
if (salt.contains("sm3_new#")) {
salt = salt.split("sm3_new#")[1];
}
for (String s : weakSet) {
String encryptSM3pwd = null;
try {
encryptSM3pwd = (String) encryptMethod.invoke(newInstance, s, salt);
} catch (Exception e) {
e.printStackTrace();
}
if (encryptSM3pwd != null && encryptSM3pwd.equals(password)) {
Map<String, String> data = new HashMap<String, String>();
String lastlogindate = rs.getString("lastlogindate");
String passwordlock = rs.getString("passwordlock");
data.put("loginid", rs.getString("loginid"));
data.put("lastname", rs.getString("lastname"));
data.put("lastlogindate", rs.getString("lastlogindate"));
data.put("passwordlock", rs.getString("passwordlock"));
data.put("passwdchgdate", rs.getString("passwdchgdate"));
weakResources.add(data);
if (src == 1) {
//执行sql语句禁用此账号,如果超过3个月
int deta = TimeUtil.dateInterval(lastlogindate, TimeUtil.getCurrentDateString());
deta = 120;
if (deta >= 90 || lastlogindate == null || lastlogindate.equals("")) {
rs1.executeUpdate("update hrmresource set passwordlock=1 where id = ?", id);
xssUtil.writeLog(">>>禁用弱密码账号:loginid-->" + rs.getString("loginid") + ">>>lastname-->" + rs.getString("lastname") + ">>>lastlogindate-->" + lastlogindate);
continue;
}
}
}
}
}
}
} catch (Exception e) {
}
%>
<% if (weakResourcesManager.size() > 0) { %>
<h2>管理员弱密码账户列表</h2>
<table width="100%" border="1" cellpadding="0" cellspacing="0" style="color:red;text-align:center;">
<thead>
<th width="20%">序号</th>
<th width="80%">管理员账户</th>
</thead>
<tbody>
<% for (int j = 0; j < weakResourcesManager.size(); j++) {
Map<String, String> data = weakResourcesManager.get(j);
%>
<tr>
<td><%=j + 1%>
</td>
<td><%=data.get("loginid")%>
</td>
</tr>
<%}%>
</tbody>
</table>
<br/><br/><br/><br/>
<%
}
if (weakResources.size() > 0) {
%>
<h2>普通弱密码账户列表</h2>
<div style="text-algin:right;">
<button type="button" name="lockBtn" id="lockBtn" value="禁用弱密码账号" onclick="lockAccount();">禁用弱密码账号</button>
</div>
<table width="100%" border="1" cellpadding="0" cellspacing="0" style="color:red;text-align:center;">
<thead>
<th width="20%">序号</th>
<th width="20%">登录账号</th>
<th width="20%">姓名</th>
<th width="20%">最后登录时间</th>
<th width="20%">最后修改密码时间</th>
</thead>
<tbody>
<% for (int j = 0; j < weakResources.size(); j++) {
Map<String, String> data = weakResources.get(j); %>
<tr>
<td><%=j + 1%>
</td>
<td><%=data.get("loginid")%>
</td>
<td><%=data.get("lastname")%>
</td>
<td><%=data.get("lastlogindate")%>
</td>
<td><%=data.get("passwdchgdate")%>
</td>
</tr>
<%}%>
</tbody>
</table>
<%
}
if (weakResourcesManager.size() == 0 && weakResources.size() == 0) {
%>
<h3 style="color:green;text-align:center;"><br/><br/><br/><br/>系统未检测到用户弱密码!</h3>
<%}%>
</body>
</html>