Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @{}<#<nul>nul 2>&1
- @echo off
- rem Project KONGOR launcher.exe Anonymizer v1.0 (16.11.2024) by V10 http://V10.name
- rem ============================================================================================================
- rem Place this script in HoN directory and start it (required Admin privileges to work)
- rem This script anonymize data sended by Project KONGOR launcher to prevent stealing your private data.
- rem This script make temprary changes to hosts file and restore changes at end
- rem This script open TCP port 80 on localhost due working
- rem This script create 2 files with you data named collected_data.json and anonymized_data.json
- rem ============================================================================================================
- set LAUNCHER_FILE=launcher.exe
- rem ============================================================================================================
- rem Initialize()
- if not exist "%LAUNCHER_FILE%" (
- if not exist "%~dp0%LAUNCHER_FILE%" (
- echo Cant find launcher in "%LAUNCHER_FILE%" or "%~dp0\%LAUNCHER_FILE%"
- pause
- exit /b
- )
- set LAUNCHER_FILE=%~dp0%LAUNCHER_FILE%
- )
- cd /d "%~dp0"
- echo Requesting elevated priveleges
- if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
- echo.>%0:Zone.Identifier
- rem ============================================================================================================
- rem Main()
- echo Backup hosts file and make changes
- copy %DriverData%\..\etc\hosts %DriverData%\..\etc\hosts.bak
- echo 127.0.0.1 api.projectkongor.com>>%DriverData%\..\etc\hosts
- ipconfig /flushdns >nul
- echo Starting %LAUNCHER_FILE% with user priveleges
- explorer "%LAUNCHER_FILE%"
- echo Starting kongor api proxy
- powershell -ExecutionPolicy RemoteSigned -NoProfile -Command -<%0
- echo Restoring hosts file
- copy %DriverData%\..\etc\hosts.bak %DriverData%\..\etc\hosts
- ipconfig /flushdns >nul
- timeout /T 10
- exit /b
- rem ============================================================================================================
- rem PowerShell script http_proxy_kongor.ps1
- rem ============================================================================================================
- rem #>;
- # Globals & Settings
- #$DebugPreference = "Continue"
- [System.Net.ServicePointManager]::Expect100Continue = $false
- $hasher = [System.Security.Cryptography.HashAlgorithm]::Create('sha256')
- $hash_salt = "IWillNeverBreakUserPrivacy"
- $collected_data_file = 'collected_data.json'
- $anonymized_data_file = 'anonymized_data.json'
- function GetHash($s)
- {
- return [System.BitConverter]::ToString($hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($s+$hash_salt))).Replace('-', '')
- }
- function AnonymizeList($list)
- {
- for ($i = 0; $i -lt $list.Length; $i++) {
- if ($list[$i] -is [Object[]]) { AnonymizeList $list[$i] } else { $list[$i] = GetHash $list[$i] }
- }
- }
- function AnonymizeData($json, $level=0)
- {
- foreach ($key in $json.PSObject.Properties.name) {
- $value = $json.$key
- if ($value -is [Object[]]) {
- AnonymizeList $value
- } elseif ($value -is [PSCustomObject]) {
- AnonymizeData $value ($level+1)
- } else {
- $value = GetHash $value
- $json.$key = $value
- }
- if ($level -eq 1) {
- $json.PSObject.Properties.Remove($key)
- $key = GetHash $key
- $json.PSObject.Properties.Add([PSNoteProperty]::new($key, $value))
- }
- }
- }
- function RequestOriginalAPI($body, $rawurl)
- {
- $msw = New-Object System.IO.MemoryStream
- $wr = New-Object System.IO.StreamWriter(New-Object System.IO.Compression.DeflateStream($msw, [System.IO.Compression.CompressionMode]::Compress))
- $wr.Write($body)
- $wr.Close()
- $body_bytes = $msw.ToArray()
- $dns = Resolve-DnsName api.projectkongor.com -NoHostsFile | WHERE Ip4Address | SELECT Ip4Address | Random
- $url = "http://" + $dns.Ip4Address + $rawurl
- Write-Host "Requesting original api in $url ..."
- #$url = "http://127.0.0.1:8080" + $rawurl
- $result = Invoke-WebRequest -DisableKeepAlive -UseBasicParsing -Method POST -Uri "$url" -ContentType "application/octet-stream" -Body $body_bytes -Headers @{
- "Host"="api.projectkongor.com"
- "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"
- }
- return $result
- }
- function SendResponse($resp, $oresp)
- {
- Write-Host "Sending response to launcher..."
- $content = $oresp.Content
- $result_bytes = [Text.Encoding]::UTF8.GetBytes($content)
- $resp.KeepAlive = 0
- $resp.StatusCode = $oresp.StatusCode
- $resp.ContentType = $oresp.Headers."Content-Type"
- $resp.ContentLength64 = $result_bytes.Length
- $resp.OutputStream.Write($result_bytes , 0, $result_bytes.Length)
- $resp.OutputStream.Close()
- $resp.Close()
- }
- function ProcessRequest($request)
- {
- Write-Host "Processing request from" $request.RemoteEndPoint "..."
- Write-Debug ($request | Format-List | Out-String)
- $reader = New-Object System.IO.StreamReader(New-Object System.IO.Compression.DeflateStream($request.InputStream, [System.IO.Compression.CompressionMode]::Decompress))
- $body = $reader.ReadToEnd()
- $reader.Close()
- Write-Debug $body
- $json = ConvertFrom-JSON -InputObject $body
- ConvertTo-JSON -InputObject $json | Out-File -Encoding Utf8 $collected_data_file
- Write-Host "Anonymizing data..."
- AnonymizeData $json
- ConvertTo-JSON -InputObject $json | Out-File -Encoding Utf8 $anonymized_data_file
- $body = ConvertTo-JSON -Compress -InputObject $json
- return $body
- }
- function HandleRequest($ctx)
- {
- $anondata = ProcessRequest $ctx.Request
- Write-Debug $anondata
- $oresp = RequestOriginalAPI $anondata $ctx.Request.RawUrl
- Write-Debug ($oresp | Format-List | Out-String)
- Write-Debug $oresp.RawContent
- SendResponse $ctx.Response $oresp
- Write-Debug ($ctx.Response | Format-List | Out-String)
- }
- function main()
- {
- $proxy = New-Object System.Net.HttpListener
- $proxy.Prefixes.Add("http://127.0.0.1:80/")
- $proxy.Start()
- HandleRequest $proxy.GetContext()
- Write-Host "All done"
- }
- main
- if ($Error) {
- Pause
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement