Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76393173
jadx
提交
7d3caa28
J
jadx
项目概览
2301_76393173
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jadx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7d3caa28
编写于
1月 03, 2018
作者:
S
Sergey Toshin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adds checks for resources, and logs detected attacks
上级
418546a6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
47 addition
and
11 deletion
+47
-11
jadx-core/src/main/java/jadx/api/ResourceFile.java
jadx-core/src/main/java/jadx/api/ResourceFile.java
+9
-1
jadx-core/src/main/java/jadx/api/ResourceFileContent.java
jadx-core/src/main/java/jadx/api/ResourceFileContent.java
+9
-1
jadx-core/src/main/java/jadx/api/ResourcesLoader.java
jadx-core/src/main/java/jadx/api/ResourcesLoader.java
+9
-5
jadx-core/src/main/java/jadx/core/utils/files/ZipSecurity.java
...core/src/main/java/jadx/core/utils/files/ZipSecurity.java
+16
-2
jadx-gui/src/main/java/jadx/gui/treemodel/JResource.java
jadx-gui/src/main/java/jadx/gui/treemodel/JResource.java
+4
-2
未找到文件。
jadx-core/src/main/java/jadx/api/ResourceFile.java
浏览文件 @
7d3caa28
package
jadx.api
;
import
jadx.core.utils.files.ZipSecurity
;
import
jadx.core.xmlgen.ResContainer
;
import
java.io.File
;
...
...
@@ -34,7 +35,7 @@ public class ResourceFile {
private
final
ResourceType
type
;
private
ZipRef
zipRef
;
ResourceFile
(
JadxDecompiler
decompiler
,
String
name
,
ResourceType
type
)
{
protected
ResourceFile
(
JadxDecompiler
decompiler
,
String
name
,
ResourceType
type
)
{
this
.
decompiler
=
decompiler
;
this
.
name
=
name
;
this
.
type
=
type
;
...
...
@@ -64,4 +65,11 @@ public class ResourceFile {
public
String
toString
()
{
return
"ResourceFile{name='"
+
name
+
'\''
+
", type="
+
type
+
"}"
;
}
public
static
ResourceFile
createResourceFileInstance
(
JadxDecompiler
decompiler
,
String
name
,
ResourceType
type
)
{
if
(!
ZipSecurity
.
isValidZipEntryName
(
name
))
{
return
null
;
}
return
new
ResourceFile
(
decompiler
,
name
,
type
);
}
}
jadx-core/src/main/java/jadx/api/ResourceFileContent.java
浏览文件 @
7d3caa28
package
jadx.api
;
import
jadx.core.codegen.CodeWriter
;
import
jadx.core.utils.files.ZipSecurity
;
import
jadx.core.xmlgen.ResContainer
;
public
class
ResourceFileContent
extends
ResourceFile
{
private
final
CodeWriter
content
;
p
ublic
ResourceFileContent
(
String
name
,
ResourceType
type
,
CodeWriter
content
)
{
p
rivate
ResourceFileContent
(
String
name
,
ResourceType
type
,
CodeWriter
content
)
{
super
(
null
,
name
,
type
);
this
.
content
=
content
;
}
...
...
@@ -16,4 +17,11 @@ public class ResourceFileContent extends ResourceFile {
public
ResContainer
loadContent
()
{
return
ResContainer
.
singleFile
(
getName
(),
content
);
}
public
static
ResourceFileContent
createResourceFileContentInstance
(
String
name
,
ResourceType
type
,
CodeWriter
content
)
{
if
(!
ZipSecurity
.
isValidZipEntryName
(
name
))
{
return
null
;
}
return
new
ResourceFileContent
(
name
,
type
,
content
);
}
}
jadx-core/src/main/java/jadx/api/ResourcesLoader.java
浏览文件 @
7d3caa28
...
...
@@ -157,8 +157,10 @@ public final class ResourcesLoader {
private
void
addResourceFile
(
List
<
ResourceFile
>
list
,
File
file
)
{
String
name
=
file
.
getAbsolutePath
();
ResourceType
type
=
ResourceType
.
getFileType
(
name
);
ResourceFile
rf
=
new
ResourceFile
(
jadxRef
,
name
,
type
);
list
.
add
(
rf
);
ResourceFile
rf
=
ResourceFile
.
createResourceFileInstance
(
jadxRef
,
name
,
type
);
if
(
rf
!=
null
)
{
list
.
add
(
rf
);
}
}
private
void
addEntry
(
List
<
ResourceFile
>
list
,
File
zipFile
,
ZipEntry
entry
)
{
...
...
@@ -167,9 +169,11 @@ public final class ResourcesLoader {
}
String
name
=
entry
.
getName
();
ResourceType
type
=
ResourceType
.
getFileType
(
name
);
ResourceFile
rf
=
new
ResourceFile
(
jadxRef
,
name
,
type
);
rf
.
setZipRef
(
new
ZipRef
(
zipFile
,
name
));
list
.
add
(
rf
);
ResourceFile
rf
=
ResourceFile
.
createResourceFileInstance
(
jadxRef
,
name
,
type
);
if
(
rf
!=
null
)
{
rf
.
setZipRef
(
new
ZipRef
(
zipFile
,
name
));
list
.
add
(
rf
);
}
}
public
static
CodeWriter
loadToCodeWriter
(
InputStream
is
)
throws
IOException
{
...
...
jadx-core/src/main/java/jadx/core/utils/files/ZipSecurity.java
浏览文件 @
7d3caa28
...
...
@@ -3,7 +3,12 @@ package jadx.core.utils.files;
import
java.io.File
;
import
java.util.zip.ZipEntry
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
ZipSecurity
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ZipSecurity
.
class
);
// size of uncompressed zip entry shouldn't be bigger of compressed in MAX_SIZE_DIFF times
private
static
final
int
MAX_SIZE_DIFF
=
5
;
...
...
@@ -24,9 +29,14 @@ public class ZipSecurity {
try
{
File
currentPath
=
new
File
(
"."
).
getCanonicalFile
();
File
canonical
=
new
File
(
currentPath
,
entryName
).
getCanonicalFile
();
return
isInSubDirectory
(
currentPath
,
canonical
);
if
(
isInSubDirectory
(
currentPath
,
canonical
))
{
return
true
;
}
LOG
.
debug
(
"Path traversal attack detected, invalid name: {}"
,
entryName
);
return
false
;
}
catch
(
Exception
e
)
{
LOG
.
debug
(
"Path traversal attack detected, invalid name: {}"
,
entryName
);
return
false
;
}
}
...
...
@@ -37,7 +47,11 @@ public class ZipSecurity {
if
(
compressedSize
<
0
||
uncompressedSize
<
0
)
{
return
true
;
}
return
compressedSize
*
MAX_SIZE_DIFF
<
uncompressedSize
;
if
(
compressedSize
*
MAX_SIZE_DIFF
<
uncompressedSize
)
{
LOG
.
debug
(
"Zip bomp attack detected, invalid sizes: compressed {}, uncompressed {}"
,
compressedSize
,
uncompressedSize
);
return
true
;
}
return
false
;
}
public
static
boolean
isValidZipEntry
(
ZipEntry
entry
)
{
...
...
jadx-gui/src/main/java/jadx/gui/treemodel/JResource.java
浏览文件 @
7d3caa28
...
...
@@ -101,8 +101,10 @@ public class JResource extends JNode implements Comparable<JResource> {
String
resName
=
rc
.
getName
();
String
[]
path
=
resName
.
split
(
"/"
);
String
resShortName
=
path
.
length
==
0
?
resName
:
path
[
path
.
length
-
1
];
ResourceFileContent
fileContent
=
new
ResourceFileContent
(
resShortName
,
ResourceType
.
XML
,
cw
);
addPath
(
path
,
root
,
new
JResource
(
fileContent
,
resName
,
resShortName
,
JResType
.
FILE
));
ResourceFileContent
fileContent
=
ResourceFileContent
.
createResourceFileContentInstance
(
resShortName
,
ResourceType
.
XML
,
cw
);
if
(
fileContent
!=
null
)
{
addPath
(
path
,
root
,
new
JResource
(
fileContent
,
resName
,
resShortName
,
JResType
.
FILE
));
}
}
}
List
<
ResContainer
>
subFiles
=
rc
.
getSubFiles
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录