Showing posts with label security. Show all posts
Showing posts with label security. Show all posts

Thursday, January 29, 2026

Is a DoS attack similar to Slowloris possible on the layer 3 network protocols? Or a Network interface controller (NIC)?

I have written this article in collaboration with Krishna Bhandarge  

Background

Slowloris is a type of denial of service (DoS) attack which exploits the application‑layer (HTTP) connection handling weaknesses.  The Slowloris is a technique of capitalizing on how web servers keep open partial HTTP requests.

A web server allocates a thread for each incoming request.  Slowloris opens a connection to the target web server and sends partial HTTP headers.  Slowloris holds the connection open as long as possible by sending subsequent HTTP headers, adding to, but never completing the request.  By holding many such connections, Slowloris attempts to exhaust the server's thread / connection pool.  If the affected server keeps the connections open, the maximum concurrent connection pool would get filled completely, eventually denying additional connection attempts from the web clients.



Can the Slowloris attack concept be used to exploit the layer 3 network protocols?  Can the Slowloris attack concept be used to exploit a Network interface controller (NIC)?

A Network interface controller (NIC) operates at Layer 1 (physical layer) and Layer 2 (data link layer).  Slowloris relies entirely on connection handling weaknesses.  Layer 1, layer 2 and layer 3 devices, including NICs, do not maintain a per‑connection state.  Hence, this attack pattern is impossible at Layer 2 and layer 3.


Layer 3 DoS attacks are possible, but they are different from the Slowloris concept.  They are :

- ICMP floods

- Fragmentation floods

- IP packet storms

- Malformed IP packet attacks


These attacks attempt to saturate:

- NIC Rx queues (ring buffers)

- Host CPU network stack processing

- PCIe bandwidth

- Device driver's interrupt-handling capacity


None of these attacks resemble the Slowloris pattern because:

- They do not use partial requests

- They do not require keeping connections open

- They do not exploit HTTP behavior


If a Slowloris attack is happening on a web server, the web server's NIC has no way to detect the attack.  The NIC can not provide any protection.  Here is why.

A Network interface controller (NIC) does not do layer 7 filtering.  A NIC typically provides :

- hardware offloads for TCP

- virtualization support (SR-IOV)

- traffic shaping / QoS

- RDMA (RoCE/iWARP) capabilities

But none of these features prevent Slowloris, because Slowloris is not a bandwidth or packet-rate attack. Slowloris is a protocol resource exhaustion attack.


However, SmartNICs and DPUs are the exception.  Some vendors (NVIDIA BlueField, Intel IPU, AMD Pensando) manufacture SmartNICs or Data Processing Units which can offload Layer 7 logic.


On a side note, here are some ways to prevent a Slowloris attack on a web server.  Layer 7 filtering is typically performed by firewalls, proxies, DPI engines, or service meshes.

Mitigations for Slowloris attack are :

- SYN cookies / TCP stack hardening

- connection rate-limiting via OS firewall

- load balancers or reverse proxies (nginx, Varnish)


Thursday, December 17, 2020

What is noquery in NTP configuration file

Sometime last year, a security vulnerability was reported at a system that acts as NTP server.  After investigation, I found that the system in question was not having noquery in its NTP configuration file /etc/ntp.conf and this resulted in the security vulnerability.  This was probably found by doing a vulnerability scan of the system using Nessus or OpenVAS or something similar.

As a mitigation, I suggested to add noquery in the NTP configuration file and then restart NTP service, so that update to the NTP configuration file comes into effect.


What is this noquery and what is the necessity to have it?

In the NTP configuration file, noquery is a flag that could be used along with restrict command.  When this flag is added to the restrict command, all NTP mode 6 and 7 packets are ignored from the specified source.  In other words, ntpq and ntpdc queries are denied from the specified source.
In absence of noquery flag, that is, if ntpq and ntpdc queries are allowed, then NTP server status information (such as OS and ntpd version) could be identified by doing a scan of the system using Nessus.  This open channel that could be used for revealing system information is reported as a security vulnerability.


So, whether to have noquery flag or not depends on the decision - do we want to allow others to see our server status information?
If answer is yes, then do not have noquery flag along with the restrict command.
If answer is no, then do have the noquery flag.

noquery flag does not affect time service of the NTP server.


Please be aware, the UDP nature of NTP makes NTP servers prone to be abused in case of reflection and amplification attacks.

Friday, July 17, 2020

Python code to generate CAPTCHA

Today I wrote python code to generate CAPTCHA images.  Before we jump into the code, let's recap what a CAPTCHA is.  CAPTCHA is an acronym for Completely Automated Public Turing test to tell Computers and Humans Apart.  This is one type of a challenge–response test that is used in computing to determine whether the user is a human or not.  This is implemented at places where we want only humans to proceed ahead, and stop others (bots et al.)  How effective is the method of using CAPTCHA, and can it be circumvented is not a topic I take here.  Right now, let us get to writing python code for generating CAPTCHA images.

Well, a python library named captcha is available that you could use to generate audio and image CAPTCHAs.  You could install this library and use it to write your python code for generating audio and image CAPTCHAs.  If you want to generate image CAPTCHAs from python code yourself, without using the python's captcha library, do read on.  Wait.  Why would someone write their own code, while a standard library is available?  This is an obvious question.  Well, in most cases we should use the standard library.  Only in some exceptional cases we should write our own code.  In cases when standard library is not available, or is not allowed to be installed.  And in cases when we want some customization in the implementation.  What we have here could be one such case, where we want to customize how the image CAPTCHAs are being generated.

Here is the python code I wrote to generate image CAPTCHAs.

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import string
import random


def draw_text(img, x_given, y_given, text_given, font_given, fill_given):
    d = ImageDraw.Draw(img)
    d.text((x_given, y_given), text_given, font=font_given, fill=fill_given)


def char_selecting(size=6):
    characters = "abdefghijklmnqrtuy123456789ABDEFGHIJKLMNQRTUY"
    # Exclude letters that look similar in capital and small cases
    # Why?
    # We are randomly choosing a font size.  Bigger to smaller.
    # So can't tell whether you are looking at C or c in that situation
    # Exclude zero because we want to avoid confusion between 0 and O and o
    selection = ""
    for x in range(0, size):
        char = characters[random.randint(0, len(characters) - 1)]
        selection = selection + char
    return selection


image_x_size = 200
image_y_size = 100
img = Image.new('RGB', (image_x_size, image_y_size), color = (250, 250, 250))

word = char_selecting(6)    # We want 6 characters in our CAPTCHA
print word

x_pos = 10    # Position of the first character in the image

for char in (list(word)):
    print char

    font_size = random.randint(16, 50)
    # Font size smaller than 16 is too small
    # Font size bigger than 50 is too big
    font_selected = ImageFont.truetype('/usr/share/fonts/gnu-free/FreeMono.ttf', font_size)

    fill_selected = (random.randint(0, 200), random.randint(0, 200), random.randint(0, 200), random.randint(0, 255))
    # Chose a random colour

    y_random = random.randint(0, 30)
    # All characters should not be in a horizontal line.
    # So shift position of each character randomly

    draw_text(img, x_pos, y_random, char, font_selected, fill_selected)

    x_pos = x_pos + 30
    # Position of the next character
    # We are randomly choosing a font size for each character
    # So position of the next character should not be chosen randomly

mid_x = image_x_size / 2
mid_y = image_y_size / 2

first_half_x = random.randint(1, mid_x - 1)
first_half_y = random.randint(1, mid_y - 1)

second_half_x = mid_x + random.randint(1, mid_x - 1)
second_half_y = mid_y + random.randint(1, mid_y - 1)

print "Going to draw a line from", first_half_x, ",", first_half_y, "to", second_half_x, ",", second_half_y
d = ImageDraw.Draw(img)
d.line((first_half_x, first_half_y, second_half_x, second_half_y), 10)

img.save('captcha.png')   # Save the image as a file on the disk


Here are some of the CAPTCHA images that I generated from this code.








Now let us see this code in detail.

from PIL import Image
We are using the Image module from the PIL library.

from PIL import ImageDraw
We are using the ImageDraw module from the PIL library.

from PIL import ImageFont
We are using the ImageFont module from the PIL library.


def draw_text(img, x_given, y_given, text_given, font_given, fill_given):
    d = ImageDraw.Draw(img)
    d.text((x_given, y_given), text_given, font=font_given, fill=fill_given)

I have written this function to draw the given text at the specified place in the given image.  The font and color to be used must be specified.  So why did I write a separate function for this?  Why not simply do this in the main code?  Well, you could do that.  Here I wrote a generic function, and used it.  So that tomorrow if I have to extend this code, a generic function would be useful.


def char_selecting(size=6):
    characters = "abdefghijklmnqrtuy123456789ABDEFGHIJKLMNQRTUY"

    # Exclude letters that look similar in capital and small cases
    # Why?
    # We are randomly choosing a font size.  Bigger to smaller.
    # So can't tell whether you are looking at C or c in that situation
    # Exclude zero because we want to avoid confusion between 0 and O and o
    selection = ""
    for x in range(0, size):
        char = characters[random.randint(0, len(characters) - 1)]
        selection = selection + char
    return selection

This is the function where the magic happens.  The magic of choosing a set of characters that we want to show in the CAPTCHA image.  Caller may choose the length of the string, by passing a numeric value.  Else, a default of 6 is taken.  We randomly choose the characters and form a string using them.  While choosing the characters in the string, I have not considered all of the upper case letters, small case letters, and numbers.  Why?  Allow me to explain please.  By looking at the CAPTCHA images that I have generated, you must have noticed that font size of each character varies.  I did that deliberately.  To avoid the text being recognized by an OCR software.  But when we have a mix of small and big font sizes, how could you tell the difference between c and C, or between z and Z?  Same for P, S, V, W, and X.  O is even difficult, because a 0 (zero) also looks similar.  So I chose not to use these characters.  So that we don't create a confusion for humans.

image_x_size = 200
image_y_size = 100
img = Image.new('RGB', (image_x_size, image_y_size), color = (250, 250, 250))
This is the start of the main code.  I have chosen image size of 200 x 100 pixels.  I have chosen background color which is almost white, but not exactly white.

word = char_selecting(6)    # We want 6 characters in our CAPTCHA
print word
A call to function char_selecting gets us a string of length 6, made up of randomly selected characters.

x_pos = 10    # Position of the first character in the image
In the loop that follows, you will observe that I keep on increasing this value, for the subsequent characters in the image.

for char in (list(word)):
    print char
From the string that we have prepared, here we take one character at a time, and work on it.

    font_size = random.randint(16, 50)
    # Font size smaller than 16 is too small
    # Font size bigger than 50 is too big
    font_selected = ImageFont.truetype('/usr/share/fonts/gnu-free/FreeMono.ttf', font_size)
As mentioned earlier, I have deliberately chosen a random font size for each character.  So that the resulting text could not be recognized by an OCR software.  Here I am using the same font for all characters.  If you want, you could obtain a list of fonts available in your system, and randomly choose a different font for each character.  That implementation I leave up to you.  Some weird fonts may be present in the system, which would render some of the characters beyond recognition by humans.  Considering this possibility, I did not do that.  I found a font in which the characters are rendered in a way that is easy for recognition by humans.  And I am sticking to that font.

    fill_selected = (random.randint(0, 200), random.randint(0, 200), random.randint(0, 200), random.randint(0, 255))
    # Chose a random colour
We are deliberately choosing a different color for each character.  So that the resulting text could not be recognized by an OCR software.

    y_random = random.randint(0, 30)
    # All characters should not be in a horizontal line.
    # So shift position of each character randomly
In my opinion, this is an important trick.  If all characters appear in an horizontal line, there is a possibility of them being recognized by an OCR software.  To minimize this possibility, we shift position of each character.  In the range of 30 pixels.

    draw_text(img, x_pos, y_random, char, font_selected, fill_selected)

    x_pos = x_pos + 30
    # Position of the next character
    # We are randomly choosing a font size for each character
    # So position of the next character should not be chosen randomly
Function draw_text is where we draw the character in the image.  Now let's see what precautions we have taken so that the text could not be recognized by an OCR software.
1. Color of each character is different.
2. Font size of each character is different.
3. Characters are not in a horizontal line.  They are slightly off-positioned.  Well enough to fool the OCR software.  But not too out-of-position.  So that humans don't have a difficulty in recognizing the sequence.

Now let's add something more in the image, which will prevent the OCR software from recognizing the text.  Let's draw a line.

mid_x = image_x_size / 2
mid_y = image_y_size / 2

first_half_x = random.randint(1, mid_x - 1)
first_half_y = random.randint(1, mid_y - 1)

second_half_x = mid_x + random.randint(1, mid_x - 1)
second_half_y = mid_y + random.randint(1, mid_y - 1)

print "Going to draw a line from", first_half_x, ",", first_half_y, "to", second_half_x, ",", second_half_y
d = ImageDraw.Draw(img)
d.line((first_half_x, first_half_y, second_half_x, second_half_y), 10)
First we decide the position of the line in the image.  We consider the image in two parts, say left part and right part.  In the left part, we chose a random position, one end point of the line.  In the right part, we chose a random position, the other end point of the line.  And we draw the line, using the end points that we have chosen.  Well, you could argue that a better method could have been used to draw the line.  Yes, I agree.  I leave this part up to you.  To implement a better method to draw a line.  Or may be some other geometrical object.  Or may be two geometrical objects.  Basically we want to have something that would prevent the OCR software from recognizing the text.

img.save('captcha.png')   # Save the image as a file on the disk
Finally we save the image as a file named captcha.png
Is this code perfect?  I don't claim it to be.  Does this code generate CAPCHAs that are easily recognizable by humans, but could never be recognized by OCR software?  I don't claim that either.  If you try hard enough, you might find an OCR software that recognizes the text.  And then what?  Well, if I'd get to know that, may be I'd change my code so that the flaw is removed.  After all, this is a game of cat and mouse that we all are playing, right?

And we did not generate audio CAPCHA yet.  So let's do that.

from gtts import gTTS

word = "TAAaGr"

text = ""
for char in (list(word)):
    text =  text + char + " "

speech = gTTS(text = text, lang = 'en', slow = True)

speech.save("captcha.mp3")

We are using the gtts library for this purpose.  For each character to be clearly audible, we are separating them by spaces.  You'd notice there is no difference in which small case letters and upper case letters are spoken.  So, if we have to implement image and audio CAPTCHA together, then along with numbers we should use only lower case letters or only upper case letters.

What if we could make the challenge–response test a little more difficult to be solved by a non-human, while keeping it easy for humans.  One way to do this is to show two numbers, ask what is their addition, and check the response.  Let's see python code for this.

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import random



def draw_text(img, x_given, y_given, text_given, font_given, fill_given):
    d = ImageDraw.Draw(img)
    d.text((x_given, y_given), text_given, font=font_given, fill=fill_given)


image_x_size = 150
image_y_size = 70
img = Image.new('RGB', (image_x_size, image_y_size), color = (250, 250, 250))

num1 = random.randint(1,9)
num2 = random.randint(1,9)
total = num1 + num2
print num1, "+", num2, "=", total

font_size = random.randint(16, 50)
# Font size smaller than 16 is too small
# Font size bigger than 50 is too big

font_selected = ImageFont.truetype('/usr/share/fonts/gnu-free/FreeMono.ttf', font_size)

fill_selected = (random.randint(0, 200), random.randint(0, 200), random.randint(0, 200), random.randint(0, 255))
# Chose a random colour

x_pos = 10    # Position of the first character in the image

y_random = random.randint(0, 20)
# All characters should not be in a horizontal line.
# So shift position of each character randomly

draw_text(img, x_pos, y_random, str(num1), font_selected, fill_selected)

fill_selected = (random.randint(0, 200), random.randint(0, 200), random.randint(0, 200), random.randint(0, 255))
x_pos = x_pos + 30
y_random = random.randint(0, 20)
draw_text(img, x_pos, y_random, "+", font_selected, fill_selected)

fill_selected = (random.randint(0, 200), random.randint(0, 200), random.randint(0, 200), random.randint(0, 255))
x_pos = x_pos + 30
y_random = random.randint(0, 20)
draw_text(img, x_pos, y_random, str(num2), font_selected, fill_selected)

fill_selected = (random.randint(0, 200), random.randint(0, 200), random.randint(0, 200), random.randint(0, 255))
x_pos = x_pos + 30
y_random = random.randint(0, 20)
draw_text(img, x_pos, y_random, "=", font_selected, fill_selected)

img.save('captcha_num.png')   # Save the image as a file on the disk

Here are some of the CAPTCHA images that I generated from this.




For simplicity, I chose single-digit integers.  You could choose bigger numbers, if that suits you.

Tuesday, September 4, 2018

How to identify world-writable files in a Unix / Linux system

World writable files are those that all users of the system could write to.  In Unix / Linux systems, few of the files and directories are world writable, and for a specific purpose.  /tmp and /var/tmp directories are world writable, and sticky bit is set for them.  A directory that is world writable should have sticky bit set as well.  If stick bit is not set for a world writable directory, that is a cause for an alarm.  World writable files pose even more risk when they are executable by all as well.  Because those are scripted disasters that are waiting to happen.

Here is a command to list files that are world-writable.

# find /  -perm -777  ! -type l  ! \( -type d -and -perm -1000 \)  -exec ls -ld {} \;  2>/dev/null

Symbolic links should be excluded from this list, since their permission bits are ignored.  We achieved this using   ! -type l

Directories that have sticky bit set should be excluded from this list.  We got this done using   ! \( -type d -and -perm -1000 \)

If you are not familiar with the find command, do check the manual page of find command.  And about the options I have used in the above command, here is what the manual says about them :

       -perm mode
              File's  permission  bits  are exactly mode (octal or symbolic). 
             
       -type l      symbolic link

       -type d      directory

       -exec command ;
              Execute command; true if 0 status is returned.  All following arguments to find are taken to be arguments to the command until an argument consisting of ; is encountered.  The string {} is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find.  Both of these constructions might need to be escaped (with a \) or quoted to protect them from expansion by the shell.


Careful examination should be done to identify whether the world writable files and directories found are actually necessary for the functionality of the system.  Permission should be updated appropriately for all the files and directories that are not necessary for the functionality of the system.

How to identify suid and sgid files in a Unix / Linux system

When a file is executed in a Unix / Linux system, execution is done using the privileges of the user who started execution.  This usual behavior could be altered using setuid and setgid flags.  Setuid and setgid flags provide elevated access rights while executing a file.  When setuid flag is set, execution is done using the privileges of the owner of the file.  Similarly, when setgid flag is set, privileges of the group owner of the file are used for executing the file.  This facility of executing files with elevated privileges is necessary for certain tasks of the operating system.  However, this facility poses risk when exploited by an attacker.

To mitigate the risk posed by presence of files having suid and sgid files set, careful examination should be done to identify whether the setuid and setgid flags are actually necessary for the functionality of the system.  All those that are not necessary should be removed.

Here is a command to list files that have suid flag set.

$ find /  -perm -4000  -exec ls -l {} \; 2>/dev/null

Here is a command to list files that have sgid flag set.

$ find /  -perm -2000  -exec ls -l {} \; 2>/dev/null

Here is a command to list files that have both suid and sgid flag set.

$ find /  -perm -6000  -exec ls -l {} \; 2>/dev/null

Are you wondering how is this facility is used by the Unix / Linux operating system.  Well, check the lists obtained from commands listed above.  You will see passwd which is used to update passwords of system users.  You will see sudo that is useful for executing a command as superuser or another user.  You will see ping, the useful networking command.  And many others.  So, before taking action on files that have suid or sgid flag set, careful examination should be done to ensure that we're doing what is right.  In an attempt of hardening the system, we don't want to halt some legitimate functionality of the system.

And how could an attacker exploit this facility.  Well, if an attacker gains access to the system, they could write a program to make a copy of /etc/shadow file.  Then set suid flag on that file.  Then change ownership of that file to superuser, who has access to /etc/shadow file.  Thus, /etc/shadow file is obtained.  Then remove the program that helped in this endeavor.  Now passwords could be obtained using John the Ripper.  Of course, these actions would be logged, and could be traced.  But why let the damage take place, when you could avoid it.

How to identify orphaned or unowned files in a Unix / Linux system

In a Unix / Linux system, files that are not owned by any user or group are known as orphaned files.  Having such files in the system is not a good idea.  Although these files themselves are not a risk, they could be used by an attacker in case of a breach. 

Here is a command to list files that are not owned by any user or group.

# find /  -path /proc -prune   -nouser -o -nogroup  -exec ls -l {} \; 2>/dev/null

For the files in this list, you could determine and implement appropriate actions, for the purpose of hardening the system.  Appropriate action could be to assign a user or group owner to the file, which was missing.  Or to remove the file if it is not required for the functionality of the system.  Or may be some other action.  Making these informed choices is better than not being aware of the situation.

If you are not familiar with the find command, do check the manual page of find command.  And about the options I have used in the above command, here is what the manual says about them :

       -path pattern
              File name matches shell pattern pattern. 

       -prune True;  if  the  file  is  a  directory,  do not descend into it.


       -nouser
              No user corresponds to file's numeric user ID.

       -nogroup
              No group corresponds to file's numeric group ID.

      -exec command ;
              Execute command; true if 0 status is returned.  All following arguments to find are taken to be arguments to the command until an argument consisting of ; is encountered.  The string {} is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find.  Both of these constructions might need to be escaped (with a \) or quoted to protect them from expansion by the shell.

Friday, April 6, 2018

How to identify which ports are open of a machine - active reconnaissance

Earlier this week, I was asked to check if a particular port is open or not for our storage product.  I checked all ports, and provided the report.  All systems require open ports and services to communicate and perform the required tasks.  A good security policy is to keep only the required ports open and close all others.

This indeed is a general and recurring question.  Which ports are open of my machine?  Obtaining an answer isn't complicated, if you are aware of nmap and the magical things it does.

If you have never heard of nmap, well, I'd say time to learn something new.  What is nmap and what sort of magic it does, this is a huge subject entirely.  Here is something to get you started.

nmap is a scanning tool that does port scan.  nmap sends various types of probes to the target IP address and then examines the responses to determine whether the service is actually listening.  For example, with an SYN scan, nmap sends a TCP SYN packet to the TCP port it is probing. This process is also known as half-open scanning because it does not open a full TCP connection.  If the response is a SYN/ACK, that is an indication of the port being in a listening state.  If the response to the SYN packet is an RST (reset), that hints us that the port is closed or is not in a listening state.  If no response is received to the SYN probe, nmap marks the port as filtered because it cannot determine if the port is open or closed.
 
If you have a machine with nmap installed, and your target machine is reachable from there, then you have the setup ready for you.

# nmap  -sV --version-all --version-trace  -p1-65535  -f  target.machine.ip.address

