Category: Windows

  • NTFS The disk contains an unclean file system

    NTFS The disk contains an unclean file system

    When trying to mount a Windows NTFS partition on Linux, I got the following error message

    root@vmi552968:~# mount -t ntfs /dev/sda1 /mnt
    The disk contains an unclean file system (0, 0).
    Metadata kept in Windows cache, refused to mount.
    Falling back to read-only mount because the NTFS partition is in an
    unsafe state. Please resume and shutdown Windows fully (no hibernation
    or fast restarting.)
    Could not mount read-write, trying read-only
    root@vmi552968:~#
    

    This is because Windows Machine is not properly shutdown. If you don’t have access to properly shutdown, for example, you lost password for windows, you can use the “ntfsfix” command to fix the warning.

    ntfsfix /dev/sda1
    

    Example

    root@vmi552968:~# ntfsfix /dev/sda1
    Mounting volume... The disk contains an unclean file system (0, 0).
    Metadata kept in Windows cache, refused to mount.
    FAILED
    Attempting to correct errors... 
    Processing $MFT and $MFTMirr...
    Reading $MFT... OK
    Reading $MFTMirr... OK
    Comparing $MFTMirr to $MFT... OK
    Processing of $MFT and $MFTMirr completed successfully.
    Setting required flags on partition... OK
    Going to empty the journal ($LogFile)... OK
    Checking the alternate boot sector... OK
    NTFS volume version is 3.1.
    NTFS partition /dev/sda1 was processed successfully.
    root@vmi552968:~# mount -t ntfs /dev/sda1 /mnt
    root@vmi552968:~# 
    

    Back to mount

  • How to Reset Windows Password in Linux Rescue

    How to Reset Windows Password in Linux Rescue

    If you lost your windows user password, you can boot into Linux Live CD or Rescue CD and reset your Windows password as follows. Most VPS and dedicated server providers have the option to boot your server into rescue mode.

    Install required packages

    apt-get install chntpw ntfs-3g

    Find the Windows partition and mount it

    mount -t ntfs /dev/nvme0n1p1 /mnt

    If you get error while mounting, see NTFS The disk contains an unclean file system.

    Go to the directory where Windows Password is stored

    cd /mnt/Windows/System32/config

    To list available users, run

    chntpw -l SAM

    To reset the password for a user, run

    chntpw -u USER_NAME_HERE SAM

    Select option 1

     1 - Clear (blank) user password

    This will set the Windows password for the user to blank.

    Next select option 2.

     2 - Unlock and enable user account [probably locked now]

    It will change to

    (2 - Unlock and enable user account) [seems unlocked already]

    Select option q to quit.

     q - Quit editing user, back to user select

    It will ask you to save changes, press “y” to save.

    root@vmi1255071:/mnt/Windows/System32/config# chntpw -u Administrator SAM
    chntpw version 1.00 140201, (c) Petter N Hagen
    Hive  name (from header): <\SystemRoot\System32\Config\SAM>
    ROOT KEY at offset: 0x001020 * Subkey indexing type is: 666c 
    File size 262144 [40000] bytes, containing 7 pages (+ 1 headerpage)
    Used for data: 298/26896 blocks/bytes, unused: 16/1552 blocks/bytes.
    
    ================= USER EDIT ====================
    
    RID     : 0500 [01f4]
    Username: Administrator
    fullname: 
    comment : Built-in account for administering the computer/domain
    homedir : 
    
    00000220 = Administrators (which has 1 members)
    
    Account bits: 0x0010 =
    [ ] Disabled        | [ ] Homedir req.    | [ ] Passwd not req. | 
    [ ] Temp. duplicate | [X] Normal account  | [ ] NMS account     | 
    [ ] Domain trust ac | [ ] Wks trust act.  | [ ] Srv trust act   | 
    [ ] Pwd don't expir | [ ] Auto lockout    | [ ] (unknown 0x08)  | 
    [ ] (unknown 0x10)  | [ ] (unknown 0x20)  | [ ] (unknown 0x40)  | 
    
    Failed login count: 19, while max tries is: 0
    Total  login count: 15
    ** No NT MD4 hash found. This user probably has a BLANK password!
    ** No LANMAN hash found either. Try login with no password!
    
    - - - - User Edit Menu:
     1 - Clear (blank) user password
     2 - Unlock and enable user account [probably locked now]
     3 - Promote user (make user an administrator)
     4 - Add user to a group
     5 - Remove user from a group
     q - Quit editing user, back to user select
    Select: [q] > 1
    Password cleared!
    ================= USER EDIT ====================
    
    RID     : 0500 [01f4]
    Username: Administrator
    fullname: 
    comment : Built-in account for administering the computer/domain
    homedir : 
    
    00000220 = Administrators (which has 1 members)
    
    Account bits: 0x0010 =
    [ ] Disabled        | [ ] Homedir req.    | [ ] Passwd not req. | 
    [ ] Temp. duplicate | [X] Normal account  | [ ] NMS account     | 
    [ ] Domain trust ac | [ ] Wks trust act.  | [ ] Srv trust act   | 
    [ ] Pwd don't expir | [ ] Auto lockout    | [ ] (unknown 0x08)  | 
    [ ] (unknown 0x10)  | [ ] (unknown 0x20)  | [ ] (unknown 0x40)  | 
    
    Failed login count: 19, while max tries is: 0
    Total  login count: 15
    ** No NT MD4 hash found. This user probably has a BLANK password!
    ** No LANMAN hash found either. Try login with no password!
    
    - - - - User Edit Menu:
     1 - Clear (blank) user password
     2 - Unlock and enable user account [probably locked now]
     3 - Promote user (make user an administrator)
     4 - Add user to a group
     5 - Remove user from a group
     q - Quit editing user, back to user select
    Select: [q] > 2
    Unlocked!
    ================= USER EDIT ====================
    
    RID     : 0500 [01f4]
    Username: Administrator
    fullname: 
    comment : Built-in account for administering the computer/domain
    homedir : 
    
    00000220 = Administrators (which has 1 members)
    
    Account bits: 0x0210 =
    [ ] Disabled        | [ ] Homedir req.    | [ ] Passwd not req. | 
    [ ] Temp. duplicate | [X] Normal account  | [ ] NMS account     | 
    [ ] Domain trust ac | [ ] Wks trust act.  | [ ] Srv trust act   | 
    [X] Pwd don't expir | [ ] Auto lockout    | [ ] (unknown 0x08)  | 
    [ ] (unknown 0x10)  | [ ] (unknown 0x20)  | [ ] (unknown 0x40)  | 
    
    Failed login count: 0, while max tries is: 0
    Total  login count: 15
    ** No NT MD4 hash found. This user probably has a BLANK password!
    ** No LANMAN hash found either. Try login with no password!
    
    - - - - User Edit Menu:
     1 - Clear (blank) user password
    (2 - Unlock and enable user account) [seems unlocked already]
     3 - Promote user (make user an administrator)
     4 - Add user to a group
     5 - Remove user from a group
     q - Quit editing user, back to user select
    Select: [q] > q
    
    Hives that have changed:
     #  Name
     0  
    Write hive files? (y/n) [n] : y
     0   - OK
    root@vmi1255071:/mnt/Windows/System32/config# 

    Now you need to log in to the server using the console, it won’t ask for any password. Once logged in, you can set a password for the user. You can’t log in using RDP with a blank password.

    After the password reset, “chntpw -l SAM” will look like the following

    root@vmi1255071:/mnt/Windows/System32/config# chntpw -l SAM
    chntpw version 1.00 140201, (c) Petter N Hagen
    Hive  name (from header): <\SystemRoot\System32\Config\SAM>
    ROOT KEY at offset: 0x001020 * Subkey indexing type is: 666c 
    File size 262144 [40000] bytes, containing 7 pages (+ 1 headerpage)
    Used for data: 298/26896 blocks/bytes, unused: 16/1552 blocks/bytes.
    
    | RID -|---------- Username ------------| Admin? |- Lock? --|
    | 01f4 | Administrator                  | ADMIN  | *BLANK*  |
    | 01f5 | Guest                          |        | dis/lock |
    root@vmi1255071:/mnt/Windows/System32/config# 

    Back to Windows

  • The best Windows backup software

    The best Windows backup software

    If you are using a Windows Server, you may need to backup your data as storage devices can fail at any time. It is better to have a backup instead of worrying about lost data. Here is some software that can help with protecting data on your windows servers.

    Paragon Backup & Recovery

    PARAGON Backup & Recovery Community Edition is free backup software for personal use. If you are using it for commercial use, you may need to get paid version of the software. This software makes an image of your HD & so you can quickly restore the complete system should the disk fail.

    https://www.paragon-software.com/free/br-free/

    Cobian Backup

    Cobian Backup is a file-backup program that can be used to make automatic backups for your directories and files. Cobian Backup can be run as a service or as a regular application. It can backup to some other location in the same computer, to the network and even to an FTP server. The program supports compression and encryption.

    https://www.cobiansoft.com/cobianbackup.html

    Robycopy

    robocopy is a command line program like the Linux rsync command, you can write a batch script and use Task Scheduler to run it as needed.

    https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy

  • Enable Remote Connection in MS SQL Server

    Enable Remote Connection in MS SQL Server

    MS SQL Server does not allow remote connection by default. To enable MS SQL remote connection, you need to open port 1433 in the firewall. After the port is open, you need to enable TCP/IP protocol in MS SQL Server.

    Start SQL Server Management Studio, take the property of the server

    Enable SQL Server and Windows Authentication mode

    SQL server autentication

    Under Connections, allow Allow Remote Connections

    SQL Server allow remote connection

    Start SQL Configuration Manager.

    Start SQL Configuration Manager

    Go to

    SQL Configuration Manager > SQL Server Network Configuration > Protocols for MSSQL SERVER
    

    Enable TCP/IP

    MS SQL enable TCP/IP

    Now you need to restart MS SQL server, after that, you should be able to connect to MS SQL server remotely.

  • How to uninstall the PowerShell Module?

    To uninstall a PowerShell module use the Uninstall-Module command. The module should not be in use to uninstall it.

    Uninstall-Module -Name MODULE_NAME_HERE
    

    To force uninstall a module run

    Uninstall-Module -Name MODULE_NAME_HERE -Force -Verbose
    

    To uninstall all versions of a module, use option -AllVersions

    Uninstall-Module -Name MODULE_NAME_HERE -AllVersions -Force -Verbose
    

    If you need to keep a version and uninstall all other versions, run

    Uninstall-Module -Name MODULE_NAME_HERE -RequiredVersion 2.1.2 -Force -Verbose
    
  • How to backup PuTTY Settings

    PuTTY is a very lightweight SSH Client software for the Windows Operating system. Sometimes you need to back up and restore Putty sessions (saved SSH connections) to another computer. Putty stores its settings and SSH sessions in Windows Registry.

    PuTTY settings are stored in Windows Registry at

    HKEY_CURRENT_USER\Software\SimonTatham
    

    To back up, the settings, run

    regedit /e "%USERPROFILE%\Desktop\putty.reg" HKEY_CURRENT_USER\Software\SimonTatham
    

    This will create a file putty.reg on your Desktop.

    To restore it, double click on the putty.reg file.

    See PuTTY

  • Restart IIS from command line

    Restart IIS from command line

    To restart IIS from command line, click on start, search for “cmd”, right click on “Command Prompt” select run as Administrator. On the command prompt, run

    iisreset
    

    Start IIS

    To start IIS from command line, run

    iisreset /start
    

    restart iis from command line

    Stop IIS

    iisreset /stop
    

    See IIS

  • Nginx on Windows

    You can download nginx for windows from

    https://nginx.org/en/download.html

    To download nginx from command line, use following command in PowerShell

    Invoke-WebRequest -Uri https://nginx.org/download/nginx-1.19.6.zip -OutFile nginx-1.19.6.zip
    

    Auto Start Nginx on Windows

    When using Nginx on Windows, you need to escape paths with \ like following

    root C:\\sites\\my-site;
    

    For SSL, i used

    listen 443 ssl http2;
    ssl_certificate C:\\nginx\\ssl\\crt\\dedi.ai-chain.pem;
    ssl_certificate_key C:\\nginx\\ssl\\crt\\dedi.ai-key.pem;
    

    See Nginx

  • Downloading a file with PowerShell

    To download a file using PowerShell, run

    Invoke-WebRequest -Uri URL_HERE -OutFile FILE_NAME_HERE
    

    Example

    Invoke-WebRequest -Uri http://nginx.org/download/nginx-1.17.10.zip -OutFile nginx-1.17.10.zip
    

    See Windows

  • Enable TLS 1.2 on Windows Server 2008 R2

    Enable TLS 1.2 on Windows Server 2008 R2

    Windows Server 2008 R2 come with IIS 7.5, latest supported TLS version is 1.1. Recently Google Chrome starting showing sites using TLS 1.0 and 1.1 as insecure.

    To fix this, create a file tls12-enable.reg with following content

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client]
    "DisabledByDefault"=dword:00000000
    "Enabled"=dword:00000001
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server]
    "DisabledByDefault"=dword:00000000
    "Enabled"=dword:00000001
    

    Now run a command promt (cmd.exe) as Administrator. Go to the folder where tls12-enable.reg is saved, run

    reg import tls12-enable.reg
    

    Now reboot your server. Once server is back online, check if server is supporting TLS 1.2 using

    https://www.ssllabs.com/ssltest/analyze.html

    If TLS 1.2 is showing as enbaled, we can disable all older insecure protocols, for this, create a file disable.reg with following content

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Client]
    "DisabledByDefault"=dword:00000001
    "Enabled"=dword:00000000
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Server]
    "DisabledByDefault"=dword:00000001
    "Enabled"=dword:00000000
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0\Client]
    "DisabledByDefault"=dword:00000001
    "Enabled"=dword:00000000
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0\Server]
    "DisabledByDefault"=dword:00000001
    "Enabled"=dword:00000000
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Client]
    "DisabledByDefault"=dword:00000001
    "Enabled"=dword:00000000
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Server]
    "DisabledByDefault"=dword:00000001
    "Enabled"=dword:00000000
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Client]
    "DisabledByDefault"=dword:00000001
    "Enabled"=dword:00000000
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Server]
    "DisabledByDefault"=dword:00000001
    "Enabled"=dword:00000000
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\RC4 128/128]
    "Enabled"=dword:00000000
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\RC4 40/128]
    "Enabled"=dword:00000000
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\RC4 56/128]
    "Enabled"=dword:00000000
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\KeyExchangeAlgorithms\Diffie-Hellman]
    "ServerMinKeyBitLength"=dword:00000800
    

    Start a command promt as user Administrator, navigate to folder where disable.reg is saved, run command

    reg import disable.reg
    

    Reboot server. once server is back online, you will have all disabled protocols disabled. ssllabs will show Score A.

    SSL Score A

  • LetsEncrypt Windows

    LetsEncrypt provide Free SSL with 90 day validity. You need to renew it every 90 days, there are software to do this. For windows some of the popular software are.

    win-acme

    This is a small exe file, it have command line interface (No GUI). You need to run this program ad Administrator (Run as Administrator), then only it will setup Scheduled Tasks needed for auto SSL renew.

    It support auto SSL install on IIS and have option for custom SSL install.

    https://www.win-acme.com/

    CertifyATheWeb

    This is a GUI program.

    https://certifytheweb.com

    See Nginx on Windows, Nginx SSL