Extremely Serious

Category: Windows (Page 1 of 4)

Using the Windows Runas Command: Run Programs with Different User Credentials and Domains

The runas command in Windows is a versatile tool that allows you to run programs with different user credentials, making it valuable for administrative tasks and situations requiring elevated privileges. Additionally, the command can be used to run programs with credentials from different domains, and the /netonly parameter provides a focused approach for accessing remote resources with distinct credentials.

Running Programs with Different User Credentials

To run a program with different user credentials, follow these steps:

  1. Open Command Prompt: Press Win + R, type "cmd," and press Enter to open the Command Prompt.

  2. Use runas: Enter the following command, replacing <username> with the desired username and "<program_path>" with the program's path:

    runas /user:<username> "<program_path>"
  3. Password Prompt: After entering the command, you will be prompted to enter the password for the specified user.

  4. Run Program: Once you enter the correct password, the program will run with the credentials of the specified user.

For example:

runas /user:Administrator "C:\Windows\System32\cmd.exe"

This command runs the Command Prompt as the Administrator user.

Running Programs with Different User Credentials from a Different Domain

To run a program with different user credentials from a different domain, use the following syntax:

runas /user:<domain>\<username> "<program_path>"
  • <domain>: Replace this with the domain name where the user account is located.
  • <username>: Replace this with the username of the account you want to use.
  • "<program_path>": Replace this with the full path to the program you want to run.

For example:

runas /user:ExampleDomain\User1 "C:\Path\To\Program.exe"

This command prompts for the password of the specified domain user and runs the program with those credentials.

Ensure you have the necessary permissions, network connectivity, and correct domain and username format for running programs across different domains.

Running Programs with Different User Credentials Using /netonly

The /netonly parameter allows you to run a program with different user credentials specifically for accessing remote resources. Use the following syntax:

runas /netonly /user:<domain>\<username> "<program_path>"
  • <domain>: Replace this with the domain name where the user account is located.
  • <username>: Replace this with the username of the account you want to use.
  • "<program_path>": Replace this with the full path to the program you want to run.

For example:

runas /netonly /user:ExampleDomain\User1 "C:\Path\To\Program.exe"

When using /netonly, the specified program runs with the specified user credentials only for network connections. Local resources and interactions continue to use the credentials of the currently logged-in user.

This feature is beneficial when accessing resources on a different domain or using different credentials for a specific task without affecting the local user session.

Remember to provide the correct domain, username, and program path for your specific scenario. The /netonly parameter enhances the flexibility of the runas command, making it a valuable tool for managing credentials in diverse network environments.

Windows Shutdown and Restart Event IDs

The event IDs that can be searched in windows event viewer (i.e. Windows Logs -> System) for the confirmation of shutdown or restart.

Event ID Name Description
14 The system has rebooted without cleanly shutting down first This event indicates that some unexpected activity prevented Windows from shutting down correctly. Such a shutdown might be caused by an interruption in the power supply or by a Stop error. If feasible, Windows records any error codes as it shuts down.
1074 System has been shutdown by a process/user. This event is written when an application causes the system to restart, or when the user initiates a restart or shutdown by clicking Start or pressing CTRL+ALT+DELETE, and then clicking Shut Down.
6006 The event log service was stopped. The event is logged at boot time noting that the Event Log service was stopped.
6008 Unexpected system shutdown The previous system shutdown at Time on
Date was unexpected.

Java as a Windows service with NSSM

Pre-requisite

Installing a Java Service

  1. Register a java application as a windows service using the following syntax:

    nssm install <SERVICE_NAME> <JAVA_EXECUTABLE> <JAVA_ARGUMENTS>

    Example

    nssm install "JavaService" "${JAVA_HOME}\bin\java.exe" "-jar java-service.jar --spring.profiles.active=dev"
  2. Update the service with application directory using the following syntax:

    nssm set <SERVICE_NAME> AppDirectory <JAR_FILE_DIRECTORY>

    Example

    nssm set "JavaService" AppDirectory "C:\apps"
  3. Update the service with description using the following syntax:

    nssm set <SERVICE_NAME> Description <APP_DESCRIPTION>

    Example

    nssm set "JavaService" Description "A custom java service."

Displaying the NSSM details of the Java Service

Use the following syntax to display the details of the services:

nssm dump <SERVICE_NAME>

Example

nssm dump "JavaService"

Uninstalling a Java Service

Use the following syntax to remove a java service using nssm:

nssm remove <SERVICE_NAME> confirm

confirm parameter here specifies that we don't want to see the gui confirmation.

Example

nssm remove "JavaService" confirm

Tomcat 8.5 Service Basic Management

Service Creation

  1. Open a cmd terminal and change the current directory to the following:

    %CATALINA_HOME%\bin

    In this directory you will find the following files:

    • tomcat8.exe
    • tomcat8w.exe
  2. Copy the file tomcat8w.exe to CustomTomcat8w.exe.

    tomcat8w.exe is in the following pattern:

    <SERVICE_NAME>w.exe

    This makes the default service name set to tomcat8. Copying it to CustomTomcat8w.exe makes a service name of CustomTomcat8.

  3. Set the basic properties of the CustomTomcat8 service using the following command:

    tomcat8.exe //IS//CustomTomcat8 --DisplayName="Apache Custom Tomcat 8" --Install="%CATALINA_HOME%\bin\tomcat8.exe" --StartMode=jvm --StopMode=jvm --StartClass=org.apache.catalina.startup.Bootstrap --StartParams=start --StopClass=org.apache.catalina.startup.Bootstrap --StopParams=stop --Description="Apache Custom Tomcat 8 by Ron"
  4. Set the classpath using the following command:

    tomcat8.exe //US//CustomTomcat8 --Classpath="%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_HOME%\bin\tomcat-juli.jar"
  5. Set the JVM to use using the following command:

    tomcat8.exe //US//CustomTomcat8 --Jvm="%JAVA_HOME%\jre\bin\server\jvm.dll"
  6. Set some JVM options using the following command:

    tomcat8.exe //US//CustomTomcat8 --JvmOptions="-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_HOME%"
  7. Set logging using the following command:

    tomcat8.exe //US//CustomTomcat8 --LogLevel="Info" --LogPrefix="custom_tomcat8_service-" --LogPath="%CATALINA_HOME%\logs" --StdOutput="auto" --StdError="auto" --PidFile="tomcat8.pid"
  8. Set JVM memory using the following command:

    tomcat8.exe //US//CustomTomcat8 --JvmMs=512 --JvmMx=1024

Service Post Creation

  1. Using the file explorer, find the directory specified by your CATALINA_HOME environment variable and add the LOCAL SERVICE group on the security. Also add the permissions Full Control and Modify to it.

    For example if your CATALINA_HOME is pointing to C:\dev\tools\apache-tomcat-8.5.64 directory, expect something like the following as an output:

  2. Using the file explorer, navigate to %CATALINA_HOME%\bin directory and double click the CustomTomcat8w.exe file. Click the Java tab and ensure that the Java Virtual Machine field was correctly set. If not, update it accordingly.

    For example if your JAVA_HOME is pointing to C:\Program Files\Java\jdk1.8.0_271 directory, ensure that the Java Virtual Machine field is pointing to the correct location of the jvm.dll.

Service Execution

  1. Open a cmd terminal and change the current directory to the following:

    %CATALINA_HOME%\bin
  2. Run the CustomTomcat8 service using the following command:

    tomcat8.exe //RS//CustomTomcat8

Service Termination

  1. Open a cmd terminal and change the current directory to the following:

    %CATALINA_HOME%\bin
  2. Stop the CustomTomcat8 service using the following command:

    tomcat8.exe //SS//CustomTomcat8

Service Removal

  1. Open a cmd terminal and change the current directory to the following:

    %CATALINA_HOME%\bin
  2. Remove the CustomTomcat8 service using the following command:

    tomcat8.exe //DS//CustomTomcat8

Windows Services App

After the service creation was completed and without any error, we can also manage the service using the windows services app. Just look for the value of the --DisplayName parameter (i.e. Apache Custom Tomcat 8) when setting the basic properties of the service. This is depicted as follows by the following snapshot:

Reference

Assigning an IP to an Interface of a Cisco Router

Pre-requisite

  • Putty application

Displaying the Interfaces

Use the following command to display the available interfaces and their states:

show ip interface brief

Assigning an IP

  1. Connect to cisco console using putty.

  2. Press the enter key to enter into user mode.

  3. Execute the following command to enter into privilege mode:

    enable
  4. Load the startup-config into the running-config using the following command:

    copy startup-config running-config
  5. Execute the following command to enter into the configuration mode:

    config terminal
  6. Configure an interface using the following syntax:

    interface <INTERFACE_NAME> 

    Example

    interface GigabitEthernet0/0
  7. Assign an IP address using the following syntax:

    ip address <IP_ADDRESS> <SUBNET_MASK>

    Example

    ip address 10.0.0.210 255.255.255.0
  8. Turn on the interface using the following command:

    no shutdown
  9. Exit the interface configuration using the following command:

    exit
  10. Exit the configuration mode:

    exit

    After this you can display the interfaces and see the state of the interface just configured

  11. Save the update on the running-config to the startup-config file using the following command:

    copy running-config startup-config

Synchronizing Logging in Cisco Router

To always have a readable command line on cisco console, aux and/or virtual terminals it is recommended to synchronize the logging.

Pre-requisite

  • Putty application

Synchronizing the Logging

  1. Connect to cisco console using putty.

  2. Press the enter key to enter into user mode.

  3. Execute the following command to enter into privilege mode:

    enable
  4. Load the startup-config into the running-config using the following command:

    copy startup-config running-config
  5. Execute the following command to enter into the configuration mode:

    config terminal
  6. Synchronize the logging on console using the following commands:

    line con 0
    logging sync
  7. Synchronize the logging on AUX using the following command:

    line aux 0
    logging sync
  8. (Optional) Synchronize the logging on 5 virtual terminals using the following command:

    line vty 0 4
    logging sync

    Only do this if you are using virtual terminals, specially with SSH connections.

  9. Exit the virtual terminal configuration using the following command:

    exit
  10. Exit the configuration mode:

    exit
  11. Save the update on the running-config to the startup-config file using the following command:

    copy running-config startup-config

Enable SSH on a Cisco Router

Pre-requisite

  • Putty application

Enabling SSH

  1. Connect to cisco console using putty.

  2. Press the enter key to enter into user mode.

  3. Execute the following command to enter into privilege mode:

    enable
  4. Load the startup-config into the running-config using the following command:

    copy startup-config running-config
  5. Execute the following command to enter into the configuration mode:

    config terminal
  6. Change the hostname using the following syntax:

    hostname 
  7. Change the domain name using the following syntax:

    ip domain-name 
  8. Generate the SSH keys using the following command:

    crypto key generate rsa general-keys
  9. On How many bits in the modules [512]:, type in 2048 and press the enter key.

  10. Enable SSH version 2 using the following command:

    ip ssh version 2
  11. Create an SSH credential using the following syntax:

    username  secret 
  12. Create 5 (i.e. vty 0 to 4) virtual terminals for SSH connections, using the following command.

    line vty 0 4
  13. Allow only SSH to the newly created virtual connection using the following command:

    transport input ssh
  14. Use only the local database for credentials using the following command:

    login local
  15. Exit the virtual terminal configuration:

    exit
  16. Exit the configuration mode:

    exit
  17. Save the update on the running-config to the startup-config file using the following command:

    copy running-config startup-config
  18. Using putty, connect on any known IP of the router via SSH using the credentials you made from step 11.

Override the Forgotten Password on a Cisco Router

Pre-requisite

  • Putty application

Overriding the Forgotten Password

  1. Connect to cisco console using putty.

  2. Press the enter key to enter into user mode.

  3. Once in the user mode (i.e. the prompt with greater than sign >), reboot the cisco router (i.e. using the physical switch of the router).

  4. Going back to your putty terminal, once you see any text on it, issue the break command.

    1. Point and click your mouse to the putty icon on putty title bar.

    2. Select Special Command.

    3. Select Break.

      Expect the see the rom monitor prompt as follows:

      rommon 1 >

  5. Execute the following command to disable the startup-config:

    confreg 0x2142
  6. Reset cisco router using the following command:

    reset
  7. Expect to see the following question:

    Would you like to enter the initialization configuration dialog? [yes/no]
  8. Type in no for the answer and press the enter key.

  9. Press the enter key one more time to enter into user mode.

  10. Execute the following command to enter into privilege mode:

    enable
  11. Load the startup-config into the running-config using the following command:

    copy startup-config running-config
  12. On Destination filename [running-config]?, press the enter key.

  13. Execute the following command to enter into the configuration mode:

    config terminal
  14. Change the password using the following syntax:

    enable secret <PASSWORD>

    Example of setting cisco as the password:

    enable secret cisco
  15. Execute the following command to enable the startup-config:

    config-register 0x2102
  16. Exit from the configuration mode using the following command:

    exit
  17. Save the update on the running-config to the startup-config file using the following command:

    copy running-config startup-config
  18. On Destination filename [startup-config]?, press enter key.

  19. Reboot the cisco router (i.e. using the physical switch of the router).

    After this you have the new password in effect.

Using USB to Connect to Cisco Console

Pre-requisite

  • Windows 64-bit
  • Putty application

Connecting to Cisco Console

  1. Access https://software.cisco.com/download/home.

    This requires you to be logged in to download anything.

  2. Search for the following:

    Software on Chassis : 3945 Integrated Services Router
  3. On the Select a software type, choose the following:

    USB Console Software
  4. Download the latest release (i.e. 3.1 is the latest at the time of this writing).

    This is in the form of the zip file.

  5. Extract the zip file and select which appropriate installer (i.e. based on OS type) you need.

    We will choose Windows 64-bit for this procedure.

  6. Once the installer is identified, install it.

  7. Insert the mini USB-B to the console port at the back of the cisco router.

  8. Power on your cisco router.

  9. Insert the USB-A to one of your computer's USB where you installed the USB Console Software.

  10. Open your windows device manager and check the node, Ports (COM & LPT).

  11. Identify the COM port for Cisco Serial, as follows:

  12. Once the COM port is identified, open your putty application.

  13. Select Serial as the Connection type.

  14. In the Serial line, type in the identified COM port from step 11.

  15. Click the Open button.

    This will open a cisco console, if everything is good.

« Older posts