Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. $ErrorActionPreference = "STOP"
  2.  
  3. $sqlServer = "127.0.0.1"
  4. $sqlUser = "cohserver"
  5. $sqlPassword = "freecoh"
  6. $sqlDb = "cohauth"
  7.  
  8. $userName = "coh"
  9. $userId = 200
  10. $userPassword = "coh"
  11.  
  12. function Get-Adler32 {
  13. param(
  14. [string] $data
  15. )
  16.  
  17. $mod_adler = 65521
  18. $a = 1
  19. $b = 0
  20. $len = $data.Length
  21. for ($index = 0; $index -lt $len; $index++) {
  22. $a = ($a + [byte]$data[$index]) % $mod_adler
  23. $b = ($b + $a) % $mod_adler
  24. }
  25.  
  26. return ($b -shl 16) -bor $a;
  27. }
  28.  
  29. function Get-HashedPassword {
  30. param(
  31. [string] $UserName,
  32. [string] $Password
  33. )
  34. $a32 = adler32($UserName.ToLower())
  35. $a32hex = $a32.ToString("x8")
  36. $a32hex = $a32hex.Substring(6, 2) + $a32hex.Substring(4, 2) + $a32hex.Substring(2, 2) + $a32hex.Substring(0, 2)
  37. $bytes = [System.Text.Encoding]::UTF8.GetBytes($Password + $a32hex)
  38. $digest = [System.Security.Cryptography.HashAlgorithm]::Create("SHA512").ComputeHash($bytes)
  39. return $digest
  40. }
  41.  
  42. function Get-Connection {
  43. $connection = [System.Data.SqlClient.SqlConnection]::new()
  44. $connection.ConnectionString = "Server='$sqlServer';Database='$sqlDb';User Id='$sqlUser';Password='$sqlPassword';"
  45. $connection.Open()
  46. return $connection
  47. }
  48.  
  49. function Set-UserAccount {
  50. param(
  51. [System.Data.SqlClient.SqlConnection] $Connection,
  52. [string] $UserName,
  53. [int] $UserId,
  54. [int] $ForumId
  55. )
  56.  
  57. $command = [System.Data.SqlClient.SqlCommand]::new()
  58. $command.Connection = $Connection
  59. $command.CommandText = "INSERT INTO user_account (account, uid, forum_id, pay_stat) VALUES (@UserName, @UserId, @ForumId, 1014);"
  60. $command.Parameters.AddWithValue("@UserName", $UserName) > $null
  61. $command.Parameters.AddWithValue("@UserId", $UserId) > $null
  62. $command.Parameters.AddWithValue("@ForumId", $ForumId) > $null
  63. $command.ExecuteScalar()
  64. $command.Dispose()
  65. }
  66.  
  67. function Set-UserAuth {
  68. param(
  69. [System.Data.SqlClient.SqlConnection] $Connection,
  70. [string] $UserName,
  71. [byte[]] $HashedPassword
  72. )
  73.  
  74. $p = ""
  75. foreach($byte in $hashedPassword) {
  76. $p = $p + $byte.ToString("x2");
  77. }
  78.  
  79. $command = [System.Data.SqlClient.SqlCommand]::new()
  80. $command.Connection = $Connection
  81. $command.CommandText = "INSERT INTO user_auth (account, password, salt, hash_type) VALUES (@UserName, CONVERT(BINARY(128), '$p'), 0, 1);"
  82. $command.Parameters.AddWithValue("@UserName", $UserName) > $null
  83. # Using AddWithValue for the password results in extra bytes being added to the string for some reason?
  84. # In a rush, so hack it for now
  85. #$command.Parameters.AddWithValue("@Password", $HashedPassword)
  86. #$command.Parameters.AddWithValue("@Password", $p)
  87. $command.ExecuteScalar()
  88. $command.Dispose()
  89. }
  90.  
  91. function Set-UserData {
  92. param(
  93. [System.Data.SqlClient.SqlConnection] $Connection,
  94. [string] $UserId
  95. )
  96.  
  97. $command = [System.Data.SqlClient.SqlCommand]::new()
  98. $command.Connection = $Connection
  99. $command.CommandText = "INSERT INTO user_data (uid, user_data) VALUES (@UserId, 0x0080C2E000D00B0C000000000CB40058);"
  100. $command.Parameters.AddWithValue("@UserId", $UserId) > $null
  101. $command.ExecuteScalar()
  102. $command.Dispose()
  103. }
  104.  
  105. function Set-User {
  106. param(
  107. [string] $UserName,
  108. [string] $Password,
  109. [int] $UserId,
  110. [int] $ForumId
  111. )
  112.  
  113. $hashedPassword = Get-HashedPassword -UserName $UserName -Password $Password
  114.  
  115. $connection = Get-Connection
  116. Set-UserAccount -Connection $connection -UserName $UserName -UserId $UserId -ForumId $UserId
  117. Set-UserAuth -Connection $connection -UserName $UserName -HashedPassword $hashedPassword
  118. Set-UserData -Connection $connection -UserId $UserId
  119. $connection.Dispose()
  120. }
  121.  
  122. Set-User -UserName $userName -Password $userPassword -UserId $userId -ForumId $forumId
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement