The SANS Top 20 Controls has a control named Account Monitoring and Control. Within that control is a Quick Win: Ensure that systems automatically create a report on a daily basis that includes a list of locked-out accounts, disabled accounts, accounts with passwords that exceed the maximum password age, and accounts with passwords that never expire. This list should be sent to the associated system administrator in a secure fashion.
We don't have an automated report of those types of accounts, and quite frankly, we have very poor visibility into account control. Coming from a DoD environment, I'm not used to having such lax controls. Slowly, I'm starting to push the company forward, but it is taking time.
My first thought was to look at the inactive accounts. I figured that these accounts would be low enough of the low-hanging fruit to start with, and here's how I have gone about finding them.
(Note: that I have created a master script that will do more than what this post details...I'm only describing inactive accounts at this time.)
1. This command is in a batch file: dsquery user -inactive 4 -limit 3000 > accountout.txt
Call the output file what you like. The -inactive 4 parameter tells dsquery to look for accounts that have been inactive for at least four weeks. I picked four to start with, as I realize that we have users that travel extensively. My hope is that once we manage the output, I'll be able to lower that number.
2. I took the output of the file, and copied it to Excel. From there, I went to Data>Text-to-Columns in order to break up the data nicely.
3. Column 2 seemed to be where I could differentiate between user and non-user accounts. I filtered on just user accounts and copied that to a new sheet.
My results were staggering. There are way too many accounts. My next step is to find or create a process to validate that these accounts are a) legitimate, and b) truly inactive. Spot checking a bunch of these users revealed users that are contractors. And, if I have to guess, they are no longer with the company. Prime targets to attack - which is why they should be disabled or deleted.
Once that's done, I'll need to automate the process and schedule it to run weekly or so. As for locked-out, disabled, and password length checking...those will be added in time.
Showing posts with label Scripts. Show all posts
Showing posts with label Scripts. Show all posts
Friday, May 9, 2014
Wednesday, March 12, 2014
Finding hostnames on a Subnet
We have offices all over the world. What I came to learn today is that there are two countries where we have very poor visibility into our own corporate networks. To the point that I suspect that they are not managed very well, if at all. I know I chase down malware in a couple of the networks on a daily basis.
One of our admins asked me if there is a way that we can get all of the hostnames on one of those subnets that we don't have much visibility to. NMAP would have worked well, but I wanted to come up with a command that I could have had a non-technical person run and send me the output. So, using a little Command Line Kung-Fu, I came up with:
It worked like a champ. I suspect that there is an easier way to do this, but this worked easy enough.
One of our admins asked me if there is a way that we can get all of the hostnames on one of those subnets that we don't have much visibility to. NMAP would have worked well, but I wanted to come up with a command that I could have had a non-technical person run and send me the output. So, using a little Command Line Kung-Fu, I came up with:
for /L %A in (0 1 255) do nbtstat -A "XXX.XX.XXX.%A">>hosts.txtSubstitute your subnet for the Xs in that command.
It worked like a champ. I suspect that there is an easier way to do this, but this worked easy enough.
Friday, April 15, 2011
Scripting the retrieval of the warning banner (legal notice) when pushed by Group Policy
As an auditor, one of the controls I constantly come up against is ECWM-1, which states:
So, there is the question of how to look at all of those warning banners. Or, at least, how to look at a representational sample. There are many references on how to set a warning banner on a local host. The text you want to display as a banner gets added to the following key:
hklm\software\microsoft\windows nt\current version\winlogon and the key is LegalNoticeText
However, in these enterprise systems and enclaves, the warning banner is almost always pushed down to the workstation by Group Policy. That key is: hklm\software\microsoft\Windows\CurrentVersion\Policies\system and the key is LegalNoticeText.
To script this out, I do:
objShell.Run "cmd /c reg query ""hklm\software\microsoft\Windows\CurrentVersion\Policies\system"" /v LegalNoticeText >" legalnotice.txt
Now, I have a copy of the warning banner which I can inspect for compliance later on.
All users are warned that they are entering a Government information system, and areAll workstations, servers, applications, networking gear, and other hosts must have a specific banner. (I'm aware of exceptions, but I'm discussing that first-line of defense to an asset, the warning banner.) Gold Disk, in its latest incarnation does not appear to actively check for the banner; in the tests that I have run, it marks the check as NR and must be manually reviewed. Doing this for a machine or two is not bad. However, many times I am working an enterprise system where there man be many servers and hundreds of workstations. To solve that issue I wrap up many tools (including Gold Disk and Oval) in a a script in order to deploy the script and collect the results automagically. Usually, I'll set up a share on a server where all servers and workstations can automatically dump their results.
provided with appropriate privacy and security notices to include statements informing
them that they are subject to monitoring, recording and auditing.
So, there is the question of how to look at all of those warning banners. Or, at least, how to look at a representational sample. There are many references on how to set a warning banner on a local host. The text you want to display as a banner gets added to the following key:
hklm\software\microsoft\windows nt\current version\winlogon and the key is LegalNoticeText
However, in these enterprise systems and enclaves, the warning banner is almost always pushed down to the workstation by Group Policy. That key is: hklm\software\microsoft\Windows\CurrentVersion\Policies\system and the key is LegalNoticeText.
To script this out, I do:
objShell.Run "cmd /c reg query ""hklm\software\microsoft\Windows\CurrentVersion\Policies\system"" /v LegalNoticeText >" legalnotice.txt
Now, I have a copy of the warning banner which I can inspect for compliance later on.
Monday, March 15, 2010
Script to help find unknown or rogue sql servers
When I'm auditing a lan/enclave/data center, one of my test script producesa "netstat -naob" of the machine. (I do this by running "netstat -naob > [machinename]_netstat.txt. machinename gets populated from an environment variable.) Sure, I understand it is a point in time snapshot of the machine, but it gives me a good idea of what is running. And it's nice to have the output in a file in order to review later.
I like to check for sql servers because they traditionally get installed by a user as part of an application. Sure, many times it is the "lite" version of sql server. But that is not always the case. And, we all know how vulnerable a sql server could be; and their need for extra care and feeding.
Typically, I'll collect all of my netstat files in one directory. Then, I run following script:
for /R "c:\documents and settings\me\desktop\NetstatFiles" %f in (*_netstat.txt) do findstr /M "sqlservr.exe" "%f" >> sqlseeker.txt
Each of my netstat files is prefaced by the machine name of the machine being tested. sqlseeker.txt is a file that contains a list of all netstat files that contained a netstat line where a SQL server was found to be listening.
I'm sure there could be a false positive or two, but it gives me someplace else to look for rouge or unknown sql servers.
I like to check for sql servers because they traditionally get installed by a user as part of an application. Sure, many times it is the "lite" version of sql server. But that is not always the case. And, we all know how vulnerable a sql server could be; and their need for extra care and feeding.
Typically, I'll collect all of my netstat files in one directory. Then, I run following script:
for /R "c:\documents and settings\me\desktop\NetstatFiles" %f in (*_netstat.txt) do findstr /M "sqlservr.exe" "%f" >> sqlseeker.txt
Each of my netstat files is prefaced by the machine name of the machine being tested. sqlseeker.txt is a file that contains a list of all netstat files that contained a netstat line where a SQL server was found to be listening.
I'm sure there could be a false positive or two, but it gives me someplace else to look for rouge or unknown sql servers.
Tuesday, June 23, 2009
Closing a port / killing a process using WMIC
This is really just for my memory's sake. I'm writing this up as I've just recently had to perform these steps a couple of times. For 99% of the readers, this is old hat. Here's the situation:
You have a port that's open and you want it closed, or, you have a process running that you can not kill. Here are the steps I've followed:
netstat -naob (use on XP Pro or newer...I don't think the 'b' switch is available in the home edition.)
Find the port that's open or the offending process.
wmic process list brief
This will list the process and their processid.
wmid process [processid] delete.
Poof....it's gone.
WMIC...hugely powerful. I've mentioned it in posts here and here.
You have a port that's open and you want it closed, or, you have a process running that you can not kill. Here are the steps I've followed:
netstat -naob (use on XP Pro or newer...I don't think the 'b' switch is available in the home edition.)
Find the port that's open or the offending process.
wmic process list brief
This will list the process and their processid.
wmid process [processid] delete.
Poof....it's gone.
WMIC...hugely powerful. I've mentioned it in posts here and here.
Gold Disk and password policies
The other day, a bunch of us were talking about the Gold Disk and how we mitigate for any false positives that are returned. One area that produced some discussion were password policies. Currently, I believe that the Gold Disk looks for 10-character passwords, as per policy. Army policy enforces 14 characters, at a minimum. So, while testing an Army system, Gold Disk could find a 12-character password, and pass the control. Without further review, the auditor would never know that the finding is actually a failure (with regards to the Army.)
That said, I created a little script that I'll try on my next engagement. The script idea came from a posting on the phenomenal Command Line Kung Fu blog. At a prompt:
net accounts > %computername%-AcctSecPolicy.txt
Or, if you want domain-level policy:
net accounts /domain > %computername%-DomAcctSecPolicy.txt
A quick breakdown: net accounts returns the overall general security settings for all accounts. the /domain switch will grab the same information on the domain level. Then, I shoot the output to a file that starts with the name of the computer (that's the %computername% environment variable.) This way, I can grab the results from the computer, along with the Gold Disk data. Later, I'll have the data to analyze along with the Gold Disk data, and I'll know which system it came from.
That said, I created a little script that I'll try on my next engagement. The script idea came from a posting on the phenomenal Command Line Kung Fu blog. At a prompt:
net accounts > %computername%-AcctSecPolicy.txt
Or, if you want domain-level policy:
net accounts /domain > %computername%-DomAcctSecPolicy.txt
A quick breakdown: net accounts returns the overall general security settings for all accounts. the /domain switch will grab the same information on the domain level. Then, I shoot the output to a file that starts with the name of the computer (that's the %computername% environment variable.) This way, I can grab the results from the computer, along with the Gold Disk data. Later, I'll have the data to analyze along with the Gold Disk data, and I'll know which system it came from.
Subscribe to:
Posts (Atom)