Showing
1 changed file
with
9 additions
and
62 deletions
... | @@ -126,39 +126,26 @@ namespace VulnUserCodeAnalyzer | ... | @@ -126,39 +126,26 @@ namespace VulnUserCodeAnalyzer |
126 | long receivedTotal = progress.ReceivedBytes; | 126 | long receivedTotal = progress.ReceivedBytes; |
127 | double received = progress.ReceivedBytes / 1000000; | 127 | double received = progress.ReceivedBytes / 1000000; |
128 | double percent = ((double)receivedBytes / (double)totalBytes); | 128 | double percent = ((double)receivedBytes / (double)totalBytes); |
129 | - | ||
130 | Console.WriteLine($"Progress: {percent.ToString("P2")}, Remain: {receivedBytes} of {totalBytes}"); //, 받은 용량: {received.ToString()}MB"); | 129 | Console.WriteLine($"Progress: {percent.ToString("P2")}, Remain: {receivedBytes} of {totalBytes}"); //, 받은 용량: {received.ToString()}MB"); |
131 | Console.ForegroundColor = ConsoleColor.DarkGreen; | 130 | Console.ForegroundColor = ConsoleColor.DarkGreen; |
132 | return true; | 131 | return true; |
133 | } | 132 | } |
134 | - | ||
135 | - | ||
136 | public static void CheckoutProcess(string path, int completedSteps, int totalSteps) | 133 | public static void CheckoutProcess(string path, int completedSteps, int totalSteps) |
137 | { | 134 | { |
138 | Console.WriteLine($"{completedSteps}, {totalSteps}, {path}"); | 135 | Console.WriteLine($"{completedSteps}, {totalSteps}, {path}"); |
139 | } | 136 | } |
140 | 137 | ||
141 | - | ||
142 | public static void Clone(string path, string url) | 138 | public static void Clone(string path, string url) |
143 | { | 139 | { |
144 | - | ||
145 | - | ||
146 | Console.WriteLine($"Start Cloning Path : {path}"); | 140 | Console.WriteLine($"Start Cloning Path : {path}"); |
147 | - | ||
148 | - | ||
149 | string clone = Repository.Clone(url, $@"{path}", new CloneOptions { OnTransferProgress = TransferProgress, OnCheckoutProgress = CheckoutProcess }); | 141 | string clone = Repository.Clone(url, $@"{path}", new CloneOptions { OnTransferProgress = TransferProgress, OnCheckoutProgress = CheckoutProcess }); |
150 | Console.ResetColor(); | 142 | Console.ResetColor(); |
151 | Console.WriteLine($"Finished Clone Repository: {clone}"); | 143 | Console.WriteLine($"Finished Clone Repository: {clone}"); |
152 | - | ||
153 | - | ||
154 | } | 144 | } |
155 | static void Main(string[] args) | 145 | static void Main(string[] args) |
156 | { | 146 | { |
157 | - | ||
158 | - | ||
159 | /* 연도별 CVE JSON 파일 로드 */ | 147 | /* 연도별 CVE JSON 파일 로드 */ |
160 | CVE_JSON.AutoLoad(); | 148 | CVE_JSON.AutoLoad(); |
161 | - | ||
162 | /* 크롤러 타입 */ | 149 | /* 크롤러 타입 */ |
163 | var crawler = new VulnC(); | 150 | var crawler = new VulnC(); |
164 | 151 | ||
... | @@ -194,7 +181,6 @@ namespace VulnUserCodeAnalyzer | ... | @@ -194,7 +181,6 @@ namespace VulnUserCodeAnalyzer |
194 | Console.WriteLine("Fail Connection"); | 181 | Console.WriteLine("Fail Connection"); |
195 | return; | 182 | return; |
196 | } | 183 | } |
197 | - | ||
198 | while (true) | 184 | while (true) |
199 | { | 185 | { |
200 | string userId = string.Empty; | 186 | string userId = string.Empty; |
... | @@ -218,27 +204,21 @@ namespace VulnUserCodeAnalyzer | ... | @@ -218,27 +204,21 @@ namespace VulnUserCodeAnalyzer |
218 | } | 204 | } |
219 | var repoBytes = Encoding.Unicode.GetBytes(repository); | 205 | var repoBytes = Encoding.Unicode.GetBytes(repository); |
220 | var repoBase64 = Convert.ToBase64String(repoBytes); | 206 | var repoBase64 = Convert.ToBase64String(repoBytes); |
221 | - | 207 | + var repoDir = new DirectoryInfo($@"C:\Repo\{repoBase64}"); |
222 | - foreach (var (userName, repository) in reposits) | 208 | + if (repoDir.Exists) |
223 | { | 209 | { |
224 | - Console.WriteLine($"{userName}, {repository}"); | 210 | + continue; |
225 | } | 211 | } |
226 | - | 212 | + repoDir.Create(); |
213 | + Console.WriteLine($"Clone... Path : {repoDir.FullName}, Url : {repository}"); | ||
214 | + Clone(repoDir.FullName, repository); | ||
227 | repoPath = repoDir.FullName; | 215 | repoPath = repoDir.FullName; |
228 | userId = userName; | 216 | userId = userName; |
229 | -<<<<<<<<< Temporary merge branch 1 | ||
230 | - } | ||
231 | - if (!string.IsNullOrWhiteSpace(repoPath) && !string.IsNullOrWhiteSpace(userId)) | ||
232 | - { | ||
233 | - break; | ||
234 | - } | ||
235 | -========= | ||
236 | } | 217 | } |
237 | if (!string.IsNullOrWhiteSpace(repoPath) && !string.IsNullOrWhiteSpace(userId)) | 218 | if (!string.IsNullOrWhiteSpace(repoPath) && !string.IsNullOrWhiteSpace(userId)) |
238 | { | 219 | { |
239 | break; | 220 | break; |
240 | } | 221 | } |
241 | ->>>>>>>>> Temporary merge branch 2 | ||
242 | repoWatch.Restart(); | 222 | repoWatch.Restart(); |
243 | } | 223 | } |
244 | //Console.WriteLine("엔터를 누르세요"); | 224 | //Console.WriteLine("엔터를 누르세요"); |
... | @@ -301,11 +281,8 @@ namespace VulnUserCodeAnalyzer | ... | @@ -301,11 +281,8 @@ namespace VulnUserCodeAnalyzer |
301 | * CVE를 가지고 있다고 인정하는 프로그램 정책 때문 | 281 | * CVE를 가지고 있다고 인정하는 프로그램 정책 때문 |
302 | */ | 282 | */ |
303 | var searchedCveHashList = VulnRDS.SelectVulnbyCve(cve); | 283 | var searchedCveHashList = VulnRDS.SelectVulnbyCve(cve); |
304 | -<<<<<<<<< Temporary merge branch 1 | 284 | + |
305 | - Console.WriteLine($"cve:{cve}, {searchedCveHashList.Count()}개 가져옴"); | ||
306 | -========= | ||
307 | Console.WriteLine($"CVE:{cve}, Received Count : {searchedCveHashList.Count()}"); | 285 | Console.WriteLine($"CVE:{cve}, Received Count : {searchedCveHashList.Count()}"); |
308 | ->>>>>>>>> Temporary merge branch 2 | ||
309 | foreach (var s in searchedCveHashList) | 286 | foreach (var s in searchedCveHashList) |
310 | { | 287 | { |
311 | vulnHashSet.Add(s); | 288 | vulnHashSet.Add(s); |
... | @@ -331,11 +308,6 @@ namespace VulnUserCodeAnalyzer | ... | @@ -331,11 +308,6 @@ namespace VulnUserCodeAnalyzer |
331 | { | 308 | { |
332 | if (hashDict.ContainsKey(vuln.LenFunc)) | 309 | if (hashDict.ContainsKey(vuln.LenFunc)) |
333 | { | 310 | { |
334 | -<<<<<<<<< Temporary merge branch 1 | ||
335 | - Console.WriteLine("찾음"); | ||
336 | -========= | ||
337 | - //Console.WriteLine("찾음"); | ||
338 | ->>>>>>>>> Temporary merge branch 2 | ||
339 | /* Bloom Filter는 아쉽게도 포함 여부만 알 수 있기에 | 311 | /* Bloom Filter는 아쉽게도 포함 여부만 알 수 있기에 |
340 | * 포함되었음을 알았다면 검색해서 정보를 구한다. */ | 312 | * 포함되었음을 알았다면 검색해서 정보를 구한다. */ |
341 | var userBlock = hashDict[vuln.LenFunc].FirstOrDefault(b => b.Hash == vuln.BlockHash); | 313 | var userBlock = hashDict[vuln.LenFunc].FirstOrDefault(b => b.Hash == vuln.BlockHash); |
... | @@ -364,21 +336,13 @@ namespace VulnUserCodeAnalyzer | ... | @@ -364,21 +336,13 @@ namespace VulnUserCodeAnalyzer |
364 | /* 취약점 레코드가 전부 있어야 CVE 찾음 인정 */ | 336 | /* 취약점 레코드가 전부 있어야 CVE 찾음 인정 */ |
365 | if (match) | 337 | if (match) |
366 | { | 338 | { |
367 | -<<<<<<<<< Temporary merge branch 1 | ||
368 | - Console.WriteLine($"CVE 찾음 {vulnSet.Key}"); | ||
369 | -========= | ||
370 | Console.WriteLine($"Matched CVE : {vulnSet.Key}"); | 339 | Console.WriteLine($"Matched CVE : {vulnSet.Key}"); |
371 | ->>>>>>>>> Temporary merge branch 2 | ||
372 | /* 찾았으면 cve값을 기록함 밑에서 찾은 cve 정보 전송하기 위해 */ | 340 | /* 찾았으면 cve값을 기록함 밑에서 찾은 cve 정보 전송하기 위해 */ |
373 | findCveList.Add(vulnSet.Key); | 341 | findCveList.Add(vulnSet.Key); |
374 | } | 342 | } |
375 | else | 343 | else |
376 | { | 344 | { |
377 | -<<<<<<<<< Temporary merge branch 1 | ||
378 | - Console.WriteLine("없음"); | ||
379 | -========= | ||
380 | Console.WriteLine("Not"); | 345 | Console.WriteLine("Not"); |
381 | ->>>>>>>>> Temporary merge branch 2 | ||
382 | } | 346 | } |
383 | } | 347 | } |
384 | stopwatch.Stop(); | 348 | stopwatch.Stop(); |
... | @@ -386,14 +350,8 @@ namespace VulnUserCodeAnalyzer | ... | @@ -386,14 +350,8 @@ namespace VulnUserCodeAnalyzer |
386 | var hours = stopwatch.Elapsed.Hours; | 350 | var hours = stopwatch.Elapsed.Hours; |
387 | var minutes = stopwatch.Elapsed.Minutes; | 351 | var minutes = stopwatch.Elapsed.Minutes; |
388 | var seconds = stopwatch.Elapsed.Seconds; | 352 | var seconds = stopwatch.Elapsed.Seconds; |
389 | -<<<<<<<<< Temporary merge branch 1 | ||
390 | - Console.WriteLine($"경과 시간 {hours.ToString("00")}:{minutes.ToString("00")}:{seconds.ToString("00")}"); | ||
391 | - Console.WriteLine($"찾은 CVE 개수 : {findCveList.Count}"); | ||
392 | -========= | ||
393 | Console.WriteLine($"Elapsed Time : {hours.ToString("00")}:{minutes.ToString("00")}:{seconds.ToString("00")}"); | 353 | Console.WriteLine($"Elapsed Time : {hours.ToString("00")}:{minutes.ToString("00")}:{seconds.ToString("00")}"); |
394 | Console.WriteLine($"Matched CVE Count : {findCveList.Count}"); | 354 | Console.WriteLine($"Matched CVE Count : {findCveList.Count}"); |
395 | ->>>>>>>>> Temporary merge branch 2 | ||
396 | - //Console.ReadLine(); | ||
397 | 355 | ||
398 | var yearMatch = new Regex(@"CVE-(\d{4})-(\d+)"); | 356 | var yearMatch = new Regex(@"CVE-(\d{4})-(\d+)"); |
399 | foreach (var cve in findCveList) | 357 | foreach (var cve in findCveList) |
... | @@ -448,15 +406,7 @@ namespace VulnUserCodeAnalyzer | ... | @@ -448,15 +406,7 @@ namespace VulnUserCodeAnalyzer |
448 | 406 | ||
449 | var urlBytes = Convert.FromBase64String(findCveDict[cve].FirstOrDefault().Url); | 407 | var urlBytes = Convert.FromBase64String(findCveDict[cve].FirstOrDefault().Url); |
450 | string url = Encoding.Unicode.GetString(urlBytes); | 408 | string url = Encoding.Unicode.GetString(urlBytes); |
451 | -<<<<<<<<< Temporary merge branch 1 | ||
452 | - Console.WriteLine(findCveDict[cve].FirstOrDefault().Path.Replace(repoPath, "")); | ||
453 | - /* DB 전송 */ | ||
454 | - VulnRDS.InsertVulnDetail(new VulnRDS.Vuln_detail | ||
455 | -========= | ||
456 | - //Console.WriteLine(findCveDict[cve].FirstOrDefault().Path.Replace(repoPath, "")); | ||
457 | - | ||
458 | var vulnDetail = new VulnRDS.Vuln_detail | 409 | var vulnDetail = new VulnRDS.Vuln_detail |
459 | ->>>>>>>>> Temporary merge branch 2 | ||
460 | { | 410 | { |
461 | CveName = data.Code, | 411 | CveName = data.Code, |
462 | Type = type, | 412 | Type = type, |
... | @@ -470,17 +420,14 @@ namespace VulnUserCodeAnalyzer | ... | @@ -470,17 +420,14 @@ namespace VulnUserCodeAnalyzer |
470 | FileName = findCveDict[cve].FirstOrDefault().Path.Replace(repoPath, ""), | 420 | FileName = findCveDict[cve].FirstOrDefault().Path.Replace(repoPath, ""), |
471 | FuncName = findCveDict[cve].FirstOrDefault().FuncName, | 421 | FuncName = findCveDict[cve].FirstOrDefault().FuncName, |
472 | Product = data.Type, | 422 | Product = data.Type, |
473 | -<<<<<<<<< Temporary merge branch 1 | ||
474 | - }); | ||
475 | - Console.WriteLine("추가 완료"); | ||
476 | -========= | ||
477 | }; | 423 | }; |
424 | + Console.WriteLine("추가 완료"); | ||
425 | + | ||
478 | 426 | ||
479 | /* DB 전송 */ | 427 | /* DB 전송 */ |
480 | VulnRDS.InsertVulnDetail(vulnDetail); | 428 | VulnRDS.InsertVulnDetail(vulnDetail); |
481 | 429 | ||
482 | Console.WriteLine($"Added CVE: {vulnDetail.CveName}, Type: {vulnDetail.Type}, CVSS: {vulnDetail.Level}"); | 430 | Console.WriteLine($"Added CVE: {vulnDetail.CveName}, Type: {vulnDetail.Type}, CVSS: {vulnDetail.Level}"); |
483 | ->>>>>>>>> Temporary merge branch 2 | ||
484 | } | 431 | } |
485 | } | 432 | } |
486 | } | 433 | } | ... | ... |
-
Please register or login to post a comment