Check NTP server working or not, Check NTP server Date and Time – Windows, Linux

Windows

1 Use Win + R to open run Window

Microsoft Windows - Run window
Microsoft Windows – Run window

2 Type cmd, then hit Enter key

Microsoft Windows - Run window - cmd.exe
Microsoft Windows – Run window – cmd.exe

The command we use is in following format:

w32tm /stripchart /computer:domainnameORipaddress /dataonly /samples:5

3 Enter following command to test “time.windows.com”

w32tm /stripchart /computer:time.windows.com /dataonly /samples:5
Microsoft Windows - CMD -   w32tm /stripchart /computer:time.windows.com /dataonly /samples:5 output
Microsoft Windows – CMD – w32tm /stripchart /computer:time.windows.com /dataonly /samples:5 output

Bonus: Other commands

1 Show the current time zone settings:

w32tm /tz

2 List external NTP servers (peers)

w32tm /query /peers
Microsoft Windows - CMD -  w32tm /query /peers output
Microsoft Windows – CMD – w32tm /query /peers output

Note! If you have encountered this error: “The following error occurred: The service has not been started. (0x80070426)”, you need to start the “Windows Time” service, you can start a elevated cmd or PowerShell by using Win + X key combination then select “Command Prompt (Admin)” or “Windows PowerShell (Admin)” then type “sc start W32Time” to start the Windows Time service or using Run window and type “services.msc” then find “Windows Time” service and start it.

3 Restore Windows Time service settings to default

C:\>net stop w32time
C:\>w32tm /unregister
C:\>w32tm /register
C:\>net start w32time

4 Re-sync Time

Resynchronize the clock as soon as possible, disregarding all accumulated error statistics. If no computer is specified, the local computer will resynchronize. The command will wait for resynchronization unless the /nowait switch is used.

w32tm /resync

5 Redirect the network configuration and Re-sync time

Force redetection of network resource before resynchronization.

w32tm /resync /rediscover
Microsoft Windows - PowerShell - w32tm /resync /rediscover output
Microsoft Windows – PowerShell – w32tm /resync /rediscover output

6 Check current NTP configuration

Show Information:

w32tm /query /status
Microsoft Windows - PowerShell -  w32tm /query /status  output
Microsoft Windows – PowerShell – w32tm /query /status output

Show Configuration:

w32tm /query /configuration
Microsoft Windows - PowerShell -  w32tm /query /configuration  output
Microsoft Windows – PowerShell – w32tm /query /configuration output

Linux

1 ntpdate -q domainnameORipaddress

ntpdate -q time.windows.com
Linux - Terminal - ntpdate -q time.windows.com output
Linux – Terminal – ntpdate -q time.windows.com output

2 ntpq -p domainnameORipaddress

ntpq -p 192.168.1.1

Windows Server, Windows 10 missing disk performance counter in Task Manager

To fix missing disk performance counter in Task Manager:

Windows Task Manager missing disk performance counter
Windows Task Manager missing disk performance counter
Windows Task Manager with disk performance counter
Windows Task Manager with disk performance counter

Fix

1 Use Win + X key combination to open menu, click on Windows PowerShell (Admin) to open elevated PowerShell window.

2 Close Task Manager if you have it open

3 Type following command and hit Enter Key

diskperf -y
Windows PowerShell - diskperf -y
Windows PowerShell – diskperf -y

4 Now open Windows Task Manager again, the disk performance counter should appear.

Note: To diesable it again, just repeat these steps but replace diskperf -y with diskperf -n

How to use Apache .htaccess .htpasswd to protect files, folders and paths and to protect multiple files, multiple folders and paths

Keywords: Apache, .htaccess, .htpasswd, block access, protect file, protect folder, protect directory, protect path

If we have following folders

/web/resource1/file1.htm
/web/resource1/A/
/web/resource2/file2.php
/web/resource2/B/C/D/
/web/resource3/E/F/

and Following url path

https://www.example.com/
https://www.example.com resource1/file1.htm
https://www.example.com/ resource1/A/
https://www.example.com/ resource2/file2.php
https://www.example.com/ resource2/B/C/D/
https://www.example.com resource3/E/F/ https://www.example.com/secret

The document root for “https://www.example.com/” is “/web/”

Path secret is a virtual path which does not reflect to a real directory with name “secret” (e.g. an existing rewrite rule in .htaccess)

Now we want to protect file “file1.htm” directory “D” and directory “E”, “F” and virtual path “secret”

1.1 We need to create a .htaccess file under “web” directory

1.2 Open the .htaccess file, we need to add following contents for protecting files

#Protected file
<Files file1.htm>
#Password file path
AuthUserFile /web/.htpasswd
#Message for user to see
AuthName "Password protected"
AuthType Basic
#(If only allow specific user, use "require user username" if allow all valid users use "Require valid-user")
require user username
</Files>

Note: if dealing with multiple files, filesmatch should be used.

<FilesMatch "file1\.htm|file2\.php">
AuthUserFile /web/.htpasswd
AuthName "Password protected"
AuthType Basic
require user username
</FilesMatch>

Tip: Targeting files start with abc or def and end in .php

<FilesMatch "^(abc|def).php$">
AuthUserFile /web/.htpasswd
AuthName "Password protected"
AuthType Basic
require user username
</FilesMatch>

1.3 We add following content to protect directories and the virtual path (We can use this method to protect multiple sub-directories/sub-folders/paths)

#Do the regex check against the URI here, if match, set the "require_auth" var
SetEnvIf Request_URI ^/ resource2\/B\/C\/D require_auth=true
SetEnvIf Request_URI ^/ resource3\/E require_auth=true

#Auth stuff
AuthUserFile /web/.htpasswd
AuthName "Password protected"
AuthType Basic

#Setup a deny/allow
Order Deny,Allow
#Deny from everyone
Deny from all
#except if either of these are satisfied
Satisfy any
#1. a valid authenticated user
Require valid-user
#or 2. the "require_auth" var is NOT set
Allow from env=!require_auth

https://stackoverflow.com/questions/14603568/password-protect-a-specific-url

1.4 We create a .htpasswd file under “web” directory

1.5 Open the .htpasswd file we add following contents (File contains username:hashed user password)

user1:$apr1$MknR4YQ8$ls4RTpNIxaJWyedBK5m030
user2:$apr1$FtfabsVg$NoxTA07DDeGhSOYT9NMLF/

These password can be generated using htpasswd with following command:

$  sudo htpasswd -c /web/.htpasswd user1

(You will need to supply and confirm the password for the user)

$ sudo htpasswd /web/.htpasswd user2

Another way to protect current directory:

e.g. If we want to protect directory “A”

2.1 Creat a .htaccess file under in directory “A”, so we have “/web/resource1/A/.htaccess”

2.2 We add following content to the file

<Files ~ "^.(htaccess|htpasswd)$">
deny from all
</Files>
AuthUserFile /web/resource1/A/.htpasswd
AuthGroupFile /dev/null
AuthName "Please enter your ID and password"
AuthType Basic
require valid-user 
order deny,allow

2.3 We create the .htpasswd file under “/web/resource1/A/”, so we have “/web/resource1/A/.htpasswd”

2.4 We generate password as in step 1.5 (We need to change path from “/web/.htpasswd” to “/web/resource1/A/.htpasswd”)

Now the directory “A” is protected


Tips:

1 We can use online .htpasswd generator to create password for convenience

https://www.htaccesstools.com/htpasswd-generator/

https://www.web2generators.com/apache-tools/htpasswd-generator

https://www.askapache.com/online-tools/htpasswd-generator/

https://htmlstrip.com/htpasswd-generator

https://www.mobilefish.com/services/htpasswd_generator/htpasswd_generator.php

2 We can use online tools to generate .htaccess for convenience

https://www.htaccessredirect.net/

https://hostingfacts.com/htaccess-generator/

https://makeawebsitehub.com/htaccess-generator/

How to fix Microsoft Hyper-V Error: The application encountered an error while attempting to change the state of ‘New Virtual Machine’.

The Error:

The application encountered an error while attempting to change the state of ‘New Virtual Machine’.

‘New Virtual Machine’ failed to start.

Synthetic SCSI Controller (Instance ID xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx): Failed to Power on with Error ‘General access denied error’.

Hyper-V Virtual Machine Management service Account does not have permission to open attachment ‘D:\vm.vhdx’. Error ‘General access denied error’.

Hyper-V Error: Virtual Machine Connection - 'New Virtual Machine' failed to start
Hyper-V Error: Virtual Machine Connection – ‘New Virtual Machine’ failed to start

Note: Other similar errors which is related to virtual hard drive (vhd, vhdx) permission issue when starting the Hyper-V virtual might also be fix by using following method.

The Fix:

Method 1:

Remove the virtual hard drive from virtual machine via Hyper-V Manager then reattach the hard drive

Method 2:

1 We need to get the SID of the virtual machine, usually it will be displayed in the error dialogue. If you have the SID continue with step 2, If not, follow the steps below:

1.1 Open the Run window by using Win + R key combination.

Microsoft Windows - Run window
Microsoft Windows – Run window

1.2 Type virtmgmt.msc and hit “OK” button

1.3 Write down the name of the virtual machine which is having perimssion issue.

1.4 Use key combination Win + X, click on Windows PowerShell (Admin) to open PowerShell window. Type following command and hit Enter key (Replace Name of Virtual Machine to your virtual machine’s name)

Get-VM 'Name of Virtual Machine' | Select-Object VMID
Windows PowerShell -  Get-VM 'Name of Virtual Machine' | Select-Object VMID
Windows PowerShell – Get-VM ‘Name of Virtual Machine’ | Select-Object VMID

2 Enter following command in PowerShell to grant permission for this virtual machine to attach the virtual herd drive. ()

icacls "<Path of .vhd or .avhd file>" /grant "NT VIRTUAL MACHINE\<Virtual Machine ID from step 1>":F

or

icacls "<Path of .vhd or .avhd file>" /grant "<Virtual Machine ID from step 1>":F

Tip: By default Hyper-V store virtual machine configuration files in “C:\ProgramData\Microsoft\Windows\Hyper-V”, hard drives in “C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks”

Linux clear intrusion footprint

1 Clear login Log

echo >/var/log/wtmp

2 Clear failed login Log

echo >/var/log/btmp

3 Remove last login echo (Comment out PrintLastLog yes and rstart ssdh service)

vi /etc/ssh/sshd_config

#PrintLastLog yes

service sshd restart OR /etc/init.d/sshd restart

4 Delete bash history

history -c

5 Clear bash history file

rm -rf ~/.bash_history

Kali Linux apt upgrade Error – File has unexpected size

If you have encountered this error, it can be your firewall or other anti virus software blocked the download.

Err:3 http://http.kali.org/kali kali-rolling/main amd64 gzip amd64 1.9-3+b1
   File has unexpected size (220668 != 128516). Mirror sync in progress? [IP: 104.18.103.100 80]
   Hashes of expected file:
 SHA256:e523e6898509a24e6a6424b4fcd4575354a771a4e17ebc244e4a52986a781873
 SHA1:a75db093d2b6f6939be80ab076c78d4e3c1cd54b [weak]
 MD5Sum:679ac9ca25637099514d9f3b1e3ceed5 [weak]
 Filesize:128516 [weak] 
Kali Linux - apt upgrade, File has unexpected size
Kali Linux – apt upgrade, File has unexpected size

A quick workaround can be using https instead of http

Enter this command, then use apt clean, apt update and apt upgrade

echo "deb https://http.kali.org/kali kali-rolling main non-free contrib" > /etc/apt/sources.list

apt clean
apt update
apt upgrade

Ubuntu 18.04.3 LTS /usr/lib/apt/methods/http: relocation error

When updating package list with sudo apt update, following error comes up

/usr/lib/apt/methods/http: relocation error: /usr/lib/x86_64-linux-gnu/libgnutls.so.30: symbol _idn2_punycode_decode version IDN2_0.0.0 not defined in file libidn2.so.0 with link time reference    
Reading package lists… Done
E: Method http has died unexpectedly!
E: Sub-process http returned an error code (127)
E: Method /usr/lib/apt/methods/http did not start correctly

1 Download http://ftp.us.debian.org/debian/pool/main/libi/libidn2/libidn2-0_2.0.5-1_amd64.deb

2 Run sudo dpkg -i path/libidn2-0_2.0.5-1_amd64.deb

Computer can only access Google, YouTube, microsoft.com etc. or Nothing at all

Keywords: Internet connection, Limited internet access, netsh, winsock, ipconfig, Microsoft Windows, WiFi, WiFi Router, Modem

Sometimes, you will find that your computer can only access Google, or microsoft.com etc.

For Mirosoft Windows there are many tricks you can try:

1 Win + R

2 Type cmd and hit Enter key.

Try each of these and hit enter at the end of each line

(If use netsh int ip reset, ignore netsh int ipv4 reset and netsh int ipv6 reset)

netsh winsock reset
netsh int ip reset
netsh int ipv4 reset
netsh int ipv6 reset

3 Restart your computer

4 Follow step 1-3 and type following commands, hit enter at the end of each line

ipconfig /release
ipconfig /renew

5 Wait 3 minutes

If you still can not get online.

Try to power cycle/restart your WiFi/Router/Modem. (Normally the box at home or small office you use to access WiFi and internet.)

Linux Server Tips

Keywords: Linux Server Tips, Linux commands

1 Check last login details, who, when

“w” to check last start up time, currently logged in users

“last” to check logins

“who” Currently logged in users’ details

“lastlog” Users’ last login time

“whoami” Show current username

“finger” Find user information

“id” Current user uid, gid and group information

2 Find ports

netstat -anp | grep 443

lsof -i:443

3 Compile source code

“ar” extract archive, archived installation files

“./configure” configure to fit current systems

“make” compile the source code into binary files e.g. executables

“make install” install the compiled program

4 Linux Directories

“/boot”: Linux kernel, boot configuration etc.

“/bin”: Basic user commands, can be run by users

“/dev”: HDD, Keyboard, Mouse, DVD/CD-ROM device files

“/etc”: Configuration files

“/home”: Users’ working directories (home directory etc.)

“/sbin”: Basic management commands, normally only accessable by administrators

“/usr”: Application, source code files, documents etc.

“/var”: Logs, user mail, process data

“/tmp”: Temporary files

5 Common log files

“/var/log/messages”: Kernel and public messages

“/var/log/cron”: Scheduled Tasks/Crontab

“/var/log/dmesg”: System boot log

“/var/log/maillog”: System mail log

“/var/log/secure”: Access control log

6 Common Linux boot files

“/etc/fstab”: Auto mount on boot

“/etc/initab”: Define default boot level

“/etc/rc.local”: Define custom boot tasks

7 suid, sgid, sticky bit

suid: Run as the owner of the file/binary

sgid: Files created within the folder inherits the folder owner’s permission

sticky bit: Users can only modify, delete wheir own files

8 Check process: “ps”, “top”

9 Check process scheduling: “at”, “crontab”, “batch”, “kill”

10 Extract files

1.*.tarExtract using tar -xvf
2.*.gz Extract using gzip -d OR gunzip
3.*.tar.gz Extract using tar -xzf
4.*.bz2 Extract using bzip2 -d OR bunzip2
5.*.tar.bz2 Extract using tar -xjf
6.*.Z Extract using uncompress
7.*.tar.Z Extract using tar -xZf
8.*.rar Extract using unrar e
9.*.zip Extract using unzip

11 Mounting Windows share

mount -t cifs -o username=windowsusername, password="windowspassword" //ipaddress/folder mnt/linuxtargetfolder

OR

mount.cifs //ipaddress/folder /mnt.linuxtargetfolder -o username="windowsusername", password="windowspassword"