Toggle navigation
Toggle navigation
This project
Loading...
Sign in
노현종
/
2018-1-Capstone1-VulnNotti
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
노현종
2018-05-17 17:40:07 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
856c913e95c4699840255761485efa9f40b14ac7
856c913e
1 parent
488ac921
크리티컬 변수 선정시 예약어 제외 기능 추가
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
12 deletions
Vulnerablity_DB/VulnCrawler/CReserved.txt
Vulnerablity_DB/VulnCrawler/Program.cs
Vulnerablity_DB/VulnCrawler/VulnAbstractCrawler.cs
Vulnerablity_DB/VulnCrawler/VulnC.cs
Vulnerablity_DB/VulnCrawler/VulnCrawler.csproj
Vulnerablity_DB/VulnCrawler/VulnPython.cs
Vulnerablity_DB/VulnCrawler/CReserved.txt
0 → 100644
View file @
856c913
auto
bool
break
case
char
const
continue
default
defined
do
double
else
enum
extern
float
for
goto
if
int
long
register
return
short
signed
sizeof
static
struct
switch
typedef
union
unsigned
void
volatile
while
\ No newline at end of file
Vulnerablity_DB/VulnCrawler/Program.cs
View file @
856c913
...
...
@@ -67,16 +67,14 @@ namespace VulnCrawler
public
static
void
Run
()
{
// Repository 폴더들이 있는 주소를 지정하면 하위 폴더 목록을 가져옴(Repository 목록)
// var fields = VulnWorker.GetCriticalVariant(@"return _is_safe_url(url, host) and _is_safe_url(url.replace('\\', '/'), host)");
var
fields
=
VulnAbstractCrawler
.
GetCriticalVariant
(
@"if(i + inl < bl) {"
);
// var fields = VulnWorker.GetCriticalVariant(@"return _is_safe_url(url, host) and _is_safe_url(url.replace('\\', '/'), host)");
var
c
=
new
VulnC
();
var
fields
=
c
.
GetCriticalVariant
(
@"if(i + inl < bl) {"
);
foreach
(
var
item
in
fields
)
{
Console
.
WriteLine
(
item
);
}
// return;
return
;
var
directorys
=
Directory
.
GetDirectories
(
@"c:\VulnPy"
);
if
(
directorys
.
Length
==
0
)
{
Console
.
WriteLine
(
"Repository 목록 찾기 실패"
);
...
...
Vulnerablity_DB/VulnCrawler/VulnAbstractCrawler.cs
View file @
856c913
...
...
@@ -14,8 +14,8 @@ namespace VulnCrawler
public
abstract
class
VulnAbstractCrawler
{
protected
abstract
string
[]
ReservedList
{
get
;
}
protected
HashSet
<
string
>
ReservedList
{
get
;
}
protected
abstract
string
ReservedFileName
{
get
;
}
// = { "if", "return", "break", "while", "typedef" };
/// <summary>
...
...
@@ -26,15 +26,39 @@ namespace VulnCrawler
/// </summary>
/// <param name="path"></param>
public
VulnAbstractCrawler
()
{
ReservedList
=
new
HashSet
<
string
>();
LoadReservedList
();
}
// 소멸자
~
VulnAbstractCrawler
()
{
Repository
.
Dispose
();
Repository
?.
Dispose
();
}
private
void
LoadReservedList
()
{
try
{
var
lines
=
File
.
ReadLines
(
ReservedFileName
,
Encoding
.
Default
);
foreach
(
var
item
in
lines
)
{
if
(
string
.
IsNullOrWhiteSpace
(
item
))
{
continue
;
}
ReservedList
.
Add
(
item
);
}
}
catch
(
FileNotFoundException
)
{
Console
.
WriteLine
(
$
"{this.GetType().ToString()} 예약어 파일 목록이 없습니다. 파일 이름 : {ReservedFileName}"
);
}
}
protected
virtual
Regex
MethodExtractor
=>
new
Regex
(
RegexFuncPattern
);
#
region
메서드
패턴
정규식
그룹
...
...
@@ -138,7 +162,12 @@ namespace VulnCrawler
return
string
.
Empty
;
}
public
static
IEnumerable
<
string
>
GetCriticalVariant
(
string
line
)
/// <summary>
/// 크리티컬 변수 목록 추출
/// </summary>
/// <param name="line">현재 코드줄</param>
/// <returns></returns>
public
IEnumerable
<
string
>
GetCriticalVariant
(
string
line
)
{
// 메서드 정규식 패턴
...
...
@@ -166,10 +195,17 @@ namespace VulnCrawler
var
field
=
x
as
Match
;
if
(
field
.
Success
)
{
/* 전 단계에서 구한 메서드 목록에 있으면 넘어감 */
if
(
methodSets
.
Contains
(
field
.
Value
))
{
continue
;
}
/* 예약어 목록에 있으면 넘어감 */
if
(
ReservedList
.
Contains
(
field
.
Value
))
{
continue
;
}
yield
return
field
.
Value
;
}
}
...
...
Vulnerablity_DB/VulnCrawler/VulnC.cs
View file @
856c913
...
...
@@ -10,12 +10,12 @@ namespace VulnCrawler
{
public
class
VulnC
:
VulnAbstractCrawler
{
protected
override
string
[]
ReservedList
=>
new
string
[]
{
"if"
,
"return"
,
"break"
,
"while"
,
"typedef"
};
protected
override
string
RegexFuncPattern
=>
$
@"@@ \-(?<{OldStart}>\d+),(?<{OldLines}>\d+) \+(?<{NewStart}>\d+),(?<{NewLines}>\d+) @@ (?<{MethodName}>(static)? [\w]+ [\w]+)\([\w \*\,\t\n]*\)"
;
protected
override
string
Extension
=>
".c"
;
protected
override
string
ReservedFileName
=>
"CReserved.txt"
;
public
override
MatchCollection
GetMatches
(
string
patchCode
)
{
var
regs
=
Regex
.
Matches
(
patchCode
,
RegexFuncPattern
);
...
...
Vulnerablity_DB/VulnCrawler/VulnCrawler.csproj
View file @
856c913
...
...
@@ -66,6 +66,9 @@
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="CReserved.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
...
...
Vulnerablity_DB/VulnCrawler/VulnPython.cs
View file @
856c913
...
...
@@ -20,7 +20,8 @@ namespace VulnCrawler
protected
override
string
Extension
=>
".py"
;
protected
override
string
RegexFuncPattern
=>
$
@"@@ \-(?<{OldStart}>\d+),(?<{OldLines}>\d+) \+(?<{NewStart}>\d+),(?<{NewLines}>\d+) @@ def (?<{MethodName}>\w+)"
;
protected
override
string
[]
ReservedList
=>
throw
new
NotImplementedException
();
protected
override
string
ReservedFileName
=>
throw
new
NotImplementedException
();
// protected override Regex MethodExtractor => new Regex(RegexFuncPattern);
...
...
Please
register
or
login
to post a comment