Mark Minasi's Tech Forum
Register Calendar Latest Topics Chat
 
 
 


Reply
  Author   Comment  
jsclmedave

Administrator
Registered:
Posts: 418
Reply with quote  #1 

 This is really geeky BUT can be useful if posting your email On-Line where someone will have to know to use PowerShell to unravel it.   <g>


 The full explanation I initially came across can be found here http://rakhesh.com/powershell/obfuscate-email-addresses-with-powershell/

 
The first time I saw this being used as “Contact Info” was from from Rob Campbell, ‏@mjolinor  on Twitter, who was kind enough to point me to this link for further reference – “Post your sig thread”

 

Note there are a couple minor typos in the original link but I believe I was able to sort them all out below.

 

First we need to measure the email address, So for example -

Code:

"MarkMinasi@BigDog.com" | Measure-Object -Character

Lines Words Characters Property
----- -----    ----------    --------
                   21

 

 

So now we know that this email address is going to be 21 Characters = (0..20|% for our script below.

Here are the values we get converting the Character into a Integer –

Code:

[int[]][char[]]"MarkMinasi@BigDog.com" -join " "

 

77 97 114 107 77 105 110 97 115 105 64 66 105 103 68 111 103 46 99 111 109

 

Now let’s convert it all to a String to see the actual value that we have defined –

Code:

[String][char[]][int[]]("77 97 114 107 77 105 110 97 115 105 64 66 105 103 68 111 103 46 99 111 109".Split(" ")) -replace " "

 

MarkMinasi@BigDog.com

 

Now let’s take it a step further and subtract a value from each integer we created –

Code:

([int[]][char[]]"MarkMinasi@BigDog.com" | %{ $_ -46 }) -join " "

 

31 51 68 61 31 59 64 51 69 59 18 20 59 57 22 65 57 0 53 65 63

 

I see a problem with subtracting this value –

31 51 68 61 31 59 64 51 69 59 18 20 59 57 22 65 57 0 53 65 63


This will error off since it cannot handle the 0 placeholder.

 

NOTE!! For this step you will need to use    -join ""  without spaces or you will get a mess…

 

 

Code:

([int[]][char[]]"MarkMinasi@BigDog.com" | %{ $_ -46 }) -join ""

 

 

 

[string](0..20|%{[char][int](46+("31516861315964516959182059572265570536563").substring(($_*2),2))})-replace ""

 

Exception calling "Substring" with "2" argument(s): "Index and length must refer to a location within the string.

Parameter name: length"

At line:1 char:18

+ ... ng](0..20|%{[char][int](46+("3151686131596451695918205957226557053656 ...

+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : ArgumentOutOfRangeException

 

M a r k M i n a s i @ B i g D o g 3 R f

 

 

 

To fix this you can either add a following 0 or put a space ahead of the 0 –

 

 

Code:

[string](0..20|%{[char][int](46+("315168613159645169591820595722655700536563").substring(($_*2),2))})-replace ""

 

M a r k M i n a s i @ B i g D o g . c o m

 

 

[string](0..20|%{[char][int](46+("3151686131596451695918205957226557 0536563").substring(($_*2),2))})-replace ""

 

M a r k M i n a s i @ B i g D o g . c o m

 

 

 

An easier way that has worked with my email addresses is to simply subtract using a lower number –

 

 

Code:

([int[]][char[]]"MarkMinasi@BigDog.com" | %{ $_ -32 }) -join ""

 

456582754573786583733234737136797114677977

 

 

[string](0..20|%{[char][int](32+("456582754573786583733234737136797114677977").substring(($_*2),2))}) -replace ""

 

M a r k M i n a s i @ B i g D o g . c o m

 

 

 

Attempting to Automate somewhat I came up with this, however I cannot figure out how to get the Characters Length saved, currently  (0..20 |   so that I can pass it to $Value –

 

 

Code:

$Email = Read-Host 'Enter Email Address'

Write-Output $Email

$Int01 = ([int[]][char[]]$Email | %{ $_ -32 }) -join ""

Write-Output $Int01

$Value = [string](0..20|%{[char][int](32+($Int01).substring(($_*2),2))})-replace ""

Write-Output $Value

 

  

This should get you started.

 

I want to again thank Rob Campbell for providing me with further explanation and using it on his post, as well as Rakhesh Sasidharan via his website http://rakhesh.com/powershell/obfuscate-email-addresses-with-powershell/

 


__________________
Tim Bolton @jsclmedave
Email: [string](0..20|%{[char][int](32+('527377347976847978324785847679797514357977').substring(($_*2),2))}) -replace ' '  

New to the forum? Please Read this
0
Xenophane

Avatar / Picture

New Friend (or an Old Friend who Built a New Account)
Registered:
Posts: 18
Reply with quote  #2 
You could do
Code:

$Value = [string](0..$($Email.Length))|%{[char][int](32+($Int01).substring(($_*2),2))})-replace ""

__________________
Claus T Nielsen
Microsoft Cloud and Datacenter MVP 
Founder of the Danish PowerShell UserGroup http://psug.dk
 
<SIG> George Bernard Shaw : The power of accurate observation is commonly called cynicism by those who have not got it. </SIG>
0
jsclmedave

Administrator
Registered:
Posts: 418
Reply with quote  #3 
Thanks Claus!!


Rob shared this as well.  I had not tried wrapping $Int01 in single quotes... 

Thanks Rob!! ="[string](0..$($email.length -1)|%{[char][int](32+('$Int01').substring((`$_*2),2))}) -replace ' '"

__________________
Tim Bolton @jsclmedave
Email: [string](0..20|%{[char][int](32+('527377347976847978324785847679797514357977').substring(($_*2),2))}) -replace ' '  

New to the forum? Please Read this
0
jsclmedave

Administrator
Registered:
Posts: 418
Reply with quote  #4 
Quote:
Originally Posted by Xenophane
You could do
Code:
 $Value = [string](0..$($Email.Length))|%{[char][int](32+($Int01).substring(($_*2),2))})-replace "" 


Claus,   As Ron pointed out 

"0..$($Email.Length) is going to cause an "out of range" condition. Need -1 because of 0-based array indexing."

__________________
Tim Bolton @jsclmedave
Email: [string](0..20|%{[char][int](32+('527377347976847978324785847679797514357977').substring(($_*2),2))}) -replace ' '  

New to the forum? Please Read this
0
gyz

Still Checking the Forum Out
Registered:
Posts: 2
Reply with quote  #5 
Why not use base64, much simpler in my opinion,
Here is my fake mail address:
[Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('ZQBtAGEAaQBsAEAAZwBtAGEAaQBsAC4AYwBvAG0A'))
0
jsclmedave

Administrator
Registered:
Posts: 418
Reply with quote  #6 
Quote:
Originally Posted by gyz
Why not use base64, much simpler in my opinion,
Here is my fake mail address:
[Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('ZQBtAGEAaQBsAEAAZwBtAGEAaQBsAC4AYwBvAG0A'))


So for example..? -- 

Code:

PS F:\> $Email = ‘TimBolton@outlook.com’
PS F:\> $Bytes = [System.Text.Encoding]::Unicode.GetBytes($Email)
PS F:\> $EncodedText =[Convert]::ToBase64String($Bytes)
PS F:\> $EncodedText
VABpAG0AQgBvAGwAdABvAG4AQABvAHUAdABsAG8AbwBrAC4AYwBvAG0A
PS F:\> $DecodedText = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($EncodedText))
PS F:\> $DecodedText
TimBolton@outlook.com

__________________
Tim Bolton @jsclmedave
Email: [string](0..20|%{[char][int](32+('527377347976847978324785847679797514357977').substring(($_*2),2))}) -replace ' '  

New to the forum? Please Read this
0
gyz

Still Checking the Forum Out
Registered:
Posts: 2
Reply with quote  #7 
Yes completely right for creating it. But the whole point is that the person who needs your email address just runs 

[Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('VABpAG0AQgBvAGwAdABvAG4AQABvAHUAdABsAG8AbwBrAC4AYwBvAG0A'))
0
MickyBalladelli

Avatar / Picture

Still Checking the Forum Out
Registered:
Posts: 1
Reply with quote  #8 
((1..20)|%{[char][byte]$("0x"+(('6D69636B794062616C6C6164656C6C692E636F6DFF'-split"^((?:[\S\S]){2}){$_}([\S\S]+)")[1]))})-join''



[smile]
0
jsclmedave

Administrator
Registered:
Posts: 418
Reply with quote  #9 
More examples

Simple Obfuscation with PowerShell using Base64 Encoding



http://mikefrobbins.com/2017/06/15/simple-obfuscation-with-powershell-using-base64-encoding/



__________________
Tim Bolton @jsclmedave
Email: [string](0..20|%{[char][int](32+('527377347976847978324785847679797514357977').substring(($_*2),2))}) -replace ' '  

New to the forum? Please Read this
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation: