martes, 27 de septiembre de 2011

How to force WSUS updates to install on a computer

LA forma de fozar a un computer (workstation o server) a que se comunique con WSUS y descargue los paquetes que tiene pendientes de instalación es reiniciando los servicios que utiliza WSUS:

Desde un CMD ejcutar lo siguiente:

net stop "windows installer"
net start "windows installer"
net stop "
automatic updates"
net start "automatic updates"
net stop "background intelligent Transfer Service"
net start "background intelligent Transfer Service"



Si quieren hacer un vbscript puede hacerlo de la siguiente forma:

'Iniciar servicios de Windows Update
WSHShell.run "cmd.exe /K net stop ""windows installer"" & net start ""windows installer"" & exit", 1, true
WSHShell.run "cmd.exe /K net stop ""automatic updates"" & net start ""automatic updates"" & exit", 1, true
WSHShell.run "cmd.exe /K net stop ""background intelligent Transfer Service"" & net start ""background intelligent Transfer Service"" & exit", 1, true



Para ver el log de windows update y chequear los mensajes, desde Inicio > Ejecutar peguen esto:

notepad %WinDir%\WindowsUpdate.log

sábado, 10 de septiembre de 2011

Unix Hands-on: hardening sendmail

En este post algunas recomendaciones de como segurizar sendmail:

1. Primero que nada debemos verificar version actual y si requiere upgrade. Esto es lo primero a evaluar en cuanto a seguridad en cualquier producto.


2. Para todas  estas configuraciones vamos a necesitar trabajar como root.
/usr/local/bin/sudo su - root

3. Vamos a hacer las configuraciones de seguridad del servicio.
-Cambiar el banner que muestra el servicio para que no sea facil detectar que servicio y version estamos usando. Esto sirve para dificultar la detección de vulnerabilidades conocidas.
-Cambiar las privacy options.

#Muestra config actual
cat /etc/mail/sendmail.cf | grep PrivacyOptions

#Hago copia de seguridad
cp  /etc/mail/sendmail.cf  /etc/mail/sendmail.copy_old

#Reemplazo las PrivacyOptions
sed '
/O PrivacyOptions/ c\
O PrivacyOptions=authwarnings,needmailhelo,needexpnhelo,novrfy,noexpn,restrictqrun,restrictmailq' /etc/mail/sendmail.cf  > /etc/mail/sendmail.cf2
mv /etc/mail/sendmail.cf2  /etc/mail/sendmail.cf

#Reemplazo el banner
sed "s/O SmtpGreetingMessage=\$j Sendmail \$v\/\$Z; \$b/O SmtpGreetingMessage=\$j myOwnMailService/" /etc/mail/sendmail.cf > /etc/mail/sendmail.cf2
mv /etc/mail/sendmail.cf2  /etc/mail/sendmail.cf

#Restart service Solaris 9
/etc/init.d/sendmail restart

#Restart service Solaris 10
/usr/sbin/svcadm  restart /network/smtp:sendmail
svcs /network/smtp:sendmail


#Muestra la nueva config
uname -a

cat /etc/mail/sendmail.cf | grep PrivacyOptions


Unix Hands-on: ssh keys

Las ssh keys nos permiten loguearnos de forma "segura" (no siempre) a los equipos definidos sin tener que ingresar un password. Esto es sobre todo util para usuarios de servicio que deban loguearse a otros equipos a ejecutar comandos.
Decía que no siempre es seguro, ya que depende de como esté configurado el su o sudo. Si el su no pide el password para root o para otros usuarios, es muy sencillo que un usuario no autorizado pueda loguearse en otros equipos utilizando las ssh keys de otro usuario. Por esto es que hay que tener cuidado en como se utilizan las ssh keys; pero sobre todo en como se configura su y sudo.

#Crear las ssh keys en el equipo cliente
mkdir ~/.ssh chmod 700 ~/.ssh ssh-keygen -q -f ~/.ssh/id_rsa -t rsa

# upload public key from client to server (o directamente lo apendo a authorized keys como esta abajo)
scp ~/.ssh/id_rsa.pub user@10.195.8.190:.ssh/authorized_keys

# Setup the public key on server
bash
cd ~
mkdir .ssh
chmod 700 .ssh

#Inserto mi public key en authorized keys
echo "ssh-rsa AAAB3NzaC1yc2EAAAAOIwAAAIEApF+hzf1x366jjC+qt61R267dtDM36lxIqvw3ICUbNhTNB5wP/628rfWNIdi16MeCxJaufaf42tm2TYrsdGUAKfVCbssmCWJLoRwgeHUzOPIueAHwVkiuyFIG5/EJW7gvvF65pQzXoAXlktq1sWOh7kL8HLGDgUwJe4xlwvDP4Lk= user@client" >> .ssh/authorized_keys
chmod 600 .ssh/authorized_keys

 Nota: ssh keys = llaves ssh (que mal que suena en castellano...)

Unix Hands-on: Como habiltiar auth.log

En caso que tengamos problemas con un usuario que no puede acceder y no sabemos por que... o seamos conscientes de que el día de mañana podemos llegar a necesitar saber si alguien bloqueo un usuario o estuvo intentando adivinar un password, les paso el método para habilitar el auth.log. o lo que es lo mismo el how to enable auth.log

#edit syslog
vi /etc/syslog.conf

#add this line
auth.debug /var/tmp/auth.log rotate time 15d
touch /var/tmp/auth.log
chmod 640 /var/tmp/auth.log

#Finally refresh the syslog daemon
refresh -s syslogd

#View connections
tail -f /var/tmp/auth.log

Notar que la rotacion del archivo fue seteado en 15 días, lo que implica que los eventos anteriores a los 15 dias seran removidos en forma automática. Esto es bueno tenerlo en cuenta para no generar un archivo de log demasiado grande.

Unix Hands-on: AIX Security files

Los siguientes archivos contienen las principales informaciones necesarias para adminsitrar la seguridad de un equipo


/etc/passwd
Contains the basic attributes of users.
/etc/security/user
Contains the extended attributes of users.
/etc/security/user.roles
Contains the administrative role attributes of users.
/etc/security/limits
Defines resource quotas and limits for each user.
/etc/security/environ
Contains the environment attributes of users.
/etc/security/audit/config
Contains audit configuration information.
/etc/security/lastlog
Contains the last login attributes of users.
/etc/group
Contains the basic attributes of groups.
/etc/security/group
Contains the extended attributes of groups.
/etc/security/login.cfg
Contains login restrictions and messages.

jueves, 8 de septiembre de 2011

Como evaluar que bloquea un usuario


Este post puede servir para identificar quien o que bloquea un usuario de dominio o local.

1. Primero ejecutar el tool EventCombMT.exe



Nota: Los números de eventos de Seguridad de Windows a utilizar pueden consultarse desde esta URL: 
http://support.microsoft.com/kb/174074 (Aplica para Windows Server 2003)
http://support.microsoft.com/kb/947226 (Aplica para Windows Server 2008)
*Tener en cuenta que en Windows Vista / Server 2008 / Seven / Server 2012 tienen códigos de eventos de Seguridad diferentes a Windows 2003. Lo bueno es que no se solapan, arrancan de una nuemeración distinta a la que posee 2003.



Nota 3: Como utilizar el EventCombMT en esta URL : 
http://support.microsoft.com/kb/824209 

Una vez que la herramienta finaliza generará un txt en el directorio %temp%. Una linea de ejemplo es la siguiente:

644,AUDIT SUCCESS,Security,Sat Sep 03 07:07:48 2011,NT AUTHORITY\SYSTEM,User Account Locked Out:     Target Account Name: usuario1    Target Account ID: %{S-1-5-21-3880413253-2914564469-1958111818-20410}     Caller Machine Name: server1 Caller User Name: DCServer$     Caller Domain: contoso     Caller Logon ID: (0x0,0x3E7)    


Con esto vemos que usuario1 se esta bloqueando en el dominio contoso por una intento fallido de login desde el server1, a traves del Domain Controller DCServer$

2.Analizar en el servidor desde donde se realiza el login (en nuestro ejemplo server1)
Debemos analizar si:
  • El usuario tiene tareas en ejecución logeado (desde un cmd TASKLIST /FI "USERNAME ne usuario1")
  • Existen procesos que corren con este usuario (services.msc)
  • Existen tareas programadas (taskschd.msc)

3. Si con el paso anterior no encontramos que es lo que bloquea al usuario, analicemos el EventId: 529 para determinar que proceso bloquea el usuario.

En este caso vemos que el usuario se bloquea desde el Process ID 2592, que corresponde al servicio de Reporting Services


lunes, 5 de septiembre de 2011

Como delegar permisos de Active Directory

Para delegar permisos de Active Directory a un grupo de usuarios y no morir en el intento, recomiendo utilizar la herramienta de linea de comando dsacls.


Si utilizan el wizard que ofrece Windows 2003 server, van a encontrar que genera problemas con la herencia la mayoría de las veces.


A continuación un ejemplo del comando applicado en una delegación concreta de permisos sobre un atributo de un objeto user


dsacls "OU=Sites,OU=Argentina,DC=dominio,DC=ccf" /I:S /G domino\group:WP;personalTitle;user


Ejemplo para permitir a un grupo modificar la expiracion de los usuarios:


Para delegar el permiso de modificar el atributo accountExpires

dsacls "CN=Pepe,OU=Usuarios,OU=ARGENTINA,DC=dominio,DC=ccf" /I:S /G SA\HelpServicesGroup:RPWP;accountExpires;user >> out.log


Para delegar el permiso de modificar el atributo expirationTime:

dsacls "CN=Pepe,OU=Usuarios,OU=ARGENTINA,DC=dominio,DC=ccf" /I:S /G SA\HelpServicesGroup:RPWP;expirationTime;user >> out.log

Se puede poner RP (read) y WP (write) seguidos en una misma línea, como están arriba (RPWP;) y no tener que hacer 2 líneas por separado para cada Property.
El “>> out.log” se puede usar para tener registro de los resultados, si vamos a ejecutar muchos comandos juntos. Puede que fallen si el nombre (CN=) tiene caracteres no permitidos (Ñ,  comilla simple, etc.).




Mas info sobre el comando:


This article describes how to use the Dsacls.exe tool (Dsacls.exe) to manage access control lists (ACLs) for directory services in Microsoft Windows Server 2003 and Microsoft Windows 2000 Server. Dsacls.exe is a command-line tool that you can use to query the security attributes and to change permissions and security attributes of Active Directory objects. It is the command-line equivalent of the Security tab in the Windows Active Directory snap-in tools such as Active Directory Users and Computers and Active Directory Sites and Services.

Dsacls.exe is included with the Windows Support Tools. To install the Support Tools, run Setup.exe from the Support\Tools folder on the Windows Server 2003 or Windows 2000 Server CD-ROM. 

You can use Dsacls.exe and another Windows Support Tool, ACL Diagnostics (Acldiag.exe), to provide security configuration and diagnosis functionality on Active Directory objects from the command prompt.

Note You can use Dsacls.exe to display and change permissions (access control entries) in the access control list (ACL) of objects in Active Directory Application Mode (ADAM) in Windows Server 2003.

Important Do not use Dsacls.exe to modify permissions if you have implemented a Hosting solution such as Windows-based Hosting, High Volume Exchange (HVE), Hosted Messaging and Collaboration, or Hosted Exchange, or if the customer is using Microsoft Provisioning Service. The Hosting solutions depend on specific security model to isolate the ISP's customers from each other. 
DsAcls uses the following syntax:

dsacls object [/a] [/d {user | group}:permissions [...]] [/g {user | group}:permissions [...]] [/i:{p | s | t}] [/n] [/p:{y | n}] [/r {user | group} [...]] [/s [/t]]
You can use the following parameters with Dsacls.exe:
  • object: This is the path to the directory services object on which to display or change the ACLs. This path must be a distinguished name (also known as RFC 1779 or x.500 format). For example:
    CN=Someone,OU=Software,OU=Engineering,DC=Microsoft,DC=Com
    To specify a server, add \\Servername\ before the object. For example:
    \\MyServer\CN=Someone,OU=Software,OU=Engineering,DC=Microsoft,DC=Com
    When you run the dsacls command with only the object parameter (dsacls object), the security information about the object is displayed.
  • /a : Use this parameter to display the ownership and auditing information with the permissions.
  • /d {user | group}:permissions: Use this parameter to deny specified permissions to a user or group.User must use either user@domain or domain\user format, and group must use either group@domain ordomain\group format. You can specify more than one user or group in a command. For more information about the correct syntax to use for permissions, see the <Permissions> Syntax section later in this article.
  • /g {user | group}:permissions: Use this parameter to grant specified permissions to a user or group.User must use either user@domain or domain\user format, and group must use either group@domain ordomain\group format. You can specify more than one user or group in a command. For more information about the correct syntax to use for permissions, see the <Permissions> Syntax section later in this article.
  • /i:{p | t} : Use this parameter to specify one of the following inheritance flags:
    • p: Use this option to propagate inheritable permissions one level only.
    • s: Use this option to propagate inheritable permissions to subobjects only.
    • t: Use this option to propagate inheritable permissions to this object and subobjects.
  • /n : Use this parameter to replace the current access on the object, instead of editing it.
  • /p:{n}: This parameter determines whether the object can inherit permissions from its parent objects. If you omit this parameter, the inheritance properties of the object are not changed. Use this parameter to mark the object as protected (y = yes) or not protected (n = no).

    Note This parameter changes a property of the object, not of an Access Control Entry (ACE). To determine whether an ACE is inheritable, use the /I parameter.
  • /r {user | group}: Use this parameter to remove all permissions for the specified user or group. You can specify more than one user or group in a command. User must use either user@domain or domain\userformat, and group must use either group@domain or domain\group format.
  • /s: Use this parameter to restore the security on the object to the default security for that object class, as defined in the Active Directory schema.
  • /t : Use this parameter to restore the security on the tree of objects to the default for each object class. This switch is valid only when you also use the /s parameter.

Permissions Syntax

You must use the following syntax for permissions when you use the /d {user | group}:permissions or /g {user |group}:permissions parameter :
[PermissionBits];[{Object|Property}];[InheritedObjectType]
  • PermissionBits can use any of the following values, which can be concatenated together without spaces:

    Generic Permissions
    GRGeneric Read
    GEGeneric Execute
    GWGeneric Write
    GAGeneric All

    Specific Permissions
    SDDelete
    DTDelete an object and all its child objects.
    RCRead security information
    WDChange security information
    WOChange owner information
    LCList the child objects of an object
    CCCreate child object. If {Object|Property} is not specified to define a specific property, this applies to all properties of an object. Otherwise, it applies to the specified property of the object.
    DCDelete child object. If {Object|Property} is not specified to define a specific property, this applies to all properties of an object. Otherwise, it applies to the specified property of the object.
    WSWrite to self object. If {Object|Property} is not specified to define a specific property, this applies to all properties of an object. Otherwise, it applies to the specified property of the object.
    RPRead property. If {Object|Property} is not specified to define a specific property, this applies to all properties of an object. Otherwise, it applies to the specified property of the object.
    WPWrite property. If {Object|Property} is not specified to define a specific property, this applies to all properties of an object. Otherwise, it applies to the specified property of the object.
    CAControl access right. If {Object|Property} is not specified to define a specific property, this applies to all properties of an object. Otherwise, it applies to the specified property of the object.
    LOList the object access. Can be used to grant list access to a specific object if List Children (LC) is not also granted to the parent. Can also be denied on specific objects to hide those objects if the user or group has LC on the parent. By default, Active Directory does not enforce this permission.
  • {Object|Property}: This represents the display name of the object type or property. For example, "user" (without the quotation marks) is the display name for user objects, and "telephone number" (without the quotation marks) is the display name for the telephone number property.

    For example, the following command permits the user to create all types of child objects:
    /G Domain\User:CC

    However, the following command permits the user to create only child computer objects:
    /G Domain\User:CC;computer
  • InheritedObjectType: This represents the display name of the object type by which the permissions are expected to be inherited.

    If an object type is not specified, the permission can be inherited by all object types. This parameter is used only when permissions are inheritable.

    For example, the following command permits all types of objects to inherit the permission:
    /G Domain\User:CC
    However, the following command permits only user objects to inherit the permission:
    /G Domain\User:CC;;user
IMPORTANT: Use permissions only when you define object-specific permissions that override the default permissions defined in the Active Directory schema for that object type. Use with caution and only if you have a full understanding of object-specific permissions. 






Examples of Permissions
  • SDRCWDWO;;user

    This notation represents Delete, Read security information, Change security information, and Change ownership permissions on objects of type "user".
  • CCDC;group;

    This notation represents Create child and Delete child permissions to create or delete objects of type "group".
  • RPWP;telephonenumber;

    This notation represents Read property and Write property permissions on the telephone number property.