using NBitcoin; using QBitNinja.Client; using QBitNinja.Client.Models; using System.Collections; using System.Diagnostics; using System.Net; using System.Net.Sockets; using System.Text; using static System.Console; using System.IO; using Newtonsoft.Json; using static System.Net.Mime.MediaTypeNames; using System.Text.RegularExpressions; using System.IO.Compression; using NBitcoin.Protocol; using System; using MihaZupan; using System; using System.Globalization; using System.IO; using System.Linq; using System.Net.Http; using System.Security.Cryptography; using System.Threading; try { WriteLine("*****************************************************************************"); WriteLine("** ActiveTKDotJP WebServer / Build.20221207#BETA"); WriteLine("** (c) 2022 ActiveTK."); WriteLine("*****************************************************************************"); var nws = new ActiveTKDotJP.WebServer(); Write("** new ActiveTKDotJP.WebServer().StartServerAsync()"); nws.StartServerAsync(); ForegroundColor = ConsoleColor.Green; WriteLine(" [OK]"); ResetColor(); WriteLine("** AppInfo:"); WriteLine(" Date : " + DateTime.Now.ToUniversalTime().ToString("R")); Process c = Process.GetCurrentProcess(); c.Refresh(); WriteLine(" ProcessID : " + c.Id); WriteLine(" ProcrssName : " + c.ProcessName); WriteLine(" MemorySize : " + c.WorkingSet64 / 1024 / 1024 + "MB"); WriteLine(" VirtualMemorySize : " + c.VirtualMemorySize64 / 1024 / 1024 + "MB"); WriteLine(" OS : " + Environment.OSVersion); WriteLine(" Whoami : \\\\" + Environment.MachineName + "\\" + Environment.UserName); WriteLine("*****************************************************************************"); nws.Join(); } catch (Exception e) { WriteLine(e.Message); WriteLine(e.StackTrace); } void Write(string Message) { try { File.AppendAllText("/home/activetk/logs/ActiveTKDotJP.log", Message); } catch { } } void WriteLine(string Message) { try { File.AppendAllText("/home/activetk/logs/ActiveTKDotJP.log", Message + Environment.NewLine); } catch { } } namespace ActiveTKDotJP { class WebServer { private TcpListener TCPListener = null; QBitNinjaClient BTCClient = new QBitNinjaClient(Network.Main); private bool _IsRunning = false; public string[] Cut(object strings, char cutword) { if (0 <= ((string)strings).IndexOf(cutword)) { } else strings = strings + cutword.ToString(); object command = strings, hikisuu = ""; try { int d = ((string)strings).IndexOf(cutword); command = ((string)strings).Remove(d); command = Environment.ExpandEnvironmentVariables(command.ToString()); hikisuu = ((string)strings).Remove(0, d + 1); hikisuu = Environment.ExpandEnvironmentVariables(hikisuu.ToString()); } catch { } return new string[2] { command.ToString(), hikisuu.ToString() }; } public static string[] Cut(object strings, string cutword) { if (0 <= ((string)strings).IndexOf(cutword)) { } else strings = strings + cutword.ToString(); object command = strings, hikisuu = ""; try { int d = ((string)strings).IndexOf(cutword); command = ((string)strings).Remove(d); command = command.ToString(); hikisuu = ((string)strings).Remove(0, d + 1); hikisuu = hikisuu.ToString(); } catch { } return new string[2] { command.ToString(), hikisuu.ToString() }; } public async void StartServerAsync() { TCPListener = new TcpListener(IPAddress.Loopback, 5929); TCPListener.Start(); _IsRunning = true; Hashtable ERR_DATA = new Hashtable { [400] = File.ReadAllText("/home/activetk/apps/atkdotjp/net6.0/Error/400.html"), [404] = File.ReadAllText("/home/activetk/apps/atkdotjp/net6.0/Error/404.html"), [500] = File.ReadAllText("/home/activetk/apps/atkdotjp/net6.0/Error/500.html") }; Hashtable FileData = new Hashtable(); string[] files = Directory.GetFiles("/home/activetk/apps/atkdotjp/net6.0/public_html", "*", SearchOption.AllDirectories); foreach (string file in files) { try { FileData[file.Remove(0, ("/home/activetk/apps/atkdotjp/net6.0/public_html").Length)] = File.ReadAllText(file); } catch { } } while (true) { var tcpClient = await TCPListener.AcceptTcpClientAsync(); #pragma warning disable CS4014 Task.Run(async () => { HTTPError HTTPError = new HTTPError(ERR_DATA); Hashtable headers = new Hashtable(); Random r = new Random(); using (var stream = tcpClient.GetStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) { try { var requestHeaders = new List(); while (true) { var line = await reader.ReadLineAsync(); if (string.IsNullOrWhiteSpace(line)) break; requestHeaders.Add(line); headers[Cut(line, ": ")[0].ToLower()] = Cut(line, ' ')[1]; } ClientInfo ClientInfo = new ClientInfo(headers, tcpClient.Client.RemoteEndPoint); var requestLine = requestHeaders.FirstOrDefault(); var requestParts = requestLine?.Split(new[] { ' ' }, 3); if (!requestHeaders.Any() || requestParts.Length != 3) { await writer.WriteLineAsync(HTTPError.Throw(400, "", ClientInfo)); return; } var met = requestParts[0].ToUpper(); var pathall = requestParts[1]; var httpvs = requestParts[2].ToUpper(); var qupath = Cut(pathall, '#')[0]; var param = Cut(pathall, '?')[1]; var paramarr = param.Split('&'); var path = Cut(qupath, '?')[0]; var patharr = path.Split('/'); if ((met != "GET" && met != "POST") || (httpvs != "HTTP/1.0" && httpvs != "HTTP/1.1")) { WriteLine("** [!ERR_UNKNOWN_METHOD] " + DateTime.Now.ToUniversalTime().ToString("R") + ": " + ClientInfo.ip + "(" + tcpClient.Client.RemoteEndPoint + ") => " + requestLine); await writer.WriteAsync(HTTPError.Throw(400, path, ClientInfo)); return; } var host = ClientInfo.GetHeader("x-host"); WriteLine("** [" + host + "] " + DateTime.Now.ToUniversalTime().ToString("R") + ": " + ClientInfo.ip + "(" + tcpClient.Client.RemoteEndPoint + ") => " + requestLine); if (empty(host)) await writer.WriteAsync(HTTPError.Throw(400, path, ClientInfo)); else if (host == "bitcoin.atkserver.localhost") { if (empty(path) || path == "/") { await writer.WriteLineAsync("HTTP/1.1 200 OK"); await writer.WriteLineAsync(DefaultHeaders("text/html")); string text = (string)FileData["/index.html"]; text = CGIRUN(text, ClientInfo, path + "?" + param); await writer.WriteLineAsync("Content-Length: " + Encoding.GetEncoding("UTF-8").GetByteCount(text)); await writer.WriteLineAsync(); await writer.WriteLineAsync(text); } else if (path == "/new") { await writer.WriteLineAsync("HTTP/1.1 200 OK"); await writer.WriteLineAsync(DefaultHeaders("text/html")); string text = (string)FileData["/new.html"]; text = CGIRUN(text, ClientInfo, path + "?" + param); await writer.WriteLineAsync("Content-Length: " + Encoding.GetEncoding("UTF-8").GetByteCount(text)); await writer.WriteLineAsync(); await writer.WriteLineAsync(text); } else if (path == "/source") { await writer.WriteLineAsync("HTTP/1.1 200 OK"); await writer.WriteLineAsync(DefaultHeaders("text/plain")); string text = (string)FileData["/Program.cs"]; await writer.WriteLineAsync("Content-Length: " + Encoding.GetEncoding("UTF-8").GetByteCount(text)); await writer.WriteLineAsync(); await writer.WriteLineAsync(text); } else if (patharr[1] == "debug") { await writer.WriteLineAsync("HTTP/1.1 200 OK"); await writer.WriteLineAsync(DefaultHeaders("text/html")); string text = "

良くこんなページに気づきましたねw

";
                                    text += "IPaddress: " + ClientInfo.ip.ToString() + "
"; text += "Time: " + DateTime.Now.ToUniversalTime().ToString("R") + "
"; text += "Path: " + htmlspecialchars(path) + "
"; text += "PathArr: "; foreach (string s in patharr) text += htmlspecialchars(s) + ", "; text += "
Param: " + htmlspecialchars(param) + "
"; text += "ParamArr: "; foreach (string s in paramarr) text += htmlspecialchars(s) + ", "; text += "

Headers:

"; text += htmlspecialchars(ClientInfo.GetAllHeader()); await writer.WriteLineAsync("Content-Length: " + Encoding.GetEncoding("UTF-8").GetByteCount(text)); await writer.WriteLineAsync(); await writer.WriteLineAsync(text); } else if (patharr[1] == "gen") { await writer.WriteLineAsync("HTTP/1.1 200 OK"); await writer.WriteLineAsync(DefaultHeaders("text/html")); var result = new Key(); var pub = result.PubKey; string text = "Public Address: " + pub.GetAddress(ScriptPubKeyType.Legacy, Network.Main).ToString() + Environment.NewLine; text += "Public Key: " + pub.ToString() + Environment.NewLine; text += "Private Key (WIF): " + result.GetWif(Network.Main); await writer.WriteLineAsync("Content-Length: " + Encoding.GetEncoding("UTF-8").GetByteCount(text)); await writer.WriteLineAsync(); await writer.WriteLineAsync(text); } else if (patharr[1] == "transaction") { if (patharr.Length < 3 || empty(patharr[2]) || !IsSafestr(patharr[2]) || patharr[2].Length != 64) { string text = "{\"statusCode\":400,\"message\":\"Invalid Hex String\",\"location\":null}"; await writer.WriteLineAsync("HTTP/1.1 200 OK"); await writer.WriteLineAsync(DefaultHeaders("application/json")); await writer.WriteLineAsync("Content-Length: " + Encoding.GetEncoding("UTF-8").GetByteCount(text)); await writer.WriteLineAsync(); await writer.WriteAsync(text); return; } var transactionId = patharr[2]; HttpRequestMessage req = new HttpRequestMessage(); req.Method = HttpMethod.Get; req.RequestUri = new Uri("http://api.qbit.ninja/transactions/" + transactionId); var result = await new HttpClient().SendAsync(req); string json; if (result.IsSuccessStatusCode) json = await result.Content.ReadAsStringAsync(); else json = "{\"statusCode\":400,\"message\":\"Invalid Hex String\",\"location\":null}"; await writer.WriteLineAsync("HTTP/1.1 200 OK"); await writer.WriteLineAsync(DefaultHeaders("application/json")); await writer.WriteLineAsync("Content-Length: " + Encoding.GetEncoding("UTF-8").GetByteCount(json)); await writer.WriteLineAsync(); await writer.WriteLineAsync(json); } else if (path == "/400") await writer.WriteAsync(HTTPError.Throw(400, path, ClientInfo)); else if (path == "/404") await writer.WriteAsync(HTTPError.Throw(404, path, ClientInfo)); else if (path == "/500") await writer.WriteAsync(HTTPError.Throw(500, path, ClientInfo)); else await writer.WriteAsync(HTTPError.Throw(404, path, ClientInfo)); } else if (host == "darkweb-archive.atkserver.localhost") { if (empty(path) || path == "/") await writer.WriteAsync(HTTPError.Throw(400, path, ClientInfo)); else if (!empty(patharr[1])) { await writer.WriteLineAsync("HTTP/1.1 200 OK"); await writer.WriteLineAsync(DefaultHeaders("text/html")); var archiverhandle = new WebArchive(); string uniqid = (string.Concat(Enumerable.Range(0, 1).Select(i => char.ConvertFromUtf32(new Random().Next('A', 'Z' + 1)))) + ((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString("X")).ToLower(); archiverhandle.uniqid = uniqid; archiverhandle.outpath = "/home/activetk/apps/darkweb-archive/data/" + uniqid + ".zip"; archiverhandle.temp = "/home/activetk/apps/darkweb-archive/temp/" + uniqid; archiverhandle.GetArchive(path); await writer.WriteLineAsync("Content-Length: " + Encoding.GetEncoding("UTF-8").GetByteCount(uniqid)); await writer.WriteLineAsync(); await writer.WriteLineAsync(uniqid); } else if (path == "/400") await writer.WriteAsync(HTTPError.Throw(400, path, ClientInfo)); else if (path == "/404") await writer.WriteAsync(HTTPError.Throw(404, path, ClientInfo)); else if (path == "/500") await writer.WriteAsync(HTTPError.Throw(500, path, ClientInfo)); else await writer.WriteAsync(HTTPError.Throw(404, path, ClientInfo)); } else await writer.WriteAsync(HTTPError.Throw(400, path, ClientInfo)); } catch (Exception e) { await writer.WriteAsync(HTTPError.ThrowInternal(e)); return; } } }); #pragma warning restore CS4014 } string CGIRUN(string Script, ClientInfo info, string path) { Script = Script.Replace("", path); Script = Script.Replace("", info.ip.ToString()); Script = Script.Replace("", DateTime.Now.ToUniversalTime().ToString("R")); Script = Script.Replace("", info.GetHeader("user-agent")); return Script; } string htmlspecialchars(string text) { text = text.Replace("<", "<"); text = text.Replace(">", ">"); return text; } bool empty(string text) { return string.IsNullOrWhiteSpace(text) ? true : false; } bool IsSafestr(string text) { return Regex.IsMatch(text, @"^[0-9a-zA-Z]+$"); } void WriteLine(string Message) { try { File.AppendAllText("/home/activetk/logs/ActiveTKDotJP.log", Message + Environment.NewLine); } catch { } } } public void Join() { while (true) { Thread.Sleep(5000); if (!IsRunning()) break; } } public bool IsRunning() { return _IsRunning; } private string DefaultHeaders(string ContentType) { string DefaultHeader = ""; DefaultHeader += "Connection: close" + Environment.NewLine; DefaultHeader += "Date: " + DateTime.Now.ToUniversalTime().ToString("R") + Environment.NewLine; DefaultHeader += "X-Server: ActiveTKDotJP.WebServer.Service (.NET 6.0)" + Environment.NewLine; DefaultHeader += "Content-Type: " + ContentType + "; charset=UTF-8"; return DefaultHeader; } } public class HTTPError { private Hashtable _ERR = null; private string DefaultHeaders(string ContentType) { string DefaultHeader = ""; DefaultHeader += "Connection: close" + Environment.NewLine; DefaultHeader += "Date: " + DateTime.Now.ToUniversalTime().ToString("R") + Environment.NewLine; DefaultHeader += "X-Server: ActiveTKDotJP.WebServer.Service (.NET 6.0)" + Environment.NewLine; DefaultHeader += "Content-Type: " + ContentType + "; charset=UTF-8" + Environment.NewLine; return DefaultHeader; } public HTTPError(Hashtable ERR) { _ERR = ERR; } public string Throw(int StatusCode, string path, ClientInfo info) { if (StatusCode == 400) return ERR_400(info, path); else if (StatusCode == 404) return ERR_404(info, path); else return ERR_500(info, path); } public string ThrowInternal(Exception e) { return ERR_500(e); } private string ERR_400(ClientInfo info, string path) { string Error = ""; Error += "HTTP/1.1 400 Bad Request" + Environment.NewLine; Error += DefaultHeaders("text/html"); string text = (string)_ERR[400]; text = CGIRUN(text, info, path); Error += "Content-Length: " + Encoding.GetEncoding("UTF-8").GetByteCount(text) + Environment.NewLine; Error += Environment.NewLine; Error += text; return Error; } private string ERR_404(ClientInfo info, string path) { string Error = ""; Error += "HTTP/1.1 404 Not Found" + Environment.NewLine; Error += DefaultHeaders("text/html"); string text = (string)_ERR[404]; text = CGIRUN(text, info, path); Error += "Content-Length: " + Encoding.GetEncoding("UTF-8").GetByteCount(text) + Environment.NewLine; Error += Environment.NewLine; Error += text; return Error; } private string ERR_500(ClientInfo info, string path) { string Error = ""; Error += "HTTP/1.1 500 Internal Server Error" + Environment.NewLine; Error += DefaultHeaders("text/html"); string text = (string)_ERR[500]; text = CGIRUN(text, info, path); Error += "Content-Length: " + Encoding.GetEncoding("UTF-8").GetByteCount(text) + Environment.NewLine; Error += Environment.NewLine; Error += text; return Error; } private string ERR_500(Exception e) { string Error = ""; Error += "HTTP/1.1 500 Internal Server Error" + Environment.NewLine; Error += DefaultHeaders("text/html"); string text = "