What options of nmap are we using :

           SERVICE/VERSION DETECTION:
             -sV: Probe open ports to determine service/version info
             --version-all: Try every single probe (intensity 9)
             --version-trace: Show detailed version scan activity (for debugging)

           PORT SPECIFICATION AND SCAN ORDER:
             -p : Only scan specified ports
                -p1-65535 scan ports in the range 1 to 65535

           FIREWALL/IDS EVASION AND SPOOFING:
             -f; --mtu : fragment packets (optionally w/given MTU)


If the target machine is reachable, output from nmap would begin like :

Starting Nmap 5.51 ( http://nmap.org ) at 2018-04-06 06:48 UTC
--------------- Timing report ---------------
  hostgroups: min 1, max 100000
  rtt-timeouts: init 1000, min 100, max 10000
  max-scan-delay: TCP 1000, UDP 1000, SCTP 1000
  parallelism: min 0, max 0
  max-retries: 10, host-timeout: 0
  min-rate: 0, max-rate: 0
---------------------------------------------


This would be followed by a vast output.  The summary at the end is what you'd be interested in.  Here is an example.

Nmap scan report for target.machine.ip.address
Host is up (0.00012s latency).
Scanned at 2018-04-06 06:48:39 UTC for 15s
Not shown: 65523 closed ports
PORT      STATE SERVICE VERSION
22/tcp    open  ssh     OpenSSH 5.3 (protocol 2.0)
111/tcp   open  rpcbind
875/tcp   open  rpcbind
2049/tcp  open  rpcbind
5920/tcp  open  vnc     VNC (protocol 3.8)
6020/tcp  open  X11     (access denied)
41253/tcp open  rpcbind
44220/tcp open  rpcbind
45208/tcp open  rpcbind
45964/tcp open  rpcbind
46691/tcp open  rpcbind
51961/tcp open  rpcbind
Service Info: OS: Unix
Final times for host: srtt: 122 rttvar: 17  to: 100000

Read from /usr/share/nmap: nmap-payloads nmap-rpc nmap-service-probes nmap-services.
Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 14.28 seconds
#


Let's understand the summary in the example.
Out of the 65535 ports, 12 are open and 65523 are closed.  For the closed ports, no information appears in the summary.  For the open ports, details are listed.

If ports are reported as "filtered", this indicates access to those ports is denied by a firewall.

And this leads us to another question.  "What if I want to check locally, and not from any other machine on my network?"  The same question could be put in more ways.  "What if I do not want to use nmap?"  "I got the list from nmap.  I want to cross-verify the same."

In this case, the netstat utility is our good friend.
Useful options of netstat are :
 
        -t, --tcp                  tcp only
        -n, --numeric              don't resolve names
        -l, --listening            display listening server sockets
        -p, --programs             display PID/Program name for sockets
 
For the curious minds who want to understand more about nmap, some of the most commonly used nmap scanning options for few specific scenarios are:
TCP Connect Scan (-sT)
UDP Scan (-sU)
TCP FIN Scan (-sF)
Host Discovery Scan (-sn)
Timing Options (-T 0-5)
If knowning these in detail is the intention, then I leave to the reader to explore and learn.
 

Tuesday, July 25, 2017

How do I check if my website is using SHA-1

SHA-1 (Secure Hash Algorithm 1) is an alogrithm used to verify data authenticity.  In 2005, SHA-1 was also found to be insecure.  So you should stop using SHA-1 and switch to SHA-2.  Is your website still using SHA-1 ?
 
You could do this check from command line of a Unix-like system.

openssl s_client -connect www.mysite.com:443 < /dev/null 2>/dev/null | openssl x509 -text -in /dev/stdin | grep "Signature Algorithm"
In the above command line, replace www.mysite.com with what you have.  For SSL, default port is 443.

    Signature Algorithm: sha1WithRSAEncryption
If this the result, your site is using SHA-1.  You should consider using SHA-2 in place of SHA-1.

    Signature Algorithm: sha256WithRSAEncryption
If this the result, your site is using SHA-2.

But why should I stop using SHA-1?

Today, more and more people consider SHA-1 to be insecure.  Since 2005, folks have published attacks on SHA-1.  The SHAttered attack is the most recent one.

Wednesday, April 13, 2016

How to save $$$ by using open source software instead of proprietary software

In March 2014, a storm happened in our office.  Some 50 folks were given marching orders.  From being laid back and overstaffed, our office floor was suddenly "awakened" and short-staffed.  Some folks had seen their "moment of truth".  For me, I was told to take some new tasks.  Tasks that my team members were "supposedly" doing.  And also an additional role in the security team of our products, SONAS and V7000 Unified.  I am always ready to take new tasks.  Being an evolved Aquarian, I welcome change.

The new role in the security team of our products, I started it in my natural style, taking the bull by the horn.  I strongly believe that's what works in a stormy weather.  My method was to question everything.  Review everything, and replace / adjust what is appropriate.

As part of this security role, my colleagues used to execute a security scan of our products on periodical basis, using Nessus.  Nessus is a proprietary comprehensive vulnerability scanner.  I studied this task in the same manner - question everything.  I found OpenVAS, a framework of several services and tools offering a vulnerability scanning and vulnerability management solution.

I did not use Nessus at all.  I told our admin folks not to continue the paid user account that was being used for executing vulnerability scans using Nessus.  I started using OpenVAS.

From the OpenVAS web site, I downloaded an image that contained a ready to use Virtual Machine, along with OpenVAS.  I prepared a virtual machine in my laptop.  It was easy.  I like the idea of providing an image that I could download and start a virtual machine that has OpenVAS installed.

In the scope of my projects, both Nessus and OpenVAS are vulnerability scanners.  Both work on the principle of scanning the product for presence of known security issues.  I did not do a deep study to determine which one is slightly better than the other.  I did not have that luxury of time.  More important was to get the job done, in time, and with minimum money spent.  In my limited study of Nessus and OpenVAS, I found Nessus has a richer GUI than OpenVAS.

What was the benefit of using Nessus?  The centralized IBM team was managing Nessus server.  At the cost of project money.  I decided to put some effort to setup OpenVAS, maintain it, and use it.  I saved on the project money that was spent for Nessus user account, and hardware in the lab from where security scan was initiated.

What is the benefit of using OpenVAS?
* No need to purchase software or any licenses
* No additional hardware needed.  OpenVAS is running in a virtual machine, which is running in my laptop

And the cost associated?  The effort required to setup and maintain OpenVAS running in a virtual machine.

Considering benefits vs the cost associated, this was a good bargain.

What did I miss?  Nessus seems to have a richer GUI than OpenVAS.  I am willing to miss a better user experience, for saving some $$$ from my project budget.

In my opinion, rather than which vulnerability scanner is being used, what is important in the scope of my project is identifying the optimal frequency at which scan should be done, and doing it.

Checking the product using a vulnerability scanner during development phase is important.  But this has a limited value.  Vulnerability scanners check the product against known security issues.  They can not find security issues that are not yet recognized.  Recognizing security issues is done by skilled humans, by looking at code (for example, Bar Mitzvah attack), by applying new ideas (for example, slowloris) etc.  Then these vulnerability scanners update their "signatures" to detect the new issue.

So, checking the product using a vulnerability scanner during development phase should be done.  This ensures that we are not shipping our product with any of the known security issues.  But this does not guarantee our product is 100% secure at the time of release.  There could be security issues present in our product, resulting from unsafe code.

If you are not sure about which vulnerability scanner to use, a good idea is to use two vulnerability scanners and compare the results.  In my project work, I did not have the luxury of using two vulnerability scanners and comparing the results.  So I chose one and used it, with awareness of the situation and the possible outcomes.

Please note : thoughts expressed here are my own, and not necessarily of my employer.