It’s rare during a penetration test that I actually exploit a vulnerability to gain more information. Newcomers to my filed will often use the term “network security”. I don’t care about the network, have the network for all I care. What I’m more concerned about is the information inside the network. The better way to describe it is “information security”. Performing penetration tests one has to keep that in mind, yea it’s fun to exploit some user that’s running an old version of war-ftp but if that user doesn’t yield sensitive information then who cares to some extent.
I often see that professional penetration testers will highlight an open windows share that can be read or written to by everyone. They will often highlight other shares that are accessible by a large group such as Authenticated users. I don’t want to scoff at these types of open shares as they should be investigated by the business owner that created the open shares. The main thing to consider is what information lies within those open shares. Open shares are usually created for a reason, so that users easily share information. This is not bad unless the information in those shares is secret / classified material. To check for this possible sensitive information one would have to search all the files and folders in that share. Now you can use the cute little dog search feature inside of windows explorer to look for this information but using that your hands are somewhat tied. The search feature inside windows explorer actually does a nice job but if you wanted to automate the process to look at multiple shares and search for multiple terms then you’re out of luck. Because of this I wanted to script something that would automate the process. Powershell could have been an option but because I’m already familiar with python I stuck to what I know. This means that in order to run the script you’ll have to have python installed on windows. I could have written the script to work in Linux but that would have meant using cifs to map drives which seemed like more of a headache then just using python on windows.
You’ll need to open up a windows command prompt to run the script and it’s a good idead to add Python to the windows path. So the script takes two arguments. The first argument is the file containing all the shares that you want to search. The second argument is the file that contains all the terms you want to search for. So to run the script you would issue a command similar to below, where searchShares.py is the name of the python script.
python.exe searchShares.py shares.txt searchTerms.txt
\\one\two
\\three\four\five
\\six\seven\eight\nine
\\three\four\five
\\six\seven\eight\nine
secret
password
username
password
username
Once you run the script you will see output similar to below.
C:\temp>python searchShares.py shares.txt searchTerms.txt
Walking directory \\192.168.99.184\test
Found \\192.168.99.184\testtest.txt
Found \\192.168.99.184\testTravisAltmanResume.doc
Found \\192.168.99.184\test\onewordDoc1.docx
Found \\192.168.99.184\test\one\twopasswords.txt
Found \\192.168.99.184\test\one\two\threewordDoc2.docx
Searching file \\192.168.99.184\test\test.txt for term secret
Searching file \\192.168.99.184\test\TravisAltmanResume.doc for term secret
Searching file \\192.168.99.184\test\one\wordDoc1.docx for term secret
Searching file \\192.168.99.184\test\one\two\passwords.txt for term secret
Searching file \\192.168.99.184\test\one\two\three\wordDoc2.docx for term secret
Searching file \\192.168.99.184\test\test.txt for term password
Searching file \\192.168.99.184\test\TravisAltmanResume.doc for term password
Searching file \\192.168.99.184\test\one\wordDoc1.docx for term password
Searching file \\192.168.99.184\test\one\two\passwords.txt for term password
Searching file \\192.168.99.184\test\one\two\three\wordDoc2.docx for term password
Searching file \\192.168.99.184\test\test.txt for term username
Searching file \\192.168.99.184\test\TravisAltmanResume.doc for term username
Searching file \\192.168.99.184\test\one\wordDoc1.docx for term username
Searching file \\192.168.99.184\test\one\two\passwords.txt for term username
Searching file \\192.168.99.184\test\one\two\three\wordDoc2.docx for term username
Walking directory \\192.168.99.184\test
Found \\192.168.99.184\testtest.txt
Found \\192.168.99.184\testTravisAltmanResume.doc
Found \\192.168.99.184\test\onewordDoc1.docx
Found \\192.168.99.184\test\one\twopasswords.txt
Found \\192.168.99.184\test\one\two\threewordDoc2.docx
Searching file \\192.168.99.184\test\test.txt for term secret
Searching file \\192.168.99.184\test\TravisAltmanResume.doc for term secret
Searching file \\192.168.99.184\test\one\wordDoc1.docx for term secret
Searching file \\192.168.99.184\test\one\two\passwords.txt for term secret
Searching file \\192.168.99.184\test\one\two\three\wordDoc2.docx for term secret
Searching file \\192.168.99.184\test\test.txt for term password
Searching file \\192.168.99.184\test\TravisAltmanResume.doc for term password
Searching file \\192.168.99.184\test\one\wordDoc1.docx for term password
Searching file \\192.168.99.184\test\one\two\passwords.txt for term password
Searching file \\192.168.99.184\test\one\two\three\wordDoc2.docx for term password
Searching file \\192.168.99.184\test\test.txt for term username
Searching file \\192.168.99.184\test\TravisAltmanResume.doc for term username
Searching file \\192.168.99.184\test\one\wordDoc1.docx for term username
Searching file \\192.168.99.184\test\one\two\passwords.txt for term username
Searching file \\192.168.99.184\test\one\two\three\wordDoc2.docx for term username
=== Directories or file names matching search criteria ===
\\192.168.99.184\test\one\two\passwords.txt
=== Files matching search criteria ===
found secret in file \\192.168.99.184\test\one\two\passwords.txt
found password in file \\192.168.99.184\test\one\two\passwords.txt
\\192.168.99.184\test\one\two\passwords.txt
=== Files matching search criteria ===
found secret in file \\192.168.99.184\test\one\two\passwords.txt
found password in file \\192.168.99.184\test\one\two\passwords.txt
Let me know if this works / doesn’t work and also let me know if you have any suggestions on how to make it better. One thing I might do in the future is to limit the types of files it searches to say only .txt, .doc, .xls, etc. Happy hunting for information on shares.import osimport sys import re output = open('output.txt', 'a') output.write('\n') fileList = [] shareList = open(sys.argv[1]) eachShare = shareList.readlines(); for shares in eachShare: path = shares.rstrip('\r\n') print '\nWalking directory ' + path + '\n' for root, subFolders, files in os.walk(path): #print 'Indexing ' + root + '\n' for file in files: fileList.append(os.path.join(root,file)) print 'Found ' + root + file keywords = open(sys.argv[2]) searchTerm = keywords.readlines(); output.write('=== Directories or file names matching search criteria ===\n') for term in searchTerm: strip = term.rstrip('\r\n') if any(strip in s for s in fileList): matching = [s for s in fileList if strip in s] for item in matching: output.write('\n' + item) output.write('\n\n=== Files matching search criteria ===\n\n') for term in searchTerm: strip = term.strip('\r\n') for item in fileList: print 'Searching file ' + item + ' for term ' + term searchFile = open(item, 'rb') for line in searchFile: if re.search(strip, line, re.IGNORECASE): output.write('found ' + strip + ' in file ' + item + '\n') break searchFile.close()output.close()
No comments:
Post a Comment