NetSec
Getting Comfortable with Console Access
In the world of web applications and cloud infrastructure, access is achieved with a browser.
Occasionally, you screw up so bad that this method of access becomes unavailable.
This is the issue Andrew and I experienced recently. We needed a way to configure a device without a graphical interface.
–
The Problem
While configuring a firewall, I created a rule that locked us out of the device completely. All my HTTPS requests to the firewall were blocked. All my SSH access was blocked.
–
Enter the Console Cable
Fortunately, I spent a fair amount of time working from both Linux and Cisco CLI, so it was easy to plug in a console cable, navigate the FreeBSD/OPNSense environment, and bring the network back online.
There is a lot of overlap between devices in terms of commands and configuration options. Occasionally one device has less features, or uses more ‘proprietary’ lingo.
This is where documentation, AI, and messaging your peers on Slack come in handy.
–
What You Need to Console at Home
For most users, the cable you’ll want is a USB to console adapter. https://www.amazon.com/Essential-Ubiquiti-Switches-Connection-Compatible/dp/B0CXSV6SX3
This is the most accessible for laptops.
–
Install Putty
To actually make use of the new console connection, we needed software to help interpret the signal and configure some settings.
Putty is a free, open-source solution that serves this purpose. You can use it on a variety of operating systems:
Windows/Unix https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
Linux sudo apt install putty
Mac possible with some headaches
Setting Up to Connect
Devices vary in how they interact with the console cable.
In my experience, there are only two things that change:
-
The baud rate, or how fast the devices send data back and forth over
-
the serial line, which is the name of the port you are plugging into
In practice, you will find the baud rate through research, and remember it.
The serial line can be found on Windows through Start > Device Manager > Ports (COM & LPT)
Your device will show up in that list.
Here is what you’ll need to enter in the Putty menu
Session tab
Serial Line COM5
Speed 9600
Data bits 8
Stop bits 1
Parity None
Flow control XON/XOFF
–
Seeing the Terminal
When you plug in the device, you’ll probably have to press enter or click a few times to ‘wake up’ the device. Unplugging the port can work, too.
By now you have a terminal session visible on Putty.
A Note on Console Access to Servers
We encountered an unintuitive issue when setting up the OPNSense firewall (which runs on FreeBSD).
After going through the usual steps to configure console access, we remained unable to get access over Putty. Fortunately, we were able to SSH into the server to at least poke around internally to set this up.
We verified that OPNSense configurations allowed for a serial console connection, and took note of the speed (baud rate).
(On the GUI - Systems > Settings > Administration >
[Console]
Use the virtual terminal driver (vt) [x]
Primary Console Serial Console
Secondary Console None
Serial Speed 9600
Use USB-based serial ports [x]
Password protect the console menu [x]
)
(From the CLI use sed or vi to view the console section in /conf/conf.xml )
We verified the baud rate was correct - the file in /boot/loader.conf indicated
comconsole_speed="9600"
We verified that the modules needed in the kernel were loaded (although it was an unnecessary step as you’ll see)
root > kldload uftdi // kldload: can't load uftdi: module already loaded or in kernel
The only thing that made sense at this point was if the kernel was looking at the wrong interface dmesg logs and examining the /etc/tty file revealed this to be the case
[1] ns8250: UART FCR is broken
[1] ns8250: UART FCR is broken
[1] uart0: <16550 or compatible> port 0x3f8-0x3ff irq 4 flags 0x10 on acpi0
[1] ns8250: UART FCR is broken
[1] uart0: console (9600,n,8,1) /// This shows the console cable registered on uart0, a motherboard device
[1] ns8250: UART FCR is broken
[1] ns8250: UART FCR is broken
[1] uart1: <16550 or compatible> port 0x2f8-0x2ff irq 3 on acpi0
The kernel was looking at ttyU0 (read: USB driver as an interface), NOT the motherboard (ttyu0) After adding this line into /etc/tty, we triggered a system-wide configuration reload and immediately got access
sh
vi /etc/tty
(inserted this line
ttyu0 "/usr/libexec/getty 3wire.9600" vt100 on secure
)
kill -HUP 1
This is as good an explanation as I can find on why these steps were necessary
On a technical level, what is happening boils down to a fundamental architectural design in FreeBSD (and OPNsense): the difference between **static hardware** and **dynamic (hot-plugged) hardware**, and how the system initialization daemon (`init`) manages them.
Here is the step-by-step breakdown of how this works under the hood.
---
### 1. Dynamic Device Node Creation (The DevFS Layer)
When you check the box for *"Use USB-based serial ports"*, OPNsense ensures that the USB serial kernel modules (like `uftdi`) are loaded.
FreeBSD uses a subsystem called **DevFS (Device File System)**. DevFS manages the `/dev/` directory dynamically:
* When a USB serial adapter is plugged in, the USB subsystem detects the hardware vendor and product ID.
* The kernel driver (e.g., `uftdi`) claims the device.
* The driver tells DevFS: *"Hey, I have a functional serial device here."*
* DevFS instantly flashes the virtual nodes `/dev/ttyU0` and `/dev/cuaU0` into existence.
If you unplug the USB adapter, DevFS instantly destroys those nodes. They only exist while the physical hardware is connected.
---
### 2. The Role of `init` and `/etc/ttys`
While DevFS handles the *hardware* layer, it does not handle the *software* layer. It does not know that you want to use that port for a terminal login session. That responsibility falls entirely on **`init`** (PID 1).
During boot, `init` reads the `/etc/ttys` file. This file is a static lookup table that tells `init` exactly which terminal lines should have a login prompt (`getty`) attached to them.
```text
# Device Command Type Status
ttyu0 "/usr/libexec/getty std.9600" vt100 on secure
```
When `init` parses this file:
1. It looks at the **Device** column (`ttyu0`).
2. If the **Status** is set to `on`, `init` executes the **Command** column (`/usr/libexec/getty`).
3. The `getty` process opens the device node, configures the baud rate, and sits there waiting to output the `login:` text the moment someone presses a key.
---
### 3. The "Disconnect" with USB Devices
This is where the breakdown occurs for hot-plugged USB adapters.
For a traditional motherboard serial port (`ttyu0`), the hardware is hardwired and permanent. `init` can open `/dev/ttyu0` safely at boot because that port will never disappear.
However, for a USB port (`ttyU0`), `init` faces a problem: **the hardware might not be plugged in when the server boots.**
If `/etc/ttys` tells `init` to start a `getty` process on `ttyU0`, but the USB cable is unplugged, the `getty` process will fail immediately because `/dev/ttyU0` does not exist.
* When a process fails inside `init`, `init` will continually try to restart it.
* This creates a rapid, infinite loop known as **"getty spawning too fast"**, which floods the system logs and wastes CPU cycles.
Because of this architectural risk, FreeBSD **defaults all dynamic `ttyU*` ports to `off**` (or leaves them out of the file entirely).
---
### Summary of the Lifecycle
When you manually add the line to `/etc/ttys` and run `kill -HUP 1`, you are completing the bridge:
```
[Physical USB Connection]
│
▼
[Kernel Driver Interception]
│
▼
[DevFS creates /dev/ttyU0] ◄─── (Dynamic Hardware Layer)
│
▼
[init reads /etc/ttys] ◄─── (Your manual instruction saying "Yes, this port is safe")
│
▼
[getty process launched] ◄─── (Software Layer: PuTTY now gets a login prompt)
```
By explicitly declaring it `on`, you are reassuring `init` that it is safe to bind a software login manager to that dynamic, virtual node.
Scapy
Getting the opportunity to use Scapy hands-on in a demo was amazing!
DEFCON704 hosted the event, where we learned how this Python library is capable of manipulating packet data in a variety of protocols. This simplifies the attacker’s workflow considerably.
The highlight scenario was setting up an Evil Twin with an updated Linux distribution and the Scapy library.
We also touched on the specific FCC regulations and other laws applicable to this class of attack.
Snort Rules
I was really impressed with the way this article was written. It illustrates what Snort can achieve with practical examples and context against the OWASP top 10.
Update: Ansible for Cisco IOS Devices
Sharing some configurations for anyone wanting to play with old Cisco gear via Ansible
In particular, I set things up to be more secure than my previous implementations
SSH - Can Your Box Do It?
Not every IOS version has this capability. One switch I own runs
flash:/c2950-i6q4l2-mz.121-12c.EA1.bin HASH: 3109efb5f9f3d4f35d165d9c4ed74fd3
Telnet is the best I can do
The other significant downside is that when old Cisco equipment does run SSH, it is not up-to-date with modern encryption standards. I have to pass these flags just to get the handshake to work
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -oHostKeyAlgorithms=+ssh-rsa -c aes256-cbc -m hmac-sha1
That’s certainly an improvement on Telent, but an adversary can still decrypt the packets with minimal effort
Upgrading Cisco IOS
- The tricky part is getting your hands on an updated image.
Once you do, these are the steps you take:
1. Prepare the Linux TFTP Server
- Linux:
sudo apt update && sudo apt install tftpd-hpa(Installs the TFTP server package) - Linux:
sudo cp c2950-i6q4l2-mz.121-22.EA14.bin /srv/tftp/(Copies the new Cisco IOS.binfile into the default TFTP root directory) - Linux:
sudo chmod 644 /srv/tftp/c2950-i6q4l2-mz.121-22.EA14.bin(Ensures the file is readable by the TFTP daemon) - Linux:
sudo systemctl restart tftpd-hpa(Restarts the TFTP service to apply changes)
2. Verify Connectivity and Flash Space
- Switch:
ping 192.168.1.10(Verifies network connectivity to the Linux server’s IP address) - Switch:
enable; show flash:(Checks the available space on the switch’s flash memory) - Switch:
delete flash:html(Optional: Deletes the old web interface directory if free space is insufficient for the new image)
3. Transfer and Boot Configuration
- Switch:
copy tftp://192.168.1.10/c2950-i6q4l2-mz.121-22.EA14.bin flash:c2950-i6q4l2-mz.121-22.EA14.bin(Downloads the new IOS image file from the Linux server to the switch flash) - Switch:
configure terminal(Enters global configuration mode) - Switch(config):
no boot system(Clears any old boot path environment variables) - Switch(config):
boot system flash:c2950-i6q4l2-mz.121-22.EA14.bin(Instructs the switch to boot using the newly downloaded image file) - Switch(config):
exit(Returns to privileged EXEC mode)
4. Save and Reboot
- Switch:
copy running-config startup-config(Saves the updated boot settings to non-volatile memory) - Switch:
reload(Reboots the switch to execute the newly installed IOS software)
Storing Passwords Securely
I am using Bitwarden in this case, but you can use any password manager in theory
Bitwarden has a plugin for Ansible you need to install
ansible-galaxy collection install bitwarden.secrets
Configuring Your Linux Environment for Security
A few things to do
- create a dedicated Ansible user + group
- create a serviced file that will populate your Bitwarden API key on startup
- create a dedicated python environment that this group will use
- set file permissions so other users/groups cannot access these
- set an ACL so other groups cannot run Ansible, or download it from elsewhere
Here’s a good introductory to Bitwarden in K8 context
Ansible Syntax and Quirks
Some good resources
Format & Variables More Fancy Ideas CLI Command Module LibSSH vs Paramiko
Writing the Playbook
Here’s an example
- name: first play
hosts: routers
vars:
ansible_connection: ansible.netcommon.network_cli
ansible_network_os: cisco.ios.ios
ansible_become: yes
ansible_become_method: enable
access_token: "{{ lookup('ansible.builtin.env', 'BWS_ACCESS_TOKEN') }}"
ansible_ssh_extra_args: '-oKexAlgorithms=+diffie-hellman-group1-sha1 -oHostKeyAlgorithms=+ssh-rsa -c aes256-cbc -m hmac-sha1'
gather_facts: false
tasks:
- name: Read Pass
ansible.builtin.set_fact:
passwd: "{{ lookup('bitwarden.secrets.lookup', 'a2b29ea3-a53d-43b3-a433-b46d014959ed', access_token=access_token) }}"
- name: Debug Pass
ansible.builtin.debug:
msg: "Successfully found password {{ lookup('bitwarden.secrets.lookup', 'a2b29ea3-a53d-43b3-a433-b46d014959ed', access_token=access_token) }}"
no_log: false
- name: Set Pass
ansible.builtin.set_fact:
ansible_password: "{{ passwd }}"
ansible_become_password: "{{ passwd }}"
- name: Get run config
cisco.ios.ios_command:
commands:
- show running-config | section FastEthernet0/1
- name: Get running configuration
cisco.ios.ios_config:
lines:
- interface fa 0/1
- ip addr 10.10.10.10 255.255.255.0
- no shut
- name: Get run config
cisco.ios.ios_command:
commands:
- show running-config | section FastEthernet0/1
You can do more specific error-handling with blocks and rescues
Troubleshooting Playbooks
My go-to is ansible-playbook playbook_name.yml –flush-cache -vvvv
This forces connections to reset and gives you a trace for most events occurring in your plays
Usually, if you Google the errors you are getting, you’ll find an indicator for where the issue lies fairly quickly.
The other important debugging step is to write out a plain English template of what you want to do before you start writing the Ansible code.
Ansible for Cisco IOS Devices
After procrastinating for weeks, I finally started to set up Ansible in order to administer my Cisco switches and routers. They are all ancient, but functional enough for my needs.
My main laptop still has Windows, but I downloaded WSL to allow Ansible to function properly.
The first hour I spent scanning the Ansible documentation. The gist is you can write files that act as instruction manuals for what devices you want configured, and the desired configurations. This requires a functional SSH connection to each device (which, to my knowledge, has to be set up manually).
The tricky part is understanding what terms you need in a playbook / inventory file and where they belong. I found that googling and looking at visual examples was the best way for me to understand this.
Cisco devices in particular are tricky because you interact with them via a CLI, not python. It is necessary to tell Ansible this so you don’t get errors related to it trying to run Python on the managed device.
Also, remember to install ansible-pylibssh (or paramiko).
pip install ansible-pylibssh
Following is the functional inventory file I used:
all:
children:
routers: #this is the name you give to groups of devices
hosts:
router_one: #this is the name you use to identify each device
ansible_host: ip.address.of.device
ansible_user: username
ansible_port: 22
vars:
ansible_connection: ansible.netcommon.network_cli
ansible_network_os: cisco.ios.ios
ansible_become: true
ansible_become_method: enable
ansible_become_password: password
# how to get password here securely
Password Cracking
After purchasing a bundle of used Cisco devices for CCNA training, I learned the majority of devices were password locked (ugh). The seller insisted that no passwords were set, so I was stuck.
As you probably guessed, I learned how to get the devices into ROMMON mode to overwrite the current start config with the blank slate available on a different part of flash. But before I went about wiping all the devices, I looked into how feasible it would be to brute force the passwords.
The only passwords that needed to be attacked were the ones that are MD5 hashed. The rest were clear text or the cipher option.
Playing around with Hashcat, I first attempted a public wordlist without any hits. I started reading about how templates can be used to construct custom word lists. This is convenient when the password behavior is predictable.
For instance, many people enter passwords in the form <alphabetical><numerical><special characters>. A set of rules can be written (see maskprocessor) and used with Hashcat to generate passwords that follow this form. This avoids guessing the garbled mess that password managers would use by default.
I will eventually show the exact difference in stats, but it is orders of magnitude easier to crack formulaic passwords.
references - maskprocessor, hybrid attack