1

I am working on a project where we need to search a set of our network drives to examine each file and look for credit card numbers and social security numbers. I have been trying to use the Cornell Spider program without success since it seems to crash every time I use it.

I would like to know if there is a way to use Powershell, or a scripting language available on Windows, to perform an analysis (I am assuming a strings match) that would match the patterns for credit card numbers and social security numbers (probably a regex). If there is a way, and since I am not a programmer, I was curious if there was some code that I could use to do this with. Also, the ability to save/dump the results of what is found out to a file (text or CSV) would be very helpful as well.

Any ideas or help that you can provide would be greatly appreciated.

=======================================================

Okay, I have been working on a test script and have come up with the following:

$spath = "C:\Users\name\Desktop\"
$opath = "C:\Users\name\Desktop\Results.txt"

$Old_SSN_Regex = "[0-9]{3}[-| ][0-9]{2}[-| ][0-9]{4}"
$SSN_Regex = "^(?!000)([0-6]\d{2}|7([0-6]\d|7[012]))([ -]?)(?!00)\d\d\3(?!0000)\d{4}$"
$CC_Regex = "^((?:4\d{3})|(?:5[1-5]\d{2})|(?:6011)|(?:3[68]\d{2})|(?:30[012345]\d))[ -]?(\d{4})[ -]?(\d{4})[ -]?(\d{4}|3[4,7]\d{13})$"
$CC_2_Regex = "^(\d{4}-){3}\d{4}$|^(\d{4} ){3}\d{4}$|^\d{16}$"

Get-ChildItem $spath -Include *.txt -Recurse | Select-String -Pattern $SSN_Regex | Select-Object Path,Filename,Matches | Out-File $opath
Get-ChildItem $spath -Include *.txt -Recurse | Select-String -Pattern $CC_Regex | Select-Object Path,Filename,Matches | Out-File $opath -Append
Get-ChildItem $spath -Include *.txt -Recurse | Select-String -Pattern $CC_2_Regex | Select-Object Path,Filename,Matches | Out-File $opath -Append

This seems to be working well, the problem is that if there is a space before or after the item to be matched, the regexs listed do not catch it. Is there something that I can do differently so that it will catch the item if it has a space before or after the pattern to be matched within a file?

John
  • 24,083
  • 5
  • 24
  • 25
  • This question has been reformulated and answered [here](http://stackoverflow.com/questions/5782920/regex-and-ignore-whitespace). – Emiliano Poggi Apr 26 '11 at 05:42

1 Answers1

1

See this PowerGUI.org thread for the solution: PowerShell Script to locate Social Security Numbers (SSN) and Credit Card numbers in files across the network.

DSotnikov
  • 634
  • 3
  • 10
  • The mentioned link does not appear to work anymore. Can you post the content as an edit to your answer? – John Nov 05 '19 at 18:59
  • Indeed. :( These were community forums owned by Quest Software and looks like they have shut them down. Unfortunately, this was 8+ years ago now and I no longer have these scripts locally anywhere. – DSotnikov Nov 06 '19 at 19:08