Debian is a popular version, or fork, of the Linux operating system.
The most recently released version is Debian 10, codenamed Buster. The previous version Debian 9 Stretch is officially supported until June 2022. The newer version offers a longer support period and new features, so it is highly recommended to upgrade if running Debian 9.
This tutorial will walk you through how to upgrade from Debian 9 (Stretch) to Debian 10 (Buster).
Prerequisites
A system running Debian 9
A Debian user account with sudo privileges
Access to a command line/terminal window (Ctrl–Alt–F2)
A recent snapshot (backup) of the system
Upgrade to Debian Version 10 Buster
Make sure to back up your system and data prior to upgrading. That way, if anything breaks during the upgrade, you can easily restore your system configuration.
Step 1: Update Package Manager and Repositories
By default, Debian 9 refers to the repositories designated for Stretch.
1. First, create a backup copy of the /etc/apt/sources.list file:
2. Then, open the file for editing (we are using GNU nano for text editing):
sudo nano /etc/apt/sources.list
3. Change all the references in this file from Stretch to Buster. The entries should appear as follows:
deb http://deb.debian.org/debian debian buster main
deb http://deb.debian.org/debian buster-updates main
deb http://deb.debian.org/debian buster/updates main
4. Save the file using the keyboard combination Ctrl+O and Exit by pressing Ctrl+X.
We can use several NMAP command flags to scan specific TCP and UDP ports, as seen inTable 1.1below.
Description
NMAP Command Flag
Scan all ports
-p “*”
Scan top ports
–top-ports [number]
Scan specific ports
-p [port]
Scan ports by name
-p [name]
Scan ports by protocol
-p U:[UDP ports],T:[TCP ports]
Perform a fast scan
-F
Perform a sequential port scan
-r
Table 1.1: [NMAP Scan Any Port]: Flags summary
Let’s discuss each NMAP flag in the above table, their syntax, and use case.
Scan All Ports With NMAP
FLAG: -p “*”
Command syntax: nmap -p “*” [Target]
Description: Perform NMAP scan for all 65,535 TCP/UDP ports. This command do does not mandate elevated privileges.
The NMAP Scan All Ports flag will produce a scan for all 65,535 TCP and UDP ports on a target machine and output a list of open ports as well as the services running on a specific port [Figure 1.1].
Make sure your wildcard [*] statement is enclosed in quotes (“”); otherwise, NMAP will throw a syntax error, as seen in Figure 1.2 below.
Scan Top Ports With NMAP
Flag: –top-ports [Number]
Command Syntax: nmap –top-ports [Number] [Target]
Description: Perform an NMAP scan by specifying the number of top-ranked ports to scan.
The NMAP Scan Top Ports flag allows us to define the number of top-ranked ports to scan. For example, let’s assume we want to scan the top commonly used 50 ports.
The NMAP command for scanning the top commonly used ports is shown below with the output in Figure 1.3.
nmap – top-ports 10000 172.16.121.134
NOTE: Remember to replace the IP address in my example with your target IP address.
Let’s perform another scan, this time for the top 10000 commonly used ports on a target machine using the NMAP command below and the output shown in Figure 1.4
nmap – top-ports 10000 172.16.121.134
NOTE: Top commonly used ports e.g., 10000, do not refer to the range of ports starting with, e.g., 1 to 10000.
Scan Specific Ports With NMAP
Flag: -p
Command Syntax: nmap -p [Port] [Target]
Description: Perform an NMAP scan for a specified port or range of ports.
The Scan Specific Port(s) flag instructs NMAP to perform a scan on a single port or multiple ports [separated by a comma and no spaces] on a specified target. Check out the list of the most commonly hacked ports for your reference.
Let’s practice this method by instructing NMAP to scan a single port, e.g., port 80, using the following command with the output shown in Figure 1.5.
nmap -p 80 172.16.121.134
Next, let’s instruct NMAP to scan multiple or a range of ports, e.g., 25, 53, 80-500 using the command below with the output seen in Figure 1.6.
nmap -p 25,53,80-500 172.16.121.134
Scan Ports By Name With NMAP
Flag: -p
Command Syntax: nmap -p [Port name(s)] [Target]
Description: Perform an NMAP scan for a specified port or ports.
The NMAP Scan Ports By Name uses the same -p flag as used in the previous method. Here we will instruct NMAP to scan based on the port name [http,ftp,smtp] and not a number.
NOTE: When scanning multiple ports by name, make sure you separate the name with a comma and no spaces.
The port name must match the exact name as specified in the nmap-service file.
On Windows, you can find the nmap-service file in the c:\Program Files\Nmap\ folder. On Linux/UNIX, the nmap-service file is generally located in/usr/share/nmap folder [Kali Linux 2021].
Alternatively, you can access the list of NMAP port names included in the nmap-service file HERE.
Let’s instruct NMAP to scan the FTP [21] and HTTP [80] ports on a target using the following command and the output shown in Figure 1.7.
nmap -p ftp,http 172.16.121.134
This NMAP command flag also supports wildcard. Let’s filter all the FTP ports using the command below with the output shown in Figure 1.8.
Description: Search for a specific protocol and port combination.
As in previous examples, the Scan Ports By Protocol method uses the -p option followed by T: [for TCP ports] and U: [for UDP ports] flags. Simply said, we will instruct NMAP to scan for a specific TCP and UDP port on a target machine in a single command line.
Let’s execute a scan using this method for UDP port 53 [DNS] and TCP port 25 [SMTP], as shown in Figure 1.9 below. Pay attention to the NMAP WARNING message highlight in yellow.
By default, NMAP scans only the TCP ports. We need to instruct NMAP to check the UDP ports as well. To do that, we need to enforce our command with the additional -sU and -sT flags.
So let’s run the command again, this time including the additional flags as shown below with the output in Figure: 1.10.
nmap -sU -sT -p U:53,T:25 172.16.121.134
Voilà ! Both TCP port 25 and UDP port 53 were successfully scanned on the target machine.
Fast Scan Flag With NMAP
FLAG: -F
Command Syntax: nmap -F [Target]
Description: Perform a fast scan of only 100 most commonly used ports. Do not mandate elevated privileges.
As explained in the previous sections, NMAP will scan by default only the commonly used 1000 ports.
The NMAP Fast ScanFlag will reduce the number of ports scanned from 1000 to 100 [commonly used ports] and drastically improve the time per scan while still providing us valuable information on the open ports in numerical order [Figure 1.11].
But wait! There’s a catch.
Each time NMAP shows an output will automatically sort the final result. We can use the additional flag -v [verbose mode] and see the sequential port scan in real-time [Figure 1.12].
That’s it. By now, you should know how to use NMAP to scan any TCP and UDP port(s) on a target computer.
Often times we are tasked with having to programmatically come with a list of durations per SQL Server Agent Job to trend the run times and order the results by date. Unfortunately Microsoft has not made that very easy in the way the data is stored in the system tables in the MSDB database. In this tip I will explain how to use the system tables to get the data into the correct format for dates and job durations.
Solution
SQL Server stores job information in the MSDB system tables. The table that stores historical job executions is msdb.dbo.sysjobhistory and the date/time information as well as the duration of the job execution is stored a little different than what you will see in most system tables. Let's dive into the tables to learn how to perform the calculations.
MSDB.dbo.sysjobhistory Table - run_date and run_time Columns
In the msdb.dbo.sysjobhistory table, the date (run_date column) and time (run_time column) are stored as two different columns and the columns are an INT data type as seen in the screenshot below.
If you were to query the sysjobhistory (joined to sysjobs of course) this is what the raw data would look like. Note run_date appears to be in YYYYMMDD format but the time is a little trickier. It is in format HHMMSS and not always 6 numbers long as you can see in this example the times are 3:30 AM represented by 33000 in the run_time column.
The result set in the picture above was generated by running the following T-SQL script:
select
j.name as 'JobName',
run_date,
run_time
From msdb.dbo.sysjobs j
INNER JOIN msdb.dbo.sysjobhistory h
ON j.job_id = h.job_id
where j.enabled = 1 --Only Enabled Jobs
order by JobName, run_date, run_time desc
This can be very confusing when trying to analyze these results and more importantly trying to order results by date and time, which as a common practice for DBA's. There are many ways to get the date/time into a true DATETIME format and I have seen some very creative scripts over the years. Starting in SQL Server 2005 there is an system scalar function located in MSDB that will convert this for you. I say it is undocumented as I could not find a BOL article for it. The function name is MSDB.dbo.agent_datetime(run_date, run_time) and will return a nicely formatted DATETIME column that is much easier to use programmatically. Below is the same query as the first one above with just an additional column that is a call to this function.
select
j.name as 'JobName',
run_date,
run_time,
msdb.dbo.agent_datetime(run_date, run_time) as 'RunDateTime'
From msdb.dbo.sysjobs j
INNER JOIN msdb.dbo.sysjobhistory h
ON j.job_id = h.job_id
where j.enabled = 1 --Only Enabled Jobs
order by JobName, RunDateTime desc
Below are the results that this query produces and the nicely formatted DATETIME column at the end. This makes sorting easy as well as date range queries against your SQL Agent Jobs.