HTTP 500 / Internal Server Error


" + htmlspecialchars(e.Message) + "
" + htmlspecialchars(e.StackTrace); Error += "Content-Length: " + Encoding.GetEncoding("UTF-8").GetByteCount(text) + Environment.NewLine; Error += Environment.NewLine; Error += text; return Error; } private string CGIRUN(string Script, ClientInfo info, string path) { Script = Script.Replace("", path); Script = Script.Replace("", info.ip); Script = Script.Replace("", DateTime.Now.ToUniversalTime().ToString("R")); Script = Script.Replace("", info.GetHeader("User-Agent")); return Script; } string htmlspecialchars(string text) { text = text.Replace("<", "<"); text = text.Replace(">", ">"); return text; } } public class ClientInfo { public string ip = ""; public Hashtable headers = new Hashtable() { }; public ClientInfo(Hashtable _headers, EndPoint _ip) { headers = _headers; ip = GetHeader("cf-connecting-ip"); if (ip == null || ip == "") ip = _ip.ToString(); } public string GetHeader(string headername) { try { if (headername == null) return ""; return (string)headers[headername.ToLower()]; } catch { return ""; } } public string GetAllHeader() { string dump = ""; foreach (string key in headers.Keys) if (key != "x-host") dump += key + ": " + headers[key] + Environment.NewLine; return dump; } } public class WebArchive { public string outpath = ""; public string temp = ""; public string uniqid = ""; public void GetArchive(string path) { try { Directory.CreateDirectory(temp); temp += "/"; } catch { return; } WriteLineX("*****************************************************************************"); WriteLineX("** ActiveTKDotJP DarkWeb-Archive / Build.20230105#BETA"); WriteLineX("** Download Data: https://darkweb-archive.activetk.jp/?q=" + uniqid); WriteLineX("** Contact: webmaster[@]activetk.jp / PGP: rinu.cf/pgp"); WriteLineX("*****************************************************************************"); WriteLine("[START] SystemConfig[]: uniqid=" + uniqid + ";url=http:/" + path + ";"); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag("en"); var url = "http:/" + path; try { /* fetching first file */ string filename = Path.GetFileName(url); if (filename == "" || filename == "/") filename = "index.php"; Uri baseurl = new Uri(url); filename = Cut(filename, '?')[0]; WriteLine("FirstFile.Name => " + filename); var local = temp; if (local.Remove(local.Length - 1) != "/" && local.Remove(local.Length - 1) != "/") local += "/"; if (Directory.Exists(local + baseurl.Host)) { } else { Directory.CreateDirectory(local + baseurl.Host); WriteLine("mkdir [/" + baseurl.Host + "]"); } string dfilename = local + baseurl.Host + "/" + Cut(filename, '?')[0]; WriteLine("Fetching => http://" + baseurl.DnsSafeHost + baseurl.PathAndQuery); var handler = new HttpClientHandler(); handler.Proxy = new HttpToSocks5Proxy("127.0.0.1", 9050); handler.UseProxy = true; var client = new HttpClient(handler); client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"); client.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); client.DefaultRequestHeaders.Add("Accept-Encoding", ""); client.DefaultRequestHeaders.Add("Accept-Language", "en-US,en;q=0.5"); client.DefaultRequestHeaders.Add("Sec-Fetch-Dest", "document"); client.DefaultRequestHeaders.Add("Sec-Fetch-Mode", "navigate"); client.DefaultRequestHeaders.Add("Sec-Fetch-Site", "none"); client.DefaultRequestHeaders.Add("Sec-Fetch-User", "?1"); client.DefaultRequestHeaders.Add("Upgrade-Insecure-Requests", "1"); client.Timeout = TimeSpan.FromMilliseconds(60000); var e = client.GetAsync("http://" + baseurl.DnsSafeHost + baseurl.PathAndQuery); e.Wait(); WriteLineX("-----BEGIN HTTP RESPONSE HEADERS-----"); WriteX(Enumerable .Empty<(String name, String value)>() .Concat( e.Result.Headers .SelectMany(kvp => kvp.Value .Select(v => (name: kvp.Key, value: v)) ) ) .Concat( e.Result.Content.Headers .SelectMany(kvp => kvp.Value .Select(v => (name: kvp.Key, value: v)) ) ) .Aggregate( seed: new StringBuilder(), func: (sb, pair) => sb.Append(pair.name).Append(": ").Append(pair.value).AppendLine(), resultSelector: sb => sb.ToString() )); WriteLineX("----END HTTP RESPONSE HEADERS----"); var data = e.Result.Content.ReadAsStringAsync().Result; File.WriteAllText(dfilename, data); WriteLine("Data saved at /" + baseurl.Host + "/" + Cut(filename, '?')[0]); byte[] FileData = Encoding.GetEncoding("UTF-8").GetBytes(data); WriteLine(" FileSize: " + FileData.Length); WriteLine(" MD5 : " + GetMD5Hash(FileData)); WriteLine(" SHA1 : " + GetSHA1Hash(FileData)); WriteLine(" SHA256 : " + GetSHA256Hash(FileData)); WriteLine(" SHA384 : " + GetSHA384Hash(FileData)); WriteLine(" SHA512 : " + GetSHA512Hash(FileData)); WriteLineX("*****************************************************************************"); string[] filter = { @"src=""(?.*?)""", @"href=""(?.*?)""" }; WriteLine("URL filters: [" + string.Join(", ", filter) + "]"); /* fetching next file */ string[] URLs = { }; var encode = DetectEncodingFromBOM(FileData); string text = ""; if (encode == null) { WriteLine("[WARN] Unknown Encoding; using Encoding.UTF8"); encode = Encoding.UTF8; } text = encode.GetString(FileData); decimal i = 0; foreach (string f in filter) { var q = from Match m in Regex.Matches(text, f) where m.Success select m.Groups["url"]; foreach (var x in q) { if (Cut(x.ToString(), ':')[0] == "data") continue; i++; if (i > 1000) break; WriteLine("Found URL (" + i + ")[" + x + "]"); Uri u = new Uri(baseurl, x.ToString()); WriteLine(" this.AbsoluteUri => " + u.AbsoluteUri); Array.Resize(ref URLs, URLs.Length + 1); URLs[URLs.Length - 1] = u.AbsoluteUri; } } foreach (string URL in URLs.Distinct()) { try { if (URL == baseurl.AbsoluteUri) continue; WriteLineX("*****************************************************************************"); Uri u2 = new Uri(URL); WriteLine("Fetching => http://" + u2.DnsSafeHost + u2.PathAndQuery); if (!Directory.Exists(local + u2.Host)) { Directory.CreateDirectory(local + u2.Host); WriteLine(" mkdir [/" + u2.Host + "]"); } string wherepath = u2.Host, last = ""; foreach (string t in u2.Segments) { wherepath += t; if (t == "/" || t == "" || Directory.Exists(local + wherepath)) { } else { try { if (!File.Exists(local + wherepath)) Directory.CreateDirectory(local + wherepath); else { File.Move(local + wherepath, local + wherepath + "_tmp"); Directory.CreateDirectory(local + wherepath); File.Move(local + wherepath + "_tmp", local + wherepath + "index.html"); } } catch (Exception e3) { WriteLine("[WARN] " + e3.Message); WriteLine(e3.StackTrace); } WriteLine(" mkdir [/" + wherepath + "]"); last = wherepath; } } if (Directory.Exists(local + last)) { RMDIR(local + last); WriteLine(" rmdir [/" + last + "]"); } var e2 = client.GetAsync("http://" + u2.DnsSafeHost + u2.PathAndQuery); e2.Wait(); WriteLineX("-----BEGIN HTTP RESPONSE HEADERS-----"); WriteX(Enumerable .Empty<(String name, String value)>() .Concat( e2.Result.Headers .SelectMany(kvp => kvp.Value .Select(v => (name: kvp.Key, value: v)) ) ) .Concat( e.Result.Content.Headers .SelectMany(kvp => kvp.Value .Select(v => (name: kvp.Key, value: v)) ) ) .Aggregate( seed: new StringBuilder(), func: (sb, pair) => sb.Append(pair.name).Append(": ").Append(pair.value).AppendLine(), resultSelector: sb => sb.ToString() )); WriteLineX("----END HTTP RESPONSE HEADERS----"); var data2 = e2.Result.Content.ReadAsStringAsync().Result; WriteLine("Saving Data.. [/" + Cut(wherepath, '?')[0] + "]"); File.WriteAllText(local + Cut(wherepath, '?')[0], data2); byte[] FileData2 = Encoding.GetEncoding("UTF-8").GetBytes(data2); WriteLine(" FileSize: " + FileData2.Length); WriteLine(" MD5 : " + GetMD5Hash(FileData2)); WriteLine(" SHA1 : " + GetSHA1Hash(FileData2)); WriteLine(" SHA256 : " + GetSHA256Hash(FileData2)); WriteLine(" SHA384 : " + GetSHA384Hash(FileData2)); WriteLine(" SHA512 : " + GetSHA512Hash(FileData2)); } catch (Exception e2) { WriteLine("[WARN] " + e2.Message); WriteLine(e2.StackTrace); } } } catch (Exception e) { WriteLine("[ERROR] " + e.Message); WriteLineX(e.StackTrace); } WriteLineX("*****************************************************************************"); WriteLine("[END]"); WriteLineX("*****************************************************************************"); /* temp to zip */ ZipFile.CreateFromDirectory(temp, outpath, CompressionLevel.Optimal, true); RMDIR(temp); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfoByIetfLanguageTag("ja"); } private void WriteLineX(string Message) { try { File.AppendAllText(temp + "info.log", Message + Environment.NewLine); } catch { } } private void WriteX(string Message) { try { File.AppendAllText(temp + "info.log", Message); } catch { } } private void WriteLine(string Message) { try { File.AppendAllText(temp + "info.log", "** " + DateTime.Now.ToUniversalTime().ToString("R") + ": " + Message + Environment.NewLine); } catch { } } public static void RMDIR(string targetDirectoryPath) { if (!Directory.Exists(targetDirectoryPath)) return; string[] filePaths = Directory.GetFiles(targetDirectoryPath); foreach (string filePath in filePaths) { File.SetAttributes(filePath, FileAttributes.Normal); File.Delete(filePath); } string[] directoryPaths = Directory.GetDirectories(targetDirectoryPath); foreach (string directoryPath in directoryPaths) RMDIR(directoryPath); Directory.Delete(targetDirectoryPath, false); } public string[] Cut(object strings, char cutword) { if (0 <= ((string)strings).IndexOf(cutword)) { } else strings = strings + cutword.ToString(); object command = strings, hikisuu = ""; try { int d = ((string)strings).IndexOf(cutword); command = ((string)strings).Remove(d); command = Environment.ExpandEnvironmentVariables(command.ToString()); hikisuu = ((string)strings).Remove(0, d + 1); hikisuu = Environment.ExpandEnvironmentVariables(hikisuu.ToString()); } catch { } return new string[2] { command.ToString(), hikisuu.ToString() }; } public static string[] Cut(object strings, string cutword) { if (0 <= ((string)strings).IndexOf(cutword)) { } else strings = strings + cutword.ToString(); object command = strings, hikisuu = ""; try { int d = ((string)strings).IndexOf(cutword); command = ((string)strings).Remove(d); command = command.ToString(); hikisuu = ((string)strings).Remove(0, d + 1); hikisuu = hikisuu.ToString(); } catch { } return new string[2] { command.ToString(), hikisuu.ToString() }; } public static string GetMD5Hash(byte[] data) { System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); var str2 = new StringBuilder(); foreach (byte byte_ in new MD5CryptoServiceProvider().ComputeHash(data)) str2.Append(byte_.ToString("x2")); sw.Stop(); return str2.ToString() + " (" + sw.Elapsed.TotalMilliseconds + "ms)"; } public static string GetSHA1Hash(byte[] data) { System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); var str2 = new StringBuilder(); foreach (byte byte_ in new SHA1CryptoServiceProvider().ComputeHash(data)) str2.Append(byte_.ToString("x2")); sw.Stop(); return str2.ToString() + " (" + sw.Elapsed.TotalMilliseconds + "ms)"; } public static string GetSHA256Hash(byte[] data) { System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); var str2 = new StringBuilder(); foreach (byte byte_ in new SHA256CryptoServiceProvider().ComputeHash(data)) str2.Append(byte_.ToString("x2")); sw.Stop(); return str2.ToString() + " (" + sw.Elapsed.TotalMilliseconds + "ms)"; } public static string GetSHA384Hash(byte[] data) { System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); var str2 = new StringBuilder(); foreach (byte byte_ in new SHA384CryptoServiceProvider().ComputeHash(data)) str2.Append(byte_.ToString("x2")); sw.Stop(); return str2.ToString() + " (" + sw.Elapsed.TotalMilliseconds + "ms)"; } public static string GetSHA512Hash(byte[] data) { System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); var str2 = new StringBuilder(); foreach (byte byte_ in new SHA512CryptoServiceProvider().ComputeHash(data)) str2.Append(byte_.ToString("x2")); sw.Stop(); return str2.ToString() + " (" + sw.Elapsed.TotalMilliseconds + "ms)"; } private static Encoding DetectEncodingFromBOM(byte[] bytes) { if (bytes.Length < 2) { return null; } if ((bytes[0] == 0xfe) && (bytes[1] == 0xff)) { //UTF-16 BE return new System.Text.UnicodeEncoding(true, true); } if ((bytes[0] == 0xff) && (bytes[1] == 0xfe)) { if ((4 <= bytes.Length) && (bytes[2] == 0x00) && (bytes[3] == 0x00)) { //UTF-32 LE return new System.Text.UTF32Encoding(false, true); } //UTF-16 LE return new System.Text.UnicodeEncoding(false, true); } if (bytes.Length < 3) { return null; } if ((bytes[0] == 0xef) && (bytes[1] == 0xbb) && (bytes[2] == 0xbf)) { //UTF-8 return new System.Text.UTF8Encoding(true, true); } if (bytes.Length < 4) { return null; } if ((bytes[0] == 0x00) && (bytes[1] == 0x00) && (bytes[2] == 0xfe) && (bytes[3] == 0xff)) { //UTF-32 BE return new System.Text.UTF32Encoding(true, true); } return null; } } }