Advertisement
V10

kongor_anonymize

V10
Nov 17th, 2024
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 6.25 KB | Gaming | 0 0
  1. @{}<#<nul>nul 2>&1
  2. @echo off
  3. rem Project KONGOR launcher.exe Anonymizer v1.0 (16.11.2024) by V10 http://V10.name
  4. rem ============================================================================================================
  5. rem Place this script in HoN directory and start it (required Admin privileges to work)
  6. rem This script anonymize data sended by Project KONGOR launcher to prevent stealing your private data.
  7. rem This script make temprary changes to hosts file and restore changes at end
  8. rem This script open TCP port 80 on localhost due working
  9. rem This script create 2 files with you data named collected_data.json and anonymized_data.json
  10. rem ============================================================================================================
  11. set LAUNCHER_FILE=launcher.exe
  12. rem ============================================================================================================
  13. rem Initialize()
  14.  
  15. if not exist "%LAUNCHER_FILE%" (
  16.    if not exist "%~dp0%LAUNCHER_FILE%" (
  17.       echo Cant find launcher in "%LAUNCHER_FILE%" or "%~dp0\%LAUNCHER_FILE%"
  18.       pause
  19.       exit /b
  20.    )
  21.    set LAUNCHER_FILE=%~dp0%LAUNCHER_FILE%
  22. )
  23. cd /d "%~dp0"
  24. echo Requesting elevated priveleges
  25. if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
  26. echo.>%0:Zone.Identifier
  27. rem ============================================================================================================
  28. rem Main()
  29. echo Backup hosts file and make changes
  30. copy %DriverData%\..\etc\hosts %DriverData%\..\etc\hosts.bak
  31. echo 127.0.0.1 api.projectkongor.com>>%DriverData%\..\etc\hosts
  32. ipconfig /flushdns >nul
  33. echo Starting %LAUNCHER_FILE% with user priveleges
  34. explorer "%LAUNCHER_FILE%"
  35. echo Starting kongor api proxy
  36. powershell -ExecutionPolicy RemoteSigned -NoProfile -Command -<%0
  37. echo Restoring hosts file
  38. copy %DriverData%\..\etc\hosts.bak %DriverData%\..\etc\hosts
  39. ipconfig /flushdns >nul
  40. timeout /T 10
  41. exit /b
  42.  
  43. rem ============================================================================================================
  44. rem  PowerShell script http_proxy_kongor.ps1
  45. rem ============================================================================================================
  46. rem #>;
  47.  
  48. # Globals & Settings
  49. #$DebugPreference = "Continue"
  50. [System.Net.ServicePointManager]::Expect100Continue = $false
  51. $hasher = [System.Security.Cryptography.HashAlgorithm]::Create('sha256')
  52. $hash_salt = "IWillNeverBreakUserPrivacy"
  53. $collected_data_file = 'collected_data.json'
  54. $anonymized_data_file = 'anonymized_data.json'
  55.  
  56. function GetHash($s)
  57. {
  58.     return [System.BitConverter]::ToString($hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($s+$hash_salt))).Replace('-', '')
  59. }
  60.  
  61. function AnonymizeList($list)
  62. {
  63.     for ($i = 0; $i -lt $list.Length; $i++) {
  64.         if ($list[$i] -is [Object[]]) { AnonymizeList $list[$i] } else { $list[$i] = GetHash $list[$i] }
  65.     }
  66. }
  67.  
  68. function AnonymizeData($json, $level=0)
  69. {
  70.     foreach ($key in $json.PSObject.Properties.name) {
  71.         $value = $json.$key
  72.         if ($value -is [Object[]]) {
  73.             AnonymizeList $value
  74.         } elseif ($value -is [PSCustomObject]) {
  75.             AnonymizeData $value ($level+1)
  76.         } else {
  77.             $value = GetHash $value
  78.             $json.$key = $value
  79.         }
  80.         if ($level -eq 1) {
  81.             $json.PSObject.Properties.Remove($key)
  82.             $key = GetHash $key
  83.             $json.PSObject.Properties.Add([PSNoteProperty]::new($key, $value))
  84.         }
  85.     }
  86. }
  87.  
  88. function RequestOriginalAPI($body, $rawurl)
  89. {
  90.     $msw = New-Object System.IO.MemoryStream
  91.     $wr = New-Object System.IO.StreamWriter(New-Object System.IO.Compression.DeflateStream($msw, [System.IO.Compression.CompressionMode]::Compress))
  92.     $wr.Write($body)
  93.     $wr.Close()
  94.     $body_bytes = $msw.ToArray()
  95.  
  96.     $dns = Resolve-DnsName api.projectkongor.com -NoHostsFile | WHERE Ip4Address | SELECT Ip4Address | Random
  97.     $url = "http://" + $dns.Ip4Address + $rawurl
  98.     Write-Host "Requesting original api in $url ..."
  99.     #$url = "http://127.0.0.1:8080" + $rawurl
  100.     $result = Invoke-WebRequest -DisableKeepAlive -UseBasicParsing -Method POST -Uri "$url" -ContentType "application/octet-stream" -Body $body_bytes -Headers @{
  101.         "Host"="api.projectkongor.com"
  102.         "User-Agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.46"
  103.     }
  104.     return $result
  105. }
  106.  
  107. function SendResponse($resp, $oresp)
  108. {
  109.     Write-Host "Sending response to launcher..."
  110.     $content = $oresp.Content
  111.     $result_bytes = [Text.Encoding]::UTF8.GetBytes($content)
  112.     $resp.KeepAlive = 0
  113.     $resp.StatusCode = $oresp.StatusCode
  114.     $resp.ContentType = $oresp.Headers."Content-Type"
  115.     $resp.ContentLength64 = $result_bytes.Length
  116.     $resp.OutputStream.Write($result_bytes , 0, $result_bytes.Length)
  117.     $resp.OutputStream.Close() 
  118.     $resp.Close()  
  119. }
  120.  
  121. function ProcessRequest($request)
  122. {
  123.     Write-Host "Processing request from" $request.RemoteEndPoint "..."
  124.     Write-Debug ($request | Format-List | Out-String)
  125.     $reader = New-Object System.IO.StreamReader(New-Object System.IO.Compression.DeflateStream($request.InputStream, [System.IO.Compression.CompressionMode]::Decompress))
  126.     $body = $reader.ReadToEnd()
  127.     $reader.Close()
  128.     Write-Debug $body
  129.     $json = ConvertFrom-JSON -InputObject $body
  130.     ConvertTo-JSON -InputObject $json | Out-File -Encoding Utf8 $collected_data_file
  131.     Write-Host "Anonymizing data..."
  132.     AnonymizeData $json
  133.     ConvertTo-JSON -InputObject $json | Out-File -Encoding Utf8 $anonymized_data_file
  134.     $body = ConvertTo-JSON -Compress -InputObject $json
  135.     return $body
  136. }
  137.  
  138. function HandleRequest($ctx)
  139. {
  140.     $anondata = ProcessRequest $ctx.Request
  141.     Write-Debug $anondata
  142.     $oresp = RequestOriginalAPI $anondata $ctx.Request.RawUrl
  143.     Write-Debug ($oresp | Format-List | Out-String)
  144.     Write-Debug $oresp.RawContent
  145.     SendResponse $ctx.Response $oresp
  146.     Write-Debug ($ctx.Response | Format-List | Out-String)
  147. }
  148.  
  149. function main()
  150. {
  151.     $proxy = New-Object System.Net.HttpListener
  152.     $proxy.Prefixes.Add("http://127.0.0.1:80/")
  153.     $proxy.Start()    
  154.     HandleRequest $proxy.GetContext()
  155.     Write-Host "All done"
  156. }
  157.  
  158. main
  159. if ($Error) {
  160.     Pause
  161. }
  162.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement