mirror of
https://github.com/chipsec/chipsec
synced 2026-06-08 13:31:00 +00:00
9be66dadbd
`print_buffer_bytes` can directly handle bytes, instead of converting
them to a string.
While at it, replace buggy calls to `print_buffer(buffer)` (when
`buffer` uses type `bytes`) with `print_buffer_bytes(buffer)`.
This fixes `./chipsec_util.py idt 0`. Before it failed with:
[CHIPSEC] Dumping IDT of 8 CPU threads
[cpu0] Physical Address: 0x000000036639E000
[cpu0] # of entries : 256
[cpu0] Contents (4 entries):
Traceback (most recent call last):
File "./chipsec_util.py", line 210, in <module>
sys.exit(main())
File "./chipsec_util.py", line 205, in main
return chipsecMain.main()
File "./chipsec_util.py", line 190, in main
comm.run()
File "chipsec/utilcmd/desc_cmd.py", line 84, in run
self.cs.msr.IDT_all(4)
File "chipsec/hal/msr.py", line 166, in IDT_all
self.IDT(tid, num_entries)
File "chipsec/hal/msr.py", line 158, in IDT
return self.dump_Descriptor_Table(cpu_thread_id, DESCRIPTOR_TABLE_CODE_IDTR, num_entries)
File "chipsec/hal/msr.py", line 144, in dump_Descriptor_Table
print_buffer(dt)
File "chipsec/logger.py", line 493, in print_buffer
prt_str = bytes2string(arr, length)
File "chipsec/logger.py", line 466, in bytes2string
num_string += [f'{ord(c):02X} ']
TypeError: ord() expected string of length 1, but int found
There was another bug in `hal/msr.py` where `ord(dt[...])` was used
instead of `dt`.
Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
94 lines
4.0 KiB
Python
94 lines
4.0 KiB
Python
# CHIPSEC: Platform Security Assessment Framework
|
|
# Copyright (c) 2010-2020, Intel Corporation
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation; Version 2.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
#
|
|
# Contact information:
|
|
# chipsec@intel.com
|
|
#
|
|
|
|
|
|
"""
|
|
Checks for exposure of pre-boot passwords (BIOS/HDD/pre-bot authentication SW) in the BIOS keyboard buffer.
|
|
|
|
Reference:
|
|
- DEFCON 16: `Bypassing Pre-boot Authentication Passwords by Instrumenting the BIOS Keyboard Buffer <https://www.defcon.org/images/defcon-16/dc16-presentations/brossard/defcon-16-brossard-wp.pdf>`_ by Jonathan Brossard
|
|
|
|
Usage:
|
|
``chipsec_main -m common.bios_kbrd_buffer``
|
|
|
|
Examples:
|
|
>>> chipsec_main.py -m common.bios_kbrd_buffer
|
|
|
|
"""
|
|
|
|
from chipsec.module_common import BaseModule, ModuleResult, MTAG_BIOS
|
|
from chipsec.logger import print_buffer_bytes
|
|
|
|
TAGS = [MTAG_BIOS]
|
|
|
|
COMMON_FILL_PTRN = "".join(['{:1}'.format((chr(x + 0x1E))) for x in range(32)])
|
|
|
|
|
|
class bios_kbrd_buffer(BaseModule):
|
|
def __init__(self):
|
|
BaseModule.__init__(self)
|
|
|
|
def is_supported(self):
|
|
return True
|
|
|
|
def check_BIOS_keyboard_buffer(self):
|
|
kbrd_buf_head = self.cs.mem.read_physical_mem_dword(0x41A) & 0x000000FF
|
|
kbrd_buf_tail = self.cs.mem.read_physical_mem_dword(0x41C) & 0x000000FF
|
|
self.logger.log("[*] Keyboard buffer head pointer = 0x{:X} (at 0x41A), tail pointer = 0x{:X} (at 0x41C)".format(kbrd_buf_head, kbrd_buf_tail))
|
|
bios_kbrd_buf = self.cs.mem.read_physical_mem(0x41E, 32)
|
|
self.logger.log("[*] Keyboard buffer contents (at 0x41E):")
|
|
print_buffer_bytes(bios_kbrd_buf)
|
|
bios_kbrd_buf = bios_kbrd_buf.decode('latin_1')
|
|
|
|
has_contents = False
|
|
|
|
if COMMON_FILL_PTRN == bios_kbrd_buf:
|
|
self.logger.log_good("Keyboard buffer is filled with common fill pattern")
|
|
return ModuleResult.PASSED
|
|
|
|
for x in bios_kbrd_buf:
|
|
if ("\x00" != x) and ("\x20" != x):
|
|
has_contents = True
|
|
break
|
|
|
|
if (0x1E < kbrd_buf_tail) and (kbrd_buf_tail <= 0x1E + 32):
|
|
self.logger.log_bad("Keyboard buffer tail points inside the buffer (= 0x{:X})".format(kbrd_buf_tail))
|
|
self.logger.log(" It may potentially expose lengths of pre-boot passwords. Was your password {:d} characters long?".format((kbrd_buf_tail + 2 - 0x1E) // 2))
|
|
|
|
self.logger.log("[*] Checking contents of the keyboard buffer..\n")
|
|
|
|
if has_contents:
|
|
self.logger.log_warning("Keyboard buffer is not empty. The test cannot determine conclusively if it contains pre-boot passwords.")
|
|
self.logger.log(" - The contents might have not been cleared by pre-boot firmware or overwritten with garbage.")
|
|
self.logger.log(" - Visually inspect the contents of keyboard buffer for pre-boot passwords (BIOS, HDD, full-disk encryption).")
|
|
else:
|
|
self.logger.log_passed("Keyboard buffer looks empty. Pre-boot passwords don't seem to be exposed")
|
|
|
|
return (ModuleResult.WARNING if has_contents else ModuleResult.PASSED)
|
|
|
|
# --------------------------------------------------------------------------
|
|
# run( module_argv )
|
|
# Required function: run here all tests from this module
|
|
# --------------------------------------------------------------------------
|
|
def run(self, module_argv):
|
|
self.logger.start_test("Pre-boot Passwords in the BIOS Keyboard Buffer")
|
|
self.res = self.check_BIOS_keyboard_buffer()
|
|
return self.res
|