LoginSignup
0
0

More than 1 year has passed since last update.

cscの作法 その242

Last updated at Posted at 2022-07-17

概要

cscの作法、調べてみた。
練習問題やってみた。

練習問題

ファイルをhashしてvirustotalに投げて、判定せよ。

サンプルコード

using System.Collections;
using System.IO;
using System;
using System.Text;
using System.Linq;
using System.Security.Cryptography;
using LitJson;
using System.Net;
using System.Net.Http;

namespace app
{
	class test0 {
		static void Main(string[] args) {
			ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
			if (args.Length == 0)
			{
				Console.WriteLine("cert0 file");
				return;
			}
			byte[] byteValue = File.ReadAllBytes(args[0]);
			SHA256 crypto = new SHA256CryptoServiceProvider();
			byte[] hashValue = crypto.ComputeHash(byteValue);
			var hash = String.Join("", hashValue.Select(x => x.ToString("x2")).ToArray());
			Console.WriteLine(hash);
			string url = "https://www.virustotal.com/vtapi/v2/file/report?apikey=******&resource=" + hash;
			HttpClient client = new HttpClient();
			string response = client.GetStringAsync(url).Result;
			LitJson.JsonData json = LitJson.JsonMapper.ToObject(response);
			try
			{
				Console.WriteLine("total: " + json["total"]);
				Console.WriteLine("positive: " + json["positives"]);
			}
			catch (Exception ex)
			{
				Console.WriteLine("pass");
			}
		}
	}
}






実行結果

>virustotal2 myenc.txt
pass

>

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0