-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4833b43
commit c2cccc1
Showing
214 changed files
with
9,885 additions
and
3,260 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
src/main/kotlin/org/skgroup/securityinspector/enums/VulnElemType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
package org.skgroup.securityinspector.enums | ||
|
||
class VulnElemType { | ||
enum class VulnElemType { | ||
ASSIGNMENT_EXPRESSION, | ||
LOCAL_VARIABLE, | ||
CLASS_FIELD | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/org/skgroup/securityinspector/enums/VulnType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.skgroup.securityinspector.utils | ||
package org.skgroup.securityinspector.enums | ||
|
||
enum class VulnType { | ||
|
||
|
12 changes: 11 additions & 1 deletion
12
src/main/kotlin/org/skgroup/securityinspector/enums/XmlFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
package org.skgroup.securityinspector.enums | ||
|
||
class XmlFactory { | ||
enum class XmlFactory { | ||
DOCUMENT_BUILDER_FACTORY, | ||
SAX_PARSER_FACTORY, | ||
SAX_TRANSFORMER_FACTORY, | ||
SAX_BUILDER, | ||
SAX_READER, | ||
XML_READER_FACTORY, | ||
SCHEMA_FACTORY, | ||
XML_INPUT_FACTORY, | ||
TRANSFORMER_FACTORY, | ||
VALIDATOR_OF_SCHEMA | ||
} |
6 changes: 3 additions & 3 deletions
6
src/main/kotlin/org/skgroup/securityinspector/inspectors/BaseLocalInspectionTool.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/org/skgroup/securityinspector/inspectors/InspectionTool.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
package org.skgroup.securityinspector.inspectors | ||
|
||
import com.intellij.codeInspection.ProblemsHolder | ||
import com.intellij.psi.PsiFile | ||
|
||
interface InspectionTool { | ||
/** | ||
* 针对给定的 PsiFile 运行检查器 | ||
* @param psiFile 目标 PsiFile | ||
* @param problemsHolder 用于收集问题 | ||
*/ | ||
fun inspectFile(psiFile: PsiFile, problemsHolder: ProblemsHolder) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 62 additions & 2 deletions
64
src/main/kotlin/org/skgroup/securityinspector/rules/files/read/ReadFile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,64 @@ | ||
package org.skgroup.securityinspector.rules.files.read | ||
|
||
class ReadFile { | ||
} | ||
import com.intellij.codeInspection.ProblemHighlightType | ||
import com.intellij.codeInspection.ProblemsHolder | ||
import com.intellij.psi.JavaElementVisitor | ||
import com.intellij.psi.PsiElementVisitor | ||
import com.intellij.psi.PsiMethodCallExpression | ||
import com.intellij.psi.PsiNewExpression | ||
import org.jetbrains.annotations.NotNull | ||
import org.skgroup.securityinspector.inspectors.BaseLocalInspectionTool | ||
import org.skgroup.securityinspector.utils.InspectionBundle | ||
import org.skgroup.securityinspector.utils.SecExpressionUtils | ||
|
||
/** | ||
* 检查任意文件读取漏洞 | ||
*/ | ||
class ReadFile : BaseLocalInspectionTool() { | ||
|
||
companion object { | ||
private val MESSAGE = InspectionBundle.message("vuln.massage.ReadFile") | ||
private val READFILE_METHOD_SINKS: Map<String, List<String>> = mapOf( | ||
"java.lang.Class" to listOf("getResourceAsStream"), | ||
"org.apache.commons.io.FileUtils" to listOf( | ||
"readFileToByteArray", | ||
"readFileToString", | ||
"readLines" | ||
), | ||
"java.nio.file.Files" to listOf( | ||
"readAllBytes", | ||
"readAllLines" | ||
), | ||
"java.io.BufferedReader" to listOf("readLine") | ||
) | ||
} | ||
|
||
@NotNull | ||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { | ||
return object : JavaElementVisitor() { | ||
|
||
override fun visitMethodCallExpression(expression: PsiMethodCallExpression) { | ||
if (SecExpressionUtils.isMethodSink(expression, READFILE_METHOD_SINKS)) { | ||
holder.registerProblem( | ||
expression, | ||
MESSAGE, | ||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING | ||
) | ||
} | ||
} | ||
|
||
override fun visitNewExpression(expression: PsiNewExpression) { | ||
if (SecExpressionUtils.hasFullQualifiedName(expression, "java.io.FileInputStream") | ||
|| SecExpressionUtils.hasFullQualifiedName(expression, "java.io.FileReader") | ||
) { | ||
holder.registerProblem( | ||
expression, | ||
MESSAGE, | ||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.