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-23 00:48:42 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c6a2bab85f3045c0565105149929541a6aeb000b
c6a2bab8
1 parent
974aae40
GetCriticalBlock Syntax 기반 구현
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
161 additions
and
57 deletions
Vulnerablity_DB/VulnCrawler/VulnAbstractCrawler.cs
Vulnerablity_DB/VulnCrawler/VulnC.cs
Vulnerablity_DB/VulnCrawler/VulnAbstractCrawler.cs
View file @
c6a2bab
...
...
@@ -382,11 +382,18 @@ namespace VulnCrawler
{
return
false
;
}
/* 대문자로 구성된 변수면 넘어감 */
if
(
m
.
Value
.
All
(
c
=>
char
.
IsUpper
(
c
)
||
!
char
.
IsLetter
(
c
)))
{
return
false
;
}
/* 제일 앞자리가 숫자로 시작하면 넘어감 */
if
(
Regex
.
IsMatch
(
m
.
Value
,
invalidPattern
))
{
return
false
;
}
/* 전 단계에서 구한 메서드 목록에 있으면 넘어감 */
if
(
methodSets
.
Contains
(
m
.
Value
))
{
...
...
@@ -403,6 +410,8 @@ namespace VulnCrawler
{
return
false
;
}
return
true
;
})
.
Distinct
(
new
MatchComparer
());
...
...
Vulnerablity_DB/VulnCrawler/VulnC.cs
View file @
c6a2bab
...
...
@@ -232,7 +232,6 @@ namespace VulnCrawler
// srcCode = Regex.Replace(srcCode, @"if.+\n\{", @"if.+\{", RegexOptions.Multiline);
var
split
=
srcCode
.
Split
(
'\n'
);
int
bracketCount
=
0
;
var
blockList
=
new
List
<
Block
>();
StringBuilder
builder
=
new
StringBuilder
();
var
crList
=
criticalList
as
HashSet
<
string
>;
...
...
@@ -240,68 +239,141 @@ namespace VulnCrawler
{
return
null
;
}
bool
mainLine
=
true
;
/* 현재 라인이 메인 코드 라인인지 */
int
blockNum
=
1
;
/* 블록 번호 */
bool
group
=
false
;
Queue
<
string
>
groupQ
=
new
Queue
<
string
>();
var
mainQ
=
new
Queue
<
string
>();
var
groupQ
=
new
Queue
<
string
>();
bool
mainLine
=
true
;
int
crNum
=
1
;
int
bracketCount
=
1
;
bool
prevStartBlock
=
false
;
foreach
(
var
line
in
split
)
{
bool
criticalBlock
=
false
;
/* 현재 라인이 크리티컬 블록 라인인지 */
bool
criticalBlock
=
false
;
string
trimLine
=
line
.
Trim
();
if
(
mainLine
)
{
if
(
trimLine
.
EndsWith
(
"&&"
)
||
trimLine
.
EndsWith
(
"||"
))
{
mainQ
.
Enqueue
(
line
);
continue
;
}
string
trim
=
line
.
Trim
();
if
(
trimLine
.
StartsWith
(
"&&"
)
||
trimLine
.
StartsWith
(
"||"
))
{
groupQ
.
Enqueue
(
line
);
continue
;
}
if
(
Regex
.
IsMatch
(
trim
,
@"^(if|for|while)"
))
{
group
=
true
;
mainLine
=
false
;
groupQ
.
Enqueue
(
line
);
if
(
trim
.
EndsWith
(
"{"
))
bracketCount
=
1
;
StringBuilder
groupBuilder
=
new
StringBuilder
();
while
(
groupQ
.
Count
>
0
)
{
group
=
true
;
string
s
=
groupQ
.
Dequeue
();
if
(!
criticalBlock
)
{
foreach
(
var
item
in
ExtractCriticalVariant
(
s
))
{
if
(
crList
.
Contains
(
item
))
{
criticalBlock
=
true
;
break
;
}
}
}
groupBuilder
.
AppendLine
(
s
);
}
else
if
(
trim
.
EndsWith
(
"}"
))
if
(
groupBuilder
.
Length
>
0
)
{
group
=
false
;
blockList
.
Add
(
new
Block
{
Code
=
groupBuilder
.
ToString
(),
HasCritical
=
criticalBlock
,
Num
=
crNum
++})
;
}
else
if
(
trim
.
EndsWith
(
";
"
))
if
(
Regex
.
IsMatch
(
trimLine
,
@"(if|for|while|switch|do)\s*
"
))
{
group
=
false
;
if
(!
trimLine
.
EndsWith
(
"{"
))
{
mainLine
=
false
;
prevStartBlock
=
true
;
}
else
if
(
trimLine
.
EndsWith
(
";"
))
{
mainLine
=
true
;
}
else
{
mainLine
=
false
;
bracketCount
++;
}
groupQ
.
Enqueue
(
line
);
continue
;
}
continue
;
mainQ
.
Enqueue
(
line
)
;
}
if
(
group
)
else
{
groupQ
.
Enqueue
(
line
);
if
(
trim
.
EndsWith
(
"}"
))
/* 중괄호 수 세기 */
int
openBracketCount
=
trimLine
.
Count
(
c
=>
c
==
'{'
);
int
closeBracketCount
=
trimLine
.
Count
(
c
=>
c
==
'}'
);
int
subtract
=
openBracketCount
-
closeBracketCount
;
bracketCount
+=
subtract
;
if
(
trimLine
.
EndsWith
(
"&&"
)
||
trimLine
.
EndsWith
(
"||"
))
{
group
=
false
;
groupQ
.
Enqueue
(
line
);
continue
;
}
else
if
(
trim
.
EndsWith
(
";"
))
//if (trimLine.StartsWith("&&") || trimLine.StartsWith("||"))
//{
// mainQ.Enqueue(line);
// continue;
//}
groupQ
.
Enqueue
(
line
);
if
(
prevStartBlock
)
{
group
=
false
;
prevStartBlock
=
false
;
if
(
Regex
.
IsMatch
(
trimLine
,
@"(if|for|while|switch|do)\s*\("
))
{
prevStartBlock
=
true
;
continue
;
}
else
if
(
trimLine
.
EndsWith
(
";"
))
{
bracketCount
--;
}
}
continue
;
}
mainQ
.
Enqueue
(
line
);
if
(
bracketCount
<=
1
)
{
if
(
trimLine
.
Contains
(
"else"
))
{
bracketCount
++;
prevStartBlock
=
true
;
continue
;
}
StringBuilder
mainBuilder
=
new
StringBuilder
();
if
(!
mainLine
)
{
while
(
mainQ
.
Count
>
0
)
mainLine
=
true
;
}
StringBuilder
mainBuilder
=
new
StringBuilder
();
while
(
mainQ
.
Count
>
0
)
{
string
s
=
mainQ
.
Dequeue
();
if
(!
criticalBlock
)
{
foreach
(
var
var
in
ExtractCriticalVariant
(
s
))
foreach
(
var
item
in
ExtractCriticalVariant
(
s
))
{
if
(
crList
.
Contains
(
var
))
if
(
crList
.
Contains
(
item
))
{
criticalBlock
=
true
;
break
;
...
...
@@ -310,47 +382,70 @@ namespace VulnCrawler
}
mainBuilder
.
AppendLine
(
s
);
}
if
(
mainBuilder
.
Length
>
0
)
{
blockList
.
Add
(
new
Block
{
Code
=
mainBuilder
.
ToString
(),
HasCritical
=
criticalBlock
,
Num
=
blockNum
++
});
//continue;
blockList
.
Add
(
new
Block
{
Code
=
mainBuilder
.
ToString
(),
HasCritical
=
criticalBlock
,
Num
=
crNum
++
});
}
}
}
bool
cb
=
false
;
if
(
mainQ
.
Count
>
0
)
{
StringBuilder
mainBuilder
=
new
StringBuilder
();
while
(
mainQ
.
Count
>
0
)
{
string
s
=
mainQ
.
Dequeue
();
if
(!
cb
)
{
foreach
(
var
item
in
ExtractCriticalVariant
(
s
))
{
if
(
crList
.
Contains
(
item
))
{
cb
=
true
;
break
;
}
}
}
mainBuilder
.
AppendLine
(
s
);
}
if
(
mainBuilder
.
Length
>
0
)
{
blockList
.
Add
(
new
Block
{
Code
=
mainBuilder
.
ToString
(),
HasCritical
=
cb
,
Num
=
crNum
++
});
}
}
else
{
StringBuilder
groupBuilder
=
new
StringBuilder
();
while
(
groupQ
.
Count
>
0
)
{
var
s
=
groupQ
.
Dequeue
();
if
(!
c
riticalBlock
)
string
s
=
groupQ
.
Dequeue
();
if
(!
c
b
)
{
foreach
(
var
var
in
ExtractCriticalVariant
(
s
))
foreach
(
var
item
in
ExtractCriticalVariant
(
s
))
{
if
(
crList
.
Contains
(
var
))
if
(
crList
.
Contains
(
item
))
{
c
riticalBlock
=
true
;
c
b
=
true
;
break
;
}
}
}
groupBuilder
.
AppendLine
(
s
);
}
if
(
groupBuilder
.
Length
>
0
)
{
blockList
.
Add
(
new
Block
{
Code
=
groupBuilder
.
ToString
(),
HasCritical
=
criticalBlock
,
Num
=
blockNum
++
});
continue
;
blockList
.
Add
(
new
Block
{
Code
=
groupBuilder
.
ToString
(),
HasCritical
=
cb
,
Num
=
crNum
++
});
}
mainLine
=
true
;
}
Console
.
WriteLine
(
"끝"
);
return
blockList
;
}
}
...
...
Please
register
or
login
to post a comment