Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DTT1 - Test Module - Implement Windows tests #5230

Closed
3 tasks done
Tracked by #5218
fcaffieri opened this issue Apr 16, 2024 · 11 comments · Fixed by #5310
Closed
3 tasks done
Tracked by #5218

DTT1 - Test Module - Implement Windows tests #5230

fcaffieri opened this issue Apr 16, 2024 · 11 comments · Fixed by #5310
Assignees

Comments

@fcaffieri
Copy link
Member

fcaffieri commented Apr 16, 2024

Description

The objective of the issue is to make the necessary adaptations to perform agent tests on Windows systems.

Tasks

  • Adapt the tests for Windows
  • Implement winrm python library for the tests
  • Perform integration tests of Windows
@wazuhci wazuhci moved this to Backlog in Release 4.9.0 Apr 16, 2024
@fcaffieri fcaffieri self-assigned this Apr 16, 2024
@wazuhci wazuhci moved this from Backlog to In progress in Release 4.9.0 Apr 16, 2024
@fcaffieri
Copy link
Member Author

https://github.com/diyan/pywinrm

Connection to Windows

 telnet ec2-54-84-55-248.compute-1.amazonaws.com 3389
Trying 54.84.55.248...
Connected to ec2-54-84-55-248.compute-1.amazonaws.com.
Escape character is '^]'.
from winrm.protocol import Protocol

# Definir los detalles de conexión
host = '54.84.55.248'
port = 3389  # El puerto predeterminado para WinRM
username = 'Administrator'
password = 'vNP7gjyvMI8'

if port == 5986:
    protocol = 'https'
else:
    protocol = 'http'

endpoint_url = f'{protocol}://{host}:{port}'

# Crear la instancia del protocolo WinRM
p = Protocol(
    endpoint=endpoint_url,
    transport='ntlm',
    username=username,
    password=password, server_cert_validation='ignore'
)

shell_id = ""
try:
    # Conectar al servidor Windows
    shell_id = p.open_shell()
    command_id = p.run_command('ipconfig')

    # Leer la salida del comando
    stdout, stderr, status_code = p.get_command_output(command_id)

    if status_code == 0:
        print("Comando ejecutado exitosamente:")
        print(stdout.decode())
    else:
        print("Hubo un error al ejecutar el comando:")
        print(stderr.decode())
except Exception as e:
    print("Error al conectar o ejecutar el comando:", str(e))
finally:
    # Cerrar la conexión
    p.close_shell(shell_id)

Error:

    raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='ec2-54-84-55-248.compute-1.amazonaws.com', port=3389): Read timed out. (read timeout=30)

Implementation

from winrm.protocol import Protocol
import winrm

# Definir los detalles de conexión
host = '54.84.55.248'
port = 3389  # El puerto predeterminado para WinRM
username = 'Administrator'
password = 'vNP7gjyvMI8'



if port == 5986:
    protocol = 'https'
else:
    protocol = 'http'

endpoint_url = f'{protocol}://{host}:{port}'

try:
    session = winrm.Session(endpoint_url, auth=(username, password),transport='ntlm', server_cert_validation='ignore')
    cmd = session.run_cmd('ipconfig')
    if cmd.status_code == 0:
        print("WinRM connection successful.")
        stdout, stderr, status_code = winrm.get_command_output(cmd)
        print(stdout)
    else:
        print(f'WinRM connection failed. Check the credentials in the inventory file.')
except Exception as e:
    print(f'Error on attempt {e}')

Error:

$ python3 /home/fcaffieri/wazuh-env/wazuh-qa/deployability/modules/testing/tests/test_agent/test.py
Error on attempt HTTPConnectionPool(host='ec2-54-84-55-248.compute-1.amazonaws.com', port=3389): Read timed out. (read timeout=30)

@fcaffieri
Copy link
Member Author

fcaffieri commented Apr 17, 2024

Update

The connection via winrm to Windows has been resolved.
Implementation.

@staticmethod
     def execute_windows_command(inventory_path, command) -> str:

         with open(inventory_path, 'r') as yaml_file:
             inventory_data = yaml.safe_load(yaml_file)

         windows_host = inventory_data.get('ansible_host')
         windows_port = inventory_data.get('ansible_port')
         windows_password = inventory_data.get('ansible_password')
         windows_username = inventory_data.get('ansible_user')

         if windows_port == 5986:
             windows_protocol = 'https'
         else:
             windows_protocol = 'http'

         endpoint_url = f'{windows_protocol}://{windows_host}:{windows_port}'

         try:
             session = winrm.Session(endpoint_url, auth=(windows_username, windows_password),transport='ntlm', server_cert_validation='ignore')
             ret = session.run_cmd(command)
             if ret.status_code == 0:
                 return ret.std_out
             else:
                 return Exception(f'Error executing command: {command}')
         except Exception as e:
             raiseException(f'Error executing command: {command}')

Tasks:

  • Implement command execution in Windows.
  • Implement agent installation in Windows
  • Implement agent registration in Windows
  • Implement agent restart on Windows
  • Implement agent stop on Windows
  • Implement agent uninstall on Windows
  • Adapt the helpers used for agents:
    • Helper agent.py
    • Helper constants.py
    • Helper generic.py
    • Helper test.py
    • Helper utils.py
    • Helper executor.py

A bug was found in the installation of the agents in the tests when the repository was live:

image

This URL is made:

https://packages.wazuh.com/4.7/yum/wazuh-agent-4.7.1-1.x86_64.rpm

Should be:

https://packages.wazuh.com/4.x/yum/wazuh-agent-4.7.1-1.x86_64.rpm

@fcaffieri
Copy link
Member Author

fcaffieri commented Apr 20, 2024

Update

All tests, helpers and everything necessary to perform tests on Windows agents were added.
All that remains is to validate with @pro-akim a method of helpers/generic.py which I need to validate the implementation.
After that change, the tests begin.

Changes done in:

40df79b
6ac8f3e
0d37706

@fcaffieri
Copy link
Member Author

Update

The implementation was added to perform checkfile tests both in the installation and uninstall of the agent.
Performing comprehensive testing due to a large number of changes

@fcaffieri
Copy link
Member Author

fcaffieri commented Apr 25, 2024

Test Windows 🟢

Test Windows2022 🟢

  • Input file:

test-agent-windows-complete.yaml.txt

  • Logs:

windows2022.log.txt

Test Windows2019 🟢

  • Input file:

test-agent-windows-complete.yaml.txt

  • Logs:

windows2019.log.txt

Test Windows2016 🟢

  • Input file:

test-agent-windows-complete.yaml.txt

  • Logs:

windows2016.log.txt

Test Windows 10 🟢

  • Input file:

test-agent-windows-complete.yaml.txt

  • Logs:

windows10.log.txt

Test Windows2012 🟢

  • Input file:

test-agent-windows-complete.yaml.txt

  • Logs:

windows2012.log.txt

Test With linux and Windows agents 🟢

Test five Windows and five Linux:green_circle:

  • Input file:

test-agent-windows-complete.yaml.txt

  • Logs:

complete_test.log.txt

Test five Windows and five Linux with check-files 🟢

  • Input file:

test-agent-windows-complete.yaml.txt

  • Logs:

complete_test_checkfiles.log.txt

@fcaffieri fcaffieri linked a pull request Apr 25, 2024 that will close this issue
@wazuhci wazuhci moved this from In progress to Pending review in Release 4.9.0 Apr 25, 2024
@rauldpm
Copy link
Member

rauldpm commented Apr 25, 2024

Moved the ETA to 26/04/2024 as Fede is OOO and we need to finish other tasks before reviewing this

@wazuhci wazuhci moved this from Pending review to In review in Release 4.9.0 Apr 26, 2024
@pro-akim
Copy link
Member

Update

Moved to in progress

@wazuhci wazuhci moved this from In review to In progress in Release 4.9.0 Apr 26, 2024
@pro-akim pro-akim self-assigned this Apr 29, 2024
@pro-akim pro-akim removed a link to a pull request Apr 30, 2024
@pro-akim pro-akim linked a pull request Apr 30, 2024 that will close this issue
@pro-akim pro-akim removed a link to a pull request Apr 30, 2024
@pro-akim pro-akim linked a pull request Apr 30, 2024 that will close this issue
@pro-akim
Copy link
Member

Update

Integration macOs and Windows were integrated in #5310

@wazuhci wazuhci moved this from In progress to Pending review in Release 4.9.0 Apr 30, 2024
@wazuhci wazuhci moved this from Pending review to In review in Release 4.9.0 Apr 30, 2024
@wazuhci wazuhci moved this from In review to On hold in Release 4.9.0 Apr 30, 2024
@wazuhci wazuhci moved this from On hold to In progress in Release 4.9.0 May 2, 2024
@wazuhci wazuhci moved this from In progress to Pending review in Release 4.9.0 May 2, 2024
@pro-akim
Copy link
Member

pro-akim commented May 2, 2024

Update

ETA was updated to 03/05/2024 considering all the fixes to be done.

Requested changes done

@wazuhci wazuhci moved this from Pending review to On hold in Release 4.9.0 May 2, 2024
@pro-akim
Copy link
Member

pro-akim commented May 3, 2024

Update

Requested fixes done.

@wazuhci wazuhci moved this from On hold to Pending review in Release 4.9.0 May 3, 2024
@wazuhci wazuhci moved this from Pending review to Pending final review in Release 4.9.0 May 3, 2024
@wazuhci wazuhci moved this from Pending final review to In final review in Release 4.9.0 May 3, 2024
@rauldpm
Copy link
Member

rauldpm commented May 3, 2024

LGTM, good job team!

@rauldpm rauldpm closed this as completed May 3, 2024
@wazuhci wazuhci moved this from In final review to Done in Release 4.9.0 May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants